J. S. Choi
f4236f43a1
Extend hasPlugin to accept plugin-configuration array pairs ( #13982 )
...
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-12-02 23:17:51 +01: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
54c539ecc1
Refactor bindingProperty parsing ( #13929 )
...
* refactor: inline parseMaybePrivateName
* correct test case
* perf: fast exit in checkExpressionErrors
* refactor: add parseBindingProperty
* fix: private property with variance
* Update packages/babel-parser/src/parser/expression.js
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
* chore: update testcase
* refactor: remove refExpressionErrors for record/tuple
They are always non-ambiguous.
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-11-12 10:11:46 -05:00
Nicolò Ribaudo
62b2c5ebb9
Regenerate parser fixtures ( #13882 )
2021-10-24 18:12:10 +02:00
Huáng Jùnliàng
178d43ff17
Tokenize keywords-like identifier as new tokens ( #13769 )
...
* refactor: add more identifier token helpers
* refactor: explode tt.name into multiple tokens
* fix: disallow escape in interface keyword
* refactor: simplify isMaybeDefaultImport
* review comments
* refactor: avoid string comparison
2021-09-23 10:54:44 -04: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
Nicolò Ribaudo
9286cdb072
Re-enable disabled flow parser test ( #13661 )
2021-08-10 20:57:27 +02:00
doing-art
1229336fea
Fix parse error when using named import "as" with flow parser ( #13659 )
2021-08-10 20:55:21 +02:00
Nicolò Ribaudo
e721f61110
[flow] Fix parsing of arrows in conditional exprs in parens ( #13655 )
2021-08-10 20:46:38 +02:00
Nicolò Ribaudo
9d0aa1ec9d
Disallow <T>(a => b) when parsing Flow ( #13645 )
2021-08-10 19:09:23 +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
Tony Gorez
b0fe6bdbc3
chore(parser): add test to handle optional paramteter in async call ( #13504 )
...
* chore(parser): add test to handle optional paramteter in async call
* chore(parser): add flow test
* chore(parser): add ts test
2021-06-23 11:11:06 -04: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
Nicolò Ribaudo
1341e560ff
Skip flow/typecasts/3 test on Node.js 6 ( #13382 )
2021-05-27 09:20:45 -05:00
Huáng Jùnliàng
0d0950f341
fix: preserve tokensLength in tryParse ( #13326 )
...
* fix: preserve tokensLength in tryParse
* Apply suggestions from code review
Co-authored-by: Brian Ng <bng412@gmail.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
2021-05-17 15:32:12 -04:00
George Zahariev
8433cd0c05
Support parsing Flow's Optional Indexed Access Types ( #13224 )
2021-04-28 18:21:31 +02:00
Nicolò Ribaudo
57daba85aa
Parse string export names by default (moduleStringNames) ( #13195 )
...
* Parse string epxort names by default (`moduleStringNames`)
* Remove remaining references
2021-04-28 18:21:31 +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
2521c666f7
Add internal ESLint rule for consistent parser error messages ( #13130 )
2021-04-28 18:21:31 +02:00
Sosuke Suzuki
f8aa32f767
Support parsing Flow's Indexed Access Types ( #13053 )
2021-04-28 18:21:31 +02:00
Sosuke Suzuki
b62fc3d44f
babel-parser(flow): Set this property to null for FunctionTypeAnnotation without parens ( #12930 )
...
* Add null property to FunctionTypeAnnotation without parens
* Update tests
* Update tests
2021-03-01 09:15:43 -05:00
George Zahariev
5b99b8f221
Flow Enums with unknown members support ( #12193 )
...
* Flow Enums with unknown members parsing
* Updates after rebase
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2021-02-21 18:42:23 +01:00
Daniel Sainati
16e9f1c8e5
Support Flow this parameter annotations ( #12234 )
2021-02-21 17:44:27 +01:00
Nicolò Ribaudo
c07185207c
[parser] Fix scope handling of Flow declared functions ( #12735 )
2021-02-10 21:07:14 +01: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
Sosuke Suzuki
f5bd9f2013
Allows the interface to be used as an Identifier for flow plugin ( #12254 )
2020-10-26 08:50:57 -05:00
Sosuke Suzuki
f1bc314c79
Fix parsing of imports with module string name in flow plugin ( #12224 )
2020-10-20 23:46:12 +02:00
Brian Ng
84ea6e4501
Throw error on invalid flow async generic arrow syntax ( #11979 )
2020-08-19 16:11:17 -05:00
Brian Ng
96cc8292b7
Fix parsing type casted generic flow arrow exprs ( #11955 )
2020-08-19 14:15:01 -05:00
Huáng Jùnliàng
a4ebe29b3f
Parser refactoring ( #11871 )
...
* refactor: parseMaybeUnary => parseUnary
* refactor: extract shouldExitDescending method
* refactor: add parseUpdate
* refactor: avoid comparing with hardcoded token value
* refactor: add ParseNewOrNewTarget
* refactor: add parseCoverCallAndAsyncArrowHead
* add parseBind
* refactor: polish parseTaggedTemplateExpression interface
* refactor: add parseMember method
* refactor: add parseSuper method
* refactor: add parseAsyncArrowUnaryFunction method
* fix: disallow line break before async binding arrow
* refactor: simplify tt.name logic
* refactor: add parseDo method
* refactor: misc
* refactor: rename parseObjectMember by parsePropertyDefinition
* refactor: unify set/get/async keyword parsing in ObjectMethod
* refactor: misc
* refactor: add parseArrayLike method
* refactor: move fsharp epilogure and prologue inside parseObjectLike
* fixup
* refactor: rename parseFunctionExpression to parseFunctionOrFunctionSent
* refactor: remove redundant logic
* refactor: rename parseClassPropertyName by parseClassElementName
* refactor: avoid unecessary lookahead when parsing tt._export
* fix: export-default-from should support escaped async as export binding
* address review comments
* parseUnary -> parseMaybeUnary
2020-07-31 20:36:04 -04:00
Vivek Nayyar
66b86e088c
added basic support for module attributes and tests updated ( #10962 )
...
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-05-25 01:26:28 +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
fba64d439d
fix: disallow expression after binding identifier of ( #11355 )
2020-04-21 15:12:23 -04:00
Huáng Jùnliàng
a466f9c310
fix: report missing plugins on type exports ( #11417 )
...
* fix: report missing plugins on type exports
* nit refactors
* Update packages/babel-parser/src/parser/statement.js [skip ci]
2020-04-14 15:23:54 +02: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
Nicolò Ribaudo
5c1a8210da
Implement support for declare on class fields with Flow ( #11178 )
...
* Add parser support for Flow declare fields
* Add generator test
* Add "allowDeclareFields" option to flow-strip-types
* Add test
* Update error messages
* More tests
2020-03-16 23:08:26 +01:00
Brian Ng
4f394e30d2
Add support for flow's SymbolTypeAnnotation ( #11077 )
2020-03-16 23:00:17 +01:00
jack
5f807ae45b
Enable optional chaining by default in @babel/parser ( #10817 )
2020-01-10 03:09:39 +01:00
Huáng Jùnliàng
30449fe05d
Refactor parseSubscript ( #10937 )
...
* refactor: unify optionalMemberExpression generation
* test: add optional calls invalid typecasts
* fix: do not parse async arrow when call is optional
* test: update test fixtures
2019-12-30 16:11:39 -05:00
Alex Lewis
bb6cc61979
fix(optional chaining): Optional delete returns true with nullish base ( #10806 )
...
Per issue 10805, the return value when using delete on a nullish base is
currently undefined. The correct return type should be true.
2019-12-04 12:56:25 +01:00
George Zahariev
01d6d6dd3b
Flow enums: fix enum body location ( #10737 )
2019-11-19 22:46:08 -06:00
Brian Ng
a502d88043
Fix some incorrect typeof parsing in flow ( #10657 )
2019-11-18 19:22:27 +01:00
Kai Cataldo
a6d134804a
Unify build step for ESLint packages ( #10723 )
2019-11-16 10:15:15 +01:00
Nicolò Ribaudo
9082e68d6f
Parse arrows with params annotations in conditional expressions ( #10669 )
2019-11-07 02:18:36 +03: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
George Zahariev
ec3345bb57
Flow enums parsing ( #10344 )
...
* Flow enums parsing
* Parse exporting enums
* Enums parsing remove lookahead, other improvements
* Enums: add EnumBody and EnumMember aliases, change boolean members to use BooleaLiteral value
* Fix enum member init flow type, now that boolean members have a BooleanLiteral value
* Flow enums: use contextual utils, change members length checks to use logic operators, remove reserved word logic modification
* Flow enums: remove unnecessary code in generator, fix error message
2019-10-29 22:55:12 +01:00
Nicolò Ribaudo
4cd93ab5f3
[parser] Enable "exportNamespaceFrom" by default ( #10521 )
2019-10-29 18:44:32 +01: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