Huáng Jùnliàng
a470f7b479
Recover from shorthand assign exprs ( #13968 )
...
* refactor: avoid duplicate property access
* refactor: tweak parseMember
* polish: recover from shorthand assign in exprs
2021-11-19 10:22:29 -05:00
Francisco Ryan Tolmasky I
966387d263
Always expose expressionValue in DirectiveLiteral nodes ( #13960 )
...
* fix(babel-parser): Move storage of expressionValue in DirectiveLiteral to main parser so it is accessible to others.
Closes #13953 .
Reviewed by @tolmasky.
* Add results from running `OVERWRITE=true yarn jest babel-parser`.
Reviewed by @tolmasky.
2021-11-13 20:46:16 -05:00
Huáng Jùnliàng
872086a9a0
feat: support startColumn option ( #13887 )
2021-10-29 01:20:32 +02:00
Nicolò Ribaudo
62b2c5ebb9
Regenerate parser fixtures ( #13882 )
2021-10-24 18:12:10 +02:00
Huáng Jùnliàng
d2076a531f
Store token type as number ( #13768 )
...
* refactor: abstract token metadata access
* refactor: move token-specific update context logic
* refactor: centralize token definitions
* refactor: abstract token type creation
* refactor: use number as token storage
* build: replace tt.* as number
* fix flow errors
* fix: build on Node 12
* Update packages/babel-parser/src/tokenizer/types.js
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
* refactor: rename token types exports to tt
* update unit test
* test: update Babel 8 test fixtures
* fix: centralize obsolete token type updateContext
* fix flow errors
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-09-17 09:36:11 -04:00
Sosuke Suzuki
62e42a3f60
fix(babel-parser): Fix end of range of SequenceExpression ( #13731 )
2021-09-04 12:01:20 +02:00
Huáng Jùnliàng
976bfbbf69
fix: assure left bracket is not consumed after dot ( #13695 )
...
* fix: assure left bracket is not consumed after dot
* address review comments
2021-08-20 11:29:44 +02:00
Huáng Jùnliàng
79d3276f61
Overhaul comment attachment ( #13521 )
...
* refactor: inline pushComment
* chore: add benchmark cases
* perf: overhaul comment attachment
* cleanup
* update test fixtures
They are all bugfixes.
* fix: merge HTMLComment parsing to skipSpace
* perf: remove unattachedCommentStack
baseline 128 nested leading comments: 11_034 ops/sec ±50.64% (0.091ms)
baseline 256 nested leading comments: 6_037 ops/sec ±11.46% (0.166ms)
baseline 512 nested leading comments: 3_077 ops/sec ±2.31% (0.325ms)
baseline 1024 nested leading comments: 1_374 ops/sec ±3.22% (0.728ms)
current 128 nested leading comments: 11_027 ops/sec ±37.41% (0.091ms)
current 256 nested leading comments: 6_736 ops/sec ±1.39% (0.148ms)
current 512 nested leading comments: 3_306 ops/sec ±0.69% (0.302ms)
current 1024 nested leading comments: 1_579 ops/sec ±2.09% (0.633ms)
baseline 128 nested trailing comments: 10_073 ops/sec ±42.95% (0.099ms)
baseline 256 nested trailing comments: 6_294 ops/sec ±2.19% (0.159ms)
baseline 512 nested trailing comments: 3_041 ops/sec ±0.8% (0.329ms)
baseline 1024 nested trailing comments: 1_530 ops/sec ±1.18% (0.654ms)
current 128 nested trailing comments: 11_461 ops/sec ±44.89% (0.087ms)
current 256 nested trailing comments: 7_212 ops/sec ±1.6% (0.139ms)
current 512 nested trailing comments: 3_403 ops/sec ±1% (0.294ms)
current 1024 nested trailing comments: 1_539 ops/sec ±1.49% (0.65ms)
* fix: do not expose CommentWhitespace type
* add comments on CommentWhitespace
* add test case for #11576
* fix: mark containerNode be the innermost node containing commentWS
* fix: adjust trailing comma comments for Record/Tuple/OptionalCall
* fix: drain comment stacks in parseExpression
* docs: update comments
* add a new benchmark
* chore: containerNode => containingNode
* add more benchmark cases
* fix: avoid finishNodeAt in stmtToDirective
* finalize comment right after containerNode is set
* add testcase about directive
* fix: finish SequenceExpression at current pos and adjust later
* chore: rename test cases
* add new test case on switch statement
* fix: adjust comments after trailing comma of function params
* add comment attachment design doc
* misc fix
* fix: reset previous trailing comments when parsing async method/accessor
* chore: add more comment testcases
* fix flow errors
* fix: handle comments when parsing async arrow
* fix: handle comments when "static" is a class modifier
* fix flow errors
* fix: handle comments when parsing async function/do
* refactor: simplify resetPreviousNodeTrailingComments
* update test fixtures
2021-07-07 11:51:40 -04:00
Huáng Jùnliàng
b9c1884a58
Reduce exprAllowed usage ( #13431 )
2021-06-09 16:36:09 +02:00
Huáng Jùnliàng
a387973821
Refactor private name tokenizing ( #13256 )
...
* add benchmark
* refactor: create tt.privateName token for private names
* add backward compat privateName = hash + name to Babel 7
* perf: get private name SV from token value
* chore: tweak benchmark file
* chore: update test fixtures
* convert tt.privateName to PrivateIdentifier
* perf: avoid most isPrivateName call
* Update packages/babel-parser/src/parser/expression.js
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
* perf: use inlinable codePointAtPos
* make prettier happy
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2021-05-06 09:46:09 -04:00
Huáng Jùnliàng
278193b6f7
fix: update chunkStart on missing unicode escape ( #13261 )
2021-05-06 08:31:11 -04:00
Sosuke Suzuki
2521c666f7
Add internal ESLint rule for consistent parser error messages ( #13130 )
2021-04-28 18:21:31 +02:00
Huáng Jùnliàng
0067fd9e02
Disallow await before exponential ( #12441 )
...
* refactor: move unary exponential check to parseMaybeUnary
* fix: disallow await before exponential
* add test cases
2021-03-25 11:20:47 -04:00
Nicolò Ribaudo
8cf0a757d5
Recover from "missing semicolon" errors ( #12437 )
...
* Recover from "missing semicolon" errors
* Update other tests
* Fix flow
* Fix windows test
* Add back deleted test
2021-02-01 10:08:43 +01:00
Huáng Jùnliàng
a0c1a9a9e4
Disallow non octal decimal escape before use strict ( #12366 )
2020-12-15 12:24:32 +01:00
Huáng Jùnliàng
5bbad8936b
fix: disallow all parenthesized pattern except parsing LHS ( #12327 )
...
* fix: disallow all parenthesized pattern except parsing LHS
* fix: forStatement requires LHS
* simplify toAssignable
* add more test cases
* fix: pass through isLHS on object property and assignment expression
* fix: record parenthesized identifier error for LHS
* remove duplicated skipped tests
* fix: do not record errors on ancestry arrow head
* Update packages/babel-parser/src/util/expression-scope.js
Co-authored-by: Brian Ng <bng412@gmail.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-11-10 14:42:37 -05:00
Huáng Jùnliàng
a8c66f4680
Handle exprAllowed before ObjectLike is parsed ( #12267 )
...
* fix: disallow expression after `}` is consumed in parseObjectLike
* refactor: avoid accessing this.prodParam in context update
2020-10-27 20:25:50 -04:00
iamfotx
59d97d9bca
[parser] Better error message for missing number exponent ( #12072 )
...
* fix(babel-parser) better error message for missing number exponent after 'e'
* fix(babel-parser) requested changes
* msg
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-10-14 21:17:38 +02:00
Sosuke Suzuki
45f0cc2ed9
Recover from error for missing initializer in const declaration ( #12120 )
2020-09-29 18:40:51 +02:00
fisker Cheung
18d13d0032
Fix invalid setter parse ( #12076 )
...
* Fix invalid `setter` parse
* estree
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-09-19 10:03:35 +02:00
Huáng Jùnliàng
01d4625412
Correctly check reserved word for PropertyDefinition: IdentifierReference ( #11862 )
...
* fix: check IdentifierReference in PropertyDefinition
* chore: add more test cases
* fix: incorrect test title
2020-07-29 19:40:52 -04:00
Huáng Jùnliàng
2bf38fb914
fix: disallow \8, \9 in strict mode string ( #11852 )
2020-07-21 09:44:56 -04:00
Huáng Jùnliàng
f4eeff947d
fix: correctly set innerEndPos in CoverParenthesizedExpressionAndArrowParameterList ( #11847 )
2020-07-16 17:11:06 -05:00
Kiko Estrada
5dd7f438c9
Enable import.meta by default in @babel/parser ( #11406 )
2020-05-24 22:57:34 +02:00
Brian Ng
40c517ed84
Set exprAllowed to false for star token ( #11449 )
2020-04-21 14:22:40 -05:00
Huáng Jùnliàng
dc7c5640e9
Compact parser fixture loc info ( #11322 )
...
* chore: compact loc information in parser fixtures
* chore: update test fixtures
2020-03-23 20:10:29 -04:00
Huáng Jùnliàng
841f4428e8
Rephrase parser error message ( #11208 )
...
* refactor: rephrase some parser error messages
* update test fixtures
* Update packages/babel-parser/src/parser/location.js
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
* address review comments
* Update packages/babel-parser/src/parser/location.js
Co-Authored-By: Brian Ng <bng412@gmail.com>
* update test fixtures
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-03-16 21:48:32 -04:00
Kai Cataldo
2057d2b159
fix: non-directive "use strict" should not enable parsing in strict mode ( #11188 )
...
* fix: non-directive "use strict" should not enable parsing in strict mode
* Remove dead code
* Add stricter type annotations
* set oldStrict explicitly to null
* Fix error
* label callback argument
* update comment
* Address feedback
* Remove this.state.octalPosition
* Add additional tests
* Revert "Remove this.state.octalPosition"
This reverts commit bcc78c9530f8c840f85e86053b75efce662f34d1.
* Remove containsOctal
* Report multiple octal literals in single token
* Fix comments
* remove Array.prototype.flat()
2020-03-05 17:34:27 -05:00
Huáng Jùnliàng
43b23e0869
refactor: simplify toAssignable routine ( #11032 )
...
* refactor: remove isBinding parameter
* remove unused contextDescription
* refactor: remove unnecessary nullish check
* refactor: simplify toAssignable on ParenthesizedExpression
* tests: categorize createParenthesizedExpression tests
2020-01-20 21:04:16 +01:00
Vedant Roy
341964bd4e
fix: properly parse member expression after property initializ… ( #11031 )
...
Fixes issue 10989 where the only the identifier in a member expression that is the value of an object property would be parsed. Removing checkExpressionErrors in parseExprSubscripts results in the subscript also being parsed.
2020-01-20 00:33:09 +01:00
Huáng Jùnliàng
45301c5304
Update coalesce precedence ( #11017 )
...
* refactor: reimplement nullish coalescing precedence tracking
Co-authored-by: Toru Nagashima <public@mysticatea.dev>
* fix: Coalesce has same precedence with LogicalOR
* fix flow errors
Co-authored-by: Toru Nagashima <public@mysticatea.dev>
2020-01-17 20:57:07 +01:00
Kai Cataldo
7b54a94389
@babel/eslint-parser: fix ImportExpression node to match ESTree spec ( #10828 )
...
* @babel/eslint-parser: fix ImportExpression node to match ESTree spec
* Update caller name for @babel/core.parseSync
* Move logic into estree plugin
* Add estree plugin tests
* Fix Flow error
* Fix flow
* Remove extra properties on ImportExpression node
* Incorporate review feedback
2019-12-11 11:13:57 +01:00
Nicolò Ribaudo
5156d3ea06
Restore @babel/parser tests ( #10854 )
...
* Make parser tests work again
* Update failing fixtures
* Fix serialization of BigInt
* Fix
2019-12-11 11:09:13 +01:00
Bowei Han
20e43ad103
validate parentheses in the left-hand side of assignment expressions ( #10576 )
...
* invalid left-hand assignments based on parenthesis
* validate against nested ParenthesizedExpressions
2019-12-09 20:29:02 -05:00
Kai Cataldo
a6d134804a
Unify build step for ESLint packages ( #10723 )
2019-11-16 10:15:15 +01:00
Nicolò Ribaudo
87feda7c2a
@babel/parser error recovery ( #10363 )
...
* Add error recovery support to @babel/parser
* Update @babel/parser tests to always recover from errors
* Update this.raise usage in @babel/parser:
- expression.js
- lval.js
- statement.js
- estree.js
- flow.js
- jsx/index.js
- tokenizer/index.js
* Update @babel/parser fixtures with recovered errors
* Fix tests out of @babel/parser
* Do not use try/catch for control flow
* Update invalid fixtures
* Do not report invalid lhs in toAssignable
* Do not validate function id multiple times
* Dedupe reserved await errors
* Remove duplicate errors about strict reserved bindings
* Remove duplicated error about yield/await inside params
* Don't error twice for methods in object patterns
* Don't report invalid super() twice
* Remove dup error about reserved param for expr arrows
* Remove double escapes in migrated tests
* Dedupe errors about invalid escapes in identifiers
* Remove duplicated error about decorated constructor
* Remove duplicated error about spread in flow class
* Don't throw for invalid super usage
* Don't fail for object decorators with stage 2
* Fix flow inexact type errors
* Fix flow
* Fix errors about escapes in keywords (ref: #10455 )
* Update after rebase
* Fix todo
* Remove duplicated error when using += for defaults
* Remove unnecessary throw
* Nit: use ??
2019-11-05 10:15:00 +01:00
Vivek Nayyar
4b3a19ea9f
fixed missing errors on assignment pattern in object expression ( #10607 )
...
* 🐛 fixed missing errors on assignment pattern in object expression
* ♻️ remove a non-needed comment
* 🐛 missed adding comma in the test input
* 🐛 fixed the failing valid-property-initializer test
2019-10-29 22:32:02 +01:00
Nicolò Ribaudo
78cd63d9cf
Fix invalid test layout in @babel/parser
2019-10-18 11:16:17 +02:00
piotr
5800fc97b3
[parser] Exception to 8 and 9 in tagged template ( #10567 )
2019-10-17 00:01:22 +02:00
Nicolò Ribaudo
34937f13d5
Trailing comma after rest - The final fix ( #10491 )
...
* [parser] Track trailing commas in extras instead of state
* Update existing tests
* Update test262 whitelist
* Improve error message and location
* nit
* Use lookaheadCharCode
2019-10-08 23:08:50 +02:00
Nicolò Ribaudo
cb881e6b3f
[parser] Report escapes in kws only if they won't be used as i… ( #10455 )
...
We can do it by tokenizing escaped keywords as normal identifiers, so that they won't
be accidentally used as real keywords.
2019-09-18 00:13:51 +02:00
Vivek Nayyar
b02e35c19a
Fix parenthesis for nullish coalescing ( #10269 )
...
* ♻️ added condition to check for left and right of nullish coalescing operator and if any is a logical expression without a paren then throw an error
* 🐛 bugs fixed and test cases updated for babel parser
* ♻️ code comments added
* 🐛 spell error rectified
* ♻️ failing test updated
* 🐛 push tests after make build
* Skip nullish-coalescing flow precedence tests
They're now incorrect
* ♻️ error message updated, binop priority of other logical operators +1 from ?? and
* ♻️ increaed the binOp for in and instanceOf, added logic to print the brackets in an ?? && || expression, test cases added
* 🐛 failing test fixed and comments updated
* ♻️ new lines added between tests
* ♻️ basic tests for checking the binOp of instanceOf, in and relational operators to be equal added
* ♻️ new lines added in between tests
2019-09-06 17:35:44 +02:00
Daniel Tschinder
4f0840ab88
Update dev dependencies and fix linting errors ( #10228 )
...
* chore: Uppate dev dependencies
* chore: Fix lint errors
* chore: Format options.json files
* chore: Fix stupid flow errors
* Update test262 whitelist
Seems test262-stream was updated and now these tests work.
2019-07-27 15:09:30 +02:00
Nicolò Ribaudo
ca67637da4
[@babel/parser] Add "allowUndeclaredExports" option ( #9864 )
...
Ref: https://github.com/babel/notes/blob/master/2019/04/09.md#export-changes-in-scope-pr-break-meteor-issue
2019-06-30 11:16:05 +02:00
Daniel Tschinder
85432e2c44
Remove guardedHandlers from ASTs ( #9979 )
2019-05-15 03:37:22 -07:00
Nicolò Ribaudo
cf3668779c
Always register global bindings as exportable ( #9865 )
2019-04-26 10:50:12 +02:00
Daniel Tschinder
444daf9224
Optimize parseBindingAtom code to get better error messages ( #9762 )
2019-03-25 14:23:39 -07:00
Nicolò Ribaudo
2201fd839b
Modules might be in loose mode when checking for undecl exports ( #9725 )
2019-03-20 17:57:12 -07:00
Erik Arvidsson
fba5655a44
Parenthesized expressions ( #8025 )
...
* Add parser createParenthesizedExpressions option …
When set to `true` we create `ParenthesizedExpression` nodes instead of
setting `extra.parenthesized`.
* Also update babel-parser.d.ts
2019-03-06 22:43:36 +01:00
Daniel Tschinder
29999007f6
Disallow escape sequences in contextual keywords ( #9618 )
...
* Disallow escape sequences in async
* Disallow escape sequences in get, set and async in class
* invalid escape tests
* Update whitelist
* tests for async in parens
* Add test for invalid newline between params and arrow
* Move canInsertSemilcolon() into shouldPArseAsyncArrow
2019-03-05 17:20:36 -08:00