Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES Next: Logical assignment operators #168

Closed
jods4 opened this issue Jan 24, 2021 · 10 comments · Fixed by #173
Closed

ES Next: Logical assignment operators #168

jods4 opened this issue Jan 24, 2021 · 10 comments · Fixed by #173
Assignees

Comments

@jods4
Copy link

jods4 commented Jan 24, 2021

This proposal is completed (stage 4) and supported by TS, it's expected to be part of ES2021.
https://github.com/tc39/proposal-logical-assignment

It also works in most browsers today:
https://caniuse.com/mdn-javascript_operators_logical_nullish_assignment

Can you add support for it?
I have code that uses ??= and it doesn't parse :(

@KFlash
Copy link
Contributor

KFlash commented Jan 24, 2021

Try use option next for now.

cc / @3cp

@jods4
Copy link
Author

jods4 commented Jan 24, 2021

I use next: true in my options.
Many things work, like import.meta but ??= doesn't and I don't see it listed on the README.

Is it supposed to work? I can investigate further if it is, but I have the impression it's not.

@KFlash
Copy link
Contributor

KFlash commented Jan 24, 2021

What is the code line you try to parse? It's implemented in Meriyah without any need to enable next.

IGNORE

I got confused by my own parser, but I noticed now this is not implemented in Meriyah source!

@3cp Will you take a stab at it?

@jods4
Copy link
Author

jods4 commented Jan 25, 2021

@KFlash I saw you have a parser of your own. Would you advise using it?
I value ES support, speed and require a standard AST with locations.

@KFlash
Copy link
Contributor

KFlash commented Jan 25, 2021

I think Meriyah is the best choice. I have my own parser yes, but it's part of my non-open source project.
My goal was to do the same as Babel with transformers, linting, minifier, prettify, parse TS etc.

I archived my goal and still playing around.

You can check out this readme and try out the demo.

Meriyah is a simple JS parser that follows ESTree and also used in Prettier. It's an better alternative than for example Acorn due to it's performance.

@3cp
Copy link
Member

3cp commented Jan 28, 2021

Looks like not difficult to implement. Question @KFlash, do we want to shift the numbers below assign operators to make spaces for ||= &&= and ??=? Or we can give new numbers for them

  /* Assign operators */
  Assign                  = 29 | IsAssignOp | IsClassField, // =
  ShiftLeftAssign         = 30 | IsAssignOp, // <<=
  ShiftRightAssign        = 31 | IsAssignOp, // >>=
  LogicalShiftRightAssign = 32 | IsAssignOp, // >>>=
  ExponentiateAssign      = 33 | IsAssignOp, // **=
  AddAssign               = 34 | IsAssignOp, // +=
  SubtractAssign          = 35 | IsAssignOp, // -=
  MultiplyAssign          = 36 | IsAssignOp, // *=
  DivideAssign            = 37 | IsAssignOp | IsExpressionStart, // /=
  ModuloAssign            = 38 | IsAssignOp, // %=
  BitwiseXorAssign        = 39 | IsAssignOp, // ^=
  BitwiseOrAssign         = 40 | IsAssignOp, // |=
  BitwiseAndAssign        = 41 | IsAssignOp, // &=
  
  // Do we give 42, 43, 44 to ||=, &&=, and ??= ?
  // Or use 136, 137, 138 (after the last one JSXText 135)?

  /* Unary/binary operators */
  TypeofKeyword      = 42 | IsUnaryOp | Reserved,
  DeleteKeyword      = 43 | IsUnaryOp | Reserved,
  VoidKeyword        = 44 | IsUnaryOp | Reserved,
  Negate             = 45 | IsUnaryOp, // !

@3cp 3cp self-assigned this Jan 28, 2021
@KFlash
Copy link
Contributor

KFlash commented Jan 28, 2021

The order doesn't matter, but probably easier to understand if grouped together like 41, 42 ... etc

Do not forget to add | IsAssignOp behind the numbers or else this will not parse :P

The token dispatch code also need a quick update for this to work, but nothing of this is super hard. Maybe 10 min to fix it.

@3cp
Copy link
Member

3cp commented Jan 30, 2021

@KFlash does stage4 mean still need next flag?

@KFlash
Copy link
Contributor

KFlash commented Jan 30, 2021

It's means it's implemented in all browsers and is now part of the ECMA language, so no!

@3cp
Copy link
Member

3cp commented Jan 30, 2021

Good, I didn't do that.

@3cp 3cp closed this as completed in #173 Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants