GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: support mult-line string-keyed objects by rubys · Pull Request #21805 · nodejs/node

Conversation

@rubys

@rubys rubys commented Jul 13, 2018

Copy link
Copy Markdown
Member

isRecoverableError is completely reimplemented using acorn and an
acorn plugin that examines the state of the parser at the time of the
error to determine if the code could be completed on a subsequent line.

fixes #21657

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jul 13, 2018
@rubys rubys mentioned this pull request Jul 13, 2018
repl: support mult-line string-keyed objects #21775
Closed
3 tasks done
@vsemozhetbyt

vsemozhetbyt commented Jul 14, 2018

Copy link
Copy Markdown
Contributor

CI: https://ci.nodejs.org/job/node-test-pull-request/15871/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these additions be placed near the other acorn work in lib/internal/repl/?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 14, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by these additions here. The require isn't new, just the capturing of the name as acorn is new. More generally, isRecoverableError isn't new, just completely rewritten.

Perhaps you are suggesting that isRecoverableError be split out into a separate file and placed into lib/internal/repl/? If so, I can do that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting keeping the acorn extensions and other acorn bits closer together.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acorn.tokTypes is commonly stored in a var called tt in acorn plugins.
So then it would be tt.eof.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe parse.type can be this.type

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆 Might put a note that these message strings are subject to change and to periodically check in on them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 14, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ponder how to word that. Meanwhile, I'll note that should these message strings change, a test will fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@BridgeAR BridgeAR Jul 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to manually update acorn to run into this issue. Having a failed test in such a circumstance would be fine and we'd have to invest that one way or the other. So I guess it is fine to keep it is as.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆 Acorn has a thorough regexp for whitespace. Might use that for the leading optional whitespace check.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 14, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think it is very important that the regular expression exactly match the one in defaultEval as it would be problematic for this code to treat a given input as recoverable only to later find out that defaultEval would consider it to be a syntax error when done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as above, inconsistent use of parser vs. this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 14, 2018
View reviewed changes
Comment thread lib/repl.js Outdated

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of nextToken.call and other .call's we should have const ReflectApply = Reflect.apply and then use it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 14, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, can I ask why? First, I don't see const ReflectApply = Reflect.apply as a common pattern inside of the node codebase (I only found two occurrences, and even those two differed). Second, I believe that .call is more concise and clearer (at a minimum, I wouldn't need to put [] around the arguments). What am I missing?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jdalton jdalton Jul 14, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since core is not run in its own isolated context but in the one shared with the user, its builtins are the same ones that user-land can touch and interact with. Grabbing references to builtin prototype methods and static builtin methods before user-land code executes is an attempt to strengthen the core against accidental user-land augmentation. While handled inconsistently in Node core, new code added seems to have these guards. It's reasonable, where possible, to keep that up.

The use of ReflectApply covers the Function#call case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Jul 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdalton there was a long discussion around this but no conclusion. As long as this is not something everyone agrees to I think it is best to keep these things to the PR openers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BridgeAR
BridgeAR approved these changes Jul 15, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great work @rubys and thanks a lot for taking up my suggestion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/repl.js Outdated

@BridgeAR BridgeAR Jul 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdalton there was a long discussion around this but no conclusion. As long as this is not something everyone agrees to I think it is best to keep these things to the PR openers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/repl.js Outdated

@BridgeAR BridgeAR Jul 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to manually update acorn to run into this issue. Having a failed test in such a circumstance would be fine and we'd have to invest that one way or the other. So I guess it is fine to keep it is as.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR

BridgeAR commented Jul 15, 2018

Copy link
Copy Markdown
Member

CI https://ci.nodejs.org/job/node-test-pull-request/15883/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TimothyGu
TimothyGu approved these changes Jul 15, 2018
View reviewed changes

@TimothyGu TimothyGu left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/repl/recoverable.js Outdated

@TimothyGu TimothyGu Jul 15, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: replRecoverable maybe?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@addaleax

addaleax commented Jul 18, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/15935/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Jul 18, 2018
jdalton
jdalton reviewed Jul 18, 2018
View reviewed changes
Comment thread lib/internal/repl/recoverable.js Outdated

@jdalton jdalton Jul 18, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆 Line continuations allow more than just \ followed by \n. See this bit of this.
This might be hit by folks copy-pasting code chunks in.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 18, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I think it could be more than just Windows users (and potentially more than acorn currently supports). HTML specifies \r\n terminators for form input. And the ECMA standard defines more than \r and \n.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jdalton reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
jdalton
jdalton suggested changes Jul 18, 2018
View reviewed changes

@jdalton jdalton left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change requested here for Windows user considerations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton reviewed Jul 19, 2018
View reviewed changes
Comment thread lib/internal/repl/recoverable.js Outdated

@jdalton jdalton Jul 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token.match() will return an array or null.
You probably want /\\(?:\r\n?|\n|\u2028|\u2029)$/.test(token).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jdalton
jdalton approved these changes Jul 19, 2018
View reviewed changes
sagirk
sagirk approved these changes Jul 26, 2018
View reviewed changes

@sagirk sagirk left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉, with a minor nit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/repl/recoverable.js Outdated

@sagirk sagirk Jul 26, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since e is not being used inside the catch block, can we get rid of it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@devsnek devsnek Jul 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to use them until eslint updates to support optional catch bindings and we update to that eslint.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rubys rubys Jul 26, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to work just fine:

$ git diff
diff --git a/lib/internal/repl/recoverable.js b/lib/internal/repl/recoverable.js
index 29411d6534..465d77451a 100644
--- a/lib/internal/repl/recoverable.js
+++ b/lib/internal/repl/recoverable.js
@@ -69,7 +69,7 @@ function isRecoverableError(e, code) {
     // but Acorn detected no issue.  Presume that additional text won't
     // address this issue.
     return false;
-  } catch (e) {
+  } catch {
     return recoverable;
   }
 }
