176 Commits

Author SHA1 Message Date
Nicolò Ribaudo
a254ea38a4
Enable ergonomic brand checks (#priv in) by default (#13554)
* Enable ergonomic brand checks by default in `@babel/parser`

* Enable ergonomic brand checks by default in `preset-env`

* Fix error position

* Update Babel 8 tests
2021-08-03 23:02:17 +02:00
Huáng Jùnliàng
d3a7cd5e8d
Replace generic __clone call by specific methods (#13611)
* update benchmark babel parser version

* perf: replace generic __clone by specific methods

baseline 256 length-1 named export: 4_704 ops/sec ±1.59% (0.213ms)
baseline 512 length-1 named export: 2_426 ops/sec ±0.52% (0.412ms)
baseline 1024 length-1 named export: 1_118 ops/sec ±1.23% (0.895ms)
baseline 2048 length-1 named export: 556 ops/sec ±0.77% (1.799ms)
current 256 length-1 named export: 7_073 ops/sec ±33.67% (0.141ms)
current 512 length-1 named export: 4_441 ops/sec ±0.79% (0.225ms)
current 1024 length-1 named export: 2_142 ops/sec ±1.09% (0.467ms)
current 2048 length-1 named export: 943 ops/sec ±2.12% (1.06ms)

* breaking: remove Node#__clone in Babel 8

* test: use t.cloneNode
2021-07-30 22:19:35 +02:00
Nicolò Ribaudo
4a56387330
ts: Check if param is assignable when parsing arrow return type (#13581) 2021-07-26 17:58:10 +02:00
Nicholas Eveland
2c6db56696
Allow module block to start a member expression (#13573)
* Accept module in primaryExpression

* Add module blocks to primaryExpression

* Fix package.json

* Fix yarn.lock

* Fix yarn.lock

* Remove package.tgz file
2021-07-19 17:29:23 -04:00
Huáng Jùnliàng
6e57617138
Fix await binding error within static block (#13088)
* fix: allow await within SCOPE_FUNCTION under static block

* perf: scan scopeStack for once

* add new test case

* chore: update allowlist
2021-07-16 10:35:19 -04: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
8a3e0fd960
Async do expression should start at async (#13534) 2021-07-07 00:09:34 -04:00
Huáng Jùnliàng
5145c98a73
Simplify token context (#13450)
* refactor: unify tc.brace and tc.templateQuasi

* refactor: remove unused context check

* perf: reduce arrayPrototype call and hoist variables
2021-06-21 10:51:00 -04:00
Tony Gorez
101249f3aa
refactor(parser): remove refNeedsArrowPos (#13419)
* fix(parser:expression): remove refNeedsArrowPos in parseExprListItem

* feat: use refExpressionErrors to catch optional parameters

* feat: delete useless refNeedArrowPos

* fix: forgotten deletion

* fix: lint and factorize

* fix: delete useless comment

* fix: review corrections

* fix: review corrections pt2

* fix: review correction pt2

* fix: nit correction

* fix: update types

* Update packages/babel-parser/src/parser/util.js

* fix: add invariant comment in flow and ts file

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-06-19 10:40:52 +02:00
Huáng Jùnliàng
b9c1884a58
Reduce exprAllowed usage (#13431) 2021-06-09 16:36:09 +02:00
Tony Gorez
a0369fdbfa
fix: throw when async() call param is object with assignement (#13410) 2021-06-03 16:12:15 +02:00
Huáng Jùnliàng
cbad50ac1d
Faster checkReservedWord (#13386)
* perf: faster parser scope check

* perf: early return for identifier length > 10

* perf: early return for normal identifier names

* chore: add benchmark

* Update packages/babel-parser/src/parser/expression.js
2021-06-01 08:42:23 -04:00
Huáng Jùnliàng
461ba2531a
refactor: add parse*Literal parser routines (#13333)
* refactor: simplify parseLiteral interface

* refactor: extract specific methods on parsing literals

* fix: avoid StringLiteral type comparison

* add test cases

* fix: remove redundant node

* Update packages/babel-parser/src/plugins/flow/index.js

Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>

* update test fixtures

* fix: refine parseLiteral typings

Co-authored-by: Federico Ciardi <fed.ciardi@gmail.com>
2021-05-19 16:00:24 -04:00
Huáng Jùnliàng
b3d35cd412
[Babel 8]: remove module attributes parser/generator support (#13308)
* breaking: remove support of moduleAttributes

* Update packages/babel-parser/src/plugin-utils.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* chore: remove todo comments

* make prettier happy

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-05-14 09:55:40 -04: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
Stuart Cook
fa01fbe052
Parse for await (async of ...) (#13244) 2021-05-01 18:00:21 +02:00
Huáng Jùnliàng
28d7442aae Parse async do expressions (#13043)
* parse async do expressions

* add test cases

* update test fixtures

* chore: add syntax-async-do-expressions

* generater support

* fix: do not transform async do expressions

* chore: add asyncDoExpressions to missing plugin helpers

* update ast types

* add more test cases

* throw when asyncDoExpressions is enabled but not doExpressions

* avoid add parentheses for async do expressions

* address review comments

* chore: update parser typings
2021-04-28 18:26:01 +02:00
Huáng Jùnliàng
ceaab0bae7 Parse class fields and private methods by default (#13175)
* feat: materialize class features

* chore: move testcases to es2022

* chore: update test fixtures

* chore: remove classPr\w+ from options.json

* chore: remove empty options.json

* update flow test allowlist

* update typescript allowlist
2021-04-28 18:21:31 +02:00
Sosuke Suzuki
0ee98139a6 Introduce parser error codes (#13033) 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
Huáng Jùnliàng
efdca01409
fix: add tokens when tokens: true is passed to parseExpression (#12939) 2021-03-01 14:09:56 -05:00
Huáng Jùnliàng
03d7911be6
Implement class features in estree (#12370)
Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
2021-02-21 20:12:12 +01:00
Sosuke Suzuki
9c567baa9b
Parse JS Module Blocks proposal (#12469) 2021-02-21 20:08:20 +01:00
Nicolò Ribaudo
e735266dee
Avoid importing .json files (#12759)
* Avoid importing `.json` files

* Use ESold in babel.config.json

* Use `import/extensions` eslint plugin
2021-02-05 23:34:36 +01:00
Huáng Jùnliàng
ecfe20395b
spec: disable await binding identifier within static block (#12661) 2021-02-01 21:55:43 +01:00
Huáng Jùnliàng
108564fdad
refactor: raise AwaitNotInAsyncContext when an AwaitExpression will be parsed (#12716)
* refactor: raise AwaitNotInAsyncContext when an AwaitExpression will be parsed

* tweak logic

* early exit when errors are before thrown error position

* fix: always return true in assert.throws callback

See https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message

* update test fixtures

* fix flow error
2021-02-01 10:46:43 -05:00
Sosuke Suzuki
8fcba6eb55
Raise recoverable error for await expressions in sync functions (#12520) 2021-01-24 01:45:27 +01:00
Huáng Jùnliàng
8478027d1a
Make sure babel parser throws exactly same recoverable errors when estree plugin is enabled (#12375)
* refactor: introduce isPrivateName and getPrivateNameSV

* feat: check recoverable errors on estree-throw

* fix: pass through all params of parseBlockBody

* fix: set bigInt to null when invalid bigInt value is parsed

e.g. 0.1n

* fix: use string literal value in error message

When estree plugin is enabled, stringLiteral#extra.raw is not accessible. Use StringLiteral#value instead.

* refactor: introduce hasPropertyAsPrivateName

* fix: adapt to ChainExpression

* fix: port checkLVal early return for method in object pattern

* fix: throw new a?.() on estree

* fix: early return for __proto__ in accessors

* fix: test record element via isObjectProperty

* fix: pass through isLHS in toAssignable

* refactor: introduce isObjectMethod methods
2020-12-03 08:36:54 +00:00
Huáng Jùnliàng
89f3247e32
refactor: simplify isAwaitAllowed (#12398) 2020-11-25 13:49:35 -05:00
Huáng Jùnliàng
b564368d6e
refactor: reorder checkLVal parameters (#12346)
* refactor: reorder checkLVal parameters

* update allow list

* Apply suggestions from code review
2020-11-17 09:07:32 -05: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
Huáng Jùnliàng
5b48f40a08
Polish parser errors (#12258)
* polish: update AwaitNotInAsyncFunction message

* polish: update YieldInParameter error message

* Apply suggestions from code review

Co-authored-by: Brian Ng <bng412@gmail.com>

* update test fixtures

Co-authored-by: Brian Ng <bng412@gmail.com>
2020-10-26 20:55:04 -04:00
Huáng Jùnliàng
2782a549e9
Refactor yield await classification (#12230)
* fix: incomplete ParamKind declaration

* refactor: add expression scope handler

* test: update test262 allowlist

* chore: cleanup

* fix: push expression scope for function body

* fix: push new expression scope for initializer and static block

* test: add more test cases

* fix flow error

* refactor: remove unecessary expression scope

* fix: parameter initializer error should not cross expression scope boundary

* chore: cleanup outdated comments

* fix: do not record async arrow error on ParameterDeclaration

* Update packages/babel-parser/src/util/expression-scope.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* polish: clear ancestry declaration error on validate

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-10-26 11:42:02 -04:00
Brian Ng
c00bb14f79
[ts] Error on invalid type casts in JSX (#12221) 2020-10-23 08:09:35 -05:00
Nicolò Ribaudo
4fe8c3acc5
Revert "Fix: check if param is assignable when parsing arrow return type annotation" (#12198)
This reverts commit 84987a00e632e65bdafdf7f70df46ded7fb083c8.
2020-10-16 08:16:37 +02:00
Nicolò Ribaudo
84987a00e6
Reland "Fix: check if param is assignable when parsing arrow return type annotation" (#12183)
* Reland "Fix: check if param is assignable when parsing arrow return type annotation"

This reverts commit 91a7a64b4b0c30ab1fdfbb12f77522afa2285ec4.

* Mark `RestElement` as assignable
2020-10-15 11:32:37 -04:00
Nicolò Ribaudo
91a7a64b4b
Revert "Fix: check if param is assignable when parsing arrow return type annotation" (#12173)
This reverts commit 136e6301cbfa9448cfb20396f82f93f0d3e10c12.
2020-10-14 21:42:05 +02:00
Sven Sauleau
af8e0facc1
Parse import-assertions (#12139)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-10-14 21:18:16 +02:00
Huáng Jùnliàng
3ccca88178 Parse class static block (#12079)
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-10-14 21:16:24 +02:00
Nicolò Ribaudo
3fd963fdc8
[ts] Add support for template interpolations in types (#12131)
Co-authored-by: Brian Ng <bng412@gmail.com>
2020-10-14 20:15:42 +02:00
Huáng Jùnliàng
136e6301cb
Check if param is assignable when parsing arrow return type (#11992) 2020-10-14 20:09:48 +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
2c60595342
fix: ExpressionBody should respect [In] parameter (#11931) 2020-08-26 13:24:44 -04:00
Brian Ng
941f610275
Set generator to true during error recovery of accessor (#11987) 2020-08-21 14:37:52 -05:00
Huáng Jùnliàng
df9ee2c7cd
Simplify tokenizer update context (#11944)
* replace lineBreak.test by hasPrecedingLingBreak

* refactor: simplify updateContext
2020-08-11 13:43:03 -04:00
Huáng Jùnliàng
4bb1e164da
Refactor [In] production parameter tracking (#11930)
* refactor: track [In] parameter in prodParam

* Apply suggestions from code review
2020-08-10 07:32:38 -04:00
Huáng Jùnliàng
a827ca41f3
refactor: simplify smart pipeline parsing (#11919) 2020-08-05 21:15:42 -04:00
Huáng Jùnliàng
cd577eedfd
refactor: add recoverable error on accessorIsGenerator (#11921)
* refactor: add recoverable error on accessorIsGenerator

* Update packages/babel-parser/src/parser/error-message.js

Co-authored-by: Brian Ng <bng412@gmail.com>

* Apply suggestions from code review

Co-authored-by: Brian Ng <bng412@gmail.com>
2020-08-05 17:52:13 -04:00
Huáng Jùnliàng
50b3262063
refactor: avoid unnecessary property access (#11918)
* refactor: avoid unnecessary property access

* refactor: `else` is redundant because keyName is const
2020-08-05 15:39:45 -04:00