35 Commits

Author SHA1 Message Date
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
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
Brian Ng
c0f6f0394d
Support ConditionalExpressions in dry-error-messages rule (#11917)
* Support ConditionalExpressions in dry-error-messages rule

* tests
2020-08-05 16:28:35 -04: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
Kai Cataldo
75c2300c28
Add @babel/eslint-plugin-development-internal (#11376)
* Add @babel/eslint-plugin-internal

* Add dry-error-messages rule

* Address feedback

* Enable new rule

* fix author field

* Fix errors

* Add readme

* Add example configuration

* Handle directories

* run make bootstrap

* More updates!

* Fix errors

* Update tests

* Fix CI race condition
2020-06-22 19:43:29 -04:00
Huáng Jùnliàng
b5c4a46a69
refactor: split locationParser into ParserErrors and error message (#11653) 2020-05-30 15:05:42 -04:00
Nicolò Ribaudo
31b361b736
Use ?. where it represents the intended semantics (#11512) 2020-05-09 23:31:50 +02:00
Rick Button
3ce7c2e394
Added support for record and tuple syntax. (#10865)
* Added support for record and tuple syntax.

This commit adds support for both the hash #{} and bar {||}
syntaxes to babel-parser, as well as adds the supporting
babel-plugin-syntax-record-and-tuple plugin to enable support
for the syntax. Does not include any transform for records and
tuples.

* typo

* added check to ensure recordAndTuple in babel-parser

* switched to syntaxType option instead of explicit entries for each record and tuple type

* switched to using recordAndTupleSyntaxType for generator options instead of adding to node

* added tests for generator option recordAndTupleSyntaxType

* added test for record and tuple bar syntax with flow typings

* added tests for invalid/missing recordAndTuple syntaxType parser option

* fixed flowcheck errors

* fix merge with class privates in tokenizer

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

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* improved recordAndTuple generator error message, added tests for invalid,missing options

* updated error messages for invalid parser syntaxType option

* updated error message

* added better error messages for when the recordAndTuple syntaxType is doesn't match the syntax used

* updated record and tuple support to use new error message templates

* added recordAndTuple to missing plugin helpers

* Fix linting

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-03-16 23:57:44 +01:00
Huáng Jùnliàng
e297e406ce
refactor: remove redundant contextDescription empty check (#11219) 2020-03-05 16:17:01 -05:00
Huáng Jùnliàng
21c9141872
Refactor: add parser message template (#11192)
* refactor: add raiseWithData method

* refactor: error message template

* fix missing plugin error structure

* fix flow errors

* refactor: use error message template in eslint plugin

* refacotr: use error message template in flow plugin

* refactor: use error message template in typescript plugin

* refactor: use error message template in jsx plugin

* address review comments

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

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-03-03 14:06:05 -05:00
Nicolò Ribaudo
8ab27c8ffe Wrap type-only class fields in flow comments (#11096)
* Wrap type-only class fields in flow comments

* Fix
2020-02-09 11:45:42 +01: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
Huáng Jùnliàng
9df70b4505
Duplicate __proto__ key should be allowed in object patterns (#10987)
* refactor: replace refShorthandDefaultPos by refExpressionErrors

* fix: duplicate __proto__ keys should be allowed in patterns

* docs: add comments for ExpressionErrors.doubleProto [ci-skip]

* test: add more test for coverage
2020-01-14 22:53:45 -05: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
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
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
gr
095f28a913 fix: Exclude catch clause from let identifier error (#10559)
* Exclude catch clause from let identifier error

* Disallow let binding based on parameter

* Add test

* Remove unused getter

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

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2019-10-17 09:30:36 +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
Pig Fang
11fa2461ce Disallow "let" as name at lexical bindings (#10099)
* Disallow "let" as name at lexical bindings

* Simplify

* Clean up
2019-06-18 23:17:00 +02:00
Nicolò Ribaudo
30d507c915
Add TS support to @babel/parser's Scope (#9766)
* [parser] Allow plugins to extend ScopeHandler

* Directly extend Scope

* Don't use new.target to get the ScopeHandler

* [parser] Add TS enum  support to the Scope

* Remove duplicated options in tests

* Fix

* Fix flow

* Rename tests

* Add tests

* Full typescript support in scope

* Remove BIND_SIMPLE_CATCH

SCOPE_SIMPLE_CATCH was used instead

* Export TS types

* Register function declarations

* Fix body-less functions and namespaces

1) Move this.scope.exit() for functions from parseFunctionBody to the callers.
    Otherwise the scope of body-less functions was never closed.
    Also, it is easier to track scope.exit() if it is near to scope.enter()
2) Register namespace ids for export

* Disallow redeclaration of enum with const enum
2019-04-26 14:19:53 +02:00
Daniel Tschinder
444daf9224
Optimize parseBindingAtom code to get better error messages (#9762) 2019-03-25 14:23:39 -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
98ab1b6428
Refactor parsing object members (#9607)
* Refactor parsing object members

* Ensure decorators on rest don’t swallow decorators silently

* Use hasPrecedingLineBreak

* Add test for async with linebreak

* Update flow whitelist
2019-02-28 11:42:12 -08:00
Daniel Tschinder
a7391144b3
Introduce scope tracking in the parser (#9493)
* Introduce scope tracking

* Fix tests

* Add new tests

* Remove constructor-super check from transform as it is now in parser

* Correctly handle class properties and class scope

* Fix duplicate name check

* Convert scope identifier storage to array

* Enter a new scope in typescript module blocks

* Add test for duplicate declaration

* Rename error for duplicate exports

* Treat class declarations as lexical declaration

* Update whitelist

* Add tests

* Fix scope tracking for function declarations

* Migrate try-catch duplicate error

* Fix test

* More tests

* One more test

* Make scope a separate class and fix review comments

* Do not allow new.target in top scope arrow function

* Correctly enter new scope for declare module and treat type aliases as lexical declarations

* Tests for typescript scope tracking to not mark type aliases as duplicate

* Fix flow scope tracking

* Remove ident from test names as redundant

* Add test case for var and function

* Improve error messages

* Improve literal regex
2019-02-25 11:04:52 -08:00
Justin Ridgewell
fc1ea7f496 Revert "Parenthesized expressions (#8025)"
This reverts commit dd8b700a2c4c975584c7b2ea43023aa275c16167.
2019-02-25 19:03:00 +01:00
Erik Arvidsson
dd8b700a2c 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-02-23 02:45:25 -05:00
Daniel Tschinder
9eb010da50
Unify reserved word checking and update error messages (#9402)
* Unify reserved word checking and update error messages

* Fix test
2019-01-31 19:02:32 -08:00
Daniel Tschinder
46ba5940c2
Make yield a contextual keyword (#9400) 2019-01-23 14:33:23 -08:00
Daniel Tschinder
25a8db2a29 perf: use normal equality check in stead of indexOf 2019-01-17 16:14:57 -08:00
Daniel Tschinder
48fd387779 perf: precalculate length 2019-01-17 16:14:56 -08:00
Nicolò Ribaudo
9764718c32
Disallow trailing comma after rest (#9311)
* Add new tests

* Use state instead of param and disallow comma in [...a,]=[]

* Unify error messages

* Object destructuring

* Update whitelist
2019-01-11 13:08:38 +01:00
Nicolò Ribaudo
856edbf95f
[flow] Allow type casts in array patterns inside arrow parameters (#9069) 2018-11-24 12:23:49 +01:00
Grigory Moroz
445b14148e Better error for disallowed trailing commas/parameters after rest elements (#9046)
* handle disordered rest parameter in function expressions

* remove spaces [lint]

* polish function parameters validation

* add test with arrow function and comma after rest parameter [babel-parser]
2018-11-21 07:49:36 +01:00
Daniel Tschinder
e3b2c1afff
fix: Do not allow TypeCastExpressions w/o parens (#8956) 2018-11-05 15:34:24 -08:00
Chaitanya Kumar Kamatham
daf0ca8680 Rename "babylon" to "@babel/parser" (#7937) 🎉 2018-05-19 00:03:05 -04:00