Skip to content

Commit

Permalink
fix(parser): Use 'const' instead of 'let'
Browse files Browse the repository at this point in the history
In the latest fixes for escaped keyword I chose to throw on "invalid left hand side in assignment" instead of invalid keyword in cases like this "var y = { c\u0061se: x } = { case: 42 };"

This is a design choice, because we don't know before parsing the "=" if there is an invalid LHS assign.

@aladdin-add Agree?
  • Loading branch information
KFlash committed Aug 15, 2019
1 parent 6c48765 commit f1bc71f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,7 @@ export function parseObjectLiteralOrPattern(
let state = PropertyKind.None;
let key: ESTree.Expression | null = null;
let value;
let t = parser.token;
const t = parser.token;
if (parser.token & (Token.IsIdentifier | Token.Keyword) || parser.token === Token.EscapedReserved) {
key = parseIdentifier(parser, context, 0);

Expand Down

3 comments on commit f1bc71f

@aladdin-add
Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds reasonable. (though I think the unchanged is more friendly to users.)

btw, the commit seems not a bugfix, it's a non-user-faced change.:-)

@KFlash
Copy link
Contributor Author

@KFlash KFlash commented on f1bc71f Aug 15, 2019

Choose a reason for hiding this comment

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

Ah! Sorry! I wrote the comment here. See the 2 latest commits and you can see the changes. My mistake :)

unchanged?

The other way around is to track errors and throw them later e.g. on invalid assignment, but I'm afraid that will just kill the performance somehow.

BTW. Do you have a chance to do a PR against #34 with fixes? I'm kind of stuck in a regex mess after I discovered that V8 and other engines have a lot of invalid validations. So I'm soon done with my own :)

@aladdin-add
Copy link
Collaborator

Choose a reason for hiding this comment

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

either is fine, I don't feel strong.

re #34 , I can take care of it later. 😄

Please sign in to comment.