186 Commits

Author SHA1 Message Date
Nicolò Ribaudo
143d159982
Create parser plugin "topLevelAwait" (#10449)
* Create parser plugin "topLevelAwait"

* Update test262 whitelist

* Update ts typings

* Fix "sourceType: unambiguous" with TLA

* Ambiguous tokens after await

* Update await %x(0)

* typo [skip ci]

* Typo [skip ci]

Co-Authored-By: Brian Ng <bng412@gmail.com>
2019-10-29 22:18:39 +01:00
Georgii Dolzhykov
63f9a3c946 rename assertsModifier to asserts (#10613)
see https://github.com/babel/babel/pull/10543#issuecomment-547571501
2019-10-29 16:25:42 -04:00
Tan Li Hau
38a3063111 add assertions signature for TypeScript (#10543)
* add asserts predicate

* fix flow

* babel-generator for typescript assertions

* babel-types for typescript assertions

* asserts modifier as boolean
2019-10-29 18:51:33 +01:00
Nicolò Ribaudo
4cd93ab5f3
[parser] Enable "exportNamespaceFrom" by default (#10521) 2019-10-29 18:44:32 +01:00
Nicolò Ribaudo
1d1fab4ea2
[parser] Add support for private fields in TypeScript (#10483)
* [parser] Add support for private fields in TypeScript

* Fix flow
2019-10-29 18:27:54 +01:00
gr
b6ef9689b2 [parser] Parse only modifiers of actual methods (#10594)
* Parse only modifiers of actual methods

* Throw question token if is used before the real name
2019-10-29 17:56:05 +01:00
Nicolò Ribaudo
78cd63d9cf
Fix invalid test layout in @babel/parser 2019-10-18 11:16:17 +02: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
piotr
5800fc97b3 [parser] Exception to 8 and 9 in tagged template (#10567) 2019-10-17 00:01:22 +02:00
Alejandro Sánchez
06313a6288 Allow duplicate __proto__ keys in patterns, simple case (#6705) (#10532)
* Allow duplicate __proto__ keys in patterns, simple case (#6705)

* Update test262 whitelist

* Rename checkDuplicatedProto's parameter and adjust type

* Store first __proto__ redefinition's position
2019-10-15 00:18:33 +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
Tan Li Hau
b0acfb24dd add scope to TSModuleDeclaration (#10119) 2019-10-08 19:35:40 +02:00
Nicolò Ribaudo
a219b6de7a
Disallow await inside async arrow params (#10469)
* Disallow await inside async arrow params

* Use -1 as default for awaitPos/yieldPos
2019-10-02 07:37:40 +02:00
Huáng Jùnliàng
fa5057f9fb Flow: interface identifier should be declared in the scope (#10220)
* fix: typo

* declare name for flow interface

* add test case for export overload function, typescript

* test: add test

Fixes #10044

* test: update test

* test(flow): add multiple declarations regression test

* re-enable flow test case

# Conflicts:
#	packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/def-site-variance/input.js
#	packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-declare-statements/input.js
#	packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-interfaces-module-and-script/input.js
#	packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-iterator/input.js

* test: disable two flow dupl-decl test

* fix: do not declare name for declare function until we figure out a better way

* test: duplicate declare function and function would not throw
2019-10-02 07:32:42 +02:00
Nicolò Ribaudo
80d99b4d4e
Do not allow member expressions to start async arrows (#10332)
* Do not allow member expressions to start async arrows

* Boolean -> boolean
2019-10-01 11:40:42 +02:00
Gonzalo Rodríguez
490798a26d [parser] Disallow numeric separators in legacy octal like inte… (#10493)
* Disallow numeric separators in lols

* Update whitelist

* Rename test

* Better syntax when checking
2019-09-25 01:32:50 +02:00
Nicolò Ribaudo
0e9502685a
[parser] Don't crash on comment after trailing comma after eli… (#10490) 2019-09-24 17:08:58 +02:00
Gonzalo Rodríguez
69d00dc5b0 [parser] Invalid NonOctal Decimal (#10467)
* Add test

* Add nonOctalDecimal verification

* Update regex and code style

* Refactor non octal detection

* Add numeric separator test

* Disallow numeric separators in non octals

* Update whitelist

* Better test naming

* Disallow numeric separators in non oct for all numbers

* Specific error above the general error

* Add test for invalid leading zero in num separator

* Add start position to error
2019-09-23 23:07:52 +02:00
Ivan Medina
f339d2d034 [parser] Disallow numeric separator in unicode scape sequences (#10468)
* [parser] Disallow numeric separator in unicode scape sequences (#10460)

* raise error only when numeric separator plugin is set

* Adds argument for checking numeric separator

* Fix condition for readability

* Add test for hex escape sequence and rephrase error message

* Remove exposure for allowNumSeparator in readHexChar method
2019-09-23 22:47:18 +02:00
Nicolò Ribaudo
3069747a81
Leave trailing comments after handling a possible trailing com… (#10445)
* Leave trailing comments aftre handling a possible trailing comma

* perf
2019-09-23 19:14:43 +02:00
Vivek Nayyar
b7333ea97a added check to disallow super.private variable access and test case added (#10472)
* 🚀 added check to disallow super.private variable access and test case added

* ♻️ change the other linting change back to how it was

* ♻️ change the other linting change back to how it was

* ♻️ added newline at the end test output.json file

* ♻️ changed the linting style to the way it was

* ♻️ updated error message, removed super private member access test cases from whitelist of flow and test 262 suite

* ♻️ added newline in output.json
2019-09-21 00:22:37 +02:00
Guy Waldman
9c1ad0a9f7 [parser] Disallow static fields named constructor (#10461)
* Disallow static fields named `constructor` in a class

    - Disallowed static fields named `constructor` in a class (previously only non-static were disallowed)
    - Updated the text for the error for one consolidated warning, for both static and non-static fields
    - Added a test
    - Updated an existing test in the `flow` test suite of the parser to reflect the parse error.
  Strangely, the test used to pass and started failing when inlining the `isNonstaticConstructor` method, without any changes.
  In that test, `constructor` was a field, so in theory it should never have passed.
  Would appreciate some feedback on this, as I'm not 100% sure if this is somehow related to Flow

* Update test262 whitelist

* Add comment and fix && operator
2019-09-18 01:19:45 +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
Huáng Jùnliàng
da0af5fd99 V8intrinsic syntax plugin (#10148)
* feat: v8intrinsic syntax plugin

Implement V8 Intrinsic Syntax Extension. Here we check the execution branch inside the parseSubscript to make sure the V8IntrinsicIdentifier is immediately followed by a call expression.

* feat: disable combining placeholders and v8intrisic

per https://github.com/babel/babel/issues/10104#issuecomment-506950969

* test: add more error cases

* refactor: parse v8 intrinsic in parseExprAtom

This approach is identical to V8’s implementation. Move the test cases as the behaviour changes.

* fix: plugin-name typo

* test: add yield-expression test case

* feat: require startsExpr on modulo for v8intrinsic

* perf: skip eof and braceR check as they must return false

* Print V8IntrinsicIdentifier

* feat: add v8intrinsic to parser typings

* Add generated type helpers

* fix: incorrect type definition

* fix: allow V8IntrinsicIdentifier to be callee
2019-09-06 17:43:19 +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
Shrey Banga
c0e3fa0081 Refactor trailing comma comment adjustment (#10380)
* Refactor trailing comment adjustment

Following up from https://github.com/babel/babel/pull/10369

- Unify the logic for adjusting trailing comments into a separate
  function
- Use it for all three cases, which fixes a bug for ObjectExpressions
  and CallExpressions
- Update tests to check for the fixed bug

* Fix tests

- Only modify trailingComments if necessary
- Update snapshots of a couple of affected tests

* Drop the underscore in adjustCommentsAfterTrailingComma_

* Handle ArrayPattern

* Handle ObjectPattern

* Handle import and export declarations

These have to be handled a bit differently, because the  node is visited after the  and before the declaration. So we intercept when we are going from the last specifier to the source node.

* Remove unnecessary check
2019-09-02 20:35:15 -04:00
Shrey Banga
8a775a32ba Retain trailing comments in array expressions (#10369)
* Retain trailing comments in array expressions

This is a proposed fix for https://github.com/babel/babel/issues/10368
with a simple test.

* Move lastElement in the block where it's used

* Test trailing comment after array expression

* Don't move comments after the array expression

* Retain trailing comment after the array expression
2019-08-28 14:03:37 -04:00
Justin Ridgewell
1664cce681
Don't allow JSXNamespacedName to chain (#10366)
Eg, `namespace:foo.bar` used to parse but is invalid in the [spec](https://facebook.github.io/jsx/).

Also, allow `JSXNamespacedName` in the `JSXOpeningElement`/`JSXClosingElement` builders.
2019-08-26 13:16:22 -04:00
Nicolò Ribaudo
15aa511b8e Do not register ambient classes to the TS scope (#10352) 2019-08-20 17:22:47 -05:00
Huáng Jùnliàng
75090f10e5 fix: assign comment to ObjectProperty only when inside an ObjectExpression (#10292)
Fixes #10230
2019-08-13 13:49:16 -05: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
Daniel Tschinder
d8da63c929 Use correct extension for typescript fixtures (#10014)
* Use correct extension for typescript fixtures

* Change transform fixtures

* Adjust editorconfig for ts files

* Rename new tests

Co-authored-by: Nicolò Ribaudo (nicolo.ribaudo@gmail.com)
2019-07-15 22:46:03 +02:00
Tan Li Hau
f588e4ec47 BigInt type for Flow (#10091)
* flow BigIntLiteralTypeAnnotation

* numericSeparator for flow test plugins

* fix flow tuple

* fix code review
2019-07-03 16:48:46 +02:00
James DiGioia
6b8a37c413 Implement f# pipeline in parser (#9450) 2019-06-30 12:53:22 +02:00
Nicolò Ribaudo
8bf9714d69
[legacy decorators] Allow decorating generator methods (#9912)
* [legacy decorators] Allow decorating generator methods

The old proposal used LeftHandSideExpression (instead of
AssignmentExpression) to satisfy this usecase:
e240cbc91a

* Update flow whitelist
2019-06-30 11:32:16 +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
Tan Li Hau
1d3f9815df fix import typeof in declare module (#10132) 2019-06-26 13:37:16 -05: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
Tan Li Hau
fdbbb743b6 flow - allow type parameter defaults in function declarations (#10084)
* flow - allow type parameter defaults in function declarations

* fix flow test

* add intern_comments option

* fix flow parser test

* remove allowdefault from flowParseTypeParameterDeclaration

* rename test cases
2019-06-15 12:31:12 +02:00
Daniel Tschinder
54d257c105 Fix location for optional params in arrow functions (#9998)
* Fix location with optional params in arrow functions

* add test

* Ensure rollup replaces NODE_ENV and create sourcemap in dev

* Ensure finishNod*() is never called twice on a node

* Fix check for already finished nodes
2019-05-21 18:53:13 +02:00
Matthew Robertson
9c06e4ed4d avoid exceptions for control flow (#9974)
* avoid exceptions for control flow

* review feedback: remove conditional because we know it is "<"

* drop tsTryParseTypeArguments method
2019-05-21 17:23:53 +02:00
Daniel Tschinder
85432e2c44
Remove guardedHandlers from ASTs (#9979) 2019-05-15 03:37:22 -07:00
Tan Li Hau
354666aa17 fix: allow shebang directive (#9922)
* fix: allow shebang directive

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

* chore: prettier
2019-05-07 16:22:25 +02:00
Nicolò Ribaudo
555d50a08c
Generate missing test output 2019-04-26 23:57:06 +02:00
Tan Li Hau
277a2620c6 allow directives and other comments before flow pragma (#9891) 2019-04-26 22:23:35 +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
Nicolò Ribaudo
cf3668779c
Always register global bindings as exportable (#9865) 2019-04-26 10:50:12 +02:00
Brian Ng
d7757f6d08 Fix TypeScript readonly error location (#9887) 2019-04-23 10:47:22 -04:00
Tan Li Hau
4198d91b89 Fix: remove constant context type check for TS (#9869) 2019-04-23 10:46:23 -04:00
Devon Govett
338853b5d3 Fix parsing typescript bodiless methods with the estree plugin also enabled (#9890) 2019-04-23 09:20:42 -05:00