-
-
Notifications
You must be signed in to change notification settings - Fork 258
NumberLiteralSeparator: Stage 1 feature plugin. Closes gh-538 #541
Conversation
Signed-off-by: Rick Waldron <[email protected]>
Amazing, that was super quick! A few things to note:
|
@hzoo thanks for the quick review turnaround, I will get these issues addressed and ping you when ready :) |
Yeah, I should probably add that information to the contributing, let us know if there's anything that can be clarified or is frustrating |
Signed-off-by: Rick Waldron <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #541 +/- ##
==========================================
+ Coverage 98.13% 98.13% +<.01%
==========================================
Files 22 22
Lines 3588 3599 +11
Branches 1002 1007 +5
==========================================
+ Hits 3521 3532 +11
Misses 24 24
Partials 43 43
Continue to review full report at Codecov.
|
@hzoo changes pushed. I didn't make changes to ast/spec.md because I don't believe there are any changes to make there (I could be wrong, but need guidance) |
…alSeparatorSiblings Signed-off-by: Rick Waldron <[email protected]>
src/tokenizer/index.js
Outdated
if (forbiddenNumericLiteralSeparatorSiblings.includes(prev) || | ||
forbiddenNumericLiteralSeparatorSiblings.includes(next) || | ||
Number.isNaN(next)) { | ||
this.raise(this.state.pos, "Invalid NumericLiteralSeparator"); |
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 might actually create a different error message for multi _
, if it's at the end or the beginning, or around invalid chars but we can totally do that later too.
Could be a good 2nd PR
src/tokenizer/index.js
Outdated
const prev = this.input.charCodeAt(this.state.pos - 1); | ||
const next = this.input.charCodeAt(this.state.pos + 1); | ||
if (code === 95) { | ||
if (forbiddenNumericLiteralSeparatorSiblings.includes(prev) || |
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.
Thanks for the PR, @rwaldron! I believe we need to switch to Array#indexOf
here instead of Array#includes
. We don't load any polyfills in Babylon, and the minimum supported node version is 4.0.0.
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.
Dang forgot about that 🤔
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.
Ah, ok, no problem. I saw all the other modern JS and just assumed I could use it...whoops! Will fix now.
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.
Looks good to me! 👍 Amazing work for the first PR
Ideally the cases that have a weird error message should be fixed to have the same error message as the others
✔ ._1_1 is Unexpected token (1:0) (module)
✔ ._1_1 is Unexpected token (1:0) (script)
✔ 0o01_8 is Unexpected token, expected ; (1:5) (module)
✔ 0o01_8 is Unexpected token, expected ; (1:5) (script)
✔ 0b2_1 is Expected number in radix 2 (1:2) (module)
✔ 0b2_1 is Expected number in radix 2 (1:2) (script)
✔ 0xZ_1 is Expected number in radix 16 (1:2) (module)
✔ 0xZ_1 is Expected number in radix 16 (1:2) (script)
Signed-off-by: Rick Waldron <[email protected]>
@DrewML pushed change for includes -> indexOf |
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 most those stay as they are because they have a different violation in them before the illegal
I think this:
...is an outlier that should be fixed, but I'm not sure how. The And this:
... involves changing |
Yeah I think this is good for this PR |
Let's do this 😄 |
Does |
It shouldn't the separator is only allowed in between numeric values. |
Well |
@jridgewell @hzoo @diervo correct, |
@rwaldron I believe there's a bug in that this allows legacy octal integer literals to have separators. Even if this does restrict them, I don't see a test for that. Do you mind sending a PR to correct that? |
Ping @rwaldron. |
Signed-off-by: Rick Waldron [email protected]
I modified
readInt
to ignore_
characters found in decimal, hex, binary and octal literals. It will also throw SyntaxError exceptions when the_
is misused.