$ make jslint
Running JS linter...
Please use lint-js instead of jslint

Should I push it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sagirk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@targos targos Jul 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's fine. We have babel-eslint and already use optional catch bindings in the codebase

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sagirk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
jasnell
jasnell approved these changes Jul 30, 2018
View reviewed changes
@rubys rubys mentioned this pull request Jul 31, 2018
dynamic import can't be used in the REPL #19570
Closed
@trivikr

trivikr commented Aug 1, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16117/

rubys reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Aug 1, 2018

Copy link
Copy Markdown
Member

Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16138/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr

trivikr commented Aug 2, 2018

Copy link
Copy Markdown
Member

@rubys This PR needs a rebase from upstream/master.
The instructions are described in Step 5

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rubys added 5 commits August 2, 2018 09:40
@rubys
repl: support mult-line string-keyed objects
9affc6f
isRecoverableError is completely reimplemented using acorn and an
acorn plugin that examines the state of the parser at the time of the
error to determine if the code could be completed on a subsequent line.
@rubys
parser. => this. and acorn.tokTypes => tt
7bb9bf1
@rubys
split out isRecoverableError, changed call to Reflect.apply.
d426b00
Added comments for regular expressions that need to match and
comparisons against exception message strings produced by Acorn.
@rubys
s/plugins.repl/plugins.replRecoverable/g
974b337
@rubys
all Line Terminators matter
02c5827
rubys added 2 commits August 2, 2018 09:40
@rubys
token.match() => .test(token)
e58b861
@rubys
remove unused exception variable
d426d86
@rubys
rubys force-pushed the repl-json branch from 9dbd64c to d426d86 Compare August 2, 2018 14:01
@rubys

rubys commented Aug 2, 2018

Copy link
Copy Markdown
Member Author

There wasn't a conflict with master, but I rebased, tested, and pushed it anyway.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Aug 2, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16161/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr

trivikr commented Aug 3, 2018

Copy link
Copy Markdown
Member

Resumed CI: https://ci.nodejs.org/job/node-test-pull-request/16174/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Aug 4, 2018

Copy link
Copy Markdown
Member

Landed in a2ec808

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott closed this Aug 4, 2018
Trott pushed a commit to Trott/io.js that referenced this pull request Aug 4, 2018
@rubys @Trott
repl: support mult-line string-keyed objects
a2ec808
isRecoverableError is completely reimplemented using acorn and an
acorn plugin that examines the state of the parser at the time of the
error to determine if the code could be completed on a subsequent line.

PR-URL: nodejs#21805
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this pull request Aug 4, 2018
@rubys @targos
repl: support mult-line string-keyed objects
e4f3468
isRecoverableError is completely reimplemented using acorn and an
acorn plugin that examines the state of the parser at the time of the
error to determine if the code could be completed on a subsequent line.

PR-URL: #21805
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@rvagg rvagg mentioned this pull request Aug 13, 2018
Release proposal: v10.9.0 #22295
Merged
This was referenced Aug 16, 2018
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#230
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#215
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#231
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#216
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#232
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#217
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#233
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#218
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#234
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#219
Closed
This was referenced Aug 17, 2018
Node REPL says "SyntaxError: unexpected symbol :" when parsing multi-line string-keyed objects (e.g. JSON) #21657
Closed
repl contains v8-specific syntax error message sniffs #21478
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
+5 more reviewers
@targos targos targos left review comments
@devsnek devsnek devsnek left review comments
@jdalton jdalton jdalton approved these changes
@TimothyGu TimothyGu TimothyGu approved these changes
@sagirk sagirk sagirk approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Node REPL says "SyntaxError: unexpected symbol :" when parsing multi-line string-keyed objects (e.g. JSON)

Uh oh!

There was an error while loading. Please reload this page.

13 participants

@rubys @vsemozhetbyt @BridgeAR @addaleax @trivikr @Trott @jdalton @jasnell @TimothyGu @targos @sagirk @devsnek @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.