diff --git a/.circleci/config.yml b/.circleci/config.yml index 7fe155f9f564..cb085191b714 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ jobs: build: working_directory: ~/babel docker: - - image: circleci/node:10 + - image: circleci/node:12 steps: - checkout - restore-cache: *restore-yarn-cache @@ -42,7 +42,7 @@ jobs: - run: yarn --version - run: make test-ci-coverage # Builds babel-standalone with the regular Babel config - - run: make build + - run: IS_PUBLISH=true make build # test-ci-coverage doesn't test babel-standalone, as trying to gather coverage # data for a JS file that's several megabytes large is bound to fail. Here, # we just run the babel-standalone test separately. diff --git a/.editorconfig b/.editorconfig index ba48528bbf4b..e86321667115 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,9 +6,12 @@ charset = utf-8 trim_trailing_whitespace = true end_of_line = lf -[*.{js,json}] +[*.{js,json,ts,tsx}] indent_style = space indent_size = 2 +[Makefile] +indent_style = tab + [*.{md,markdown}] trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore index 18e74eafba27..092fbbb802cd 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,8 +5,8 @@ package.json lerna.json packages/babel-runtime !packages/babel-plugin-transform-runtime/scripts -!packages/babel-runtime-corejs2/core-js.js packages/babel-runtime-corejs2 +packages/babel-runtime-corejs3 packages/*/node_modules packages/*/lib packages/*/dist diff --git a/.eslintrc.json b/.eslintrc.json index d26b40aa6c5d..a59dc0d9e2dd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "root": true, + "plugins": ["prettier", "@babel/development", "import"], "extends": "babel", - "plugins": ["local-rules", "prettier"], "rules": { "prettier/prettier": "error" }, @@ -12,8 +12,10 @@ { "files": ["packages/*/src/**/*.js", "codemods/*/src/**/*.js"], "rules": { - "local-rules/no-undefined-identifier": "error", - "local-rules/no-deprecated-clone": "error" + "@babel/development/no-undefined-identifier": "error", + "@babel/development/no-deprecated-clone": "error", + "import/no-extraneous-dependencies": "error", + "guard-for-in": "error" } }, { @@ -26,6 +28,14 @@ "env": { "jest": true } + }, + { + "files": ["packages/babel-plugin-*/src/index.js"], + "excludedFiles": ["packages/babel-plugin-transform-regenerator/**/*.js"], + "rules": { + "@babel/development/plugin-name": "error", + "eqeqeq": ["error", "always", { "null": "ignore" }] + } } ] } diff --git a/.flowconfig b/.flowconfig index 9aacaf35ebdd..694811e55964 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,11 +1,10 @@ [ignore] -.*/build/.* -.*/packages/.*/lib -.*/packages/.*/test -.*/codemods/.*/lib -.*/codemods/.*/test -.*/node_modules/conventional-changelog-core/ -.*/node_modules/module-deps/ +/build/.* +/packages/.*/lib +/packages/.*/test +/codemods/.*/lib +/codemods/.*/test +/node_modules/module-deps/ [include] packages/*/src diff --git a/.github/CHANGELOG-6to5.md b/.github/CHANGELOG-6to5.md index 6005a2db3ab0..45afe2368d8d 100644 --- a/.github/CHANGELOG-6to5.md +++ b/.github/CHANGELOG-6to5.md @@ -84,7 +84,7 @@ * More performance improvements. * Parsing is now ~30% faster thanks to [marijnh/acorn@7264bc0178e7e6af7cfe02e9e0c6b26ee0e6007f](https://github.com/marijnh/acorn/commit/7264bc0178e7e6af7cfe02e9e0c6b26ee0e6007f). * **New Feature** - * Optional `es6.blockScopingTDZ` is now completely functional and handles all edgecases. + * Optional `es6.blockScopingTDZ` is now completely functional and handles all edge cases. * `super` in object literals. * Tail call optimisation. Thanks [@RReverser](https://github.com/RReverser)! @@ -474,7 +474,7 @@ * **Polish** * Rest parameters now allocate the array before populating. * **Internal** - * `for...in` loops have been changed to optimized `for` loops - better performance and no enumeration of protoype keys. + * `for...in` loops have been changed to optimized `for` loops - better performance and no enumeration of prototype keys. * Parts of the code generator have now been optimized thanks to [gaearon](https://github.com/gaearon). ## 2.12.3 @@ -643,7 +643,7 @@ * **Bug Fix** * Better handling of number literal property keys. - * Handle `NewExpression` paren insertion edegcases better. + * Handle `NewExpression` paren insertion edge cases better. * **Internal** * Fix incorrect AST node `identifier("this")`. * Better `toIdentifier` method that handles reserved words. @@ -850,7 +850,7 @@ ## 1.14.10 - * Fix let scoping unneccesary override. + * Fix let scoping unnecessary override. ## 1.14.6 @@ -973,7 +973,7 @@ ## 1.12.21 - * Fix unneccesary let scoping replacement. + * Fix unnecessary let scoping replacement. * Add `commonInterop` module formatter. Thanks [@Naddiseo](https://github.com/Naddiseo). * Fix `return` outside of function body bug. Thanks [@brentburg](https://github.com/brentburg). * Add more flexible option types. @@ -1020,7 +1020,7 @@ ## 1.12.12 - * Make scope tracker more reliable to handle all edgecases. + * Make scope tracker more reliable to handle all edge cases. ## 1.12.11 diff --git a/.github/CHANGELOG-v4.md b/.github/CHANGELOG-v4.md index 70ba225ffaef..7a06b2c93eee 100644 --- a/.github/CHANGELOG-v4.md +++ b/.github/CHANGELOG-v4.md @@ -127,7 +127,7 @@ ## 4.6.4 * **Bug Fix** - * Fix `ForOfStatement` not proplery inheriting labels. + * Fix `ForOfStatement` not properly inheriting labels. * When in closure mode in block scoping transformer, properly check for variable shadowing. * **New Feature** * New `utility.inlineEnvironmentVariables` and `utility.inlineExpression` transformers. @@ -153,7 +153,7 @@ * **Spec Compliancy** * `for...of` now outputs in a lengthy `try...catch` this is to ensure spec compliancy in regards to iterator returns and abrupt completions. See [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and [babel/babel/#838](https://github.com/babel/babel/issues/838) for more information. * **Polish** - * Rest parameters that are only refered to via number properties on member expressions are desugared into a direct `arguments` reference. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)! + * Rest parameters that are only referred to via number properties on member expressions are desugared into a direct `arguments` reference. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)! * `$ babel` no longer exits on syntax errors. * **Internal** * Upgrade `browserify`. diff --git a/.github/CHANGELOG-v5.md b/.github/CHANGELOG-v5.md index 04dfb5218d18..64d4999d58df 100644 --- a/.github/CHANGELOG-v5.md +++ b/.github/CHANGELOG-v5.md @@ -262,8 +262,8 @@ Issues with publish process. * Register labels as bindings to fix undeclared variable checks. * **Polish** * Remove unnecessary string binary expressions when transforming template literals. - * Support module live bindings in arbitary positions not in Program statement position. - * Throw error when attemping to replace a `Program` root node with another node not of type `Program`. + * Support module live bindings in arbitrary positions not in Program statement position. + * Throw error when attempting to replace a `Program` root node with another node not of type `Program`. * Optimise rest parameters in spread element position and allocate rest array at the earliest common ancestor of all references. * Generate original number representation when value was not changed. * Check for invalid binding identifiers when generating inferred method names. @@ -543,12 +543,12 @@ Issues with publish process. * **Internal** * Removed native inheritance support from classes. * Added `replaceWithSourceString` path API. - * Split up `es3.propertyLiterals` and `es3.memberExpressionLiterals` transformers to `minfication.propertyLiterals` and `es3.memberExpressionLiterals`. + * Split up `es3.propertyLiterals` and `es3.memberExpressionLiterals` transformers to `minification.propertyLiterals` and `es3.memberExpressionLiterals`. ## 5.2.6 * **Internal** - * Fix transformer aliases being accidently set as deprecated ones. + * Fix transformer aliases being accidentally set as deprecated ones. * Expose `Pipeline` as `TransformerPipeline` instead. ## 5.2.5 @@ -824,10 +824,10 @@ Issues with publish process. * Save register cache on tick instead of `SIGINT`. * Enable strict mode on babel-node eval flag. * **Bug Fixes** - * Add support for live bindings. This change also increases the reliablity of export specifier renaming. + * Add support for live bindings. This change also increases the reliability of export specifier renaming. * Add support for super update and non equals assignment expressions. * Rename shadow constructor binding in classes. - * Seed next iteration bindings with previous fresh bindings when reassinging loop block scoped variables. + * Seed next iteration bindings with previous fresh bindings when reassigning loop block scoped variables. * Fix new expression spread referencing the wrong constructor. * Call `resolveModuleSource` on dynamic imports. * Added `param` to list of duplicate declaration kinds. @@ -836,4 +836,3 @@ Issues with publish process. * ES7 Abstract References have been removed. * Experimental option has been removed in favor of a stage option. * Rename `returnUsedHelpers` to `metadataUsedHelpers`. - \ No newline at end of file diff --git a/.github/CHANGELOG-v6.md b/.github/CHANGELOG-v6.md index bed990b56e9e..92d9173db5b8 100644 --- a/.github/CHANGELOG-v6.md +++ b/.github/CHANGELOG-v6.md @@ -19,7 +19,7 @@ ## 6.26.0 (2017-08-16) -> Backports for some folks (also other's when we accidently merged PRs from both 6.x/master) +> Backports for some folks (also other's when we accidentally merged PRs from both 6.x/master) > Lesson learned: just use `master` and backport on another branch. #### :eyeglasses: Spec Compliancy @@ -1767,7 +1767,7 @@ typeof Symbol.prototype === 'object' * [#3456](https://github.com/babel/babel/pull/3456) Use the real sourcemap API and handle input sourcemaps - Fixes [#7259](https://github.com/babel/babel/issues/7259). ([@loganfsmyth](https://github.com/loganfsmyth)) * [#4507](https://github.com/babel/babel/pull/4507) Only set options in cli if different from default. ([@danez](https://github.com/danez)) -Fix an issue with defaults not being overidden. This was causing options like `comments: false` not to work correctly. +Fix an issue with defaults not being overridden. This was causing options like `comments: false` not to work correctly. * [#4508](https://github.com/babel/babel/pull/4508) Support custom ports for V8 --inspect. ([@andykant](https://github.com/andykant)) * [#4562](https://github.com/babel/babel/pull/4562) Fixes [#2299](https://github.com/babel/babel/issues/2299): Prevent REPL from printing implicit 'use strict'. ([@hzoo](https://github.com/hzoo)) @@ -2084,7 +2084,7 @@ Also added more tests and will update Babel to use the new preset options after ## v6.13.1 (2016-08-04) -We had a regression in our new babel-preset-es2015@6.13.0 that made it unexpectedly backward-incompatible. This release introduces a new alternative plugin-options approach that is uglier but supports backward-compatiblity. Ideally new plugins would use the new `module.exports = function(babel, options){ }` approach and simple skip supporting `babel-core@<6.13.x`. +We had a regression in our new babel-preset-es2015@6.13.0 that made it unexpectedly backward-incompatible. This release introduces a new alternative plugin-options approach that is uglier but supports backward-compatibility. Ideally new plugins would use the new `module.exports = function(babel, options){ }` approach and simple skip supporting `babel-core@<6.13.x`. #### Bug Fix * `babel-core`, `babel-preset-es2015` @@ -2092,7 +2092,7 @@ We had a regression in our new babel-preset-es2015@6.13.0 that made it unexpecte ## v6.13.0 (2016-08-04) -> Since the last release we've created https://github.com/babel/notes to track discussions on our slack and high level features/changes that could be added - definetely check it out if you're interested in Babel's development! +> Since the last release we've created https://github.com/babel/notes to track discussions on our slack and high level features/changes that could be added - definitely check it out if you're interested in Babel's development! Some small but very important additions in this release: @@ -3817,7 +3817,7 @@ Thanks to @samwgoldman for all the new flow support! * **New Feature** * Add support for `function.sent`. * **Internal** - * Bump `invariant` depenency version. + * Bump `invariant` dependency version. * **Polish** * Infer filename from the base directory when resolving plugins and presets. * Allow JSX pragma to be specified in line comments. @@ -3887,7 +3887,7 @@ Thanks to @samwgoldman for all the new flow support! ## 6.1.2 * **Bug Fix** - * Fix bug where the parser wouldn't allow typed annotated default parametesr in arrow functions. + * Fix bug where the parser wouldn't allow typed annotated default parameters in arrow functions. * Add existence check to `NodePath#has` to ensure safeness when making comparisons. * Protect against replacing a class expression with a name inferred version that would result in it never being transformed. @@ -3976,7 +3976,7 @@ Thanks to @samwgoldman for all the new flow support! * Fix SystemJS module formatter exporting function parameters. * Ensure that invalid identifier JSX attribute keys are quoted when transforming to calls. * Fix ES3 property literal plugin. - * Fix parameters after defaults in arrow functions refering to the wrong `arguments`. + * Fix parameters after defaults in arrow functions referring to the wrong `arguments`. ## 6.0.13 diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 13ef44cc2688..344922e4702c 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,6 +1,9 @@ --- -name: 🐛 Bug Report -about: If something isn't working as expected 🤔. +name: "\U0001F41B Bug Report" +about: "If something isn't working as expected \U0001F914." +title: '' +labels: 'i: bug, i: needs triage' +assignees: '' --- @@ -31,7 +34,7 @@ A clear and concise description of what you expected to happen (or code). - Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34] - Node/npm version: [e.g. Node 8/npm 5] - OS: [e.g. OSX 10.13.4, Windows 10] -- Monorepo [e.g. yes/no/Lerna] +- Monorepo: [e.g. yes/no/Lerna] - How you are using Babel: [e.g. `cli`, `register`, `loader`] **Possible Solution** diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index fdbe35c81ed3..b9c82542ff8c 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -1,6 +1,9 @@ --- -name: 🚀 Feature Request -about: I have a suggestion (and may want to implement it 🙂)! +name: "\U0001F680 Feature Request" +about: "I have a suggestion (and may want to implement it \U0001F642)!" +title: '' +labels: 'i: enhancement, i: needs triage' +assignees: '' --- diff --git a/.github/ISSUE_TEMPLATE/Regression-v7.md b/.github/ISSUE_TEMPLATE/Regression-v7.md index cf839d261cbb..a700b90ba073 100644 --- a/.github/ISSUE_TEMPLATE/Regression-v7.md +++ b/.github/ISSUE_TEMPLATE/Regression-v7.md @@ -1,12 +1,16 @@ --- -name: 💥 v7 Regression -about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first ✌️) +name: "\U0001F4A5 v7 Regression" +about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first + ✌️) +title: '' +labels: 'i: bug, 7.x: regression, i: needs triage' +assignees: '' --- # v7 Regression -> First check out: https://new.babeljs.io/docs/en/next/v7-migration.html +> First check out: https://babeljs.io/docs/en/v7-migration > Also a partial upgrade tool: https://github.com/babel/babel-upgrade **Potential Commit/PR that introduced the regression** diff --git a/.github/ISSUE_TEMPLATE/Support_question.md b/.github/ISSUE_TEMPLATE/Support_question.md index 32ad69fa25a3..57c183f7323d 100644 --- a/.github/ISSUE_TEMPLATE/Support_question.md +++ b/.github/ISSUE_TEMPLATE/Support_question.md @@ -1,6 +1,9 @@ --- -name: 🤗 Support Question -about: If you have a question 💬, please check out our Slack or StackOverflow! +name: "\U0001F917 Support Question" +about: "If you have a question \U0001F4AC, please check out our Slack or StackOverflow!" +title: '' +labels: 'i: question, i: needs triage' +assignees: '' --- diff --git a/.github/ISSUE_TEMPLATE/Support_us.md b/.github/ISSUE_TEMPLATE/Support_us.md index 56c9c08d57cc..cd7eb394bdd8 100644 --- a/.github/ISSUE_TEMPLATE/Support_us.md +++ b/.github/ISSUE_TEMPLATE/Support_us.md @@ -1,6 +1,10 @@ --- -name: 🤝 Support us on Babel -about: If you would like to support our efforts in maintaining this community-driven project 🙌! +name: "\U0001F91D Support us on Babel" +about: "If you would like to support our efforts in maintaining this community-driven + project \U0001F64C!" +title: '' +labels: '' +assignees: '' --- diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 000000000000..3267641c50ce --- /dev/null +++ b/.github/main.workflow @@ -0,0 +1,76 @@ +workflow "Release" { + on = "push" + resolves = ["Trigger GitHub release"] +} + +action "Is version tag" { + uses = "actions/bin/filter@0dbb077f64d0ec1068a644d25c71b1db66148a24" + args = "tag v*" +} + +action "Is tag from master" { + uses = "babel/actions/commit-matches-branch@master" + needs = [ + "Is version tag", + ] + args = "master" +} + +action "Trigger GitHub release" { + uses = "babel/actions/trigger-github-release@master" + secrets = ["GITHUB_TOKEN"] + env = { + COMMIT_AUTHOR_NAME = "Babel Bot" + COMMIT_AUTHOR_EMAIL = "babel-bot@users.noreply.github.com" + } + needs = [ + "Is version tag", + "Is tag from master", + ] +} + +workflow "Welcome" { + resolves = [ + "Create Welcome Comment" + ] + on = "issues" +} + +action "Is action 'opened'" { + uses = "actions/bin/filter@master" + args = "action opened" +} + +action "Create Welcome Comment" { + uses = "babel/actions/create-welcome-comment@master" + secrets = ["GITHUB_TOKEN", "BOT_TOKEN"] + needs = ["Is action 'opened'"] +} + +workflow "Needs Info" { + resolves = [ + "Create Needs Info Comment" + ] + on = "issues" +} + +action "Is action 'labeled'" { + uses = "actions/bin/filter@master" + args = "action labeled" +} + +action "Has label 'Needs Info'" { + uses = "actions/bin/filter@master" + needs = [ + "Is action 'labeled'" + ] + args = "label 'Needs Info'" +} + +action "Create Needs Info Comment" { + uses = "babel/actions/create-needs-info-comment@master" + needs = [ + "Has label 'Needs Info'", + ] + secrets = ["BOT_TOKEN", "GITHUB_TOKEN"] +} diff --git a/.gitignore b/.gitignore index 2b06f7e3e409..2f99b017304b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ +.npmrc + .DS_Store /node_modules +/.github/actions/*/node_modules /packages/*/node_modules /packages/*/LICENSE !/packages/babel-parser/LICENSE @@ -15,6 +18,7 @@ coverage dist /.package.json package-lock.json +!/.github/actions/*/package-lock.json /packages/babel-runtime/helpers/*.js !/packages/babel-runtime/helpers/toArray.js @@ -36,6 +40,11 @@ package-lock.json /packages/babel-runtime-corejs2/core-js/**/*.js !/packages/babel-runtime-corejs2/core-js/map.js +/packages/babel-runtime-corejs3/helpers/*.js +/packages/babel-runtime-corejs3/helpers/esm/*.js +/packages/babel-runtime-corejs3/core-js/**/*.js +/packages/babel-runtime-corejs3/core-js-stable/**/*.js + /packages/babel-register/test/.babel /packages/babel-cli/test/tmp /packages/babel-node/test/tmp diff --git a/.prettierignore b/.prettierignore index 0318d666e9dc..e86c7aa505d3 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,5 @@ package.json packages/babel-preset-env/data +packages/*/test/fixtures/**/input.* +packages/*/test/fixtures/**/exec.* +packages/*/test/fixtures/**/output.* diff --git a/.travis.yml b/.travis.yml index 67627f76c300..3957c277c102 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,12 @@ git: - depth: 10 -sudo: false + depth: 5 language: node_js cache: yarn: true - directories: - - node_modules node_js: # We test the latest version on circleci - - '9' + - '11' + - '10' - '8' - '6' @@ -20,17 +18,20 @@ env: before_install: - curl -o- -L https://yarnpkg.com/install.sh | bash -install: yarn --ignore-engines +install: + # the `make test-ci` script runs this command already + - if [ "$JOB" != "test" ] && [ "$JOB" != "lint" ]; then yarn install; fi + - if [ "$JOB" = "lint" ]; then make bootstrap; fi before_script: - - 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make bootstrap-flow; fi' - - 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make bootstrap-test262; fi' + - if [ "$JOB" = "babel-parser-flow-tests" ]; then make bootstrap-flow; fi + - if [ "$JOB" = "babel-parser-test262-tests" ]; then make bootstrap-test262; fi script: - - 'if [ "$JOB" = "test" ]; then make test-ci; fi' - - 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi' - - 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make test-flow-ci; fi' - - 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make test-test262-ci; fi' + - if [ "$JOB" = "test" ]; then make test-ci; fi + - if [ "$JOB" = "lint" ]; then make lint && make flow; fi + - if [ "$JOB" = "babel-parser-flow-tests" ]; then make test-flow-ci; fi + - if [ "$JOB" = "babel-parser-test262-tests" ]; then make test-test262-ci; fi matrix: fast_finish: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7eadb7c7d4..9ce2fc517e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,1018 @@ See [CHANGELOG - v4](/.github/CHANGELOG-v4.md), [CHANGELOG - v5](/.github/CHANGE See [CHANGELOG - 6to5](/.github/CHANGELOG-6to5.md) for the pre-4.0.0 version changelog. See [Babylon's CHANGELOG](packages/babylon/CHANGELOG.md) for the Babylon pre-7.0.0-beta.29 version changelog. + + + +## v7.5.5 (2019-07-17) + +#### :bug: Bug Fix +* `babel-code-frame` + * [#10211](https://github.com/babel/babel/pull/10211) fix code-frame marker with highlighting ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-plugin-proposal-object-rest-spread` + * [#10200](https://github.com/babel/babel/pull/10200) Workaround #10179 in proposal-object-rest-spread ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-types` + * [#10198](https://github.com/babel/babel/pull/10198) add assertShape to validate templateElement ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-helper-create-class-features-plugin`, `babel-helper-member-expression-to-functions`, `babel-helper-replace-supers`, `babel-helpers`, `babel-plugin-proposal-class-properties`, `babel-plugin-transform-classes`, `babel-plugin-transform-object-super`, `babel-types` + * [#10017](https://github.com/babel/babel/pull/10017) destructuring private fields with array pattern / object pattern ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-plugin-transform-flow-comments` + * [#9901](https://github.com/babel/babel/pull/9901) fix transform-flow-comments for import types ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-core`, `babel-helpers` + * [#10208](https://github.com/babel/babel/pull/10208) always throw when add missing helpers ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-plugin-transform-runtime` + * [#10207](https://github.com/babel/babel/pull/10207) Closes [#10205](https://github.com/babel/babel/issues/10205) ([@sag1v](https://github.com/sag1v)) +* `babel-helpers`, `babel-plugin-transform-instanceof` + * [#10197](https://github.com/babel/babel/pull/10197) fix: custom instOfHandler result should be cast to boolean ([@JLHwung](https://github.com/JLHwung)) + +#### :house: Internal +* `babel-parser`, `babel-plugin-transform-typescript` + * [#10014](https://github.com/babel/babel/pull/10014) Use correct extension for typescript fixtures ([@danez](https://github.com/danez)) + +#### :running_woman: Performance +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#10189](https://github.com/babel/babel/pull/10189) perf: match ownKeys perf to the one of objectSpread ([@JLHwung](https://github.com/JLHwung)) + +## v7.5.4 (2019-07-09) + +#### :bug: Bug Fix +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#10188](https://github.com/babel/babel/pull/10188) Fix _objectSpread2 for real ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.5.3 (2019-07-09) + +#### :bug: Bug Fix +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#10180](https://github.com/babel/babel/pull/10180) [_objectSpread2] Do not use hoisted var from prev iteration ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.5.2 (2019-07-08) + +#### :bug: Bug Fix +* `babel-plugin-transform-typescript` + * [#10174](https://github.com/babel/babel/pull/10174) Do not trust Scope when removing TypeScript types ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#10171](https://github.com/babel/babel/pull/10171) Don't rely on getOwnPropertyDescriptors in objectSpread2 ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-export-default-from`, `babel-plugin-proposal-export-namespace-from` + * [#10172](https://github.com/babel/babel/pull/10172) fix: register injected importDeclaration ([@JLHwung](https://github.com/JLHwung)) + +## v7.5.1 (2019-07-06) + +#### :bug: Bug Fix +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread` + * [#10170](https://github.com/babel/babel/pull/10170) Fix objectSpread2 backward compatibility ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-transform-typescript` + * [#10167](https://github.com/babel/babel/pull/10167) Retain typescript export-from-source ([@Wolvereness](https://github.com/Wolvereness)) + +## v7.5.0 (2019-07-04) + +#### :eyeglasses: Spec Compliance +* `babel-parser` + * [#10099](https://github.com/babel/babel/pull/10099) Disallow "let" as name at lexical bindings ([@g-plane](https://github.com/g-plane)) + +#### :rocket: New Feature +* `babel-parser` + * [#10091](https://github.com/babel/babel/pull/10091) BigInt type for Flow ([@tanhauhau](https://github.com/tanhauhau)) + * [#9450](https://github.com/babel/babel/pull/9450) Implement f# pipeline in parser ([@mAAdhaTTah](https://github.com/mAAdhaTTah)) + * [#9912](https://github.com/babel/babel/pull/9912) [legacy decorators] Allow decorating generator methods ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9864](https://github.com/babel/babel/pull/9864) [@babel/parser] Add "allowUndeclaredExports" option ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-dynamic-import`, `babel-preset-env-standalone`, `babel-preset-env` + * [#10109](https://github.com/babel/babel/pull/10109) Add @babel/plugin-proposal-dynamic-import to @babel/preset-env ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-dynamic-import`, `babel-plugin-transform-modules-amd`, `babel-plugin-transform-modules-commonjs`, `babel-plugin-transform-modules-systemjs` + * [#9552](https://github.com/babel/babel/pull/9552) Create @babel/plugin-proposal-dynamic-import ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-pipeline-operator`, `babel-plugin-syntax-pipeline-operator` + * [#9984](https://github.com/babel/babel/pull/9984) Transform for F# Pipeline ([@thiagoarrais](https://github.com/thiagoarrais)) +* `babel-plugin-transform-typescript`, `babel-types` + * [#9785](https://github.com/babel/babel/pull/9785) Implement TypeScript namespace support ([@Wolvereness](https://github.com/Wolvereness)) + +#### :bug: Bug Fix +* `babel-plugin-proposal-do-expressions`, `babel-traverse` + * [#10072](https://github.com/babel/babel/pull/10072) fix await and yield for do expression ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-helpers`, `babel-plugin-transform-react-constant-elements` + * [#10155](https://github.com/babel/babel/pull/10155) Added es3 backward compatibility for react helper code ([@sormy](https://github.com/sormy)) +* `babel-preset-env` + * [#10127](https://github.com/babel/babel/pull/10127) Bump compat-table and updating preset-env mappings ([@existentialism](https://github.com/existentialism)) + * [#8897](https://github.com/babel/babel/pull/8897) Allow `defaults` query in preset-env ([@existentialism](https://github.com/existentialism)) +* `babel-parser` + * [#10132](https://github.com/babel/babel/pull/10132) fix import typeof in declare module ([@tanhauhau](https://github.com/tanhauhau)) + * [#10084](https://github.com/babel/babel/pull/10084) flow - allow type parameter defaults in function declarations ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-types` + * [#10126](https://github.com/babel/babel/pull/10126) fix exportKind declaration in babel-types ([@zxbodya](https://github.com/zxbodya)) +* `babel-node` + * [#9951](https://github.com/babel/babel/pull/9951) Prevents exception on PnP ([@arcanis](https://github.com/arcanis)) +* `babel-generator` + * [#10041](https://github.com/babel/babel/pull/10041) Fix printer for explicitly inexact Flow types ([@mrtnzlml](https://github.com/mrtnzlml)) +* `babel-plugin-transform-typescript` + * [#10034](https://github.com/babel/babel/pull/10034) Use scope for typescript export removals ([@Wolvereness](https://github.com/Wolvereness)) + * [#10019](https://github.com/babel/babel/pull/10019) fix(typescript): erase default export if exporting a TS type ([@airato](https://github.com/airato)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-class-properties`, `babel-traverse` + * [#10029](https://github.com/babel/babel/pull/10029) Fixed computed keys for class expression ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#9384](https://github.com/babel/babel/pull/9384) Retry to fix object spread helper compatibility ([@saschanaz](https://github.com/saschanaz)) +* `babel-plugin-transform-destructuring` + * [#10013](https://github.com/babel/babel/pull/10013) fix destructuring rest with template literal ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-transform-typescript` + * [#9610](https://github.com/babel/babel/pull/9610) Use `injectInitialization` to generate ts parameter properties ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :nail_care: Polish +* `babel-core` + * [#10157](https://github.com/babel/babel/pull/10157) Fix incorrect usage of $o instead of %o in debug ([@ChlorideCull](https://github.com/ChlorideCull)) +* `babel-helpers` + * [#10117](https://github.com/babel/babel/pull/10117) Simplify the helpers for classPrivateField{Get,Set} ([@arv](https://github.com/arv)) +* `babel-plugin-transform-typescript` + * [#10047](https://github.com/babel/babel/pull/10047) Refactor isImportTypeOnly helper function ([@Andarist](https://github.com/Andarist)) + +#### :memo: Documentation +* `babel-plugin-proposal-partial-application`, `babel-plugin-syntax-partial-application` + * [#10103](https://github.com/babel/babel/pull/10103) docs: update readmes ([@xtuc](https://github.com/xtuc)) + +## v7.4.5 (2019-05-21) + +#### :bug: Bug Fix +* `babel-parser` + * [#9998](https://github.com/babel/babel/pull/9998) Fix location for optional params in arrow functions ([@danez](https://github.com/danez)) + * [#9982](https://github.com/babel/babel/pull/9982) Avoid unnecessary work during lookahead ([@danez](https://github.com/danez)) + * [#9922](https://github.com/babel/babel/pull/9922) fix: allow shebang directive ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-preset-env` + * [#10002](https://github.com/babel/babel/pull/10002) Update preset-env dependencies and fix fixtures ([@danez](https://github.com/danez)) + * [#9978](https://github.com/babel/babel/pull/9978) Fix mobile browsers support in preset-env ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9902](https://github.com/babel/babel/pull/9902) Fix destructuring assignments being transpiled for edge 15 ([@eps1lon](https://github.com/eps1lon)) +* `babel-plugin-transform-typescript` + * [#9944](https://github.com/babel/babel/pull/9944) fix(typescript): erase type exports ([@airato](https://github.com/airato)) + +#### :nail_care: Polish +* `babel-parser` + * [#9995](https://github.com/babel/babel/pull/9995) Do not use lookahead when parsing construct signature declarations in TS ([@danez](https://github.com/danez)) + * [#9989](https://github.com/babel/babel/pull/9989) Only compute Position if not already in state ([@danez](https://github.com/danez)) + * [#9988](https://github.com/babel/babel/pull/9988) Do not use lookahead when parsing jsx expression containers ([@danez](https://github.com/danez)) + * [#9987](https://github.com/babel/babel/pull/9987) Do not use lookahead when parsing imports in declare module in flow ([@danez](https://github.com/danez)) + * [#9985](https://github.com/babel/babel/pull/9985) Do not use lookahead when parsing declare module or declare module.exports in flow ([@danez](https://github.com/danez)) + * [#9983](https://github.com/babel/babel/pull/9983) Do not use lookahead when parsing dynamic import or import.meta ([@danez](https://github.com/danez)) + * [#9979](https://github.com/babel/babel/pull/9979) Remove guardedHandlers from ASTs ([@danez](https://github.com/danez)) +* `babel-preset-env` + * [#9992](https://github.com/babel/babel/pull/9992) use console.warn for warning ([@schu34](https://github.com/schu34)) +* `babel-core` + * [#9945](https://github.com/babel/babel/pull/9945) Fixed null error in plugin opts and added a test for it ([@divbhasin](https://github.com/divbhasin)) +* `babel-core`, `babel-traverse` + * [#9909](https://github.com/babel/babel/pull/9909) Add missing space in error messages ([@pnavarrc](https://github.com/pnavarrc)) + +#### :house: Internal +* `babel-node` + * [#9914](https://github.com/babel/babel/pull/9914) [babel-node] Do not hardcode node flags ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.4.4 (2019-04-26) + +#### :bug: Bug Fix +* `babel-plugin-transform-flow-comments` + * [#9897](https://github.com/babel/babel/pull/9897) fix flow-comments - class type paramters and implements ([@tanhauhau](https://github.com/tanhauhau)) + * [#9893](https://github.com/babel/babel/pull/9893) fix flow-comment - object destructuring ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-parser` + * [#9766](https://github.com/babel/babel/pull/9766) Add TS support to @babel/parser's Scope ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9865](https://github.com/babel/babel/pull/9865) Always register global bindings as exportable ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9887](https://github.com/babel/babel/pull/9887) Fix TypeScript readonly error location ([@existentialism](https://github.com/existentialism)) + * [#9869](https://github.com/babel/babel/pull/9869) ! remove constant context assertions ([@tanhauhau](https://github.com/tanhauhau)) + * [#9890](https://github.com/babel/babel/pull/9890) Fix parsing typescript bodiless methods with the estree plugin also enabled ([@devongovett](https://github.com/devongovett)) +* `babel-traverse` + * [#9870](https://github.com/babel/babel/pull/9870) Fix flow types in traverse/path/family and enable flow ([@danez](https://github.com/danez)) +* `babel-plugin-proposal-class-properties`, `babel-plugin-transform-modules-commonjs`, `babel-types` + * [#9861](https://github.com/babel/babel/pull/9861) Fix: PrivateName Identifier should not be isReferenced. ([@coreyfarrell](https://github.com/coreyfarrell)) +* `babel-types` + * [#9832](https://github.com/babel/babel/pull/9832) Fix typo in cloneNode. ([@evandervalk](https://github.com/evandervalk)) + + +## v7.4.3 (2019-04-02) + +#### :eyeglasses: Spec Compliance +* `babel-parser` + * [#9769](https://github.com/babel/babel/pull/9769) Don't accept '\08' or '\09' in strict mode. ([@danez](https://github.com/danez)) + * [#9768](https://github.com/babel/babel/pull/9768) Correctly check for-in and for-of loop for invalid left-hand side. ([@danez](https://github.com/danez)) + * [#9767](https://github.com/babel/babel/pull/9767) Parse right-hand-side of for/of as an assignment expression. ([@danez](https://github.com/danez)) + * [#9748](https://github.com/babel/babel/pull/9748) [typescript] parsing template literal as type . ([@tanhauhau](https://github.com/tanhauhau)) + +#### :rocket: New Feature +* `babel-plugin-transform-runtime` + * [#9754](https://github.com/babel/babel/pull/9754) [runtime-corejs3] Only polyfill instance methods when it might be needed. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :bug: Bug Fix +* `babel-polyfill` + * [#9780](https://github.com/babel/babel/pull/9780) Closes [#9232](https://github.com/babel/babel/issues/9232), add some missed modules to `@babel/polyfill/noConflict`. ([@zloirock](https://github.com/zloirock)) +* `babel-cli` + * [#9807](https://github.com/babel/babel/pull/9807) Upgrade lodash to 4.17.11. ([@danez](https://github.com/danez)) +* `babel-helper-module-transforms`, `babel-plugin-transform-modules-commonjs` + * [#9802](https://github.com/babel/babel/pull/9802) Fix lazy option of babel-plugin-transform-modules-commonjs. ([@AndreasCag](https://github.com/AndreasCag)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-private-methods` + * [#9801](https://github.com/babel/babel/pull/9801) Fix super method call in private instance method calling overridden method. ([@MattiasBuelens](https://github.com/MattiasBuelens)) +* `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-destructuring` + * [#9416](https://github.com/babel/babel/pull/9416) Destructuring: Fix handling of impure computed keys with object rest. ([@motiz88](https://github.com/motiz88)) +* `babel-plugin-transform-destructuring` + * [#9412](https://github.com/babel/babel/pull/9412) Destructuring: Fix array unpacking assignments with holes on RHS. ([@motiz88](https://github.com/motiz88)) +* `babel-traverse` + * [#9415](https://github.com/babel/babel/pull/9415) @babel/traverse: Fix NodePath.getData. ([@71](https://github.com/71)) +* `babel-parser` + * [#9760](https://github.com/babel/babel/pull/9760) Allow HTML comments on first line. ([@danez](https://github.com/danez)) + * [#9700](https://github.com/babel/babel/pull/9700) Fix compatibility between estree and TS plugin. ([@danez](https://github.com/danez)) +* `babel-helpers` + * [#9756](https://github.com/babel/babel/pull/9756) Allow coreJS Symbol to be type object. ([@conartist6](https://github.com/conartist6)) +* `babel-preset-env` + * [#9752](https://github.com/babel/babel/pull/9752) Normalize `core-js` entry points. ([@zloirock](https://github.com/zloirock)) + +#### :nail_care: Polish +* `babel-parser` + * [#9762](https://github.com/babel/babel/pull/9762) Optimize parseBindingAtom code to get better error messages. ([@danez](https://github.com/danez)) +* `babel-core`, `babel-plugin-transform-for-of` + * [#9698](https://github.com/babel/babel/pull/9698) Move array reference into `for` head initializer. ([@danez](https://github.com/danez)) + +#### :house: Internal +* Other + * [#9806](https://github.com/babel/babel/pull/9806) Update test262. ([@danez](https://github.com/danez)) +* `babel-parser`, `babel-preset-typescript` + * [#9761](https://github.com/babel/babel/pull/9761) Explicit labels for tokenTypes. ([@danez](https://github.com/danez)) + + +## v7.4.2 (2019-03-21) + +#### :bug: Bug Fix +* `babel-parser` + * [#9725](https://github.com/babel/babel/pull/9725) Modules might be in loose mode when checking for undecl exports ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9719](https://github.com/babel/babel/pull/9719) Fix scope checks with enabled flow plugin ([@danez](https://github.com/danez)) +* `babel-helpers`, `babel-plugin-transform-named-capturing-groups-regex` + * [#9726](https://github.com/babel/babel/pull/9726) Fix typo in wrapRegExp helper ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-preset-env` + * [#9724](https://github.com/babel/babel/pull/9724) Closes [#9713](https://github.com/babel/babel/issues/9713) ([@zloirock](https://github.com/zloirock)) + +#### :nail_care: Polish +* `babel-preset-env` + * [#9732](https://github.com/babel/babel/pull/9732) Mark the core-js warning as such ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9716](https://github.com/babel/babel/pull/9716) Tweak preset-env corejs/useBuiltIns warning and error messages ([@existentialism](https://github.com/existentialism)) + +#### :house: Internal +* [#9718](https://github.com/babel/babel/pull/9718) Bump Babel deps ([@existentialism](https://github.com/existentialism)) + +## v7.4.1 (2019-03-20) + +#### :bug: Bug Fix +* `babel-preset-env` + * [#9711](https://github.com/babel/babel/pull/9711) Alias @babel/preset-env/data/built-ins.json.js ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9709](https://github.com/babel/babel/pull/9709) Bring back isPluginRequired ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.4.0 (2019-03-19) + +#### :eyeglasses: Spec Compliance +* `babel-parser` + * [#9529](https://github.com/babel/babel/pull/9529) Add `readonly` to TypeScript type modifier ([@tanhauhau](https://github.com/tanhauhau)) + * [#9534](https://github.com/babel/babel/pull/9534) TypeScript Constant contexts ([@tanhauhau](https://github.com/tanhauhau)) + * [#9637](https://github.com/babel/babel/pull/9637) Update identifier parsing per Unicode v12 ([@mathiasbynens](https://github.com/mathiasbynens)) + * [#9616](https://github.com/babel/babel/pull/9616) Allow any reserved word in `export {} from` specifiers ([@danez](https://github.com/danez)) + * [#9612](https://github.com/babel/babel/pull/9612) [TS] Disallow type casts in arrow parameters ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9607](https://github.com/babel/babel/pull/9607) Refactor parsing object members ([@danez](https://github.com/danez)) + * [#9599](https://github.com/babel/babel/pull/9599) Disallow duplicate params in methods ([@danez](https://github.com/danez)) + * [#9586](https://github.com/babel/babel/pull/9586) Treat for loop body as part of loop scope ([@danez](https://github.com/danez)) +* `babel-parser`, `babel-plugin-transform-typescript` + * [#9641](https://github.com/babel/babel/pull/9641) Allow context type annotation on getters/setters ([@matt-tingen](https://github.com/matt-tingen)) +* `babel-plugin-proposal-unicode-property-regex`, `babel-plugin-transform-dotall-regex`, `babel-plugin-transform-unicode-regex` + * [#9636](https://github.com/babel/babel/pull/9636) Update babel-plugin-proposal-unicode-property-regex for Unicode v12 ([@mathiasbynens](https://github.com/mathiasbynens)) +* `babel-generator`, `babel-parser`, `babel-plugin-transform-flow-strip-types`, `babel-plugin-transform-modules-systemjs` + * [#9589](https://github.com/babel/babel/pull/9589) Check exported bindings are defined ([@danez](https://github.com/danez)) +* `babel-generator`, `babel-parser`, `babel-plugin-transform-classes`, `babel-plugin-transform-flow-comments`, `babel-plugin-transform-flow-strip-types`, `babel-plugin-transform-new-target` + * [#9493](https://github.com/babel/babel/pull/9493) Introduce scope tracking in the parser ([@danez](https://github.com/danez)) + +#### :rocket: New Feature +* `babel-helpers`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-runtime`, `babel-plugin-transform-typescript`, `babel-polyfill`, `babel-preset-env`, `babel-register`, `babel-runtime-corejs2`, `babel-runtime-corejs3` + * [#7646](https://github.com/babel/babel/pull/7646) Update to `core-js@3` ([@zloirock](https://github.com/zloirock)) +* `babel-template` + * [#9648](https://github.com/babel/babel/pull/9648) Add %%placeholders%% support to @babel/template ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-parser`, `babel-plugin-proposal-partial-application` + * [#9474](https://github.com/babel/babel/pull/9474) Partial application plugin ([@byara](https://github.com/byara)) +* `babel-generator`, `babel-helper-create-class-features-plugin`, `babel-helpers`, `babel-plugin-proposal-private-methods` + * [#9446](https://github.com/babel/babel/pull/9446) Private Static Class Methods (Stage 3) ([@tim-mc](https://github.com/tim-mc)) +* `babel-generator`, `babel-types` + * [#9542](https://github.com/babel/babel/pull/9542) Add placeholders support to @babel/types and @babel/generator ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-parser` + * [#9364](https://github.com/babel/babel/pull/9364) Add parser support for placeholders ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-generator`, `babel-parser`, `babel-plugin-syntax-partial-application`, `babel-types` + * [#9343](https://github.com/babel/babel/pull/9343) Partial Application Syntax: Stage 1 ([@byara](https://github.com/byara)) + +#### :bug: Bug Fix +* `babel-helper-create-class-features-plugin`, `babel-helper-replace-supers`, `babel-plugin-proposal-private-methods` + * [#9704](https://github.com/babel/babel/pull/9704) Fix `super` Method Calls in Class Private Methods ([@tim-mc](https://github.com/tim-mc)) +* `babel-parser` + * [#9699](https://github.com/babel/babel/pull/9699) Correctly parse TS TypeAssertions around arrow functions ([@danez](https://github.com/danez)) + * [#9600](https://github.com/babel/babel/pull/9600) Fix scope check for 2nd+ lexical bindings ([@danez](https://github.com/danez)) + * [#9593](https://github.com/babel/babel/pull/9593) [TS] Correctly forget `await`s after parsing async arrows with type args ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9585](https://github.com/babel/babel/pull/9585) Fix strict mode prescanning with EmptyStatement ([@danez](https://github.com/danez)) +* `babel-core`, `babel-plugin-transform-for-of` + * [#9697](https://github.com/babel/babel/pull/9697) Correctly preserve reference to array in for-of loop ([@danez](https://github.com/danez)) +* `babel-plugin-transform-typescript` + * [#9693](https://github.com/babel/babel/pull/9693) [plugin-transform-typescript] Fix transpiling of TS abstract classes with decorators ([@agoldis](https://github.com/agoldis)) +* `babel-traverse`, `babel-types` + * [#9692](https://github.com/babel/babel/pull/9692) Fix TSFunctionType visitors definition ([@penielse](https://github.com/penielse)) +* `babel-plugin-proposal-object-rest-spread` + * [#9628](https://github.com/babel/babel/pull/9628) [proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys ([@pnowak](https://github.com/pnowak)) +* `babel-plugin-transform-modules-systemjs` + * [#9639](https://github.com/babel/babel/pull/9639) System modules - Hoist classes like other variables ([@guybedford](https://github.com/guybedford)) +* `babel-generator`, `babel-parser` + * [#9618](https://github.com/babel/babel/pull/9618) Disallow escape sequences in contextual keywords ([@danez](https://github.com/danez)) +* `babel-helper-split-export-declaration`, `babel-plugin-transform-modules-commonjs`, `babel-traverse` + * [#9613](https://github.com/babel/babel/pull/9613) Don't add params of anonymous exported function decls to the outer scope ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-transform-parameters`, `babel-plugin-transform-typescript`, `babel-types` + * [#9605](https://github.com/babel/babel/pull/9605) [plugin-transform-typescript] Strip type imports used in Enums and object types ([@echenley](https://github.com/echenley)) +* `babel-helper-call-delegate`, `babel-plugin-transform-parameters` + * [#9601](https://github.com/babel/babel/pull/9601) Don't loose "this" in helper-call-delegate ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-modules-commonjs`, `babel-traverse`, `babel-types` + * [#9492](https://github.com/babel/babel/pull/9492) Mark FOO in "var { x: FOO }˝ as a binding, not as a reference ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-preset-env` + * [#9595](https://github.com/babel/babel/pull/9595) preset-env: Sort versions before determining lowest ([@jridgewell](https://github.com/jridgewell)) +* `babel-helper-define-map`, `babel-helper-hoist-variables`, `babel-parser`, `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-block-scoping`, `babel-plugin-transform-destructuring`, `babel-plugin-transform-modules-systemjs`, `babel-traverse`, `babel-types` + * [#9518](https://github.com/babel/babel/pull/9518) Use `for..of Object.keys` instead of `for..in` ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :nail_care: Polish +* `babel-parser` + * [#9646](https://github.com/babel/babel/pull/9646) Remove input and length from state ([@danez](https://github.com/danez)) + * [#9645](https://github.com/babel/babel/pull/9645) Reorganize token types and use a map for them ([@danez](https://github.com/danez)) + * [#9591](https://github.com/babel/babel/pull/9591) Remove always false param allowExpressionBody ([@danez](https://github.com/danez)) +* `babel-standalone`, `babel-types` + * [#9025](https://github.com/babel/babel/pull/9025) Make babel-standalone an ESModule and enable flow ([@danez](https://github.com/danez)) +* `babel-generator` + * [#9579](https://github.com/babel/babel/pull/9579) change var name for coherence ([@tanohzana](https://github.com/tanohzana)) + +#### :house: Internal +* Other + * [#9588](https://github.com/babel/babel/pull/9588) Publish to npm using a GitHub action ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9640](https://github.com/babel/babel/pull/9640) Switch from rollup-stream to rollup ([@danez](https://github.com/danez)) + * [#9647](https://github.com/babel/babel/pull/9647) Add WarningsToErrorsPlugin to webpack to avoid missing build problems on CI ([@danez](https://github.com/danez)) + * [#9624](https://github.com/babel/babel/pull/9624) Update dependencies ([@danez](https://github.com/danez)) + * [#9623](https://github.com/babel/babel/pull/9623) Add editorconfig for Makefile ([@danez](https://github.com/danez)) + * [#9587](https://github.com/babel/babel/pull/9587) Update test262 ([@danez](https://github.com/danez)) + * [#9582](https://github.com/babel/babel/pull/9582) Minify bundles on circle for repl ([@danez](https://github.com/danez)) +* `babel-register` + * [#9678](https://github.com/babel/babel/pull/9678) Remove dependency on home-or-tmp package ([@AmirS](https://github.com/AmirS)) + +## v7.3.4 (2019-02-25) + +#### :bug: Bug Fix +* `babel-parser` + * [#9572](https://github.com/babel/babel/pull/9572) Fix TypeScript parsers missing token check (#9571) ([@elevatebart](https://github.com/elevatebart)) + * [#9521](https://github.com/babel/babel/pull/9521) Also check AssignmentPatterns for duplicate export name ([@danez](https://github.com/danez)) +* `babel-helper-create-class-features-plugin`, `babel-helper-replace-supers`, `babel-plugin-proposal-class-properties`, `babel-traverse` + * [#9508](https://github.com/babel/babel/pull/9508) Use correct "this" in static fields ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-preset-env` + * [#9566](https://github.com/babel/babel/pull/9566) Closes [#9465](https://github.com/babel/babel/issues/9465) ([@zloirock](https://github.com/zloirock)) +* `babel-types` + * [#9539](https://github.com/babel/babel/pull/9539) babel-types is* type checks accept null | undefiend as value TS type ([@ian-craig](https://github.com/ian-craig)) +* `babel-plugin-transform-block-scoping`, `babel-traverse` + * [#9532](https://github.com/babel/babel/pull/9532) Migrate some duplicate binding tests to traverse ([@danez](https://github.com/danez)) +* `babel-generator` + * [#9524](https://github.com/babel/babel/pull/9524) Fix typescript generator params ([@tanhauhau](https://github.com/tanhauhau)) + * [#9523](https://github.com/babel/babel/pull/9523) Fix flow babel-generator function parantheses ([@tanhauhau](https://github.com/tanhauhau)) + +#### :house: Internal +* Other + * [#9561](https://github.com/babel/babel/pull/9561) Update CHANGELOG.md using the "Trigger GitHub release" action ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-modules-systemjs` + * [#9541](https://github.com/babel/babel/pull/9541) Enable eqeqeq rule in eslint ([@danez](https://github.com/danez)) +* `babel-generator`, `babel-parser`, `babel-plugin-transform-flow-strip-types`, `babel-traverse` + * [#9522](https://github.com/babel/babel/pull/9522) Make tests spec compliant by avoiding duplicate declarations in input files ([@danez](https://github.com/danez)) +* `babel-plugin-transform-proto-to-assign` + * [#9533](https://github.com/babel/babel/pull/9533) Add import/no-extraneous-dependencies to ESLint ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.3.3 (2019-02-15) + +#### :eyeglasses: Spec Compliancy +* `babel-generator` + * [#9501](https://github.com/babel/babel/pull/9501) Correctly output escapes in directives ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :bug: Bug Fix +* `babel-parser` + * [#9477](https://github.com/babel/babel/pull/9477) Fix regression with let ([@danez](https://github.com/danez)) + * [#9431](https://github.com/babel/babel/pull/9431) Typescript function destructured params ([@mhcgrq](https://github.com/mhcgrq)) + * [#9463](https://github.com/babel/babel/pull/9463) Fix range for TypeScript optional parameter in arrow function ([@existentialism](https://github.com/existentialism)) + +#### :nail_care: Polish +* `babel-plugin-proposal-class-properties`, `babel-plugin-transform-classes`, `babel-plugin-transform-parameters` + * [#9458](https://github.com/babel/babel/pull/9458) Fix duplicated assertThisInitialized calls in constructors ([@rubennorte](https://github.com/rubennorte)) + +#### :house: Internal +* Other + * [#9517](https://github.com/babel/babel/pull/9517) Add duplicate-package-checker-webpack-plugin ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9469](https://github.com/babel/babel/pull/9469) Exclude generate @babel/types files from coverage report ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-parser` + * [#9491](https://github.com/babel/babel/pull/9491) Better error output in parser tests ([@danez](https://github.com/danez)) +## v7.3.2 (2019-02-04) + +Various spec compliancy fixes and better support for smart pipelines and private methods. + +Thanks @gverni, @naffiq, @spondbob and @dstaley for their first PRs! + +#### :eyeglasses: Spec Compliancy +* `babel-parser` + * [#9403](https://github.com/babel/babel/pull/9403) Fix line continuation with Unicode line terminators. ([@danez](https://github.com/danez)) + * [#9400](https://github.com/babel/babel/pull/9400) Make yield a contextual keyword. ([@danez](https://github.com/danez)) + * [#9398](https://github.com/babel/babel/pull/9398) Correctly fail for invalid yield in for. ([@danez](https://github.com/danez)) + * [#9375](https://github.com/babel/babel/pull/9375) Make let a contextual keyword. ([@danez](https://github.com/danez)) + +#### :rocket: New Feature +* `babel-plugin-proposal-pipeline-operator` + * [#9401](https://github.com/babel/babel/pull/9401) Support for await and yield in pipelines. ([@thiagoarrais](https://github.com/thiagoarrais)) + +#### :bug: Bug Fix +* `babel-plugin-proposal-private-methods`, `babel-types` + * [#9453](https://github.com/babel/babel/pull/9453) Fix duplicate definition error in private class methods. ([@gverni](https://github.com/gverni)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-private-methods` + * [#9423](https://github.com/babel/babel/pull/9423) Transform private async and generator functions. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-object-rest-spread`, `babel-plugin-transform-destructuring` + * [#9414](https://github.com/babel/babel/pull/9414) Destructuring: Create assignments from ForX non-declaration patterns. ([@motiz88](https://github.com/motiz88)) +* `babel-plugin-transform-typescript` + * [#9095](https://github.com/babel/babel/pull/9095) Retain JSX pragma if defined as a comment. ([@dstaley](https://github.com/dstaley)) +* `babel-parser` + * [#9406](https://github.com/babel/babel/pull/9406) Fix location/range on TypeScript ExportNamedDeclarations. ([@existentialism](https://github.com/existentialism)) + * [#9371](https://github.com/babel/babel/pull/9371) Allow toplevel await with option and correctly mark await keyword as unexpected. ([@danez](https://github.com/danez)) +* `babel-plugin-transform-typescript`, `babel-types` + * [#8738](https://github.com/babel/babel/pull/8738) Fix typescript side effects. ([@yuri-karadzhov](https://github.com/yuri-karadzhov)) +* `babel-generator`, `babel-types` + * [#9396](https://github.com/babel/babel/pull/9396) Fix support for Flow's QualifiedTypeIdentifier. ([@existentialism](https://github.com/existentialism)) + +#### :nail_care: Polish +* `babel-parser` + * [#9405](https://github.com/babel/babel/pull/9405) Simplify await and yield tracking in params. ([@danez](https://github.com/danez)) +* `babel-parser`, `babel-preset-typescript` + * [#9402](https://github.com/babel/babel/pull/9402) Unify reserved word checking and update error messages. ([@danez](https://github.com/danez)) + +## v7.3.1 (2019-01-22) + +This release fixes some regressions introduced in v7.3.0 + +#### :bug: Bug Fix +* `babel-helpers`, `babel-plugin-proposal-object-rest-spread`, `babel-preset-env` + * [#9379](https://github.com/babel/babel/pull/9379) Revert "Differentiate object spread and non-spread properties (#9341)". ([@danez](https://github.com/danez)) +* `babel-parser` + * [#9377](https://github.com/babel/babel/pull/9377) fix new keyword broken by recent refactoring. ([@danez](https://github.com/danez)) + +## v7.3.0 (2019-01-21) + +Thanks to @jamesgeorge007 and @armano2 for their first PR! + +#### :eyeglasses: Spec Compliancy +* `babel-parser` + * [#9314](https://github.com/babel/babel/pull/9314) Disallow async functions as loop body. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9315](https://github.com/babel/babel/pull/9315) Parse class heritage as strict mode code. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9313](https://github.com/babel/babel/pull/9313) Disallow `new import(x)` and `import(x,)`. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9311](https://github.com/babel/babel/pull/9311) Disallow trailing comma after rest. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :rocket: New Feature +* `babel-helper-create-class-features-plugin`, `babel-helpers`, `babel-plugin-proposal-private-methods` + * [#9101](https://github.com/babel/babel/pull/9101) Private Class Methods Stage 3: Private Accessors. ([@tim-mc](https://github.com/tim-mc)) +* `babel-plugin-proposal-pipeline-operator`, `babel-plugin-syntax-pipeline-operator` + * [#9179](https://github.com/babel/babel/pull/9179) Transform for the smart pipeline operator proposal. ([@thiagoarrais](https://github.com/thiagoarrais)) +* `babel-preset-env-standalone`, `babel-preset-env` + * [#9345](https://github.com/babel/babel/pull/9345) Add support for transform-named-capturing-groups-regex in preset-env. ([@existentialism](https://github.com/existentialism)) +* `babel-helpers`, `babel-plugin-transform-named-capturing-groups-regex` + * [#7105](https://github.com/babel/babel/pull/7105) Add @babel/plugin-transform-named-capturing-groups-regex. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-preset-env` + * [#9323](https://github.com/babel/babel/pull/9323) Add support for proposal-json-strings in preset-env. ([@existentialism](https://github.com/existentialism)) +* `babel-generator`, `babel-types` + * [#9309](https://github.com/babel/babel/pull/9309) Add emit and builder for TSImportType. ([@hzoo](https://github.com/hzoo)) +* `babel-parser` + * [#9302](https://github.com/babel/babel/pull/9302) @babel/parser(ts): Add parsing of type import. ([@armano2](https://github.com/armano2)) + +#### :bug: Bug Fix +* `babel-parser` + * [#9336](https://github.com/babel/babel/pull/9336) Disallow usage of invalid keyword after export abstract statement in Typescript. ([@armano2](https://github.com/armano2)) + * [#9328](https://github.com/babel/babel/pull/9328) Fix handling newline with TypeScript declare and abstract classes. ([@existentialism](https://github.com/existentialism)) + * [#9335](https://github.com/babel/babel/pull/9335) Fix range on TypeScript index signature parameters. ([@existentialism](https://github.com/existentialism)) + * [#9292](https://github.com/babel/babel/pull/9292) Throw error if TypeScript class has empty implements. ([@existentialism](https://github.com/existentialism)) + * [#9284](https://github.com/babel/babel/pull/9284) Fix location for typescript type assertions in AST. ([@danez](https://github.com/danez)) + * [#9276](https://github.com/babel/babel/pull/9276) Ensure modifiers are included in TSParameterProperty ranges. ([@existentialism](https://github.com/existentialism)) + * [#9230](https://github.com/babel/babel/pull/9230) babel-parser: typescript: add missing bigint keyword. ([@armano2](https://github.com/armano2)) +* `babel-types` + * [#9333](https://github.com/babel/babel/pull/9333) Copy "optional" property when cloning Identifier node. ([@unconfident](https://github.com/unconfident)) +* `babel-helper-create-class-features-plugin`, `babel-helpers`, `babel-plugin-proposal-decorators` + * [#9244](https://github.com/babel/babel/pull/9244) [decorators] Set method names at compile time instead of at runtime. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-helper-builder-react-jsx`, `babel-plugin-transform-react-jsx` + * [#9119](https://github.com/babel/babel/pull/9119) Revert "Revert babel-helper-builder-react-jsx change from #4988". ([@danez](https://github.com/danez)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-private-methods` + * [#9248](https://github.com/babel/babel/pull/9248) [private methods] Define private methods before executing initializers. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-preset-env` + * [#9219](https://github.com/babel/babel/pull/9219) Fix handling scoped packages in preset-env include/exclude options. ([@existentialism](https://github.com/existentialism)) + +#### :nail_care: Polish +* `babel-parser` + * [#9348](https://github.com/babel/babel/pull/9348) Parser Performance Collection. ([@danez](https://github.com/danez)) + +#### :memo: Documentation +* [#9370](https://github.com/babel/babel/pull/9370) add v7 downloads [skip ci]. ([@hzoo](https://github.com/hzoo)) + +#### :house: Internal +* `babel-parser` + * [#9312](https://github.com/babel/babel/pull/9312) Merge declaration and init of props in parser's state. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-types` + * [#9245](https://github.com/babel/babel/pull/9245) [@babel/types] Moved generators related to babel-types into the babel-types package directory.. ([@cameron-martin](https://github.com/cameron-martin)) +* Other + * [#9288](https://github.com/babel/babel/pull/9288) Test262 update. ([@existentialism](https://github.com/existentialism)) + * [#9290](https://github.com/babel/babel/pull/9290) Use 2014-present in license. ([@xtuc](https://github.com/xtuc)) + * [#9271](https://github.com/babel/babel/pull/9271) Bump license years for 2019. ([@berlamhenderson](https://github.com/berlamhenderson)) +* `babel-helpers` + * [#9166](https://github.com/babel/babel/pull/9166) Add mixins support to the _decorate helper. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.2.5 (2018-12-21) + +`@babel/polyfill` didn't get published correctly in v7.2.3 (#9227). + +## v7.2.4 (2018-12-20) + +Minify `@babel/standalone` and `@babel/preset-env-standalone`. + +## v7.2.3 (2018-12-20) + +This is a small release, mainly to test Lerna 3. +We force-published `@babel/polyfill` and `@babel/preset-env`, since they should have been released respectively in v7.1.0 and v7.2.2 but for different reasons they didn't get updated. + +Half of the commits in this release are made by first time contributors! Thanks to @cameron-martin, @cphamlet, @tanhauhau and @jedwards1211. :tada: + +#### :rocket: New Feature +* [#9110](https://github.com/babel/babel/pull/9110) Added type-level mapping between aliases and nodes that have that alias. ([@cameron-martin](https://github.com/cameron-martin)) + +#### :bug: Bug Fix +* `babel-plugin-transform-flow-strip-types` + * [#9197](https://github.com/babel/babel/pull/9197) Strips flow directive fully. ([@tanhauhau](https://github.com/tanhauhau)) +* `babel-parser` + * [#9184](https://github.com/babel/babel/pull/9184) Allow keywords to be used in type annotations. ([@danez](https://github.com/danez)) + +#### :house: Internal +* `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-plugin-proposal-private-methods`, `babel-traverse` + * [#9206](https://github.com/babel/babel/pull/9206) Use @babel/eslint-plugin-developement. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.2.2 (2018-12-15) + +Mostly bug fixes and internal changes. +Thanks to @paleite, @saschanaz and @joeldenning for their first PRs! + +#### :bug: Bug Fix +* `babel-plugin-transform-destructuring`, `babel-plugin-transform-spread` + * [#9108](https://github.com/babel/babel/pull/9108) Correctly transform spreads to use proper concat method. ([@danez](https://github.com/danez)) +* `babel-parser` + * [#9168](https://github.com/babel/babel/pull/9168) [parser] Handle flow comments with leading spaces. ([@vikr01](https://github.com/vikr01)) +* `babel-helper-module-transforms`, `babel-plugin-transform-modules-commonjs` + * [#9171](https://github.com/babel/babel/pull/9171) Fix transforming empty export statement. ([@danez](https://github.com/danez)) +* `babel-node` + * [#9148](https://github.com/babel/babel/pull/9148) Fix --root-mode option in babel-node. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-transform-classes` + * [#9135](https://github.com/babel/babel/pull/9135) Inherit properties in function from method in loose mode. ([@rubennorte](https://github.com/rubennorte)) +* `babel-preset-env` + * [#9140](https://github.com/babel/babel/pull/9140) Disable parameter-destructuring in Edge 18. ([@saschanaz](https://github.com/saschanaz)) +* `babel-plugin-transform-arrow-functions`, `babel-traverse` + * [#9060](https://github.com/babel/babel/pull/9060) Not depending on return value of super(). Closes [#9020](https://github.com/babel/babel/issues/9020).. ([@joeldenning](https://github.com/joeldenning)) + +#### :house: Internal +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-nullish-coalescing-operator`, `babel-plugin-syntax-bigint`, `babel-plugin-transform-dotall-regex` + * [#9176](https://github.com/babel/babel/pull/9176) Fix package.json repository URLs. ([@paleite](https://github.com/paleite)) +* Other + * [#9158](https://github.com/babel/babel/pull/9158) add triage label to new issues [skip ci]. ([@danez](https://github.com/danez)) + * [#9143](https://github.com/babel/babel/pull/9143) Fix a typo from the issue template for bugs. ([@saschanaz](https://github.com/saschanaz)) + * [#9133](https://github.com/babel/babel/pull/9133) Move to travis vm based builds. ([@danez](https://github.com/danez)) + * [#9132](https://github.com/babel/babel/pull/9132) Ensure we always use repository versions of babel dependencies in tests. ([@danez](https://github.com/danez)) + * [#9131](https://github.com/babel/babel/pull/9131) Update issue templates [skip ci]. ([@hzoo](https://github.com/hzoo)) +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators` + * [#9059](https://github.com/babel/babel/pull/9059) Move decorators transform to @babel/helper-create-class-features-plugin. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-core`, `babel-parser`, `babel-template` + * [#9128](https://github.com/babel/babel/pull/9128) Fix running flow on travis and update flow. ([@danez](https://github.com/danez)) + +## v7.2.1 (2018-12-04) + +This release fixes a regression introduced in v7.2.0 (https://github.com/babel/babel/issues/9120) + +#### :bug: Bug Fix +* `babel-helper-create-class-features-plugin` + * [#9121](https://github.com/babel/babel/pull/9121) Don't use isClassPrivateMethod because it isn't supported in <7.2.0. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.2.0 (2018-12-03) + +You can read more about this release at https://babeljs.io/blog/2018/12/03/7.2.0. + +#### :rocket: New Feature +* `babel-parser` + * [#8289](https://github.com/babel/babel/pull/8289) Implement Smart Pipeline proposal in @babel/parser. ([@mAAdhaTTah](https://github.com/mAAdhaTTah)) +* `babel-core` + * [#8986](https://github.com/babel/babel/pull/8986) Export @babel/parser#tokTypes in @babel/core. ([@kaicataldo](https://github.com/kaicataldo)) +* `babel-node` + * [#9078](https://github.com/babel/babel/pull/9078) Pass `rootMode` from `@babel/node`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg)) +* `babel-generator`, `babel-helpers`, `babel-plugin-class-features`, `babel-plugin-proposal-private-methods`, `babel-plugin-syntax-class-properties`, `babel-types` + * [#8654](https://github.com/babel/babel/pull/8654) Private class methods stage 3. ([@tim-mc](https://github.com/tim-mc)) +* `babel-preset-env` + * [#9048](https://github.com/babel/babel/pull/9048) Update mappings for node 10 in preset-env. ([@existentialism](https://github.com/existentialism)) + +#### :bug: Bug Fix +* `babel-parser` + * [#9114](https://github.com/babel/babel/pull/9114) Parse non-octals with leading zeros in non strict mode correctly. ([@danez](https://github.com/danez)) + * [#9074](https://github.com/babel/babel/pull/9074) Disallow await inside arrow functions. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9069](https://github.com/babel/babel/pull/9069) [flow] Allow type casts in array patterns inside arrow parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#9058](https://github.com/babel/babel/pull/9058) Fix compatibility between typescript and jsx plugins in interface declarations. ([@danez](https://github.com/danez)) + * [#9055](https://github.com/babel/babel/pull/9055) Fix bug with parsing TS generic async arrow function. ([@existentialism](https://github.com/existentialism)) + * [#9035](https://github.com/babel/babel/pull/9035) Fix parsing typescript function types with destructuring. ([@danez](https://github.com/danez)) +* `babel-helper-fixtures`, `babel-parser` + * [#9113](https://github.com/babel/babel/pull/9113) Ignore empty fixture directories and fix fixtures in the parser. ([@danez](https://github.com/danez)) +* `babel-preset-env` + * [#9091](https://github.com/babel/babel/pull/9091) Update mapping for regex unicode plugin in preset-env. ([@existentialism](https://github.com/existentialism)) +* `babel-plugin-transform-destructuring` + * [#8916](https://github.com/babel/babel/pull/8916) Fix destructuring assignment in arrow functions without block. ([@RubenVerborgh](https://github.com/RubenVerborgh)) +* `babel-plugin-proposal-optional-chaining` + * [#9073](https://github.com/babel/babel/pull/9073) Microbouji patch/8136. ([@jridgewell](https://github.com/jridgewell)) +* `babel-core`, `babel-helper-wrap-function`, `babel-plugin-proposal-async-generator-functions`, `babel-plugin-proposal-function-sent`, `babel-plugin-transform-async-to-generator`, `babel-plugin-transform-classes` + * [#9039](https://github.com/babel/babel/pull/9039) Fix recursive async function expressions. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-core` + * [#9034](https://github.com/babel/babel/pull/9034) Normalize presets before merging config with others.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :nail_care: Polish +* `babel-generator` + * [#9089](https://github.com/babel/babel/pull/9089) Remove unused variable. ([@Gcaufy](https://github.com/Gcaufy)) +* `babel-node` + * [#9079](https://github.com/babel/babel/pull/9079) Move `fs-readdir-recursive` and `output-file-sync` to `devDependencies` for `@babel/node`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg)) +* `babel-parser` + * [#9046](https://github.com/babel/babel/pull/9046) a better error message for disallowed trailing commas/additional parameters after rest elements in function params. ([@morozRed](https://github.com/morozRed)) +* `babel-*` + * [#8769](https://github.com/babel/babel/pull/8769) Add plugins name. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :house: Internal +* `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-private-methods` + * [#9083](https://github.com/babel/babel/pull/9083) Make @babel/plugin-class-features a normal helper package. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* Other + * [#9096](https://github.com/babel/babel/pull/9096) Add node 11 to CI and remove node 9. ([@danez](https://github.com/danez)) + * [#9094](https://github.com/babel/babel/pull/9094) Skip minifying standalone in non-publish runs. ([@danez](https://github.com/danez)) +* `babel-types` + * [#9093](https://github.com/babel/babel/pull/9093) Fix warning when using prettier in code generators. ([@danez](https://github.com/danez)) +* `babel-generator` + * [#9089](https://github.com/babel/babel/pull/9089) Remove unused variable. ([@Gcaufy](https://github.com/Gcaufy)) + +## v7.1.6 (2018-11-13) + +#### :bug: Bug Fix +* `babel-generator` + * [#9003](https://github.com/babel/babel/pull/9003) Fix retainLines regression for arrow functions. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-types` + * [#8997](https://github.com/babel/babel/pull/8997) Fix cloneNode with typeAnnotation.. ([@neoziro](https://github.com/neoziro)) +* `babel-plugin-transform-flow-strip-types`, `babel-plugin-transform-react-jsx` + * [#8701](https://github.com/babel/babel/pull/8701) Fix "TypeError: comments is not iterable". ([@AlicanC](https://github.com/AlicanC)) +* `babel-core` + * [#9004](https://github.com/babel/babel/pull/9004) Fix browser files to have the same API as the nodejs ones. ([@danez](https://github.com/danez)) +* Other + * [#9007](https://github.com/babel/babel/pull/9007) [Types] fix generated TS/Flow comment types. ([@ljqx](https://github.com/ljqx)) +* `babel-preset-env` + * [#8555](https://github.com/babel/babel/pull/8555) preset-env: fix `opera` from `esmodules` target and Browserslist not used. ([@ylemkimon](https://github.com/ylemkimon)) +* `babel-plugin-proposal-decorators`, `babel-traverse` + * [#8970](https://github.com/babel/babel/pull/8970) [decorators] Correctly insert `_initialize(this)` after `super()`.. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-parser` + * [#8972](https://github.com/babel/babel/pull/8972) Fix several edge cases with context expression state. ([@danez](https://github.com/danez)) + +#### :nail_care: Polish +* `babel-parser` + * [#8984](https://github.com/babel/babel/pull/8984) Rename primitive types to reserved types. ([@danez](https://github.com/danez)) + +#### :house: Internal +* [#8982](https://github.com/babel/babel/pull/8982) fix publish command [skip ci]. ([@hzoo](https://github.com/hzoo)) +* [#8988](https://github.com/babel/babel/pull/8988) Remove definition of micromatch which was removed.. ([@danez](https://github.com/danez)) + +## v7.1.5 (2018-11-06) + +#### :eyeglasses: Spec Compliancy +* `babel-parser`, `babylon` + * [#7727](https://github.com/babel/babel/pull/7727) Fix await in function name and parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :rocket: New Feature +* `babel-parser` + * [#8828](https://github.com/babel/babel/pull/8828) Typescript: Validate tuple type element positions. ([@Retsam](https://github.com/Retsam)) + * [#8883](https://github.com/babel/babel/pull/8883) [flow] Add support for parsing `_` as implicit instantiation in call/new. ([@jbrown215](https://github.com/jbrown215)) +* `babel-core`, `babel-generator`, `babel-parser`, `babel-plugin-syntax-typescript`, `babel-traverse` + * [#8448](https://github.com/babel/babel/pull/8448) Remove Babylon plugins for features already merged to the ECMAScript spec. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-parser`, `babel-types` + * [#8884](https://github.com/babel/babel/pull/8884) [flow] Explicit inexact objects with `...`. ([@jbrown215](https://github.com/jbrown215)) +* `babel-preset-env` + * [#8898](https://github.com/babel/babel/pull/8898) Update preset-env data. ([@existentialism](https://github.com/existentialism)) + +#### :bug: Bug Fix +* `babel-parser` + * [#8956](https://github.com/babel/babel/pull/8956) Do not allow TypeCastExpressions w/o parens . ([@danez](https://github.com/danez)) + * [#8954](https://github.com/babel/babel/pull/8954) Allow function types in type params within arrow return types. ([@danez](https://github.com/danez)) + * [#8866](https://github.com/babel/babel/pull/8866) Closes [#8865](https://github.com/babel/babel/issues/8865). ([@byronluk](https://github.com/byronluk)) +* `babel-core` + * [#8910](https://github.com/babel/babel/pull/8910) Resolve babel.config.js 'babelrcRoots' values relative to the config file.. ([@loganfsmyth](https://github.com/loganfsmyth)) + * [#8950](https://github.com/babel/babel/pull/8950) Fix message when plugin of a wrong type is passed. ([@everdimension](https://github.com/everdimension)) +* `babel-plugin-transform-block-scoping` + * [#8937](https://github.com/babel/babel/pull/8937) rename colliding let bindings with for loop init. ([@byronluk](https://github.com/byronluk)) + * [#8914](https://github.com/babel/babel/pull/8914) Treat break inside block inside loop. ([@thiagoarrais](https://github.com/thiagoarrais)) +* `babel-preset-env` + * [#8926](https://github.com/babel/babel/pull/8926) preset-env: Edge support for arrow param destructuring. ([@benmosher](https://github.com/benmosher)) +* `babel-generator` + * [#8868](https://github.com/babel/babel/pull/8868) fix single-arg async arrows when retainLines=true. ([@ryanwmarsh](https://github.com/ryanwmarsh)) +* `babel-traverse` + * [#8880](https://github.com/babel/babel/pull/8880) fix: Expression x === 'y' && '' should not evaluate to undefined.. ([@Cyp](https://github.com/Cyp)) + +#### :nail_care: Polish +* [#8873](https://github.com/babel/babel/pull/8873) fixed an extra word. ([@vvyomjjain](https://github.com/vvyomjjain)) + +## v7.1.4 (2018-10-11) + +Just re-published `@babel/traverse` without `**` so that it works in Node 6. + +## v7.1.3 (2018-10-11) + +#### :bug: Bug Fix +* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types` + * [#8720](https://github.com/babel/babel/pull/8720) Typescript - Tuple elements can be optional. ([@Retsam](https://github.com/Retsam)) +* `babel-traverse` + * [#8833](https://github.com/babel/babel/pull/8833) Insertafter jsx fix. ([@kevintab95](https://github.com/kevintab95)) +* `babel-parser` + * [#8830](https://github.com/babel/babel/pull/8830) Correct handling of newline after async with paren-less arrow func. ([@Retsam](https://github.com/Retsam)) + * [#8756](https://github.com/babel/babel/pull/8756) class private methods and properties: should not allow spaces between # and identifier. ([@macabeus](https://github.com/macabeus)) + * [#8804](https://github.com/babel/babel/pull/8804) Fix parsing of slash after class expression. ([@existentialism](https://github.com/existentialism)) + * [#8767](https://github.com/babel/babel/pull/8767) [decorators] [typescript] Parse type parameters. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#8792](https://github.com/babel/babel/pull/8792) Fix perf issue in typescript parser plugin. ([@matthewrobertson](https://github.com/matthewrobertson)) +* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types` + * [#8805](https://github.com/babel/babel/pull/8805) Typescript - Tuples can include rest elements. ([@Retsam](https://github.com/Retsam)) +* `babel-types` + * [#8791](https://github.com/babel/babel/pull/8791) types: allow jsxEmptyExpression inside jsxExpressionContainer. ([@tvooo](https://github.com/tvooo)) +* `babel-plugin-transform-modules-systemjs` + * [#8820](https://github.com/babel/babel/pull/8820) System module format - fixes function hoisting failure case. ([@guybedford](https://github.com/guybedford)) +* `babel-plugin-transform-destructuring` + * [#8793](https://github.com/babel/babel/pull/8793) Ensure destructuring's computed key handling matches object-rest-spread. ([@existentialism](https://github.com/existentialism)) + +## 7.1.2 (2018-09-28) + +Same as v7.1.1, except compiled against Node 6 instead of Node 8 by accident (e.g had `async functions`). + +## v7.1.1 (2018-09-28) + +> EDIT: had a publish issue here as well where it compiled against Node 8 instead of Node 6 so 7.1.2 will fix this. +> Also force publish `@babel/runtime` and `@babel/runtime-corejs2`. We need to fix the publishing around that since Lerna doesn't pickup the `@babel/helpers` changes as there is no "dependency" + +#### :bug: Bug Fix +* `babel-generator`, `babel-parser`, `babel-types` + * [#8755](https://github.com/babel/babel/pull/8755) TypeScript: reserve `unknown` as TSUnknownKeyword. ([@g-plane](https://github.com/g-plane)) +* `babel-plugin-transform-destructuring` + * [#8535](https://github.com/babel/babel/pull/8535) Do not unpack array patterns that update a referenced binding. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-plugin-proposal-decorators` + * [#8742](https://github.com/babel/babel/pull/8742) [decorators] Support async and generator methods. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-helpers`, `babel-plugin-proposal-decorators` + * [#8761](https://github.com/babel/babel/pull/8761) [decorators] Fields are enumerable. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-generator` + * [#8751](https://github.com/babel/babel/pull/8751) Fix some missing parens cases with OptionalMemberExpression in generator. ([@existentialism](https://github.com/existentialism)) + * [#8727](https://github.com/babel/babel/pull/8727) Handle throw expressions in generator. ([@existentialism](https://github.com/existentialism)) + +#### :house: Internal +* Other + * [#8780](https://github.com/babel/babel/pull/8780) Run test262 tests for exportNamespaceFrom. ([@existentialism](https://github.com/existentialism)) +* `babel-helper-transform-fixture-test-runner` + * [#8768](https://github.com/babel/babel/pull/8768) Use babel-check-duplicated-nodes. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.1.0 (2018-09-17) + +Check http://babeljs.io/blog/2018/09/17/7.1.0 + +#### :rocket: New Feature +* `babel-cli`, `babel-core` + * [#8660](https://github.com/babel/babel/pull/8660) Better support monorepos by allowing users to opt into automatically resolving 'root' with `rootMode: "upward"`.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-helper-transform-fixture-test-runner` + * [#7582](https://github.com/babel/babel/pull/7582) Allow regular plugins/presets resolution algorithm for packages outsi…. ([@Andarist](https://github.com/Andarist)) +* `babel-helpers`, `babel-plugin-proposal-decorators`, `babel-plugin-syntax-decorators` + * [#7976](https://github.com/babel/babel/pull/7976) Add support for the new decorators proposal. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-helpers`, `babel-plugin-proposal-class-properties` + * [#8205](https://github.com/babel/babel/pull/8205) Private Static Fields Features: Stage 3. ([@rricard](https://github.com/rricard)) + +#### :bug: Bug Fix +* `babel-parser` + * [#8698](https://github.com/babel/babel/pull/8698) Fix parsing of newline between 'async' and 'function'. ([@existentialism](https://github.com/existentialism)) + * [#8677](https://github.com/babel/babel/pull/8677) Fix typescript parsing typed object shorthand methods. ([@existentialism](https://github.com/existentialism)) +* `babel-plugin-transform-typescript` + * [#8682](https://github.com/babel/babel/pull/8682) Fix TSParameterProperty getting lost with transform-classes. ([@existentialism](https://github.com/existentialism)) + * [#8695](https://github.com/babel/babel/pull/8695) Adjust TSParameterProperty handling to work with transform-parameters. ([@existentialism](https://github.com/existentialism)) + * [#8666](https://github.com/babel/babel/pull/8666) Fix typescript import elision. ([@Retsam](https://github.com/Retsam)) +* `babel-preset-env` + * [#8693](https://github.com/babel/babel/pull/8693) Fix es6.string.iterator mapping in babel-preset-env. ([@existentialism](https://github.com/existentialism)) +* `babel-core`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-plugin-transform-runtime` + * [#8659](https://github.com/babel/babel/pull/8659) Fix version checks in .availableHelper and transform-runtime definitions.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* Other + * [#8627](https://github.com/babel/babel/pull/8627) ts generator: allow reserved keywords in interfaces. ([@43081j](https://github.com/43081j)) +* `babel-plugin-transform-parameters` + * [#8414](https://github.com/babel/babel/pull/8414) Allow patterns as argument of RestElement. ([@microbouji](https://github.com/microbouji)) +* `babel-core`, `babel-plugin-transform-runtime` + * [#8624](https://github.com/babel/babel/pull/8624) Verify 'sourceMap' option with hasOwnProperty, and verify string-typed 'version'. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-helpers`, `babel-plugin-proposal-class-properties` + * [#8614](https://github.com/babel/babel/pull/8614) [static private] Unify loose handling of static and instance props. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :nail_care: Polish +* `babel-plugin-transform-runtime` + * [#8581](https://github.com/babel/babel/pull/8581) Fix grammar in error message at @babel/plugin-transform-runtime. ([@tricknotes](https://github.com/tricknotes)) +* `babel-parser` + * [#8576](https://github.com/babel/babel/pull/8576) More helpful errorr message for missing decoratorsBeforeExport in parser. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :memo: Documentation +* [#8561](https://github.com/babel/babel/pull/8561) Added pronounciation of babel. ([@siddhant1](https://github.com/siddhant1)) + +#### :house: Internal +* `babel-core` + * [#8714](https://github.com/babel/babel/pull/8714) Fix Flow error with new versionRange test.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* Other + * [#8679](https://github.com/babel/babel/pull/8679) remove force publish, temp tag [skip ci]. ([@hzoo](https://github.com/hzoo)) +* `babel-plugin-transform-runtime` + * [#8661](https://github.com/babel/babel/pull/8661) Makefile: run fix json on fix. ([@xtuc](https://github.com/xtuc)) +* `babel-*` + * [#8658](https://github.com/babel/babel/pull/8658) Format fixture options.json with Prettier.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-parser` + * [#8630](https://github.com/babel/babel/pull/8630) Bump flow to 0.80 and fix sourceType error. ([@existentialism](https://github.com/existentialism)) + * [#8610](https://github.com/babel/babel/pull/8610) types: missing `unambiguous` sourceType. ([@xtuc](https://github.com/xtuc)) + * [#8170](https://github.com/babel/babel/pull/8170) @babel/parser: expose a TypeScript definition file from package. ([@AviVahl](https://github.com/AviVahl)) +* `babel-*` + * [#8573](https://github.com/babel/babel/pull/8573) add access public to all packages [skip ci]. ([@hzoo](https://github.com/hzoo)) + +## v7.0.1 (2018-09-11) + +Doing a quick patch regarding helpers versioning to prevent future issues: https://github.com/babel/babel/pull/8659 + +## v7.0.0 (2018-08-27) + +No change from rc.4. Finally released as https://babeljs.io/blog/2018/08/27/7.0.0! + +## v7.0.0-rc.4 (2018-08-27) + +> Similar to removing proposals in `@babel/polyfill`, we are removing them in `transform-runtime` + +#### :boom: Breaking Change +* `babel-plugin-transform-runtime` + * [#8547](https://github.com/babel/babel/pull/8547) Remove nonstandard functions and fake prototype methods from babel-runtime. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-parser` + * [#8539](https://github.com/babel/babel/pull/8539) Update parser whitespace for clarity. ([@jridgewell](https://github.com/jridgewell)) + +#### :bug: Bug Fix +* `babel-register` + * [#8553](https://github.com/babel/babel/pull/8553) bump source-map-support. ([@hzoo](https://github.com/hzoo)) +* `babel-core` + * [#8546](https://github.com/babel/babel/pull/8546) Default highlightCode:true for the parser highlighting.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :house: Internal +* Other + * [#8554](https://github.com/babel/babel/pull/8554) Lerna: remove exact [skip ci]. ([@hzoo](https://github.com/hzoo)) +* `babel-parser` + * [#8540](https://github.com/babel/babel/pull/8540) Cleanup getLineInfo. ([@jridgewell](https://github.com/jridgewell)) + * [#8541](https://github.com/babel/babel/pull/8541) Update to ES6 String methods. ([@jridgewell](https://github.com/jridgewell)) + * [#8537](https://github.com/babel/babel/pull/8537) Flatten TokenType class hierarchy. ([@jridgewell](https://github.com/jridgewell)) + * [#8539](https://github.com/babel/babel/pull/8539) Update parser whitespace for clarity. ([@jridgewell](https://github.com/jridgewell)) + +## v7.0.0-rc.3 (2018-08-24) + +#### :boom: Breaking Change +* `babel-preset-env` + * [#8509](https://github.com/babel/babel/pull/8509) Add browserslist 4 support.. ([@yavorsky](https://github.com/yavorsky)) +* `babel-plugin-transform-runtime` + * [#8518](https://github.com/babel/babel/pull/8518) Make 'useESModules' only toggle CJS vs ESM helpers when importing file is ESM.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :rocket: New Feature +* `babel-plugin-transform-runtime` + * [#8520](https://github.com/babel/babel/pull/8520) Expose opt-in useESModules:"auto" from transform-runtime to toggle based on 'supportsStaticESM'. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :bug: Bug Fix +* `babel-helpers`, `babel-plugin-transform-classes`, `babel-preset-env` + * [#8501](https://github.com/babel/babel/pull/8501) [_wrapNativeSuper] Don't wrap non-native constructors. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-generator`, `babel-traverse`, `babel-types` + * [#8478](https://github.com/babel/babel/pull/8478) Fix path.scope.rename() to not change break clauses. ([@rafeca](https://github.com/rafeca)) +* `babel-plugin-proposal-object-rest-spread` + * [#8514](https://github.com/babel/babel/pull/8514) fix: object rest with default values bug. ([@jquense](https://github.com/jquense)) +* `babel-traverse` + * [#8505](https://github.com/babel/babel/pull/8505) Rename exported functions where name conflicts with param.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :house: Internal +* `babel-plugin-transform-object-set-prototype-of-to-assign` + * [#8409](https://github.com/babel/babel/pull/8409) Add LICENSE file to published npm packages [skip ci]. ([@opichals](https://github.com/opichals)) +* Other + * [#8504](https://github.com/babel/babel/pull/8504) Update Babel to rc.2. ([@hzoo](https://github.com/hzoo)) + +## v7.0.0-rc.2 (2018-08-21) + +A notable change is the addition of https://github.com/babel/babel/pull/8485 which enables https://github.com/babel/babel-loader/pull/660 (automatically doing `modules: false` for `@babel/preset-env` when using `babel-loader`. + +#### :boom: Breaking Change +* `babel-core` + * [#8470](https://github.com/babel/babel/pull/8470) Remove File#resolveModuleSource. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + * [#8473](https://github.com/babel/babel/pull/8473) Allow babel-plugin/preset prefix to not be a prefix, when used in a scope.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-core`, `babel-parser`, `babel-plugin-syntax-decorators` + * [#8465](https://github.com/babel/babel/pull/8465) Require decoratorsBeforeExport option for decorators. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +#### :rocket: New Feature +* `babel-preset-env` + * [#8500](https://github.com/babel/babel/pull/8500) Add missing es7.promise.finally polyfill when using useBuiltIns: usage. ([@jsnajdr](https://github.com/jsnajdr)) +* `babel-cli`, `babel-core`, `babel-node`, `babel-preset-env`, `babel-register` + * [#8485](https://github.com/babel/babel/pull/8485) Allow preset-env to toggle module handling based on flags from the caller (like babel-loader). ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-core` + * [#8474](https://github.com/babel/babel/pull/8474) Preserve 'false'-options for disabled plugins/presets.. ([@loganfsmyth](https://github.com/loganfsmyth)) + * [#8473](https://github.com/babel/babel/pull/8473) Allow babel-plugin/preset prefix to not be a prefix, when used in a scope.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-helper-transform-fixture-test-runner`, `babel-plugin-transform-runtime` + * [#8435](https://github.com/babel/babel/pull/8435) Allow transform-runtime to insert runtime references with absolute paths.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :bug: Bug Fix +* `babel-parser` + * [#8488](https://github.com/babel/babel/pull/8488) Fix trailingComments for FunctionExpression that is CallExpression arguments. ([@jiaxuan](https://github.com/jiaxuan)) +* `babel-core` + * [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-helpers`, `babel-plugin-proposal-decorators` + * [#7429](https://github.com/babel/babel/pull/7429) Fix default descriptor setting for class properties with decorators. ([@yhpark](https://github.com/yhpark)) +* `babel-plugin-transform-parameters` + * [#8479](https://github.com/babel/babel/pull/8479) Fixes setter paratemer default value. ([@nikolayemrikh](https://github.com/nikolayemrikh)) + +#### :nail_care: Polish +* `babel-core` + * [#8494](https://github.com/babel/babel/pull/8494) Cache individual programmatic descriptors along with the overall list.. ([@loganfsmyth](https://github.com/loganfsmyth)) + * [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :house: Internal +* `babel-core` + * [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-plugin-transform-classes` + * [#8472](https://github.com/babel/babel/pull/8472) Remove unused file. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) + +## v7.0.0-rc.1 (2018-08-09) + +Same as rc.0 but fixes the peerDep issue #8443. It's changed to just be ^7.0.0-0 + +## v7.0.0-rc.0 (2018-08-09) + +> This had an issue with `peerDependencies` so please use `rc.1`. + +Alright finally at the end 🙂. Shouldn't have anymore breaking changes and going to wait some time to fix bugs/regressions + +> Summary: `@babel/polyfill` will not include proposal polyfills by default and fixed a regression. + +#### :boom: Breaking Change +* `babel-polyfill` + * [#8440](https://github.com/babel/babel/pull/8440) remove proposals polyfills from default import [skip ci]. ([@hzoo](https://github.com/hzoo)) + +> Will add this to the upgrade guide/polyfill docs. I guess we could include a `babel-upgrade` for this too, not sure. + +#### :bug: Bug Fix +* `babel-cli` + * [#8436](https://github.com/babel/babel/pull/8436) Require v1.1.0 so that correct filter params are passed.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +## v7.0.0-beta.56 (2018-08-03) + +- Separate `@babel/runtime`: should work for helpers alone and opt-into core-js if necessary. +- More details in http://babeljs.io/docs/en/next/babel-runtime, http://babeljs.io/docs/en/next/babel-plugin-transform-runtime (via https://github.com/babel/babel/pull/8266, https://github.com/babel/website/pull/1714) +- `babel-upgrade` issue: https://github.com/babel/babel-upgrade/issues/70 + +#### :boom: Breaking Change +* `babel-plugin-transform-regenerator`, `babel-plugin-transform-runtime`, `babel-runtime-corejs2`, `babel-runtime` + * [#8266](https://github.com/babel/babel/pull/8266) Split @babel/runtime into 2 modules via @babel/runtime-corejs2. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-core`, `babel-helper-module-imports`, `babel-helpers`, `babel-plugin-external-helpers`, `babel-plugin-transform-runtime` + * [#8398](https://github.com/babel/babel/pull/8398) Only reference helpers from external/runtime helpers if they are known to be available.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :rocket: New Feature +* `babel-plugin-transform-regenerator`, `babel-plugin-transform-runtime`, `babel-runtime-corejs2`, `babel-runtime` + * [#8266](https://github.com/babel/babel/pull/8266) Split @babel/runtime into 2 modules via @babel/runtime-corejs2. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :bug: Bug Fix +* `babel-parser`, `babel-plugin-transform-typescript` + * [#8408](https://github.com/babel/babel/pull/8408) Allow TSInterfaceDeclaration to be default export. ([@existentialism](https://github.com/existentialism)) +* `babel-preset-env` + * [#8403](https://github.com/babel/babel/pull/8403) Ensure esmodule targets are parsed by browserslist. ([@existentialism](https://github.com/existentialism)) +* Other + * [#8024](https://github.com/babel/babel/pull/8024) Run transform-runtime on the standalone bundle so it stays ES5-compatible.. ([@loganfsmyth](https://github.com/loganfsmyth)) + +#### :memo: Documentation +* [#8412](https://github.com/babel/babel/pull/8412) Update Documentation[skip ci]. ([@leongjiameng](https://github.com/leongjiameng)) + +## v7.0.0-beta.55 (2018-07-28) + +Breaking Change in beta: + +> Throws an error on using Stage presets: https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets + +#### :boom: Breaking Change +* `babel-core`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-preset-stage-0`, `babel-preset-stage-1`, `babel-preset-stage-2`, `babel-preset-stage-3`, `babel-standalone` + * [#8293](https://github.com/babel/babel/pull/8293) Remove Stage presets. ([@hzoo](https://github.com/hzoo)) + +#### :rocket: New Feature +* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types` + * [#7754](https://github.com/babel/babel/pull/7754) TypeScript: Support type arguments on tagged templates. ([@andy-ms](https://github.com/andy-ms)) + +#### :bug: Bug Fix +* `babel-cli`, `babel-core`, `babel-generator` + * [#8380](https://github.com/babel/babel/pull/8380) Ensure that Identifier source mappings explicitly start and stop on the generated range. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-preset-env` + * [#8391](https://github.com/babel/babel/pull/8391) Ensure preset-env doesn't clobber browserslist defaults. ([@existentialism](https://github.com/existentialism)) +* `babel-core` + * [#8376](https://github.com/babel/babel/pull/8376) Fix order of optional argument reordering. ([@Qix-](https://github.com/Qix-)) + * [#8381](https://github.com/babel/babel/pull/8381) Allow an Array for `babelrcRoots`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg)) + * [#8342](https://github.com/babel/babel/pull/8342) Do not mutate ast. ([@thiagoarrais](https://github.com/thiagoarrais)) +* `babel-parser` + * [#8374](https://github.com/babel/babel/pull/8374) Correctly parse interface methods named 'static'. ([@bakkot](https://github.com/bakkot)) + +#### :nail_care: Polish +* `babel-parser` + * [#8355](https://github.com/babel/babel/pull/8355) remove .then from `dynamic import` parser exception message. ([@dnalborczyk](https://github.com/dnalborczyk)) + +#### :house: Internal +* `babel-core`, `babel-preset-stage-0`, `babel-preset-stage-1`, `babel-preset-stage-2`, `babel-preset-stage-3`, `babel-standalone` + * [#8397](https://github.com/babel/babel/pull/8397) Remove our own use of stage presets. ([@hzoo](https://github.com/hzoo)) +* `babel-helpers`, `babel-plugin-proposal-class-properties` + * [#8318](https://github.com/babel/babel/pull/8318) Save full descriptor instead of only value for private fields.. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)) +* `babel-core` + * [#8381](https://github.com/babel/babel/pull/8381) Allow an Array for `babelrcRoots`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg)) +* `babel-cli`, `babel-core`, `babel-generator`, `babel-helper-define-map`, `babel-helper-fixtures`, `babel-helper-module-imports`, `babel-helper-module-transforms`, `babel-helper-regex`, `babel-helper-simple-access`, `babel-helper-transform-fixture-test-runner`, `babel-node`, `babel-plugin-transform-block-scoping`, `babel-register`, `babel-template`, `babel-traverse`, `babel-types` + * [#8377](https://github.com/babel/babel/pull/8377) Bumped lodash to 4.17.10. ([@Berkmann18](https://github.com/Berkmann18)) + ## v7.0.0-beta.54 (2018-07-16) > Regarding https://github.com/babel/babel/issues/8184, we aren't using `micromatch` for paths, just basic `*/**` substitution now. For anything more complicated we will recommend using a regex/`.js` config. @@ -40,7 +1052,7 @@ See [Babylon's CHANGELOG](packages/babylon/CHANGELOG.md) for the Babylon pre-7.0 ## v7.0.0-beta.53 (2018-07-11) - Fix for regression with paths on windows due to micromatch upgrade, remove yearly presets (not published) -- (There was an issue with the Stage presets in this release, but it is also deprecated) +- (There was an issue with the Stage presets in this release, but it is also deprecated) #### :boom: Breaking Change * `babel-*` @@ -1694,7 +2706,7 @@ Initial release of typescript equivalent of how Babel handles flow with a new `b * `babel-plugin-check-es2015-constants` * [#5930](https://github.com/babel/babel/pull/5930) Spec compliancy of check-es2015-constants plugin. ([@maurobringolf](https://github.com/maurobringolf)) -> Instead of throwing a compile time error when const is violated, Babel should insert a throw statement before the violation. +> Instead of throwing a compile time error when const is violated, Babel should insert a throw statement before the violation. #### :boom: Breaking Change * `babel-plugin-transform-flow-comments` @@ -2261,7 +3273,7 @@ Also started Babel to compile itself with Babel 7! (We'll be working on making i #### :nail_care: Polish * `babel-register` - * [#5411](https://github.com/babel/babel/pull/5411) Seperate version env cache files. ([@pwmckenna](https://github.com/pwmckenna)) + * [#5411](https://github.com/babel/babel/pull/5411) Separate version env cache files. ([@pwmckenna](https://github.com/pwmckenna)) #### :memo: Documentation * `babel-plugin-transform-runtime` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c5a3ec7910c..e7b9bd953b54 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -310,7 +310,7 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe - Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more. - The pull request should include: - [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal) - - [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/bloc/master/packages/babel-parser/ast/spec.md) + - [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md) - [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior) - [ ] Add failing/passing tests according to spec behavior - Start working about the Babel transform itself! diff --git a/Gulpfile.js b/Gulpfile.js index a03b34f15915..5df9882ca3f2 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -6,19 +6,17 @@ const chalk = require("chalk"); const newer = require("gulp-newer"); const babel = require("gulp-babel"); const gulpWatch = require("gulp-watch"); -const gutil = require("gulp-util"); +const fancyLog = require("fancy-log"); const filter = require("gulp-filter"); const gulp = require("gulp"); const path = require("path"); const webpack = require("webpack"); const merge = require("merge-stream"); -const rollup = require("rollup-stream"); -const source = require("vinyl-source-stream"); -const buffer = require("vinyl-buffer"); +const rollup = require("rollup"); const rollupBabel = require("rollup-plugin-babel"); const rollupNodeResolve = require("rollup-plugin-node-resolve"); -const registerStandalonePackageTask = require("./scripts/gulp-tasks") - .registerStandalonePackageTask; +const rollupReplace = require("rollup-plugin-replace"); +const { registerStandalonePackageTask } = require("./scripts/gulp-tasks"); const sources = ["codemods", "packages"]; @@ -36,13 +34,9 @@ function getIndexFromPackage(name) { return `${name}/src/index.js`; } -function compilationLogger(rollup) { +function compilationLogger() { return through.obj(function(file, enc, callback) { - gutil.log( - `Compiling '${chalk.cyan(file.relative)}'${ - rollup ? " with rollup " : "" - }...` - ); + fancyLog(`Compiling '${chalk.cyan(file.relative)}'...`); callback(null, file); }); } @@ -50,7 +44,7 @@ function compilationLogger(rollup) { function errorsLogger() { return plumber({ errorHandler(err) { - gutil.log(err.stack); + fancyLog(err.stack); }, }); } @@ -91,32 +85,40 @@ function buildBabel(exclude) { } function buildRollup(packages) { - return merge( + return Promise.all( packages.map(pkg => { - return rollup({ - input: getIndexFromPackage(pkg), - format: "cjs", - plugins: [ - rollupBabel({ - envName: "babel-parser", - }), - rollupNodeResolve(), - ], - }) - .pipe(source("index.js")) - .pipe(buffer()) - .pipe(errorsLogger()) - .pipe(compilationLogger(/* rollup */ true)) - .pipe(gulp.dest(path.join(pkg, "lib"))); + const input = getIndexFromPackage(pkg); + fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`); + return rollup + .rollup({ + input, + plugins: [ + rollupReplace({ + "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), + }), + rollupBabel({ + envName: "babel-parser", + }), + rollupNodeResolve(), + ], + }) + .then(bundle => { + return bundle.write({ + file: path.join(pkg, "lib/index.js"), + format: "cjs", + name: "babel-parser", + sourcemap: process.env.NODE_ENV !== "production", + }); + }); }) ); } -gulp.task("build", function() { - const bundles = ["packages/babel-parser"]; +const bundles = ["packages/babel-parser"]; - return merge([buildBabel(/* exclude */ bundles), buildRollup(bundles)]); -}); +gulp.task("build-rollup", () => buildRollup(bundles)); +gulp.task("build-babel", () => buildBabel(/* exclude */ bundles)); +gulp.task("build", gulp.parallel("build-rollup", "build-babel")); gulp.task("default", gulp.series("build")); @@ -138,7 +140,7 @@ registerStandalonePackageTask( "babel", "Babel", path.join(__dirname, "packages"), - require("./packages/babel-core/package.json").version + require("./packages/babel-standalone/package.json").version ); const presetEnvWebpackPlugins = [ @@ -167,6 +169,6 @@ registerStandalonePackageTask( "babel-preset-env", "babelPresetEnv", path.join(__dirname, "packages"), - require("./packages/babel-preset-env/package.json").version, + require("./packages/babel-preset-env-standalone/package.json").version, presetEnvWebpackPlugins ); diff --git a/LICENSE b/LICENSE index a06ec0e70f28..f31575ec773b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2018 Sebastian McKenzie and other contributors +Copyright (c) 2014-present Sebastian McKenzie and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Makefile b/Makefile index 0e50484068f1..5fa5cb0cfdbf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ MAKEFLAGS = -j1 -FLOW_COMMIT = bea8b83f50f597454941d2a7ecef6e93a881e576 -TEST262_COMMIT = f90a52b39609a620c0854e0bd0b3a906c930fd17 +FLOW_COMMIT = 09669846b7a7ca5a6c23c12d56bb3bebdafd67e9 +TEST262_COMMIT = de567d3aa5de4eaa11e00131d26b9fe77997dfb0 # Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967 export FORCE_COLOR = true @@ -11,12 +11,13 @@ SOURCES = packages codemods build: clean clean-lib ./node_modules/.bin/gulp build + node ./packages/babel-standalone/scripts/generate.js node ./packages/babel-types/scripts/generateTypeHelpers.js # call build again as the generated files might need to be compiled again. ./node_modules/.bin/gulp build # generate flow and typescript typings - node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow - node scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts + node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow + node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts ifneq ("$(BABEL_COVERAGE)", "true") make build-standalone make build-preset-env-standalone @@ -28,6 +29,12 @@ build-standalone: build-preset-env-standalone: ./node_modules/.bin/gulp build-babel-preset-env-standalone +prepublish-build-standalone: + BABEL_ENV=production IS_PUBLISH=true ./node_modules/.bin/gulp build-babel-standalone + +prepublish-build-preset-env-standalone: + BABEL_ENV=production IS_PUBLISH=true ./node_modules/.bin/gulp build-babel-preset-env-standalone + build-dist: build cd packages/babel-polyfill; \ scripts/build-dist.sh @@ -40,7 +47,8 @@ watch: clean clean-lib # development too. BABEL_ENV=development ./node_modules/.bin/gulp build-no-bundle node ./packages/babel-types/scripts/generateTypeHelpers.js - node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow + node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow + node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts BABEL_ENV=development ./node_modules/.bin/gulp watch flow: @@ -56,6 +64,7 @@ fix-json: ./node_modules/.bin/prettier "{packages,codemod}/*/test/fixtures/**/options.json" --write --loglevel warn clean: test-clean + rm -f .npmrc rm -rf packages/babel-polyfill/browser* rm -rf packages/babel-polyfill/dist rm -rf coverage @@ -82,7 +91,7 @@ test-ci-coverage: bootstrap-flow: rm -rf ./build/flow mkdir -p ./build - git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/facebook/flow.git ./build/flow + git clone --branch=master --single-branch --shallow-since=2018-11-01 https://github.com/facebook/flow.git ./build/flow cd build/flow && git checkout $(FLOW_COMMIT) test-flow: @@ -96,7 +105,7 @@ test-flow-update-whitelist: bootstrap-test262: rm -rf ./build/test262 mkdir -p ./build - git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/tc39/test262.git ./build/test262 + git clone --branch=master --single-branch --shallow-since=2019-01-01 https://github.com/tc39/test262.git ./build/test262 cd build/test262 && git checkout $(TEST262_COMMIT) test-test262: @@ -115,22 +124,39 @@ prepublish-build: rm -rf packages/babel-runtime/helpers rm -rf packages/babel-runtime-corejs2/helpers rm -rf packages/babel-runtime-corejs2/core-js - BABEL_ENV=production make build-dist + NODE_ENV=production BABEL_ENV=production make build-dist make clone-license prepublish: - git pull --rebase + make bootstrap-only make prepublish-build make test +new-version: + git pull --rebase + ./node_modules/.bin/lerna version --force-publish="@babel/runtime,@babel/runtime-corejs2,@babel/runtime-corejs3,@babel/standalone,@babel/preset-env-standalone" + +# NOTE: Run make new-version first publish: prepublish - # --only-explicit-updates - ./node_modules/.bin/lerna publish + ./node_modules/.bin/lerna publish from-git --require-scripts make clean -bootstrap: clean-all +publish-ci: prepublish +ifneq ("$(NPM_TOKEN)", "") + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc +else + echo "Missing NPM_TOKEN env var" + exit 1 +endif + ./node_modules/.bin/lerna publish from-git --require-scripts --yes + rm -f .npmrc + make clean + +bootstrap-only: clean-all yarn --ignore-engines ./node_modules/.bin/lerna bootstrap -- --ignore-engines + +bootstrap: bootstrap-only make build cd packages/babel-plugin-transform-runtime; \ node scripts/build-dist.js diff --git a/README.md b/README.md index cc2f50d52efa..579b85a7cd88 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,16 @@ The compiler for writing next generation JavaScript.

+

+ v7 npm Downloads + v6 npm Downloads +

Travis Status CircleCI Status Coverage Status Slack Status - npm Downloads + Follow on Twitter

Supporting Babel

@@ -27,11 +31,11 @@ Babel (pronounced ["babble"](https://soundcloud.com/sebmck/how-to-pronounce-babel)) is a community-driven project used by many companies and projects, and is maintained by a group of [volunteers](https://babeljs.io/team). If you'd like to help support the future of the project, please consider: - Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/) for guidance!) -- Giving funds by becoming a sponsor (see below)! +- Giving funds by becoming a sponsor on [Open Collective](https://opencollective.com/babel) or [Patreon](https://www.patreon.com/henryzhu)! -## Open Collective Sponsors +## Sponsors -Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/babel#sponsor)] +Our top sponsors are shown below! [[Become a sponsor](https://opencollective.com/babel#sponsor)] @@ -48,35 +52,6 @@ Become a sponsor and get your logo on our README on Github with a link to your s - - - - - - - - - - - - - - - - -## Patreon Sponsors - -Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://www.patreon.com/henryzhu)] - -## Silver - - - -## Bronze - - - -

Mike Sherov

## Intro @@ -103,11 +78,11 @@ Try it out at our [REPL](https://babeljs.io/repl/build/master#?code_lz=NoRgNATGD ### Who maintains Babel? -Mostly a handful of volunteers! Please check out our [team page](https://babeljs.io/team)! +Mostly a handful of volunteers, funded by you! Please check out our [team page](https://babeljs.io/team)! ### Looking for support? -For questions and support please visit join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs). +For questions and support please join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs). ### Is there a Babel song? diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000000..7fe81999cccc --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +# Security Policy + +## Supported Versions + +This is the list of versions of `babel` which are +currently being supported with security updates. + +| Version | Supported | +| -------- | ------------------ | +| 7.x | :white_check_mark: | +| 6.26.x | :white_check_mark: | +| < 6.26.0 | :x: | + +## Reporting a Vulnerability + +To report a vulnerability please send an email with the details to security@babeljs.io. +This will help us to assess the risk and start the necessary steps. + +Thanks for helping to keep babel secure. diff --git a/SONG.md b/SONG.md index a6939e15af28..234b5ed3e373 100644 --- a/SONG.md +++ b/SONG.md @@ -19,7 +19,8 @@ Generators, const and let I used them all without regret And it’s a terse and a destructured Hallelujah -Hallelujah etc. +Hallelujah, Hallelujah +Hallelujah, Hallelujah Well my faith was strong but I needed proof The standard was my source of truth @@ -28,7 +29,9 @@ So even though you weren’t impressed I checked the build against the spec And it’s a more-or-less compliant Hallelujah -Hallelujah etc. + +Hallelujah, Hallelujah +Hallelujah, Hallelujah Now you say the build step’s too complex And you claim no need for ES Next @@ -37,7 +40,9 @@ But your code grows older with each line It’s a joyless dirge on a withered vine It’s a threnody for a bygone Hallelujah -Hallelujah etc. + +Hallelujah, Hallelujah +Hallelujah, Hallelujah Yes I learned about the danger signs How they’d polyfilled a thousand lines @@ -46,7 +51,9 @@ Still I disregarded common sense Now my source is small but the build’s immense And it’s a slow and unresponsive Hallelujah -Hallelujah etc. + +Hallelujah, Hallelujah +Hallelujah, Hallelujah There was a time when they let me know What’s really going on below @@ -55,7 +62,9 @@ And debugging’s not a progress march It’s a frenzied fumble in the dark It’s a labyrinthine search for Hallelujah -Hallelujah etc. + +Hallelujah, Hallelujah +Hallelujah, Hallelujah Well, maybe there’s a god up there But all I ever got from prayers @@ -64,6 +73,8 @@ And that anguished cry you hear at night Is the plugin I forgot to write It’s a cold and it’s a broken Hallelujah -Hallelujah etc. + +Hallelujah, Hallelujah +Hallelujah, Hallelujah [Angus Croll](https://github.com/angus-c) diff --git a/babel.config.js b/babel.config.js index ce4eb1d5653c..82966a7f07ca 100644 --- a/babel.config.js +++ b/babel.config.js @@ -5,21 +5,26 @@ module.exports = function(api) { const includeCoverage = process.env.BABEL_COVERAGE === "true"; - const envOpts = { + const envOptsNoTargets = { loose: true, modules: false, exclude: ["transform-typeof-symbol"], }; + const envOpts = Object.assign({}, envOptsNoTargets); let convertESM = true; let ignoreLib = true; let includeRuntime = false; + const nodeVersion = "6.9"; switch (env) { // Configs used during bundling builds. case "babel-parser": convertESM = false; ignoreLib = false; + envOpts.targets = { + node: nodeVersion, + }; break; case "standalone": convertESM = false; @@ -29,7 +34,7 @@ module.exports = function(api) { case "production": // Config during builds before publish. envOpts.targets = { - node: "6.9", + node: nodeVersion, }; break; case "development": @@ -93,6 +98,11 @@ module.exports = function(api) { convertESM ? "@babel/transform-modules-commonjs" : null, ].filter(Boolean), }, + { + test: "./packages/babel-polyfill", + presets: [["@babel/env", envOptsNoTargets]], + plugins: [["@babel/transform-modules-commonjs", { lazy: false }]], + }, { // The vast majority of our src files are modules, but we use // unambiguous to keep things simple until we get around to renaming @@ -111,9 +121,11 @@ module.exports = function(api) { "packages/babel-runtime", /[\\/]node_modules[\\/](?:@babel\/runtime|babel-runtime|core-js)[\\/]/, ], - plugins: [includeRuntime ? "@babel/transform-runtime" : null].filter( - Boolean - ), + plugins: [ + includeRuntime + ? ["@babel/transform-runtime", { version: "7.4.4" }] + : null, + ].filter(Boolean), }, ].filter(Boolean), }; diff --git a/codecov.yml b/codecov.yml index 9937c4cc4949..ed4545a1bf7d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,3 +8,5 @@ coverage: target: "80%" patch: enabled: false +ignore: + - packages/babel-types/src/*/generated/index.js diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/input.js b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/input.js deleted file mode 100644 index 520eab559fbd..000000000000 --- a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/input.js +++ /dev/null @@ -1,5 +0,0 @@ -try { - throw 0; -} catch (e) { - let e = new TypeError('Duplicate variable declaration; will throw an error.'); -} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json deleted file mode 100644 index ab01b7471a66..000000000000 --- a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "plugins": ["../../../../lib"], - "throws": "Duplicate declaration \"e\"" -} diff --git a/eslint-local-rules.js b/eslint-local-rules.js deleted file mode 100644 index 73af83e4840e..000000000000 --- a/eslint-local-rules.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -const noDeprecatedClone = require("./scripts/eslint_rules/no-deprecated-clone"); -const noUndefinedIdentifier = require("./scripts/eslint_rules/no-undefined-identifier"); - -module.exports = { - "no-deprecated-clone": noDeprecatedClone, - "no-undefined-identifier": noUndefinedIdentifier, -}; diff --git a/lerna.json b/lerna.json index 0a083def2273..10d091d9337f 100644 --- a/lerna.json +++ b/lerna.json @@ -1,34 +1,34 @@ { - "lerna": "2.11.0", - "version": "7.1.0", + "version": "7.5.5", "changelog": { "repo": "babel/babel", "cacheDir": ".changelog", "labels": { - "PR: Spec Compliancy :eyeglasses:": ":eyeglasses: Spec Compliancy", + "PR: Spec Compliance :eyeglasses:": ":eyeglasses: Spec Compliance", "PR: Breaking Change :boom:": ":boom: Breaking Change", "PR: New Feature :rocket:": ":rocket: New Feature", "PR: Bug Fix :bug:": ":bug: Bug Fix", "PR: Polish :nail_care:": ":nail_care: Polish", "PR: Docs :memo:": ":memo: Documentation", - "PR: Internal :house:": ":house: Internal" + "PR: Internal :house:": ":house: Internal", + "PR: Performance :running_woman:": ":running_woman: Performance" } }, - "commands": { + "command": { "publish": { - "ignore": [ + "ignoreChanges": [ "*.md", - "*.json", "*.txt", "test/**", "codemods/**", - "package.json" + "# We ignore every JSON file, except for built-in-modules, built-ins and plugins defined in babel-preset-env/data.", + "@(!(built-in-modules|built-ins|plugins|package)).json" ] } }, "packages": [ - "packages/*", - "codemods/*" + "codemods/*", + "packages/*" ], "npmClient": "yarn", "npmClientArgs": [ diff --git a/lib/third-party-libs.js.flow b/lib/third-party-libs.js.flow index 74913a5df11a..c21a2797acfe 100644 --- a/lib/third-party-libs.js.flow +++ b/lib/third-party-libs.js.flow @@ -2,12 +2,6 @@ * Basic declarations for the npm modules we use. */ -declare module "micromatch" { - declare module.exports: { - (Array, Array, ?{ nocase: boolean }): Array, - }; -} - declare module "resolve" { declare export default { sync: (string, {| basedir: string |}) => string; @@ -33,16 +27,31 @@ declare module "lodash/merge" { } declare module "semver" { + declare class SemVer { + build: Array; + loose: ?boolean; + major: number; + minor: number; + patch: number; + prerelease: Array; + raw: string; + version: string; + + constructor(version: string | SemVer): SemVer; + } + declare module.exports: { - valid(v: string): boolean; + SemVer: SemVer; + + coerce(version: string | SemVer): SemVer | null; gt(v1: string, v2: string): boolean; + intersects(r1: string, r2: string): boolean; lt(v1: string, v2: string): boolean; major(v: string): number; minor(v: string): number; patch(v: string): number; satisfies(v1: string, r1: string): boolean; - - intersects(r1: string, r2: string): boolean; + valid(v: string): boolean; } } @@ -186,3 +195,13 @@ declare module "js-levenshtein" { (string, string): number, }; } + +declare module "core-js-compat/data" { + declare type Target = "node" | "chrome" | "opera" | "edge" | "firefox" | "safari" | "ie" | "ios" | "android" | "electron" | "samsung"; + + declare module.exports: { + [key: string]: { + [target: Target]: string; + } + } +} diff --git a/package.json b/package.json index 3dd415a9d732..bd04e0638455 100644 --- a/package.json +++ b/package.json @@ -6,73 +6,75 @@ "build": "make build", "fix": "make fix", "lint": "make lint", - "precommit": "lint-staged", "test": "make test" }, "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/plugin-proposal-class-properties": "^7.0.0", - "@babel/plugin-proposal-export-namespace-from": "^7.0.0", - "@babel/plugin-proposal-numeric-separator": "^7.0.0", - "@babel/plugin-transform-modules-commonjs": "^7.0.0", - "@babel/plugin-transform-runtime": "^7.0.0", - "@babel/preset-env": "^7.0.0", + "@babel/cli": "^7.4.4", + "@babel/core": "^7.4.5", + "@babel/eslint-plugin-development": "^1.0.1", + "@babel/plugin-proposal-class-properties": "^7.4.4", + "@babel/plugin-proposal-export-namespace-from": "^7.2.0", + "@babel/plugin-proposal-numeric-separator": "^7.2.0", + "@babel/plugin-transform-modules-commonjs": "^7.4.4", + "@babel/plugin-transform-runtime": "^7.4.4", + "@babel/preset-env": "^7.4.5", "@babel/preset-flow": "^7.0.0", - "@babel/register": "^7.0.0", - "@babel/runtime": "^7.0.0", - "babel-core": "^7.0.0-0", - "babel-eslint": "^9.0.0", - "babel-jest": "^23.4.0", - "babel-loader": "8.0.0-beta.4", - "babel-plugin-transform-charcodes": "^0.1.0", - "browserify": "^16.2.2", + "@babel/register": "^7.4.4", + "@babel/runtime": "^7.4.5", + "babel-eslint": "^11.0.0-beta.0", + "babel-jest": "^24.8.0", + "babel-loader": "^8.0.6", + "babel-plugin-transform-charcodes": "^0.2.0", + "browserify": "^16.2.3", "bundle-collapser": "^1.2.1", - "chalk": "^2.3.2", - "charcodes": "^0.1.0", + "chalk": "^2.4.2", + "charcodes": "^0.2.0", "derequire": "^2.0.2", + "duplicate-package-checker-webpack-plugin": "^2.1.0", "enhanced-resolve": "^3.0.0", - "eslint": "^5.3.0", - "eslint-config-babel": "^8.0.0", - "eslint-plugin-flowtype": "^2.50.0", - "eslint-plugin-local-rules": "0.1.0", - "eslint-plugin-prettier": "^2.6.2", - "flow-bin": "^0.80.0", - "graceful-fs": "^4.1.11", - "gulp": "^4.0.0", - "gulp-babel": "^8.0.0-beta.2", + "eslint": "^5.16.0", + "eslint-config-babel": "^9.0.0", + "eslint-plugin-flowtype": "^3.8.2", + "eslint-plugin-import": "^2.17.2", + "eslint-plugin-prettier": "^3.1.0", + "fancy-log": "^1.3.3", + "flow-bin": "^0.94.0", + "graceful-fs": "^4.1.15", + "gulp": "^4.0.2", + "gulp-babel": "^8.0.0", "gulp-filter": "^5.1.0", "gulp-newer": "^1.0.0", - "gulp-plumber": "^1.0.1", - "gulp-rename": "^1.2.2", - "gulp-uglify": "^3.0.0", - "gulp-util": "^3.0.7", - "gulp-watch": "^5.0.0", - "husky": "^0.14.3", - "jest": "^23.4.1", - "lerna": "^2.11.0", + "gulp-plumber": "^1.2.1", + "gulp-rename": "^1.4.0", + "gulp-uglify": "^3.0.2", + "gulp-watch": "^5.0.1", + "husky": "^2.3.0", + "jest": "^24.8.0", + "lerna": "^3.14.2", "lerna-changelog": "^0.5.0", - "lint-staged": "^6.0.1", - "lodash": "^4.17.10", + "lint-staged": "^8.1.7", + "lodash": "^4.17.13", "merge-stream": "^1.0.1", "output-file-sync": "^2.0.0", - "prettier": "^1.13.7", - "pump": "^1.0.2", - "rimraf": "^2.4.3", - "rollup-plugin-babel": "^4.0.0-beta.0", - "rollup-plugin-node-resolve": "^3.0.2", - "rollup-stream": "^1.24.1", + "prettier": "^1.17.1", + "pump": "^3.0.0", + "rimraf": "^2.6.3", + "rollup": "^1.12.0", + "rollup-plugin-babel": "^4.0.0", + "rollup-plugin-node-resolve": "^5.0.0", + "rollup-plugin-replace": "^2.2.0", "test262-stream": "^1.2.0", "through2": "^2.0.0", - "uglify-js": "^2.4.16", - "vinyl-buffer": "^1.0.1", - "vinyl-source-stream": "^2.0.0", + "warnings-to-errors-webpack-plugin": "^2.0.0", "webpack": "^3.4.1", "webpack-dependency-suite": "^2.4.4", "webpack-stream": "^4.0.0" }, + "resolutions": { + "@lerna/**/@lerna/collect-updates": "https://github.com/babel/lerna.git#babel-collect-updates" + }, "engines": { - "node": ">= 6.9.0 <= 11.0.0-0", + "node": ">= 6.9.0 < 13.0.0", "npm": ">= 3.x <= 6.x", "yarn": ">=0.27.5 || >=1.0.0-20170811" }, @@ -81,6 +83,11 @@ "eslint --format=codeframe" ] }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, "jest": { "collectCoverageFrom": [ "packages/*/src/**/*.mjs", @@ -102,7 +109,9 @@ "_browser\\.js" ], "testEnvironment": "node", - "setupTestFrameworkScriptFile": "/test/testSetupFile.js", + "setupFilesAfterEnv": [ + "/test/testSetupFile.js" + ], "transformIgnorePatterns": [ "/node_modules/", "/packages/babel-standalone/babel(\\.min)?\\.js", @@ -121,6 +130,10 @@ "/test/tmp/", "/test/__data__/", "/build/" - ] - } + ], + "moduleNameMapper": { + "^@babel/([a-zA-Z0-9_-]+)$": "/packages/babel-$1/" + } + }, + "dependencies": {} } diff --git a/packages/babel-cli/package.json b/packages/babel-cli/package.json index e5446c644c0e..0b4bd8731363 100644 --- a/packages/babel-cli/package.json +++ b/packages/babel-cli/package.json @@ -1,6 +1,6 @@ { "name": "@babel/cli", - "version": "7.1.0", + "version": "7.5.5", "description": "Babel command line.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -23,21 +23,21 @@ "convert-source-map": "^1.1.0", "fs-readdir-recursive": "^1.1.0", "glob": "^7.0.0", - "lodash": "^4.17.10", + "lodash": "^4.17.13", "mkdirp": "^0.5.1", "output-file-sync": "^2.0.0", "slash": "^2.0.0", "source-map": "^0.5.0" }, "optionalDependencies": { - "chokidar": "^2.0.3" + "chokidar": "^2.0.4" }, "peerDependencies": { "@babel/core": "^7.0.0-0" }, "devDependencies": { - "@babel/core": "^7.0.0", - "@babel/helper-fixtures": "^7.0.0" + "@babel/core": "^7.5.5", + "@babel/helper-fixtures": "^7.5.5" }, "bin": { "babel": "./bin/babel.js", diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js index 31433b33da3f..f0678e27ed39 100644 --- a/packages/babel-cli/src/babel/file.js +++ b/packages/babel-cli/src/babel/file.js @@ -137,7 +137,11 @@ export default async function({ cliOptions, babelOptions }) { const dirname = filename; util - .readdirForCompilable(filename, cliOptions.includeDotfiles) + .readdirForCompilable( + filename, + cliOptions.includeDotfiles, + cliOptions.extensions, + ) .forEach(function(filename) { _filenames.push(path.join(dirname, filename)); }); diff --git a/packages/babel-cli/src/babel/options.js b/packages/babel-cli/src/babel/options.js index 16a9c025bcd9..41cc0fb83e7f 100644 --- a/packages/babel-cli/src/babel/options.js +++ b/packages/babel-cli/src/babel/options.js @@ -22,7 +22,7 @@ commander.option( "comma-separated list of plugin names", collect, ); -commander.option("--config-file [path]", "Path a to .babelrc file to use"); +commander.option("--config-file [path]", "Path to a .babelrc file to use"); commander.option( "--env-name [name]", "The name of the 'env' to use when loading configs and plugins. " + @@ -81,7 +81,7 @@ commander.option( "print a comment after any injected non-user code", ); -// General soucemap formatting. +// General source map formatting. commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify); commander.option( "--source-map-target [string]", @@ -221,36 +221,47 @@ export default function parseArgv(args: Array) { const opts = commander.opts(); + const babelOptions = { + presets: opts.presets, + plugins: opts.plugins, + rootMode: opts.rootMode, + configFile: opts.configFile, + envName: opts.envName, + sourceType: opts.sourceType, + ignore: opts.ignore, + only: opts.only, + retainLines: opts.retainLines, + compact: opts.compact, + minified: opts.minified, + auxiliaryCommentBefore: opts.auxiliaryCommentBefore, + auxiliaryCommentAfter: opts.auxiliaryCommentAfter, + sourceMaps: opts.sourceMaps, + sourceFileName: opts.sourceFileName, + sourceRoot: opts.sourceRoot, + moduleRoot: opts.moduleRoot, + moduleIds: opts.moduleIds, + moduleId: opts.moduleId, + + // Commander will default the "--no-" arguments to true, but we want to + // leave them undefined so that @babel/core can handle the + // default-assignment logic on its own. + babelrc: opts.babelrc === true ? undefined : opts.babelrc, + highlightCode: opts.highlightCode === true ? undefined : opts.highlightCode, + comments: opts.comments === true ? undefined : opts.comments, + }; + + // If the @babel/cli version is newer than the @babel/core version, and we have added + // new options for @babel/core, we'll potentially get option validation errors from + // @babel/core. To avoid that, we delete undefined options, so @babel/core will only + // give the error if users actually pass an unsupported CLI option. + for (const key of Object.keys(babelOptions)) { + if (babelOptions[key] === undefined) { + delete babelOptions[key]; + } + } + return { - babelOptions: { - presets: opts.presets, - plugins: opts.plugins, - rootMode: opts.rootMode, - configFile: opts.configFile, - envName: opts.envName, - sourceType: opts.sourceType, - ignore: opts.ignore, - only: opts.only, - retainLines: opts.retainLines, - compact: opts.compact, - minified: opts.minified, - auxiliaryCommentBefore: opts.auxiliaryCommentBefore, - auxiliaryCommentAfter: opts.auxiliaryCommentAfter, - sourceMaps: opts.sourceMaps, - sourceFileName: opts.sourceFileName, - sourceRoot: opts.sourceRoot, - moduleRoot: opts.moduleRoot, - moduleIds: opts.moduleIds, - moduleId: opts.moduleId, - - // Commander will default the "--no-" arguments to true, but we want to - // leave them undefined so that @babel/core can handle the - // default-assignment logic on its own. - babelrc: opts.babelrc === true ? undefined : opts.babelrc, - highlightCode: - opts.highlightCode === true ? undefined : opts.highlightCode, - comments: opts.comments === true ? undefined : opts.comments, - }, + babelOptions, cliOptions: { filename: opts.filename, filenames, diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js index ad972fd0cd15..99c9ae9b00cd 100644 --- a/packages/babel-cli/src/babel/util.js +++ b/packages/babel-cli/src/babel/util.js @@ -29,8 +29,11 @@ export function readdir( export function readdirForCompilable( dirname: string, includeDotfiles: boolean, + altExts?: Array, ) { - return readdir(dirname, includeDotfiles, isCompilableExtension); + return readdir(dirname, includeDotfiles, function(filename) { + return isCompilableExtension(filename, altExts); + }); } /** diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/bar/bar.es b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/bar/bar.es new file mode 100644 index 000000000000..9e99278492df --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/bar/bar.es @@ -0,0 +1 @@ + (() => 42) \ No newline at end of file diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/foo.es b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/foo.es new file mode 100644 index 000000000000..4bc9539528d4 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/in-files/src/foo.es @@ -0,0 +1 @@ +arr.map(x => x * MULTIPLIER); diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/options.json b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/options.json new file mode 100644 index 000000000000..cb501c3b853c --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/options.json @@ -0,0 +1,3 @@ +{ + "args": ["src", "--out-file", "test.js", "--extensions", ".es"] +} diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/out-files/test.js b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/out-files/test.js new file mode 100644 index 000000000000..d3e579815a50 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/out-files/test.js @@ -0,0 +1,10 @@ +"use strict"; + +(function () { + return 42; +}); +"use strict"; + +arr.map(function (x) { + return x * MULTIPLIER; +}); diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/stdout.txt b/packages/babel-cli/test/fixtures/babel/dir --out-file --extensions/stdout.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index 0654cadf0d16..64f64273319c 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -86,7 +86,7 @@ const assertTest = function(stdout, stderr, opts, cwd) { } if (opts.outFiles) { - const actualFiles = readDir(path.join(tmpLoc), fileFilter); + const actualFiles = readDir(tmpLoc, fileFilter); Object.keys(actualFiles).forEach(function(filename) { if ( @@ -171,12 +171,12 @@ const buildTest = function(binName, testName, opts) { }; fs.readdirSync(fixtureLoc).forEach(function(binName) { - if (binName[0] === ".") return; + if (binName.startsWith(".")) return; const suiteLoc = path.join(fixtureLoc, binName); describe("bin/" + binName, function() { fs.readdirSync(suiteLoc).forEach(function(testName) { - if (testName[0] === ".") return; + if (testName.startsWith(".")) return; const testLoc = path.join(suiteLoc, testName); diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json index 7e0609b321b4..0b753eb11230 100644 --- a/packages/babel-code-frame/package.json +++ b/packages/babel-code-frame/package.json @@ -1,6 +1,6 @@ { "name": "@babel/code-frame", - "version": "7.0.0", + "version": "7.5.5", "description": "Generate errors that contain a code frame that point to source locations.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", diff --git a/packages/babel-code-frame/src/index.js b/packages/babel-code-frame/src/index.js index 11e0095aa8ab..0aae7fabcd23 100644 --- a/packages/babel-code-frame/src/index.js +++ b/packages/babel-code-frame/src/index.js @@ -76,7 +76,7 @@ function getMarkerLines( } else if (i === 0) { const sourceLength = source[lineNumber - 1].length; - markerLines[lineNumber] = [startColumn, sourceLength - startColumn]; + markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1]; } else if (i === lineDiff) { markerLines[lineNumber] = [0, endColumn]; } else { @@ -112,15 +112,16 @@ export function codeFrameColumns( const maybeHighlight = (chalkFn, string) => { return highlighted ? chalkFn(string) : string; }; - if (highlighted) rawLines = highlight(rawLines, opts); - const lines = rawLines.split(NEWLINE); const { start, end, markerLines } = getMarkerLines(loc, lines, opts); const hasColumns = loc.start && typeof loc.start.column === "number"; const numberMaxWidth = String(end).length; - let frame = lines + const highlightedLines = highlighted ? highlight(rawLines, opts) : rawLines; + + let frame = highlightedLines + .split(NEWLINE) .slice(start, end) .map((line, index) => { const number = start + 1 + index; diff --git a/packages/babel-code-frame/test/index.js b/packages/babel-code-frame/test/index.js index c06214c5b4e5..23f724ee3209 100644 --- a/packages/babel-code-frame/test/index.js +++ b/packages/babel-code-frame/test/index.js @@ -102,6 +102,45 @@ describe("@babel/code-frame", function() { ); }); + test("opts.highlightCode with multiple columns and lines", function() { + // prettier-ignore + const rawLines = [ + "function a(b, c) {", + " return b + c;", + "}" + ].join("\n"); + + const result = codeFrameColumns( + rawLines, + { + start: { + line: 1, + column: 1, + }, + end: { + line: 3, + column: 1, + }, + }, + { + highlightCode: true, + message: "Message about things", + }, + ); + const stripped = stripAnsi(result); + expect(stripped).toEqual( + // prettier-ignore + [ + "> 1 | function a(b, c) {", + " | ^^^^^^^^^^^^^^^^^^", + "> 2 | return b + c;", + " | ^^^^^^^^^^^^^^^", + "> 3 | }", + " | ^ Message about things", + ].join('\n'), + ); + }); + test("opts.linesAbove", function() { const rawLines = [ "/**", diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index e6fbbdc26ef8..56efb4a95fc5 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -1,6 +1,6 @@ { "name": "@babel/core", - "version": "7.1.0", + "version": "7.5.5", "description": "Babel compiler core.", "main": "lib/index.js", "author": "Sebastian McKenzie ", @@ -33,23 +33,23 @@ "./lib/transform-file.js": "./lib/transform-file-browser.js" }, "dependencies": { - "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.0.0", - "@babel/helpers": "^7.1.0", - "@babel/parser": "^7.1.0", - "@babel/template": "^7.1.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0", + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.5.5", + "@babel/helpers": "^7.5.5", + "@babel/parser": "^7.5.5", + "@babel/template": "^7.4.4", + "@babel/traverse": "^7.5.5", + "@babel/types": "^7.5.5", "convert-source-map": "^1.1.0", - "debug": "^3.1.0", - "json5": "^0.5.0", - "lodash": "^4.17.10", + "debug": "^4.1.0", + "json5": "^2.1.0", + "lodash": "^4.17.13", "resolve": "^1.3.2", "semver": "^5.4.1", "source-map": "^0.5.0" }, "devDependencies": { - "@babel/helper-transform-fixture-test-runner": "^7.0.0", - "@babel/register": "^7.0.0" + "@babel/helper-transform-fixture-test-runner": "^7.5.5", + "@babel/register": "^7.5.5" } } diff --git a/packages/babel-core/src/config/caching.js b/packages/babel-core/src/config/caching.js index c8db5a166c71..5b915e7f7767 100644 --- a/packages/babel-core/src/config/caching.js +++ b/packages/babel-core/src/config/caching.js @@ -54,6 +54,7 @@ function makeCachedFunction< ArgT, ResultT, SideChannel, + // $FlowIssue https://github.com/facebook/flow/issues/4528 Cache: CacheMap, >( callCache: Cache, diff --git a/packages/babel-core/src/config/config-chain.js b/packages/babel-core/src/config/config-chain.js index b9e13a130797..3bbedcdff1a9 100644 --- a/packages/babel-core/src/config/config-chain.js +++ b/packages/babel-core/src/config/config-chain.js @@ -67,7 +67,7 @@ export function buildPresetChain( return { plugins: dedupDescriptors(chain.plugins), presets: dedupDescriptors(chain.presets), - options: chain.options, + options: chain.options.map(o => normalizeOptions(o)), }; } @@ -155,6 +155,7 @@ export function buildRootChain( } let { babelrc, babelrcRoots } = opts; + let babelrcRootsDirectory = context.cwd; const configFileChain = emptyChain(); if (configFile) { @@ -168,6 +169,7 @@ export function buildRootChain( babelrc = validatedFile.options.babelrc; } if (babelrcRoots === undefined) { + babelrcRootsDirectory = validatedFile.dirname; babelrcRoots = validatedFile.options.babelrcRoots; } @@ -185,7 +187,7 @@ export function buildRootChain( if ( (babelrc === true || babelrc === undefined) && pkgData && - babelrcLoadEnabled(context, pkgData, babelrcRoots) + babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory) ) { ({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig( pkgData, @@ -229,6 +231,7 @@ function babelrcLoadEnabled( context: ConfigContext, pkgData: FilePackageData, babelrcRoots: BabelrcSearch | void, + babelrcRootsDirectory: string, ): boolean { if (typeof babelrcRoots === "boolean") return babelrcRoots; @@ -243,7 +246,9 @@ function babelrcLoadEnabled( let babelrcPatterns = babelrcRoots; if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns]; babelrcPatterns = babelrcPatterns.map(pat => { - return typeof pat === "string" ? path.resolve(context.cwd, pat) : pat; + return typeof pat === "string" + ? path.resolve(babelrcRootsDirectory, pat) + : pat; }); // Fast path to avoid having to match patterns if the babelrc is just @@ -253,10 +258,12 @@ function babelrcLoadEnabled( } return babelrcPatterns.some(pat => { - if (typeof pat === "string") pat = pathPatternToRegex(pat, context.cwd); + if (typeof pat === "string") { + pat = pathPatternToRegex(pat, babelrcRootsDirectory); + } return pkgData.directories.some(directory => { - return matchPattern(pat, context.cwd, directory, context); + return matchPattern(pat, babelrcRootsDirectory, directory, context); }); }); } diff --git a/packages/babel-core/src/config/files/configuration.js b/packages/babel-core/src/config/files/configuration.js index 279da6b7cf08..ab3353f6fde3 100644 --- a/packages/babel-core/src/config/files/configuration.js +++ b/packages/babel-core/src/config/files/configuration.js @@ -10,7 +10,7 @@ import { makeWeakCache, type CacheConfigurator, } from "../caching"; -import makeAPI from "../helpers/config-api"; +import makeAPI, { type PluginAPI } from "../helpers/config-api"; import { makeStaticFileCache } from "./utils"; import pathPatternToRegex from "../pattern-to-regex"; import type { FilePackageData, RelativeConfig, ConfigFile } from "./types"; @@ -114,7 +114,7 @@ export function findRootConfig( const conf = readConfig(filepath, envName, caller); if (conf) { - debug("Found root config %o in $o.", BABEL_CONFIG_JS_FILENAME, dirname); + debug("Found root config %o in %o.", BABEL_CONFIG_JS_FILENAME, dirname); } return conf; } @@ -132,7 +132,7 @@ export function loadConfig( throw new Error(`Config file ${filepath} contains no configuration data`); } - debug("Loaded config %o from $o.", name, dirname); + debug("Loaded config %o from %o.", name, dirname); return conf; } @@ -150,7 +150,7 @@ const LOADING_CONFIGS = new Set(); const readConfigJS = makeStrongCache( ( - filepath, + filepath: string, cache: CacheConfigurator<{ envName: string, caller: CallerMetadata | void, @@ -193,7 +193,7 @@ const readConfigJS = makeStrongCache( } if (typeof options === "function") { - options = options(makeAPI(cache)); + options = ((options: any): (api: PluginAPI) => {})(makeAPI(cache)); if (!cache.configured()) throwConfigError(); } diff --git a/packages/babel-core/src/config/files/plugins.js b/packages/babel-core/src/config/files/plugins.js index 6bef09039d8f..be20468d1615 100644 --- a/packages/babel-core/src/config/files/plugins.js +++ b/packages/babel-core/src/config/files/plugins.js @@ -132,7 +132,7 @@ function resolveStandardizedName( } catch (e2) {} if (resolvedOppositeType) { - e.message += `\n- Did you accidentally pass a ${type} as a ${oppositeType}?`; + e.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`; } throw e; diff --git a/packages/babel-core/src/config/full.js b/packages/babel-core/src/config/full.js index af4212953f67..88c65ff882be 100644 --- a/packages/babel-core/src/config/full.js +++ b/packages/babel-core/src/config/full.js @@ -202,7 +202,7 @@ const loadDescriptor = makeWeakCache( if (typeof item.then === "function") { throw new Error( `You appear to be using an async plugin, ` + - `which your current version of Babel does not support.` + + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version.`, ); diff --git a/packages/babel-core/src/config/helpers/config-api.js b/packages/babel-core/src/config/helpers/config-api.js index fa106f0ce24b..a93756ae9fa3 100644 --- a/packages/babel-core/src/config/helpers/config-api.js +++ b/packages/babel-core/src/config/helpers/config-api.js @@ -55,6 +55,7 @@ export default function makeAPI( async: () => false, caller, assertVersion, + tokTypes: undefined, }; } diff --git a/packages/babel-core/src/config/validation/option-assertions.js b/packages/babel-core/src/config/validation/option-assertions.js index 321e1c063229..87244b4f16b3 100644 --- a/packages/babel-core/src/config/validation/option-assertions.js +++ b/packages/babel-core/src/config/validation/option-assertions.js @@ -231,7 +231,7 @@ function assertIgnoreItem(loc: GeneralPath, value: mixed): IgnoreItem { throw new Error( `${msg( loc, - )} must be an array of string/Funtion/RegExp values, or undefined`, + )} must be an array of string/Function/RegExp values, or undefined`, ); } return value; @@ -337,7 +337,7 @@ function assertPluginItem(loc: GeneralPath, value: mixed): PluginItem { if ( opts !== undefined && opts !== false && - (typeof opts !== "object" || Array.isArray(opts)) + (typeof opts !== "object" || Array.isArray(opts) || opts === null) ) { throw new Error( `${msg(access(loc, 1))} must be an object, false, or undefined`, diff --git a/packages/babel-core/src/config/validation/options.js b/packages/babel-core/src/config/validation/options.js index c790adfac9f9..3ee072ae344f 100644 --- a/packages/babel-core/src/config/validation/options.js +++ b/packages/babel-core/src/config/validation/options.js @@ -350,7 +350,7 @@ function validateNested(loc: NestingPath, opts: {}) { NONPRESET_VALIDATORS[key] || BABELRC_VALIDATORS[key] || ROOT_VALIDATORS[key] || - throwUnknownError; + (throwUnknownError: Validator); validator(optLoc, opts[key]); }); diff --git a/packages/babel-core/src/index.js b/packages/babel-core/src/index.js index 075351715ab1..e7ae7c0edfc6 100644 --- a/packages/babel-core/src/index.js +++ b/packages/babel-core/src/index.js @@ -10,6 +10,8 @@ export { version } from "../package.json"; export { getEnv } from "./config/helpers/environment"; export * as types from "@babel/types"; +export { tokTypes } from "@babel/parser"; + export { default as traverse } from "@babel/traverse"; export { default as template } from "@babel/template"; diff --git a/packages/babel-core/src/transform-file-browser.js b/packages/babel-core/src/transform-file-browser.js index ed74df780202..fc1b12af0e50 100644 --- a/packages/babel-core/src/transform-file-browser.js +++ b/packages/babel-core/src/transform-file-browser.js @@ -1,14 +1,29 @@ // @flow -import type { FileResult } from "./transformation"; -export default function transformFile( - filename: string, - opts?: Object = {}, - callback: (?Error, FileResult | null) => void, +// duplicated from transform-file so we do not have to import anything here +type TransformFile = { + (filename: string, callback: Function): void, + (filename: string, opts: ?Object, callback: Function): void, +}; + +export const transformFile: TransformFile = (function transformFile( + filename, + opts, + callback, ) { if (typeof opts === "function") { callback = opts; } callback(new Error("Transforming files is not supported in browsers"), null); +}: Function); + +export function transformFileSync() { + throw new Error("Transforming files is not supported in browsers"); +} + +export function transformFileAsync() { + return Promise.reject( + new Error("Transforming files is not supported in browsers"), + ); } diff --git a/packages/babel-core/src/transform-file-sync-browser.js b/packages/babel-core/src/transform-file-sync-browser.js deleted file mode 100644 index 144242f3e383..000000000000 --- a/packages/babel-core/src/transform-file-sync-browser.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow - -export default function transformFileSync() { - throw new Error("Transforming files is not supported in browsers"); -} diff --git a/packages/babel-core/src/transform-file.js b/packages/babel-core/src/transform-file.js index 1011bd8a4d89..d3c9ab640fc3 100644 --- a/packages/babel-core/src/transform-file.js +++ b/packages/babel-core/src/transform-file.js @@ -9,6 +9,14 @@ import { type FileResultCallback, } from "./transformation"; +import typeof * as transformFileBrowserType from "./transform-file-browser"; +import typeof * as transformFileType from "./transform-file"; + +// Kind of gross, but essentially asserting that the exports of this module are the same as the +// exports of transform-file-browser, since this file may be replaced at bundle time with +// transform-file-browser. +((({}: any): $Exact): $Exact); + type TransformFile = { (filename: string, callback: FileResultCallback): void, (filename: string, opts: ?InputOptions, callback: FileResultCallback): void, diff --git a/packages/babel-core/src/transformation/file/file.js b/packages/babel-core/src/transformation/file/file.js index bbc28767180e..a0a9f65bcdf4 100644 --- a/packages/babel-core/src/transformation/file/file.js +++ b/packages/babel-core/src/transformation/file/file.js @@ -183,7 +183,7 @@ export default class File { // and this fails because a prerelease version can only satisfy a range // if it is a prerelease within the same major/minor/patch range. // - // Note: If this is found to have issues, please also revist the logic in + // Note: If this is found to have issues, please also revisit the logic in // transform-runtime's definitions.js file. if (semver.valid(versionRange)) versionRange = `^${versionRange}`; @@ -203,6 +203,9 @@ export default class File { if (res) return res; } + // make sure that the helper exists + helpers.ensure(name); + const uid = (this.declarations[name] = this.scope.generateUidIdentifier( name, )); diff --git a/packages/babel-core/src/transformation/file/merge-map.js b/packages/babel-core/src/transformation/file/merge-map.js index 991373862e1e..ff2e65b042b8 100644 --- a/packages/babel-core/src/transformation/file/merge-map.js +++ b/packages/babel-core/src/transformation/file/merge-map.js @@ -94,7 +94,7 @@ export default function mergeSourceMap( } function makeMappingKey(item: { line: number, columnStart: number }) { - return JSON.stringify([item.line, item.columnStart]); + return `${item.line}/${item.columnStart}`; } function eachOverlappingGeneratedOutputRange( diff --git a/packages/babel-core/src/transformation/index.js b/packages/babel-core/src/transformation/index.js index 8174f7bd8228..a03c4db0cf2a 100644 --- a/packages/babel-core/src/transformation/index.js +++ b/packages/babel-core/src/transformation/index.js @@ -93,7 +93,7 @@ function transformFile(file: File, pluginPasses: PluginPasses): void { if (isThenable(result)) { throw new Error( `You appear to be using an plugin with an async .pre, ` + - `which your current version of Babel does not support.` + + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`, ); @@ -117,7 +117,7 @@ function transformFile(file: File, pluginPasses: PluginPasses): void { if (isThenable(result)) { throw new Error( `You appear to be using an plugin with an async .post, ` + - `which your current version of Babel does not support.` + + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`, ); @@ -131,6 +131,7 @@ function isThenable(val: mixed): boolean { return ( !!val && (typeof val === "object" || typeof val === "function") && + !!val.then && typeof val.then === "function" ); } diff --git a/packages/babel-core/src/transformation/util/missing-plugin-helper.js b/packages/babel-core/src/transformation/util/missing-plugin-helper.js index 2f1090c9110e..b0642c50c3cf 100644 --- a/packages/babel-core/src/transformation/util/missing-plugin-helper.js +++ b/packages/babel-core/src/transformation/util/missing-plugin-helper.js @@ -1,16 +1,6 @@ // @flow const pluginNameMap = { - asyncGenerators: { - syntax: { - name: "@babel/plugin-syntax-async-generators", - url: "https://git.io/vb4SY", - }, - transform: { - name: "@babel/plugin-proposal-async-generator-functions", - url: "https://git.io/vb4yp", - }, - }, classProperties: { syntax: { name: "@babel/plugin-syntax-class-properties", @@ -143,26 +133,6 @@ const pluginNameMap = { url: "https://git.io/vb4yS", }, }, - objectRestSpread: { - syntax: { - name: "@babel/plugin-syntax-object-rest-spread", - url: "https://git.io/vb4y5", - }, - transform: { - name: "@babel/plugin-proposal-object-rest-spread", - url: "https://git.io/vb4Ss", - }, - }, - optionalCatchBinding: { - syntax: { - name: "@babel/plugin-syntax-optional-catch-binding", - url: "https://git.io/vb4Sn", - }, - transform: { - name: "@babel/plugin-proposal-optional-catch-binding", - url: "https://git.io/vb4SI", - }, - }, optionalChaining: { syntax: { name: "@babel/plugin-syntax-optional-chaining", @@ -203,6 +173,41 @@ const pluginNameMap = { url: "https://git.io/vb4Sm", }, }, + + // TODO: This plugins are now supported by default by @babel/parser: they can + // be removed from this list. Although removing them isn't a breaking change, + // it's better to keep a nice error message for users using older versions of + // the parser. They can be removed in Babel 8. + asyncGenerators: { + syntax: { + name: "@babel/plugin-syntax-async-generators", + url: "https://git.io/vb4SY", + }, + transform: { + name: "@babel/plugin-proposal-async-generator-functions", + url: "https://git.io/vb4yp", + }, + }, + objectRestSpread: { + syntax: { + name: "@babel/plugin-syntax-object-rest-spread", + url: "https://git.io/vb4y5", + }, + transform: { + name: "@babel/plugin-proposal-object-rest-spread", + url: "https://git.io/vb4Ss", + }, + }, + optionalCatchBinding: { + syntax: { + name: "@babel/plugin-syntax-optional-catch-binding", + url: "https://git.io/vb4Sn", + }, + transform: { + name: "@babel/plugin-proposal-optional-catch-binding", + url: "https://git.io/vb4SI", + }, + }, }; const getNameURLCombination = ({ name, url }) => `${name} (${url})`; diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 5c3a97c7a376..9f2f955f1d7e 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -154,6 +154,14 @@ describe("api", function() { ); }); + it("exposes types", function() { + expect(babel.types).toBeDefined(); + }); + + it("exposes the parser's token types", function() { + expect(babel.tokTypes).toBeDefined(); + }); + it("transformFile", function(done) { const options = { babelrc: false, @@ -769,10 +777,10 @@ describe("api", function() { options, function(err) { expect(err.message).toMatch( - "Support for the experimental syntax 'asyncGenerators' isn't currently enabled (1:15):", + "Support for the experimental syntax 'logicalAssignment' isn't currently enabled (1:3):", ); expect(err.message).toMatch( - "Add @babel/plugin-proposal-async-generator-functions (https://git.io/vb4yp) to the " + + "Add @babel/plugin-proposal-logical-assignment-operators (https://git.io/vAlRe) to the " + "'plugins' section of your Babel config to enable transformation.", ); done(); @@ -780,4 +788,28 @@ describe("api", function() { ); }); }); + + describe("missing helpers", function() { + it("should always throw", function() { + expect(() => + babel.transformSync(``, { + configFile: false, + plugins: [ + function() { + return { + visitor: { + Program(path) { + try { + path.pushContainer("body", this.addHelper("fooBar")); + } catch {} + path.pushContainer("body", this.addHelper("fooBar")); + }, + }, + }; + }, + ], + }), + ).toThrow(); + }); + }); }); diff --git a/packages/babel-core/test/fixtures/api/parsing-errors/syntax-and-transform/file.js b/packages/babel-core/test/fixtures/api/parsing-errors/syntax-and-transform/file.js index a0eb4637c6d8..0cb4253cd41b 100644 --- a/packages/babel-core/test/fixtures/api/parsing-errors/syntax-and-transform/file.js +++ b/packages/babel-core/test/fixtures/api/parsing-errors/syntax-and-transform/file.js @@ -1,4 +1 @@ -async function* agf() { - await 1; - yield 2; -} +a ||= 2; diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1169/output.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/output.js index d2974e11c46d..910053ac4d12 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1169/output.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/output.js @@ -2,8 +2,8 @@ function foo() { var input = ['a', 'b', 'c']; var output = {}; - for (var _i = 0; _i < input.length; _i++) { - var c = input[_i]; + for (var _i = 0, _input = input; _i < _input.length; _i++) { + var c = _input[_i]; var name = c; output[name] = name; } diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-2892/output.js b/packages/babel-core/test/fixtures/transformation/misc/regression-2892/output.js index 11385a0a000b..ec30a24e9b09 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-2892/output.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-2892/output.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +exports["default"] = void 0; function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } @@ -40,19 +40,21 @@ function () { return _context.stop(); } } - }, _callee, this); + }, _callee); })); - return function bar() { + function bar() { return _bar.apply(this, arguments); - }; + } + + return bar; }() }]); return Foo; }(); -exports.default = Foo; +exports["default"] = Foo; function foo() { return _foo.apply(this, arguments); @@ -84,7 +86,7 @@ function _foo() { return _context2.stop(); } } - }, _callee2, this); + }, _callee2); })); return _bar2.apply(this, arguments); }; @@ -98,7 +100,7 @@ function _foo() { return _context3.stop(); } } - }, _callee3, this); + }, _callee3); })); return _foo.apply(this, arguments); } diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json index 2f59220d176b..489d3a868c4b 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-4855/options.json @@ -1,5 +1,8 @@ { "compact": false, "presets": ["env"], - "plugins": ["external-helpers", "proposal-object-rest-spread"] + "plugins": [ + ["external-helpers", { "helperVersion": "7.1.5" }], + "proposal-object-rest-spread" + ] } diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index 28830f58f33d..4a6301ab4777 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -38,6 +38,17 @@ describe("option-manager", () => { expect(calls).toEqual([]); }); + it("throws for null options", () => { + const { calls, plugin } = makePlugin(); + expect(() => { + loadOptions({ + plugins: [[plugin, null]], + }).toThrow(/.plugins[0][1] must be an object, false, or undefined/); + }); + + expect(calls).toEqual([]); + }); + it("should not throw if a repeated plugin has a different name", () => { const { calls: calls1, plugin: plugin1 } = makePlugin(); const { calls: calls2, plugin: plugin2 } = makePlugin(); @@ -87,7 +98,6 @@ describe("option-manager", () => { expect(calls1).toEqual([{ arg: 1 }]); expect(calls2).toEqual([{ arg: 2 }]); }); - it("should merge .env[] presets with parent presets", () => { const { calls: calls1, plugin: preset1 } = makePlugin(); const { calls: calls2, plugin: preset2 } = makePlugin(); diff --git a/packages/babel-core/test/resolution.js b/packages/babel-core/test/resolution.js index 4280b27ddd76..203d76ec5769 100644 --- a/packages/babel-core/test/resolution.js +++ b/packages/babel-core/test/resolution.js @@ -400,7 +400,7 @@ describe("addon resolution", function() { presets: ["testplugin"], }); }).toThrow( - /Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a preset as a plugin\?/, + /Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a plugin as a preset\?/, ); }); @@ -414,7 +414,7 @@ describe("addon resolution", function() { plugins: ["testpreset"], }); }).toThrow( - /Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a plugin as a preset\?/, + /Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a preset as a plugin\?/, ); }); diff --git a/packages/babel-generator/package.json b/packages/babel-generator/package.json index 42155d2bd44c..815171acf262 100644 --- a/packages/babel-generator/package.json +++ b/packages/babel-generator/package.json @@ -1,6 +1,6 @@ { "name": "@babel/generator", - "version": "7.0.0", + "version": "7.5.5", "description": "Turns an AST into code.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -14,14 +14,14 @@ "lib" ], "dependencies": { - "@babel/types": "^7.0.0", + "@babel/types": "^7.5.5", "jsesc": "^2.5.1", - "lodash": "^4.17.10", + "lodash": "^4.17.13", "source-map": "^0.5.0", "trim-right": "^1.0.1" }, "devDependencies": { - "@babel/helper-fixtures": "^7.0.0", - "@babel/parser": "^7.0.0" + "@babel/helper-fixtures": "^7.5.5", + "@babel/parser": "^7.5.5" } } diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js index f49bfad8c545..fd64201a921b 100644 --- a/packages/babel-generator/src/buffer.js +++ b/packages/babel-generator/src/buffer.js @@ -235,7 +235,7 @@ export default class Buffer { source(prop: string, loc: Location, force?: boolean): void { if (prop && !loc) return; - // Since this is called extremly often, we re-use the same _sourcePosition + // Since this is called extremely often, we re-use the same _sourcePosition // object for the whole lifetime of the buffer. this._normalizePosition(prop, loc, this._sourcePosition, force); } diff --git a/packages/babel-generator/src/generators/base.js b/packages/babel-generator/src/generators/base.js index 49a1cb2c88b5..dd45014377f6 100644 --- a/packages/babel-generator/src/generators/base.js +++ b/packages/babel-generator/src/generators/base.js @@ -50,8 +50,45 @@ export function Directive(node: Object) { this.semicolon(); } +// These regexes match an even number of \ followed by a quote +const unescapedSingleQuoteRE = /(?:^|[^\\])(?:\\\\)*'/; +const unescapedDoubleQuoteRE = /(?:^|[^\\])(?:\\\\)*"/; + +export function DirectiveLiteral(node: Object) { + const raw = this.getPossibleRaw(node); + if (raw != null) { + this.token(raw); + return; + } + + const { value } = node; + + // NOTE: In directives we can't change escapings, + // because they change the behavior. + // e.g. "us\x65 string" (\x65 is e) is not a "use strict" directive. + + if (!unescapedDoubleQuoteRE.test(value)) { + this.token(`"${value}"`); + } else if (!unescapedSingleQuoteRE.test(value)) { + this.token(`'${value}'`); + } else { + throw new Error( + "Malformed AST: it is not possible to print a directive containing" + + " both unescaped single and double quotes.", + ); + } +} + export function InterpreterDirective(node: Object) { this.token(`#!${node.value}\n`); } -export { StringLiteral as DirectiveLiteral } from "./types"; +export function Placeholder(node: Object) { + this.token("%%"); + this.print(node.name); + this.token("%%"); + + if (node.expectedNode === "Statement") { + this.semicolon(); + } +} diff --git a/packages/babel-generator/src/generators/classes.js b/packages/babel-generator/src/generators/classes.js index 22780dc3f03b..e8c62339a6d2 100644 --- a/packages/babel-generator/src/generators/classes.js +++ b/packages/babel-generator/src/generators/classes.js @@ -140,6 +140,12 @@ export function ClassMethod(node: Object) { this.print(node.body, node); } +export function ClassPrivateMethod(node: Object) { + this._classMethodHead(node); + this.space(); + this.print(node.body, node); +} + export function _classMethodHead(node) { this.printJoin(node.decorators, node); diff --git a/packages/babel-generator/src/generators/flow.js b/packages/babel-generator/src/generators/flow.js index d46118debd48..225428b00801 100644 --- a/packages/babel-generator/src/generators/flow.js +++ b/packages/babel-generator/src/generators/flow.js @@ -409,7 +409,7 @@ export function ObjectTypeAnnotation(node: Object) { indent: true, statement: true, iterator: () => { - if (props.length !== 1) { + if (props.length !== 1 || node.inexact) { this.token(","); this.space(); } @@ -419,6 +419,15 @@ export function ObjectTypeAnnotation(node: Object) { this.space(); } + if (node.inexact) { + this.indent(); + this.token("..."); + if (props.length) { + this.newline(); + } + this.dedent(); + } + if (node.exact) { this.token("|}"); } else { diff --git a/packages/babel-generator/src/generators/methods.js b/packages/babel-generator/src/generators/methods.js index 5dc17e065a20..1019aba04c7c 100644 --- a/packages/babel-generator/src/generators/methods.js +++ b/packages/babel-generator/src/generators/methods.js @@ -111,7 +111,25 @@ export function ArrowFunctionExpression(node: Object) { t.isIdentifier(firstParam) && !hasTypes(node, firstParam) ) { - this.print(firstParam, node); + if ( + this.format.retainLines && + node.loc && + node.body.loc && + node.loc.start.line < node.body.loc.start.line + ) { + this.token("("); + if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) { + this.indent(); + this.print(firstParam, node); + this.dedent(); + this._catchUp("start", node.body.loc); + } else { + this.print(firstParam, node); + } + this.token(")"); + } else { + this.print(firstParam, node); + } } else { this._params(node); } diff --git a/packages/babel-generator/src/generators/types.js b/packages/babel-generator/src/generators/types.js index 4a5ed312a661..fdd090dd4113 100644 --- a/packages/babel-generator/src/generators/types.js +++ b/packages/babel-generator/src/generators/types.js @@ -7,6 +7,10 @@ export function Identifier(node: Object) { }); } +export function ArgumentPlaceholder() { + this.token("?"); +} + export function RestElement(node: Object) { this.token("..."); this.print(node.argument, node); @@ -151,3 +155,15 @@ export function BigIntLiteral(node: Object) { } this.token(node.value); } + +export function PipelineTopicExpression(node: Object) { + this.print(node.expression, node); +} + +export function PipelineBareFunction(node: Object) { + this.print(node.callee, node); +} + +export function PipelinePrimaryTopicReference() { + this.token("#"); +} diff --git a/packages/babel-generator/src/generators/typescript.js b/packages/babel-generator/src/generators/typescript.js index c2e5f9d42cd3..c5d737892f2d 100644 --- a/packages/babel-generator/src/generators/typescript.js +++ b/packages/babel-generator/src/generators/typescript.js @@ -127,6 +127,9 @@ export function TSIndexSignature(node) { export function TSAnyKeyword() { this.word("any"); } +export function TSUnknownKeyword() { + this.word("unknown"); +} export function TSNumberKeyword() { this.word("number"); } @@ -228,7 +231,7 @@ export function tsPrintBraced(members, node) { } export function TSArrayType(node) { - this.print(node.elementType); + this.print(node.elementType, node); this.token("[]"); } @@ -238,6 +241,16 @@ export function TSTupleType(node) { this.token("]"); } +export function TSOptionalType(node) { + this.print(node.typeAnnotation, node); + this.token("?"); +} + +export function TSRestType(node) { + this.token("..."); + this.print(node.typeAnnotation, node); +} + export function TSUnionType(node) { this.tsPrintUnionOrIntersectionType(node, "|"); } @@ -463,6 +476,21 @@ export function TSModuleBlock(node) { this.tsPrintBraced(node.body, node); } +export function TSImportType(node) { + const { argument, qualifier, typeParameters } = node; + this.word("import"); + this.token("("); + this.print(argument, node); + this.token(")"); + if (qualifier) { + this.token("."); + this.print(qualifier, node); + } + if (typeParameters) { + this.print(typeParameters, node); + } +} + export function TSImportEqualsDeclaration(node) { const { isExport, id, moduleReference } = node; if (isExport) { diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index e78391c2bd58..8c38fa627239 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -35,7 +35,16 @@ export function NullableTypeAnnotation(node: Object, parent: Object): boolean { return t.isArrayTypeAnnotation(parent); } -export { NullableTypeAnnotation as FunctionTypeAnnotation }; +export function FunctionTypeAnnotation(node: Object, parent: Object): boolean { + return ( + // (() => A) | (() => B) + t.isUnionTypeAnnotation(parent) || + // (() => A) & (() => B) + t.isIntersectionTypeAnnotation(parent) || + // (() => A)[] + t.isArrayTypeAnnotation(parent) + ); +} export function UpdateExpression(node: Object, parent: Object): boolean { return ( @@ -127,6 +136,18 @@ export function TSTypeAssertion() { return true; } +export function TSUnionType(node: Object, parent: Object): boolean { + return ( + t.isTSArrayType(parent) || + t.isTSOptionalType(parent) || + t.isTSIntersectionType(parent) || + t.isTSUnionType(parent) || + t.isTSRestType(parent) + ); +} + +export { TSUnionType as TSIntersectionType }; + export function BinaryExpression(node: Object, parent: Object): boolean { // let i = (1 in []); // for ((1 in []);;); @@ -166,6 +187,7 @@ export function YieldExpression(node: Object, parent: Object): boolean { t.isCallExpression(parent) || t.isMemberExpression(parent) || t.isNewExpression(parent) || + (t.isAwaitExpression(parent) && t.isYieldExpression(node)) || (t.isConditionalExpression(parent) && node === parent.test) || isClassExtendsClause(node, parent) ); @@ -209,6 +231,7 @@ export function ConditionalExpression(node: Object, parent: Object): boolean { t.isBinary(parent) || t.isConditionalExpression(parent, { test: node }) || t.isAwaitExpression(parent) || + t.isOptionalMemberExpression(parent) || t.isTaggedTemplateExpression(parent) || t.isTSTypeAssertion(parent) || t.isTSAsExpression(parent) @@ -219,6 +242,13 @@ export function ConditionalExpression(node: Object, parent: Object): boolean { return UnaryLike(node, parent); } +export function OptionalMemberExpression( + node: Object, + parent: Object, +): boolean { + return t.isCallExpression(parent) || t.isMemberExpression(parent); +} + export function AssignmentExpression(node: Object): boolean { if (t.isObjectPattern(node.left)) { return true; diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index 1b740ce0c48b..fb4715d491c5 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -363,14 +363,14 @@ export default class Printer { } if (needsParens) this.token("("); - this._printLeadingComments(node, parent); + this._printLeadingComments(node); const loc = t.isProgram(node) || t.isFile(node) ? null : node.loc; this.withSource("start", loc, () => { - this[node.type](node, parent); + printMethod.call(this, node, parent); }); - this._printTrailingComments(node, parent); + this._printTrailingComments(node); if (needsParens) this.token(")"); @@ -472,12 +472,12 @@ export default class Printer { this.print(node, parent); } - _printTrailingComments(node, parent) { - this._printComments(this._getComments(false, node, parent)); + _printTrailingComments(node) { + this._printComments(this._getComments(false, node)); } - _printLeadingComments(node, parent) { - this._printComments(this._getComments(true, node, parent)); + _printLeadingComments(node) { + this._printComments(this._getComments(true, node)); } printInnerComments(node, indent = true) { diff --git a/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/input.js b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/input.js new file mode 100644 index 000000000000..753a9cfbb2b5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/input.js @@ -0,0 +1,12 @@ +// One +(1); + +/* Two */ +(2); + +( + // Three + 3 +); + +(/* Four */ 4); diff --git a/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/options.json b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/options.json new file mode 100644 index 000000000000..7c49b91ec9b2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/options.json @@ -0,0 +1,3 @@ +{ + "parserOpts": {"createParenthesizedExpressions": true} +} diff --git a/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/output.js b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/output.js new file mode 100644 index 000000000000..b78500e8017f --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/create-parenthesized-expressions/output.js @@ -0,0 +1,10 @@ +// One +(1); +/* Two */ + +(2); +( // Three +3); +( +/* Four */ +4); \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/compact/expression-statement/options.json b/packages/babel-generator/test/fixtures/compact/expression-statement/options.json deleted file mode 100644 index 8a2a1d3bfa91..000000000000 --- a/packages/babel-generator/test/fixtures/compact/expression-statement/options.json +++ /dev/null @@ -1 +0,0 @@ -{ "plugins": ["objectRestSpread"] } diff --git a/packages/babel-generator/test/fixtures/edgecase/async-generator/options.json b/packages/babel-generator/test/fixtures/edgecase/async-generator/options.json index 1ec463510a34..600c3f8fc13c 100644 --- a/packages/babel-generator/test/fixtures/edgecase/async-generator/options.json +++ b/packages/babel-generator/test/fixtures/edgecase/async-generator/options.json @@ -1 +1 @@ -{ "plugins": ["asyncGenerators", "classProperties"] } +{ "plugins": ["classProperties"] } diff --git a/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/input.js b/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/input.js index 3d4fdd63e337..11f766a1c91d 100644 --- a/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/input.js +++ b/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/input.js @@ -4,7 +4,7 @@ function foo(l) { ); } -function foo() { +function foo2() { return ( 1 && 2 ) || 3; diff --git a/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/output.js b/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/output.js index eda704040f14..494b4cf7d5f8 100644 --- a/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/output.js +++ b/packages/babel-generator/test/fixtures/edgecase/return-with-retainlines-option/output.js @@ -4,7 +4,7 @@ function foo(l) { } -function foo() { +function foo2() { return ( 1 && 2 || 3); diff --git a/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/input.js b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/input.js new file mode 100644 index 000000000000..b5a205cc36d6 --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/input.js @@ -0,0 +1,11 @@ +var fn = async ( + arg +) => {} + +async (x) => +{} + +async x => {} + +async (x +) => {}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/options.json b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/options.json new file mode 100644 index 000000000000..97925bbcb61b --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/options.json @@ -0,0 +1,3 @@ +{ + "retainLines": true +} diff --git a/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/output.js b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/output.js new file mode 100644 index 000000000000..6bb2ce5093e8 --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/single-arg-async-arrow-with-retainlines/output.js @@ -0,0 +1,11 @@ +var fn = async ( + arg +) => {}; + +async (x) => +{}; + +async x => {}; + +async (x) => +{}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json b/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json new file mode 100644 index 000000000000..a2e80d9ec294 --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/unary-op/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/fixtures/escapes/jsonEscape/input.js b/packages/babel-generator/test/fixtures/escapes/jsonEscape/input.js index 2305ada28e08..b999a74fa0c0 100644 --- a/packages/babel-generator/test/fixtures/escapes/jsonEscape/input.js +++ b/packages/babel-generator/test/fixtures/escapes/jsonEscape/input.js @@ -1 +1,2 @@ +0; // Not a directive "©"; diff --git a/packages/babel-generator/test/fixtures/escapes/jsonEscape/output.js b/packages/babel-generator/test/fixtures/escapes/jsonEscape/output.js index 354db9cc775e..4da42cb39725 100644 --- a/packages/babel-generator/test/fixtures/escapes/jsonEscape/output.js +++ b/packages/babel-generator/test/fixtures/escapes/jsonEscape/output.js @@ -1 +1,2 @@ +0;// Not a directive "\u00A9"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/declare-exports/input.js b/packages/babel-generator/test/fixtures/flow/declare-exports/input.js index ea4a8c7cd463..97544d82b930 100644 --- a/packages/babel-generator/test/fixtures/flow/declare-exports/input.js +++ b/packages/babel-generator/test/fixtures/flow/declare-exports/input.js @@ -17,6 +17,7 @@ declare export * from 'asd'; declare export { a, b }; declare export {}; declare export { c, d } from 'bar'; +var a, b; declare module B { declare export type B = {}; @@ -24,9 +25,9 @@ declare module B { } declare module "foo" { declare export type * from "bar"; } -declare export opaque type Foo; +declare export opaque type Foo1; declare export opaque type Bar; declare export opaque type Baz: Foo; -declare export opaque type Foo: Bar; -declare export opaque type Foo: Bar; -declare export opaque type Foo: Bar; +declare export opaque type Foo3: Bar; +declare export opaque type Foo4: Bar; +declare export opaque type Foo5: Bar; diff --git a/packages/babel-generator/test/fixtures/flow/declare-exports/output.js b/packages/babel-generator/test/fixtures/flow/declare-exports/output.js index da22c014154d..59f3a4c56856 100644 --- a/packages/babel-generator/test/fixtures/flow/declare-exports/output.js +++ b/packages/babel-generator/test/fixtures/flow/declare-exports/output.js @@ -26,6 +26,7 @@ declare export * from 'asd'; declare export { a, b }; declare export {}; declare export { c, d } from 'bar'; +var a, b; declare module B { declare export type B = {}; declare export interface Moon {} @@ -33,9 +34,9 @@ declare module B { declare module "foo" { declare export type * from "bar"; } -declare export opaque type Foo; +declare export opaque type Foo1; declare export opaque type Bar; declare export opaque type Baz: Foo; -declare export opaque type Foo: Bar; -declare export opaque type Foo: Bar; -declare export opaque type Foo: Bar; \ No newline at end of file +declare export opaque type Foo3: Bar; +declare export opaque type Foo4: Bar; +declare export opaque type Foo5: Bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/def-site-variance/input.js b/packages/babel-generator/test/fixtures/flow/def-site-variance/input.js index 5cda68f8e9c5..9f00e80993d1 100644 --- a/packages/babel-generator/test/fixtures/flow/def-site-variance/input.js +++ b/packages/babel-generator/test/fixtures/flow/def-site-variance/input.js @@ -1,10 +1,10 @@ class C1<+T, -U> {} function f<+T, -U>() {} type T<+T, -U> = {}; -type T = { +p: T }; -type T = { -p: T }; -type T = { +[k:K]: V }; -type T = { -[k:K]: V }; +type T2 = { +p: T }; +type T3 = { -p: T }; +type T4 = { +[k:K]: V }; +type T5 = { -[k:K]: V }; interface I { +p: T } interface I { -p: T } interface I { +[k:K]: V } diff --git a/packages/babel-generator/test/fixtures/flow/def-site-variance/output.js b/packages/babel-generator/test/fixtures/flow/def-site-variance/output.js index e411f4646133..5c2b69d1a6dd 100644 --- a/packages/babel-generator/test/fixtures/flow/def-site-variance/output.js +++ b/packages/babel-generator/test/fixtures/flow/def-site-variance/output.js @@ -3,16 +3,16 @@ class C1<+T, -U> {} function f<+T, -U>() {} type T<+T, -U> = {}; -type T = { +type T2 = { +p: T }; -type T = { +type T3 = { -p: T }; -type T = { +type T4 = { +[k: K]: V }; -type T = { +type T5 = { -[k: K]: V }; interface I { diff --git a/packages/babel-generator/test/fixtures/flow/implements/input.js b/packages/babel-generator/test/fixtures/flow/implements/input.js index 32acd7162b81..0dd3e5458978 100644 --- a/packages/babel-generator/test/fixtures/flow/implements/input.js +++ b/packages/babel-generator/test/fixtures/flow/implements/input.js @@ -1,5 +1,5 @@ -class A implements B {} -class A implements B, C {} -declare class A implements B {} -declare class A mixins B implements C {} -declare class A implements B, C {} +class A1 implements B {} +class A2 implements B, C {} +declare class A3 implements B {} +declare class A4 mixins B implements C {} +declare class A5 implements B, C {} diff --git a/packages/babel-generator/test/fixtures/flow/implements/output.js b/packages/babel-generator/test/fixtures/flow/implements/output.js index 6f2f01668147..b1bd305e650a 100644 --- a/packages/babel-generator/test/fixtures/flow/implements/output.js +++ b/packages/babel-generator/test/fixtures/flow/implements/output.js @@ -1,7 +1,7 @@ -class A implements B {} +class A1 implements B {} -class A implements B, C {} +class A2 implements B, C {} -declare class A implements B {} -declare class A mixins B implements C {} -declare class A implements B, C {} \ No newline at end of file +declare class A3 implements B {} +declare class A4 mixins B implements C {} +declare class A5 implements B, C {} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/interface-types/input.js b/packages/babel-generator/test/fixtures/flow/interface-types/input.js index e475f614c9e3..77d12fad914b 100644 --- a/packages/babel-generator/test/fixtures/flow/interface-types/input.js +++ b/packages/babel-generator/test/fixtures/flow/interface-types/input.js @@ -1,3 +1,4 @@ type A = interface { p: string }; type B = interface extends X { p: string }; type C = interface extends X, Y { p: string }; +type D = interface extends X.Y { p: string }; diff --git a/packages/babel-generator/test/fixtures/flow/interface-types/output.js b/packages/babel-generator/test/fixtures/flow/interface-types/output.js index 6fa9a97f7a1f..5f648bf74774 100644 --- a/packages/babel-generator/test/fixtures/flow/interface-types/output.js +++ b/packages/babel-generator/test/fixtures/flow/interface-types/output.js @@ -6,4 +6,7 @@ type B = interface extends X { }; type C = interface extends X, Y { p: string -}; \ No newline at end of file +}; +type D = interface extends X.Y { + p: string +}; diff --git a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/input.js b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/input.js index 85decdae352b..ea741621024b 100644 --- a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/input.js +++ b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/input.js @@ -1,9 +1,9 @@ -interface A {} -interface A extends B {} -interface A extends B, C {} -interface A { foo: () => number; } +interface A1 {} +interface A2 extends B {} +interface A3 extends B, C {} +interface A4 { foo: () => number; } interface Dictionary { [index: string]: string; length: number; } -class Foo implements Bar {} -class Foo extends Bar implements Bat, Man {} -class Foo extends class Bar implements Bat {} {} -class Foo extends class Bar implements Bat {} implements Man {} +class Foo1 implements Bar {} +class Foo2 extends Bar implements Bat, Man {} +class Foo3 extends class Bar implements Bat {} {} +class Foo4 extends class Bar implements Bat {} implements Man {} diff --git a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/output.js b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/output.js index f6f4341fddb3..ef7fce8a5087 100644 --- a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/output.js +++ b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/output.js @@ -1,7 +1,7 @@ -interface A {} -interface A extends B {} -interface A extends B, C {} -interface A { +interface A1 {} +interface A2 extends B {} +interface A3 extends B, C {} +interface A4 { foo: () => number } interface Dictionary { @@ -9,10 +9,10 @@ interface Dictionary { [index: string]: string, } -class Foo implements Bar {} +class Foo1 implements Bar {} -class Foo extends Bar implements Bat, Man {} +class Foo2 extends Bar implements Bat, Man {} -class Foo extends class Bar implements Bat {} {} +class Foo3 extends class Bar implements Bat {} {} -class Foo extends class Bar implements Bat {} implements Man {} \ No newline at end of file +class Foo4 extends class Bar implements Bat {} implements Man {} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/internal-slot/input.js b/packages/babel-generator/test/fixtures/flow/internal-slot/input.js index 7888fc6cb43e..b00d3bd76f22 100644 --- a/packages/babel-generator/test/fixtures/flow/internal-slot/input.js +++ b/packages/babel-generator/test/fixtures/flow/internal-slot/input.js @@ -1,7 +1,7 @@ declare class C { static [[foo]]: T } declare class C { [[foo]]: T } -interface T { [[foo]]: X } -interface T { [[foo]](): X } -type T = { [[foo]]: X } -type T = { [[foo]](): X } -type T = { [[foo]]?: X } +interface I { [[foo]]: X } +interface I { [[foo]](): X } +type T1 = { [[foo]]: X } +type T2 = { [[foo]](): X } +type T3 = { [[foo]]?: X } diff --git a/packages/babel-generator/test/fixtures/flow/internal-slot/output.js b/packages/babel-generator/test/fixtures/flow/internal-slot/output.js index a8c375a2c456..2a48fb9f186a 100644 --- a/packages/babel-generator/test/fixtures/flow/internal-slot/output.js +++ b/packages/babel-generator/test/fixtures/flow/internal-slot/output.js @@ -4,18 +4,18 @@ declare class C { declare class C { [[foo]]: T } -interface T { +interface I { [[foo]]: X } -interface T { +interface I { [[foo]]() => X } -type T = { +type T1 = { [[foo]]: X }; -type T = { +type T2 = { [[foo]]() => X }; -type T = { +type T3 = { [[foo]]?: X -}; +}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/input.js b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/input.js new file mode 100644 index 000000000000..08324814210d --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/input.js @@ -0,0 +1,4 @@ +type T1 = { ... }; +type T2 = { a: { b: { c: {...}, ... }, ... } } +type T3 = { foo: number, ... }; +type T4 = { foo: number, bar: string, ... }; diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/options.json b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/options.json new file mode 100644 index 000000000000..eb4e948bfaa5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/options.json @@ -0,0 +1,3 @@ +{ + "compact": true +} diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/output.js b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/output.js new file mode 100644 index 000000000000..a0027248e9a5 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types-compact/output.js @@ -0,0 +1 @@ +type T1={...};type T2={a:{b:{c:{...},...},...}};type T3={foo:number,...};type T4={foo:number,bar:string,...}; diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types/input.js b/packages/babel-generator/test/fixtures/flow/object-literal-types/input.js index 6d747ee65e10..9733370c5ff8 100644 --- a/packages/babel-generator/test/fixtures/flow/object-literal-types/input.js +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types/input.js @@ -1,11 +1,15 @@ type U = {}; type V = {}; -type T = { ...U, }; -type T = { ...U, ...V }; -type T = { p: V, ...U }; -type T = { ...U, p: V, }; -type T = { ...{}|{ p: V, }}; -type T = { foo(): number } -type T = { foo: () => number } -type T = { [string]: U }; -type T = { [param: string]: U }; +type T1 = { ...U, }; +type T2 = { ...U, ...V }; +type T3 = { p: V, ...U }; +type T4 = { ...U, p: V, }; +type T5 = { ...{}|{ p: V, }}; +type T6 = { foo(): number } +type T7 = { foo: () => number } +type T8 = { [string]: U }; +type T9 = { [param: string]: U }; +type T10 = { ... }; +type T11 = { a: { b: { c: {...}, ... }, ... } } +type T12 = { foo: number, ... }; +type T13 = { foo: number, bar: string, ... }; diff --git a/packages/babel-generator/test/fixtures/flow/object-literal-types/output.js b/packages/babel-generator/test/fixtures/flow/object-literal-types/output.js index 952f62e3022e..2a3769b1abd5 100644 --- a/packages/babel-generator/test/fixtures/flow/object-literal-types/output.js +++ b/packages/babel-generator/test/fixtures/flow/object-literal-types/output.js @@ -1,30 +1,49 @@ type U = {}; type V = {}; -type T = { ...U +type T1 = { ...U }; -type T = { ...U, +type T2 = { ...U, ...V, }; -type T = { +type T3 = { p: V, ...U, }; -type T = { ...U, +type T4 = { ...U, p: V, }; -type T = { ...{} | { +type T5 = { ...{} | { p: V } }; -type T = { +type T6 = { foo(): number }; -type T = { +type T7 = { foo: () => number }; -type T = { +type T8 = { [string]: U }; -type T = { +type T9 = { [param: string]: U -}; \ No newline at end of file +}; +type T10 = {...}; +type T11 = { + a: { + b: { + c: {...}, + ... + }, + ... + } +}; +type T12 = { + foo: number, + ... +}; +type T13 = { + foo: number, + bar: string, + ... +}; diff --git a/packages/babel-generator/test/fixtures/flow/opaque-type-alias/input.js b/packages/babel-generator/test/fixtures/flow/opaque-type-alias/input.js index 1988fcaeed71..3e77fce2b1ca 100644 --- a/packages/babel-generator/test/fixtures/flow/opaque-type-alias/input.js +++ b/packages/babel-generator/test/fixtures/flow/opaque-type-alias/input.js @@ -1,7 +1,7 @@ opaque type ID = string; opaque type Foo = Bar; opaque type Maybe = _Maybe; -export opaque type Foo = number; +export opaque type Foo2 = number; opaque type union = | {type: "A"} diff --git a/packages/babel-generator/test/fixtures/flow/opaque-type-alias/output.js b/packages/babel-generator/test/fixtures/flow/opaque-type-alias/output.js index d5868b9298d7..293f54010947 100644 --- a/packages/babel-generator/test/fixtures/flow/opaque-type-alias/output.js +++ b/packages/babel-generator/test/fixtures/flow/opaque-type-alias/output.js @@ -1,10 +1,10 @@ opaque type ID = string; opaque type Foo = Bar; opaque type Maybe = _Maybe; -export opaque type Foo = number; +export opaque type Foo2 = number; opaque type union = { type: "A" } | { type: "B" }; -opaque type overloads = (x: string) => number & (x: number) => string; \ No newline at end of file +opaque type overloads = ((x: string) => number) & ((x: number) => string); \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/parantheses/input.js b/packages/babel-generator/test/fixtures/flow/parantheses/input.js new file mode 100644 index 000000000000..f7e2c3973871 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/parantheses/input.js @@ -0,0 +1,3 @@ +type A = ((T) => $Foo) & ((T) => $Foo); +type B = ((T) => $Foo) | ((T) => $Foo); +type C = ((T) => $Foo)[]; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/parantheses/output.js b/packages/babel-generator/test/fixtures/flow/parantheses/output.js new file mode 100644 index 000000000000..f7e2c3973871 --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/parantheses/output.js @@ -0,0 +1,3 @@ +type A = ((T) => $Foo) & ((T) => $Foo); +type B = ((T) => $Foo) | ((T) => $Foo); +type C = ((T) => $Foo)[]; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/predicates/input.js b/packages/babel-generator/test/fixtures/flow/predicates/input.js index bbbbe2c8f2a6..8e614a82f184 100644 --- a/packages/babel-generator/test/fixtures/flow/predicates/input.js +++ b/packages/babel-generator/test/fixtures/flow/predicates/input.js @@ -12,6 +12,6 @@ function is_string(x): boolean %checks { var f = (x: mixed): %checks => typeof x === "string"; -const foo = (x: mixed): boolean %checks => typeof x === "string"; +const foo2 = (x: mixed): boolean %checks => typeof x === "string"; (x): %checks => x !== null; diff --git a/packages/babel-generator/test/fixtures/flow/predicates/output.js b/packages/babel-generator/test/fixtures/flow/predicates/output.js index 23ddac63478f..bc1ac228aaa1 100644 --- a/packages/babel-generator/test/fixtures/flow/predicates/output.js +++ b/packages/babel-generator/test/fixtures/flow/predicates/output.js @@ -12,6 +12,6 @@ function is_string(x): boolean %checks { var f = (x: mixed): %checks => typeof x === "string"; -const foo = (x: mixed): boolean %checks => typeof x === "string"; +const foo2 = (x: mixed): boolean %checks => typeof x === "string"; x: %checks => x !== null; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/string-literal-types/input.js b/packages/babel-generator/test/fixtures/flow/string-literal-types/input.js index 6acd7f134271..a80478634827 100644 --- a/packages/babel-generator/test/fixtures/flow/string-literal-types/input.js +++ b/packages/babel-generator/test/fixtures/flow/string-literal-types/input.js @@ -1,2 +1,2 @@ -function createElement(tagName: "div"): HTMLDivElement {} -function createElement(tagName: 'div'): HTMLDivElement {} +function createElement1(tagName: "div"): HTMLDivElement {} +function createElement2(tagName: 'div'): HTMLDivElement {} diff --git a/packages/babel-generator/test/fixtures/flow/string-literal-types/output.js b/packages/babel-generator/test/fixtures/flow/string-literal-types/output.js index 97251990f3ea..523469a5c34f 100644 --- a/packages/babel-generator/test/fixtures/flow/string-literal-types/output.js +++ b/packages/babel-generator/test/fixtures/flow/string-literal-types/output.js @@ -1,3 +1,3 @@ -function createElement(tagName: "div"): HTMLDivElement {} +function createElement1(tagName: "div"): HTMLDivElement {} -function createElement(tagName: 'div'): HTMLDivElement {} \ No newline at end of file +function createElement2(tagName: 'div'): HTMLDivElement {} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/type-alias/input.js b/packages/babel-generator/test/fixtures/flow/type-alias/input.js index ed16c5d28d5a..c1d567e6dfdd 100644 --- a/packages/babel-generator/test/fixtures/flow/type-alias/input.js +++ b/packages/babel-generator/test/fixtures/flow/type-alias/input.js @@ -1,7 +1,7 @@ type FBID = number; type Foo = Bar; type Maybe = _Maybe; -export type Foo = number; +export type Foo2 = number; type union = | {type: "A"} @@ -14,3 +14,5 @@ type overloads = ; type func = string => string; + +type D = X.Y; diff --git a/packages/babel-generator/test/fixtures/flow/type-alias/output.js b/packages/babel-generator/test/fixtures/flow/type-alias/output.js index dc12829d21c7..51933a7a774e 100644 --- a/packages/babel-generator/test/fixtures/flow/type-alias/output.js +++ b/packages/babel-generator/test/fixtures/flow/type-alias/output.js @@ -1,11 +1,12 @@ type FBID = number; type Foo = Bar; type Maybe = _Maybe; -export type Foo = number; +export type Foo2 = number; type union = { type: "A" } | { type: "B" }; -type overloads = (x: string) => number & (x: number) => string; +type overloads = ((x: string) => number) & ((x: number) => string); type func = (string) => string; +type D = X.Y; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/input.js b/packages/babel-generator/test/fixtures/flow/type-annotations/input.js index d94dd1ce665c..e7335c30b72a 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/input.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/input.js @@ -1,130 +1,130 @@ -function foo(numVal: any) {} -function foo(numVal: number) {} -function foo(numVal: number, strVal: string) {} -function foo(numVal: number, untypedVal) {} -function foo(untypedVal, numVal: number) {} -function foo(nullableNum: ?number) {} -function foo(callback: () => void) {} -function foo(callback: () => number) {} -function foo(callback: (_: bool) => number) {} -function foo(callback: (_1: bool, _2: string) => number) {} -function foo(callback: (_1: bool, ...foo: Array) => number) {} -function foo(): number{} -function foo():() => void {} -function foo():(_:bool) => number{} -function foo():(_?:bool) => number{} -function foo(): {} {} -function foo() {} -function foo() {} -function foo() {} -a = function() {}; -a = { set fooProp(value: number) {} }; -a = { set fooProp(value: number): void {} }; -a = { get fooProp():number{} }; -a = { id(x: T): T {} }; -a = { *id(x: T): T {} }; -a = { async id(x: T): T {} }; -a = { 123(x: T): T {} }; -class Foo { +function foo1(numVal: any) {} +function foo2(numVal: number) {} +function foo3(numVal: number, strVal: string) {} +function foo4(numVal: number, untypedVal) {} +function foo5(untypedVal, numVal: number) {} +function foo6(nullableNum: ?number) {} +function foo7(callback: () => void) {} +function foo8(callback: () => number) {} +function foo9(callback: (_: bool) => number) {} +function foo10(callback: (_1: bool, _2: string) => number) {} +function foo11(callback: (_1: bool, ...foo: Array) => number) {} +function foo12(): number{} +function foo13():() => void {} +function foo14():(_:bool) => number{} +function foo15():(_?:bool) => number{} +function foo16(): {} {} +function foo17() {} +function foo18() {} +function foo19() {} +a1 = function() {}; +a2 = { set fooProp(value: number) {} }; +a3 = { set fooProp(value: number): void {} }; +a4 = { get fooProp():number{} }; +a5 = { id(x: T): T {} }; +a6 = { *id(x: T): T {} }; +a7 = { async id(x: T): T {} }; +a8 = { 123(x: T): T {} }; +class Foo1 { set fooProp(value: number) {} } -class Foo { +class Foo2 { set fooProp(value: number): void {} } -class Foo { +class Foo3 { get fooProp(): number {} } -var numVal: number; -var numVal: empty; -var numVal: mixed; -var numVal: number = otherNumVal; -var a: { numVal: number }; -var a: { numVal: number; }; -var a: { numVal: number; [indexer: string]: number }; -var a: ?{ numVal: number }; -var a: { numVal: number; strVal: string } -var a: { subObj: {strVal: string} } -var a: { subObj: ?{strVal: string} } -var a: { param1: number; param2: string } -var a: { param1: number; param2?: string } -var a: { [a: number]: string; [b: number]: string; }; -var a: { add(x: number, ...y: Array): void }; -var a: { subtract: (x: number, ...y: Array) => void }; -var a: { id(x: T): T; }; -var a:Array = [1, 2, 3] -a = class Foo {} -a = class Foo extends Bar {} -class Foo {} -class Foo extends Bar {} -class Foo extends mixin(Bar) {} -class Foo { +var numVal1: number; +var numVal2: empty; +var numVal3: mixed; +var numVal4: number = otherNumVal; +var a1: { numVal: number }; +var a2: { numVal: number; }; +var a3: { numVal: number; [indexer: string]: number }; +var a4: ?{ numVal: number }; +var a5: { numVal: number; strVal: string } +var a6: { subObj: {strVal: string} } +var a7: { subObj: ?{strVal: string} } +var a8: { param1: number; param2: string } +var a9: { param1: number; param2?: string } +var a10: { [a: number]: string; [b: number]: string; }; +var a11: { add(x: number, ...y: Array): void }; +var a12: { subtract: (x: number, ...y: Array) => void }; +var a13: { id(x: T): T; }; +var a14:Array = [1, 2, 3] +a13 = class Foo {} +a14 = class Foo extends Bar {} +class Foo4 {} +class Foo5 extends Bar {} +class Foo6 extends mixin(Bar) {} +class Foo7 { bar():number { return 42; } } -class Foo { +class Foo8 { "bar"() {} } -function foo(requiredParam, optParam?) {} -class Foo { +function foo20(requiredParam, optParam?) {} +class Foo9 { prop1: string; prop2: number; } -class Foo { +class Foo10 { static prop1: string; prop2: number; } -class Foo { +class Foo11 { #prop1: string; prop2: number; } -var x: number | string = 4; +var x1: number | string = 4; class Array { concat(items:number | string) {}; } -var x: () => number | () => string = fn; -var x: typeof Y = Y; -var x: typeof Y | number = Y; -var {x}: {x: string; } = { x: "hello" }; -var {x}: {x: string } = { x: "hello" }; -var [x]: Array = [ "hello" ]; -function foo({x}: { x: string; }) {} -function foo([x]: Array) {} -function foo(...rest: Array) {} +var x2: () => number | () => string = fn; +var x3: typeof Y = Y; +var x4: typeof Y | number = Y; +var {x5}: {x5: string; } = { x5: "hello" }; +var {x6}: {x6: string } = { x6: "hello" }; +var [x7]: Array = [ "hello" ]; +function foo21({x}: { x: string; }) {} +function foo22([x]: Array) {} +function foo23(...rest: Array) {} (function (...rest: Array) {}); ((...rest: Array) => rest); -var a: Map > -var a: Map> -var a: number[] -var a: ?string[] -var a: Promise[] -var a:(...rest:Array) => number -var identity: (x: T) => T -var identity: (x: T, ...y:T[]) => T -import type foo from "bar"; -import type { foo, bar } from "baz"; -import type { foo as bar } from "baz"; +var a15: Map > +var a16: Map> +var a17: number[] +var a18: ?string[] +var a19: Promise[] +var a20:(...rest:Array) => number +var identity1: (x: T) => T +var identity2: (x: T, ...y:T[]) => T +import type foo24 from "bar"; +import type { foo25, bar1 } from "baz"; +import type { foo as bar2 } from "baz"; import type from "foo"; -import type, { foo } from "bar"; +import type2, { foo26 } from "bar"; import typeof * as namespace from "bar"; -import { type Foo } from "bar"; -import { typeof Foo } from "bar"; -import { type Foo as Bar } from "bar"; -import { typeof Foo as Bar } from "bar"; -export type { foo }; +import { type Foo12 } from "bar"; +import { typeof Foo13 } from "bar"; +import { type Foo as Bar1 } from "bar"; +import { typeof Foo as Bar2 } from "bar"; +export type { foo1 }; export type { bar } from "bar"; export interface baz { p: number } export interface qux { p: T } -var a: ?Array; -var a: {| numVal: number |}; -var a: {| numVal: number; |}; -var a: {| numVal: number; [indexer: string]: number |}; -var a: ?{| numVal: number |}; -var a: {| numVal: number; strVal: string |} -var a: {| subObj: {strVal: string} |} -var a: {| subObj: ?{strVal: string} |} -var a: {| param1: number; param2: string |} -var a: {| param1: number; param2?: string |} -var a: {| [a: number]: string; [b: number]: string; |}; -var a: {| add(x: number, ...y: Array): void |}; -var a: {| subtract: (x: number, ...y: Array) => void |}; -var a: {| id(x: T): T; |}; -function foo(numVal: number = 2) {} -function foo(numVal?: number = 2) {} +var a21: ?Array; +var a22: {| numVal: number |}; +var a23: {| numVal: number; |}; +var a24: {| numVal: number; [indexer: string]: number |}; +var a25: ?{| numVal: number |}; +var a26: {| numVal: number; strVal: string |} +var a27: {| subObj: {strVal: string} |} +var a28: {| subObj: ?{strVal: string} |} +var a29: {| param1: number; param2: string |} +var a30: {| param1: number; param2?: string |} +var a31: {| [a: number]: string; [b: number]: string; |}; +var a32: {| add(x: number, ...y: Array): void |}; +var a33: {| subtract: (x: number, ...y: Array) => void |}; +var a34: {| id(x: T): T; |}; +function foo27(numVal: number = 2) {} +function foo28(numVal?: number = 2) {} export type * from "foo"; diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/output.js b/packages/babel-generator/test/fixtures/flow/type-annotations/output.js index 433354505279..6465359f336d 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/output.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/output.js @@ -1,237 +1,237 @@ -function foo(numVal: any) {} +function foo1(numVal: any) {} -function foo(numVal: number) {} +function foo2(numVal: number) {} -function foo(numVal: number, strVal: string) {} +function foo3(numVal: number, strVal: string) {} -function foo(numVal: number, untypedVal) {} +function foo4(numVal: number, untypedVal) {} -function foo(untypedVal, numVal: number) {} +function foo5(untypedVal, numVal: number) {} -function foo(nullableNum: ?number) {} +function foo6(nullableNum: ?number) {} -function foo(callback: () => void) {} +function foo7(callback: () => void) {} -function foo(callback: () => number) {} +function foo8(callback: () => number) {} -function foo(callback: (_: boolean) => number) {} +function foo9(callback: (_: boolean) => number) {} -function foo(callback: (_1: boolean, _2: string) => number) {} +function foo10(callback: (_1: boolean, _2: string) => number) {} -function foo(callback: (_1: boolean, ...foo: Array) => number) {} +function foo11(callback: (_1: boolean, ...foo: Array) => number) {} -function foo(): number {} +function foo12(): number {} -function foo(): () => void {} +function foo13(): () => void {} -function foo(): (_: boolean) => number {} +function foo14(): (_: boolean) => number {} -function foo(): (_?: boolean) => number {} +function foo15(): (_?: boolean) => number {} -function foo(): {} {} +function foo16(): {} {} -function foo() {} +function foo17() {} -function foo() {} +function foo18() {} -function foo() {} +function foo19() {} -a = function () {}; +a1 = function () {}; -a = { +a2 = { set fooProp(value: number) {} }; -a = { +a3 = { set fooProp(value: number): void {} }; -a = { +a4 = { get fooProp(): number {} }; -a = { +a5 = { id(x: T): T {} }; -a = { +a6 = { *id(x: T): T {} }; -a = { +a7 = { async id(x: T): T {} }; -a = { +a8 = { 123(x: T): T {} }; -class Foo { +class Foo1 { set fooProp(value: number) {} } -class Foo { +class Foo2 { set fooProp(value: number): void {} } -class Foo { +class Foo3 { get fooProp(): number {} } -var numVal: number; -var numVal: empty; -var numVal: mixed; -var numVal: number = otherNumVal; -var a: { +var numVal1: number; +var numVal2: empty; +var numVal3: mixed; +var numVal4: number = otherNumVal; +var a1: { numVal: number }; -var a: { +var a2: { numVal: number }; -var a: { +var a3: { numVal: number, [indexer: string]: number, }; -var a: ?{ +var a4: ?{ numVal: number }; -var a: { +var a5: { numVal: number, strVal: string, }; -var a: { +var a6: { subObj: { strVal: string } }; -var a: { +var a7: { subObj: ?{ strVal: string } }; -var a: { +var a8: { param1: number, param2: string, }; -var a: { +var a9: { param1: number, param2?: string, }; -var a: { +var a10: { [a: number]: string, [b: number]: string, }; -var a: { +var a11: { add(x: number, ...y: Array): void }; -var a: { +var a12: { subtract: (x: number, ...y: Array) => void }; -var a: { +var a13: { id(x: T): T }; -var a: Array = [1, 2, 3]; -a = class Foo {}; -a = class Foo extends Bar {}; +var a14: Array = [1, 2, 3]; +a13 = class Foo {}; +a14 = class Foo extends Bar {}; -class Foo {} +class Foo4 {} -class Foo extends Bar {} +class Foo5 extends Bar {} -class Foo extends mixin(Bar) {} +class Foo6 extends mixin(Bar) {} -class Foo { +class Foo7 { bar(): number { return 42; } } -class Foo { +class Foo8 { "bar"() {} } -function foo(requiredParam, optParam?) {} +function foo20(requiredParam, optParam?) {} -class Foo { +class Foo9 { prop1: string; prop2: number; } -class Foo { +class Foo10 { static prop1: string; prop2: number; } -class Foo { +class Foo11 { #prop1: string; prop2: number; } -var x: number | string = 4; +var x1: number | string = 4; class Array { concat(items: number | string) {} } -var x: () => number | () => string = fn; -var x: typeof Y = Y; -var x: typeof Y | number = Y; +var x2: () => number | (() => string) = fn; +var x3: typeof Y = Y; +var x4: typeof Y | number = Y; var { - x + x5 }: { - x: string + x5: string } = { - x: "hello" + x5: "hello" }; var { - x + x6 }: { - x: string + x6: string } = { - x: "hello" + x6: "hello" }; -var [x]: Array = ["hello"]; +var [x7]: Array = ["hello"]; -function foo({ +function foo21({ x }: { x: string }) {} -function foo([x]: Array) {} +function foo22([x]: Array) {} -function foo(...rest: Array) {} +function foo23(...rest: Array) {} (function (...rest: Array) {}); (...rest: Array) => rest; -var a: Map>; -var a: Map>; -var a: number[]; -var a: ?string[]; -var a: Promise[]; -var a: (...rest: Array) => number; -var identity: (x: T) => T; -var identity: (x: T, ...y: T[]) => T; -import type foo from "bar"; -import type { foo, bar } from "baz"; -import type { foo as bar } from "baz"; +var a15: Map>; +var a16: Map>; +var a17: number[]; +var a18: ?string[]; +var a19: Promise[]; +var a20: (...rest: Array) => number; +var identity1: (x: T) => T; +var identity2: (x: T, ...y: T[]) => T; +import type foo24 from "bar"; +import type { foo25, bar1 } from "baz"; +import type { foo as bar2 } from "baz"; import type from "foo"; -import type, { foo } from "bar"; +import type2, { foo26 } from "bar"; import typeof * as namespace from "bar"; -import { type Foo } from "bar"; -import { typeof Foo } from "bar"; -import { type Foo as Bar } from "bar"; -import { typeof Foo as Bar } from "bar"; -export type { foo }; +import { type Foo12 } from "bar"; +import { typeof Foo13 } from "bar"; +import { type Foo as Bar1 } from "bar"; +import { typeof Foo as Bar2 } from "bar"; +export type { foo1 }; export type { bar } from "bar"; export interface baz { p: number @@ -239,58 +239,58 @@ export interface baz { export interface qux { p: T } -var a: ?Array; -var a: {| +var a21: ?Array; +var a22: {| numVal: number |}; -var a: {| +var a23: {| numVal: number |}; -var a: {| +var a24: {| numVal: number, [indexer: string]: number, |}; -var a: ?{| +var a25: ?{| numVal: number |}; -var a: {| +var a26: {| numVal: number, strVal: string, |}; -var a: {| +var a27: {| subObj: { strVal: string } |}; -var a: {| +var a28: {| subObj: ?{ strVal: string } |}; -var a: {| +var a29: {| param1: number, param2: string, |}; -var a: {| +var a30: {| param1: number, param2?: string, |}; -var a: {| +var a31: {| [a: number]: string, [b: number]: string, |}; -var a: {| +var a32: {| add(x: number, ...y: Array): void |}; -var a: {| +var a33: {| subtract: (x: number, ...y: Array) => void |}; -var a: {| +var a34: {| id(x: T): T |}; -function foo(numVal: number = 2) {} +function foo27(numVal: number = 2) {} -function foo(numVal?: number = 2) {} +function foo28(numVal?: number = 2) {} export type * from "foo"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/flow/type-parameters/input.js b/packages/babel-generator/test/fixtures/flow/type-parameters/input.js index a995d06499f4..5d0b94ca1569 100644 --- a/packages/babel-generator/test/fixtures/flow/type-parameters/input.js +++ b/packages/babel-generator/test/fixtures/flow/type-parameters/input.js @@ -1,21 +1,21 @@ -type A = T; -type A = T; -type A = T; -type A = T; -type A = T; -class A {} -class A {} -class A {} -class A {} -(class A {}); -(class A {}); -(class A {}); -(class A {}); -declare class A {} -declare class A {} -declare class A {} -declare class A {} -interface A {} -interface A {} -interface A {} -interface A {} +type A1 = T; +type A2 = T; +type A3 = T; +type A4 = T; +type A5 = T; +class A6 {} +class A7 {} +class A8 {} +class A9 {} +(class A10 {}); +(class A11 {}); +(class A12 {}); +(class A13 {}); +declare class A14 {} +declare class A15 {} +declare class A16 {} +declare class A17 {} +interface A18 {} +interface A19 {} +interface A20 {} +interface A21 {} diff --git a/packages/babel-generator/test/fixtures/flow/type-parameters/output.js b/packages/babel-generator/test/fixtures/flow/type-parameters/output.js index f4477884494d..768f82b1feaf 100644 --- a/packages/babel-generator/test/fixtures/flow/type-parameters/output.js +++ b/packages/babel-generator/test/fixtures/flow/type-parameters/output.js @@ -1,30 +1,30 @@ -type A = T; -type A = T; -type A = T; -type A = T; -type A = T; +type A1 = T; +type A2 = T; +type A3 = T; +type A4 = T; +type A5 = T; -class A {} +class A6 {} -class A {} +class A7 {} -class A {} +class A8 {} -class A {} +class A9 {} -(class A {}); +(class A10 {}); -(class A {}); +(class A11 {}); -(class A {}); +(class A12 {}); -(class A {}); +(class A13 {}); -declare class A {} -declare class A {} -declare class A {} -declare class A {} -interface A {} -interface A {} -interface A {} -interface A {} \ No newline at end of file +declare class A14 {} +declare class A15 {} +declare class A16 {} +declare class A17 {} +interface A18 {} +interface A19 {} +interface A20 {} +interface A21 {} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/input.js index b9325bbae180..a198e5160062 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/input.js @@ -4,15 +4,15 @@ function t2({responseText}) { } function t3([a, b]) { } -var [i, j, k] = array; +var [i1, j1, k1] = array; var { - i, - j, - k + i2, + j2, + k2 } = obj; -let {i, j, k} = obj; -const {i, j, k} = obj; -var { value } = obj; +let {i3, j3, k3} = obj; +const {i4, j4, k4} = obj; +var { value1 } = obj; var { - value + value2 } = obj; diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/output.js index 8c09588f29a4..65da4d30e45d 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/destructuring-assignment/output.js @@ -8,25 +8,25 @@ function t2({ function t3([a, b]) {} -var [i, j, k] = array; +var [i1, j1, k1] = array; var { - i, - j, - k + i2, + j2, + k2 } = obj; let { - i, - j, - k + i3, + j3, + k3 } = obj; const { - i, - j, - k + i4, + j4, + k4 } = obj; var { - value + value1 } = obj; var { - value + value2 } = obj; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js index ec680f05ac1d..540245d565b3 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/input.js @@ -1,3 +1,4 @@ +var a, c; export * from "OK" export { name } from "OK" export { a as b, c as d } from "hello" diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js index 5482292b19a7..84c968fe12a3 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/exports/output.js @@ -1,3 +1,4 @@ +var a, c; export * from "OK"; export { name } from "OK"; export { a as b, c as d } from "hello"; diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/input.js index 7fb048846d58..0b3e895ed0cc 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/input.js @@ -1,5 +1,5 @@ -import foo from "foo"; -import * as foo from "foo"; +import foo1 from "foo"; +import * as foo2 from "foo"; import ok, { foo as bar, test as testing, diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/output.js index 26bcdddc4545..0cc3e0472082 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/import-with-default/output.js @@ -1,3 +1,3 @@ -import foo from "foo"; -import * as foo from "foo"; +import foo1 from "foo"; +import * as foo2 from "foo"; import ok, { foo as bar, test as testing, logging } from "foo"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/imports/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/imports/input.js index 98bbc6bbcb68..db91fc8028d1 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/imports/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/imports/input.js @@ -1,8 +1,8 @@ import "foo"; import {foo} from "foo"; -import {foo as bar} from "foo"; +import {foo as bar1} from "foo"; import { - foo as bar, + foo as bar2, test as testing, logging } from "foo"; diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/imports/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/imports/output.js index 2406027fa302..651af1c0fe4a 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/imports/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/imports/output.js @@ -1,4 +1,4 @@ import "foo"; import { foo } from "foo"; -import { foo as bar } from "foo"; -import { foo as bar, test as testing, logging } from "foo"; \ No newline at end of file +import { foo as bar1 } from "foo"; +import { foo as bar2, test as testing, logging } from "foo"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/input.js b/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/input.js index c4cd936913e0..6e3396d15676 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/input.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/input.js @@ -1,5 +1,5 @@ -var [a, b, ...rest] = array; -const [a, b, ...rest] = array; -function a([a, b, ...rest]) { +var [a1, b1, ...rest1] = array; +const [a2, b2, ...rest2] = array; +function a([a1, b1, ...rest1]) { } -([a, b, ...rest]) => { }; +([a1, b1, ...rest1]) => { }; diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/output.js b/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/output.js index d378ae924426..070fa55a1f3d 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/output.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/spread-element/output.js @@ -1,6 +1,6 @@ -var [a, b, ...rest] = array; -const [a, b, ...rest] = array; +var [a1, b1, ...rest1] = array; +const [a2, b2, ...rest2] = array; -function a([a, b, ...rest]) {} +function a([a1, b1, ...rest1]) {} -([a, b, ...rest]) => {}; \ No newline at end of file +([a1, b1, ...rest1]) => {}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/misc/placeholders/input.js b/packages/babel-generator/test/fixtures/misc/placeholders/input.js new file mode 100644 index 000000000000..42eb25727b64 --- /dev/null +++ b/packages/babel-generator/test/fixtures/misc/placeholders/input.js @@ -0,0 +1,8 @@ +var %%a%% = %%b%% + +%%c%% + +class %%d%% {} +class A %%e%% + +function %%f%%(...%%g%%) %%h%% diff --git a/packages/babel-generator/test/fixtures/misc/placeholders/options.json b/packages/babel-generator/test/fixtures/misc/placeholders/options.json new file mode 100644 index 000000000000..92404e501295 --- /dev/null +++ b/packages/babel-generator/test/fixtures/misc/placeholders/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["placeholders"] +} diff --git a/packages/babel-generator/test/fixtures/misc/placeholders/output.js b/packages/babel-generator/test/fixtures/misc/placeholders/output.js new file mode 100644 index 000000000000..82ad54ecc61e --- /dev/null +++ b/packages/babel-generator/test/fixtures/misc/placeholders/output.js @@ -0,0 +1,8 @@ +var %%a%% = %%b%%; +%%c%%; + +class %%d%% {} + +class A %%e%% + +function %%f%%(...%%g%%) %%h%% \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/parentheses/class-extends/input.js b/packages/babel-generator/test/fixtures/parentheses/class-extends/input.js index 308200e8d2e4..23e941a3b122 100644 --- a/packages/babel-generator/test/fixtures/parentheses/class-extends/input.js +++ b/packages/babel-generator/test/fixtures/parentheses/class-extends/input.js @@ -1,22 +1,22 @@ -class A extends (() => {}) {} -class A extends (B = C) {} -class A extends (B || C) {} -class A extends (B + C) {} -class A extends B() {} -class A extends class {} {} -class A extends (B ? C : D) {} -class A extends (new B()) {} -class A extends (B, C) {} -class A extends ({}) {} -class A extends B.C {} -class A extends function() {} {} -class A extends (void B) {} -class A extends (++B) {} +class A1 extends (() => {}) {} +class A2 extends (B = C) {} +class A3 extends (B || C) {} +class A4 extends (B + C) {} +class A5 extends B() {} +class A6 extends class {} {} +class A7 extends (B ? C : D) {} +class A8 extends (new B()) {} +class A9 extends (B, C) {} +class A10 extends ({}) {} +class A11 extends B.C {} +class A12 extends function() {} {} +class A13 extends (void B) {} +class A14 extends (++B) {} -async function f() { - class A extends (await C) {} +async function f1() { + class A15 extends (await C) {} } -function* f() { - class A extends (yield 1) {} +function* f2() { + class A16 extends (yield 1) {} } diff --git a/packages/babel-generator/test/fixtures/parentheses/class-extends/output.js b/packages/babel-generator/test/fixtures/parentheses/class-extends/output.js index 4b67a09f7e4a..a898c15b5a13 100644 --- a/packages/babel-generator/test/fixtures/parentheses/class-extends/output.js +++ b/packages/babel-generator/test/fixtures/parentheses/class-extends/output.js @@ -1,35 +1,35 @@ -class A extends (() => {}) {} +class A1 extends (() => {}) {} -class A extends (B = C) {} +class A2 extends (B = C) {} -class A extends (B || C) {} +class A3 extends (B || C) {} -class A extends (B + C) {} +class A4 extends (B + C) {} -class A extends B() {} +class A5 extends B() {} -class A extends class {} {} +class A6 extends class {} {} -class A extends (B ? C : D) {} +class A7 extends (B ? C : D) {} -class A extends (new B()) {} +class A8 extends (new B()) {} -class A extends (B, C) {} +class A9 extends (B, C) {} -class A extends {} {} +class A10 extends {} {} -class A extends B.C {} +class A11 extends B.C {} -class A extends function () {} {} +class A12 extends function () {} {} -class A extends (void B) {} +class A13 extends (void B) {} -class A extends (++B) {} +class A14 extends (++B) {} -async function f() { - class A extends (await C) {} +async function f1() { + class A15 extends (await C) {} } -function* f() { - class A extends (yield 1) {} +function* f2() { + class A16 extends (yield 1) {} } \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/parentheses/terminator-break/input.js b/packages/babel-generator/test/fixtures/parentheses/terminator-break/input.js index ad3ad2eecf90..b7fe375717db 100644 --- a/packages/babel-generator/test/fixtures/parentheses/terminator-break/input.js +++ b/packages/babel-generator/test/fixtures/parentheses/terminator-break/input.js @@ -1,10 +1,10 @@ -function foo() { +function foo1() { return ( // foobar "bar" ); } -function foo() { +function foo2() { return ( // foobar "bar" diff --git a/packages/babel-generator/test/fixtures/parentheses/terminator-break/output.js b/packages/babel-generator/test/fixtures/parentheses/terminator-break/output.js index 1267e861f3a4..7ec6459a0d85 100644 --- a/packages/babel-generator/test/fixtures/parentheses/terminator-break/output.js +++ b/packages/babel-generator/test/fixtures/parentheses/terminator-break/output.js @@ -1,10 +1,10 @@ -function foo() { +function foo1() { return (// foobar "bar" ); } -function foo() { +function foo2() { return (// foobar "bar" ); diff --git a/packages/babel-generator/test/fixtures/parentheses/yield-expression/input.js b/packages/babel-generator/test/fixtures/parentheses/yield-expression/input.js index b000b972b537..2d6b7957f17c 100644 --- a/packages/babel-generator/test/fixtures/parentheses/yield-expression/input.js +++ b/packages/babel-generator/test/fixtures/parentheses/yield-expression/input.js @@ -10,3 +10,7 @@ function* asdf() { function* a(b) { (yield xhr({ url: "views/test.html" })).data; } + +(async function* () { + await (yield 1); +}); diff --git a/packages/babel-generator/test/fixtures/parentheses/yield-expression/output.js b/packages/babel-generator/test/fixtures/parentheses/yield-expression/output.js index 28340375a453..e7c3bcd100df 100644 --- a/packages/babel-generator/test/fixtures/parentheses/yield-expression/output.js +++ b/packages/babel-generator/test/fixtures/parentheses/yield-expression/output.js @@ -11,4 +11,8 @@ function* a(b) { (yield xhr({ url: "views/test.html" })).data; -} \ No newline at end of file +} + +(async function* () { + await (yield 1); +}); diff --git a/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/input.js b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/input.js new file mode 100644 index 000000000000..29e9b90f83e0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/input.js @@ -0,0 +1,12 @@ +foo(?); +foo(?, x); +foo(x, ?); +foo(?, x, ?); +obj.foo(x, ?); +obj.foo(?, x); +obj.foo(?, x, ?); +class foo { + constructor() { + baz(this, () => super.bar(?)); + } +} diff --git a/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/options.json b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/options.json new file mode 100644 index 000000000000..eff064512269 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/options.json @@ -0,0 +1 @@ +{ "plugins": ["partialApplication"] } diff --git a/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/output.js b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/output.js new file mode 100644 index 000000000000..7cb1b16bd55e --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/ArgumentPlaceholder/output.js @@ -0,0 +1,14 @@ +foo(?); +foo(?, x); +foo(x, ?); +foo(?, x, ?); +obj.foo(x, ?); +obj.foo(?, x); +obj.foo(?, x, ?); + +class foo { + constructor() { + baz(this, () => super.bar(?)); + } + +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js index bec3598e321c..ae3f4b33c003 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js @@ -5,12 +5,31 @@ class Foo { get foo() {} set foo(bar) {} + async #foo() {} + #foo() {} + get #foo() {} + set #foo(bar) {} + * #foo() {} + async * #foo() {} + get #bar() {} + set #baz(taz) {} + static async foo() {} static foo() {} static ["foo"]() {} static get foo() {} static set foo(bar) {} static static() {} + static * foo() {} + static async * foo() {} + + static #foo() {} + static async #foo() {} + static ["foo"]() {} + static get #foo() {} + static set #foo(taz) {} + static * #foo() {} + static async * #foo() {} get () {} @@ -52,4 +71,4 @@ class Foo { get static () {} -} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/options.json b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/options.json new file mode 100644 index 000000000000..894b1b617167 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/options.json @@ -0,0 +1 @@ +{ "plugins": ["classPrivateMethods", "asyncGenerators"] } diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js index 4676bff086d0..24f3e9229c84 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js @@ -9,6 +9,22 @@ class Foo { set foo(bar) {} + async #foo() {} + + #foo() {} + + get #foo() {} + + set #foo(bar) {} + + *#foo() {} + + async *#foo() {} + + get #bar() {} + + set #baz(taz) {} + static async foo() {} static foo() {} @@ -21,6 +37,24 @@ class Foo { static static() {} + static *foo() {} + + static async *foo() {} + + static #foo() {} + + static async #foo() {} + + static ["foo"]() {} + + static get #foo() {} + + static set #foo(taz) {} + + static *#foo() {} + + static async *#foo() {} + get() {} set() {} diff --git a/packages/babel-generator/test/fixtures/types/ClassExpression/input.js b/packages/babel-generator/test/fixtures/types/ClassExpression/input.js index 1931f1faeae2..195044c70d69 100644 --- a/packages/babel-generator/test/fixtures/types/ClassExpression/input.js +++ b/packages/babel-generator/test/fixtures/types/ClassExpression/input.js @@ -1,2 +1,2 @@ class Foo {} -class Foo extends Bar {} +class Foo2 extends Bar {} diff --git a/packages/babel-generator/test/fixtures/types/ClassExpression/output.js b/packages/babel-generator/test/fixtures/types/ClassExpression/output.js index 5355e2a5ed56..500088a1f3f7 100644 --- a/packages/babel-generator/test/fixtures/types/ClassExpression/output.js +++ b/packages/babel-generator/test/fixtures/types/ClassExpression/output.js @@ -1,3 +1,3 @@ class Foo {} -class Foo extends Bar {} \ No newline at end of file +class Foo2 extends Bar {} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/Decorator/input.js b/packages/babel-generator/test/fixtures/types/Decorator/input.js index f1946c7635fa..198a50e9c7a6 100644 --- a/packages/babel-generator/test/fixtures/types/Decorator/input.js +++ b/packages/babel-generator/test/fixtures/types/Decorator/input.js @@ -31,14 +31,14 @@ class Foo { } @foo -export default class Foo { +export default class Foo2 { bar() { class Baz {} } } @foo -export class Foo { +export class Foo3 { bar() { class Baz {} } diff --git a/packages/babel-generator/test/fixtures/types/Decorator/output.js b/packages/babel-generator/test/fixtures/types/Decorator/output.js index 5c526f5f61f9..db5f62ff6b7c 100644 --- a/packages/babel-generator/test/fixtures/types/Decorator/output.js +++ b/packages/babel-generator/test/fixtures/types/Decorator/output.js @@ -33,14 +33,14 @@ class Foo { } export default @foo -class Foo { +class Foo2 { bar() { class Baz {} } } export @foo -class Foo { +class Foo3 { bar() { class Baz {} } diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js index f40ac5c3434e..701c971b8991 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/input.js @@ -1 +1,2 @@ export { foo }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js index f604032cb6d6..520c0fb1dda1 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier11/output.js @@ -1 +1,2 @@ -export { foo }; \ No newline at end of file +export { foo }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js index 9dfa348be312..5e6c6606032a 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/input.js @@ -1 +1,2 @@ export { foo, bar }; +var foo, bar; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js index 4cb44a4b2592..be6d973b815d 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier12/output.js @@ -1 +1,2 @@ -export { foo, bar }; \ No newline at end of file +export { foo, bar }; +var foo, bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js index e4cca384daec..dd1cfea6d77d 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/input.js @@ -1 +1,2 @@ export { foo as bar }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js index 5d4569c099d2..d6e7ac50254e 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier13/output.js @@ -1 +1,2 @@ -export { foo as bar }; \ No newline at end of file +export { foo as bar }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js index 95daad9d9676..5e840fff920b 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/input.js @@ -1 +1,2 @@ export { foo as default }; +var foo; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js index f96da82b3b2c..4a3a9fe44ea7 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier14/output.js @@ -1 +1,2 @@ -export { foo as default }; \ No newline at end of file +export { foo as default }; +var foo; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js index ebd14b2d969e..022457fd87a6 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/input.js @@ -1 +1,2 @@ export { foo as default, bar }; +var foo, bar; diff --git a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js index 2ef73817d596..974c22ae14f2 100644 --- a/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js +++ b/packages/babel-generator/test/fixtures/types/ExportSpecifier15/output.js @@ -1 +1,2 @@ -export { foo as default, bar }; \ No newline at end of file +export { foo as default, bar }; +var foo, bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/input.js b/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/input.js index 3b31e93eb772..c42d876ad7b2 100644 --- a/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/input.js +++ b/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/input.js @@ -1,23 +1,23 @@ -function foo(bar = "bar") {} +function foo1(bar = "bar") {} -function foo(bar = "bar", ...items) {} +function foo2(bar = "bar", ...items) {} -function foo(...items) {} +function foo3(...items) {} -function* foo() {} +function* foo4() {} -function foo() {} +function foo5() {} -async function foo() {} +async function foo6() {} -var foo = function* foo() {}; +var foo7 = function* foo7() {}; -var foo = function foo() {}; +var foo8 = function foo8() {}; -var foo = async function foo() {}; +var foo9 = async function foo9() {}; -var foo = function* () {}; +var foo10 = function* () {}; -var foo = function () {}; +var foo11 = function () {}; -var foo = async function () {}; +var foo12 = async function () {}; diff --git a/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/output.js b/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/output.js index ef42e4b2fbb2..2c2841253255 100644 --- a/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/output.js +++ b/packages/babel-generator/test/fixtures/types/FunctionDeclaration-FunctionExpression/output.js @@ -1,23 +1,23 @@ -function foo(bar = "bar") {} +function foo1(bar = "bar") {} -function foo(bar = "bar", ...items) {} +function foo2(bar = "bar", ...items) {} -function foo(...items) {} +function foo3(...items) {} -function* foo() {} +function* foo4() {} -function foo() {} +function foo5() {} -async function foo() {} +async function foo6() {} -var foo = function* foo() {}; +var foo7 = function* foo7() {}; -var foo = function foo() {}; +var foo8 = function foo8() {}; -var foo = async function foo() {}; +var foo9 = async function foo9() {}; -var foo = function* () {}; +var foo10 = function* () {}; -var foo = function () {}; +var foo11 = function () {}; -var foo = async function () {}; \ No newline at end of file +var foo12 = async function () {}; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/input.js b/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/input.js index b7a4a4b9fdce..84e2db5be047 100644 --- a/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/input.js +++ b/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/input.js @@ -1,9 +1,9 @@ import "foo"; -import foo from "foo"; -import { default as foo } from "foo"; -import * as foo from "foo"; -import foo, { baz as xyz } from "foo"; -import { bar } from "foo"; -import { bar, baz } from "foo"; -import { bar as baz } from "foo"; -import { bar as baz, xyz } from "foo"; +import foo1 from "foo"; +import { default as foo2 } from "foo"; +import * as foo3 from "foo"; +import foo4, { baz as xyz1 } from "foo"; +import { bar1 } from "foo"; +import { bar2, baz1 } from "foo"; +import { bar as baz2 } from "foo"; +import { bar as baz3, xyz2 } from "foo"; diff --git a/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/output.js b/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/output.js index 7cd5b681f8f2..c460e5b96277 100644 --- a/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/output.js +++ b/packages/babel-generator/test/fixtures/types/ImportDeclaration-ImportSpecifier-ImportNamespaceSpecifier/output.js @@ -1,9 +1,9 @@ import "foo"; -import foo from "foo"; -import { default as foo } from "foo"; -import * as foo from "foo"; -import foo, { baz as xyz } from "foo"; -import { bar } from "foo"; -import { bar, baz } from "foo"; -import { bar as baz } from "foo"; -import { bar as baz, xyz } from "foo"; \ No newline at end of file +import foo1 from "foo"; +import { default as foo2 } from "foo"; +import * as foo3 from "foo"; +import foo4, { baz as xyz1 } from "foo"; +import { bar1 } from "foo"; +import { bar2, baz1 } from "foo"; +import { bar as baz2 } from "foo"; +import { bar as baz3, xyz2 } from "foo"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/input.js b/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/input.js index 1c60f768707d..6e71f9167264 100644 --- a/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/input.js +++ b/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/input.js @@ -14,3 +14,7 @@ foo?.["bar"]?.foo; 0.?.toString(); 0.5?.toString(); 1.000?.toString(); + +(a?.b).c; +(a ? b : c)?.d; +(a?.b)() diff --git a/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/output.js b/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/output.js index be34e83a5833..a99aa9039c18 100644 --- a/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/output.js +++ b/packages/babel-generator/test/fixtures/types/Optional-MemberExpression/output.js @@ -11,4 +11,7 @@ foo?.["bar"].foo; foo?.["bar"]?.foo; 0.?.toString(); 0.5?.toString(); -1.000?.toString(); \ No newline at end of file +1.000?.toString(); +(a?.b).c; +(a ? b : c)?.d; +(a?.b)(); \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/options.json b/packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/options.json deleted file mode 100644 index f7793b0dd816..000000000000 --- a/packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/options.json +++ /dev/null @@ -1 +0,0 @@ -{ "plugins": ["optionalCatchBinding"] } diff --git a/packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js new file mode 100644 index 000000000000..e5b2807245d0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js @@ -0,0 +1 @@ +let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim; diff --git a/packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js new file mode 100644 index 000000000000..e5b2807245d0 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js @@ -0,0 +1 @@ +let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim; diff --git a/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js new file mode 100644 index 000000000000..4c8ffd3bf244 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js @@ -0,0 +1,8 @@ +value |> # + 1; +value |> 1 + #; +value |> do { + #; +}; +value |> do { + if (yes) #; +}; diff --git a/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js new file mode 100644 index 000000000000..4c8ffd3bf244 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js @@ -0,0 +1,8 @@ +value |> # + 1; +value |> 1 + #; +value |> do { + #; +}; +value |> do { + if (yes) #; +}; diff --git a/packages/babel-generator/test/fixtures/types/RestProperty/options.json b/packages/babel-generator/test/fixtures/types/RestProperty/options.json deleted file mode 100644 index 8a2a1d3bfa91..000000000000 --- a/packages/babel-generator/test/fixtures/types/RestProperty/options.json +++ /dev/null @@ -1 +0,0 @@ -{ "plugins": ["objectRestSpread"] } diff --git a/packages/babel-generator/test/fixtures/types/ReturnStatement/input.js b/packages/babel-generator/test/fixtures/types/ReturnStatement/input.js index cadd08000823..793ca5c4bacb 100644 --- a/packages/babel-generator/test/fixtures/types/ReturnStatement/input.js +++ b/packages/babel-generator/test/fixtures/types/ReturnStatement/input.js @@ -1,4 +1,4 @@ -function foo() { +function foo1() { return; } @@ -6,10 +6,10 @@ function bar() { return "foo"; } -function foo() { +function foo2() { return 1, "foo"; } () => { return /a/; } -function foo() { return /a/; } +function foo3() { return /a/; } diff --git a/packages/babel-generator/test/fixtures/types/ReturnStatement/output.js b/packages/babel-generator/test/fixtures/types/ReturnStatement/output.js index e9aa8d34019a..5fb776fc769b 100644 --- a/packages/babel-generator/test/fixtures/types/ReturnStatement/output.js +++ b/packages/babel-generator/test/fixtures/types/ReturnStatement/output.js @@ -1,4 +1,4 @@ -function foo() { +function foo1() { return; } @@ -6,7 +6,7 @@ function bar() { return "foo"; } -function foo() { +function foo2() { return 1, "foo"; } @@ -14,6 +14,6 @@ function foo() { return /a/; }; -function foo() { +function foo3() { return /a/; } \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json b/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json new file mode 100644 index 000000000000..a2e80d9ec294 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/UnaryExpression/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/input.js b/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/input.js index ede42c53ec82..ae204a4df56d 100644 --- a/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/input.js +++ b/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/input.js @@ -1,13 +1,13 @@ -let foo; -var foo; +let foo1; +var foo2; -let foo = "foo"; -var foo = "bar"; -const foo = "foo"; +let foo3 = "foo"; +var foo4 = "bar"; +const foo5 = "foo"; -let foo, bar = "bar"; -var foo, bar = "bar"; +let foo6, bar1 = "bar"; +var foo7, bar2 = "bar"; -let foo = "foo", bar = "bar"; -var foo = "foo", bar = "bar"; -const foo = "foo", bar = "bar"; +let foo8 = "foo", bar3 = "bar"; +var foo9 = "foo", bar4 = "bar"; +const foo10 = "foo", bar5 = "bar"; diff --git a/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/output.js b/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/output.js index c3e42e09131a..60453ccb0247 100644 --- a/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/output.js +++ b/packages/babel-generator/test/fixtures/types/VariableDeclaration-VariableDeclarator/output.js @@ -1,15 +1,15 @@ -let foo; -var foo; -let foo = "foo"; -var foo = "bar"; -const foo = "foo"; -let foo, - bar = "bar"; -var foo, - bar = "bar"; -let foo = "foo", - bar = "bar"; -var foo = "foo", - bar = "bar"; -const foo = "foo", - bar = "bar"; \ No newline at end of file +let foo1; +var foo2; +let foo3 = "foo"; +var foo4 = "bar"; +const foo5 = "foo"; +let foo6, + bar1 = "bar"; +var foo7, + bar2 = "bar"; +let foo8 = "foo", + bar3 = "bar"; +var foo9 = "foo", + bar4 = "bar"; +const foo10 = "foo", + bar5 = "bar"; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/WithStatement/options.json b/packages/babel-generator/test/fixtures/types/WithStatement/options.json new file mode 100644 index 000000000000..a2e80d9ec294 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/WithStatement/options.json @@ -0,0 +1,3 @@ +{ + "strictMode": false +} diff --git a/packages/babel-generator/test/fixtures/typescript/class-abstract/input.js b/packages/babel-generator/test/fixtures/typescript/class-abstract/input.js index 8f41a8b71f2a..3cb560c5a3dc 100644 --- a/packages/babel-generator/test/fixtures/typescript/class-abstract/input.js +++ b/packages/babel-generator/test/fixtures/typescript/class-abstract/input.js @@ -1,7 +1,7 @@ -abstract class C {} -declare abstract class C {} -export abstract class C {} +abstract class C1 {} +declare abstract class C2 {} +export abstract class C3 {} // `export abstract class { }` is not valid. export default abstract class { } -export default abstract class C { } +export default abstract class C4 { } // `abstract class` is not valid as an expression. diff --git a/packages/babel-generator/test/fixtures/typescript/class-abstract/output.js b/packages/babel-generator/test/fixtures/typescript/class-abstract/output.js index 860e03a34dd9..e621d56e2e37 100644 --- a/packages/babel-generator/test/fixtures/typescript/class-abstract/output.js +++ b/packages/babel-generator/test/fixtures/typescript/class-abstract/output.js @@ -1,8 +1,8 @@ -abstract class C {} +abstract class C1 {} -declare abstract class C {} +declare abstract class C2 {} -export abstract class C {} // `export abstract class { }` is not valid. +export abstract class C3 {} // `export abstract class { }` is not valid. export default abstract class {} -export default abstract class C {} // `abstract class` is not valid as an expression. \ No newline at end of file +export default abstract class C4 {} // `abstract class` is not valid as an expression. \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-empty/input.js b/packages/babel-generator/test/fixtures/typescript/tuple-empty/input.js new file mode 100644 index 000000000000..f7cd7b5a0e25 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-empty/input.js @@ -0,0 +1 @@ +let x: []; diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-empty/output.js b/packages/babel-generator/test/fixtures/typescript/tuple-empty/output.js new file mode 100644 index 000000000000..a602e2203789 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-empty/output.js @@ -0,0 +1 @@ +let x: []; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-optional/input.js b/packages/babel-generator/test/fixtures/typescript/tuple-optional/input.js new file mode 100644 index 000000000000..3b8d21ba958c --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-optional/input.js @@ -0,0 +1 @@ +let x: [string, number?, (string | number)?] diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-optional/output.js b/packages/babel-generator/test/fixtures/typescript/tuple-optional/output.js new file mode 100644 index 000000000000..c32cf4f129a6 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-optional/output.js @@ -0,0 +1 @@ +let x: [string, number?, (string | number)?]; diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-rest/input.js b/packages/babel-generator/test/fixtures/typescript/tuple-rest/input.js new file mode 100644 index 000000000000..d7719b2cb4e6 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-rest/input.js @@ -0,0 +1 @@ +let x: [string, ...number[]] diff --git a/packages/babel-generator/test/fixtures/typescript/tuple-rest/output.js b/packages/babel-generator/test/fixtures/typescript/tuple-rest/output.js new file mode 100644 index 000000000000..52be881f835c --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple-rest/output.js @@ -0,0 +1 @@ +let x: [string, ...number[]]; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/tuple/input.js b/packages/babel-generator/test/fixtures/typescript/tuple/input.js new file mode 100644 index 000000000000..53c8e72ec952 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple/input.js @@ -0,0 +1 @@ +let x: [number, number, number]; diff --git a/packages/babel-generator/test/fixtures/typescript/tuple/output.js b/packages/babel-generator/test/fixtures/typescript/tuple/output.js new file mode 100644 index 000000000000..07edd6a75272 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/tuple/output.js @@ -0,0 +1 @@ +let x: [number, number, number]; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/types-import-type/input.js b/packages/babel-generator/test/fixtures/typescript/types-import-type/input.js new file mode 100644 index 000000000000..848a461d3c57 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/types-import-type/input.js @@ -0,0 +1,3 @@ +let x: typeof import('./x'); +let Y: import('./y').Y; +let z: import("/z").foo.bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/types-import-type/output.js b/packages/babel-generator/test/fixtures/typescript/types-import-type/output.js new file mode 100644 index 000000000000..848a461d3c57 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/types-import-type/output.js @@ -0,0 +1,3 @@ +let x: typeof import('./x'); +let Y: import('./y').Y; +let z: import("/z").foo.bar; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/types-keywords/input.js b/packages/babel-generator/test/fixtures/typescript/types-keywords/input.js index d2ddfb94bbc6..0fec8f608a1c 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-keywords/input.js +++ b/packages/babel-generator/test/fixtures/typescript/types-keywords/input.js @@ -1,4 +1,5 @@ let a: any; +let un: unknown; let b: boolean; let ne: never; let nul: null; diff --git a/packages/babel-generator/test/fixtures/typescript/types-keywords/output.js b/packages/babel-generator/test/fixtures/typescript/types-keywords/output.js index 0c6820fbaf27..0fec8f608a1c 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-keywords/output.js +++ b/packages/babel-generator/test/fixtures/typescript/types-keywords/output.js @@ -1,4 +1,5 @@ let a: any; +let un: unknown; let b: boolean; let ne: never; let nul: null; @@ -7,4 +8,4 @@ let o: object; let st: string; let sy: symbol; let u: undefined; -let v: void; \ No newline at end of file +let v: void; diff --git a/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/input.js b/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/input.js index d2cea8ee69cc..d047bcfa5908 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/input.js +++ b/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/input.js @@ -1,2 +1,2 @@ let x: true; -let x: false; +let x2: false; diff --git a/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/output.js b/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/output.js index 2a25bd9d18bf..dbec899ee6af 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/output.js +++ b/packages/babel-generator/test/fixtures/typescript/types-literal-boolean/output.js @@ -1,2 +1,2 @@ let x: true; -let x: false; \ No newline at end of file +let x2: false; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/types-mapped/input.js b/packages/babel-generator/test/fixtures/typescript/types-mapped/input.js index 575af654a45f..6415810f0530 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-mapped/input.js +++ b/packages/babel-generator/test/fixtures/typescript/types-mapped/input.js @@ -1,4 +1,4 @@ -let map: { [P in string]: number }; -let map: { readonly [P in string]?: number }; -let map: { +readonly [P in string]+?: number }; -let map: { -readonly [P in string]-?: number }; +let map1: { [P in string]: number }; +let map2: { readonly [P in string]?: number }; +let map3: { +readonly [P in string]+?: number }; +let map4: { -readonly [P in string]-?: number }; diff --git a/packages/babel-generator/test/fixtures/typescript/types-mapped/output.js b/packages/babel-generator/test/fixtures/typescript/types-mapped/output.js index bb0a6786368f..208e77ca4019 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-mapped/output.js +++ b/packages/babel-generator/test/fixtures/typescript/types-mapped/output.js @@ -1,4 +1,4 @@ -let map: { [P in string]: number }; -let map: { readonly [P in string]?: number }; -let map: { +readonly [P in string]+?: number }; -let map: { -readonly [P in string]-?: number }; \ No newline at end of file +let map1: { [P in string]: number }; +let map2: { readonly [P in string]?: number }; +let map3: { +readonly [P in string]+?: number }; +let map4: { -readonly [P in string]-?: number }; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/types-union-intersection/output.js b/packages/babel-generator/test/fixtures/typescript/types-union-intersection/output.js index 8f74eb81d7ac..24a187a151f4 100644 --- a/packages/babel-generator/test/fixtures/typescript/types-union-intersection/output.js +++ b/packages/babel-generator/test/fixtures/typescript/types-union-intersection/output.js @@ -1,4 +1,4 @@ let union: number | null | undefined; let intersection: number & string; -let precedence1: number | string & boolean; -let precedence2: number & string | boolean; \ No newline at end of file +let precedence1: number | (string & boolean); +let precedence2: (number & string) | boolean; \ No newline at end of file diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index f79b964d0a83..80bee85f9eaf 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -384,6 +384,82 @@ describe("programmatic generation", function() { [key: any]: number }`); }); + + describe("directives", function() { + it("preserves escapes", function() { + const directive = t.directive( + t.directiveLiteral(String.raw`us\x65 strict`), + ); + const output = generate(directive).code; + + expect(output).toBe(String.raw`"us\x65 strict";`); + }); + + it("preserves escapes in minified output", function() { + // https://github.com/babel/babel/issues/4767 + + const directive = t.directive(t.directiveLiteral(String.raw`foo\n\t\r`)); + const output = generate(directive, { minified: true }).code; + + expect(output).toBe(String.raw`"foo\n\t\r";`); + }); + + it("unescaped single quote", function() { + const directive = t.directive(t.directiveLiteral(String.raw`'\'\"`)); + const output = generate(directive).code; + + expect(output).toBe(String.raw`"'\'\"";`); + }); + + it("unescaped double quote", function() { + const directive = t.directive(t.directiveLiteral(String.raw`"\'\"`)); + const output = generate(directive).code; + + expect(output).toBe(String.raw`'"\'\"';`); + }); + + it("unescaped single and double quotes together throw", function() { + const directive = t.directive(t.directiveLiteral(String.raw`'"`)); + + expect(() => { + generate(directive); + }).toThrow(); + }); + }); + + describe("typescript generate parentheses if necessary", function() { + it("wraps around union for array", () => { + const typeStatement = t.TSArrayType( + t.TSUnionType([ + t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]), + t.TSNullKeyword(), + ]), + ); + const output = generate(typeStatement).code; + expect(output).toBe("((number & boolean) | null)[]"); + }); + it("wraps around intersection for array", () => { + const typeStatement = t.TSArrayType( + t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]), + ); + const output = generate(typeStatement).code; + expect(output).toBe("(number & boolean)[]"); + }); + it("wraps around rest", () => { + const typeStatement = t.tsRestType( + t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]), + ); + const output = generate(typeStatement).code; + expect(output).toBe("...(number & boolean)"); + }); + it("wraps around optional type", () => { + const typeStatement = t.tsOptionalType( + t.TSIntersectionType([t.TSNumberKeyword(), t.TSBooleanKeyword()]), + ); + const output = generate(typeStatement).code; + expect(output).toBe("(number & boolean)?"); + }); + }); }); describe("CodeGenerator", function() { @@ -413,9 +489,10 @@ suites.forEach(function(testSuite) { const actualAst = parse(actualCode, { filename: actual.loc, plugins: task.options.plugins || [], - strictMode: false, + strictMode: task.options.strictMode === false ? false : true, sourceType: "module", sourceMaps: !!task.sourceMap, + ...task.options.parserOpts, }); const options = { sourceFileName: path.relative(__dirname, actual.loc), diff --git a/packages/babel-helper-builder-react-jsx/package.json b/packages/babel-helper-builder-react-jsx/package.json index 8ef4b652d317..7b13e4b4753a 100644 --- a/packages/babel-helper-builder-react-jsx/package.json +++ b/packages/babel-helper-builder-react-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-builder-react-jsx", - "version": "7.0.0", + "version": "7.3.0", "description": "Helper function to build react jsx", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx", "license": "MIT", @@ -9,7 +9,7 @@ }, "main": "lib/index.js", "dependencies": { - "@babel/types": "^7.0.0", + "@babel/types": "^7.3.0", "esutils": "^2.0.0" } } diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js index 4f2473ae5062..3602ecb8496e 100644 --- a/packages/babel-helper-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -19,6 +19,13 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`, ); } }; + + visitor.JSXSpreadChild = function(path) { + throw path.buildCodeFrameError( + "Spread children are not supported in React.", + ); + }; + visitor.JSXElement = { exit(path, file) { const callExpr = buildElementCall(path, file); diff --git a/packages/babel-helper-call-delegate/package.json b/packages/babel-helper-call-delegate/package.json index 37ebc6134f08..3e7fd81bcf40 100644 --- a/packages/babel-helper-call-delegate/package.json +++ b/packages/babel-helper-call-delegate/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-call-delegate", - "version": "7.1.0", + "version": "7.4.4", "description": "Helper function to call delegate", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-call-delegate", "license": "MIT", @@ -9,8 +9,8 @@ }, "main": "lib/index.js", "dependencies": { - "@babel/helper-hoist-variables": "^7.0.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" + "@babel/helper-hoist-variables": "^7.4.4", + "@babel/traverse": "^7.4.4", + "@babel/types": "^7.4.4" } } diff --git a/packages/babel-helper-call-delegate/src/index.js b/packages/babel-helper-call-delegate/src/index.js index 8aee0276132c..d4bf041d0131 100644 --- a/packages/babel-helper-call-delegate/src/index.js +++ b/packages/babel-helper-call-delegate/src/index.js @@ -41,7 +41,7 @@ export default function(path: NodePath, scope = path.scope) { path.traverse(visitor, state); - if (state.foundArguments) { + if (state.foundArguments || state.foundThis) { callee = t.memberExpression(container, t.identifier("apply")); args = []; diff --git a/packages/babel-helper-create-class-features-plugin/.npmignore b/packages/babel-helper-create-class-features-plugin/.npmignore new file mode 100644 index 000000000000..f9806945836e --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/packages/babel-helper-create-class-features-plugin/README.md b/packages/babel-helper-create-class-features-plugin/README.md new file mode 100644 index 000000000000..5ce5e8c6b570 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/README.md @@ -0,0 +1,19 @@ +# @babel/helper-create-class-features-plugin + +> Compile class public and private fields, private methods and decorators to ES6 + +See our website [@babel/helper-create-class-features-plugin](https://babeljs.io/docs/en/next/babel-helper-create-class-features-plugin.html) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/helper-create-class-features-plugin +``` + +or using yarn: + +```sh +yarn add @babel/helper-create-class-features-plugin --dev +``` diff --git a/packages/babel-helper-create-class-features-plugin/package.json b/packages/babel-helper-create-class-features-plugin/package.json new file mode 100644 index 000000000000..a5c46704a7db --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/package.json @@ -0,0 +1,31 @@ +{ + "name": "@babel/helper-create-class-features-plugin", + "version": "7.5.5", + "author": "The Babel Team (https://babeljs.io/team)", + "license": "MIT", + "description": "Compile class public and private fields, private methods and decorators to ES6", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-create-class-features-plugin", + "main": "lib/index.js", + "publishConfig": { + "access": "public" + }, + "keywords": [ + "babel", + "babel-plugin" + ], + "dependencies": { + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-member-expression-to-functions": "^7.5.5", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.5.5", + "@babel/helper-split-export-declaration": "^7.4.4" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + }, + "devDependencies": { + "@babel/core": "^7.5.5", + "@babel/helper-plugin-test-runner": "^7.0.0" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.js b/packages/babel-helper-create-class-features-plugin/src/decorators.js new file mode 100644 index 000000000000..74fc7d059523 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.js @@ -0,0 +1,164 @@ +import { types as t, template } from "@babel/core"; +import ReplaceSupers from "@babel/helper-replace-supers"; +import nameFunction from "@babel/helper-function-name"; + +export function hasOwnDecorators(node) { + return !!(node.decorators && node.decorators.length); +} + +export function hasDecorators(node) { + return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators); +} + +function prop(key, value) { + if (!value) return null; + return t.objectProperty(t.identifier(key), value); +} + +function method(key, body) { + return t.objectMethod( + "method", + t.identifier(key), + [], + t.blockStatement(body), + ); +} + +function takeDecorators(node) { + let result; + if (node.decorators && node.decorators.length > 0) { + result = t.arrayExpression( + node.decorators.map(decorator => decorator.expression), + ); + } + node.decorators = undefined; + return result; +} + +function getKey(node) { + if (node.computed) { + return node.key; + } else if (t.isIdentifier(node.key)) { + return t.stringLiteral(node.key.name); + } else { + return t.stringLiteral(String(node.key.value)); + } +} + +// NOTE: This function can be easily bound as .bind(file, classRef, superRef) +// to make it easier to use it in a loop. +function extractElementDescriptor(/* this: File, */ classRef, superRef, path) { + const { node, scope } = path; + const isMethod = path.isClassMethod(); + + if (path.isPrivate()) { + throw path.buildCodeFrameError( + `Private ${ + isMethod ? "methods" : "fields" + } in decorated classes are not supported yet.`, + ); + } + + new ReplaceSupers( + { + methodPath: path, + methodNode: node, + objectRef: classRef, + isStatic: node.static, + superRef, + scope, + file: this, + }, + true, + ).replace(); + + const properties = [ + prop("kind", t.stringLiteral(isMethod ? node.kind : "field")), + prop("decorators", takeDecorators(node)), + prop("static", node.static && t.booleanLiteral(true)), + prop("key", getKey(node)), + ].filter(Boolean); + + if (isMethod) { + const id = node.computed ? null : node.key; + t.toExpression(node); + properties.push(prop("value", nameFunction({ node, id, scope }) || node)); + } else if (node.value) { + properties.push( + method("value", template.statements.ast`return ${node.value}`), + ); + } else { + properties.push(prop("value", scope.buildUndefinedNode())); + } + + path.remove(); + + return t.objectExpression(properties); +} + +function addDecorateHelper(file) { + try { + return file.addHelper("decorate"); + } catch (err) { + if (err.code === "BABEL_HELPER_UNKNOWN") { + err.message += + "\n '@babel/plugin-transform-decorators' in non-legacy mode" + + " requires '@babel/core' version ^7.0.2 and you appear to be using" + + " an older version."; + } + throw err; + } +} + +export function buildDecoratedClass(ref, path, elements, file) { + const { node, scope } = path; + const initializeId = scope.generateUidIdentifier("initialize"); + const isDeclaration = node.id && path.isDeclaration(); + const isStrict = path.isInStrictMode(); + const { superClass } = node; + + node.type = "ClassDeclaration"; + if (!node.id) node.id = t.cloneNode(ref); + + let superId; + if (superClass) { + superId = scope.generateUidIdentifierBasedOnNode(node.superClass, "super"); + node.superClass = superId; + } + + const classDecorators = takeDecorators(node); + const definitions = t.arrayExpression( + elements.map(extractElementDescriptor.bind(file, node.id, superId)), + ); + + let replacement = template.expression.ast` + ${addDecorateHelper(file)}( + ${classDecorators || t.nullLiteral()}, + function (${initializeId}, ${superClass ? superId : null}) { + ${node} + return { F: ${t.cloneNode(node.id)}, d: ${definitions} }; + }, + ${superClass} + ) + `; + let classPathDesc = "arguments.1.body.body.0"; + + if (!isStrict) { + replacement.arguments[1].body.directives.push( + t.directive(t.directiveLiteral("use strict")), + ); + } + + if (isDeclaration) { + replacement = template.ast`let ${ref} = ${replacement}`; + classPathDesc = "declarations.0.init." + classPathDesc; + } + + return { + instanceNodes: [template.statement.ast`${initializeId}(this)`], + wrapClass(path) { + path.replaceWith(replacement); + return path.get(classPathDesc); + }, + }; +} diff --git a/packages/babel-helper-create-class-features-plugin/src/features.js b/packages/babel-helper-create-class-features-plugin/src/features.js new file mode 100644 index 000000000000..fffc0d0014e0 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/src/features.js @@ -0,0 +1,93 @@ +import { hasOwnDecorators } from "./decorators"; + +export const FEATURES = Object.freeze({ + //classes: 1 << 0, + fields: 1 << 1, + privateMethods: 1 << 2, + decorators: 1 << 3, +}); + +// We can't use a symbol because this needs to always be the same, even if +// this package isn't deduped by npm. e.g. +// - node_modules/ +// - @babel/plugin-class-features +// - @babel/plugin-proposal-decorators +// - node_modules +// - @babel-plugin-class-features +const featuresKey = "@babel/plugin-class-features/featuresKey"; +const looseKey = "@babel/plugin-class-features/looseKey"; + +export function enableFeature(file, feature, loose) { + // We can't blindly enable the feature because, if it was already set, + // "loose" can't be changed, so that + // @babel/plugin-class-properties { loose: true } + // @babel/plugin-class-properties { loose: false } + // is transformed in loose mode. + // We only enabled the feature if it was previously disabled. + if (!hasFeature(file, feature)) { + file.set(featuresKey, file.get(featuresKey) | feature); + if (loose) file.set(looseKey, file.get(looseKey) | feature); + } +} + +function hasFeature(file, feature) { + return !!(file.get(featuresKey) & feature); +} + +export function isLoose(file, feature) { + return !!(file.get(looseKey) & feature); +} + +export function verifyUsedFeatures(path, file) { + if (hasOwnDecorators(path.node)) { + if (!hasFeature(file, FEATURES.decorators)) { + throw path.buildCodeFrameError( + "Decorators are not enabled." + + "\nIf you are using " + + '["@babel/plugin-proposal-decorators", { "legacy": true }], ' + + 'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' + + "and enable loose mode, like so:\n" + + '\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' + + '\t["@babel/plugin-proposal-class-properties", { "loose": true }]', + ); + } + + if (path.isPrivate()) { + throw path.buildCodeFrameError( + `Private ${ + path.isClassMethod() ? "methods" : "fields" + } in decorated classes are not supported yet.`, + ); + } + } + + // NOTE: We can't use path.isPrivateMethod() because it isn't supported in <7.2.0 + if (path.isPrivate() && path.isMethod()) { + if (!hasFeature(file, FEATURES.privateMethods)) { + throw path.buildCodeFrameError("Class private methods are not enabled."); + } + + if (path.node.static && path.node.kind !== "method") { + throw path.buildCodeFrameError( + "@babel/plugin-class-features doesn't support class static private accessors yet.", + ); + } + } + + if ( + hasFeature(file, FEATURES.privateMethods) && + hasFeature(file, FEATURES.fields) && + isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.fields) + ) { + throw path.buildCodeFrameError( + "'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " + + "and @babel/plugin-proposal-private-methods", + ); + } + + if (path.isProperty()) { + if (!hasFeature(file, FEATURES.fields)) { + throw path.buildCodeFrameError("Class fields are not enabled."); + } + } +} diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.js b/packages/babel-helper-create-class-features-plugin/src/fields.js new file mode 100644 index 000000000000..c6fb3da40ded --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/src/fields.js @@ -0,0 +1,671 @@ +import { template, traverse, types as t } from "@babel/core"; +import ReplaceSupers, { + environmentVisitor, +} from "@babel/helper-replace-supers"; +import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions"; +import optimiseCall from "@babel/helper-optimise-call-expression"; + +export function buildPrivateNamesMap(props) { + const privateNamesMap = new Map(); + for (const prop of props) { + const isPrivate = prop.isPrivate(); + const isMethod = !prop.isProperty(); + const isInstance = !prop.node.static; + if (isPrivate) { + const { name } = prop.node.key.id; + const update = privateNamesMap.has(name) + ? privateNamesMap.get(name) + : { + id: prop.scope.generateUidIdentifier(name), + static: !isInstance, + method: isMethod, + }; + if (prop.node.kind === "get") { + update.getId = prop.scope.generateUidIdentifier(`get_${name}`); + } else if (prop.node.kind === "set") { + update.setId = prop.scope.generateUidIdentifier(`set_${name}`); + } else if (prop.node.kind === "method") { + update.methodId = prop.scope.generateUidIdentifier(name); + } + privateNamesMap.set(name, update); + } + } + return privateNamesMap; +} + +export function buildPrivateNamesNodes(privateNamesMap, loose, state) { + const initNodes = []; + + for (const [name, value] of privateNamesMap) { + // In loose mode, both static and instance fields are transpiled using a + // secret non-enumerable property. Hence, we also need to generate that + // key (using the classPrivateFieldLooseKey helper). + // In spec mode, only instance fields need a "private name" initializer + // because static fields are directly assigned to a variable in the + // buildPrivateStaticFieldInitSpec function. + const { id, static: isStatic, method: isMethod, getId, setId } = value; + if (loose) { + initNodes.push( + template.statement.ast` + var ${id} = ${state.addHelper("classPrivateFieldLooseKey")}("${name}") + `, + ); + } else if (isMethod && !isStatic) { + if (getId || setId) { + initNodes.push(template.statement.ast`var ${id} = new WeakMap();`); + } else { + initNodes.push(template.statement.ast`var ${id} = new WeakSet();`); + } + } else if (!isStatic) { + initNodes.push(template.statement.ast`var ${id} = new WeakMap();`); + } + } + + return initNodes; +} + +// Traverses the class scope, handling private name references. If an inner +// class redeclares the same private name, it will hand off traversal to the +// restricted visitor (which doesn't traverse the inner class's inner scope). +const privateNameVisitor = { + PrivateName(path) { + const { privateNamesMap } = this; + const { node, parentPath } = path; + + if (!parentPath.isMemberExpression({ property: node })) return; + if (!privateNamesMap.has(node.id.name)) return; + + this.handle(parentPath); + }, + + Class(path) { + const { privateNamesMap } = this; + const body = path.get("body.body"); + + for (const prop of body) { + if (!prop.isPrivate()) { + continue; + } + if (!privateNamesMap.has(prop.node.key.id.name)) continue; + + // This class redeclares the private name. + // So, we can only evaluate the things in the outer scope. + path.traverse(privateNameInnerVisitor, this); + path.skip(); + break; + } + }, +}; + +// Traverses the outer portion of a class, without touching the class's inner +// scope, for private names. +const privateNameInnerVisitor = traverse.visitors.merge([ + { + PrivateName: privateNameVisitor.PrivateName, + }, + environmentVisitor, +]); + +const privateNameHandlerSpec = { + memoise(member, count) { + const { scope } = member; + const { object } = member.node; + + const memo = scope.maybeGenerateMemoised(object); + if (!memo) { + return; + } + + this.memoiser.set(object, memo, count); + }, + + receiver(member) { + const { object } = member.node; + + if (this.memoiser.has(object)) { + return t.cloneNode(this.memoiser.get(object)); + } + + return t.cloneNode(object); + }, + + get(member) { + const { classRef, privateNamesMap, file } = this; + const { name } = member.node.property.id; + const { + id, + static: isStatic, + method: isMethod, + methodId, + getId, + setId, + } = privateNamesMap.get(name); + + if (isStatic) { + const helperName = isMethod + ? "classStaticPrivateMethodGet" + : "classStaticPrivateFieldSpecGet"; + + return t.callExpression(file.addHelper(helperName), [ + this.receiver(member), + t.cloneNode(classRef), + t.cloneNode(id), + ]); + } + + if (isMethod) { + if (getId || setId) { + return t.callExpression(file.addHelper("classPrivateFieldGet"), [ + this.receiver(member), + t.cloneNode(id), + ]); + } + return t.callExpression(file.addHelper("classPrivateMethodGet"), [ + this.receiver(member), + t.cloneNode(id), + t.cloneNode(methodId), + ]); + } + return t.callExpression(file.addHelper("classPrivateFieldGet"), [ + this.receiver(member), + t.cloneNode(id), + ]); + }, + + set(member, value) { + const { classRef, privateNamesMap, file } = this; + const { name } = member.node.property.id; + const { + id, + static: isStatic, + method: isMethod, + setId, + } = privateNamesMap.get(name); + + if (isStatic) { + const helperName = isMethod + ? "classStaticPrivateMethodSet" + : "classStaticPrivateFieldSpecSet"; + + return t.callExpression(file.addHelper(helperName), [ + this.receiver(member), + t.cloneNode(classRef), + t.cloneNode(id), + value, + ]); + } + if (isMethod) { + if (setId) { + return t.callExpression(file.addHelper("classPrivateFieldSet"), [ + this.receiver(member), + t.cloneNode(id), + value, + ]); + } + return t.callExpression(file.addHelper("classPrivateMethodSet"), []); + } + return t.callExpression(file.addHelper("classPrivateFieldSet"), [ + this.receiver(member), + t.cloneNode(id), + value, + ]); + }, + + destructureSet(member) { + const { privateNamesMap, file } = this; + const { name } = member.node.property.id; + const { id } = privateNamesMap.get(name); + return t.memberExpression( + t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [ + this.receiver(member), + t.cloneNode(id), + ]), + t.identifier("value"), + ); + }, + + call(member, args) { + // The first access (the get) should do the memo assignment. + this.memoise(member, 1); + + return optimiseCall(this.get(member), this.receiver(member), args); + }, +}; + +const privateNameHandlerLoose = { + handle(member) { + const { privateNamesMap, file } = this; + const { object } = member.node; + const { name } = member.node.property.id; + + member.replaceWith( + template.expression`BASE(REF, PROP)[PROP]`({ + BASE: file.addHelper("classPrivateFieldLooseBase"), + REF: object, + PROP: privateNamesMap.get(name).id, + }), + ); + }, +}; + +export function transformPrivateNamesUsage( + ref, + path, + privateNamesMap, + loose, + state, +) { + const body = path.get("body"); + + if (loose) { + body.traverse(privateNameVisitor, { + privateNamesMap, + file: state, + ...privateNameHandlerLoose, + }); + } else { + memberExpressionToFunctions(body, privateNameVisitor, { + privateNamesMap, + classRef: ref, + file: state, + ...privateNameHandlerSpec, + }); + } +} + +function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { + const { id } = privateNamesMap.get(prop.node.key.id.name); + const value = prop.node.value || prop.scope.buildUndefinedNode(); + + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + writable: true, + value: ${value} + }); + `; +} + +function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) { + const { id } = privateNamesMap.get(prop.node.key.id.name); + const value = prop.node.value || prop.scope.buildUndefinedNode(); + + return template.statement.ast`${id}.set(${ref}, { + // configurable is always false for private elements + // enumerable is always false for private elements + writable: true, + value: ${value}, + })`; +} + +function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { + const { id } = privateNamesMap.get(prop.node.key.id.name); + const value = prop.node.value || prop.scope.buildUndefinedNode(); + + return template.statement.ast` + var ${id} = { + // configurable is false by default + // enumerable is false by default + writable: true, + value: ${value} + }; + `; +} + +function buildPrivateMethodInitLoose(ref, prop, privateNamesMap) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { methodId, id, getId, setId, initAdded } = privateName; + if (initAdded) return; + + if (methodId) { + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + // writable is false by default + value: ${methodId.name} + }); + `; + } + + if (getId || setId) { + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + initAdded: true, + }); + + if (getId && setId) { + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + // writable is false by default + get: ${getId.name}, + set: ${setId.name} + }); + `; + } else if (getId && !setId) { + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + // writable is false by default + get: ${getId.name} + }); + `; + } else if (!getId && setId) { + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + // writable is false by default + set: ${setId.name} + }); + `; + } + } +} + +function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { id, getId, setId, initAdded } = privateName; + if (initAdded) return; + + if (getId || setId) { + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + initAdded: true, + }); + + if (getId && setId) { + return template.statement.ast` + ${id}.set(${ref}, { + get: ${getId.name}, + set: ${setId.name} + }); + `; + } else if (getId && !setId) { + return template.statement.ast` + ${id}.set(${ref}, { + get: ${getId.name} + }); + `; + } else if (!getId && setId) { + return template.statement.ast` + ${id}.set(${ref}, { + set: ${setId.name} + }); + `; + } + } + return template.statement.ast`${id}.add(${ref})`; +} + +function buildPublicFieldInitLoose(ref, prop) { + const { key, computed } = prop.node; + const value = prop.node.value || prop.scope.buildUndefinedNode(); + + return t.expressionStatement( + t.assignmentExpression( + "=", + t.memberExpression(ref, key, computed || t.isLiteral(key)), + value, + ), + ); +} + +function buildPublicFieldInitSpec(ref, prop, state) { + const { key, computed } = prop.node; + const value = prop.node.value || prop.scope.buildUndefinedNode(); + + return t.expressionStatement( + t.callExpression(state.addHelper("defineProperty"), [ + ref, + computed || t.isLiteral(key) ? key : t.stringLiteral(key.name), + value, + ]), + ); +} + +function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) { + const { id, methodId } = privateNamesMap.get(prop.node.key.id.name); + return template.statement.ast` + Object.defineProperty(${ref}, ${id}, { + // configurable is false by default + // enumerable is false by default + // writable is false by default + value: ${methodId.name} + }); + `; +} + +function buildPrivateMethodDeclaration(prop, privateNamesMap, loose = false) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { + id, + methodId, + getId, + setId, + getterDeclared, + setterDeclared, + static: isStatic, + } = privateName; + const { params, body, generator, async } = prop.node; + const methodValue = t.functionExpression( + methodId, + params, + body, + generator, + async, + ); + const isGetter = getId && !getterDeclared && params.length === 0; + const isSetter = setId && !setterDeclared && params.length > 0; + + if (isGetter) { + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + getterDeclared: true, + }); + return t.variableDeclaration("var", [ + t.variableDeclarator(getId, methodValue), + ]); + } + if (isSetter) { + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + setterDeclared: true, + }); + return t.variableDeclaration("var", [ + t.variableDeclarator(setId, methodValue), + ]); + } + if (isStatic && !loose) { + return t.variableDeclaration("var", [ + t.variableDeclarator( + id, + t.functionExpression(id, params, body, generator, async), + ), + ]); + } + + return t.variableDeclaration("var", [ + t.variableDeclarator(methodId, methodValue), + ]); +} + +const thisContextVisitor = traverse.visitors.merge([ + { + ThisExpression(path, state) { + state.needsClassRef = true; + path.replaceWith(t.cloneNode(state.classRef)); + }, + }, + environmentVisitor, +]); + +function replaceThisContext(path, ref, superRef, file, loose) { + const state = { classRef: ref, needsClassRef: false }; + + const replacer = new ReplaceSupers({ + methodPath: path, + isLoose: loose, + superRef, + file, + getObjectRef() { + state.needsClassRef = true; + return path.node.static + ? ref + : t.memberExpression(ref, t.identifier("prototype")); + }, + }); + replacer.replace(); + if (path.isProperty()) { + path.traverse(thisContextVisitor, state); + } + return state.needsClassRef; +} + +export function buildFieldsInitNodes( + ref, + superRef, + props, + privateNamesMap, + state, + loose, +) { + const staticNodes = []; + const instanceNodes = []; + let needsClassRef = false; + + for (const prop of props) { + const isStatic = prop.node.static; + const isInstance = !isStatic; + const isPrivate = prop.isPrivate(); + const isPublic = !isPrivate; + const isField = prop.isProperty(); + const isMethod = !isField; + + if (isStatic || (isMethod && isPrivate)) { + const replaced = replaceThisContext(prop, ref, superRef, state, loose); + needsClassRef = needsClassRef || replaced; + } + + switch (true) { + case isStatic && isPrivate && isField && loose: + needsClassRef = true; + staticNodes.push( + buildPrivateFieldInitLoose(t.cloneNode(ref), prop, privateNamesMap), + ); + break; + case isStatic && isPrivate && isField && !loose: + needsClassRef = true; + staticNodes.push( + buildPrivateStaticFieldInitSpec(prop, privateNamesMap), + ); + break; + case isStatic && isPublic && isField && loose: + needsClassRef = true; + staticNodes.push(buildPublicFieldInitLoose(t.cloneNode(ref), prop)); + break; + case isStatic && isPublic && isField && !loose: + needsClassRef = true; + staticNodes.push( + buildPublicFieldInitSpec(t.cloneNode(ref), prop, state), + ); + break; + case isInstance && isPrivate && isField && loose: + instanceNodes.push( + buildPrivateFieldInitLoose(t.thisExpression(), prop, privateNamesMap), + ); + break; + case isInstance && isPrivate && isField && !loose: + instanceNodes.push( + buildPrivateInstanceFieldInitSpec( + t.thisExpression(), + prop, + privateNamesMap, + ), + ); + break; + case isInstance && isPrivate && isMethod && loose: + instanceNodes.unshift( + buildPrivateMethodInitLoose( + t.thisExpression(), + prop, + privateNamesMap, + ), + ); + staticNodes.push( + buildPrivateMethodDeclaration(prop, privateNamesMap, loose), + ); + break; + case isInstance && isPrivate && isMethod && !loose: + instanceNodes.unshift( + buildPrivateInstanceMethodInitSpec( + t.thisExpression(), + prop, + privateNamesMap, + ), + ); + staticNodes.push( + buildPrivateMethodDeclaration(prop, privateNamesMap, loose), + ); + break; + case isStatic && isPrivate && isMethod && !loose: + needsClassRef = true; + staticNodes.push( + buildPrivateMethodDeclaration(prop, privateNamesMap, loose), + ); + break; + case isStatic && isPrivate && isMethod && loose: + needsClassRef = true; + staticNodes.push( + buildPrivateMethodDeclaration(prop, privateNamesMap, loose), + ); + staticNodes.push( + buildPrivateStaticMethodInitLoose( + t.cloneNode(ref), + prop, + state, + privateNamesMap, + ), + ); + break; + case isInstance && isPublic && isField && loose: + instanceNodes.push(buildPublicFieldInitLoose(t.thisExpression(), prop)); + break; + case isInstance && isPublic && isField && !loose: + instanceNodes.push( + buildPublicFieldInitSpec(t.thisExpression(), prop, state), + ); + break; + default: + throw new Error("Unreachable."); + } + } + + return { + staticNodes, + instanceNodes: instanceNodes.filter(Boolean), + wrapClass(path) { + for (const prop of props) { + prop.remove(); + } + + if (!needsClassRef) return path; + + if (path.isClassExpression()) { + path.scope.push({ id: ref }); + path.replaceWith( + t.assignmentExpression("=", t.cloneNode(ref), path.node), + ); + } else if (!path.node.id) { + // Anonymous class declaration + path.node.id = ref; + } + + return path; + }, + }; +} diff --git a/packages/babel-helper-create-class-features-plugin/src/index.js b/packages/babel-helper-create-class-features-plugin/src/index.js new file mode 100644 index 000000000000..1ed61a1839c0 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/src/index.js @@ -0,0 +1,214 @@ +import nameFunction from "@babel/helper-function-name"; +import splitExportDeclaration from "@babel/helper-split-export-declaration"; +import { + buildPrivateNamesNodes, + buildPrivateNamesMap, + transformPrivateNamesUsage, + buildFieldsInitNodes, +} from "./fields"; +import { + hasOwnDecorators, + buildDecoratedClass, + hasDecorators, +} from "./decorators"; +import { injectInitialization, extractComputedKeys } from "./misc"; +import { + enableFeature, + verifyUsedFeatures, + FEATURES, + isLoose, +} from "./features"; + +import pkg from "../package.json"; + +export { FEATURES, injectInitialization }; + +// Note: Versions are represented as an integer. e.g. 7.1.5 is represented +// as 70000100005. This method is easier than using a semver-parsing +// package, but it breaks if we release x.y.z where x, y or z are +// greater than 99_999. +const version = pkg.version.split(".").reduce((v, x) => v * 1e5 + +x, 0); +const versionKey = "@babel/plugin-class-features/version"; + +export function createClassFeaturePlugin({ + name, + feature, + loose, + manipulateOptions, +}) { + return { + name, + manipulateOptions, + + pre() { + enableFeature(this.file, feature, loose); + + if (!this.file.get(versionKey) || this.file.get(versionKey) < version) { + this.file.set(versionKey, version); + } + }, + + visitor: { + Class(path, state) { + if (this.file.get(versionKey) !== version) return; + + verifyUsedFeatures(path, this.file); + + const loose = isLoose(this.file, feature); + + let constructor; + let isDecorated = hasOwnDecorators(path.node); + const props = []; + const elements = []; + const computedPaths = []; + const privateNames = new Set(); + const body = path.get("body"); + + for (const path of body.get("body")) { + verifyUsedFeatures(path, this.file); + + if (path.node.computed) { + computedPaths.push(path); + } + + if (path.isPrivate()) { + const { name } = path.node.key.id; + const getName = `get ${name}`; + const setName = `set ${name}`; + + if (path.node.kind === "get") { + if ( + privateNames.has(getName) || + (privateNames.has(name) && !privateNames.has(setName)) + ) { + throw path.buildCodeFrameError("Duplicate private field"); + } + + privateNames.add(getName).add(name); + } else if (path.node.kind === "set") { + if ( + privateNames.has(setName) || + (privateNames.has(name) && !privateNames.has(getName)) + ) { + throw path.buildCodeFrameError("Duplicate private field"); + } + + privateNames.add(setName).add(name); + } else { + if ( + (privateNames.has(name) && + (!privateNames.has(getName) && !privateNames.has(setName))) || + (privateNames.has(name) && + (privateNames.has(getName) || privateNames.has(setName))) + ) { + throw path.buildCodeFrameError("Duplicate private field"); + } + + privateNames.add(name); + } + } + + if (path.isClassMethod({ kind: "constructor" })) { + constructor = path; + } else { + elements.push(path); + if (path.isProperty() || path.isPrivate()) { + props.push(path); + } + } + + if (!isDecorated) isDecorated = hasOwnDecorators(path.node); + } + + if (!props.length && !isDecorated) return; + + let ref; + + if (path.isClassExpression() || !path.node.id) { + nameFunction(path); + ref = path.scope.generateUidIdentifier("class"); + } else { + ref = path.node.id; + } + + // NODE: These three functions don't support decorators yet, + // but verifyUsedFeatures throws if there are both + // decorators and private fields. + const privateNamesMap = buildPrivateNamesMap(props); + const privateNamesNodes = buildPrivateNamesNodes( + privateNamesMap, + loose, + state, + ); + + transformPrivateNamesUsage(ref, path, privateNamesMap, loose, state); + + let keysNodes, staticNodes, instanceNodes, wrapClass; + + if (isDecorated) { + staticNodes = keysNodes = []; + ({ instanceNodes, wrapClass } = buildDecoratedClass( + ref, + path, + elements, + this.file, + )); + } else { + keysNodes = extractComputedKeys(ref, path, computedPaths, this.file); + ({ staticNodes, instanceNodes, wrapClass } = buildFieldsInitNodes( + ref, + path.node.superClass, + props, + privateNamesMap, + state, + loose, + )); + } + + if (instanceNodes.length > 0) { + injectInitialization( + path, + constructor, + instanceNodes, + (referenceVisitor, state) => { + if (isDecorated) return; + for (const prop of props) { + if (prop.node.static) continue; + prop.traverse(referenceVisitor, state); + } + }, + ); + } + + path = wrapClass(path); + path.insertBefore(keysNodes); + path.insertAfter([...privateNamesNodes, ...staticNodes]); + }, + + PrivateName(path) { + if (this.file.get(versionKey) !== version) return; + + throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`); + }, + + ExportDefaultDeclaration(path) { + if (this.file.get(versionKey) !== version) return; + + const decl = path.get("declaration"); + + if (decl.isClassDeclaration() && hasDecorators(decl.node)) { + if (decl.node.id) { + // export default class Foo {} + // --> + // class Foo {} export { Foo as default } + splitExportDeclaration(path); + } else { + // Annyms class declarations can be + // transformed as if they were expressions + decl.node.type = "ClassExpression"; + } + } + }, + }, + }; +} diff --git a/packages/babel-helper-create-class-features-plugin/src/misc.js b/packages/babel-helper-create-class-features-plugin/src/misc.js new file mode 100644 index 000000000000..ff5178374a56 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/src/misc.js @@ -0,0 +1,117 @@ +import { template, traverse, types as t } from "@babel/core"; +import { environmentVisitor } from "@babel/helper-replace-supers"; + +const findBareSupers = traverse.visitors.merge([ + { + Super(path) { + const { node, parentPath } = path; + if (parentPath.isCallExpression({ callee: node })) { + this.push(parentPath); + } + }, + }, + environmentVisitor, +]); + +const referenceVisitor = { + "TSTypeAnnotation|TypeAnnotation"(path) { + path.skip(); + }, + + ReferencedIdentifier(path) { + if (this.scope.hasOwnBinding(path.node.name)) { + this.scope.rename(path.node.name); + path.skip(); + } + }, +}; + +const classFieldDefinitionEvaluationTDZVisitor = traverse.visitors.merge([ + { + ReferencedIdentifier(path) { + if ( + this.classBinding && + this.classBinding === path.scope.getBinding(path.node.name) + ) { + const classNameTDZError = this.file.addHelper("classNameTDZError"); + const throwNode = t.callExpression(classNameTDZError, [ + t.stringLiteral(path.node.name), + ]); + + path.replaceWith(t.sequenceExpression([throwNode, path.node])); + path.skip(); + } + }, + }, + environmentVisitor, +]); + +export function injectInitialization(path, constructor, nodes, renamer) { + if (!nodes.length) return; + + const isDerived = !!path.node.superClass; + + if (!constructor) { + const newConstructor = t.classMethod( + "constructor", + t.identifier("constructor"), + [], + t.blockStatement([]), + ); + + if (isDerived) { + newConstructor.params = [t.restElement(t.identifier("args"))]; + newConstructor.body.body.push(template.statement.ast`super(...args)`); + } + + [constructor] = path.get("body").unshiftContainer("body", newConstructor); + } + + if (renamer) { + renamer(referenceVisitor, { scope: constructor.scope }); + } + + if (isDerived) { + const bareSupers = []; + constructor.traverse(findBareSupers, bareSupers); + for (const bareSuper of bareSupers) { + bareSuper.insertAfter(nodes); + } + } else { + constructor.get("body").unshiftContainer("body", nodes); + } +} + +export function extractComputedKeys(ref, path, computedPaths, file) { + const declarations = []; + + for (const computedPath of computedPaths) { + computedPath.traverse(classFieldDefinitionEvaluationTDZVisitor, { + classBinding: path.node.id && path.scope.getBinding(path.node.id.name), + file, + }); + + const computedNode = computedPath.node; + // Make sure computed property names are only evaluated once (upon class definition) + // and in the right order in combination with static properties + if (!computedPath.get("key").isConstantExpression()) { + const ident = path.scope.generateUidIdentifierBasedOnNode( + computedNode.key, + ); + // Declaring in the same block scope + // Ref: https://github.com/babel/babel/pull/10029/files#diff-fbbdd83e7a9c998721c1484529c2ce92 + path.scope.push({ + id: ident, + kind: "let", + }); + declarations.push( + t.expressionStatement( + t.assignmentExpression("=", t.cloneNode(ident), computedNode.key), + ), + ); + computedNode.key = t.cloneNode(ident); + } + } + + return declarations; +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/input.js new file mode 100644 index 000000000000..eb0eb350654f --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/input.js @@ -0,0 +1,3 @@ +class A { + foo; +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/options.json new file mode 100644 index 000000000000..60fe9fc3ffdf --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["proposal-class-properties", { "loose": true }, "name 1"], + ["proposal-class-properties", { "loose": false }, "name 2"] + ] +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/output.js new file mode 100644 index 000000000000..063a057f52c0 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/loose-not-overwritten/output.js @@ -0,0 +1,6 @@ +class A { + constructor() { + this.foo = void 0; + } + +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/input.js new file mode 100644 index 000000000000..970c1db08ec2 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/input.js @@ -0,0 +1,7 @@ +const sym = Symbol(); +const sym1 = Symbol(); + +class A { + [sym]: A.B; + [sym1]: Array; +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/options.json new file mode 100644 index 000000000000..ec128fdb330b --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/options.json @@ -0,0 +1,4 @@ +{ + "presets": ["flow"], + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/output.js new file mode 100644 index 000000000000..fd32a2ea962d --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type-challenge/output.js @@ -0,0 +1,13 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +const sym = Symbol(); +const sym1 = Symbol(); + +class A { + constructor() { + _defineProperty(this, sym, void 0); + + _defineProperty(this, sym1, void 0); + } + +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/input.js new file mode 100644 index 000000000000..ccab98482097 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/input.js @@ -0,0 +1,5 @@ +const sym = Symbol(); + +class A { + [sym]: A; +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/options.json new file mode 100644 index 000000000000..ec128fdb330b --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/options.json @@ -0,0 +1,4 @@ +{ + "presets": ["flow"], + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/output.js new file mode 100644 index 000000000000..bfd8df8eda20 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-class-properties/recursive-class-property-type/output.js @@ -0,0 +1,10 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +const sym = Symbol(); + +class A { + constructor() { + _defineProperty(this, sym, void 0); + } + +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/input.js new file mode 100644 index 000000000000..40fba0a0a941 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/input.js @@ -0,0 +1,5 @@ +class X { + #privateMethod() { + return 42; + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/options.json new file mode 100644 index 000000000000..f85119d087cc --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + ["proposal-private-methods", { "loose": false }] + ] +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js new file mode 100644 index 000000000000..2a500530b640 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js @@ -0,0 +1,12 @@ +class X { + constructor() { + _privateMethod.add(this); + } + +} + +var _privateMethod = new WeakSet(); + +var _privateMethod2 = function _privateMethod2() { + return 42; +}; diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/input.js new file mode 100644 index 000000000000..40fba0a0a941 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/input.js @@ -0,0 +1,5 @@ +class X { + #privateMethod() { + return 42; + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/options.json new file mode 100644 index 000000000000..e0ee1124a93a --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + ["proposal-private-methods", { "loose": true }] + ] +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/output.js new file mode 100644 index 000000000000..a660b0038d59 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-true/output.js @@ -0,0 +1,18 @@ +var id = 0; + +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } + +class X { + constructor() { + Object.defineProperty(this, _privateMethod, { + value: _privateMethod2 + }); + } + +} + +var _privateMethod = _classPrivateFieldLooseKey("privateMethod"); + +var _privateMethod2 = function _privateMethod2() { + return 42; +}; diff --git a/packages/babel-helper-create-class-features-plugin/test/index.js b/packages/babel-helper-create-class-features-plugin/test/index.js new file mode 100644 index 000000000000..1b534b8fc64a --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/index.js @@ -0,0 +1,3 @@ +import runner from "@babel/helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-helper-define-map/package.json b/packages/babel-helper-define-map/package.json index 366e4a0610b1..a51713a7f9f5 100644 --- a/packages/babel-helper-define-map/package.json +++ b/packages/babel-helper-define-map/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-define-map", - "version": "7.1.0", + "version": "7.5.5", "description": "Helper function to define a map", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-define-map", "license": "MIT", @@ -10,7 +10,7 @@ "main": "lib/index.js", "dependencies": { "@babel/helper-function-name": "^7.1.0", - "@babel/types": "^7.0.0", - "lodash": "^4.17.10" + "@babel/types": "^7.5.5", + "lodash": "^4.17.13" } } diff --git a/packages/babel-helper-define-map/src/index.js b/packages/babel-helper-define-map/src/index.js index ff588c1ce380..da81b3a43bd7 100644 --- a/packages/babel-helper-define-map/src/index.js +++ b/packages/babel-helper-define-map/src/index.js @@ -98,7 +98,7 @@ export function push( } export function hasComputed(mutatorMap: Object): boolean { - for (const key in mutatorMap) { + for (const key of Object.keys(mutatorMap)) { if (mutatorMap[key]._computed) { return true; } diff --git a/packages/babel-helper-fixtures/package.json b/packages/babel-helper-fixtures/package.json index 2704f7328c66..809a91b81c73 100644 --- a/packages/babel-helper-fixtures/package.json +++ b/packages/babel-helper-fixtures/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-fixtures", - "version": "7.0.0", + "version": "7.5.5", "description": "Helper function to support fixtures", "author": "Sebastian McKenzie ", "license": "MIT", @@ -10,7 +10,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-fixtures", "main": "lib/index.js", "dependencies": { - "lodash": "^4.17.10", + "lodash": "^4.17.13", "semver": "^5.3.0", "try-resolve": "^1.0.0" } diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.js index 29a15433658e..7fc0cf21a3c7 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.js @@ -70,7 +70,7 @@ function findFile(filepath: string, allowJSON: boolean) { throw new Error(`Found conflicting file matches: ${matches.join(", ")}`); } - return matches[0] || filepath + ".js"; + return matches[0]; } export default function get(entryLoc): Array { @@ -101,10 +101,26 @@ export default function get(entryLoc): Array { } function push(taskName, taskDir) { - const actualLoc = findFile(taskDir + "/input"); - const expectLoc = findFile(taskDir + "/output", true /* allowJSON */); + const taskDirStats = fs.statSync(taskDir); + let actualLoc = findFile(taskDir + "/input"); let execLoc = findFile(taskDir + "/exec"); + // If neither input nor exec is present it is not a real testcase + if (taskDirStats.isDirectory() && !actualLoc && !execLoc) { + if (fs.readdirSync(taskDir).length > 0) { + console.warn(`Skipped test folder with invalid layout: ${taskDir}`); + } + return; + } else if (!actualLoc) { + actualLoc = taskDir + "/input.js"; + } else if (!execLoc) { + execLoc = taskDir + "/exec.js"; + } + + const expectLoc = + findFile(taskDir + "/output", true /* allowJSON */) || + taskDir + "/output.js"; + const actualLocAlias = suiteName + "/" + taskName + "/" + path.basename(actualLoc); const expectLocAlias = @@ -112,7 +128,7 @@ export default function get(entryLoc): Array { let execLocAlias = suiteName + "/" + taskName + "/" + path.basename(actualLoc); - if (fs.statSync(taskDir).isFile()) { + if (taskDirStats.isFile()) { const ext = path.extname(taskDir); if (EXTENSIONS.indexOf(ext) === -1) return; diff --git a/packages/babel-helper-hoist-variables/package.json b/packages/babel-helper-hoist-variables/package.json index 74c6e29d6b7d..dad2e954ce2f 100644 --- a/packages/babel-helper-hoist-variables/package.json +++ b/packages/babel-helper-hoist-variables/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-hoist-variables", - "version": "7.0.0", + "version": "7.4.4", "description": "Helper function to hoist variables", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-hoist-variables", "license": "MIT", @@ -9,6 +9,6 @@ }, "main": "lib/index.js", "dependencies": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.4.4" } } diff --git a/packages/babel-helper-hoist-variables/src/index.js b/packages/babel-helper-hoist-variables/src/index.js index 4f9c6d938bd7..6b8bb4cf3b03 100644 --- a/packages/babel-helper-hoist-variables/src/index.js +++ b/packages/babel-helper-hoist-variables/src/index.js @@ -28,7 +28,7 @@ const visitor = { ); } - for (const name in declar.getBindingIdentifiers()) { + for (const name of Object.keys(declar.getBindingIdentifiers())) { state.emit(t.identifier(name), name, declar.node.init !== null); } } diff --git a/packages/babel-helper-member-expression-to-functions/package.json b/packages/babel-helper-member-expression-to-functions/package.json index 6783f48cc9d2..4e94f0cdefaf 100644 --- a/packages/babel-helper-member-expression-to-functions/package.json +++ b/packages/babel-helper-member-expression-to-functions/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-member-expression-to-functions", - "version": "7.0.0", + "version": "7.5.5", "description": "Helper function to replace certain member expressions with function calls", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-member-expression-to-functions", "license": "MIT", @@ -10,6 +10,6 @@ "main": "lib/index.js", "author": "Justin Ridgewell ", "dependencies": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.5.5" } } diff --git a/packages/babel-helper-member-expression-to-functions/src/index.js b/packages/babel-helper-member-expression-to-functions/src/index.js index e44c3eb78496..88b8514c2cdf 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -100,6 +100,34 @@ const handle = { return; } + // { KEY: MEMBER } = OBJ -> { KEY: _destructureSet(MEMBER) } = OBJ + // { KEY: MEMBER = _VALUE } = OBJ -> { KEY: _destructureSet(MEMBER) = _VALUE } = OBJ + // {...MEMBER} -> {..._destructureSet(MEMBER)} + // + // [MEMBER] = ARR -> [_destructureSet(MEMBER)] = ARR + // [MEMBER = _VALUE] = ARR -> [_destructureSet(MEMBER) = _VALUE] = ARR + // [...MEMBER] -> [..._destructureSet(MEMBER)] + if ( + // { KEY: MEMBER } = OBJ + (parentPath.isObjectProperty({ value: node }) && + parentPath.parentPath.isObjectPattern()) || + // { KEY: MEMBER = _VALUE } = OBJ + (parentPath.isAssignmentPattern({ left: node }) && + parentPath.parentPath.isObjectProperty({ value: parent }) && + parentPath.parentPath.parentPath.isObjectPattern()) || + // [MEMBER] = ARR + parentPath.isArrayPattern() || + // [MEMBER = _VALUE] = ARR + (parentPath.isAssignmentPattern({ left: node }) && + parentPath.parentPath.isArrayPattern()) || + // {...MEMBER} + // [...MEMBER] + parentPath.isRestElement() + ) { + member.replaceWith(this.destructureSet(member)); + return; + } + // MEMBER -> _get(MEMBER) member.replaceWith(this.get(member)); }, diff --git a/packages/babel-helper-module-transforms/package.json b/packages/babel-helper-module-transforms/package.json index 4df315528955..3e4d55182dcf 100644 --- a/packages/babel-helper-module-transforms/package.json +++ b/packages/babel-helper-module-transforms/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-module-transforms", - "version": "7.1.0", + "version": "7.5.5", "description": "Babel helper functions for implementing ES6 module transformations", "author": "Logan Smyth ", "homepage": "https://babeljs.io/", @@ -13,9 +13,9 @@ "dependencies": { "@babel/helper-module-imports": "^7.0.0", "@babel/helper-simple-access": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/template": "^7.1.0", - "@babel/types": "^7.0.0", - "lodash": "^4.17.10" + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/template": "^7.4.4", + "@babel/types": "^7.5.5", + "lodash": "^4.17.13" } } diff --git a/packages/babel-helper-module-transforms/src/normalize-and-load-metadata.js b/packages/babel-helper-module-transforms/src/normalize-and-load-metadata.js index 3f2f86dfdd5a..18fe439ce59e 100644 --- a/packages/babel-helper-module-transforms/src/normalize-and-load-metadata.js +++ b/packages/babel-helper-module-transforms/src/normalize-and-load-metadata.js @@ -8,6 +8,8 @@ export type ModuleMetadata = { // The name of the variable that will reference an object containing export names. exportNameListName: null | string, + hasExports: boolean, + // Lookup from local binding to export information. local: Map, @@ -52,18 +54,7 @@ export type LocalExportMetadata = { * Check if the module has any exports that need handling. */ export function hasExports(metadata: ModuleMetadata) { - const { local, source } = metadata; - - return ( - local.size > 0 || - Array.from(source).some(([, meta]) => { - return ( - meta.reexports.size > 0 || - meta.reexportNamespace.size > 0 || - !!meta.reexportAll - ); - }) - ); + return metadata.hasExports; } /** @@ -99,7 +90,10 @@ export default function normalizeModuleAndLoadMetadata( nameAnonymousExports(programPath); - const { local, source } = getModuleMetadata(programPath, { loose, lazy }); + const { local, source, hasExports } = getModuleMetadata(programPath, { + loose, + lazy, + }); removeModuleDeclarations(programPath); @@ -127,6 +121,7 @@ export default function normalizeModuleAndLoadMetadata( return { exportName, exportNameListName: null, + hasExports, local, source, }; @@ -171,6 +166,7 @@ function getModuleMetadata( } return data; }; + let hasExports = false; programPath.get("body").forEach(child => { if (child.isImportDeclaration()) { const data = getData(child.node.source); @@ -219,6 +215,7 @@ function getModuleMetadata( } }); } else if (child.isExportAllDeclaration()) { + hasExports = true; const data = getData(child.node.source); if (!data.loc) data.loc = child.node.loc; @@ -226,6 +223,7 @@ function getModuleMetadata( loc: child.node.loc, }; } else if (child.isExportNamedDeclaration() && child.node.source) { + hasExports = true; const data = getData(child.node.source); if (!data.loc) data.loc = child.node.loc; @@ -242,6 +240,11 @@ function getModuleMetadata( throw exportName.buildCodeFrameError('Illegal export "__esModule".'); } }); + } else if ( + child.isExportNamedDeclaration() || + child.isExportDefaultDeclaration() + ) { + hasExports = true; } }); @@ -285,7 +288,7 @@ function getModuleMetadata( // dependency modules are loaded lazily. metadata.lazy = !/\./.test(source); } else if (Array.isArray(lazy)) { - metadata.lazy = lazy.indexOf(source); + metadata.lazy = lazy.indexOf(source) !== -1; } else if (typeof lazy === "function") { metadata.lazy = lazy(source); } else { @@ -295,6 +298,7 @@ function getModuleMetadata( } return { + hasExports, local: localData, source: sourceData, }; diff --git a/packages/babel-helper-module-transforms/src/rewrite-this.js b/packages/babel-helper-module-transforms/src/rewrite-this.js index 5d79687244f7..1c572c2d40e9 100644 --- a/packages/babel-helper-module-transforms/src/rewrite-this.js +++ b/packages/babel-helper-module-transforms/src/rewrite-this.js @@ -17,4 +17,7 @@ const rewriteThisVisitor = { ClassProperty(path) { path.skip(); }, + ClassPrivateProperty(path) { + path.skip(); + }, }; diff --git a/packages/babel-helper-regex/package.json b/packages/babel-helper-regex/package.json index a7fa3c2b762c..0fdf8c0aee80 100644 --- a/packages/babel-helper-regex/package.json +++ b/packages/babel-helper-regex/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-regex", - "version": "7.0.0", + "version": "7.5.5", "description": "Helper function to check for literal RegEx", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-regex", "license": "MIT", @@ -9,6 +9,6 @@ }, "main": "lib/index.js", "dependencies": { - "lodash": "^4.17.10" + "lodash": "^4.17.13" } } diff --git a/packages/babel-helper-replace-supers/package.json b/packages/babel-helper-replace-supers/package.json index 23fe71896e59..a6c6dbc76c2b 100644 --- a/packages/babel-helper-replace-supers/package.json +++ b/packages/babel-helper-replace-supers/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-replace-supers", - "version": "7.1.0", + "version": "7.5.5", "description": "Helper function to replace supers", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers", "license": "MIT", @@ -9,9 +9,9 @@ }, "main": "lib/index.js", "dependencies": { - "@babel/helper-member-expression-to-functions": "^7.0.0", + "@babel/helper-member-expression-to-functions": "^7.5.5", "@babel/helper-optimise-call-expression": "^7.0.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" + "@babel/traverse": "^7.5.5", + "@babel/types": "^7.5.5" } } diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index d8da1f0409fd..3412d321caf2 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -15,11 +15,12 @@ import * as t from "@babel/types"; * * helpers.getPrototypeOf(CLASS.prototype) */ -function getPrototypeOfExpression(objectRef, isStatic, file) { +function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) { objectRef = t.cloneNode(objectRef); - const targetRef = isStatic - ? objectRef - : t.memberExpression(objectRef, t.identifier("prototype")); + const targetRef = + isStatic || isPrivateMethod + ? objectRef + : t.memberExpression(objectRef, t.identifier("prototype")); return t.callExpression(file.addHelper("getPrototypeOf"), [targetRef]); } @@ -40,6 +41,9 @@ function skipAllButComputedKey(path) { } export const environmentVisitor = { + TypeAnnotation(path) { + path.skip(); + }, Function(path) { // Methods will be handled by the Method visit if (path.isMethod()) return; @@ -48,13 +52,7 @@ export const environmentVisitor = { path.skip(); }, - Method(path) { - skipAllButComputedKey(path); - }, - - "ClassProperty|ClassPrivateProperty"(path) { - // If the property is computed, we need to visit everything. - if (path.node.static) return; + "Method|ClassProperty|ClassPrivateProperty"(path) { skipAllButComputedKey(path); }, }; @@ -101,7 +99,12 @@ const specHandlers = { get(superMember) { return t.callExpression(this.file.addHelper("get"), [ - getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file), + getPrototypeOfExpression( + this.getObjectRef(), + this.isStatic, + this.file, + this.isPrivateMethod, + ), this.prop(superMember), t.thisExpression(), ]); @@ -109,7 +112,12 @@ const specHandlers = { set(superMember, value) { return t.callExpression(this.file.addHelper("set"), [ - getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file), + getPrototypeOfExpression( + this.getObjectRef(), + this.isStatic, + this.file, + this.isPrivateMethod, + ), this.prop(superMember), value, t.thisExpression(), @@ -117,6 +125,12 @@ const specHandlers = { ]); }, + destructureSet(superMember) { + throw superMember.buildCodeFrameError( + `Destructuring to a super field is not supported yet.`, + ); + }, + call(superMember, args) { return optimiseCall(this.get(superMember), t.thisExpression(), args); }, @@ -166,6 +180,13 @@ const looseHandlers = { value, ); }, + + destructureSet(superMember) { + const { computed } = superMember.node; + const prop = this.prop(superMember); + + return t.memberExpression(t.thisExpression(), prop, computed); + }, }; export default class ReplaceSupers { @@ -173,8 +194,8 @@ export default class ReplaceSupers { const path = opts.methodPath; this.methodPath = path; - this.isStatic = - path.isClassMethod({ static: true }) || path.isObjectMethod(); + this.isStatic = path.isObjectMethod() || path.node.static; + this.isPrivateMethod = path.isPrivate() && path.isMethod(); this.file = opts.file; this.superRef = opts.superRef; @@ -205,6 +226,7 @@ export default class ReplaceSupers { memberExpressionToFunctions(this.methodPath, visitor, { file: this.file, isStatic: this.isStatic, + isPrivateMethod: this.isPrivateMethod, getObjectRef: this.getObjectRef.bind(this), superRef: this.superRef, ...handler, diff --git a/packages/babel-helper-split-export-declaration/package.json b/packages/babel-helper-split-export-declaration/package.json index 5a449d06a82d..f8510565f9e9 100644 --- a/packages/babel-helper-split-export-declaration/package.json +++ b/packages/babel-helper-split-export-declaration/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-split-export-declaration", - "version": "7.0.0", + "version": "7.4.4", "description": "", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-split-export-declaration", "license": "MIT", @@ -9,6 +9,6 @@ }, "main": "lib/index.js", "dependencies": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.4.4" } } diff --git a/packages/babel-helper-split-export-declaration/src/index.js b/packages/babel-helper-split-export-declaration/src/index.js index ffbf52243a05..c591f8746396 100644 --- a/packages/babel-helper-split-export-declaration/src/index.js +++ b/packages/babel-helper-split-export-declaration/src/index.js @@ -49,10 +49,7 @@ export default function splitExportDeclaration(exportDeclaration) { exportDeclaration.replaceWith(updatedDeclaration); if (needBindingRegistration) { - scope.registerBinding( - isClassDeclaration ? "let" : "var", - exportDeclaration, - ); + scope.registerDeclaration(exportDeclaration); } return exportDeclaration; diff --git a/packages/babel-helper-transform-fixture-test-runner/package.json b/packages/babel-helper-transform-fixture-test-runner/package.json index 2a2ee591d06f..f1e766baff50 100644 --- a/packages/babel-helper-transform-fixture-test-runner/package.json +++ b/packages/babel-helper-transform-fixture-test-runner/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-transform-fixture-test-runner", - "version": "7.1.0", + "version": "7.5.5", "description": "Transform test runner for @babel/helper-fixtures module", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -11,13 +11,14 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner", "main": "lib/index.js", "dependencies": { - "@babel/code-frame": "^7.0.0", - "@babel/core": "^7.1.0", - "@babel/helper-fixtures": "^7.0.0", - "@babel/polyfill": "^7.0.0", - "jest": "^22.4.2", - "jest-diff": "^22.4.0", - "lodash": "^4.17.10", + "@babel/code-frame": "^7.5.5", + "@babel/core": "^7.5.5", + "@babel/helper-fixtures": "^7.5.5", + "@babel/polyfill": "^7.4.4", + "babel-check-duplicated-nodes": "^1.0.0", + "jest": "^24.8.0", + "jest-diff": "^24.8.0", + "lodash": "^4.17.13", "resolve": "^1.3.2", "source-map": "^0.5.0" } diff --git a/packages/babel-helper-transform-fixture-test-runner/src/index.js b/packages/babel-helper-transform-fixture-test-runner/src/index.js index a16e19b1a68c..a83e8ff1c61b 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.js @@ -15,6 +15,7 @@ import assert from "assert"; import fs from "fs"; import path from "path"; import vm from "vm"; +import checkDuplicatedNodes from "babel-check-duplicated-nodes"; import diff from "jest-diff"; @@ -129,51 +130,6 @@ function wrapPackagesArray(type, names, optionsDir) { }); } -function checkDuplicatedNodes(ast) { - const nodes = new WeakSet(); - const parents = new WeakMap(); - - const setParent = (child, parent) => { - if (typeof child === "object" && child !== null) { - let p = parents.get(child); - if (!p) { - p = []; - parents.set(child, p); - } - p.unshift(parent); - } - }; - const registerChildren = node => { - for (const key in node) { - if (Array.isArray(node[key])) { - node[key].forEach(child => setParent(child, node)); - } else { - setParent(node[key], node); - } - } - }; - - const hidePrivateProperties = (key, val) => { - // Hides properties like _shadowedFunctionLiteral, - // which makes the AST circular - if (key[0] === "_") return "[Private]"; - return val; - }; - - babel.types.traverseFast(ast, node => { - registerChildren(node); - if (nodes.has(node)) { - throw new Error( - "Do not reuse nodes. Use `t.cloneNode` to copy them.\n" + - JSON.stringify(node, hidePrivateProperties, 2) + - "\nParent:\n" + - JSON.stringify(parents.get(node), hidePrivateProperties, 2), - ); - } - nodes.add(node); - }); -} - function run(task) { const actual = task.actual; const expected = task.expect; @@ -222,7 +178,7 @@ function run(task) { if (execCode) { const execOpts = getOpts(exec); result = babel.transform(execCode, execOpts); - checkDuplicatedNodes(result.ast); + checkDuplicatedNodes(babel, result.ast); execCode = result.code; try { @@ -244,7 +200,7 @@ function run(task) { "", ); - checkDuplicatedNodes(result.ast); + checkDuplicatedNodes(babel, result.ast); if ( !expected.code && expectedCode && diff --git a/packages/babel-helper-wrap-function/package.json b/packages/babel-helper-wrap-function/package.json index b563d6125aa3..d0a3396e76f5 100644 --- a/packages/babel-helper-wrap-function/package.json +++ b/packages/babel-helper-wrap-function/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helper-wrap-function", - "version": "7.1.0", + "version": "7.2.0", "description": "Helper to wrap functions inside a function call.", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-wrap-function", "license": "MIT", @@ -12,6 +12,6 @@ "@babel/helper-function-name": "^7.1.0", "@babel/template": "^7.1.0", "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" + "@babel/types": "^7.2.0" } } diff --git a/packages/babel-helper-wrap-function/src/index.js b/packages/babel-helper-wrap-function/src/index.js index c05d80fc4fed..d36e9d267700 100644 --- a/packages/babel-helper-wrap-function/src/index.js +++ b/packages/babel-helper-wrap-function/src/index.js @@ -3,7 +3,7 @@ import nameFunction from "@babel/helper-function-name"; import template from "@babel/template"; import * as t from "@babel/types"; -const buildExpressionWrapper = template.expression(` +const buildAnonymousExpressionWrapper = template.expression(` (function () { var REF = FUNCTION; return function NAME(PARAMS) { @@ -12,6 +12,16 @@ const buildExpressionWrapper = template.expression(` })() `); +const buildNamedExpressionWrapper = template.expression(` + (function () { + var REF = FUNCTION; + function NAME(PARAMS) { + return REF.apply(this, arguments); + } + return NAME; + })() +`); + const buildDeclarationWrapper = template(` function NAME(PARAMS) { return REF.apply(this, arguments); } function REF() { @@ -53,7 +63,9 @@ function plainFunction(path: NodePath, callId: Object) { const functionId = node.id; const wrapper = isDeclaration ? buildDeclarationWrapper - : buildExpressionWrapper; + : functionId + ? buildNamedExpressionWrapper + : buildAnonymousExpressionWrapper; if (path.isArrowFunctionExpression()) { path.arrowFunctionToExpression(); diff --git a/packages/babel-helpers/package.json b/packages/babel-helpers/package.json index 172471ed321b..54db360349b1 100644 --- a/packages/babel-helpers/package.json +++ b/packages/babel-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@babel/helpers", - "version": "7.1.0", + "version": "7.5.5", "description": "Collection of helper functions used by Babel transforms.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -11,9 +11,9 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers", "main": "lib/index.js", "dependencies": { - "@babel/template": "^7.1.0", - "@babel/traverse": "^7.1.0", - "@babel/types": "^7.0.0" + "@babel/template": "^7.4.4", + "@babel/traverse": "^7.5.5", + "@babel/types": "^7.5.5" }, "devDependencies": { "@babel/helper-plugin-test-runner": "^7.0.0" diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index ca0491e99522..527b24c330ac 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -26,13 +26,14 @@ helpers.typeof = helper("7.0.0-beta.0")` } `; +// "for" is a reserved keyword in ES3 so escaping it here for backward compatibility helpers.jsx = helper("7.0.0-beta.0")` var REACT_ELEMENT_TYPE; export default function _createRawReactElement(type, props, key, children) { if (!REACT_ELEMENT_TYPE) { REACT_ELEMENT_TYPE = ( - typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") + typeof Symbol === "function" && Symbol["for"] && Symbol["for"]("react.element") ) || 0xeac7; } @@ -80,7 +81,7 @@ helpers.jsx = helper("7.0.0-beta.0")` helpers.asyncIterator = helper("7.0.0-beta.0")` export default function _asyncIterator(iterable) { var method - if (typeof Symbol === "function") { + if (typeof Symbol !== "undefined") { if (Symbol.asyncIterator) { method = iterable[Symbol.asyncIterator] if (method != null) return method.call(iterable); @@ -384,6 +385,7 @@ helpers.extends = helper("7.0.0-beta.0")` } `; +// This old helper can be removed in babel v8 helpers.objectSpread = helper("7.0.0-beta.0")` import defineProperty from "defineProperty"; @@ -404,6 +406,48 @@ helpers.objectSpread = helper("7.0.0-beta.0")` } `; +helpers.objectSpread2 = helper("7.5.0")` + import defineProperty from "defineProperty"; + + // This function is different to "Reflect.ownKeys". The enumerableOnly + // filters on symbol properties only. Returned string properties are always + // enumerable. It is good to use in objectSpread. + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + return keys; + } + + export default function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = (arguments[i] != null) ? arguments[i] : {}; + if (i % 2) { + ownKeys(source, true).forEach(function (key) { + defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(source).forEach(function (key) { + Object.defineProperty( + target, + key, + Object.getOwnPropertyDescriptor(source, key) + ); + }); + } + } + return target; + } +`; + helpers.inherits = helper("7.0.0-beta.0")` import setPrototypeOf from "setPrototypeOf"; @@ -548,7 +592,7 @@ helpers.wrapNativeSuper = helper("7.0.0-beta.0")` helpers.instanceof = helper("7.0.0-beta.0")` export default function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { - return right[Symbol.hasInstance](left); + return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } @@ -676,7 +720,6 @@ helpers.superPropBase = helper("7.0.0-beta.0")` `; helpers.get = helper("7.0.0-beta.0")` - import getPrototypeOf from "getPrototypeOf"; import superPropBase from "superPropBase"; export default function _get(target, property, receiver) { @@ -701,7 +744,6 @@ helpers.get = helper("7.0.0-beta.0")` `; helpers.set = helper("7.0.0-beta.0")` - import getPrototypeOf from "getPrototypeOf"; import superPropBase from "superPropBase"; import defineProperty from "defineProperty"; @@ -775,18 +817,6 @@ helpers.taggedTemplateLiteralLoose = helper("7.0.0-beta.0")` } `; -helpers.temporalRef = helper("7.0.0-beta.0")` - import undef from "temporalUndefined"; - - export default function _temporalRef(val, name) { - if (val === undef) { - throw new ReferenceError(name + " is not defined - temporal dead zone"); - } else { - return val; - } - } -`; - helpers.readOnlyError = helper("7.0.0-beta.0")` export default function _readOnlyError(name) { throw new Error("\\"" + name + "\\" is read-only"); @@ -800,7 +830,24 @@ helpers.classNameTDZError = helper("7.0.0-beta.0")` `; helpers.temporalUndefined = helper("7.0.0-beta.0")` - export default {}; + // This function isn't mean to be called, but to be used as a reference. + // We can't use a normal object because it isn't hoisted. + export default function _temporalUndefined() {} +`; + +helpers.tdz = helper("7.5.5")` + export default function _tdzError(name) { + throw new ReferenceError(name + " is not defined - temporal dead zone"); + } +`; + +helpers.temporalRef = helper("7.0.0-beta.0")` + import undef from "temporalUndefined"; + import err from "tdz"; + + export default function _temporalRef(val, name) { + return val === undef ? err(name) : val; + } `; helpers.slicedToArray = helper("7.0.0-beta.0")` @@ -935,13 +982,28 @@ helpers.skipFirstGeneratorNext = helper("7.0.0-beta.0")` } `; -helpers.toPropertyKey = helper("7.0.0-beta.0")` - export default function _toPropertyKey(key) { - if (typeof key === "symbol") { - return key; - } else { - return String(key); +helpers.toPrimitive = helper("7.1.5")` + export default function _toPrimitive( + input, + hint /*: "default" | "string" | "number" | void */ + ) { + if (typeof input !== "object" || input === null) return input; + var prim = input[Symbol.toPrimitive]; + if (prim !== undefined) { + var res = prim.call(input, hint || "default"); + if (typeof res !== "object") return res; + throw new TypeError("@@toPrimitive must return a primitive value."); } + return (hint === "string" ? String : Number)(input); + } +`; + +helpers.toPropertyKey = helper("7.1.5")` + import toPrimitive from "toPrimitive"; + + export default function _toPropertyKey(arg) { + var key = toPrimitive(arg, "string"); + return typeof key === "symbol" ? key : String(key); } `; @@ -983,7 +1045,7 @@ helpers.initializerDefineProperty = helper("7.0.0-beta.0")` helpers.applyDecoratedDescriptor = helper("7.0.0-beta.0")` export default function _applyDecoratedDescriptor(target, property, decorators, descriptor, context){ var desc = {}; - Object['ke' + 'ys'](descriptor).forEach(function(key){ + Object.keys(descriptor).forEach(function(key){ desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; @@ -1004,7 +1066,7 @@ helpers.applyDecoratedDescriptor = helper("7.0.0-beta.0")` if (desc.initializer === void 0){ // This is a hack to avoid this being processed by 'transform-runtime'. // See issue #9. - Object['define' + 'Property'](target, property, desc); + Object.defineProperty(target, property, desc); desc = null; } @@ -1030,27 +1092,65 @@ helpers.classPrivateFieldLooseBase = helper("7.0.0-beta.0")` helpers.classPrivateFieldGet = helper("7.0.0-beta.0")` export default function _classPrivateFieldGet(receiver, privateMap) { - if (!privateMap.has(receiver)) { + var descriptor = privateMap.get(receiver); + if (!descriptor) { throw new TypeError("attempted to get private field on non-instance"); } - return privateMap.get(receiver).value; + if (descriptor.get) { + return descriptor.get.call(receiver); + } + return descriptor.value; } `; helpers.classPrivateFieldSet = helper("7.0.0-beta.0")` export default function _classPrivateFieldSet(receiver, privateMap, value) { + var descriptor = privateMap.get(receiver); + if (!descriptor) { + throw new TypeError("attempted to set private field on non-instance"); + } + if (descriptor.set) { + descriptor.set.call(receiver, value); + } else { + if (!descriptor.writable) { + // This should only throw in strict mode, but class bodies are + // always strict and private fields can only be used inside + // class bodies. + throw new TypeError("attempted to set read only private field"); + } + + descriptor.value = value; + } + + return value; + } +`; + +helpers.classPrivateFieldDestructureSet = helper("7.4.4")` + export default function _classPrivateFieldDestructureSet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } var descriptor = privateMap.get(receiver); - if (!descriptor.writable) { - // This should only throw in strict mode, but class bodies are - // always strict and private fields can only be used inside - // class bodies. - throw new TypeError("attempted to set read only private field"); + if (descriptor.set) { + if (!("__destrObj" in descriptor)) { + descriptor.__destrObj = { + set value(v) { + descriptor.set.call(receiver, v) + }, + }; + } + return descriptor.__destrObj; + } else { + if (!descriptor.writable) { + // This should only throw in strict mode, but class bodies are + // always strict and private fields can only be used inside + // class bodies. + throw new TypeError("attempted to set read only private field"); + } + + return descriptor; } - descriptor.value = value; - return value; } `; @@ -1079,8 +1179,24 @@ helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")` } `; -helpers.decorate = helper("7.0.2")` +helpers.classStaticPrivateMethodGet = helper("7.3.2")` + export default function _classStaticPrivateMethodGet(receiver, classConstructor, method) { + if (receiver !== classConstructor) { + throw new TypeError("Private static access of wrong provenance"); + } + return method; + } +`; + +helpers.classStaticPrivateMethodSet = helper("7.3.2")` + export default function _classStaticPrivateMethodSet() { + throw new TypeError("attempted to set read only static private field"); + } +`; + +helpers.decorate = helper("7.1.5")` import toArray from "toArray"; + import toPropertyKey from "toPropertyKey"; // These comments are stripped by @babel/template /*:: @@ -1196,29 +1312,438 @@ helpers.decorate = helper("7.0.2")` */ + /*:: + + type Placements = { + static: Key[], + prototype: Key[], + own: Key[], + }; + + */ + // ClassDefinitionEvaluation (Steps 26-*) export default function _decorate( decorators /*: ClassDecorator[] */, factory /*: ClassFactory */, superClass /*: ?Class<*> */, + mixins /*: ?Array */, ) /*: Class<*> */ { + var api = _getDecoratorsApi(); + if (mixins) { + for (var i = 0; i < mixins.length; i++) { + api = mixins[i](api); + } + } + var r = factory(function initialize(O) { - _initializeInstanceElements(O, decorated.elements); + api.initializeInstanceElements(O, decorated.elements); }, superClass); - var decorated = _decorateClass( + var decorated = api.decorateClass( _coalesceClassElements(r.d.map(_createElementDescriptor)), decorators, ); - _initializeClassElements(r.F, decorated.elements); + api.initializeClassElements(r.F, decorated.elements); - return _runClassFinishers(r.F, decorated.finishers); + return api.runClassFinishers(r.F, decorated.finishers); + } + + function _getDecoratorsApi() { + _getDecoratorsApi = function() { + return api; + }; + + var api = { + elementsDefinitionOrder: [["method"], ["field"]], + + // InitializeInstanceElements + initializeInstanceElements: function( + /*::*/ O /*: C */, + elements /*: ElementDescriptor[] */, + ) { + ["method", "field"].forEach(function(kind) { + elements.forEach(function(element /*: ElementDescriptor */) { + if (element.kind === kind && element.placement === "own") { + this.defineClassElement(O, element); + } + }, this); + }, this); + }, + + // InitializeClassElements + initializeClassElements: function( + /*::*/ F /*: Class */, + elements /*: ElementDescriptor[] */, + ) { + var proto = F.prototype; + + ["method", "field"].forEach(function(kind) { + elements.forEach(function(element /*: ElementDescriptor */) { + var placement = element.placement; + if ( + element.kind === kind && + (placement === "static" || placement === "prototype") + ) { + var receiver = placement === "static" ? F : proto; + this.defineClassElement(receiver, element); + } + }, this); + }, this); + }, + + // DefineClassElement + defineClassElement: function( + /*::*/ receiver /*: C | Class */, + element /*: ElementDescriptor */, + ) { + var descriptor /*: PropertyDescriptor */ = element.descriptor; + if (element.kind === "field") { + var initializer = element.initializer; + descriptor = { + enumerable: descriptor.enumerable, + writable: descriptor.writable, + configurable: descriptor.configurable, + value: initializer === void 0 ? void 0 : initializer.call(receiver), + }; + } + Object.defineProperty(receiver, element.key, descriptor); + }, + + // DecorateClass + decorateClass: function( + elements /*: ElementDescriptor[] */, + decorators /*: ClassDecorator[] */, + ) /*: ElementsFinishers */ { + var newElements /*: ElementDescriptor[] */ = []; + var finishers /*: ClassFinisher[] */ = []; + var placements /*: Placements */ = { + static: [], + prototype: [], + own: [], + }; + + elements.forEach(function(element /*: ElementDescriptor */) { + this.addElementPlacement(element, placements); + }, this); + + elements.forEach(function(element /*: ElementDescriptor */) { + if (!_hasDecorators(element)) return newElements.push(element); + + var elementFinishersExtras /*: ElementFinishersExtras */ = this.decorateElement( + element, + placements, + ); + newElements.push(elementFinishersExtras.element); + newElements.push.apply(newElements, elementFinishersExtras.extras); + finishers.push.apply(finishers, elementFinishersExtras.finishers); + }, this); + + if (!decorators) { + return { elements: newElements, finishers: finishers }; + } + + var result /*: ElementsFinishers */ = this.decorateConstructor( + newElements, + decorators, + ); + finishers.push.apply(finishers, result.finishers); + result.finishers = finishers; + + return result; + }, + + // AddElementPlacement + addElementPlacement: function( + element /*: ElementDescriptor */, + placements /*: Placements */, + silent /*: boolean */, + ) { + var keys = placements[element.placement]; + if (!silent && keys.indexOf(element.key) !== -1) { + throw new TypeError("Duplicated element (" + element.key + ")"); + } + keys.push(element.key); + }, + + // DecorateElement + decorateElement: function( + element /*: ElementDescriptor */, + placements /*: Placements */, + ) /*: ElementFinishersExtras */ { + var extras /*: ElementDescriptor[] */ = []; + var finishers /*: ClassFinisher[] */ = []; + + for ( + var decorators = element.decorators, i = decorators.length - 1; + i >= 0; + i-- + ) { + // (inlined) RemoveElementPlacement + var keys = placements[element.placement]; + keys.splice(keys.indexOf(element.key), 1); + + var elementObject /*: ElementObjectInput */ = this.fromElementDescriptor( + element, + ); + var elementFinisherExtras /*: ElementFinisherExtras */ = this.toElementFinisherExtras( + (0, decorators[i])(elementObject) /*: ElementObjectOutput */ || + elementObject, + ); + + element = elementFinisherExtras.element; + this.addElementPlacement(element, placements); + + if (elementFinisherExtras.finisher) { + finishers.push(elementFinisherExtras.finisher); + } + + var newExtras /*: ElementDescriptor[] | void */ = + elementFinisherExtras.extras; + if (newExtras) { + for (var j = 0; j < newExtras.length; j++) { + this.addElementPlacement(newExtras[j], placements); + } + extras.push.apply(extras, newExtras); + } + } + + return { element: element, finishers: finishers, extras: extras }; + }, + + // DecorateConstructor + decorateConstructor: function( + elements /*: ElementDescriptor[] */, + decorators /*: ClassDecorator[] */, + ) /*: ElementsFinishers */ { + var finishers /*: ClassFinisher[] */ = []; + + for (var i = decorators.length - 1; i >= 0; i--) { + var obj /*: ClassObject */ = this.fromClassDescriptor(elements); + var elementsAndFinisher /*: ElementsFinisher */ = this.toClassDescriptor( + (0, decorators[i])(obj) /*: ClassObject */ || obj, + ); + + if (elementsAndFinisher.finisher !== undefined) { + finishers.push(elementsAndFinisher.finisher); + } + + if (elementsAndFinisher.elements !== undefined) { + elements = elementsAndFinisher.elements; + + for (var j = 0; j < elements.length - 1; j++) { + for (var k = j + 1; k < elements.length; k++) { + if ( + elements[j].key === elements[k].key && + elements[j].placement === elements[k].placement + ) { + throw new TypeError( + "Duplicated element (" + elements[j].key + ")", + ); + } + } + } + } + } + + return { elements: elements, finishers: finishers }; + }, + + // FromElementDescriptor + fromElementDescriptor: function( + element /*: ElementDescriptor */, + ) /*: ElementObject */ { + var obj /*: ElementObject */ = { + kind: element.kind, + key: element.key, + placement: element.placement, + descriptor: element.descriptor, + }; + + var desc = { + value: "Descriptor", + configurable: true, + }; + Object.defineProperty(obj, Symbol.toStringTag, desc); + + if (element.kind === "field") obj.initializer = element.initializer; + + return obj; + }, + + // ToElementDescriptors + toElementDescriptors: function( + elementObjects /*: ElementObject[] */, + ) /*: ElementDescriptor[] */ { + if (elementObjects === undefined) return; + return toArray(elementObjects).map(function(elementObject) { + var element = this.toElementDescriptor(elementObject); + this.disallowProperty(elementObject, "finisher", "An element descriptor"); + this.disallowProperty(elementObject, "extras", "An element descriptor"); + return element; + }, this); + }, + + // ToElementDescriptor + toElementDescriptor: function( + elementObject /*: ElementObject */, + ) /*: ElementDescriptor */ { + var kind = String(elementObject.kind); + if (kind !== "method" && kind !== "field") { + throw new TypeError( + 'An element descriptor\\'s .kind property must be either "method" or' + + ' "field", but a decorator created an element descriptor with' + + ' .kind "' + + kind + + '"', + ); + } + + var key = toPropertyKey(elementObject.key); + + var placement = String(elementObject.placement); + if ( + placement !== "static" && + placement !== "prototype" && + placement !== "own" + ) { + throw new TypeError( + 'An element descriptor\\'s .placement property must be one of "static",' + + ' "prototype" or "own", but a decorator created an element descriptor' + + ' with .placement "' + + placement + + '"', + ); + } + + var descriptor /*: PropertyDescriptor */ = elementObject.descriptor; + + this.disallowProperty(elementObject, "elements", "An element descriptor"); + + var element /*: ElementDescriptor */ = { + kind: kind, + key: key, + placement: placement, + descriptor: Object.assign({}, descriptor), + }; + + if (kind !== "field") { + this.disallowProperty(elementObject, "initializer", "A method descriptor"); + } else { + this.disallowProperty( + descriptor, + "get", + "The property descriptor of a field descriptor", + ); + this.disallowProperty( + descriptor, + "set", + "The property descriptor of a field descriptor", + ); + this.disallowProperty( + descriptor, + "value", + "The property descriptor of a field descriptor", + ); + + element.initializer = elementObject.initializer; + } + + return element; + }, + + toElementFinisherExtras: function( + elementObject /*: ElementObject */, + ) /*: ElementFinisherExtras */ { + var element /*: ElementDescriptor */ = this.toElementDescriptor( + elementObject, + ); + var finisher /*: ClassFinisher */ = _optionalCallableProperty( + elementObject, + "finisher", + ); + var extras /*: ElementDescriptors[] */ = this.toElementDescriptors( + elementObject.extras, + ); + + return { element: element, finisher: finisher, extras: extras }; + }, + + // FromClassDescriptor + fromClassDescriptor: function( + elements /*: ElementDescriptor[] */, + ) /*: ClassObject */ { + var obj = { + kind: "class", + elements: elements.map(this.fromElementDescriptor, this), + }; + + var desc = { value: "Descriptor", configurable: true }; + Object.defineProperty(obj, Symbol.toStringTag, desc); + + return obj; + }, + + // ToClassDescriptor + toClassDescriptor: function( + obj /*: ClassObject */, + ) /*: ElementsFinisher */ { + var kind = String(obj.kind); + if (kind !== "class") { + throw new TypeError( + 'A class descriptor\\'s .kind property must be "class", but a decorator' + + ' created a class descriptor with .kind "' + + kind + + '"', + ); + } + + this.disallowProperty(obj, "key", "A class descriptor"); + this.disallowProperty(obj, "placement", "A class descriptor"); + this.disallowProperty(obj, "descriptor", "A class descriptor"); + this.disallowProperty(obj, "initializer", "A class descriptor"); + this.disallowProperty(obj, "extras", "A class descriptor"); + + var finisher = _optionalCallableProperty(obj, "finisher"); + var elements = this.toElementDescriptors(obj.elements); + + return { elements: elements, finisher: finisher }; + }, + + // RunClassFinishers + runClassFinishers: function( + constructor /*: Class<*> */, + finishers /*: ClassFinisher[] */, + ) /*: Class<*> */ { + for (var i = 0; i < finishers.length; i++) { + var newConstructor /*: ?Class<*> */ = (0, finishers[i])(constructor); + if (newConstructor !== undefined) { + // NOTE: This should check if IsConstructor(newConstructor) is false. + if (typeof newConstructor !== "function") { + throw new TypeError("Finishers must return a constructor."); + } + constructor = newConstructor; + } + } + return constructor; + }, + + disallowProperty: function(obj, name, objectType) { + if (obj[name] !== undefined) { + throw new TypeError(objectType + " can't have a ." + name + " property."); + } + } + }; + + return api; } // ClassElementEvaluation function _createElementDescriptor( def /*: ElementDefinition */, ) /*: ElementDescriptor */ { + var key = toPropertyKey(def.key); + var descriptor /*: PropertyDescriptor */; if (def.kind === "method") { descriptor = { @@ -1232,17 +1757,17 @@ helpers.decorate = helper("7.0.2")` } else if (def.kind === "set") { descriptor = { set: def.value, configurable: true, enumerable: false }; } else if (def.kind === "field") { - descriptor = { configurable: true, writable: true, enumerable: false }; + descriptor = { configurable: true, writable: true, enumerable: true }; } var element /*: ElementDescriptor */ = { kind: def.kind === "field" ? "field" : "method", - key: def.key, + key: key, placement: def.static ? "static" : def.kind === "field" - ? "own" - : "prototype", + ? "own" + : "prototype", descriptor: descriptor, }; if (def.decorators) element.decorators = def.decorators; @@ -1269,7 +1794,9 @@ helpers.decorate = helper("7.0.2")` ) /*: ElementDescriptor[] */ { var newElements /*: ElementDescriptor[] */ = []; - var isSameElement = function(other /*: ElementDescriptor */) /*: boolean */ { + var isSameElement = function( + other /*: ElementDescriptor */, + ) /*: boolean */ { return ( other.kind === "method" && other.key === element.key && @@ -1328,392 +1855,102 @@ helpers.decorate = helper("7.0.2")` ); } - // InitializeClassElements - function _initializeClassElements /*::*/( - F /*: Class */, - elements /*: ElementDescriptor[] */, - ) { - var proto = F.prototype; - - ["method", "field"].forEach(function(kind) { - elements.forEach(function(element /*: ElementDescriptor */) { - var placement = element.placement; - if ( - element.kind === kind && - (placement === "static" || placement === "prototype") - ) { - var receiver = placement === "static" ? F : proto; - _defineClassElement(receiver, element); - } - }); - }); - } - - // InitializeInstanceElements - function _initializeInstanceElements /*::*/( - O /*: C */, - elements /*: ElementDescriptor[] */, - ) { - ["method", "field"].forEach(function(kind) { - elements.forEach(function(element /*: ElementDescriptor */) { - if (element.kind === kind && element.placement === "own") { - _defineClassElement(O, element); - } - }); - }); - } - - // DefineClassElement - function _defineClassElement /*::*/( - receiver /*: C | Class */, - element /*: ElementDescriptor */, - ) { - var descriptor /*: PropertyDescriptor */ = element.descriptor; - if (element.kind === "field") { - var initializer = element.initializer; - descriptor = { - enumerable: descriptor.enumerable, - writable: descriptor.writable, - configurable: descriptor.configurable, - value: initializer === void 0 ? void 0 : initializer.call(receiver), - }; + function _optionalCallableProperty /*::*/( + obj /*: T */, + name /*: $Keys */, + ) /*: ?Function */ { + var value = obj[name]; + if (value !== undefined && typeof value !== "function") { + throw new TypeError("Expected '" + name + "' to be a function"); } - Object.defineProperty(receiver, element.key, descriptor); + return value; } - /*:: - - type Placements = { - static: Key[], - prototype: Key[], - own: Key[], - }; - - */ - - // DecorateClass - function _decorateClass( - elements /*: ElementDescriptor[] */, - decorators /*: ClassDecorator[] */, - ) /*: ElementsFinishers */ { - var newElements /*: ElementDescriptor[] */ = []; - var finishers /*: ClassFinisher[] */ = []; - var placements /*: Placements */ = { static: [], prototype: [], own: [] }; - - elements.forEach(function(element /*: ElementDescriptor */) { - _addElementPlacement(element, placements); - }); - - elements.forEach(function(element /*: ElementDescriptor */) { - if (!_hasDecorators(element)) return newElements.push(element); - - var elementFinishersExtras /*: ElementFinishersExtras */ = _decorateElement( - element, - placements, - ); - newElements.push(elementFinishersExtras.element); - newElements.push.apply(newElements, elementFinishersExtras.extras); - finishers.push.apply(finishers, elementFinishersExtras.finishers); - }); +`; - if (!decorators) { - return { elements: newElements, finishers: finishers }; +helpers.classPrivateMethodGet = helper("7.1.6")` + export default function _classPrivateMethodGet(receiver, privateSet, fn) { + if (!privateSet.has(receiver)) { + throw new TypeError("attempted to get private field on non-instance"); } - - var result /*: ElementsFinishers */ = _decorateConstructor( - newElements, - decorators, - ); - finishers.push.apply(finishers, result.finishers); - result.finishers = finishers; - - return result; + return fn; } +`; - // AddElementPlacement - function _addElementPlacement( - element /*: ElementDescriptor */, - placements /*: Placements */, - silent /*: boolean */, - ) { - var keys = placements[element.placement]; - if (!silent && keys.indexOf(element.key) !== -1) { - throw new TypeError("Duplicated element (" + element.key + ")"); - } - keys.push(element.key); +helpers.classPrivateMethodSet = helper("7.1.6")` + export default function _classPrivateMethodSet() { + throw new TypeError("attempted to reassign private method"); } +`; - // DecorateElement - function _decorateElement( - element /*: ElementDescriptor */, - placements /*: Placements */, - ) /*: ElementFinishersExtras */ { - var extras /*: ElementDescriptor[] */ = []; - var finishers /*: ClassFinisher[] */ = []; - - for ( - var decorators = element.decorators, i = decorators.length - 1; - i >= 0; - i-- - ) { - // (inlined) RemoveElementPlacement - var keys = placements[element.placement]; - keys.splice(keys.indexOf(element.key), 1); - - var elementObject /*: ElementObjectInput */ = _fromElementDescriptor( - element, - ); - var elementFinisherExtras /*: ElementFinisherExtras */ = _toElementFinisherExtras( - (0, decorators[i])(elementObject) /*: ElementObjectOutput */ || - elementObject, - ); +helpers.wrapRegExp = helper("7.2.6")` + import wrapNativeSuper from "wrapNativeSuper"; + import getPrototypeOf from "getPrototypeOf"; + import possibleConstructorReturn from "possibleConstructorReturn"; + import inherits from "inherits"; - element = elementFinisherExtras.element; - _addElementPlacement(element, placements); + export default function _wrapRegExp(re, groups) { + _wrapRegExp = function(re, groups) { + return new BabelRegExp(re, groups); + }; - if (elementFinisherExtras.finisher) { - finishers.push(elementFinisherExtras.finisher); - } + var _RegExp = wrapNativeSuper(RegExp); + var _super = RegExp.prototype; + var _groups = new WeakMap(); - var newExtras /*: ElementDescriptor[] | void */ = - elementFinisherExtras.extras; - if (newExtras) { - for (var j = 0; j < newExtras.length; j++) { - _addElementPlacement(newExtras[j], placements); - } - extras.push.apply(extras, newExtras); - } + function BabelRegExp(re, groups) { + var _this = _RegExp.call(this, re); + _groups.set(_this, groups); + return _this; } + inherits(BabelRegExp, _RegExp); - return { element: element, finishers: finishers, extras: extras }; - } - - // DecorateConstructor - function _decorateConstructor( - elements /*: ElementDescriptor[] */, - decorators /*: ClassDecorator[] */, - ) /*: ElementsFinishers */ { - var finishers /*: ClassFinisher[] */ = []; - - for (var i = decorators.length - 1; i >= 0; i--) { - var obj /*: ClassObject */ = _fromClassDescriptor(elements); - var elementsAndFinisher /*: ElementsFinisher */ = _toClassDescriptor( - (0, decorators[i])(obj) /*: ClassObject */ || obj, - ); - - if (elementsAndFinisher.finisher !== undefined) { - finishers.push(elementsAndFinisher.finisher); - } - - if (elementsAndFinisher.elements !== undefined) { - elements = elementsAndFinisher.elements; - - for (var j = 0; j < elements.length - 1; j++) { - for (var k = j + 1; k < elements.length; k++) { - if ( - elements[j].key === elements[k].key && - elements[j].placement === elements[k].placement - ) { - throw new TypeError("Duplicated element (" + elements[j].key + ")"); + BabelRegExp.prototype.exec = function(str) { + var result = _super.exec.call(this, str); + if (result) result.groups = buildGroups(result, this); + return result; + }; + BabelRegExp.prototype[Symbol.replace] = function(str, substitution) { + if (typeof substitution === "string") { + var groups = _groups.get(this); + return _super[Symbol.replace].call( + this, + str, + substitution.replace(/\\$<([^>]+)>/g, function(_, name) { + return "$" + groups[name]; + }) + ); + } else if (typeof substitution === "function") { + var _this = this; + return _super[Symbol.replace].call( + this, + str, + function() { + var args = []; + args.push.apply(args, arguments); + if (typeof args[args.length - 1] !== "object") { + // Modern engines already pass result.groups as the last arg. + args.push(buildGroups(args, _this)); } + return substitution.apply(this, args); } - } + ); + } else { + return _super[Symbol.replace].call(this, str, substitution); } } - return { elements: elements, finishers: finishers }; - } - - // FromElementDescriptor - function _fromElementDescriptor( - element /*: ElementDescriptor */, - ) /*: ElementObject */ { - var obj /*: ElementObject */ = { - kind: element.kind, - key: element.key, - placement: element.placement, - descriptor: element.descriptor, - }; - - var desc = { - value: "Descriptor", - configurable: true, - }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - - if (element.kind === "field") obj.initializer = element.initializer; + function buildGroups(result, re) { + // NOTE: This function should return undefined if there are no groups, + // but in that case Babel doesn't add the wrapper anyway. - return obj; - } - - // ToElementDescriptors - function _toElementDescriptors( - elementObjects /*: ElementObject[] */, - ) /*: ElementDescriptor[] */ { - if (elementObjects === undefined) return; - return toArray(elementObjects).map(function(elementObject) { - var element = _toElementDescriptor(elementObject); - _disallowProperty(elementObject, "finisher", "An element descriptor"); - _disallowProperty(elementObject, "extras", "An element descriptor"); - return element; - }); - } - - // ToElementDescriptor - function _toElementDescriptor( - elementObject /*: ElementObject */, - ) /*: ElementDescriptor */ { - var kind = String(elementObject.kind); - if (kind !== "method" && kind !== "field") { - throw new TypeError( - 'An element descriptor\\'s .kind property must be either "method" or' + - ' "field", but a decorator created an element descriptor with' + - ' .kind "' + - kind + - '"', - ); + var g = _groups.get(re); + return Object.keys(g).reduce(function(groups, name) { + groups[name] = result[g[name]]; + return groups; + }, Object.create(null)); } - var key = elementObject.key; - if (typeof key !== "string" && typeof key !== "symbol") key = String(key); - - var placement = String(elementObject.placement); - if ( - placement !== "static" && - placement !== "prototype" && - placement !== "own" - ) { - throw new TypeError( - 'An element descriptor\\'s .placement property must be one of "static",' + - ' "prototype" or "own", but a decorator created an element descriptor' + - ' with .placement "' + - placement + - '"', - ); - } - - var descriptor /*: PropertyDescriptor */ = elementObject.descriptor; - - _disallowProperty(elementObject, "elements", "An element descriptor"); - - var element /*: ElementDescriptor */ = { - kind: kind, - key: key, - placement: placement, - descriptor: Object.assign({}, descriptor), - }; - - if (kind !== "field") { - _disallowProperty(elementObject, "initializer", "A method descriptor"); - } else { - _disallowProperty( - descriptor, - "get", - "The property descriptor of a field descriptor", - ); - _disallowProperty( - descriptor, - "set", - "The property descriptor of a field descriptor", - ); - _disallowProperty( - descriptor, - "value", - "The property descriptor of a field descriptor", - ); - - element.initializer = elementObject.initializer; - } - - return element; - } - - function _toElementFinisherExtras( - elementObject /*: ElementObject */, - ) /*: ElementFinisherExtras */ { - var element /*: ElementDescriptor */ = _toElementDescriptor(elementObject); - var finisher /*: ClassFinisher */ = _optionalCallableProperty( - elementObject, - "finisher", - ); - var extras /*: ElementDescriptors[] */ = _toElementDescriptors( - elementObject.extras, - ); - - return { element: element, finisher: finisher, extras: extras }; - } - - // FromClassDescriptor - function _fromClassDescriptor( - elements /*: ElementDescriptor[] */, - ) /*: ClassObject */ { - var obj = { - kind: "class", - elements: elements.map(_fromElementDescriptor), - }; - - var desc = { value: "Descriptor", configurable: true }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - - return obj; - } - - // ToClassDescriptor - function _toClassDescriptor(obj /*: ClassObject */) /*: ElementsFinisher */ { - var kind = String(obj.kind); - if (kind !== "class") { - throw new TypeError( - 'A class descriptor\\'s .kind property must be "class", but a decorator' + - ' created a class descriptor with .kind "' + - kind + - '"', - ); - } - - _disallowProperty(obj, "key", "A class descriptor"); - _disallowProperty(obj, "placement", "A class descriptor"); - _disallowProperty(obj, "descriptor", "A class descriptor"); - _disallowProperty(obj, "initializer", "A class descriptor"); - _disallowProperty(obj, "extras", "A class descriptor"); - - var finisher = _optionalCallableProperty(obj, "finisher"); - var elements = _toElementDescriptors(obj.elements); - - return { elements: elements, finisher: finisher }; + return _wrapRegExp.apply(this, arguments); } - - function _disallowProperty(obj, name, objectType) { - if (obj[name] !== undefined) { - throw new TypeError(objectType + " can't have a ." + name + " property."); - } - } - - function _optionalCallableProperty /*::*/( - obj /*: T */, - name /*: $Keys */, - ) /*: ?Function */ { - var value = obj[name]; - if (value !== undefined && typeof value !== "function") { - throw new TypeError("Expected '" + name + "' to be a function"); - } - return value; - } - - // RunClassFinishers - function _runClassFinishers( - constructor /*: Class<*> */, - finishers /*: ClassFinisher[] */, - ) /*: Class<*> */ { - for (var i = 0; i < finishers.length; i++) { - var newConstructor /*: ?Class<*> */ = (0, finishers[i])(constructor); - if (newConstructor !== undefined) { - // NOTE: This should check if IsConstructor(newConstructor) is false. - if (typeof newConstructor !== "function") { - throw new TypeError("Finishers must return a constructor."); - } - constructor = newConstructor; - } - } - return constructor; - } - `; +`; diff --git a/packages/babel-helpers/src/index.js b/packages/babel-helpers/src/index.js index 86465941a063..9dc87ce58916 100644 --- a/packages/babel-helpers/src/index.js +++ b/packages/babel-helpers/src/index.js @@ -280,6 +280,10 @@ export function getDependencies(name: string): $ReadOnlyArray { return Array.from(loadHelper(name).dependencies.values()); } +export function ensure(name: string) { + loadHelper(name); +} + export const list = Object.keys(helpers) .map(name => name.replace(/^_/, "")) .filter(name => name !== "__esModule"); diff --git a/packages/babel-highlight/package.json b/packages/babel-highlight/package.json index 0312b1aeae93..66fcb3c2db0f 100644 --- a/packages/babel-highlight/package.json +++ b/packages/babel-highlight/package.json @@ -1,6 +1,6 @@ { "name": "@babel/highlight", - "version": "7.0.0", + "version": "7.5.0", "description": "Syntax highlight JavaScript strings for output in terminals.", "author": "suchipi ", "homepage": "https://babeljs.io/", diff --git a/packages/babel-highlight/test/index.js b/packages/babel-highlight/test/index.js index 2aeab67a9b3a..a33f79fd5041 100644 --- a/packages/babel-highlight/test/index.js +++ b/packages/babel-highlight/test/index.js @@ -94,8 +94,8 @@ describe("@babel/highlight", function() { }); }); - describe("when colors are supported", function() { - stubColorSupport(true); + describe("when colors are not supported", function() { + stubColorSupport(false); describe("when forceColor is not passed", function() { it("returns a Chalk instance", function() { diff --git a/packages/babel-node/package.json b/packages/babel-node/package.json index 8ec75844217b..d613965164c4 100644 --- a/packages/babel-node/package.json +++ b/packages/babel-node/package.json @@ -1,6 +1,6 @@ { "name": "@babel/node", - "version": "7.0.0", + "version": "7.5.5", "description": "Babel command line", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -20,19 +20,20 @@ ], "dependencies": { "@babel/polyfill": "^7.0.0", - "@babel/register": "^7.0.0", + "@babel/register": "^7.5.5", "commander": "^2.8.1", - "fs-readdir-recursive": "^1.0.0", - "lodash": "^4.17.10", - "output-file-sync": "^2.0.0", + "lodash": "^4.17.13", + "node-environment-flags": "^1.0.5", "v8flags": "^3.1.1" }, "peerDependencies": { "@babel/core": "^7.0.0-0" }, "devDependencies": { - "@babel/core": "^7.0.0", - "@babel/helper-fixtures": "^7.0.0" + "@babel/core": "^7.5.5", + "@babel/helper-fixtures": "^7.5.5", + "fs-readdir-recursive": "^1.0.0", + "output-file-sync": "^2.0.0" }, "bin": { "babel-node": "./bin/babel-node.js" diff --git a/packages/babel-node/src/_babel-node.js b/packages/babel-node/src/_babel-node.js index 42ebf774d184..ff908a56e6d2 100644 --- a/packages/babel-node/src/_babel-node.js +++ b/packages/babel-node/src/_babel-node.js @@ -52,6 +52,11 @@ program.option( "The name of the 'env' to use when loading configs and plugins. " + "Defaults to the value of BABEL_ENV, or else NODE_ENV, or else 'development'.", ); +program.option( + "--root-mode [mode]", + "The project-root resolution mode. " + + "One of 'root' (the default), 'upward', or 'upward-optional'.", +); program.option("-w, --plugins [string]", "", collect); program.option("-b, --presets [string]", "", collect); @@ -59,7 +64,7 @@ program.version(pkg.version); program.usage("[options] [ -e script | script.js ] [arguments]"); program.parse(process.argv); -register({ +const babelOptions = { caller: { name: "@babel/node", }, @@ -70,12 +75,21 @@ register({ presets: program.presets, configFile: program.configFile, envName: program.envName, + rootMode: program.rootMode, // Commander will default the "--no-" arguments to true, but we want to // leave them undefined so that @babel/core can handle the // default-assignment logic on its own. babelrc: program.babelrc === true ? undefined : program.babelrc, -}); +}; + +for (const key of Object.keys(babelOptions)) { + if (babelOptions[key] === undefined) { + delete babelOptions[key]; + } +} + +register(babelOptions); const replPlugin = ({ types: t }) => ({ visitor: { diff --git a/packages/babel-node/src/babel-node.js b/packages/babel-node/src/babel-node.js index 5c29c3d4dbce..d143e4f756b4 100755 --- a/packages/babel-node/src/babel-node.js +++ b/packages/babel-node/src/babel-node.js @@ -6,6 +6,10 @@ import getV8Flags from "v8flags"; import path from "path"; +// TODO: When support for node < 10.10 will be dropped, this package +// can be replaced with process.allowedNodeEnvironmentFlags +import allowedNodeEnvironmentFlags from "node-environment-flags"; + let args = [path.join(__dirname, "_babel-node")]; let babelArgs = process.argv.slice(2); @@ -24,7 +28,9 @@ if (argSeparator > -1) { * that only the flag is returned. */ function getNormalizedV8Flag(arg) { - const matches = arg.match(/--(.+)/); + // v8 uses the "no" prefix to negate boolean flags (e.g. --nolazy), + // but they are not listed by v8flags + const matches = arg.match(/--(?:no)?(.+)/); if (matches) { return `--${matches[1].replace(/-/g, "_")}`; @@ -33,51 +39,30 @@ function getNormalizedV8Flag(arg) { return arg; } +// These are aliases for node options defined by babel-node. +const aliases = new Map([["-d", "--debug"], ["-gc", "--expose-gc"]]); + getV8Flags(function(err, v8Flags) { - babelArgs.forEach(function(arg, index) { + for (let i = 0; i < babelArgs.length; i++) { + const arg = babelArgs[i]; const flag = arg.split("=")[0]; - switch (flag) { - case "-d": - args.unshift("--debug"); - break; - - case "debug": - case "--debug": - case "--debug-brk": - case "--inspect": - case "--inspect-brk": - case "--experimental-modules": - args.unshift(arg); - break; - - case "-r": - case "--require": - args.push(flag); - args.push(babelArgs[index + 1]); - delete babelArgs[index + 1]; - break; - - case "-gc": - args.unshift("--expose-gc"); - break; - - case "--nolazy": - args.unshift(flag); - break; - - default: - if ( - v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 || - arg.indexOf("--trace") === 0 - ) { - args.unshift(arg); - } else { - args.push(arg); - } - break; + if (flag === "-r" || flag === "--require") { + args.push(flag); + args.push(babelArgs[++i]); + } else if (aliases.has(flag)) { + args.unshift(aliases.get(flag)); + } else if ( + flag === "debug" || // node debug foo.js + flag === "inspect" || + v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 || + allowedNodeEnvironmentFlags.has(flag) + ) { + args.unshift(arg); + } else { + args.push(arg); } - }); + } // append arguments passed after -- if (argSeparator > -1) { @@ -88,7 +73,12 @@ getV8Flags(function(err, v8Flags) { const kexec = require("kexec"); kexec(process.argv[0], args); } catch (err) { - if (err.code !== "MODULE_NOT_FOUND") throw err; + if ( + err.code !== "MODULE_NOT_FOUND" && + err.code !== "UNDECLARED_DEPENDENCY" + ) { + throw err; + } const child_process = require("child_process"); const proc = child_process.spawn(process.argv[0], args, { diff --git a/packages/babel-node/test/fixtures/babel-node/node_--inspect/options.json b/packages/babel-node/test/fixtures/babel-node/node_--inspect/options.json new file mode 100644 index 000000000000..68134a010bd7 --- /dev/null +++ b/packages/babel-node/test/fixtures/babel-node/node_--inspect/options.json @@ -0,0 +1,6 @@ +{ + "args": ["--inspect", "--eval", "console.log('foo');"], + "stderr": "Debugger listening on", + "stderrContains": true, + "stdout": "foo" +} diff --git a/packages/babel-node/test/fixtures/babel-node/node_--no-lazy/options.json b/packages/babel-node/test/fixtures/babel-node/node_--no-lazy/options.json new file mode 100644 index 000000000000..e993aa117b2b --- /dev/null +++ b/packages/babel-node/test/fixtures/babel-node/node_--no-lazy/options.json @@ -0,0 +1,4 @@ +{ + "args": ["--nolazy", "--eval", "console.log('foo')"], + "stdout": "foo" +} diff --git a/packages/babel-node/test/fixtures/babel-node/node_-gc_alias_--expose-gc/options.json b/packages/babel-node/test/fixtures/babel-node/node_-gc_alias_--expose-gc/options.json new file mode 100644 index 000000000000..1496c8ff8e20 --- /dev/null +++ b/packages/babel-node/test/fixtures/babel-node/node_-gc_alias_--expose-gc/options.json @@ -0,0 +1,4 @@ +{ + "args": ["-gc", "--eval", "console.log(typeof global.gc)"], + "stdout": "function" +} diff --git a/packages/babel-parser/CHANGELOG.md b/packages/babel-parser/CHANGELOG.md index cc96c3f7d128..6ddd17fb8800 100644 --- a/packages/babel-parser/CHANGELOG.md +++ b/packages/babel-parser/CHANGELOG.md @@ -178,7 +178,7 @@ The returned AST will only consist of the expression. The options are the same a Add startLine option ([#346](https://github.com/babel/babylon/pull/346)) (Raphael Mu) -A new option was added to babylon allowing to change the intial linenumber for the first line which is usually `1`. +A new option was added to babylon allowing to change the initial linenumber for the first line which is usually `1`. Changing this for example to `100` will make line `1` of the input source to be marked as line `100`, line `2` as `101`, line `3` as `102`, ... Function predicate declaration ([#103](https://github.com/babel/babylon/pull/103)) (Panagiotis Vekris) @@ -224,7 +224,7 @@ import { a as debugger } from "foo"; Do not allow overwritting of primitive types ([#314](https://github.com/babel/babylon/pull/314)) (Daniel Tschinder) -In flow it is now forbidden to overwrite the primitve types `"any"`, `"mixed"`, `"empty"`, `"bool"`, `"boolean"`, `"number"`, `"string"`, `"void"` and `"null"` with your own type declaration. +In flow it is now forbidden to overwrite the primitive types `"any"`, `"mixed"`, `"empty"`, `"bool"`, `"boolean"`, `"number"`, `"string"`, `"void"` and `"null"` with your own type declaration. Disallow import type { type a } from … ([#305](https://github.com/babel/babylon/pull/305)) (Daniel Tschinder) @@ -628,7 +628,7 @@ Annotate more errors with expected token ([#172](https://github.com/babel/babylo Remove kcheck ([#173](https://github.com/babel/babylon/pull/173))) (Daniel Tschinder) -Also run flow, linting, babel tests on seperate instances (add back node 0.10) +Also run flow, linting, babel tests on separate instances (add back node 0.10) ## v6.11.6 (2016-10-12) diff --git a/packages/babel-parser/README.md b/packages/babel-parser/README.md index 9e140cc08185..65092a05347e 100644 --- a/packages/babel-parser/README.md +++ b/packages/babel-parser/README.md @@ -2,7 +2,7 @@ > A JavaScript parser -See our website [@babel/parser](https://babeljs.io/docs/en/next/babel-parser.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20babylon%22+is%3Aopen) associated with this package. +See our website [@babel/parser](https://babeljs.io/docs/en/next/babel-parser.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A+parser+%28babylon%29%22+is%3Aopen) associated with this package. ## Install diff --git a/packages/babel-parser/ast/spec.md b/packages/babel-parser/ast/spec.md index e8b5120b135d..d1b1a51ca733 100644 --- a/packages/babel-parser/ast/spec.md +++ b/packages/babel-parser/ast/spec.md @@ -72,12 +72,14 @@ These are the core @babel/parser (babylon) AST node types. - [LogicalExpression](#logicalexpression) - [LogicalOperator](#logicaloperator) - [SpreadElement](#spreadelement) + - [ArgumentPlaceholder](#argumentplaceholder) - [MemberExpression](#memberexpression) - [BindExpression](#bindexpression) - [ConditionalExpression](#conditionalexpression) - [CallExpression](#callexpression) - [NewExpression](#newexpression) - [SequenceExpression](#sequenceexpression) + - [ParenthesizedExpression](#parenthesizedexpression) - [DoExpression](#doexpression) - [Template Literals](#template-literals) - [TemplateLiteral](#templateliteral) @@ -862,6 +864,14 @@ interface SpreadElement <: Node { } ``` +### ArgumentPlaceholder + +```js +interface ArgumentPlaceholder <: Node { + type: "ArgumentPlaceholder"; +} +``` + ### MemberExpression ```js @@ -888,6 +898,54 @@ interface BindExpression <: Expression { If `object` is `null`, then `callee` should be a `MemberExpression`. +### Pipeline + +These nodes are used by the Smart Pipeline to determine the type of the expression in a Pipeline Operator Expression. The F# Pipeline uses simple `BinaryExpression`s. + +#### PipelineBody + +```js +interface PipelineBody <: NodeBase { + type: "PipelineBody"; +} +``` + +#### PipelineBareFunctionBody + +```js +interface PipelineBody <: NodeBase { + type: "PipelineBareFunctionBody"; + callee: Expression; +} +``` + +#### PipelineBareConstructorBody + +```js +interface PipelineBareConstructorBody <: NodeBase { + type: "PipelineBareConstructorBody"; + callee: Expression; +} +``` + +#### PipelineBareAwaitedFunctionBody + +```js +interface PipelineBareConstructorBody <: NodeBase { + type: "PipelineTopicBody"; + expression: Expression; +} +``` + +#### PipelineTopicBody + +```js +interface PipelineBareConstructorBody <: NodeBase { + type: "PipelineBareAwaitedFunctionBody"; + callee: Expression; +} +``` + ## ConditionalExpression ```js @@ -936,6 +994,17 @@ interface SequenceExpression <: Expression { A sequence expression, i.e., a comma-separated sequence of expressions. +## ParenthesizedExpression + +```js +interface ParenthesizedExpression <: Expression { + type "ParenthesizedExpression"; + expression: Expression; +} +``` + +An expression wrapped by parentheses. + ## DoExpression ```js @@ -1149,6 +1218,7 @@ A specifier in an import or export declaration. ```js interface ImportDeclaration <: ModuleDeclaration { type: "ImportDeclaration"; + importKind: null | "type" | "typeof" | "value"; specifiers: [ ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier ]; source: Literal; } @@ -1156,6 +1226,8 @@ interface ImportDeclaration <: ModuleDeclaration { An import declaration, e.g., `import foo from "mod";`. +> importKind is only set when `flow` plugin enabled in babel-parser + ### ImportSpecifier ```js diff --git a/packages/babel-parser/package.json b/packages/babel-parser/package.json index 2f0652c1f24e..5fa40c1ff68c 100644 --- a/packages/babel-parser/package.json +++ b/packages/babel-parser/package.json @@ -1,6 +1,6 @@ { "name": "@babel/parser", - "version": "7.1.0", + "version": "7.5.5", "description": "A JavaScript parser", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -28,9 +28,10 @@ "node": ">=6.0.0" }, "devDependencies": { - "@babel/helper-fixtures": "^7.0.0", - "charcodes": "0.1.0", - "unicode-11.0.0": "^0.7.7" + "@babel/code-frame": "^7.5.5", + "@babel/helper-fixtures": "^7.5.5", + "charcodes": "^0.2.0", + "unicode-12.0.0": "^0.7.9" }, "bin": { "parser": "./bin/babel-parser.js" diff --git a/packages/babel-parser/scripts/generate-identifier-regex.js b/packages/babel-parser/scripts/generate-identifier-regex.js index c0c53de64e35..21e249ad4f28 100644 --- a/packages/babel-parser/scripts/generate-identifier-regex.js +++ b/packages/babel-parser/scripts/generate-identifier-regex.js @@ -1,7 +1,8 @@ "use strict"; -// Which Unicode version should be used? -const version = "11.0.0"; +// Always use the latest available version of Unicode! +// https://tc39.github.io/ecma262/#sec-conformance +const version = "12.0.0"; const start = require("unicode-" + version + @@ -60,11 +61,15 @@ function generate(chars) { const startData = generate(start); const contData = generate(cont); +console.log("/* prettier-ignore */"); console.log('let nonASCIIidentifierStartChars = "' + startData.nonASCII + '";'); +console.log("/* prettier-ignore */"); console.log('let nonASCIIidentifierChars = "' + contData.nonASCII + '";'); +console.log("/* prettier-ignore */"); console.log( "const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";" ); +console.log("/* prettier-ignore */"); console.log( "const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";" ); diff --git a/packages/babel-parser/src/options.js b/packages/babel-parser/src/options.js index 3bab7c04a287..8b030847f970 100755 --- a/packages/babel-parser/src/options.js +++ b/packages/babel-parser/src/options.js @@ -15,10 +15,12 @@ export type Options = { allowReturnOutsideFunction: boolean, allowImportExportEverywhere: boolean, allowSuperOutsideMethod: boolean, + allowUndeclaredExports: boolean, plugins: PluginList, strictMode: ?boolean, ranges: boolean, tokens: boolean, + createParenthesizedExpressions: boolean, }; export const defaultOptions: Options = { @@ -40,6 +42,8 @@ export const defaultOptions: Options = { allowImportExportEverywhere: false, // TODO allowSuperOutsideMethod: false, + // When enabled, export statements can reference undeclared variables. + allowUndeclaredExports: false, // An array of plugins to enable plugins: [], // TODO @@ -55,13 +59,16 @@ export const defaultOptions: Options = { ranges: false, // Adds all parsed tokens to a `tokens` property on the `File` node tokens: false, + // Whether to create ParenthesizedExpression AST nodes (if false + // the parser sets extra.parenthesized on the expression nodes instead). + createParenthesizedExpressions: false, }; // Interpret and default an options object export function getOptions(opts: ?Options): Options { const options: any = {}; - for (const key in defaultOptions) { + for (const key of Object.keys(defaultOptions)) { options[key] = opts && opts[key] != null ? opts[key] : defaultOptions[key]; } return options; diff --git a/packages/babel-parser/src/parser/base.js b/packages/babel-parser/src/parser/base.js index 7c84857752fb..1e451794158c 100644 --- a/packages/babel-parser/src/parser/base.js +++ b/packages/babel-parser/src/parser/base.js @@ -1,36 +1,32 @@ // @flow import type { Options } from "../options"; -import { reservedWords } from "../util/identifier"; - import type State from "../tokenizer/state"; import type { PluginsMap } from "./index"; +import type ScopeHandler from "../util/scope"; export default class BaseParser { // Properties set by constructor in index.js options: Options; inModule: boolean; + scope: ScopeHandler<*>; plugins: PluginsMap; filename: ?string; sawUnambiguousESM: boolean = false; // Initialized by Tokenizer state: State; + // input and length are not in state as they are constant and we do + // not want to ever copy them, which happens if state gets cloned input: string; - - isReservedWord(word: string): boolean { - if (word === "await") { - return this.inModule; - } else { - return reservedWords[6](word); - } - } + length: number; hasPlugin(name: string): boolean { - return Object.hasOwnProperty.call(this.plugins, name); + return this.plugins.has(name); } getPluginOption(plugin: string, name: string) { - if (this.hasPlugin(plugin)) return this.plugins[plugin][name]; + // $FlowIssue + if (this.hasPlugin(plugin)) return this.plugins.get(plugin)[name]; } } diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 48dd82d67347..9b48c7129e2f 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -21,12 +21,37 @@ import { types as tt, type TokenType } from "../tokenizer/types"; import * as N from "../types"; import LValParser from "./lval"; -import { reservedWords } from "../util/identifier"; +import { + isKeyword, + isReservedWord, + isStrictReservedWord, + isStrictBindReservedWord, +} from "../util/identifier"; import type { Pos, Position } from "../util/location"; +import * as charCodes from "charcodes"; +import { + BIND_OUTSIDE, + BIND_VAR, + functionFlags, + SCOPE_ARROW, + SCOPE_CLASS, + SCOPE_DIRECT_SUPER, + SCOPE_SUPER, + SCOPE_PROGRAM, +} from "../util/scopeflags"; + +const unwrapParenthesizedExpression = node => { + return node.type === "ParenthesizedExpression" + ? unwrapParenthesizedExpression(node.expression) + : node; +}; export default class ExpressionParser extends LValParser { // Forward-declaration: defined in statement.js - +parseBlock: (allowDirectives?: boolean) => N.BlockStatement; + +parseBlock: ( + allowDirectives?: boolean, + createNewLexicalScope?: boolean, + ) => N.BlockStatement; +parseClass: ( node: N.Class, isStatement: boolean, @@ -35,10 +60,9 @@ export default class ExpressionParser extends LValParser { +parseDecorators: (allowExport?: boolean) => void; +parseFunction: ( node: T, - isStatement: boolean, + statement?: number, allowExpressionBody?: boolean, isAsync?: boolean, - optionalId?: boolean, ) => T; +parseFunctionParams: (node: N.Function, allowModifiers?: boolean) => void; +takeDecorators: (node: N.HasDecorators) => void; @@ -49,10 +73,18 @@ export default class ExpressionParser extends LValParser { // strict mode, init properties are also not allowed to be repeated. checkPropClash( - prop: N.ObjectMember, + prop: N.ObjectMember | N.SpreadElement, propHash: { [key: string]: boolean }, ): void { - if (prop.computed || prop.kind) return; + if ( + prop.type === "SpreadElement" || + prop.computed || + prop.kind || + // $FlowIgnore + prop.shorthand + ) { + return; + } const key = prop.key; // It is either an Identifier or a String/NumericLiteral @@ -68,6 +100,7 @@ export default class ExpressionParser extends LValParser { // Convenience method to parse an Expression only getExpression(): N.Expression { + this.scope.enter(SCOPE_PROGRAM); this.nextToken(); const expr = this.parseExpression(); if (!this.match(tt.eof)) { @@ -121,14 +154,23 @@ export default class ExpressionParser extends LValParser { ): N.Expression { const startPos = this.state.start; const startLoc = this.state.startLoc; - if (this.match(tt._yield) && this.state.inGenerator) { - let left = this.parseYield(); - if (afterLeftParse) { - left = afterLeftParse.call(this, left, startPos, startLoc); + if (this.isContextual("yield")) { + if (this.scope.inGenerator) { + let left = this.parseYield(noIn); + if (afterLeftParse) { + left = afterLeftParse.call(this, left, startPos, startLoc); + } + return left; + } else { + // The tokenizer will assume an expression is allowed after + // `yield`, but this isn't that kind of yield + this.state.exprAllowed = false; } - return left; } + const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; + this.state.commaAfterSpreadAt = -1; + let failOnShorthandAssign; if (refShorthandDefaultPos) { failOnShorthandAssign = false; @@ -137,7 +179,7 @@ export default class ExpressionParser extends LValParser { failOnShorthandAssign = true; } - if (this.match(tt.parenL) || this.match(tt.name) || this.match(tt._yield)) { + if (this.match(tt.parenL) || this.match(tt.name)) { this.state.potentialArrowAt = this.state.start; } @@ -168,21 +210,29 @@ export default class ExpressionParser extends LValParser { this.checkLVal(left, undefined, undefined, "assignment expression"); - if (left.extra && left.extra.parenthesized) { - let errorMsg; - if (left.type === "ObjectPattern") { - errorMsg = "`({a}) = 0` use `({a} = 0)`"; - } else if (left.type === "ArrayPattern") { - errorMsg = "`([a]) = 0` use `([a] = 0)`"; - } - if (errorMsg) { - this.raise( - left.start, - `You're trying to assign to a parenthesized expression, eg. instead of ${errorMsg}`, - ); - } + const maybePattern = unwrapParenthesizedExpression(left); + + let patternErrorMsg; + if (maybePattern.type === "ObjectPattern") { + patternErrorMsg = "`({a}) = 0` use `({a} = 0)`"; + } else if (maybePattern.type === "ArrayPattern") { + patternErrorMsg = "`([a]) = 0` use `([a] = 0)`"; } + if ( + patternErrorMsg && + ((left.extra && left.extra.parenthesized) || + left.type === "ParenthesizedExpression") + ) { + this.raise( + maybePattern.start, + `You're trying to assign to a parenthesized expression, eg. instead of ${patternErrorMsg}`, + ); + } + + if (patternErrorMsg) this.checkCommaAfterRestFromSpread(); + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + this.next(); node.right = this.parseMaybeAssign(noIn); return this.finishNode(node, "AssignmentExpression"); @@ -190,6 +240,8 @@ export default class ExpressionParser extends LValParser { this.unexpected(refShorthandDefaultPos.start); } + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + return left; } @@ -279,15 +331,18 @@ export default class ExpressionParser extends LValParser { const prec = this.state.type.binop; if (prec != null && (!noIn || !this.match(tt._in))) { if (prec > minPrec) { - const node = this.startNodeAt(leftStartPos, leftStartLoc); const operator = this.state.value; + if (operator === "|>" && this.state.inFSharpPipelineDirectBody) { + return left; + } + const node = this.startNodeAt(leftStartPos, leftStartLoc); node.left = left; node.operator = operator; - if ( operator === "**" && left.type === "UnaryExpression" && - !(left.extra && left.extra.parenthesized) + (this.options.createParenthesizedExpressions || + !(left.extra && left.extra.parenthesized)) ) { this.raise( left.argument.start, @@ -296,22 +351,25 @@ export default class ExpressionParser extends LValParser { } const op = this.state.type; - if (op === tt.nullishCoalescing) { - this.expectPlugin("nullishCoalescingOperator"); - } else if (op === tt.pipeline) { + + if (op === tt.pipeline) { this.expectPlugin("pipelineOperator"); + this.state.inPipeline = true; + this.checkPipelineAtInfixOperator(left, leftStartPos); + } else if (op === tt.nullishCoalescing) { + this.expectPlugin("nullishCoalescingOperator"); } this.next(); - const startPos = this.state.start; - const startLoc = this.state.startLoc; - - if (op === tt.pipeline) { + if ( + op === tt.pipeline && + this.getPluginOption("pipelineOperator", "proposal") === "minimal" + ) { if ( this.match(tt.name) && this.state.value === "await" && - this.state.inAsync + this.scope.inAsync ) { throw this.raise( this.state.start, @@ -320,22 +378,17 @@ export default class ExpressionParser extends LValParser { } } - node.right = this.parseExprOp( - this.parseMaybeUnary(), - startPos, - startLoc, - op.rightAssociative ? prec - 1 : prec, - noIn, - ); + node.right = this.parseExprOpRightExpr(op, prec, noIn); this.finishNode( node, op === tt.logicalOR || - op === tt.logicalAND || - op === tt.nullishCoalescing + op === tt.logicalAND || + op === tt.nullishCoalescing ? "LogicalExpression" : "BinaryExpression", ); + return this.parseExprOp( node, leftStartPos, @@ -348,10 +401,69 @@ export default class ExpressionParser extends LValParser { return left; } + // Helper function for `parseExprOp`. Parse the right-hand side of binary- + // operator expressions, then apply any operator-specific functions. + + parseExprOpRightExpr( + op: TokenType, + prec: number, + noIn: ?boolean, + ): N.Expression { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + switch (op) { + case tt.pipeline: + switch (this.getPluginOption("pipelineOperator", "proposal")) { + case "smart": + return this.withTopicPermittingContext(() => { + return this.parseSmartPipelineBody( + this.parseExprOpBaseRightExpr(op, prec, noIn), + startPos, + startLoc, + ); + }); + case "fsharp": + return this.withSoloAwaitPermittingContext(() => { + return this.parseFSharpPipelineBody(prec, noIn); + }); + } + // falls through + + default: + return this.parseExprOpBaseRightExpr(op, prec, noIn); + } + } + + // Helper function for `parseExprOpRightExpr`. Parse the right-hand side of + // binary-operator expressions without applying any operator-specific functions. + + parseExprOpBaseRightExpr( + op: TokenType, + prec: number, + noIn: ?boolean, + ): N.Expression { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + + return this.parseExprOp( + this.parseMaybeUnary(), + startPos, + startLoc, + op.rightAssociative ? prec - 1 : prec, + noIn, + ); + } + // Parse unary operators, both prefix and postfix. parseMaybeUnary(refShorthandDefaultPos: ?Pos): N.Expression { - if (this.state.type.prefix) { + if ( + this.isContextual("await") && + (this.scope.inAsync || + (!this.scope.inFunction && this.options.allowAwaitOutsideFunction)) + ) { + return this.parseAwait(); + } else if (this.state.type.prefix) { const node = this.startNode(); const update = this.match(tt.incDec); node.operator = this.state.value; @@ -433,12 +545,21 @@ export default class ExpressionParser extends LValParser { startLoc: Position, noCalls?: ?boolean, ): N.Expression { + const maybeAsyncArrow = this.atPossibleAsync(base); + const state = { optionalChainMember: false, stop: false, }; do { - base = this.parseSubscript(base, startPos, startLoc, noCalls, state); + base = this.parseSubscript( + base, + startPos, + startLoc, + noCalls, + state, + maybeAsyncArrow, + ); } while (!state.stop); return base; } @@ -453,6 +574,7 @@ export default class ExpressionParser extends LValParser { startLoc: Position, noCalls: ?boolean, state: N.ParseSubscriptState, + maybeAsyncArrow: boolean, ): N.Expression { if (!noCalls && this.eat(tt.doubleColon)) { const node = this.startNodeAt(startPos, startLoc); @@ -468,7 +590,7 @@ export default class ExpressionParser extends LValParser { } else if (this.match(tt.questionDot)) { this.expectPlugin("optionalChaining"); state.optionalChainMember = true; - if (noCalls && this.lookahead().type == tt.parenL) { + if (noCalls && this.lookahead().type === tt.parenL) { state.stop = true; return base; } @@ -484,13 +606,8 @@ export default class ExpressionParser extends LValParser { this.expect(tt.bracketR); return this.finishNode(node, "OptionalMemberExpression"); } else if (this.eat(tt.parenL)) { - const possibleAsync = this.atPossibleAsync(base); - node.callee = base; - node.arguments = this.parseCallExpressionArguments( - tt.parenR, - possibleAsync, - ); + node.arguments = this.parseCallExpressionArguments(tt.parenR, false); node.optional = true; return this.finishNode(node, "OptionalCallExpression"); } else { @@ -522,21 +639,26 @@ export default class ExpressionParser extends LValParser { } return this.finishNode(node, "MemberExpression"); } else if (!noCalls && this.match(tt.parenL)) { - const possibleAsync = this.atPossibleAsync(base); + const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.maybeInArrowParameters = true; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.next(); - const node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.callee = base; - // TODO: Clean up/merge this into `this.state` or a class like acorn's - // `DestructuringErrors` alongside refShorthandDefaultPos and - // refNeedsArrowPos. - const refTrailingCommaPos: Pos = { start: -1 }; + const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; + this.state.commaAfterSpreadAt = -1; node.arguments = this.parseCallExpressionArguments( tt.parenR, - possibleAsync, - refTrailingCommaPos, + maybeAsyncArrow, + base.type === "Import", + base.type !== "Super", ); if (!state.optionalChainMember) { this.finishCallExpression(node); @@ -544,23 +666,30 @@ export default class ExpressionParser extends LValParser { this.finishOptionalCallExpression(node); } - if (possibleAsync && this.shouldParseAsyncArrow()) { + if (maybeAsyncArrow && this.shouldParseAsyncArrow()) { state.stop = true; - if (refTrailingCommaPos.start > -1) { - this.raise( - refTrailingCommaPos.start, - "A trailing comma is not permitted after the rest element", - ); - } + this.checkCommaAfterRestFromSpread(); - return this.parseAsyncArrowFromCallExpression( + node = this.parseAsyncArrowFromCallExpression( this.startNodeAt(startPos, startLoc), node, ); + this.checkYieldAwaitInDefaultParams(); + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; } else { - this.toReferencedList(node.arguments); + this.toReferencedListDeep(node.arguments); + + // We keep the old value if it isn't null, for cases like + // (x = async(yield)) => {} + this.state.yieldPos = oldYieldPos || this.state.yieldPos; + this.state.awaitPos = oldAwaitPos || this.state.awaitPos; } + + this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.commaAfterSpreadAt = oldCommaAfterSpreadAt; + return node; } else if (this.match(tt.backQuote)) { return this.parseTaggedTemplateExpression( @@ -600,11 +729,11 @@ export default class ExpressionParser extends LValParser { atPossibleAsync(base: N.Expression): boolean { return ( - !this.state.containsEsc && - this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && - !this.canInsertSemicolon() + this.state.lastTokEnd === base.end && + !this.canInsertSemicolon() && + this.input.slice(base.start, base.end) === "async" ); } @@ -639,18 +768,29 @@ export default class ExpressionParser extends LValParser { parseCallExpressionArguments( close: TokenType, possibleAsyncArrow: boolean, - refTrailingCommaPos?: Pos, + dynamicImport?: boolean, + allowPlaceholder?: boolean, ): $ReadOnlyArray { const elts = []; let innerParenStart; let first = true; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; while (!this.eat(close)) { if (first) { first = false; } else { this.expect(tt.comma); - if (this.eat(close)) break; + if (this.eat(close)) { + if (dynamicImport) { + this.raise( + this.state.lastTokStart, + "Trailing comma is disallowed inside import(...) arguments", + ); + } + break; + } } // we need to make sure that if this is an async arrow functions, @@ -664,7 +804,7 @@ export default class ExpressionParser extends LValParser { false, possibleAsyncArrow ? { start: 0 } : undefined, possibleAsyncArrow ? { start: 0 } : undefined, - possibleAsyncArrow ? refTrailingCommaPos : undefined, + allowPlaceholder, ), ); } @@ -674,22 +814,21 @@ export default class ExpressionParser extends LValParser { this.unexpected(); } + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + return elts; } shouldParseAsyncArrow(): boolean { - return this.match(tt.arrow); + return this.match(tt.arrow) && !this.canInsertSemicolon(); } parseAsyncArrowFromCallExpression( node: N.ArrowFunctionExpression, call: N.CallExpression, ): N.ArrowFunctionExpression { - const oldYield = this.state.yieldInPossibleArrowParameters; - this.state.yieldInPossibleArrowParameters = null; this.expect(tt.arrow); this.parseArrowExpression(node, call.arguments, true); - this.state.yieldInPossibleArrowParameters = oldYield; return node; } @@ -707,16 +846,16 @@ export default class ExpressionParser extends LValParser { // or `{}`. parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression { + // If a division operator appears in an expression position, the + // tokenizer got confused, and we force it to read a regexp instead. + if (this.state.type === tt.slash) this.readRegexp(); + const canBeArrow = this.state.potentialArrowAt === this.state.start; let node; switch (this.state.type) { case tt._super: - if ( - !this.state.inMethod && - !this.state.inClassProperty && - !this.options.allowSuperOutsideMethod - ) { + if (!this.scope.allowSuper && !this.options.allowSuperOutsideMethod) { this.raise( this.state.start, "super is only allowed in object methods and classes", @@ -725,91 +864,77 @@ export default class ExpressionParser extends LValParser { node = this.startNode(); this.next(); - if ( - !this.match(tt.parenL) && - !this.match(tt.bracketL) && - !this.match(tt.dot) - ) { - this.unexpected(); - } if ( this.match(tt.parenL) && - this.state.inMethod !== "constructor" && + !this.scope.allowDirectSuper && !this.options.allowSuperOutsideMethod ) { this.raise( node.start, - "super() is only valid inside a class constructor. " + - "Make sure the method name is spelled exactly as 'constructor'.", + "super() is only valid inside a class constructor of a subclass. " + + "Maybe a typo in the method name ('constructor') or not extending another class?", ); } - return this.finishNode(node, "Super"); - case tt._import: - if (this.lookahead().type === tt.dot) { - return this.parseImportMetaProperty(); + if ( + !this.match(tt.parenL) && + !this.match(tt.bracketL) && + !this.match(tt.dot) + ) { + this.unexpected(); } - this.expectPlugin("dynamicImport"); + return this.finishNode(node, "Super"); + case tt._import: node = this.startNode(); this.next(); + + if (this.match(tt.dot)) { + return this.parseImportMetaProperty(node); + } + + this.expectPlugin("dynamicImport", node.start); + if (!this.match(tt.parenL)) { this.unexpected(null, tt.parenL); } return this.finishNode(node, "Import"); - case tt._this: node = this.startNode(); this.next(); return this.finishNode(node, "ThisExpression"); - case tt._yield: - if (this.state.inGenerator) this.unexpected(); - case tt.name: { node = this.startNode(); - const allowAwait = - this.state.value === "await" && - (this.state.inAsync || - (!this.state.inFunction && this.options.allowAwaitOutsideFunction)); - const containsEsc = this.state.containsEsc; - const allowYield = this.shouldAllowYieldIdentifier(); - const id = this.parseIdentifier(allowAwait || allowYield); + const id = this.parseIdentifier(); - if (id.name === "await") { - if ( - this.state.inAsync || - this.inModule || - (!this.state.inFunction && this.options.allowAwaitOutsideFunction) - ) { - return this.parseAwait(node); - } - } else if ( + if ( !containsEsc && id.name === "async" && this.match(tt._function) && !this.canInsertSemicolon() ) { this.next(); - return this.parseFunction(node, false, false, true); - } else if (canBeArrow && id.name === "async" && this.match(tt.name)) { - const oldYield = this.state.yieldInPossibleArrowParameters; - this.state.yieldInPossibleArrowParameters = null; + return this.parseFunction(node, undefined, true); + } else if ( + canBeArrow && + !containsEsc && + id.name === "async" && + this.match(tt.name) && + !this.canInsertSemicolon() + ) { const params = [this.parseIdentifier()]; this.expect(tt.arrow); - // let foo = bar => {}; + // let foo = async bar => {}; this.parseArrowExpression(node, params, true); - this.state.yieldInPossibleArrowParameters = oldYield; return node; } - if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { - const oldYield = this.state.yieldInPossibleArrowParameters; - this.state.yieldInPossibleArrowParameters = null; - this.parseArrowExpression(node, [id]); - this.state.yieldInPossibleArrowParameters = oldYield; + if (canBeArrow && this.match(tt.arrow) && !this.canInsertSemicolon()) { + this.next(); + this.parseArrowExpression(node, [id], false); return node; } @@ -820,12 +945,9 @@ export default class ExpressionParser extends LValParser { this.expectPlugin("doExpressions"); const node = this.startNode(); this.next(); - const oldInFunction = this.state.inFunction; const oldLabels = this.state.labels; this.state.labels = []; - this.state.inFunction = false; - node.body = this.parseBlock(false); - this.state.inFunction = oldInFunction; + node.body = this.parseBlock(); this.state.labels = oldLabels; return this.finishNode(node, "DoExpression"); } @@ -859,7 +981,10 @@ export default class ExpressionParser extends LValParser { case tt.parenL: return this.parseParenAndDistinguishExpression(canBeArrow); - case tt.bracketL: + case tt.bracketL: { + const oldInFSharpPipelineDirectBody = this.state + .inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; node = this.startNode(); this.next(); node.elements = this.parseExprList( @@ -867,12 +992,25 @@ export default class ExpressionParser extends LValParser { true, refShorthandDefaultPos, ); - this.toReferencedList(node.elements); + if (!this.state.maybeInArrowParameters) { + // This could be an array pattern: + // ([a: string, b: string]) => {} + // In this case, we don't have to call toReferencedList. We will + // call it, if needed, when we are sure that it is a parenthesized + // expression by calling toReferencedListDeep. + this.toReferencedList(node.elements); + } + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; return this.finishNode(node, "ArrayExpression"); - - case tt.braceL: - return this.parseObj(false, refShorthandDefaultPos); - + } + case tt.braceL: { + const oldInFSharpPipelineDirectBody = this.state + .inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = false; + const ret = this.parseObj(false, refShorthandDefaultPos); + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + return ret; + } case tt._function: return this.parseFunctionExpression(); @@ -905,6 +1043,32 @@ export default class ExpressionParser extends LValParser { } } + case tt.hash: { + if (this.state.inPipeline) { + node = this.startNode(); + + if ( + this.getPluginOption("pipelineOperator", "proposal") !== "smart" + ) { + this.raise( + node.start, + "Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option.", + ); + } + + this.next(); + if (this.primaryTopicReferenceIsAllowedInCurrentTopicContext()) { + this.registerTopicReference(); + return this.finishNode(node, "PipelinePrimaryTopicReference"); + } else { + throw this.raise( + node.start, + `Topic reference was used in a lexical context without topic binding`, + ); + } + } + } + default: throw this.unexpected(); } @@ -924,6 +1088,7 @@ export default class ExpressionParser extends LValParser { this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); const node = this.startNode(); this.next(); + this.assertNoSpace("Unexpected space between # and identifier"); node.id = this.parseIdentifier(true); return this.finishNode(node, "PrivateName"); } else { @@ -933,11 +1098,20 @@ export default class ExpressionParser extends LValParser { parseFunctionExpression(): N.FunctionExpression | N.MetaProperty { const node = this.startNode(); - const meta = this.parseIdentifier(true); - if (this.state.inGenerator && this.eat(tt.dot)) { + + // We do not do parseIdentifier here because when parseFunctionExpression + // is called we already know that the current token is a "name" with the value "function" + // This will improve perf a tiny little bit as we do not do validation but more importantly + // here is that parseIdentifier will remove an item from the expression stack + // if "function" or "class" is parsed as identifier (in objects e.g.), which should not happen here. + let meta = this.startNode(); + this.next(); + meta = this.createIdentifier(meta, "function"); + + if (this.scope.inGenerator && this.eat(tt.dot)) { return this.parseMetaProperty(node, meta, "sent"); } - return this.parseFunction(node, false); + return this.parseFunction(node); } parseMetaProperty( @@ -972,20 +1146,17 @@ export default class ExpressionParser extends LValParser { return this.finishNode(node, "MetaProperty"); } - parseImportMetaProperty(): N.MetaProperty { - const node = this.startNode(); - const id = this.parseIdentifier(true); + parseImportMetaProperty(node: N.MetaProperty): N.MetaProperty { + const id = this.createIdentifier(this.startNodeAtNode(node), "import"); this.expect(tt.dot); - if (id.name === "import") { - if (this.isContextual("meta")) { - this.expectPlugin("importMeta"); - } else if (!this.hasPlugin("importMeta")) { - this.raise( - id.start, - `Dynamic imports require a parameter: import('a.js')`, - ); - } + if (this.isContextual("meta")) { + this.expectPlugin("importMeta"); + } else if (!this.hasPlugin("importMeta")) { + this.raise( + id.start, + `Dynamic imports require a parameter: import('a.js')`, + ); } if (!this.inModule) { @@ -1017,13 +1188,6 @@ export default class ExpressionParser extends LValParser { return this.finishNode(node, type); } - parseParenExpression(): N.Expression { - this.expect(tt.parenL); - const val = this.parseExpression(); - this.expect(tt.parenR); - return val; - } - parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression { const startPos = this.state.start; const startLoc = this.state.startLoc; @@ -1032,9 +1196,13 @@ export default class ExpressionParser extends LValParser { this.expect(tt.parenL); const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; - const oldYield = this.state.yieldInPossibleArrowParameters; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; this.state.maybeInArrowParameters = true; - this.state.yieldInPossibleArrowParameters = null; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.state.inFSharpPipelineDirectBody = false; const innerStartPos = this.state.start; const innerStartLoc = this.state.startLoc; @@ -1062,18 +1230,13 @@ export default class ExpressionParser extends LValParser { spreadStart = this.state.start; exprList.push( this.parseParenItem( - this.parseRest(), + this.parseRestBinding(), spreadNodeStartPos, spreadNodeStartLoc, ), ); - if (this.match(tt.comma) && this.lookahead().type === tt.parenR) { - this.raise( - this.state.start, - "A trailing comma is not permitted after the rest element", - ); - } + this.checkCommaAfterRest(); break; } else { @@ -1093,6 +1256,7 @@ export default class ExpressionParser extends LValParser { this.expect(tt.parenR); this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; let arrowNode = this.startNodeAt(startPos, startLoc); if ( @@ -1100,18 +1264,23 @@ export default class ExpressionParser extends LValParser { this.shouldParseArrow() && (arrowNode = this.parseArrow(arrowNode)) ) { + this.checkYieldAwaitInDefaultParams(); + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; for (const param of exprList) { if (param.extra && param.extra.parenthesized) { this.unexpected(param.extra.parenStart); } } - this.parseArrowExpression(arrowNode, exprList); - this.state.yieldInPossibleArrowParameters = oldYield; + this.parseArrowExpression(arrowNode, exprList, false); return arrowNode; } - this.state.yieldInPossibleArrowParameters = oldYield; + // We keep the old value if it isn't null, for cases like + // (x = (yield)) => {} + this.state.yieldPos = oldYieldPos || this.state.yieldPos; + this.state.awaitPos = oldAwaitPos || this.state.awaitPos; if (!exprList.length) { this.unexpected(this.state.lastTokStart); @@ -1123,19 +1292,25 @@ export default class ExpressionParser extends LValParser { } if (refNeedsArrowPos.start) this.unexpected(refNeedsArrowPos.start); + this.toReferencedListDeep(exprList, /* isParenthesizedExpr */ true); if (exprList.length > 1) { val = this.startNodeAt(innerStartPos, innerStartLoc); val.expressions = exprList; - this.toReferencedList(val.expressions); this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); } else { val = exprList[0]; } - this.addExtra(val, "parenthesized", true); - this.addExtra(val, "parenStart", startPos); + if (!this.options.createParenthesizedExpressions) { + this.addExtra(val, "parenthesized", true); + this.addExtra(val, "parenStart", startPos); + return val; + } - return val; + const parenExpression = this.startNodeAt(startPos, startLoc); + parenExpression.expression = val; + this.finishNode(parenExpression, "ParenthesizedExpression"); + return parenExpression; } shouldParseArrow(): boolean { @@ -1169,7 +1344,7 @@ export default class ExpressionParser extends LValParser { if (this.eat(tt.dot)) { const metaProp = this.parseMetaProperty(node, meta, "target"); - if (!this.state.inFunction && !this.state.inClassProperty) { + if (!this.scope.inNonArrowFunction && !this.state.inClassProperty) { let error = "new.target can only be used in functions"; if (this.hasPlugin("classProperties")) { @@ -1183,7 +1358,10 @@ export default class ExpressionParser extends LValParser { } node.callee = this.parseNoCallExpr(); - if ( + + if (node.callee.type === "Import") { + this.raise(node.callee.start, "Cannot use new with import(...)"); + } else if ( node.callee.type === "OptionalMemberExpression" || node.callee.type === "OptionalCallExpression" ) { @@ -1191,13 +1369,13 @@ export default class ExpressionParser extends LValParser { this.state.lastTokEnd, "constructors in/after an Optional Chain are not allowed", ); - } - if (this.eat(tt.questionDot)) { + } else if (this.eat(tt.questionDot)) { this.raise( this.state.start, "constructors in/after an Optional Chain are not allowed", ); } + this.parseNewArguments(node); return this.finishNode(node, "NewExpression"); } @@ -1261,7 +1439,6 @@ export default class ExpressionParser extends LValParser { isPattern: boolean, refShorthandDefaultPos?: ?Pos, ): T { - let decorators = []; const propHash: any = Object.create(null); let first = true; const node = this.startNode(); @@ -1269,8 +1446,6 @@ export default class ExpressionParser extends LValParser { node.properties = []; this.next(); - let firstRestLocation = null; - while (!this.eat(tt.braceR)) { if (first) { first = false; @@ -1279,140 +1454,117 @@ export default class ExpressionParser extends LValParser { if (this.eat(tt.braceR)) break; } - if (this.match(tt.at)) { - if (this.hasPlugin("decorators")) { - this.raise( - this.state.start, - "Stage 2 decorators disallow object literal property decorators", - ); - } else { - // we needn't check if decorators (stage 0) plugin is enabled since it's checked by - // the call to this.parseDecorator - while (this.match(tt.at)) { - decorators.push(this.parseDecorator()); - } - } - } + const prop = this.parseObjectMember(isPattern, refShorthandDefaultPos); + // $FlowIgnore RestElement will never be returned if !isPattern + if (!isPattern) this.checkPropClash(prop, propHash); - let prop = this.startNode(), - isGenerator = false, - isAsync = false, - startPos, - startLoc; - if (decorators.length) { - prop.decorators = decorators; - decorators = []; + // $FlowIgnore + if (prop.shorthand) { + this.addExtra(prop, "shorthand", true); } - if (this.match(tt.ellipsis)) { - this.expectPlugin("objectRestSpread"); - prop = this.parseSpread(isPattern ? { start: 0 } : undefined); - if (isPattern) { - this.toAssignable(prop, true, "object pattern"); - } - node.properties.push(prop); - if (isPattern) { - const position = this.state.start; - if (firstRestLocation !== null) { - this.unexpected( - firstRestLocation, - "Cannot have multiple rest elements when destructuring", - ); - } else if (this.eat(tt.braceR)) { - break; - } else if ( - this.match(tt.comma) && - this.lookahead().type === tt.braceR - ) { - this.unexpected( - position, - "A trailing comma is not permitted after the rest element", - ); - } else { - firstRestLocation = position; - continue; - } - } else { - continue; - } - } + node.properties.push(prop); + } - prop.method = false; + return this.finishNode( + node, + isPattern ? "ObjectPattern" : "ObjectExpression", + ); + } - if (isPattern || refShorthandDefaultPos) { - startPos = this.state.start; - startLoc = this.state.startLoc; - } + isAsyncProp(prop: N.ObjectProperty): boolean { + return ( + !prop.computed && + prop.key.type === "Identifier" && + prop.key.name === "async" && + (this.match(tt.name) || + this.match(tt.num) || + this.match(tt.string) || + this.match(tt.bracketL) || + this.state.type.keyword || + this.match(tt.star)) && + !this.hasPrecedingLineBreak() + ); + } - if (!isPattern) { - isGenerator = this.eat(tt.star); + parseObjectMember( + isPattern: boolean, + refShorthandDefaultPos: ?Pos, + ): N.ObjectMember | N.SpreadElement | N.RestElement { + let decorators = []; + if (this.match(tt.at)) { + if (this.hasPlugin("decorators")) { + this.raise( + this.state.start, + "Stage 2 decorators disallow object literal property decorators", + ); + } else { + // we needn't check if decorators (stage 0) plugin is enabled since it's checked by + // the call to this.parseDecorator + while (this.match(tt.at)) { + decorators.push(this.parseDecorator()); + } } + } - const containsEsc = this.state.containsEsc; - - if (!isPattern && this.isContextual("async")) { - if (isGenerator) this.unexpected(); + const prop = this.startNode(); + let isGenerator = false; + let isAsync = false; + let startPos; + let startLoc; - const asyncId = this.parseIdentifier(); - if ( - this.match(tt.colon) || - this.match(tt.parenL) || - this.match(tt.braceR) || - this.match(tt.eq) || - this.match(tt.comma) - ) { - prop.key = asyncId; - prop.computed = false; - } else { - isAsync = true; - if (this.match(tt.star)) { - this.expectPlugin("asyncGenerators"); - this.next(); - isGenerator = true; - } - this.parsePropertyName(prop); - } - } else { - this.parsePropertyName(prop); + if (this.match(tt.ellipsis)) { + if (decorators.length) this.unexpected(); + if (isPattern) { + this.next(); + // Don't use parseRestBinding() as we only allow Identifier here. + prop.argument = this.parseIdentifier(); + this.checkCommaAfterRest(); + return this.finishNode(prop, "RestElement"); } - this.parseObjPropValue( - prop, - startPos, - startLoc, - isGenerator, - isAsync, - isPattern, - refShorthandDefaultPos, - containsEsc, - ); - this.checkPropClash(prop, propHash); + return this.parseSpread(); + } - if (prop.shorthand) { - this.addExtra(prop, "shorthand", true); - } + if (decorators.length) { + prop.decorators = decorators; + decorators = []; + } - node.properties.push(prop); + prop.method = false; + + if (isPattern || refShorthandDefaultPos) { + startPos = this.state.start; + startLoc = this.state.startLoc; } - if (firstRestLocation !== null) { - this.unexpected( - firstRestLocation, - "The rest element has to be the last element when destructuring", - ); + if (!isPattern) { + isGenerator = this.eat(tt.star); } - if (decorators.length) { - this.raise( - this.state.start, - "You have trailing decorators with no property", - ); + const containsEsc = this.state.containsEsc; + this.parsePropertyName(prop); + + if (!isPattern && !containsEsc && !isGenerator && this.isAsyncProp(prop)) { + isAsync = true; + isGenerator = this.eat(tt.star); + this.parsePropertyName(prop); + } else { + isAsync = false; } - return this.finishNode( - node, - isPattern ? "ObjectPattern" : "ObjectExpression", + this.parseObjPropValue( + prop, + startPos, + startLoc, + isGenerator, + isAsync, + isPattern, + refShorthandDefaultPos, + containsEsc, ); + + return prop; } isGetterOrSetterMethod(prop: N.ObjectMethod, isPattern: boolean): boolean { @@ -1429,10 +1581,16 @@ export default class ExpressionParser extends LValParser { ); } + getGetterSetterExpectedParamCount( + method: N.ObjectMethod | N.ClassMethod, + ): number { + return method.kind === "get" ? 0 : 1; + } + // get methods aren't allowed to have any parameters // set methods must have exactly 1 parameter which is not a rest parameter checkGetterSetterParams(method: N.ObjectMethod | N.ClassMethod): void { - const paramCount = method.kind === "get" ? 0 : 1; + const paramCount = this.getGetterSetterExpectedParamCount(method); const start = method.start; if (method.params.length !== paramCount) { if (method.kind === "get") { @@ -1442,7 +1600,10 @@ export default class ExpressionParser extends LValParser { } } - if (method.kind === "set" && method.params[0].type === "RestElement") { + if ( + method.kind === "set" && + method.params[method.params.length - 1].type === "RestElement" + ) { this.raise( start, "setter function argument must not be a rest parameter", @@ -1466,6 +1627,7 @@ export default class ExpressionParser extends LValParser { isGenerator, isAsync, /* isConstructor */ false, + false, "ObjectMethod", ); } @@ -1479,6 +1641,7 @@ export default class ExpressionParser extends LValParser { /* isGenerator */ false, /* isAsync */ false, /* isConstructor */ false, + false, "ObjectMethod", ); this.checkGetterSetterParams(prop); @@ -1604,24 +1767,31 @@ export default class ExpressionParser extends LValParser { isGenerator: boolean, isAsync: boolean, isConstructor: boolean, + allowDirectSuper: boolean, type: string, + inClassScope: boolean = false, ): T { - const oldInFunc = this.state.inFunction; - const oldInMethod = this.state.inMethod; - const oldInGenerator = this.state.inGenerator; - this.state.inFunction = true; - this.state.inMethod = node.kind || true; - this.state.inGenerator = isGenerator; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.yieldPos = 0; + this.state.awaitPos = 0; this.initFunction(node, isAsync); node.generator = !!isGenerator; const allowModifiers = isConstructor; // For TypeScript parameter properties + this.scope.enter( + functionFlags(isAsync, node.generator) | + SCOPE_SUPER | + (inClassScope ? SCOPE_CLASS : 0) | + (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0), + ); this.parseFunctionParams((node: any), allowModifiers); - this.parseFunctionBodyAndFinish(node, type); + this.checkYieldAwaitInDefaultParams(); + this.parseFunctionBodyAndFinish(node, type, true); + this.scope.exit(); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inGenerator = oldInGenerator; + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; return node; } @@ -1631,32 +1801,26 @@ export default class ExpressionParser extends LValParser { // assignable list. parseArrowExpression( node: N.ArrowFunctionExpression, - params?: ?(N.Expression[]), - isAsync?: boolean, + params: ?(N.Expression[]), + isAsync: boolean, ): N.ArrowFunctionExpression { - // if we got there, it's no more "yield in possible arrow parameters"; - // it's just "yield in arrow parameters" - if (this.state.yieldInPossibleArrowParameters) { - this.raise( - this.state.yieldInPossibleArrowParameters.start, - "yield is not allowed in the parameters of an arrow function" + - " inside a generator", - ); - } - - const oldInFunc = this.state.inFunction; - this.state.inFunction = true; + this.scope.enter(functionFlags(isAsync, false) | SCOPE_ARROW); this.initFunction(node, isAsync); - if (params) this.setArrowFunctionParameters(node, params); - const oldInGenerator = this.state.inGenerator; const oldMaybeInArrowParameters = this.state.maybeInArrowParameters; - this.state.inGenerator = false; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; this.state.maybeInArrowParameters = false; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + + if (params) this.setArrowFunctionParameters(node, params); this.parseFunctionBody(node, true); - this.state.inGenerator = oldInGenerator; - this.state.inFunction = oldInFunc; + + this.scope.exit(); this.state.maybeInArrowParameters = oldMaybeInArrowParameters; + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; return this.finishNode(node, "ArrowFunctionExpression"); } @@ -1689,71 +1853,100 @@ export default class ExpressionParser extends LValParser { parseFunctionBodyAndFinish( node: N.BodilessFunctionOrMethodBase, type: string, - allowExpressionBody?: boolean, + isMethod?: boolean = false, ): void { // $FlowIgnore (node is not bodiless if we get here) - this.parseFunctionBody(node, allowExpressionBody); + this.parseFunctionBody(node, false, isMethod); this.finishNode(node, type); } // Parse function body and check parameters. - parseFunctionBody(node: N.Function, allowExpression: ?boolean): void { + parseFunctionBody( + node: N.Function, + allowExpression: ?boolean, + isMethod?: boolean = false, + ): void { const isExpression = allowExpression && !this.match(tt.braceL); + const oldStrict = this.state.strict; + let useStrict = false; const oldInParameters = this.state.inParameters; - const oldInAsync = this.state.inAsync; this.state.inParameters = false; - this.state.inAsync = node.async; if (isExpression) { node.body = this.parseMaybeAssign(); + this.checkParams(node, false, allowExpression); } else { - // Start a new scope with regard to labels and the `inGenerator` + const nonSimple = !this.isSimpleParamList(node.params); + if (!oldStrict || nonSimple) { + useStrict = this.strictDirective(this.state.end); + // If this is a strict mode function, verify that argument names + // are not repeated, and it does not try to bind the words `eval` + // or `arguments`. + if (useStrict && nonSimple) { + // This logic is here to align the error location with the estree plugin + const errorPos = + // $FlowIgnore + (node.kind === "method" || node.kind === "constructor") && + // $FlowIgnore + !!node.key + ? node.key.end + : node.start; + this.raise( + errorPos, + "Illegal 'use strict' directive in function with non-simple parameter list", + ); + } + } + // Start a new scope with regard to labels // flag (restore them to their old value afterwards). - const oldInGen = this.state.inGenerator; - const oldInFunc = this.state.inFunction; const oldLabels = this.state.labels; - this.state.inGenerator = node.generator; - this.state.inFunction = true; this.state.labels = []; - node.body = this.parseBlock(true); - this.state.inFunction = oldInFunc; - this.state.inGenerator = oldInGen; + if (useStrict) this.state.strict = true; + // Add the params to varDeclaredNames to ensure that an error is thrown + // if a let/const declaration in the function clashes with one of the params. + this.checkParams( + node, + !oldStrict && !useStrict && !allowExpression && !isMethod && !nonSimple, + allowExpression, + ); + node.body = this.parseBlock(true, false); this.state.labels = oldLabels; } - this.state.inAsync = oldInAsync; - this.checkFunctionNameAndParams(node, allowExpression); this.state.inParameters = oldInParameters; + // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' + if (this.state.strict && node.id) { + this.checkLVal(node.id, BIND_OUTSIDE, undefined, "function name"); + } + this.state.strict = oldStrict; + } + + isSimpleParamList( + params: $ReadOnlyArray, + ): boolean { + for (let i = 0, len = params.length; i < len; i++) { + if (params[i].type !== "Identifier") return false; + } + return true; } - checkFunctionNameAndParams( + checkParams( node: N.Function, + allowDuplicates: boolean, + // eslint-disable-next-line no-unused-vars isArrowFunction: ?boolean, ): void { - // If this is a strict mode function, verify that argument names - // are not repeated, and it does not try to bind the words `eval` - // or `arguments`. - const isStrict = this.isStrictBody(node); - // Also check for arrow functions - const checkLVal = this.state.strict || isStrict || isArrowFunction; - - const oldStrict = this.state.strict; - if (isStrict) this.state.strict = isStrict; - - if (checkLVal) { - const nameHash: any = Object.create(null); - if (node.id) { - this.checkLVal(node.id, true, undefined, "function name"); - } - for (const param of node.params) { - if (isStrict && param.type !== "Identifier") { - this.raise(param.start, "Non-simple parameter in strict mode"); - } - this.checkLVal(param, true, nameHash, "function parameter list"); - } + // $FlowIssue + const nameHash: {} = Object.create(null); + for (let i = 0; i < node.params.length; i++) { + this.checkLVal( + node.params[i], + BIND_VAR, + allowDuplicates ? null : nameHash, + "function paramter list", + ); } - this.state.strict = oldStrict; } // Parses a comma-separated list of expressions, and returns them as @@ -1787,7 +1980,7 @@ export default class ExpressionParser extends LValParser { allowEmpty: ?boolean, refShorthandDefaultPos: ?Pos, refNeedsArrowPos: ?Pos, - refTrailingCommaPos?: Pos, + allowPlaceholder: ?boolean, ): ?N.Expression { let elt; if (allowEmpty && this.match(tt.comma)) { @@ -1800,10 +1993,14 @@ export default class ExpressionParser extends LValParser { spreadNodeStartPos, spreadNodeStartLoc, ); - - if (refTrailingCommaPos && this.match(tt.comma)) { - refTrailingCommaPos.start = this.state.start; + } else if (this.match(tt.question)) { + this.expectPlugin("partialApplication"); + if (!allowPlaceholder) { + this.raise(this.state.start, "Unexpected argument placeholder"); } + const node = this.startNode(); + this.next(); + elt = this.finishNode(node, "ArgumentPlaceholder"); } else { elt = this.parseMaybeAssign( false, @@ -1822,36 +2019,52 @@ export default class ExpressionParser extends LValParser { parseIdentifier(liberal?: boolean): N.Identifier { const node = this.startNode(); const name = this.parseIdentifierName(node.start, liberal); + + return this.createIdentifier(node, name); + } + + createIdentifier(node: N.Identifier, name: string): N.Identifier { node.name = name; node.loc.identifierName = name; + return this.finishNode(node, "Identifier"); } parseIdentifierName(pos: number, liberal?: boolean): string { - if (!liberal) { - this.checkReservedWord( - this.state.value, - this.state.start, - !!this.state.type.keyword, - false, - ); - } - let name: string; if (this.match(tt.name)) { name = this.state.value; } else if (this.state.type.keyword) { name = this.state.type.keyword; + + // `class` and `function` keywords push new context into this.context. + // But there is no chance to pop the context if the keyword is consumed + // as an identifier such as a property name. + // If the previous token is a dot, this does not apply because the + // context-managing code already ignored the keyword + if ( + (name === "class" || name === "function") && + (this.state.lastTokEnd !== this.state.lastTokStart + 1 || + this.input.charCodeAt(this.state.lastTokStart) !== charCodes.dot) + ) { + this.state.context.pop(); + } } else { throw this.unexpected(); } - if (!liberal && name === "await" && this.state.inAsync) { - this.raise(pos, "invalid use of await inside of an async function"); + if (!liberal) { + this.checkReservedWord( + name, + this.state.start, + !!this.state.type.keyword, + false, + ); } this.next(); + return name; } @@ -1861,18 +2074,17 @@ export default class ExpressionParser extends LValParser { checkKeywords: boolean, isBinding: boolean, ): void { - if ( - this.state.strict && - (reservedWords.strict(word) || - (isBinding && reservedWords.strictBind(word))) - ) { - this.raise(startLoc, word + " is a reserved word in strict mode"); + if (this.scope.inGenerator && word === "yield") { + this.raise( + startLoc, + "Can not use 'yield' as identifier inside a generator", + ); } - if (this.state.inGenerator && word === "yield") { + if (this.scope.inAsync && word === "await") { this.raise( startLoc, - "yield is a reserved word inside generator functions", + "Can not use 'await' as identifier inside an async function", ); } @@ -1882,21 +2094,42 @@ export default class ExpressionParser extends LValParser { "'arguments' is not allowed in class field initializer", ); } + if (checkKeywords && isKeyword(word)) { + this.raise(startLoc, `Unexpected keyword '${word}'`); + } + + const reservedTest = !this.state.strict + ? isReservedWord + : isBinding + ? isStrictBindReservedWord + : isStrictReservedWord; - if (this.isReservedWord(word) || (checkKeywords && this.isKeyword(word))) { - this.raise(startLoc, word + " is a reserved word"); + if (reservedTest(word, this.inModule)) { + if (!this.scope.inAsync && word === "await") { + this.raise( + startLoc, + "Can not use keyword 'await' outside an async function", + ); + } + this.raise(startLoc, `Unexpected reserved word '${word}'`); } } // Parses await expression inside async function. - parseAwait(node: N.AwaitExpression): N.AwaitExpression { - // istanbul ignore next: this condition is checked at the call site so won't be hit here - if ( - !this.state.inAsync && - (this.state.inFunction || !this.options.allowAwaitOutsideFunction) - ) { - this.unexpected(); + parseAwait(): N.AwaitExpression { + if (!this.state.awaitPos) { + this.state.awaitPos = this.state.start; + } + const node = this.startNode(); + + this.next(); + + if (this.state.inParameters) { + this.raise( + node.start, + "await is not allowed in async function parameters", + ); } if (this.match(tt.star)) { this.raise( @@ -1904,39 +2137,245 @@ export default class ExpressionParser extends LValParser { "await* has been removed from the async functions proposal. Use Promise.all() instead.", ); } - node.argument = this.parseMaybeUnary(); + + if (!this.state.soloAwait) { + node.argument = this.parseMaybeUnary(); + } return this.finishNode(node, "AwaitExpression"); } // Parses yield expression inside generator. - parseYield(): N.YieldExpression { + parseYield(noIn?: ?boolean): N.YieldExpression { + if (!this.state.yieldPos) { + this.state.yieldPos = this.state.start; + } const node = this.startNode(); if (this.state.inParameters) { this.raise(node.start, "yield is not allowed in generator parameters"); } - if ( - this.state.maybeInArrowParameters && - // We only set yieldInPossibleArrowParameters if we haven't already - // found a possible invalid YieldExpression. - !this.state.yieldInPossibleArrowParameters - ) { - this.state.yieldInPossibleArrowParameters = node; - } this.next(); if ( this.match(tt.semi) || - this.canInsertSemicolon() || - (!this.match(tt.star) && !this.state.type.startsExpr) + (!this.match(tt.star) && !this.state.type.startsExpr) || + this.canInsertSemicolon() ) { node.delegate = false; node.argument = null; } else { node.delegate = this.eat(tt.star); - node.argument = this.parseMaybeAssign(); + node.argument = this.parseMaybeAssign(noIn); } return this.finishNode(node, "YieldExpression"); } + + // Validates a pipeline (for any of the pipeline Babylon plugins) at the point + // of the infix operator `|>`. + + checkPipelineAtInfixOperator(left: N.Expression, leftStartPos: number) { + if (this.getPluginOption("pipelineOperator", "proposal") === "smart") { + if (left.type === "SequenceExpression") { + // Ensure that the pipeline head is not a comma-delimited + // sequence expression. + throw this.raise( + leftStartPos, + `Pipeline head should not be a comma-separated sequence expression`, + ); + } + } + } + + parseSmartPipelineBody( + childExpression: N.Expression, + startPos: number, + startLoc: Position, + ): N.PipelineBody { + const pipelineStyle = this.checkSmartPipelineBodyStyle(childExpression); + + this.checkSmartPipelineBodyEarlyErrors( + childExpression, + pipelineStyle, + startPos, + ); + + return this.parseSmartPipelineBodyInStyle( + childExpression, + pipelineStyle, + startPos, + startLoc, + ); + } + + checkSmartPipelineBodyEarlyErrors( + childExpression: N.Expression, + pipelineStyle: N.PipelineStyle, + startPos: number, + ): void { + if (this.match(tt.arrow)) { + // If the following token is invalidly `=>`, then throw a human-friendly error + // instead of something like 'Unexpected token, expected ";"'. + throw this.raise( + this.state.start, + `Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized`, + ); + } else if ( + pipelineStyle === "PipelineTopicExpression" && + childExpression.type === "SequenceExpression" + ) { + throw this.raise( + startPos, + `Pipeline body may not be a comma-separated sequence expression`, + ); + } + } + + parseSmartPipelineBodyInStyle( + childExpression: N.Expression, + pipelineStyle: N.PipelineStyle, + startPos: number, + startLoc: Position, + ): N.PipelineBody { + const bodyNode = this.startNodeAt(startPos, startLoc); + switch (pipelineStyle) { + case "PipelineBareFunction": + bodyNode.callee = childExpression; + break; + case "PipelineBareConstructor": + bodyNode.callee = childExpression.callee; + break; + case "PipelineBareAwaitedFunction": + bodyNode.callee = childExpression.argument; + break; + case "PipelineTopicExpression": + if (!this.topicReferenceWasUsedInCurrentTopicContext()) { + throw this.raise( + startPos, + `Pipeline is in topic style but does not use topic reference`, + ); + } + bodyNode.expression = childExpression; + break; + default: + throw this.raise(startPos, `Unknown pipeline style ${pipelineStyle}`); + } + return this.finishNode(bodyNode, pipelineStyle); + } + + checkSmartPipelineBodyStyle(expression: N.Expression): N.PipelineStyle { + switch (expression.type) { + default: + return this.isSimpleReference(expression) + ? "PipelineBareFunction" + : "PipelineTopicExpression"; + } + } + + isSimpleReference(expression: N.Expression): boolean { + switch (expression.type) { + case "MemberExpression": + return ( + !expression.computed && this.isSimpleReference(expression.object) + ); + case "Identifier": + return true; + default: + return false; + } + } + + // Enable topic references from outer contexts within smart pipeline bodies. + // The function modifies the parser's topic-context state to enable or disable + // the use of topic references with the smartPipelines plugin. They then run a + // callback, then they reset the parser to the old topic-context state that it + // had before the function was called. + + withTopicPermittingContext(callback: () => T): T { + const outerContextTopicState = this.state.topicContext; + this.state.topicContext = { + // Enable the use of the primary topic reference. + maxNumOfResolvableTopics: 1, + // Hide the use of any topic references from outer contexts. + maxTopicIndex: null, + }; + + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; + } + } + + // Disable topic references from outer contexts within syntax constructs + // such as the bodies of iteration statements. + // The function modifies the parser's topic-context state to enable or disable + // the use of topic references with the smartPipelines plugin. They then run a + // callback, then they reset the parser to the old topic-context state that it + // had before the function was called. + + withTopicForbiddingContext(callback: () => T): T { + const outerContextTopicState = this.state.topicContext; + this.state.topicContext = { + // Disable the use of the primary topic reference. + maxNumOfResolvableTopics: 0, + // Hide the use of any topic references from outer contexts. + maxTopicIndex: null, + }; + + try { + return callback(); + } finally { + this.state.topicContext = outerContextTopicState; + } + } + + withSoloAwaitPermittingContext(callback: () => T): T { + const outerContextSoloAwaitState = this.state.soloAwait; + this.state.soloAwait = true; + + try { + return callback(); + } finally { + this.state.soloAwait = outerContextSoloAwaitState; + } + } + + // Register the use of a primary topic reference (`#`) within the current + // topic context. + registerTopicReference(): void { + this.state.topicContext.maxTopicIndex = 0; + } + + primaryTopicReferenceIsAllowedInCurrentTopicContext(): boolean { + return this.state.topicContext.maxNumOfResolvableTopics >= 1; + } + + topicReferenceWasUsedInCurrentTopicContext(): boolean { + return ( + this.state.topicContext.maxTopicIndex != null && + this.state.topicContext.maxTopicIndex >= 0 + ); + } + + parseFSharpPipelineBody(prec: number, noIn: ?boolean): N.Expression { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + + this.state.potentialArrowAt = this.state.start; + const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody; + this.state.inFSharpPipelineDirectBody = true; + + const ret = this.parseExprOp( + this.parseMaybeUnary(), + startPos, + startLoc, + prec, + noIn, + ); + + this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody; + + return ret; + } } diff --git a/packages/babel-parser/src/parser/index.js b/packages/babel-parser/src/parser/index.js index 6d6d9cfd8b7b..9e75bf6044d3 100644 --- a/packages/babel-parser/src/parser/index.js +++ b/packages/babel-parser/src/parser/index.js @@ -5,10 +5,10 @@ import type { File, JSXOpeningElement } from "../types"; import type { PluginList } from "../plugin-utils"; import { getOptions } from "../options"; import StatementParser from "./statement"; +import { SCOPE_PROGRAM } from "../util/scopeflags"; +import ScopeHandler from "../util/scope"; -export type PluginsMap = { - [key: string]: { [option: string]: any }, -}; +export type PluginsMap = Map; export default class Parser extends StatementParser { // Forward-declaration so typescript plugin can override jsx plugin @@ -20,14 +20,22 @@ export default class Parser extends StatementParser { options = getOptions(options); super(options, input); + const ScopeHandler = this.getScopeHandler(); + this.options = options; this.inModule = this.options.sourceType === "module"; - this.input = input; + this.scope = new ScopeHandler(this.raise.bind(this), this.inModule); this.plugins = pluginsMap(this.options.plugins); this.filename = options.sourceFilename; } + // This can be overwritten, for example, by the TypeScript plugin. + getScopeHandler(): Class> { + return ScopeHandler; + } + parse(): File { + this.scope.enter(SCOPE_PROGRAM); const file = this.startNode(); const program = this.startNode(); this.nextToken(); @@ -36,10 +44,10 @@ export default class Parser extends StatementParser { } function pluginsMap(plugins: PluginList): PluginsMap { - const pluginMap: PluginsMap = (Object.create(null): Object); + const pluginMap: PluginsMap = new Map(); for (const plugin of plugins) { - const [name, options = {}] = Array.isArray(plugin) ? plugin : [plugin, {}]; - if (!pluginMap[name]) pluginMap[name] = options || {}; + const [name, options] = Array.isArray(plugin) ? plugin : [plugin, {}]; + if (!pluginMap.has(name)) pluginMap.set(name, options || {}); } return pluginMap; } diff --git a/packages/babel-parser/src/parser/location.js b/packages/babel-parser/src/parser/location.js index 79db584a4995..1839f359ae4c 100644 --- a/packages/babel-parser/src/parser/location.js +++ b/packages/babel-parser/src/parser/location.js @@ -10,6 +10,17 @@ import CommentsParser from "./comments"; // message. export default class LocationParser extends CommentsParser { + getLocationForPosition(pos: number): Position { + let loc; + if (pos === this.state.start) loc = this.state.startLoc; + else if (pos === this.state.lastTokStart) loc = this.state.lastTokStartLoc; + else if (pos === this.state.end) loc = this.state.endLoc; + else if (pos === this.state.lastTokEnd) loc = this.state.lastTokEndLoc; + else loc = getLineInfo(this.input, pos); + + return loc; + } + raise( pos: number, message: string, @@ -21,7 +32,8 @@ export default class LocationParser extends CommentsParser { code?: string, } = {}, ): empty { - const loc = getLineInfo(this.input, pos); + const loc = this.getLocationForPosition(pos); + message += ` (${loc.line}:${loc.column})`; // $FlowIgnore const err: SyntaxError & { pos: number, loc: Position } = new SyntaxError( diff --git a/packages/babel-parser/src/parser/lval.js b/packages/babel-parser/src/parser/lval.js index 46234dade3a9..b4281ab2ffb7 100644 --- a/packages/babel-parser/src/parser/lval.js +++ b/packages/babel-parser/src/parser/lval.js @@ -14,16 +14,12 @@ import type { SpreadElement, } from "../types"; import type { Pos, Position } from "../util/location"; +import { isStrictBindReservedWord } from "../util/identifier"; import { NodeUtils } from "./node"; +import { type BindingTypes, BIND_NONE, BIND_LEXICAL } from "../util/scopeflags"; export default class LValParser extends NodeUtils { // Forward-declaration: defined in expression.js - +checkReservedWord: ( - word: string, - startLoc: number, - checkKeywords: boolean, - isBinding: boolean, - ) => void; +parseIdentifier: (liberal?: boolean) => Identifier; +parseMaybeAssign: ( noIn?: ?boolean, @@ -56,9 +52,13 @@ export default class LValParser extends NodeUtils { case "ObjectExpression": node.type = "ObjectPattern"; - for (let index = 0; index < node.properties.length; index++) { - const prop = node.properties[index]; - const isLast = index === node.properties.length - 1; + for ( + let i = 0, length = node.properties.length, last = length - 1; + i < length; + i++ + ) { + const prop = node.properties[i]; + const isLast = i === last; this.toAssignableObjectExpressionProp(prop, isBinding, isLast); } break; @@ -93,6 +93,14 @@ export default class LValParser extends NodeUtils { } break; + case "ParenthesizedExpression": + node.expression = this.toAssignable( + node.expression, + isBinding, + contextDescription, + ); + break; + case "MemberExpression": if (!isBinding) break; @@ -122,10 +130,7 @@ export default class LValParser extends NodeUtils { this.raise(prop.key.start, error); } else if (prop.type === "SpreadElement" && !isLast) { - this.raise( - prop.start, - "The rest element has to be the last element when destructuring", - ); + this.raiseRestNotLast(prop.start); } else { this.toAssignable(prop, isBinding, "object destructuring pattern"); } @@ -148,12 +153,10 @@ export default class LValParser extends NodeUtils { const arg = last.argument; this.toAssignable(arg, isBinding, contextDescription); if ( - [ - "Identifier", - "MemberExpression", - "ArrayPattern", - "ObjectPattern", - ].indexOf(arg.type) === -1 + arg.type !== "Identifier" && + arg.type !== "MemberExpression" && + arg.type !== "ArrayPattern" && + arg.type !== "ObjectPattern" ) { this.unexpected(arg.start); } @@ -162,13 +165,12 @@ export default class LValParser extends NodeUtils { } for (let i = 0; i < end; i++) { const elt = exprList[i]; - if (elt && elt.type === "SpreadElement") { - this.raise( - elt.start, - "The rest element has to be the last element when destructuring", - ); + if (elt) { + this.toAssignable(elt, isBinding, contextDescription); + if (elt.type === "RestElement") { + this.raiseRestNotLast(elt.start); + } } - if (elt) this.toAssignable(elt, isBinding, contextDescription); } return exprList; } @@ -177,16 +179,32 @@ export default class LValParser extends NodeUtils { toReferencedList( exprList: $ReadOnlyArray, + isParenthesizedExpr?: boolean, // eslint-disable-line no-unused-vars ): $ReadOnlyArray { return exprList; } + toReferencedListDeep( + exprList: $ReadOnlyArray, + isParenthesizedExpr?: boolean, + ): $ReadOnlyArray { + this.toReferencedList(exprList, isParenthesizedExpr); + + for (const expr of exprList) { + if (expr && expr.type === "ArrayExpression") { + this.toReferencedListDeep(expr.elements); + } + } + + return exprList; + } + // Parses spread element. - parseSpread( + parseSpread( refShorthandDefaultPos: ?Pos, refNeedsArrowPos?: ?Pos, - ): T { + ): SpreadElement { const node = this.startNode(); this.next(); node.argument = this.parseMaybeAssign( @@ -195,33 +213,24 @@ export default class LValParser extends NodeUtils { undefined, refNeedsArrowPos, ); + + if (this.state.commaAfterSpreadAt === -1 && this.match(tt.comma)) { + this.state.commaAfterSpreadAt = this.state.start; + } + return this.finishNode(node, "SpreadElement"); } - parseRest(): RestElement { + parseRestBinding(): RestElement { const node = this.startNode(); this.next(); node.argument = this.parseBindingAtom(); return this.finishNode(node, "RestElement"); } - shouldAllowYieldIdentifier(): boolean { - return ( - this.match(tt._yield) && !this.state.strict && !this.state.inGenerator - ); - } - - parseBindingIdentifier(): Identifier { - return this.parseIdentifier(this.shouldAllowYieldIdentifier()); - } - // Parses lvalue (assignable) atom. parseBindingAtom(): Pattern { switch (this.state.type) { - case tt._yield: - case tt.name: - return this.parseBindingIdentifier(); - case tt.bracketL: { const node = this.startNode(); this.next(); @@ -231,10 +240,9 @@ export default class LValParser extends NodeUtils { case tt.braceL: return this.parseObj(true); - - default: - throw this.unexpected(); } + + return this.parseIdentifier(); } parseBindingList( @@ -256,7 +264,8 @@ export default class LValParser extends NodeUtils { } else if (this.eat(close)) { break; } else if (this.match(tt.ellipsis)) { - elts.push(this.parseAssignableListItemTypes(this.parseRest())); + elts.push(this.parseAssignableListItemTypes(this.parseRestBinding())); + this.checkCommaAfterRest(); this.expect(close); break; } else { @@ -316,13 +325,23 @@ export default class LValParser extends NodeUtils { checkLVal( expr: Expression, - isBinding: ?boolean, + bindingType: BindingTypes = BIND_NONE, checkClashes: ?{ [key: string]: boolean }, contextDescription: string, ): void { switch (expr.type) { case "Identifier": - this.checkReservedWord(expr.name, expr.start, false, true); + if ( + this.state.strict && + isStrictBindReservedWord(expr.name, this.inModule) + ) { + this.raise( + expr.start, + `${bindingType === BIND_NONE ? "Assigning to" : "Binding"} '${ + expr.name + }' in strict mode`, + ); + } if (checkClashes) { // we need to prefix this with an underscore for the cases where we have a key of @@ -339,15 +358,26 @@ export default class LValParser extends NodeUtils { const key = `_${expr.name}`; if (checkClashes[key]) { - this.raise(expr.start, "Argument name clash in strict mode"); + this.raise(expr.start, "Argument name clash"); } else { checkClashes[key] = true; } } + if (bindingType === BIND_LEXICAL && expr.name === "let") { + this.raise( + expr.start, + "'let' is not allowed to be used as a name in 'let' or 'const' declarations.", + ); + } + if (!(bindingType & BIND_NONE)) { + this.scope.declareName(expr.name, bindingType, expr.start); + } break; case "MemberExpression": - if (isBinding) this.raise(expr.start, "Binding member expression"); + if (bindingType !== BIND_NONE) { + this.raise(expr.start, "Binding member expression"); + } break; case "ObjectPattern": @@ -355,7 +385,7 @@ export default class LValParser extends NodeUtils { if (prop.type === "ObjectProperty") prop = prop.value; this.checkLVal( prop, - isBinding, + bindingType, checkClashes, "object destructuring pattern", ); @@ -367,7 +397,7 @@ export default class LValParser extends NodeUtils { if (elem) { this.checkLVal( elem, - isBinding, + bindingType, checkClashes, "array destructuring pattern", ); @@ -378,21 +408,35 @@ export default class LValParser extends NodeUtils { case "AssignmentPattern": this.checkLVal( expr.left, - isBinding, + bindingType, checkClashes, "assignment pattern", ); break; case "RestElement": - this.checkLVal(expr.argument, isBinding, checkClashes, "rest element"); + this.checkLVal( + expr.argument, + bindingType, + checkClashes, + "rest element", + ); + break; + + case "ParenthesizedExpression": + this.checkLVal( + expr.expression, + bindingType, + checkClashes, + "parenthesized expression", + ); break; default: { const message = - (isBinding - ? /* istanbul ignore next */ "Binding invalid" - : "Invalid") + + (bindingType === BIND_NONE + ? "Invalid" + : /* istanbul ignore next */ "Binding invalid") + " left-hand side" + (contextDescription ? " in " + contextDescription @@ -403,12 +447,27 @@ export default class LValParser extends NodeUtils { } checkToRestConversion(node: SpreadElement): void { - const validArgumentTypes = ["Identifier", "MemberExpression"]; + if ( + node.argument.type !== "Identifier" && + node.argument.type !== "MemberExpression" + ) { + this.raise(node.argument.start, "Invalid rest operator's argument"); + } + } + + checkCommaAfterRest(): void { + if (this.match(tt.comma)) { + this.raiseRestNotLast(this.state.start); + } + } - if (validArgumentTypes.indexOf(node.argument.type) !== -1) { - return; + checkCommaAfterRestFromSpread(): void { + if (this.state.commaAfterSpreadAt > -1) { + this.raiseRestNotLast(this.state.commaAfterSpreadAt); } + } - this.raise(node.argument.start, "Invalid rest operator's argument"); + raiseRestNotLast(pos: number) { + this.raise(pos, `Rest element must be last element`); } } diff --git a/packages/babel-parser/src/parser/node.js b/packages/babel-parser/src/parser/node.js index 73223eea85d6..b3d322310122 100644 --- a/packages/babel-parser/src/parser/node.js +++ b/packages/babel-parser/src/parser/node.js @@ -7,8 +7,6 @@ import type { Comment, Node as NodeType, NodeBase } from "../types"; // Start an AST node, attaching a start offset. -const commentKeys = ["leadingComments", "trailingComments", "innerComments"]; - class Node implements NodeBase { constructor(parser: Parser, pos: number, loc: Position) { this.type = ""; @@ -31,16 +29,22 @@ class Node implements NodeBase { __clone(): this { // $FlowIgnore - const node2: any = new Node(); - Object.keys(this).forEach(key => { + const newNode: any = new Node(); + const keys = Object.keys(this); + for (let i = 0, length = keys.length; i < length; i++) { + const key = keys[i]; // Do not clone comments that are already attached to the node - if (commentKeys.indexOf(key) < 0) { + if ( + key !== "leadingComments" && + key !== "trailingComments" && + key !== "innerComments" + ) { // $FlowIgnore - node2[key] = this[key]; + newNode[key] = this[key]; } - }); + } - return node2; + return newNode; } } @@ -79,6 +83,12 @@ export class NodeUtils extends UtilParser { pos: number, loc: Position, ): T { + if (process.env.NODE_ENV !== "production" && node.end > 0) { + throw new Error( + "Do not call finishNode*() twice on the same node." + + " Instead use resetEndLocation() or change type directly.", + ); + } node.type = type; node.end = pos; node.loc.end = loc; @@ -87,12 +97,26 @@ export class NodeUtils extends UtilParser { return node; } + resetStartLocation(node: NodeBase, start: number, startLoc: Position): void { + node.start = start; + node.loc.start = startLoc; + if (this.options.ranges) node.range[0] = start; + } + + resetEndLocation( + node: NodeBase, + end?: number = this.state.lastTokEnd, + endLoc?: Position = this.state.lastTokEndLoc, + ): void { + node.end = end; + node.loc.end = endLoc; + if (this.options.ranges) node.range[1] = end; + } + /** * Reset the start location of node to the start location of locationNode */ resetStartLocationFromNode(node: NodeBase, locationNode: NodeBase): void { - node.start = locationNode.start; - node.loc.start = locationNode.loc.start; - if (this.options.ranges) node.range[0] = locationNode.range[0]; + this.resetStartLocation(node, locationNode.start, locationNode.loc.start); } } diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 9e890d2ef644..b677bfd0c9e2 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -3,16 +3,33 @@ import * as N from "../types"; import { types as tt, type TokenType } from "../tokenizer/types"; import ExpressionParser from "./expression"; -import { isIdentifierChar } from "../util/identifier"; +import { + isIdentifierChar, + isIdentifierStart, + keywordRelationalOperator, +} from "../util/identifier"; import { lineBreak, skipWhiteSpace } from "../util/whitespace"; - -// Reused empty array added for node fields that are always empty. - -const empty = []; +import * as charCodes from "charcodes"; +import { + BIND_CLASS, + BIND_LEXICAL, + BIND_VAR, + BIND_FUNCTION, + functionFlags, + SCOPE_CLASS, + SCOPE_OTHER, + SCOPE_SIMPLE_CATCH, + SCOPE_SUPER, +} from "../util/scopeflags"; const loopLabel = { kind: "loop" }, switchLabel = { kind: "switch" }; +const FUNC_NO_FLAGS = 0b000, + FUNC_STATEMENT = 0b001, + FUNC_HANGING_STATEMENT = 0b010, + FUNC_NULLABLE_ID = 0b100; + export default class StatementParser extends ExpressionParser { // ### Statement parsing @@ -28,6 +45,18 @@ export default class StatementParser extends ExpressionParser { this.parseBlockBody(program, true, true, tt.eof); + if ( + this.inModule && + !this.options.allowUndeclaredExports && + this.scope.undefinedExports.size > 0 + ) { + for (const [name] of Array.from(this.scope.undefinedExports)) { + const pos = this.scope.undefinedExports.get(name); + // $FlowIssue + this.raise(pos, `Export '${name}' is not defined`); + } + } + file.program = this.finishNode(program, "Program"); file.comments = this.state.comments; @@ -71,6 +100,35 @@ export default class StatementParser extends ExpressionParser { return this.finishNode(node, "InterpreterDirective"); } + isLet(context: ?string): boolean { + if (!this.isContextual("let")) { + return false; + } + skipWhiteSpace.lastIndex = this.state.pos; + const skip = skipWhiteSpace.exec(this.input); + // $FlowIgnore + const next = this.state.pos + skip[0].length; + const nextCh = this.input.charCodeAt(next); + // For ambiguous cases, determine if a LexicalDeclaration (or only a + // Statement) is allowed here. If context is not empty then only a Statement + // is allowed. However, `let [` is an explicit negative lookahead for + // ExpressionStatement, so special-case it first. + if (nextCh === charCodes.leftSquareBracket) return true; + if (context) return false; + + if (nextCh === charCodes.leftCurlyBrace) return true; + + if (isIdentifierStart(nextCh)) { + let pos = next + 1; + while (isIdentifierChar(this.input.charCodeAt(pos))) { + ++pos; + } + const ident = this.input.slice(next, pos); + if (!keywordRelationalOperator.test(ident)) return true; + } + return false; + } + // Parse a single statement. // // If expecting a statement and finding a slash operator, parse a @@ -78,16 +136,22 @@ export default class StatementParser extends ExpressionParser { // `if (foo) /blah/.exec(foo)`, where looking at the previous token // does not help. - parseStatement(declaration: boolean, topLevel?: boolean): N.Statement { + parseStatement(context: ?string, topLevel?: boolean): N.Statement { if (this.match(tt.at)) { this.parseDecorators(true); } - return this.parseStatementContent(declaration, topLevel); + return this.parseStatementContent(context, topLevel); } - parseStatementContent(declaration: boolean, topLevel: ?boolean): N.Statement { - const starttype = this.state.type; + parseStatementContent(context: ?string, topLevel: ?boolean): N.Statement { + let starttype = this.state.type; const node = this.startNode(); + let kind; + + if (this.isLet(context)) { + starttype = tt._var; + kind = "let"; + } // Most types of statements are recognized by the keyword they // start with. Many are trivial to parse, some require a bit of @@ -106,11 +170,24 @@ export default class StatementParser extends ExpressionParser { return this.parseForStatement(node); case tt._function: if (this.lookahead().type === tt.dot) break; - if (!declaration) this.unexpected(); - return this.parseFunctionStatement(node); + if (context) { + if (this.state.strict) { + this.raise( + this.state.start, + "In strict mode code, functions can only be declared at top level or inside a block", + ); + } else if (context !== "if" && context !== "label") { + this.raise( + this.state.start, + "In non-strict mode code, functions can only be declared at top level, " + + "inside a block, or as the body of an if statement", + ); + } + } + return this.parseFunctionStatement(node, false, !context); case tt._class: - if (!declaration) this.unexpected(); + if (context) this.unexpected(); return this.parseClass(node, true); case tt._if: @@ -124,12 +201,16 @@ export default class StatementParser extends ExpressionParser { case tt._try: return this.parseTryStatement(node); - case tt._let: case tt._const: - if (!declaration) this.unexpected(); // NOTE: falls through to _var - case tt._var: - return this.parseVarStatement(node, starttype); + kind = kind || this.state.value; + if (context && kind !== "var") { + this.unexpected( + this.state.start, + "Lexical declaration cannot appear in a single-statement context", + ); + } + return this.parseVarStatement(node, kind); case tt._while: return this.parseWhileStatement(node); @@ -156,7 +237,7 @@ export default class StatementParser extends ExpressionParser { this.next(); let result; - if (starttype == tt._import) { + if (starttype === tt._import) { result = this.parseImport(node); if ( @@ -183,18 +264,19 @@ export default class StatementParser extends ExpressionParser { return result; } - case tt.name: - if (this.isContextual("async")) { - // peek ahead and see if next token is a function - const state = this.state.clone(); - this.next(); - if (this.match(tt._function) && !this.canInsertSemicolon()) { - this.expect(tt._function); - return this.parseFunction(node, true, false, true); - } else { - this.state = state; + + default: { + if (this.isAsyncFunction()) { + if (context) { + this.unexpected( + null, + "Async functions can only be declared at the top level or inside a block", + ); } + this.next(); + return this.parseFunctionStatement(node, true, !context); } + } } // If the statement does not start with a statement keyword or a @@ -210,7 +292,7 @@ export default class StatementParser extends ExpressionParser { expr.type === "Identifier" && this.eat(tt.colon) ) { - return this.parseLabeledStatement(node, maybeName, expr); + return this.parseLabeledStatement(node, maybeName, expr, context); } else { return this.parseExpressionStatement(node, expr); } @@ -305,22 +387,26 @@ export default class StatementParser extends ExpressionParser { } } - if (this.eat(tt.parenL)) { - const node = this.startNodeAt(startPos, startLoc); - node.callee = expr; - node.arguments = this.parseCallExpressionArguments(tt.parenR, false); - this.toReferencedList(node.arguments); - expr = this.finishNode(node, "CallExpression"); - } - - node.expression = expr; + node.expression = this.parseMaybeDecoratorArguments(expr); this.state.decoratorStack.pop(); } else { - node.expression = this.parseMaybeAssign(); + node.expression = this.parseExprSubscripts(); } return this.finishNode(node, "Decorator"); } + parseMaybeDecoratorArguments(expr: N.Expression): N.Expression { + if (this.eat(tt.parenL)) { + const node = this.startNodeAtNode(expr); + node.callee = expr; + node.arguments = this.parseCallExpressionArguments(tt.parenR, false); + this.toReferencedList(node.arguments); + return this.finishNode(node, "CallExpression"); + } + + return expr; + } + parseBreakContinueStatement( node: N.BreakStatement | N.ContinueStatement, keyword: string, @@ -330,15 +416,24 @@ export default class StatementParser extends ExpressionParser { if (this.isLineTerminator()) { node.label = null; - } else if (!this.match(tt.name)) { - this.unexpected(); } else { node.label = this.parseIdentifier(); this.semicolon(); } - // Verify that there is an actual destination to break or - // continue to. + this.verifyBreakContinue(node, keyword); + + return this.finishNode( + node, + isBreak ? "BreakStatement" : "ContinueStatement", + ); + } + + verifyBreakContinue( + node: N.BreakStatement | N.ContinueStatement, + keyword: string, + ) { + const isBreak = keyword === "break"; let i; for (i = 0; i < this.state.labels.length; ++i) { const lab = this.state.labels[i]; @@ -350,10 +445,6 @@ export default class StatementParser extends ExpressionParser { if (i === this.state.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); } - return this.finishNode( - node, - isBreak ? "BreakStatement" : "ContinueStatement", - ); } parseDebuggerStatement(node: N.DebuggerStatement): N.DebuggerStatement { @@ -362,13 +453,30 @@ export default class StatementParser extends ExpressionParser { return this.finishNode(node, "DebuggerStatement"); } + parseHeaderExpression(): N.Expression { + this.expect(tt.parenL); + const val = this.parseExpression(); + this.expect(tt.parenR); + return val; + } + parseDoStatement(node: N.DoWhileStatement): N.DoWhileStatement { this.next(); this.state.labels.push(loopLabel); - node.body = this.parseStatement(false); + + node.body = + // For the smartPipelines plugin: Disable topic references from outer + // contexts within the loop body. They are permitted in test expressions, + // outside of the loop body. + this.withTopicForbiddingContext(() => + // Parse the loop body's body. + this.parseStatement("do"), + ); + this.state.labels.pop(); + this.expect(tt._while); - node.test = this.parseParenExpression(); + node.test = this.parseHeaderExpression(); this.eat(tt.semi); return this.finishNode(node, "DoWhileStatement"); } @@ -385,46 +493,40 @@ export default class StatementParser extends ExpressionParser { this.next(); this.state.labels.push(loopLabel); - let forAwait = false; - if (this.state.inAsync && this.isContextual("await")) { - this.expectPlugin("asyncGenerators"); - forAwait = true; - this.next(); + let awaitAt = -1; + if ( + (this.scope.inAsync || + (!this.scope.inFunction && this.options.allowAwaitOutsideFunction)) && + this.eatContextual("await") + ) { + awaitAt = this.state.lastTokStart; } + this.scope.enter(SCOPE_OTHER); this.expect(tt.parenL); if (this.match(tt.semi)) { - if (forAwait) { - this.unexpected(); + if (awaitAt > -1) { + this.unexpected(awaitAt); } return this.parseFor(node, null); } - if (this.match(tt._var) || this.match(tt._let) || this.match(tt._const)) { + const isLet = this.isLet(); + if (this.match(tt._var) || this.match(tt._const) || isLet) { const init = this.startNode(); - const varKind = this.state.type; + const kind = isLet ? "let" : this.state.value; this.next(); - this.parseVar(init, true, varKind); + this.parseVar(init, true, kind); this.finishNode(init, "VariableDeclaration"); - if (this.match(tt._in) || this.isContextual("of")) { - if (init.declarations.length === 1) { - const declaration = init.declarations[0]; - const isForInInitializer = - varKind === tt._var && - declaration.init && - declaration.id.type != "ObjectPattern" && - declaration.id.type != "ArrayPattern" && - !this.isContextual("of"); - if (this.state.strict && isForInInitializer) { - this.raise(this.state.start, "for-in initializer in strict mode"); - } else if (isForInInitializer || !declaration.init) { - return this.parseForIn(node, init, forAwait); - } - } + if ( + (this.match(tt._in) || this.isContextual("of")) && + init.declarations.length === 1 + ) { + return this.parseForIn(node, init, awaitAt); } - if (forAwait) { - this.unexpected(); + if (awaitAt > -1) { + this.unexpected(awaitAt); } return this.parseFor(node, init); } @@ -437,31 +539,39 @@ export default class StatementParser extends ExpressionParser { : "for-in statement"; this.toAssignable(init, undefined, description); this.checkLVal(init, undefined, undefined, description); - return this.parseForIn(node, init, forAwait); + return this.parseForIn(node, init, awaitAt); } else if (refShorthandDefaultPos.start) { this.unexpected(refShorthandDefaultPos.start); } - if (forAwait) { - this.unexpected(); + if (awaitAt > -1) { + this.unexpected(awaitAt); } return this.parseFor(node, init); } - parseFunctionStatement(node: N.FunctionDeclaration): N.FunctionDeclaration { + parseFunctionStatement( + node: N.FunctionDeclaration, + isAsync?: boolean, + declarationPosition?: boolean, + ): N.FunctionDeclaration { this.next(); - return this.parseFunction(node, true); + return this.parseFunction( + node, + FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), + isAsync, + ); } parseIfStatement(node: N.IfStatement): N.IfStatement { this.next(); - node.test = this.parseParenExpression(); - node.consequent = this.parseStatement(false); - node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null; + node.test = this.parseHeaderExpression(); + node.consequent = this.parseStatement("if"); + node.alternate = this.eat(tt._else) ? this.parseStatement("if") : null; return this.finishNode(node, "IfStatement"); } parseReturnStatement(node: N.ReturnStatement): N.ReturnStatement { - if (!this.state.inFunction && !this.options.allowReturnOutsideFunction) { + if (!this.scope.inFunction && !this.options.allowReturnOutsideFunction) { this.raise(this.state.start, "'return' outside of function"); } @@ -483,10 +593,11 @@ export default class StatementParser extends ExpressionParser { parseSwitchStatement(node: N.SwitchStatement): N.SwitchStatement { this.next(); - node.discriminant = this.parseParenExpression(); + node.discriminant = this.parseHeaderExpression(); const cases = (node.cases = []); this.expect(tt.braceL); this.state.labels.push(switchLabel); + this.scope.enter(SCOPE_OTHER); // Statements under must be grouped (by label) in SwitchCase // nodes. `cur` is used to keep the node that we are currently @@ -512,12 +623,13 @@ export default class StatementParser extends ExpressionParser { this.expect(tt.colon); } else { if (cur) { - cur.consequent.push(this.parseStatement(true)); + cur.consequent.push(this.parseStatement(null)); } else { this.unexpected(); } } } + this.scope.exit(); if (cur) this.finishNode(cur, "SwitchCase"); this.next(); // Closing brace this.state.labels.pop(); @@ -548,18 +660,29 @@ export default class StatementParser extends ExpressionParser { if (this.match(tt.parenL)) { this.expect(tt.parenL); clause.param = this.parseBindingAtom(); - const clashes: any = Object.create(null); - this.checkLVal(clause.param, true, clashes, "catch clause"); + const simple = clause.param.type === "Identifier"; + this.scope.enter(simple ? SCOPE_SIMPLE_CATCH : 0); + this.checkLVal(clause.param, BIND_LEXICAL, null, "catch clause"); this.expect(tt.parenR); } else { - this.expectPlugin("optionalCatchBinding"); clause.param = null; + this.scope.enter(SCOPE_OTHER); } - clause.body = this.parseBlock(); + + clause.body = + // For the smartPipelines plugin: Disable topic references from outer + // contexts within the function body. They are permitted in function + // default-parameter expressions, which are part of the outer context, + // outside of the function body. + this.withTopicForbiddingContext(() => + // Parse the catch clause's body. + this.parseBlock(false, false), + ); + this.scope.exit(); + node.handler = this.finishNode(clause, "CatchClause"); } - node.guardedHandlers = empty; node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null; if (!node.handler && !node.finalizer) { @@ -571,7 +694,7 @@ export default class StatementParser extends ExpressionParser { parseVarStatement( node: N.VariableDeclaration, - kind: TokenType, + kind: "var" | "let" | "const", ): N.VariableDeclaration { this.next(); this.parseVar(node, false, kind); @@ -581,10 +704,20 @@ export default class StatementParser extends ExpressionParser { parseWhileStatement(node: N.WhileStatement): N.WhileStatement { this.next(); - node.test = this.parseParenExpression(); + node.test = this.parseHeaderExpression(); this.state.labels.push(loopLabel); - node.body = this.parseStatement(false); + + node.body = + // For the smartPipelines plugin: + // Disable topic references from outer contexts within the loop body. + // They are permitted in test expressions, outside of the loop body. + this.withTopicForbiddingContext(() => + // Parse loop body. + this.parseStatement("while"), + ); + this.state.labels.pop(); + return this.finishNode(node, "WhileStatement"); } @@ -593,8 +726,18 @@ export default class StatementParser extends ExpressionParser { this.raise(this.state.start, "'with' in strict mode"); } this.next(); - node.object = this.parseParenExpression(); - node.body = this.parseStatement(false); + node.object = this.parseHeaderExpression(); + + node.body = + // For the smartPipelines plugin: + // Disable topic references from outer contexts within the function body. + // They are permitted in function default-parameter expressions, which are + // part of the outer context, outside of the function body. + this.withTopicForbiddingContext(() => + // Parse the statement body. + this.parseStatement("with"), + ); + return this.finishNode(node, "WithStatement"); } @@ -607,6 +750,7 @@ export default class StatementParser extends ExpressionParser { node: N.LabeledStatement, maybeName: string, expr: N.Identifier, + context: ?string, ): N.LabeledStatement { for (const label of this.state.labels) { if (label.name === maybeName) { @@ -617,8 +761,8 @@ export default class StatementParser extends ExpressionParser { const kind = this.state.type.isLoop ? "loop" : this.match(tt._switch) - ? "switch" - : null; + ? "switch" + : null; for (let i = this.state.labels.length - 1; i >= 0; i--) { const label = this.state.labels[i]; if (label.statementStart === node.start) { @@ -634,16 +778,13 @@ export default class StatementParser extends ExpressionParser { kind: kind, statementStart: this.state.start, }); - node.body = this.parseStatement(true); - - if ( - node.body.type == "ClassDeclaration" || - (node.body.type == "VariableDeclaration" && node.body.kind !== "var") || - (node.body.type == "FunctionDeclaration" && - (this.state.strict || node.body.generator || node.body.async)) - ) { - this.raise(node.body.start, "Invalid labeled declaration"); - } + node.body = this.parseStatement( + context + ? context.indexOf("label") === -1 + ? context + "label" + : context + : "label", + ); this.state.labels.pop(); node.label = expr; @@ -653,7 +794,7 @@ export default class StatementParser extends ExpressionParser { parseExpressionStatement( node: N.ExpressionStatement, expr: N.Expression, - ): N.ExpressionStatement { + ): N.Statement { node.expression = expr; this.semicolon(); return this.finishNode(node, "ExpressionStatement"); @@ -663,10 +804,19 @@ export default class StatementParser extends ExpressionParser { // strict"` declarations when `allowStrict` is true (used for // function bodies). - parseBlock(allowDirectives?: boolean): N.BlockStatement { + parseBlock( + allowDirectives?: boolean = false, + createNewLexicalScope?: boolean = true, + ): N.BlockStatement { const node = this.startNode(); this.expect(tt.braceL); + if (createNewLexicalScope) { + this.scope.enter(SCOPE_OTHER); + } this.parseBlockBody(node, allowDirectives, false, tt.braceR); + if (createNewLexicalScope) { + this.scope.exit(); + } return this.finishNode(node, "BlockStatement"); } @@ -710,7 +860,7 @@ export default class StatementParser extends ExpressionParser { octalPosition = this.state.octalPosition; } - const stmt = this.parseStatement(true, topLevel); + const stmt = this.parseStatement(null, topLevel); if (directives && !parsedNonDirective && this.isValidDirective(stmt)) { const directive = this.stmtToDirective(stmt); @@ -751,8 +901,19 @@ export default class StatementParser extends ExpressionParser { this.expect(tt.semi); node.update = this.match(tt.parenR) ? null : this.parseExpression(); this.expect(tt.parenR); - node.body = this.parseStatement(false); + + node.body = + // For the smartPipelines plugin: Disable topic references from outer + // contexts within the loop body. They are permitted in test expressions, + // outside of the loop body. + this.withTopicForbiddingContext(() => + // Parse the loop body. + this.parseStatement("for"), + ); + + this.scope.exit(); this.state.labels.pop(); + return this.finishNode(node, "ForStatement"); } @@ -761,24 +922,53 @@ export default class StatementParser extends ExpressionParser { parseForIn( node: N.ForInOf, - init: N.VariableDeclaration, - forAwait: boolean, + init: N.VariableDeclaration | N.AssignmentPattern, + awaitAt: number, ): N.ForInOf { - const type = this.match(tt._in) ? "ForInStatement" : "ForOfStatement"; - if (forAwait) { - this.eatContextual("of"); + const isForIn = this.match(tt._in); + this.next(); + + if (isForIn) { + if (awaitAt > -1) this.unexpected(awaitAt); } else { - this.next(); + node.await = awaitAt > -1; } - if (type === "ForOfStatement") { - node.await = !!forAwait; + + if ( + init.type === "VariableDeclaration" && + init.declarations[0].init != null && + (!isForIn || + this.state.strict || + init.kind !== "var" || + init.declarations[0].id.type !== "Identifier") + ) { + this.raise( + init.start, + `${ + isForIn ? "for-in" : "for-of" + } loop variable declaration may not have an initializer`, + ); + } else if (init.type === "AssignmentPattern") { + this.raise(init.start, "Invalid left-hand side in for-loop"); } + node.left = init; - node.right = this.parseExpression(); + node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign(); this.expect(tt.parenR); - node.body = this.parseStatement(false); + + node.body = + // For the smartPipelines plugin: + // Disable topic references from outer contexts within the loop body. + // They are permitted in test expressions, outside of the loop body. + this.withTopicForbiddingContext(() => + // Parse loop body. + this.parseStatement("for"), + ); + + this.scope.exit(); this.state.labels.pop(); - return this.finishNode(node, type); + + return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement"); } // Parse a list of variable declarations. @@ -786,24 +976,24 @@ export default class StatementParser extends ExpressionParser { parseVar( node: N.VariableDeclaration, isFor: boolean, - kind: TokenType, + kind: "var" | "let" | "const", ): N.VariableDeclaration { const declarations = (node.declarations = []); - // $FlowFixMe - node.kind = kind.keyword; + const isTypescript = this.hasPlugin("typescript"); + node.kind = kind; for (;;) { const decl = this.startNode(); - this.parseVarHead(decl); + this.parseVarId(decl, kind); if (this.eat(tt.eq)) { decl.init = this.parseMaybeAssign(isFor); } else { if ( - kind === tt._const && + kind === "const" && !(this.match(tt._in) || this.isContextual("of")) ) { // `const` with no initializer is allowed in TypeScript. // It could be a declaration like `const x: number;`. - if (!this.hasPlugin("typescript")) { + if (!isTypescript) { this.unexpected(); } } else if ( @@ -823,9 +1013,14 @@ export default class StatementParser extends ExpressionParser { return node; } - parseVarHead(decl: N.VariableDeclarator): void { + parseVarId(decl: N.VariableDeclarator, kind: "var" | "let" | "const"): void { decl.id = this.parseBindingAtom(); - this.checkLVal(decl.id, true, undefined, "variable declaration"); + this.checkLVal( + decl.id, + kind === "var" ? BIND_VAR : BIND_LEXICAL, + undefined, + "variable declaration", + ); } // Parse a function declaration or literal (depending on the @@ -833,67 +1028,72 @@ export default class StatementParser extends ExpressionParser { parseFunction( node: T, - isStatement: boolean, - allowExpressionBody?: boolean, - isAsync?: boolean, - optionalId?: boolean, + statement?: number = FUNC_NO_FLAGS, + isAsync?: boolean = false, ): T { - const oldInFunc = this.state.inFunction; - const oldInMethod = this.state.inMethod; - const oldInGenerator = this.state.inGenerator; - const oldInClassProperty = this.state.inClassProperty; - this.state.inFunction = true; - this.state.inMethod = false; - this.state.inClassProperty = false; + const isStatement = statement & FUNC_STATEMENT; + const isHangingStatement = statement & FUNC_HANGING_STATEMENT; + const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID); this.initFunction(node, isAsync); - if (this.match(tt.star)) { - if (node.async) { - this.expectPlugin("asyncGenerators"); - } - node.generator = true; - this.next(); + if (this.match(tt.star) && isHangingStatement) { + this.unexpected( + this.state.start, + "Generators can only be declared at the top level or inside a block", + ); } + node.generator = this.eat(tt.star); - if ( - isStatement && - !optionalId && - !this.match(tt.name) && - !this.match(tt._yield) - ) { - this.unexpected(); + if (isStatement) { + node.id = this.parseFunctionId(requireId); } - // When parsing function expression, the binding identifier is parsed - // according to the rules inside the function. - // e.g. (function* yield() {}) is invalid because "yield" is disallowed in - // generators. - // This isn't the case with function declarations: function* yield() {} is - // valid because yield is parsed as if it was outside the generator. - // Therefore, this.state.inGenerator is set before or after parsing the - // function id according to the "isStatement" parameter. - if (!isStatement) this.state.inGenerator = node.generator; - if (this.match(tt.name) || this.match(tt._yield)) { - node.id = this.parseBindingIdentifier(); + const oldInClassProperty = this.state.inClassProperty; + const oldYieldPos = this.state.yieldPos; + const oldAwaitPos = this.state.awaitPos; + this.state.inClassProperty = false; + this.state.yieldPos = 0; + this.state.awaitPos = 0; + this.scope.enter(functionFlags(node.async, node.generator)); + + if (!isStatement) { + node.id = this.parseFunctionId(); } - if (isStatement) this.state.inGenerator = node.generator; this.parseFunctionParams(node); - this.parseFunctionBodyAndFinish( - node, - isStatement ? "FunctionDeclaration" : "FunctionExpression", - allowExpressionBody, - ); - this.state.inFunction = oldInFunc; - this.state.inMethod = oldInMethod; - this.state.inGenerator = oldInGenerator; + // For the smartPipelines plugin: Disable topic references from outer + // contexts within the function body. They are permitted in test + // expressions, outside of the function body. + this.withTopicForbiddingContext(() => { + // Parse the function body. + this.parseFunctionBodyAndFinish( + node, + isStatement ? "FunctionDeclaration" : "FunctionExpression", + ); + }); + + this.scope.exit(); + + if (isStatement && !isHangingStatement) { + // We need to validate this _after_ parsing the function body + // because of TypeScript body-less function declarations, + // which shouldn't be added to the scope. + this.checkFunctionStatementId(node); + } + this.state.inClassProperty = oldInClassProperty; + this.state.yieldPos = oldYieldPos; + this.state.awaitPos = oldAwaitPos; return node; } + parseFunctionId(requireId?: boolean): ?N.Identifier { + return requireId || this.match(tt.name) ? this.parseIdentifier() : null; + } + parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { const oldInParameters = this.state.inParameters; this.state.inParameters = true; @@ -906,6 +1106,26 @@ export default class StatementParser extends ExpressionParser { ); this.state.inParameters = oldInParameters; + this.checkYieldAwaitInDefaultParams(); + } + + checkFunctionStatementId(node: N.Function): void { + if (!node.id) return; + + // If it is a regular function declaration in sloppy mode, then it is + // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding + // mode depends on properties of the current scope (see + // treatFunctionsAsVar). + this.checkLVal( + node.id, + this.state.strict || node.generator || node.async + ? this.scope.treatFunctionsAsVar + ? BIND_VAR + : BIND_LEXICAL + : BIND_FUNCTION, + null, + "function name", + ); } // Parse a class declaration or literal (depending on the @@ -918,9 +1138,17 @@ export default class StatementParser extends ExpressionParser { ): T { this.next(); this.takeDecorators(node); + + // A class definition is always strict mode code. + const oldStrict = this.state.strict; + this.state.strict = true; + this.parseClassId(node, isStatement, optionalId); this.parseClassSuper(node); - this.parseClassBody(node); + node.body = this.parseClassBody(!!node.superClass); + + this.state.strict = oldStrict; + return this.finishNode( node, isStatement ? "ClassDeclaration" : "ClassExpression", @@ -944,58 +1172,59 @@ export default class StatementParser extends ExpressionParser { ); } - parseClassBody(node: N.Class): void { - // class bodies are implicitly strict - const oldStrict = this.state.strict; - this.state.strict = true; + parseClassBody(constructorAllowsSuper: boolean): N.ClassBody { this.state.classLevel++; const state = { hadConstructor: false }; let decorators: N.Decorator[] = []; const classBody: N.ClassBody = this.startNode(); - classBody.body = []; this.expect(tt.braceL); - while (!this.eat(tt.braceR)) { - if (this.eat(tt.semi)) { - if (decorators.length > 0) { - this.raise( - this.state.lastTokEnd, - "Decorators must not be followed by a semicolon", - ); + // For the smartPipelines plugin: Disable topic references from outer + // contexts within the class body. They are permitted in test expressions, + // outside of the class body. + this.withTopicForbiddingContext(() => { + while (!this.eat(tt.braceR)) { + if (this.eat(tt.semi)) { + if (decorators.length > 0) { + this.raise( + this.state.lastTokEnd, + "Decorators must not be followed by a semicolon", + ); + } + continue; } - continue; - } - if (this.match(tt.at)) { - decorators.push(this.parseDecorator()); - continue; - } + if (this.match(tt.at)) { + decorators.push(this.parseDecorator()); + continue; + } - const member = this.startNode(); + const member = this.startNode(); - // steal the decorators if there are any - if (decorators.length) { - member.decorators = decorators; - this.resetStartLocationFromNode(member, decorators[0]); - decorators = []; - } + // steal the decorators if there are any + if (decorators.length) { + member.decorators = decorators; + this.resetStartLocationFromNode(member, decorators[0]); + decorators = []; + } - this.parseClassMember(classBody, member, state); + this.parseClassMember(classBody, member, state, constructorAllowsSuper); - if ( - member.kind === "constructor" && - member.decorators && - member.decorators.length > 0 - ) { - this.raise( - member.start, - "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?", - ); + if ( + member.kind === "constructor" && + member.decorators && + member.decorators.length > 0 + ) { + this.raise( + member.start, + "Decorators can't be used with a constructor. Did you mean '@dec class { ... }'?", + ); + } } - } + }); if (decorators.length) { this.raise( @@ -1004,16 +1233,16 @@ export default class StatementParser extends ExpressionParser { ); } - node.body = this.finishNode(classBody, "ClassBody"); - this.state.classLevel--; - this.state.strict = oldStrict; + + return this.finishNode(classBody, "ClassBody"); } parseClassMember( classBody: N.ClassBody, member: N.ClassMember, state: { hadConstructor: boolean }, + constructorAllowsSuper: boolean, ): void { let isStatic = false; const containsEsc = this.state.containsEsc; @@ -1035,6 +1264,7 @@ export default class StatementParser extends ExpressionParser { false, false, /* isConstructor */ false, + false, ); return; } else if (this.isClassProperty()) { @@ -1054,7 +1284,13 @@ export default class StatementParser extends ExpressionParser { isStatic = true; } - this.parseClassMemberWithIsStatic(classBody, member, state, isStatic); + this.parseClassMemberWithIsStatic( + classBody, + member, + state, + isStatic, + constructorAllowsSuper, + ); } parseClassMemberWithIsStatic( @@ -1062,6 +1298,7 @@ export default class StatementParser extends ExpressionParser { member: N.ClassMember, state: { hadConstructor: boolean }, isStatic: boolean, + constructorAllowsSuper: boolean, ) { const publicMethod: $FlowSubtype = member; const privateMethod: $FlowSubtype = member; @@ -1094,11 +1331,13 @@ export default class StatementParser extends ExpressionParser { true, false, /* isConstructor */ false, + false, ); return; } + const containsEsc = this.state.containsEsc; const key = this.parseClassPropertyName(member); const isPrivate = key.type === "PrivateName"; // Check the key is not a computed expression or string literal. @@ -1116,7 +1355,7 @@ export default class StatementParser extends ExpressionParser { // a normal method const isConstructor = this.isNonstaticConstructor(publicMethod); - + let allowsDirectSuper = false; if (isConstructor) { publicMethod.kind = "constructor"; @@ -1132,6 +1371,7 @@ export default class StatementParser extends ExpressionParser { this.raise(key.start, "Duplicate constructor in the same class"); } state.hadConstructor = true; + allowsDirectSuper = constructorAllowsSuper; } this.pushClassMethod( @@ -1140,6 +1380,7 @@ export default class StatementParser extends ExpressionParser { false, false, isConstructor, + allowsDirectSuper, ); } else if (this.isClassProperty()) { if (isPrivate) { @@ -1147,13 +1388,14 @@ export default class StatementParser extends ExpressionParser { } else { this.pushClassProperty(classBody, publicProp); } - } else if (isSimple && key.name === "async" && !this.isLineTerminator()) { + } else if ( + isSimple && + key.name === "async" && + !containsEsc && + !this.isLineTerminator() + ) { // an async method - const isGenerator = this.match(tt.star); - if (isGenerator) { - this.expectPlugin("asyncGenerators"); - this.next(); - } + const isGenerator = this.eat(tt.star); method.kind = "method"; // The so-called parsed name would have been "async": get the real name. @@ -1181,12 +1423,14 @@ export default class StatementParser extends ExpressionParser { isGenerator, true, /* isConstructor */ false, + false, ); } } else if ( isSimple && (key.name === "get" || key.name === "set") && - !(this.isLineTerminator() && this.match(tt.star)) + !containsEsc && + !(this.match(tt.star) && this.isLineTerminator()) ) { // `get\n*` is an uninitialized property named 'get' followed by a generator. // a getter or setter @@ -1210,6 +1454,7 @@ export default class StatementParser extends ExpressionParser { false, false, /* isConstructor */ false, + false, ); } @@ -1276,6 +1521,7 @@ export default class StatementParser extends ExpressionParser { isGenerator: boolean, isAsync: boolean, isConstructor: boolean, + allowsDirectSuper: boolean, ): void { classBody.body.push( this.parseMethod( @@ -1283,7 +1529,9 @@ export default class StatementParser extends ExpressionParser { isGenerator, isAsync, isConstructor, + allowsDirectSuper, "ClassMethod", + true, ), ); } @@ -1301,7 +1549,9 @@ export default class StatementParser extends ExpressionParser { isGenerator, isAsync, /* isConstructor */ false, + false, "ClassPrivateMethod", + true, ), ); } @@ -1320,13 +1570,16 @@ export default class StatementParser extends ExpressionParser { parseClassPrivateProperty( node: N.ClassPrivateProperty, ): N.ClassPrivateProperty { - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; this.state.inClassProperty = true; + + this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); + node.value = this.eat(tt.eq) ? this.parseMaybeAssign() : null; this.semicolon(); this.state.inClassProperty = false; - this.state.inMethod = oldInMethod; + + this.scope.exit(); + return this.finishNode(node, "ClassPrivateProperty"); } @@ -1335,10 +1588,10 @@ export default class StatementParser extends ExpressionParser { this.expectPlugin("classProperties"); } - const oldInMethod = this.state.inMethod; - this.state.inMethod = false; this.state.inClassProperty = true; + this.scope.enter(SCOPE_CLASS | SCOPE_SUPER); + if (this.match(tt.eq)) { this.expectPlugin("classProperties"); this.next(); @@ -1348,7 +1601,8 @@ export default class StatementParser extends ExpressionParser { } this.semicolon(); this.state.inClassProperty = false; - this.state.inMethod = oldInMethod; + + this.scope.exit(); return this.finishNode(node, "ClassProperty"); } @@ -1360,6 +1614,9 @@ export default class StatementParser extends ExpressionParser { ): void { if (this.match(tt.name)) { node.id = this.parseIdentifier(); + if (isStatement) { + this.checkLVal(node.id, BIND_CLASS, undefined, "class name"); + } } else { if (optionalId || !isStatement) { node.id = null; @@ -1375,35 +1632,109 @@ export default class StatementParser extends ExpressionParser { // Parses module export declaration. - // TODO: better type. Node is an N.AnyExport. - parseExport(node: N.Node): N.Node { - // export * from '...' - if (this.shouldParseExportStar()) { - this.parseExportStar(node); - if (node.type === "ExportAllDeclaration") return node; - } else if (this.isExportDefaultSpecifier()) { - this.expectPlugin("exportDefaultFrom"); - const specifier = this.startNode(); - specifier.exported = this.parseIdentifier(true); - const specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; - node.specifiers = specifiers; - if (this.match(tt.comma) && this.lookahead().type === tt.star) { - this.expect(tt.comma); - const specifier = this.startNode(); - this.expect(tt.star); - this.expectContextual("as"); - specifier.exported = this.parseIdentifier(); - specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier")); - } else { - this.parseExportSpecifiersMaybe(node); - } + parseExport(node: N.Node): N.AnyExport { + const hasDefault = this.maybeParseExportDefaultSpecifier(node); + const parseAfterDefault = !hasDefault || this.eat(tt.comma); + const hasStar = parseAfterDefault && this.eatExportStar(node); + const hasNamespace = + hasStar && this.maybeParseExportNamespaceSpecifier(node); + const parseAfterNamespace = + parseAfterDefault && (!hasNamespace || this.eat(tt.comma)); + const isFromRequired = hasDefault || hasStar; + + if (hasStar && !hasNamespace) { + if (hasDefault) this.unexpected(); this.parseExportFrom(node, true); - } else if (this.eat(tt._default)) { + + return this.finishNode(node, "ExportAllDeclaration"); + } + + const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node); + + if ( + (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) || + (hasNamespace && parseAfterNamespace && !hasSpecifiers) + ) { + throw this.unexpected(null, tt.braceL); + } + + let hasDeclaration; + if (isFromRequired || hasSpecifiers) { + hasDeclaration = false; + this.parseExportFrom(node, isFromRequired); + } else { + hasDeclaration = this.maybeParseExportDeclaration(node); + } + + if (isFromRequired || hasSpecifiers || hasDeclaration) { + this.checkExport(node, true, false, !!node.source); + return this.finishNode(node, "ExportNamedDeclaration"); + } + + if (this.eat(tt._default)) { // export default ... node.declaration = this.parseExportDefaultExpression(); this.checkExport(node, true, true); + return this.finishNode(node, "ExportDefaultDeclaration"); - } else if (this.shouldParseExportDeclaration()) { + } + + throw this.unexpected(null, tt.braceL); + } + + // eslint-disable-next-line no-unused-vars + eatExportStar(node: N.Node): boolean { + return this.eat(tt.star); + } + + maybeParseExportDefaultSpecifier(node: N.Node): boolean { + if (this.isExportDefaultSpecifier()) { + // export defaultObj ... + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = this.parseIdentifier(true); + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + return true; + } + return false; + } + + maybeParseExportNamespaceSpecifier(node: N.Node): boolean { + if (this.isContextual("as")) { + if (!node.specifiers) node.specifiers = []; + this.expectPlugin("exportNamespaceFrom"); + + const specifier = this.startNodeAt( + this.state.lastTokStart, + this.state.lastTokStartLoc, + ); + + this.next(); + + specifier.exported = this.parseIdentifier(true); + node.specifiers.push( + this.finishNode(specifier, "ExportNamespaceSpecifier"), + ); + return true; + } + return false; + } + + maybeParseExportNamedSpecifiers(node: N.Node): boolean { + if (this.match(tt.braceL)) { + if (!node.specifiers) node.specifiers = []; + node.specifiers.push(...this.parseExportSpecifiers()); + + node.source = null; + node.declaration = null; + + return true; + } + return false; + } + + maybeParseExportDeclaration(node: N.Node): boolean { + if (this.shouldParseExportDeclaration()) { if (this.isContextual("async")) { const next = this.lookahead(); @@ -1416,32 +1747,29 @@ export default class StatementParser extends ExpressionParser { node.specifiers = []; node.source = null; node.declaration = this.parseExportDeclaration(node); - } else { - // export { x, y as z } [from '...'] - node.declaration = null; - node.specifiers = this.parseExportSpecifiers(); - this.parseExportFrom(node); + + return true; } - this.checkExport(node, true); - return this.finishNode(node, "ExportNamedDeclaration"); + return false; } - isAsyncFunction() { + isAsyncFunction(): boolean { if (!this.isContextual("async")) return false; - const { input, pos } = this.state; + const { pos } = this.state; skipWhiteSpace.lastIndex = pos; - const skip = skipWhiteSpace.exec(input); + const skip = skipWhiteSpace.exec(this.input); if (!skip || !skip.length) return false; const next = pos + skip[0].length; return ( - !lineBreak.test(input.slice(pos, next)) && - input.slice(next, next + 8) === "function" && - (next + 8 === input.length || !isIdentifierChar(input.charAt(next + 8))) + !lineBreak.test(this.input.slice(pos, next)) && + this.input.slice(next, next + 8) === "function" && + (next + 8 === this.length || + !isIdentifierChar(this.input.charCodeAt(next + 8))) ); } @@ -1450,13 +1778,17 @@ export default class StatementParser extends ExpressionParser { const isAsync = this.isAsyncFunction(); - if (this.eat(tt._function) || isAsync) { + if (this.match(tt._function) || isAsync) { + this.next(); if (isAsync) { - this.eatContextual("async"); - this.expect(tt._function); + this.next(); } - return this.parseFunction(expr, true, false, isAsync, true); + return this.parseFunction( + expr, + FUNC_STATEMENT | FUNC_NULLABLE_ID, + isAsync, + ); } else if (this.match(tt._class)) { return this.parseClass(expr, true, true); } else if (this.match(tt.at)) { @@ -1473,11 +1805,7 @@ export default class StatementParser extends ExpressionParser { } this.parseDecorators(false); return this.parseClass(expr, true, true); - } else if ( - this.match(tt._let) || - this.match(tt._const) || - this.match(tt._var) - ) { + } else if (this.match(tt._const) || this.match(tt._var) || this.isLet()) { return this.raise( this.state.start, "Only expressions, functions or classes are allowed as the `default` export.", @@ -1491,12 +1819,12 @@ export default class StatementParser extends ExpressionParser { // eslint-disable-next-line no-unused-vars parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration { - return this.parseStatement(true); + return this.parseStatement(null); } isExportDefaultSpecifier(): boolean { if (this.match(tt.name)) { - return this.state.value !== "async"; + return this.state.value !== "async" && this.state.value !== "let"; } if (!this.match(tt._default)) { @@ -1510,17 +1838,9 @@ export default class StatementParser extends ExpressionParser { ); } - parseExportSpecifiersMaybe(node: N.ExportNamedDeclaration): void { - if (this.eat(tt.comma)) { - node.specifiers = node.specifiers.concat(this.parseExportSpecifiers()); - } - } - parseExportFrom(node: N.ExportNamedDeclaration, expect?: boolean): void { if (this.eatContextual("from")) { - node.source = this.match(tt.string) - ? this.parseExprAtom() - : this.unexpected(); + node.source = this.parseImportSource(); this.checkExport(node); } else { if (expect) { @@ -1533,39 +1853,6 @@ export default class StatementParser extends ExpressionParser { this.semicolon(); } - shouldParseExportStar(): boolean { - return this.match(tt.star); - } - - parseExportStar(node: N.ExportNamedDeclaration): void { - this.expect(tt.star); - - if (this.isContextual("as")) { - this.parseExportNamespace(node); - } else { - this.parseExportFrom(node, true); - this.finishNode(node, "ExportAllDeclaration"); - } - } - - parseExportNamespace(node: N.ExportNamedDeclaration): void { - this.expectPlugin("exportNamespaceFrom"); - - const specifier = this.startNodeAt( - this.state.lastTokStart, - this.state.lastTokStartLoc, - ); - - this.next(); - - specifier.exported = this.parseIdentifier(true); - - node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")]; - - this.parseExportSpecifiersMaybe(node); - this.parseExportFrom(node, true); - } - shouldParseExportDeclaration(): boolean { if (this.match(tt.at)) { this.expectOnePlugin(["decorators", "decorators-legacy"]); @@ -1586,17 +1873,18 @@ export default class StatementParser extends ExpressionParser { return ( this.state.type.keyword === "var" || this.state.type.keyword === "const" || - this.state.type.keyword === "let" || this.state.type.keyword === "function" || this.state.type.keyword === "class" || + this.isLet() || this.isAsyncFunction() ); } checkExport( node: N.ExportNamedDeclaration, - checkNames: ?boolean, + checkNames?: boolean, isDefault?: boolean, + isFrom?: boolean, ): void { if (checkNames) { // Check for duplicate exports @@ -1607,6 +1895,19 @@ export default class StatementParser extends ExpressionParser { // Named exports for (const specifier of node.specifiers) { this.checkDuplicateExports(specifier, specifier.exported.name); + // $FlowIgnore + if (!isFrom && specifier.local) { + // check for keywords used as local names + this.checkReservedWord( + specifier.local.name, + specifier.local.start, + true, + false, + ); + // check if export is defined + // $FlowIgnore + this.scope.checkLocalExport(specifier.local); + } } } else if (node.declaration) { // Exported declarations @@ -1645,7 +1946,9 @@ export default class StatementParser extends ExpressionParser { } checkDeclaration(node: N.Pattern | N.ObjectProperty): void { - if (node.type === "ObjectPattern") { + if (node.type === "Identifier") { + this.checkDuplicateExports(node, node.name); + } else if (node.type === "ObjectPattern") { for (const prop of node.properties) { this.checkDeclaration(prop); } @@ -1659,39 +1962,35 @@ export default class StatementParser extends ExpressionParser { this.checkDeclaration(node.value); } else if (node.type === "RestElement") { this.checkDeclaration(node.argument); - } else if (node.type === "Identifier") { - this.checkDuplicateExports(node, node.name); + } else if (node.type === "AssignmentPattern") { + this.checkDeclaration(node.left); } } checkDuplicateExports( - node: N.Identifier | N.ExportNamedDeclaration | N.ExportSpecifier, + node: + | N.Identifier + | N.ExportNamedDeclaration + | N.ExportSpecifier + | N.ExportDefaultSpecifier, name: string, ): void { if (this.state.exportedIdentifiers.indexOf(name) > -1) { - this.raiseDuplicateExportError(node, name); + throw this.raise( + node.start, + name === "default" + ? "Only one default export allowed per module." + : `\`${name}\` has already been exported. Exported identifiers must be unique.`, + ); } this.state.exportedIdentifiers.push(name); } - raiseDuplicateExportError( - node: N.Identifier | N.ExportNamedDeclaration | N.ExportSpecifier, - name: string, - ): empty { - throw this.raise( - node.start, - name === "default" - ? "Only one default export allowed per module." - : `\`${name}\` has already been exported. Exported identifiers must be unique.`, - ); - } - // Parses a comma-separated list of module exports. parseExportSpecifiers(): Array { const nodes = []; let first = true; - let needsFrom; // export { x, y as z } [from '...'] this.expect(tt.braceL); @@ -1704,44 +2003,39 @@ export default class StatementParser extends ExpressionParser { if (this.eat(tt.braceR)) break; } - const isDefault = this.match(tt._default); - if (isDefault && !needsFrom) needsFrom = true; - const node = this.startNode(); - node.local = this.parseIdentifier(isDefault); + node.local = this.parseIdentifier(true); node.exported = this.eatContextual("as") ? this.parseIdentifier(true) : node.local.__clone(); nodes.push(this.finishNode(node, "ExportSpecifier")); } - // https://github.com/ember-cli/ember-cli/pull/3739 - if (needsFrom && !this.isContextual("from")) { - this.unexpected(); - } - return nodes; } // Parses import declaration. - parseImport(node: N.Node): N.ImportDeclaration | N.TsImportEqualsDeclaration { + parseImport(node: N.Node): N.AnyImport { // import '...' - if (this.match(tt.string)) { - node.specifiers = []; - node.source = this.parseExprAtom(); - } else { - node.specifiers = []; - this.parseImportSpecifiers(node); + node.specifiers = []; + if (!this.match(tt.string)) { + const hasDefault = this.maybeParseDefaultImportSpecifier(node); + const parseNext = !hasDefault || this.eat(tt.comma); + const hasStar = parseNext && this.maybeParseStarImportSpecifier(node); + if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node); this.expectContextual("from"); - node.source = this.match(tt.string) - ? this.parseExprAtom() - : this.unexpected(); } + node.source = this.parseImportSource(); this.semicolon(); return this.finishNode(node, "ImportDeclaration"); } + parseImportSource(): N.StringLiteral { + if (!this.match(tt.string)) this.unexpected(); + return this.parseExprAtom(); + } + // eslint-disable-next-line no-unused-vars shouldParseDefaultImport(node: N.ImportDeclaration): boolean { return this.match(tt.name); @@ -1754,13 +2048,16 @@ export default class StatementParser extends ExpressionParser { contextDescription: string, ): void { specifier.local = this.parseIdentifier(); - this.checkLVal(specifier.local, true, undefined, contextDescription); + this.checkLVal( + specifier.local, + BIND_LEXICAL, + undefined, + contextDescription, + ); node.specifiers.push(this.finishNode(specifier, type)); } - // Parses a comma-separated list of module imports. - parseImportSpecifiers(node: N.ImportDeclaration): void { - let first = true; + maybeParseDefaultImportSpecifier(node: N.ImportDeclaration): boolean { if (this.shouldParseDefaultImport(node)) { // import defaultObj, { x, y as z } from '...' this.parseImportSpecifierLocal( @@ -1769,10 +2066,12 @@ export default class StatementParser extends ExpressionParser { "ImportDefaultSpecifier", "default import specifier", ); - - if (!this.eat(tt.comma)) return; + return true; } + return false; + } + maybeParseStarImportSpecifier(node: N.ImportDeclaration): boolean { if (this.match(tt.star)) { const specifier = this.startNode(); this.next(); @@ -1784,10 +2083,13 @@ export default class StatementParser extends ExpressionParser { "ImportNamespaceSpecifier", "import namespace specifier", ); - - return; + return true; } + return false; + } + parseNamedImportSpecifiers(node: N.ImportDeclaration) { + let first = true; this.expect(tt.braceL); while (!this.eat(tt.braceR)) { if (first) { @@ -1824,7 +2126,12 @@ export default class StatementParser extends ExpressionParser { ); specifier.local = specifier.imported.__clone(); } - this.checkLVal(specifier.local, true, undefined, "import specifier"); + this.checkLVal( + specifier.local, + BIND_LEXICAL, + undefined, + "import specifier", + ); node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } } diff --git a/packages/babel-parser/src/parser/util.js b/packages/babel-parser/src/parser/util.js index d889982f8376..bd6139a2480a 100644 --- a/packages/babel-parser/src/parser/util.js +++ b/packages/babel-parser/src/parser/util.js @@ -3,7 +3,9 @@ import { types as tt, type TokenType } from "../tokenizer/types"; import Tokenizer from "../tokenizer"; import type { Node } from "../types"; -import { lineBreak } from "../util/whitespace"; +import { lineBreak, skipWhiteSpace } from "../util/whitespace"; + +const literal = /^('|")((?:\\?.)*?)\1/; // ## Parser utilities @@ -25,7 +27,7 @@ export default class UtilParser extends Tokenizer { isLookaheadRelational(op: "<" | ">"): boolean { const l = this.lookahead(); - return l.type == tt.relational && l.value == op; + return l.type === tt.relational && l.value === op; } // TODO @@ -111,6 +113,13 @@ export default class UtilParser extends Tokenizer { this.eat(type) || this.unexpected(pos, type); } + // Throws if the current token and the prev one are separated by a space. + assertNoSpace(message: string = "Unexpected space."): void { + if (this.state.start > this.state.lastTokEnd) { + this.raise(this.state.lastTokEnd, message); + } + } + // Raise an unexpected token error. Can take the expected token type // instead of a message string. @@ -147,4 +156,45 @@ export default class UtilParser extends Tokenizer { ); } } + + checkYieldAwaitInDefaultParams() { + if ( + this.state.yieldPos && + (!this.state.awaitPos || this.state.yieldPos < this.state.awaitPos) + ) { + this.raise( + this.state.yieldPos, + "Yield cannot be used as name inside a generator function", + ); + } + if (this.state.awaitPos) { + this.raise( + this.state.awaitPos, + "Await cannot be used as name inside an async function", + ); + } + } + + strictDirective(start: number): boolean { + for (;;) { + // Try to find string literal. + skipWhiteSpace.lastIndex = start; + // $FlowIgnore + start += skipWhiteSpace.exec(this.input)[0].length; + const match = literal.exec(this.input.slice(start)); + if (!match) break; + if (match[2] === "use strict") return true; + start += match[0].length; + + // Skip semicolon, if any. + skipWhiteSpace.lastIndex = start; + // $FlowIgnore + start += skipWhiteSpace.exec(this.input)[0].length; + if (this.input[start] === ";") { + start++; + } + } + + return false; + } } diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index e378b0afda9f..c1cb6a6b7e92 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -38,7 +38,7 @@ export function getPluginOption( return null; } -const PIPELINE_PROPOSALS = ["minimal"]; +const PIPELINE_PROPOSALS = ["minimal", "smart", "fsharp"]; export function validatePlugins(plugins: PluginList) { if (hasPlugin(plugins, "decorators")) { @@ -77,7 +77,7 @@ export function validatePlugins(plugins: PluginList) { ) { throw new Error( "'pipelineOperator' requires 'proposal' option whose value should be one of: " + - PIPELINE_PROPOSALS.join(", "), + PIPELINE_PROPOSALS.map(p => `'${p}'`).join(", "), ); } } @@ -88,12 +88,17 @@ import estree from "./plugins/estree"; import flow from "./plugins/flow"; import jsx from "./plugins/jsx"; import typescript from "./plugins/typescript"; +import placeholders from "./plugins/placeholders"; -// NOTE: estree must load first; flow and typescript must load last. -export const mixinPluginNames = ["estree", "jsx", "flow", "typescript"]; +// NOTE: order is important. estree must come first; placeholders must come last. export const mixinPlugins: { [name: string]: MixinPlugin } = { estree, jsx, flow, typescript, + placeholders, }; + +export const mixinPluginNames: $ReadOnlyArray = Object.keys( + mixinPlugins, +); diff --git a/packages/babel-parser/src/plugins/estree.js b/packages/babel-parser/src/plugins/estree.js index 3da593f7d9f3..a407b8ac84ca 100644 --- a/packages/babel-parser/src/plugins/estree.js +++ b/packages/babel-parser/src/plugins/estree.js @@ -4,6 +4,7 @@ import { types as tt, TokenType } from "../tokenizer/types"; import type Parser from "../parser"; import * as N from "../types"; import type { Pos, Position } from "../util/location"; +import { type BindingTypes, BIND_NONE } from "../util/scopeflags"; function isSimpleProperty(node: N.Node): boolean { return ( @@ -104,7 +105,7 @@ export default (superClass: Class): Class => checkLVal( expr: N.Expression, - isBinding: ?boolean, + bindingType: BindingTypes = BIND_NONE, checkClashes: ?{ [key: string]: boolean }, contextDescription: string, ): void { @@ -113,28 +114,36 @@ export default (superClass: Class): Class => expr.properties.forEach(prop => { this.checkLVal( prop.type === "Property" ? prop.value : prop, - isBinding, + bindingType, checkClashes, "object destructuring pattern", ); }); break; default: - super.checkLVal(expr, isBinding, checkClashes, contextDescription); + super.checkLVal(expr, bindingType, checkClashes, contextDescription); } } checkPropClash( - prop: N.ObjectMember, + prop: N.ObjectMember | N.SpreadElement, propHash: { [key: string]: boolean }, ): void { - if (prop.computed || !isSimpleProperty(prop)) return; + if ( + prop.type === "SpreadElement" || + prop.computed || + prop.method || + // $FlowIgnore + prop.shorthand + ) { + return; + } const key = prop.key; // It is either an Identifier or a String/NumericLiteral const name = key.type === "Identifier" ? key.name : String(key.value); - if (name === "__proto__") { + if (name === "__proto__" && prop.kind === "init") { if (propHash.proto) { this.raise(key.start, "Redefinition of __proto__ property"); } @@ -203,13 +212,16 @@ export default (superClass: Class): Class => isGenerator: boolean, isAsync: boolean, isConstructor: boolean, + allowsDirectSuper: boolean, ): void { this.parseMethod( method, isGenerator, isAsync, isConstructor, - "MethodDefinition", + allowsDirectSuper, + "ClassMethod", + true, ); if (method.typeParameters) { // $FlowIgnore @@ -255,8 +267,12 @@ export default (superClass: Class): Class => return node; } - parseFunctionBody(node: N.Function, allowExpression: ?boolean): void { - super.parseFunctionBody(node, allowExpression); + parseFunctionBody( + node: N.Function, + allowExpression: ?boolean, + isMethod?: boolean = false, + ): void { + super.parseFunctionBody(node, allowExpression, isMethod); node.expression = node.body.type !== "BlockStatement"; } @@ -265,7 +281,9 @@ export default (superClass: Class): Class => isGenerator: boolean, isAsync: boolean, isConstructor: boolean, + allowDirectSuper: boolean, type: string, + inClassScope: boolean = false, ): T { let funcNode = this.startNode(); funcNode.kind = node.kind; // provide kind, so super method correctly sets state @@ -274,12 +292,16 @@ export default (superClass: Class): Class => isGenerator, isAsync, isConstructor, - "FunctionExpression", + allowDirectSuper, + type, + inClassScope, ); + funcNode.type = "FunctionExpression"; delete funcNode.kind; // $FlowIgnore node.value = funcNode; + type = type === "ClassMethod" ? "MethodDefinition" : type; return this.finishNode(node, type); } @@ -300,7 +322,7 @@ export default (superClass: Class): Class => if (node) { node.type = "Property"; - if (node.kind === "method") node.kind = "init"; + if (((node: any): N.ClassMethod).kind === "method") node.kind = "init"; node.shorthand = false; } diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index 4f574776dc07..024a21baa5ab 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -6,10 +6,19 @@ import * as N from "../types"; import type { Options } from "../options"; import type { Pos, Position } from "../util/location"; import type State from "../tokenizer/state"; +import { types as tc } from "../tokenizer/context"; import * as charCodes from "charcodes"; import { isIteratorStart } from "../util/identifier"; - -const primitiveTypes = [ +import { + functionFlags, + type BindingTypes, + BIND_NONE, + BIND_LEXICAL, + SCOPE_ARROW, + SCOPE_OTHER, +} from "../util/scopeflags"; + +const reservedTypes = [ "any", "bool", "boolean", @@ -23,6 +32,9 @@ const primitiveTypes = [ "true", "typeof", "void", + "interface", + "extends", + "_", ]; function isEsModuleType(bodyElement: N.Node): boolean { @@ -83,12 +95,25 @@ export default (superClass: Class): Class => return this.getPluginOption("flow", "all") || this.flowPragma === "flow"; } + finishToken(type: TokenType, val: any): void { + if ( + type !== tt.string && + type !== tt.semi && + type !== tt.interpreterDirective + ) { + if (this.flowPragma === undefined) { + this.flowPragma = null; + } + } + return super.finishToken(type, val); + } + addComment(comment: N.Comment): void { if (this.flowPragma === undefined) { // Try to parse a flow pragma. const matches = FLOW_PRAGMA_REGEX.exec(comment.value); if (!matches) { - this.flowPragma = null; + // do nothing } else if (matches[1] === "flow") { this.flowPragma = "flow"; } else if (matches[1] === "noflow") { @@ -197,8 +222,7 @@ export default (superClass: Class): Class => id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation"); - this.finishNode(id, id.type); - + this.resetEndLocation(id); this.semicolon(); return this.finishNode(node, "DeclareFunction"); @@ -214,13 +238,13 @@ export default (superClass: Class): Class => return this.flowParseDeclareFunction(node); } else if (this.match(tt._var)) { return this.flowParseDeclareVariable(node); - } else if (this.isContextual("module")) { - if (this.lookahead().type === tt.dot) { + } else if (this.eatContextual("module")) { + if (this.match(tt.dot)) { return this.flowParseDeclareModuleExports(node); } else { if (insideModule) { this.unexpected( - null, + this.state.lastTokStart, "`declare module` cannot be used inside another `declare module`", ); } @@ -251,7 +275,7 @@ export default (superClass: Class): Class => } flowParseDeclareModule(node: N.FlowDeclareModule): N.FlowDeclareModule { - this.next(); + this.scope.enter(SCOPE_OTHER); if (this.match(tt.string)) { node.id = this.parseExprAtom(); @@ -266,14 +290,13 @@ export default (superClass: Class): Class => let bodyNode = this.startNode(); if (this.match(tt._import)) { - const lookahead = this.lookahead(); - if (lookahead.value !== "type" && lookahead.value !== "typeof") { + this.next(); + if (!this.isContextual("type") && !this.match(tt._typeof)) { this.unexpected( - null, + this.state.lastTokStart, "Imports within a `declare module` body must always be `import type` or `import typeof`", ); } - this.next(); this.parseImport(bodyNode); } else { this.expectContextual( @@ -286,6 +309,9 @@ export default (superClass: Class): Class => body.push(bodyNode); } + + this.scope.exit(); + this.expect(tt.braceR); this.finishNode(bodyNode, "BlockStatement"); @@ -340,7 +366,7 @@ export default (superClass: Class): Class => } else { if ( this.match(tt._const) || - this.match(tt._let) || + this.isLet() || ((this.isContextual("type") || this.isContextual("interface")) && !insideModule) ) { @@ -392,8 +418,7 @@ export default (superClass: Class): Class => flowParseDeclareModuleExports( node: N.FlowDeclareModuleExports, ): N.FlowDeclareModuleExports { - this.expectContextual("module"); - this.expect(tt.dot); + this.next(); this.expectContextual("exports"); node.typeAnnotation = this.flowParseTypeAnnotation(); this.semicolon(); @@ -406,7 +431,9 @@ export default (superClass: Class): Class => ): N.FlowDeclareTypeAlias { this.next(); this.flowParseTypeAlias(node); - return this.finishNode(node, "DeclareTypeAlias"); + // Don't do finishNode as we don't want to process comments twice + node.type = "DeclareTypeAlias"; + return node; } flowParseDeclareOpaqueType( @@ -414,7 +441,9 @@ export default (superClass: Class): Class => ): N.FlowDeclareOpaqueType { this.next(); this.flowParseOpaqueType(node, true); - return this.finishNode(node, "DeclareOpaqueType"); + // Don't do finishNode as we don't want to process comments twice + node.type = "DeclareOpaqueType"; + return node; } flowParseDeclareInterface( @@ -463,7 +492,13 @@ export default (superClass: Class): Class => } while (this.eat(tt.comma)); } - node.body = this.flowParseObjectType(isClass, false, false, isClass); + node.body = this.flowParseObjectType({ + allowStatic: isClass, + allowExact: false, + allowSpread: false, + allowProto: isClass, + allowInexact: false, + }); } flowParseInterfaceExtends(): N.FlowInterfaceExtends { @@ -484,9 +519,18 @@ export default (superClass: Class): Class => return this.finishNode(node, "InterfaceDeclaration"); } + checkNotUnderscore(word: string) { + if (word === "_") { + throw this.unexpected( + null, + "`_` is only allowed as a type argument to call or new", + ); + } + } + checkReservedType(word: string, startLoc: number) { - if (primitiveTypes.indexOf(word) > -1) { - this.raise(startLoc, `Cannot overwrite primitive type ${word}`); + if (reservedTypes.indexOf(word) > -1) { + this.raise(startLoc, `Cannot overwrite reserved type ${word}`); } } @@ -499,6 +543,7 @@ export default (superClass: Class): Class => flowParseTypeAlias(node: N.FlowTypeAlias): N.FlowTypeAlias { node.id = this.flowParseRestrictedIdentifier(); + this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); @@ -518,6 +563,7 @@ export default (superClass: Class): Class => ): N.FlowOpaqueType { this.expectContextual("type"); node.id = this.flowParseRestrictedIdentifier(/*liberal*/ true); + this.scope.declareName(node.id.name, BIND_LEXICAL, node.id.start); if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); @@ -542,16 +588,7 @@ export default (superClass: Class): Class => // Type annotations - flowParseTypeParameter( - allowDefault?: boolean = true, - requireDefault?: boolean = false, - ): N.TypeParameter { - if (!allowDefault && requireDefault) { - throw new Error( - "Cannot disallow a default value (`allowDefault`) while also requiring it (`requireDefault`).", - ); - } - + flowParseTypeParameter(requireDefault?: boolean = false): N.TypeParameter { const nodeStart = this.state.start; const node = this.startNode(); @@ -564,12 +601,8 @@ export default (superClass: Class): Class => node.bound = ident.typeAnnotation; if (this.match(tt.eq)) { - if (allowDefault) { - this.eat(tt.eq); - node.default = this.flowParseType(); - } else { - this.unexpected(); - } + this.eat(tt.eq); + node.default = this.flowParseType(); } else { if (requireDefault) { this.unexpected( @@ -583,9 +616,7 @@ export default (superClass: Class): Class => return this.finishNode(node, "TypeParameter"); } - flowParseTypeParameterDeclaration( - allowDefault?: boolean = true, - ): N.TypeParameterDeclaration { + flowParseTypeParameterDeclaration(): N.TypeParameterDeclaration { const oldInType = this.state.inType; const node = this.startNode(); node.params = []; @@ -602,10 +633,7 @@ export default (superClass: Class): Class => let defaultRequired = false; do { - const typeParameter = this.flowParseTypeParameter( - allowDefault, - defaultRequired, - ); + const typeParameter = this.flowParseTypeParameter(defaultRequired); node.params.push(typeParameter); @@ -632,12 +660,36 @@ export default (superClass: Class): Class => this.state.inType = true; this.expectRelational("<"); + const oldNoAnonFunctionType = this.state.noAnonFunctionType; + this.state.noAnonFunctionType = false; while (!this.isRelational(">")) { node.params.push(this.flowParseType()); if (!this.isRelational(">")) { this.expect(tt.comma); } } + this.state.noAnonFunctionType = oldNoAnonFunctionType; + this.expectRelational(">"); + + this.state.inType = oldInType; + + return this.finishNode(node, "TypeParameterInstantiation"); + } + + flowParseTypeParameterInstantiationCallOrNew(): N.TypeParameterInstantiation { + const node = this.startNode(); + const oldInType = this.state.inType; + node.params = []; + + this.state.inType = true; + + this.expectRelational("<"); + while (!this.isRelational(">")) { + node.params.push(this.flowParseTypeOrImplicitInstantiation()); + if (!this.isRelational(">")) { + this.expect(tt.comma); + } + } this.expectRelational(">"); this.state.inType = oldInType; @@ -656,7 +708,13 @@ export default (superClass: Class): Class => } while (this.eat(tt.comma)); } - node.body = this.flowParseObjectType(false, false, false, false); + node.body = this.flowParseObjectType({ + allowStatic: false, + allowExact: false, + allowSpread: false, + allowProto: false, + allowInexact: false, + }); return this.finishNode(node, "InterfaceTypeAnnotation"); } @@ -722,9 +780,7 @@ export default (superClass: Class): Class => node.typeParameters = null; if (this.isRelational("<")) { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); } this.expect(tt.parenL); @@ -754,12 +810,19 @@ export default (superClass: Class): Class => return this.finishNode(node, "ObjectTypeCallProperty"); } - flowParseObjectType( + flowParseObjectType({ + allowStatic, + allowExact, + allowSpread, + allowProto, + allowInexact, + }: { allowStatic: boolean, allowExact: boolean, allowSpread: boolean, allowProto: boolean, - ): N.FlowObjectTypeAnnotation { + allowInexact: boolean, + }): N.FlowObjectTypeAnnotation { const oldInType = this.state.inType; this.state.inType = true; @@ -772,6 +835,7 @@ export default (superClass: Class): Class => let endDelim; let exact; + let inexact = false; if (allowExact && this.match(tt.braceBarL)) { this.expect(tt.braceBarL); endDelim = tt.braceBarR; @@ -852,16 +916,21 @@ export default (superClass: Class): Class => } } - nodeStart.properties.push( - this.flowParseObjectTypeProperty( - node, - isStatic, - protoStart, - variance, - kind, - allowSpread, - ), + const propOrInexact = this.flowParseObjectTypeProperty( + node, + isStatic, + protoStart, + variance, + kind, + allowSpread, + allowInexact, ); + + if (propOrInexact === null) { + inexact = true; + } else { + nodeStart.properties.push(propOrInexact); + } } this.flowObjectTypeSemicolon(); @@ -869,6 +938,15 @@ export default (superClass: Class): Class => this.expect(endDelim); + /* The inexact flag should only be added on ObjectTypeAnnotations that + * are not the body of an interface, declare interface, or declare class. + * Since spreads are only allowed in objec types, checking that is + * sufficient here. + */ + if (allowSpread) { + nodeStart.inexact = inexact; + } + const out = this.finishNode(nodeStart, "ObjectTypeAnnotation"); this.state.inType = oldInType; @@ -883,7 +961,8 @@ export default (superClass: Class): Class => variance: ?N.FlowVariance, kind: string, allowSpread: boolean, - ): N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty { + allowInexact: boolean, + ): (N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty) | null { if (this.match(tt.ellipsis)) { if (!allowSpread) { this.unexpected( @@ -901,8 +980,30 @@ export default (superClass: Class): Class => ); } this.expect(tt.ellipsis); - node.argument = this.flowParseType(); + const isInexactToken = this.eat(tt.comma) || this.eat(tt.semi); + + if (this.match(tt.braceR)) { + if (allowInexact) return null; + this.unexpected( + null, + "Explicit inexact syntax is only allowed inside inexact objects", + ); + } + + if (this.match(tt.braceBarR)) { + this.unexpected( + null, + "Explicit inexact syntax cannot appear inside an explicit exact object type", + ); + } + if (isInexactToken) { + this.unexpected( + null, + "Explicit inexact syntax must appear at the end of an inexact object", + ); + } + node.argument = this.flowParseType(); return this.finishNode(node, "ObjectTypeSpreadProperty"); } else { node.key = this.flowParseObjectPropertyKey(); @@ -1030,7 +1131,7 @@ export default (superClass: Class): Class => node.types = []; this.expect(tt.bracketL); // We allow trailing commas - while (this.state.pos < this.input.length && !this.match(tt.bracketR)) { + while (this.state.pos < this.length && !this.match(tt.bracketR)) { node.types.push(this.flowParseType()); if (this.match(tt.bracketR)) break; this.expect(tt.comma); @@ -1096,9 +1197,6 @@ export default (superClass: Class): Class => case "any": return this.finishNode(node, "AnyTypeAnnotation"); - case "void": - return this.finishNode(node, "VoidTypeAnnotation"); - case "bool": case "boolean": return this.finishNode(node, "BooleanTypeAnnotation"); @@ -1116,6 +1214,7 @@ export default (superClass: Class): Class => return this.finishNode(node, "StringTypeAnnotation"); default: + this.checkNotUnderscore(id.name); return this.flowParseGenericType(startPos, startLoc, id); } } @@ -1146,19 +1245,32 @@ export default (superClass: Class): Class => ); case tt.braceL: - return this.flowParseObjectType(false, false, true, false); + return this.flowParseObjectType({ + allowStatic: false, + allowExact: false, + allowSpread: true, + allowProto: false, + allowInexact: true, + }); case tt.braceBarL: - return this.flowParseObjectType(false, true, true, false); + return this.flowParseObjectType({ + allowStatic: false, + allowExact: true, + allowSpread: true, + allowProto: false, + allowInexact: false, + }); case tt.bracketL: - return this.flowParseTupleType(); + this.state.noAnonFunctionType = false; + type = this.flowParseTupleType(); + this.state.noAnonFunctionType = oldNoAnonFunctionType; + return type; case tt.relational: if (this.state.value === "<") { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); this.expect(tt.parenL); tmp = this.flowParseFunctionTypeParams(); node.params = tmp.params; @@ -1243,15 +1355,27 @@ export default (superClass: Class): Class => case tt.plusMin: if (this.state.value === "-") { this.next(); - if (!this.match(tt.num)) { - this.unexpected(null, `Unexpected token, expected "number"`); + if (this.match(tt.num)) { + return this.parseLiteral( + -this.state.value, + "NumberLiteralTypeAnnotation", + node.start, + node.loc.start, + ); } - return this.parseLiteral( - -this.state.value, - "NumberLiteralTypeAnnotation", - node.start, - node.loc.start, + if (this.match(tt.bigint)) { + return this.parseLiteral( + -this.state.value, + "BigIntLiteralTypeAnnotation", + node.start, + node.loc.start, + ); + } + + this.unexpected( + null, + `Unexpected token, expected "number" or "bigint"`, ); } @@ -1262,6 +1386,16 @@ export default (superClass: Class): Class => "NumberLiteralTypeAnnotation", ); + case tt.bigint: + return this.parseLiteral( + this.state.value, + "BigIntLiteralTypeAnnotation", + ); + + case tt._void: + this.next(); + return this.finishNode(node, "VoidTypeAnnotation"); + case tt._null: this.next(); return this.finishNode(node, "NullLiteralTypeAnnotation"); @@ -1277,6 +1411,10 @@ export default (superClass: Class): Class => default: if (this.state.type.keyword === "typeof") { return this.flowParseTypeofType(); + } else if (this.state.type.keyword) { + const label = this.state.type.label; + this.next(); + return super.createIdentifier(node, label); } } @@ -1287,7 +1425,7 @@ export default (superClass: Class): Class => const startPos = this.state.start, startLoc = this.state.startLoc; let type = this.flowParsePrimaryType(); - while (!this.canInsertSemicolon() && this.match(tt.bracketL)) { + while (this.match(tt.bracketL) && !this.canInsertSemicolon()) { const node = this.startNodeAt(startPos, startLoc); node.elementType = type; this.expect(tt.bracketL); @@ -1359,6 +1497,17 @@ export default (superClass: Class): Class => return type; } + flowParseTypeOrImplicitInstantiation(): N.FlowTypeAnnotation { + if (this.state.type === tt.name && this.state.value === "_") { + const startPos = this.state.start; + const startLoc = this.state.startLoc; + const node = this.parseIdentifier(); + return this.flowParseGenericType(startPos, startLoc, node); + } else { + return this.flowParseType(); + } + } + flowParseTypeAnnotation(): N.FlowTypeAnnotation { const node = this.startNode(); node.typeAnnotation = this.flowParseTypeInitialiser(); @@ -1373,7 +1522,7 @@ export default (superClass: Class): Class => : this.flowParseRestrictedIdentifier(); if (this.match(tt.colon)) { ident.typeAnnotation = this.flowParseTypeAnnotation(); - this.finishNode(ident, ident.type); + this.resetEndLocation(ident); } return ident; } @@ -1381,12 +1530,13 @@ export default (superClass: Class): Class => typeCastToParameter(node: N.Node): N.Node { node.expression.typeAnnotation = node.typeAnnotation; - return this.finishNodeAt( + this.resetEndLocation( node.expression, - node.expression.type, node.typeAnnotation.end, node.typeAnnotation.loc.end, ); + + return node.expression; } flowParseVariance(): ?N.FlowVariance { @@ -1408,23 +1558,26 @@ export default (superClass: Class): Class => // Overrides // ================================== - parseFunctionBody(node: N.Function, allowExpressionBody: ?boolean): void { + parseFunctionBody( + node: N.Function, + allowExpressionBody: ?boolean, + isMethod?: boolean = false, + ): void { if (allowExpressionBody) { return this.forwardNoArrowParamsConversionAt(node, () => - super.parseFunctionBody(node, true), + super.parseFunctionBody(node, true, isMethod), ); } - return super.parseFunctionBody(node, false); + return super.parseFunctionBody(node, false, isMethod); } parseFunctionBodyAndFinish( node: N.BodilessFunctionOrMethodBase, type: string, - allowExpressionBody?: boolean, + isMethod?: boolean = false, ): void { - // For arrow functions, `parseArrow` handles the return type itself. - if (!allowExpressionBody && this.match(tt.colon)) { + if (this.match(tt.colon)) { const typeNode = this.startNode(); [ @@ -1439,11 +1592,11 @@ export default (superClass: Class): Class => : null; } - super.parseFunctionBodyAndFinish(node, type, allowExpressionBody); + super.parseFunctionBodyAndFinish(node, type, isMethod); } // interfaces - parseStatement(declaration: boolean, topLevel?: boolean): N.Statement { + parseStatement(context: ?string, topLevel?: boolean): N.Statement { // strict mode handling of `interface` since it's a reserved word if ( this.state.strict && @@ -1454,7 +1607,7 @@ export default (superClass: Class): Class => this.next(); return this.flowParseInterface(node); } else { - const stmt = super.parseStatement(declaration, topLevel); + const stmt = super.parseStatement(context, topLevel); // We will parse a flow pragma in any comment before the first statement. if (this.flowPragma === undefined && !this.isValidDirective(stmt)) { this.flowPragma = null; @@ -1508,7 +1661,7 @@ export default (superClass: Class): Class => this.match(tt.name) && (this.state.value === "type" || this.state.value === "interface" || - this.state.value == "opaque") + this.state.value === "opaque") ) { return false; } @@ -1637,8 +1790,11 @@ export default (superClass: Class): Class => true, "arrow function parameters", ); + // Enter scope, as checkParams defines bindings + this.scope.enter(functionFlags(false, false) | SCOPE_ARROW); // Use super's method to force the parameters to be checked - super.checkFunctionNameAndParams(node, true); + super.checkParams(node, false, true); + this.scope.exit(); } else { arrows.push(node); } @@ -1695,6 +1851,10 @@ export default (superClass: Class): Class => node = super.parseParenItem(node, startPos, startLoc); if (this.eat(tt.question)) { node.optional = true; + // Include questionmark in location of node + // Don't use this.finishNode() as otherwise we might process comments twice and + // include already consumed parens + this.resetEndLocation(node); } if (this.match(tt.colon)) { @@ -1724,15 +1884,15 @@ export default (superClass: Class): Class => super.assertModuleNodeAllowed(node); } - parseExport(node: N.ExportNamedDeclaration): N.ExportNamedDeclaration { - node = super.parseExport(node); + parseExport(node: N.Node): N.AnyExport { + const decl = super.parseExport(node); if ( - node.type === "ExportNamedDeclaration" || - node.type === "ExportAllDeclaration" + decl.type === "ExportNamedDeclaration" || + decl.type === "ExportAllDeclaration" ) { - node.exportKind = node.exportKind || "value"; + decl.exportKind = decl.exportKind || "value"; } - return node; + return decl; } parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration { @@ -1768,27 +1928,26 @@ export default (superClass: Class): Class => } } - shouldParseExportStar(): boolean { - return ( - super.shouldParseExportStar() || - (this.isContextual("type") && this.lookahead().type === tt.star) - ); - } + eatExportStar(node: N.Node): boolean { + if (super.eatExportStar(...arguments)) return true; - parseExportStar(node: N.ExportNamedDeclaration): void { - if (this.eatContextual("type")) { + if (this.isContextual("type") && this.lookahead().type === tt.star) { node.exportKind = "type"; + this.next(); + this.next(); + return true; } - return super.parseExportStar(node); + return false; } - parseExportNamespace(node: N.ExportNamedDeclaration) { - if (node.exportKind === "type") { - this.unexpected(); + maybeParseExportNamespaceSpecifier(node: N.Node): boolean { + const pos = this.state.start; + const hasNamespace = super.maybeParseExportNamespaceSpecifier(node); + if (hasNamespace && node.exportKind === "type") { + this.unexpected(pos); } - - return super.parseExportNamespace(node); + return hasNamespace; } parseClassId(node: N.Class, isStatement: boolean, optionalId: ?boolean) { @@ -1798,20 +1957,12 @@ export default (superClass: Class): Class => } } - // don't consider `void` to be a keyword as then it'll use the void token type - // and set startExpr - isKeyword(name: string): boolean { - if (this.state.inType && name === "void") { - return false; - } else { - return super.isKeyword(name); - } - } - // ensure that inside flow types, we bypass the jsx parser plugin - readToken(code: number): void { + getTokenFromCode(code: number): void { const next = this.input.charCodeAt(this.state.pos + 1); - if ( + if (code === charCodes.leftCurlyBrace && next === charCodes.verticalBar) { + return this.finishOp(tt.braceBarL, 2); + } else if ( this.state.inType && (code === charCodes.greaterThan || code === charCodes.lessThan) ) { @@ -1820,7 +1971,7 @@ export default (superClass: Class): Class => this.state.isIterator = true; return super.readWord(); } else { - return super.readToken(code); + return super.getTokenFromCode(code); } } @@ -1859,50 +2010,36 @@ export default (superClass: Class): Class => // type casts that we've found that are illegal in this context toReferencedList( exprList: $ReadOnlyArray, + isParenthesizedExpr?: boolean, ): $ReadOnlyArray { for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; - if (expr && expr._exprListItem && expr.type === "TypeCastExpression") { - this.raise(expr.start, "Unexpected type cast"); + if ( + expr && + expr.type === "TypeCastExpression" && + (!expr.extra || !expr.extra.parenthesized) && + (exprList.length > 1 || !isParenthesizedExpr) + ) { + this.raise( + expr.typeAnnotation.start, + "The type cast expression is expected to be wrapped with parenthesis", + ); } } return exprList; } - // parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents - // the position where this function is called - parseExprListItem( - allowEmpty: ?boolean, - refShorthandDefaultPos: ?Pos, - refNeedsArrowPos: ?Pos, - ): ?N.Expression { - const container = this.startNode(); - const node = super.parseExprListItem( - allowEmpty, - refShorthandDefaultPos, - refNeedsArrowPos, - ); - if (this.match(tt.colon)) { - container._exprListItem = true; - container.expression = node; - container.typeAnnotation = this.flowParseTypeAnnotation(); - return this.finishNode(container, "TypeCastExpression"); - } else { - return node; - } - } - checkLVal( expr: N.Expression, - isBinding: ?boolean, + bindingType: BindingTypes = BIND_NONE, checkClashes: ?{ [key: string]: boolean }, contextDescription: string, ): void { if (expr.type !== "TypeCastExpression") { return super.checkLVal( expr, - isBinding, + bindingType, checkClashes, contextDescription, ); @@ -1947,15 +2084,14 @@ export default (superClass: Class): Class => isGenerator: boolean, isAsync: boolean, isConstructor: boolean, + allowsDirectSuper: boolean, ): void { if ((method: $FlowFixMe).variance) { this.unexpected((method: $FlowFixMe).variance.start); } delete (method: $FlowFixMe).variance; if (this.isRelational("<")) { - method.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + method.typeParameters = this.flowParseTypeParameterDeclaration(); } super.pushClassMethod( @@ -1964,6 +2100,7 @@ export default (superClass: Class): Class => isGenerator, isAsync, isConstructor, + allowsDirectSuper, ); } @@ -2036,9 +2173,7 @@ export default (superClass: Class): Class => // method shorthand if (this.isRelational("<")) { - typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + typeParameters = this.flowParseTypeParameterDeclaration(); if (!this.match(tt.parenL)) this.unexpected(); } @@ -2073,7 +2208,7 @@ export default (superClass: Class): Class => if (this.match(tt.colon)) { param.typeAnnotation = this.flowParseTypeAnnotation(); } - this.finishNode(param, param.type); + this.resetEndLocation(param); return param; } @@ -2117,12 +2252,17 @@ export default (superClass: Class): Class => ? this.flowParseRestrictedIdentifier(true) : this.parseIdentifier(); - this.checkLVal(specifier.local, true, undefined, contextDescription); + this.checkLVal( + specifier.local, + BIND_LEXICAL, + undefined, + contextDescription, + ); node.specifiers.push(this.finishNode(specifier, type)); } // parse typeof and type imports - parseImportSpecifiers(node: N.ImportDeclaration): void { + maybeParseDefaultImportSpecifier(node: N.ImportDeclaration): boolean { node.importKind = "value"; let kind = null; @@ -2149,7 +2289,7 @@ export default (superClass: Class): Class => } } - super.parseImportSpecifiers(node); + return super.maybeParseDefaultImportSpecifier(node); } // parse import-type/typeof shorthand @@ -2227,28 +2367,34 @@ export default (superClass: Class): Class => ); } - this.checkLVal(specifier.local, true, undefined, "import specifier"); + this.checkLVal( + specifier.local, + BIND_LEXICAL, + undefined, + "import specifier", + ); node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } // parse function type parameters - function foo() {} - parseFunctionParams(node: N.Function): void { + parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { // $FlowFixMe const kind = node.kind; if (kind !== "get" && kind !== "set" && this.isRelational("<")) { - node.typeParameters = this.flowParseTypeParameterDeclaration( - /* allowDefault */ false, - ); + node.typeParameters = this.flowParseTypeParameterDeclaration(); } - super.parseFunctionParams(node); + super.parseFunctionParams(node, allowModifiers); } // parse flow type annotations on variable declarator heads - let foo: string = bar - parseVarHead(decl: N.VariableDeclarator): void { - super.parseVarHead(decl); + parseVarId( + decl: N.VariableDeclarator, + kind: "var" | "let" | "const", + ): void { + super.parseVarId(decl, kind); if (this.match(tt.colon)) { decl.id.typeAnnotation = this.flowParseTypeAnnotation(); - this.finishNode(decl.id, decl.id.type); + this.resetEndLocation(decl.id); // set end position to end of type } } @@ -2289,7 +2435,10 @@ export default (superClass: Class): Class => refNeedsArrowPos?: ?Pos, ): N.Expression { let jsxError = null; - if (tt.jsxTagStart && this.match(tt.jsxTagStart)) { + if ( + this.hasPlugin("jsx") && + (this.match(tt.jsxTagStart) || this.isRelational("<")) + ) { const state = this.state.clone(); try { return super.parseMaybeAssign( @@ -2305,7 +2454,10 @@ export default (superClass: Class): Class => // Remove `tc.j_expr` and `tc.j_oTag` from context added // by parsing `jsxTagStart` to stop the JSX plugin from // messing with the tokens - this.state.context.length -= 2; + const cLength = this.state.context.length; + if (this.state.context[cLength - 1] === tc.j_oTag) { + this.state.context.length -= 2; + } jsxError = err; } else { @@ -2410,8 +2562,9 @@ export default (superClass: Class): Class => } } - checkFunctionNameAndParams( + checkParams( node: N.Function, + allowDuplicates: boolean, isArrowFunction: ?boolean, ): void { if ( @@ -2421,7 +2574,7 @@ export default (superClass: Class): Class => return; } - return super.checkFunctionNameAndParams(node, isArrowFunction); + return super.checkParams(node, allowDuplicates, isArrowFunction); } parseParenAndDistinguishExpression(canBeArrow: boolean): N.Expression { @@ -2481,6 +2634,7 @@ export default (superClass: Class): Class => startLoc: Position, noCalls: ?boolean, subscriptState: N.ParseSubscriptState, + maybeAsyncArrow: boolean, ): N.Expression { if (this.match(tt.questionDot) && this.isLookaheadRelational("<")) { this.expectPlugin("optionalChaining"); @@ -2510,7 +2664,7 @@ export default (superClass: Class): Class => node.callee = base; const state = this.state.clone(); try { - node.typeArguments = this.flowParseTypeParameterInstantiation(); + node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew(); this.expect(tt.parenL); node.arguments = this.parseCallExpressionArguments(tt.parenR, false); if (subscriptState.optionalChainMember) { @@ -2533,6 +2687,7 @@ export default (superClass: Class): Class => startLoc, noCalls, subscriptState, + maybeAsyncArrow, ); } @@ -2541,7 +2696,7 @@ export default (superClass: Class): Class => if (this.shouldParseTypes() && this.isRelational("<")) { const state = this.state.clone(); try { - targs = this.flowParseTypeParameterInstantiation(); + targs = this.flowParseTypeParameterInstantiationCallOrNew(); } catch (e) { if (e instanceof SyntaxError) { this.state = state; @@ -2585,21 +2740,44 @@ export default (superClass: Class): Class => super.readToken_mult_modulo(code); } - skipBlockComment(): void { + readToken_pipe_amp(code: number): void { + const next = this.input.charCodeAt(this.state.pos + 1); if ( - this.hasPlugin("flow") && - this.hasPlugin("flowComments") && - this.skipFlowComment() + code === charCodes.verticalBar && + next === charCodes.rightCurlyBrace ) { + // '|}' + this.finishOp(tt.braceBarR, 2); + return; + } + + super.readToken_pipe_amp(code); + } + + parseTopLevel(file: N.File, program: N.Program): N.File { + const fileNode = super.parseTopLevel(file, program); + if (this.state.hasFlowComment) { + this.unexpected(null, "Unterminated flow-comment"); + } + return fileNode; + } + + skipBlockComment(): void { + if (this.hasPlugin("flowComments") && this.skipFlowComment()) { + if (this.state.hasFlowComment) { + this.unexpected( + null, + "Cannot have a flow comment inside another flow comment", + ); + } this.hasFlowCommentCompletion(); this.state.pos += this.skipFlowComment(); this.state.hasFlowComment = true; return; } - let end; - if (this.hasPlugin("flow") && this.state.hasFlowComment) { - end = this.input.indexOf("*-/", (this.state.pos += 2)); + if (this.state.hasFlowComment) { + const end = this.input.indexOf("*-/", (this.state.pos += 2)); if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); this.state.pos = end + 3; return; @@ -2609,17 +2787,32 @@ export default (superClass: Class): Class => } skipFlowComment(): number | boolean { - const ch2 = this.input.charCodeAt(this.state.pos + 2); - const ch3 = this.input.charCodeAt(this.state.pos + 3); + const { pos } = this.state; + let shiftToFirstNonWhiteSpace = 2; + while ( + [charCodes.space, charCodes.tab].includes( + this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace), + ) + ) { + shiftToFirstNonWhiteSpace++; + } + + const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos); + const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1); if (ch2 === charCodes.colon && ch3 === charCodes.colon) { - return 4; // check for /*:: + return shiftToFirstNonWhiteSpace + 2; // check for /*:: } - if (this.input.slice(this.state.pos + 2, 14) === "flow-include") { - return 14; // check for /*flow-include + if ( + this.input.slice( + shiftToFirstNonWhiteSpace + pos, + shiftToFirstNonWhiteSpace + pos + 12, + ) === "flow-include" + ) { + return shiftToFirstNonWhiteSpace + 12; // check for /*flow-include } if (ch2 === charCodes.colon && ch3 !== charCodes.colon) { - return 2; // check for /*:, advance only 2 steps + return shiftToFirstNonWhiteSpace; // check for /*:, advance up to : } return false; } diff --git a/packages/babel-parser/src/plugins/jsx/index.js b/packages/babel-parser/src/plugins/jsx/index.js index 0d32ea98d11f..5d3c2ec2ece1 100644 --- a/packages/babel-parser/src/plugins/jsx/index.js +++ b/packages/babel-parser/src/plugins/jsx/index.js @@ -14,6 +14,8 @@ import { isNewLine } from "../../util/whitespace"; const HEX_NUMBER = /^[\da-fA-F]+$/; const DECIMAL_NUMBER = /^\d+$/; +// Be aware that this file is always executed and not only when the plugin is enabled. +// Therefore this contexts and tokens do always exist. tc.j_oTag = new TokContext("...", true, true); @@ -79,7 +81,7 @@ export default (superClass: Class): Class => let out = ""; let chunkStart = this.state.pos; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated JSX contents"); } @@ -93,7 +95,7 @@ export default (superClass: Class): Class => ++this.state.pos; return this.finishToken(tt.jsxTagStart); } - return this.getTokenFromCode(ch); + return super.getTokenFromCode(ch); } out += this.input.slice(chunkStart, this.state.pos); return this.finishToken(tt.jsxText, out); @@ -139,7 +141,7 @@ export default (superClass: Class): Class => let out = ""; let chunkStart = ++this.state.pos; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated string constant"); } @@ -168,7 +170,7 @@ export default (superClass: Class): Class => let ch = this.input[this.state.pos]; const startPos = ++this.state.pos; - while (this.state.pos < this.input.length && count++ < 10) { + while (this.state.pos < this.length && count++ < 10) { ch = this.input[this.state.pos++]; if (ch === ";") { if (str[0] === "#") { @@ -267,7 +269,9 @@ export default (superClass: Class): Class => let node; switch (this.state.type) { case tt.braceL: - node = this.jsxParseExpressionContainer(); + node = this.startNode(); + this.next(); + node = this.jsxParseExpressionContainer(node); if (node.expression.type === "JSXEmptyExpression") { throw this.raise( node.start, @@ -308,10 +312,8 @@ export default (superClass: Class): Class => // Parse JSX spread child - jsxParseSpreadChild(): N.JSXSpreadChild { - const node = this.startNode(); - this.expect(tt.braceL); - this.expect(tt.ellipsis); + jsxParseSpreadChild(node: N.JSXSpreadChild): N.JSXSpreadChild { + this.next(); // ellipsis node.expression = this.parseExpression(); this.expect(tt.braceR); @@ -320,9 +322,9 @@ export default (superClass: Class): Class => // Parses JSX expression enclosed into curly brackets. - jsxParseExpressionContainer(): N.JSXExpressionContainer { - const node = this.startNode(); - this.next(); + jsxParseExpressionContainer( + node: N.JSXExpressionContainer, + ): N.JSXExpressionContainer { if (this.match(tt.braceR)) { node.expression = this.jsxParseEmptyExpression(); } else { @@ -421,15 +423,17 @@ export default (superClass: Class): Class => children.push(this.parseExprAtom()); break; - case tt.braceL: - if (this.lookahead().type === tt.ellipsis) { - children.push(this.jsxParseSpreadChild()); + case tt.braceL: { + const node = this.startNode(); + this.next(); + if (this.match(tt.ellipsis)) { + children.push(this.jsxParseSpreadChild(node)); } else { - children.push(this.jsxParseExpressionContainer()); + children.push(this.jsxParseExpressionContainer(node)); } break; - + } // istanbul ignore next - should never happen default: throw this.unexpected(); @@ -506,13 +510,21 @@ export default (superClass: Class): Class => return this.parseLiteral(this.state.value, "JSXText"); } else if (this.match(tt.jsxTagStart)) { return this.jsxParseElement(); + } else if ( + this.isRelational("<") && + this.input.charCodeAt(this.state.pos) !== charCodes.exclamationMark + ) { + // In case we encounter an lt token here it will always be the start of + // jsx as the lt sign is not allowed in places that expect an expression + this.finishToken(tt.jsxTagStart); + return this.jsxParseElement(); } else { return super.parseExprAtom(refShortHandDefaultPos); } } - readToken(code: number): void { - if (this.state.inPropertyName) return super.readToken(code); + getTokenFromCode(code: number): void { + if (this.state.inPropertyName) return super.getTokenFromCode(code); const context = this.curContext(); @@ -538,12 +550,16 @@ export default (superClass: Class): Class => } } - if (code === charCodes.lessThan && this.state.exprAllowed) { + if ( + code === charCodes.lessThan && + this.state.exprAllowed && + this.input.charCodeAt(this.state.pos + 1) !== charCodes.exclamationMark + ) { ++this.state.pos; return this.finishToken(tt.jsxTagStart); } - return super.readToken(code); + return super.getTokenFromCode(code); } updateContext(prevType: TokenType): void { diff --git a/packages/babel-parser/src/plugins/placeholders.js b/packages/babel-parser/src/plugins/placeholders.js new file mode 100644 index 000000000000..aafe2d235d53 --- /dev/null +++ b/packages/babel-parser/src/plugins/placeholders.js @@ -0,0 +1,316 @@ +// @flow + +import * as charCodes from "charcodes"; + +import { types as tt, TokenType } from "../tokenizer/types"; +import type Parser from "../parser"; +import * as N from "../types"; + +tt.placeholder = new TokenType("%%", { startsExpr: true }); + +export type PlaceholderTypes = + | "Identifier" + | "StringLiteral" + | "Expression" + | "Statement" + | "Declaration" + | "BlockStatement" + | "ClassBody" + | "Pattern"; + +// $PropertyType doesn't support enums. Use a fake "switch" (GetPlaceholderNode) +//type MaybePlaceholder = $PropertyType | N.Placeholder; + +type _Switch = $Call< + ( + $ElementType<$ElementType, 0>, + ) => $ElementType<$ElementType, 1>, + Value, +>; +type $Switch = _Switch; + +type NodeOf = $Switch< + T, + [ + ["Identifier", N.Identifier], + ["StringLiteral", N.StringLiteral], + ["Expression", N.Expression], + ["Statement", N.Statement], + ["Declaration", N.Declaration], + ["BlockStatement", N.BlockStatement], + ["ClassBody", N.ClassBody], + ["Pattern", N.Pattern], + ], +>; + +// Placeholder breaks everything, because its type is incompatible with +// the substituted nodes. +type MaybePlaceholder = NodeOf; // | Placeholder + +export default (superClass: Class): Class => + class extends superClass { + parsePlaceholder( + expectedNode: T, + ): /*?N.Placeholder*/ ?MaybePlaceholder { + if (this.match(tt.placeholder)) { + const node = this.startNode(); + this.next(); + this.assertNoSpace("Unexpected space in placeholder."); + + // We can't use this.parseIdentifier because + // we don't want nested placeholders. + node.name = super.parseIdentifier(/* liberal */ true); + + this.assertNoSpace("Unexpected space in placeholder."); + this.expect(tt.placeholder); + return this.finishPlaceholder(node, expectedNode); + } + } + + finishPlaceholder( + node: N.Node, + expectedNode: T, + ): /*N.Placeholder*/ MaybePlaceholder { + const isFinished = !!(node.expectedNode && node.type === "Placeholder"); + node.expectedNode = expectedNode; + + return isFinished ? node : this.finishNode(node, "Placeholder"); + } + + /* ============================================================ * + * tokenizer/index.js * + * ============================================================ */ + + getTokenFromCode(code: number) { + if ( + code === charCodes.percentSign && + this.input.charCodeAt(this.state.pos + 1) === charCodes.percentSign + ) { + return this.finishOp(tt.placeholder, 2); + } + + return super.getTokenFromCode(...arguments); + } + + /* ============================================================ * + * parser/expression.js * + * ============================================================ */ + + parseExprAtom(): MaybePlaceholder<"Expression"> { + return ( + this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments) + ); + } + + parseIdentifier(): MaybePlaceholder<"Identifier"> { + // NOTE: This function only handles identifiers outside of + // expressions and binding patterns, since they are already + // handled by the parseExprAtom and parseBindingAtom functions. + // This is needed, for example, to parse "class %%NAME%% {}". + return ( + this.parsePlaceholder("Identifier") || + super.parseIdentifier(...arguments) + ); + } + + checkReservedWord(word: string): void { + // Sometimes we call #checkReservedWord(node.name), expecting + // that node is an Identifier. If it is a Placeholder, name + // will be undefined. + if (word !== undefined) super.checkReservedWord(...arguments); + } + + /* ============================================================ * + * parser/lval.js * + * ============================================================ */ + + parseBindingAtom(): MaybePlaceholder<"Pattern"> { + return ( + this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments) + ); + } + + checkLVal(expr: N.Expression): void { + if (expr.type !== "Placeholder") super.checkLVal(...arguments); + } + + toAssignable(node: N.Node): N.Node { + if ( + node && + node.type === "Placeholder" && + node.expectedNode === "Expression" + ) { + node.expectedNode = "Pattern"; + return node; + } + return super.toAssignable(...arguments); + } + + /* ============================================================ * + * parser/statement.js * + * ============================================================ */ + + verifyBreakContinue(node: N.BreakStatement | N.ContinueStatement) { + if (node.label && node.label.type === "Placeholder") return; + super.verifyBreakContinue(...arguments); + } + + parseExpressionStatement( + node: MaybePlaceholder<"Statement">, + expr: N.Expression, + ): MaybePlaceholder<"Statement"> { + if ( + expr.type !== "Placeholder" || + (expr.extra && expr.extra.parenthesized) + ) { + return super.parseExpressionStatement(...arguments); + } + + if (this.match(tt.colon)) { + const stmt: N.LabeledStatement = node; + stmt.label = this.finishPlaceholder(expr, "Identifier"); + this.next(); + stmt.body = this.parseStatement("label"); + return this.finishNode(stmt, "LabeledStatement"); + } + + this.semicolon(); + + node.name = expr.name; + return this.finishPlaceholder(node, "Statement"); + } + + parseBlock(): MaybePlaceholder<"BlockStatement"> { + return ( + this.parsePlaceholder("BlockStatement") || + super.parseBlock(...arguments) + ); + } + + parseFunctionId(): ?MaybePlaceholder<"Identifier"> { + return ( + this.parsePlaceholder("Identifier") || + super.parseFunctionId(...arguments) + ); + } + + parseClass( + node: T, + isStatement: /* T === ClassDeclaration */ boolean, + optionalId?: boolean, + ): T { + const type = isStatement ? "ClassDeclaration" : "ClassExpression"; + + this.next(); + this.takeDecorators(node); + + const placeholder = this.parsePlaceholder("Identifier"); + if (placeholder) { + if ( + this.match(tt._extends) || + this.match(tt.placeholder) || + this.match(tt.braceL) + ) { + node.id = placeholder; + } else if (optionalId || !isStatement) { + node.id = null; + node.body = this.finishPlaceholder(placeholder, "ClassBody"); + return this.finishNode(node, type); + } else { + this.unexpected(null, "A class name is required"); + } + } else { + this.parseClassId(node, isStatement, optionalId); + } + + this.parseClassSuper(node); + node.body = + this.parsePlaceholder("ClassBody") || + this.parseClassBody(!!node.superClass); + return this.finishNode(node, type); + } + + parseExport(node: N.Node): N.Node { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseExport(...arguments); + + if (!this.isContextual("from") && !this.match(tt.comma)) { + // export %%DECL%%; + node.specifiers = []; + node.source = null; + node.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node, "ExportNamedDeclaration"); + } + + // export %%NAME%% from "foo"; + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = placeholder; + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + + return super.parseExport(node); + } + + maybeParseExportDefaultSpecifier(node: N.Node): boolean { + if (node.specifiers && node.specifiers.length > 0) { + // "export %%NAME%%" has already been parsed by #parseExport. + return true; + } + return super.maybeParseExportDefaultSpecifier(...arguments); + } + + checkExport(node: N.ExportNamedDeclaration): void { + const { specifiers } = node; + if (specifiers && specifiers.length) { + node.specifiers = specifiers.filter( + node => node.exported.type === "Placeholder", + ); + } + super.checkExport(node); + node.specifiers = specifiers; + } + + parseImport( + node: N.Node, + ): N.ImportDeclaration | N.TsImportEqualsDeclaration { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseImport(...arguments); + + node.specifiers = []; + + if (!this.isContextual("from") && !this.match(tt.comma)) { + // import %%STRING%%; + node.source = this.finishPlaceholder(placeholder, "StringLiteral"); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + // import %%DEFAULT%% ... + const specifier = this.startNodeAtNode(placeholder); + specifier.local = placeholder; + this.finishNode(specifier, "ImportDefaultSpecifier"); + node.specifiers.push(specifier); + + if (this.eat(tt.comma)) { + // import %%DEFAULT%%, * as ... + const hasStarImport = this.maybeParseStarImportSpecifier(node); + + // import %%DEFAULT%%, { ... + if (!hasStarImport) this.parseNamedImportSpecifiers(node); + } + + this.expectContextual("from"); + node.source = this.parseImportSource(); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + parseImportSource(): MaybePlaceholder<"StringLiteral"> { + // import ... from %%STRING%%; + + return ( + this.parsePlaceholder("StringLiteral") || + super.parseImportSource(...arguments) + ); + } + }; diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js deleted file mode 100644 index 514fb1e8fb28..000000000000 --- a/packages/babel-parser/src/plugins/typescript.js +++ /dev/null @@ -1,2153 +0,0 @@ -// @flow - -import type { TokenType } from "../tokenizer/types"; -import { types as tt } from "../tokenizer/types"; -import { types as ct } from "../tokenizer/context"; -import * as N from "../types"; -import type { Pos, Position } from "../util/location"; -import Parser from "../parser"; - -type TsModifier = - | "readonly" - | "abstract" - | "static" - | "public" - | "private" - | "protected"; - -function nonNull(x: ?T): T { - if (x == null) { - // $FlowIgnore - throw new Error(`Unexpected ${x} value.`); - } - return x; -} - -function assert(x: boolean): void { - if (!x) { - throw new Error("Assert fail"); - } -} - -type ParsingContext = - | "EnumMembers" - | "HeritageClauseElement" - | "TupleElementTypes" - | "TypeMembers" - | "TypeParametersOrArguments"; - -// Doesn't handle "void" or "null" because those are keywords, not identifiers. -function keywordTypeFromName( - value: string, -): N.TsKeywordTypeType | typeof undefined { - switch (value) { - case "any": - return "TSAnyKeyword"; - case "boolean": - return "TSBooleanKeyword"; - case "never": - return "TSNeverKeyword"; - case "number": - return "TSNumberKeyword"; - case "object": - return "TSObjectKeyword"; - case "string": - return "TSStringKeyword"; - case "symbol": - return "TSSymbolKeyword"; - case "undefined": - return "TSUndefinedKeyword"; - default: - return undefined; - } -} - -export default (superClass: Class): Class => - class extends superClass { - tsIsIdentifier(): boolean { - // TODO: actually a bit more complex in TypeScript, but shouldn't matter. - // See https://github.com/Microsoft/TypeScript/issues/15008 - return this.match(tt.name); - } - - tsNextTokenCanFollowModifier() { - // Note: TypeScript's implementation is much more complicated because - // more things are considered modifiers there. - // This implementation only handles modifiers not handled by @babel/parser itself. And "static". - // TODO: Would be nice to avoid lookahead. Want a hasLineBreakUpNext() method... - this.next(); - return ( - !this.hasPrecedingLineBreak() && - !this.match(tt.parenL) && - !this.match(tt.parenR) && - !this.match(tt.colon) && - !this.match(tt.eq) && - !this.match(tt.question) - ); - } - - /** Parses a modifier matching one the given modifier names. */ - tsParseModifier(allowedModifiers: T[]): ?T { - if (!this.match(tt.name)) { - return undefined; - } - - const modifier = this.state.value; - if ( - allowedModifiers.indexOf(modifier) !== -1 && - this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this)) - ) { - return modifier; - } - return undefined; - } - - tsIsListTerminator(kind: ParsingContext): boolean { - switch (kind) { - case "EnumMembers": - case "TypeMembers": - return this.match(tt.braceR); - case "HeritageClauseElement": - return this.match(tt.braceL); - case "TupleElementTypes": - return this.match(tt.bracketR); - case "TypeParametersOrArguments": - return this.isRelational(">"); - } - - throw new Error("Unreachable"); - } - - tsParseList(kind: ParsingContext, parseElement: () => T): T[] { - const result: T[] = []; - while (!this.tsIsListTerminator(kind)) { - // Skipping "parseListElement" from the TS source since that's just for error handling. - result.push(parseElement()); - } - return result; - } - - tsParseDelimitedList( - kind: ParsingContext, - parseElement: () => T, - ): T[] { - return nonNull( - this.tsParseDelimitedListWorker( - kind, - parseElement, - /* expectSuccess */ true, - ), - ); - } - - tsTryParseDelimitedList( - kind: ParsingContext, - parseElement: () => ?T, - ): ?(T[]) { - return this.tsParseDelimitedListWorker( - kind, - parseElement, - /* expectSuccess */ false, - ); - } - - /** - * If !expectSuccess, returns undefined instead of failing to parse. - * If expectSuccess, parseElement should always return a defined value. - */ - tsParseDelimitedListWorker( - kind: ParsingContext, - parseElement: () => ?T, - expectSuccess: boolean, - ): ?(T[]) { - const result = []; - - while (true) { - if (this.tsIsListTerminator(kind)) { - break; - } - - const element = parseElement(); - if (element == null) { - return undefined; - } - result.push(element); - - if (this.eat(tt.comma)) { - continue; - } - - if (this.tsIsListTerminator(kind)) { - break; - } - - if (expectSuccess) { - // This will fail with an error about a missing comma - this.expect(tt.comma); - } - return undefined; - } - - return result; - } - - tsParseBracketedList( - kind: ParsingContext, - parseElement: () => T, - bracket: boolean, - skipFirstToken: boolean, - ): T[] { - if (!skipFirstToken) { - if (bracket) { - this.expect(tt.bracketL); - } else { - this.expectRelational("<"); - } - } - - const result = this.tsParseDelimitedList(kind, parseElement); - - if (bracket) { - this.expect(tt.bracketR); - } else { - this.expectRelational(">"); - } - - return result; - } - - tsParseEntityName(allowReservedWords: boolean): N.TsEntityName { - let entity: N.TsEntityName = this.parseIdentifier(); - while (this.eat(tt.dot)) { - const node: N.TsQualifiedName = this.startNodeAtNode(entity); - node.left = entity; - node.right = this.parseIdentifier(allowReservedWords); - entity = this.finishNode(node, "TSQualifiedName"); - } - return entity; - } - - tsParseTypeReference(): N.TsTypeReference { - const node: N.TsTypeReference = this.startNode(); - node.typeName = this.tsParseEntityName(/* allowReservedWords */ false); - if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); - } - return this.finishNode(node, "TSTypeReference"); - } - - tsParseThisTypePredicate(lhs: N.TsThisType): N.TsTypePredicate { - this.next(); - const node: N.TsTypePredicate = this.startNode(); - node.parameterName = lhs; - node.typeAnnotation = this.tsParseTypeAnnotation(/* eatColon */ false); - return this.finishNode(node, "TSTypePredicate"); - } - - tsParseThisTypeNode(): N.TsThisType { - const node: N.TsThisType = this.startNode(); - this.next(); - return this.finishNode(node, "TSThisType"); - } - - tsParseTypeQuery(): N.TsTypeQuery { - const node: N.TsTypeQuery = this.startNode(); - this.expect(tt._typeof); - node.exprName = this.tsParseEntityName(/* allowReservedWords */ true); - return this.finishNode(node, "TSTypeQuery"); - } - - tsParseTypeParameter(): N.TsTypeParameter { - const node: N.TsTypeParameter = this.startNode(); - node.name = this.parseIdentifierName(node.start); - node.constraint = this.tsEatThenParseType(tt._extends); - node.default = this.tsEatThenParseType(tt.eq); - return this.finishNode(node, "TSTypeParameter"); - } - - tsTryParseTypeParameters(): ?N.TsTypeParameterDeclaration { - if (this.isRelational("<")) { - return this.tsParseTypeParameters(); - } - } - - tsParseTypeParameters() { - const node: N.TsTypeParameterDeclaration = this.startNode(); - - if (this.isRelational("<") || this.match(tt.jsxTagStart)) { - this.next(); - } else { - this.unexpected(); - } - - node.params = this.tsParseBracketedList( - "TypeParametersOrArguments", - this.tsParseTypeParameter.bind(this), - /* bracket */ false, - /* skipFirstToken */ true, - ); - return this.finishNode(node, "TSTypeParameterDeclaration"); - } - - // Note: In TypeScript implementation we must provide `yieldContext` and `awaitContext`, - // but here it's always false, because this is only used for types. - tsFillSignature( - returnToken: TokenType, - signature: N.TsSignatureDeclaration, - ): void { - // Arrow fns *must* have return token (`=>`). Normal functions can omit it. - const returnTokenRequired = returnToken === tt.arrow; - signature.typeParameters = this.tsTryParseTypeParameters(); - this.expect(tt.parenL); - signature.parameters = this.tsParseBindingListForSignature(); - if (returnTokenRequired) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation( - returnToken, - ); - } else if (this.match(returnToken)) { - signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation( - returnToken, - ); - } - } - - tsParseBindingListForSignature(): $ReadOnlyArray< - N.Identifier | N.RestElement, - > { - return this.parseBindingList(tt.parenR).map(pattern => { - if (pattern.type !== "Identifier" && pattern.type !== "RestElement") { - throw this.unexpected( - pattern.start, - "Name in a signature must be an Identifier.", - ); - } - return pattern; - }); - } - - tsParseTypeMemberSemicolon(): void { - if (!this.eat(tt.comma)) { - this.semicolon(); - } - } - - tsParseSignatureMember( - kind: "TSCallSignatureDeclaration" | "TSConstructSignatureDeclaration", - ): N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration { - const node: - | N.TsCallSignatureDeclaration - | N.TsConstructSignatureDeclaration = this.startNode(); - if (kind === "TSConstructSignatureDeclaration") { - this.expect(tt._new); - } - this.tsFillSignature(tt.colon, node); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(node, kind); - } - - tsIsUnambiguouslyIndexSignature() { - this.next(); // Skip '{' - return this.eat(tt.name) && this.match(tt.colon); - } - - tsTryParseIndexSignature(node: N.TsIndexSignature): ?N.TsIndexSignature { - if ( - !( - this.match(tt.bracketL) && - this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)) - ) - ) { - return undefined; - } - - this.expect(tt.bracketL); - const id = this.parseIdentifier(); - this.expect(tt.colon); - id.typeAnnotation = this.tsParseTypeAnnotation(/* eatColon */ false); - this.expect(tt.bracketR); - node.parameters = [id]; - - const type = this.tsTryParseTypeAnnotation(); - if (type) node.typeAnnotation = type; - this.tsParseTypeMemberSemicolon(); - return this.finishNode(node, "TSIndexSignature"); - } - - tsParsePropertyOrMethodSignature( - node: N.TsPropertySignature | N.TsMethodSignature, - readonly: boolean, - ): N.TsPropertySignature | N.TsMethodSignature { - this.parsePropertyName(node); - if (this.eat(tt.question)) node.optional = true; - const nodeAny: any = node; - - if (!readonly && (this.match(tt.parenL) || this.isRelational("<"))) { - const method: N.TsMethodSignature = nodeAny; - this.tsFillSignature(tt.colon, method); - this.tsParseTypeMemberSemicolon(); - return this.finishNode(method, "TSMethodSignature"); - } else { - const property: N.TsPropertySignature = nodeAny; - if (readonly) property.readonly = true; - const type = this.tsTryParseTypeAnnotation(); - if (type) property.typeAnnotation = type; - this.tsParseTypeMemberSemicolon(); - return this.finishNode(property, "TSPropertySignature"); - } - } - - tsParseTypeMember(): N.TsTypeElement { - if (this.match(tt.parenL) || this.isRelational("<")) { - return this.tsParseSignatureMember("TSCallSignatureDeclaration"); - } - if ( - this.match(tt._new) && - this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this)) - ) { - return this.tsParseSignatureMember("TSConstructSignatureDeclaration"); - } - // Instead of fullStart, we create a node here. - const node: any = this.startNode(); - const readonly = !!this.tsParseModifier(["readonly"]); - - const idx = this.tsTryParseIndexSignature(node); - if (idx) { - if (readonly) node.readonly = true; - return idx; - } - return this.tsParsePropertyOrMethodSignature(node, readonly); - } - - tsIsStartOfConstructSignature() { - this.next(); - return this.match(tt.parenL) || this.isRelational("<"); - } - - tsParseTypeLiteral(): N.TsTypeLiteral { - const node: N.TsTypeLiteral = this.startNode(); - node.members = this.tsParseObjectTypeMembers(); - return this.finishNode(node, "TSTypeLiteral"); - } - - tsParseObjectTypeMembers(): $ReadOnlyArray { - this.expect(tt.braceL); - const members = this.tsParseList( - "TypeMembers", - this.tsParseTypeMember.bind(this), - ); - this.expect(tt.braceR); - return members; - } - - tsIsStartOfMappedType(): boolean { - this.next(); - if (this.eat(tt.plusMin)) { - return this.isContextual("readonly"); - } - if (this.isContextual("readonly")) { - this.next(); - } - if (!this.match(tt.bracketL)) { - return false; - } - this.next(); - if (!this.tsIsIdentifier()) { - return false; - } - this.next(); - return this.match(tt._in); - } - - tsParseMappedTypeParameter(): N.TsTypeParameter { - const node: N.TsTypeParameter = this.startNode(); - node.name = this.parseIdentifierName(node.start); - node.constraint = this.tsExpectThenParseType(tt._in); - return this.finishNode(node, "TSTypeParameter"); - } - - tsParseMappedType(): N.TsMappedType { - const node: N.TsMappedType = this.startNode(); - - this.expect(tt.braceL); - - if (this.match(tt.plusMin)) { - node.readonly = this.state.value; - this.next(); - this.expectContextual("readonly"); - } else if (this.eatContextual("readonly")) { - node.readonly = true; - } - - this.expect(tt.bracketL); - node.typeParameter = this.tsParseMappedTypeParameter(); - this.expect(tt.bracketR); - - if (this.match(tt.plusMin)) { - node.optional = this.state.value; - this.next(); - this.expect(tt.question); - } else if (this.eat(tt.question)) { - node.optional = true; - } - - node.typeAnnotation = this.tsTryParseType(); - this.semicolon(); - this.expect(tt.braceR); - - return this.finishNode(node, "TSMappedType"); - } - - tsParseTupleType(): N.TsTupleType { - const node: N.TsTupleType = this.startNode(); - node.elementTypes = this.tsParseBracketedList( - "TupleElementTypes", - this.tsParseType.bind(this), - /* bracket */ true, - /* skipFirstToken */ false, - ); - return this.finishNode(node, "TSTupleType"); - } - - tsParseParenthesizedType(): N.TsParenthesizedType { - const node = this.startNode(); - this.expect(tt.parenL); - node.typeAnnotation = this.tsParseType(); - this.expect(tt.parenR); - return this.finishNode(node, "TSParenthesizedType"); - } - - tsParseFunctionOrConstructorType( - type: "TSFunctionType" | "TSConstructorType", - ): N.TsFunctionOrConstructorType { - const node: N.TsFunctionOrConstructorType = this.startNode(); - if (type === "TSConstructorType") { - this.expect(tt._new); - } - this.tsFillSignature(tt.arrow, node); - return this.finishNode(node, type); - } - - tsParseLiteralTypeNode(): N.TsLiteralType { - const node: N.TsLiteralType = this.startNode(); - node.literal = (() => { - switch (this.state.type) { - case tt.num: - return this.parseLiteral(this.state.value, "NumericLiteral"); - case tt.string: - return this.parseLiteral(this.state.value, "StringLiteral"); - case tt._true: - case tt._false: - return this.parseBooleanLiteral(); - default: - throw this.unexpected(); - } - })(); - return this.finishNode(node, "TSLiteralType"); - } - - tsParseNonArrayType(): N.TsType { - switch (this.state.type) { - case tt.name: - case tt._void: - case tt._null: { - const type = this.match(tt._void) - ? "TSVoidKeyword" - : this.match(tt._null) - ? "TSNullKeyword" - : keywordTypeFromName(this.state.value); - if (type !== undefined && this.lookahead().type !== tt.dot) { - const node: N.TsKeywordType = this.startNode(); - this.next(); - return this.finishNode(node, type); - } - return this.tsParseTypeReference(); - } - case tt.string: - case tt.num: - case tt._true: - case tt._false: - return this.tsParseLiteralTypeNode(); - case tt.plusMin: - if (this.state.value === "-") { - const node: N.TsLiteralType = this.startNode(); - this.next(); - if (!this.match(tt.num)) { - throw this.unexpected(); - } - node.literal = this.parseLiteral( - -this.state.value, - "NumericLiteral", - node.start, - node.loc.start, - ); - return this.finishNode(node, "TSLiteralType"); - } - break; - case tt._this: { - const thisKeyword = this.tsParseThisTypeNode(); - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - return this.tsParseThisTypePredicate(thisKeyword); - } else { - return thisKeyword; - } - } - case tt._typeof: - return this.tsParseTypeQuery(); - case tt.braceL: - return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) - ? this.tsParseMappedType() - : this.tsParseTypeLiteral(); - case tt.bracketL: - return this.tsParseTupleType(); - case tt.parenL: - return this.tsParseParenthesizedType(); - } - - throw this.unexpected(); - } - - tsParseArrayTypeOrHigher(): N.TsType { - let type = this.tsParseNonArrayType(); - while (!this.hasPrecedingLineBreak() && this.eat(tt.bracketL)) { - if (this.match(tt.bracketR)) { - const node: N.TsArrayType = this.startNodeAtNode(type); - node.elementType = type; - this.expect(tt.bracketR); - type = this.finishNode(node, "TSArrayType"); - } else { - const node: N.TsIndexedAccessType = this.startNodeAtNode(type); - node.objectType = type; - node.indexType = this.tsParseType(); - this.expect(tt.bracketR); - type = this.finishNode(node, "TSIndexedAccessType"); - } - } - return type; - } - - tsParseTypeOperator(operator: "keyof" | "unique"): N.TsTypeOperator { - const node: N.TsTypeOperator = this.startNode(); - this.expectContextual(operator); - node.operator = operator; - node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); - return this.finishNode(node, "TSTypeOperator"); - } - - tsParseInferType(): N.TsInferType { - const node = this.startNode(); - this.expectContextual("infer"); - const typeParameter = this.startNode(); - typeParameter.name = this.parseIdentifierName(typeParameter.start); - node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter"); - return this.finishNode(node, "TSInferType"); - } - - tsParseTypeOperatorOrHigher(): N.TsType { - const operator = ["keyof", "unique"].find(kw => this.isContextual(kw)); - return operator - ? this.tsParseTypeOperator(operator) - : this.isContextual("infer") - ? this.tsParseInferType() - : this.tsParseArrayTypeOrHigher(); - } - - tsParseUnionOrIntersectionType( - kind: "TSUnionType" | "TSIntersectionType", - parseConstituentType: () => N.TsType, - operator: TokenType, - ): N.TsType { - this.eat(operator); - let type = parseConstituentType(); - if (this.match(operator)) { - const types = [type]; - while (this.eat(operator)) { - types.push(parseConstituentType()); - } - const node: N.TsUnionType | N.TsIntersectionType = this.startNodeAtNode( - type, - ); - node.types = types; - type = this.finishNode(node, kind); - } - return type; - } - - tsParseIntersectionTypeOrHigher(): N.TsType { - return this.tsParseUnionOrIntersectionType( - "TSIntersectionType", - this.tsParseTypeOperatorOrHigher.bind(this), - tt.bitwiseAND, - ); - } - - tsParseUnionTypeOrHigher() { - return this.tsParseUnionOrIntersectionType( - "TSUnionType", - this.tsParseIntersectionTypeOrHigher.bind(this), - tt.bitwiseOR, - ); - } - - tsIsStartOfFunctionType() { - if (this.isRelational("<")) { - return true; - } - return ( - this.match(tt.parenL) && - this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)) - ); - } - - tsSkipParameterStart(): boolean { - if (this.match(tt.name) || this.match(tt._this)) { - this.next(); - return true; - } - return false; - } - - tsIsUnambiguouslyStartOfFunctionType(): boolean { - this.next(); - if (this.match(tt.parenR) || this.match(tt.ellipsis)) { - // ( ) - // ( ... - return true; - } - if (this.tsSkipParameterStart()) { - if ( - this.match(tt.colon) || - this.match(tt.comma) || - this.match(tt.question) || - this.match(tt.eq) - ) { - // ( xxx : - // ( xxx , - // ( xxx ? - // ( xxx = - return true; - } - if (this.match(tt.parenR)) { - this.next(); - if (this.match(tt.arrow)) { - // ( xxx ) => - return true; - } - } - } - return false; - } - - tsParseTypeOrTypePredicateAnnotation( - returnToken: TokenType, - ): N.TsTypeAnnotation { - return this.tsInType(() => { - const t: N.TsTypeAnnotation = this.startNode(); - this.expect(returnToken); - - const typePredicateVariable = - this.tsIsIdentifier() && - this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); - - if (!typePredicateVariable) { - return this.tsParseTypeAnnotation(/* eatColon */ false, t); - } - - const type = this.tsParseTypeAnnotation(/* eatColon */ false); - - const node: N.TsTypePredicate = this.startNodeAtNode( - typePredicateVariable, - ); - node.parameterName = typePredicateVariable; - node.typeAnnotation = type; - t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); - return this.finishNode(t, "TSTypeAnnotation"); - }); - } - - tsTryParseTypeOrTypePredicateAnnotation(): ?N.TsTypeAnnotation { - return this.match(tt.colon) - ? this.tsParseTypeOrTypePredicateAnnotation(tt.colon) - : undefined; - } - - tsTryParseTypeAnnotation(): ?N.TsTypeAnnotation { - return this.match(tt.colon) ? this.tsParseTypeAnnotation() : undefined; - } - - tsTryParseType(): ?N.TsType { - return this.tsEatThenParseType(tt.colon); - } - - tsParseTypePredicatePrefix(): ?N.Identifier { - const id = this.parseIdentifier(); - if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { - this.next(); - return id; - } - } - - tsParseTypeAnnotation( - eatColon = true, - t: N.TsTypeAnnotation = this.startNode(), - ): N.TsTypeAnnotation { - this.tsInType(() => { - if (eatColon) this.expect(tt.colon); - t.typeAnnotation = this.tsParseType(); - }); - return this.finishNode(t, "TSTypeAnnotation"); - } - - /** Be sure to be in a type context before calling this, using `tsInType`. */ - tsParseType(): N.TsType { - // Need to set `state.inType` so that we don't parse JSX in a type context. - assert(this.state.inType); - const type = this.tsParseNonConditionalType(); - if (this.hasPrecedingLineBreak() || !this.eat(tt._extends)) { - return type; - } - const node: N.TsConditionalType = this.startNodeAtNode(type); - node.checkType = type; - node.extendsType = this.tsParseNonConditionalType(); - this.expect(tt.question); - node.trueType = this.tsParseType(); - this.expect(tt.colon); - node.falseType = this.tsParseType(); - return this.finishNode(node, "TSConditionalType"); - } - - tsParseNonConditionalType(): N.TsType { - if (this.tsIsStartOfFunctionType()) { - return this.tsParseFunctionOrConstructorType("TSFunctionType"); - } - if (this.match(tt._new)) { - // As in `new () => Date` - return this.tsParseFunctionOrConstructorType("TSConstructorType"); - } - return this.tsParseUnionTypeOrHigher(); - } - - tsParseTypeAssertion(): N.TsTypeAssertion { - const node: N.TsTypeAssertion = this.startNode(); - // Not actually necessary to set state.inType because we never reach here if JSX plugin is enabled, - // but need `tsInType` to satisfy the assertion in `tsParseType`. - node.typeAnnotation = this.tsInType(() => this.tsParseType()); - this.expectRelational(">"); - node.expression = this.parseMaybeUnary(); - return this.finishNode(node, "TSTypeAssertion"); - } - - tsParseHeritageClause(): $ReadOnlyArray { - return this.tsParseDelimitedList( - "HeritageClauseElement", - this.tsParseExpressionWithTypeArguments.bind(this), - ); - } - - tsParseExpressionWithTypeArguments(): N.TsExpressionWithTypeArguments { - const node: N.TsExpressionWithTypeArguments = this.startNode(); - // Note: TS uses parseLeftHandSideExpressionOrHigher, - // then has grammar errors later if it's not an EntityName. - node.expression = this.tsParseEntityName(/* allowReservedWords */ false); - if (this.isRelational("<")) { - node.typeParameters = this.tsParseTypeArguments(); - } - - return this.finishNode(node, "TSExpressionWithTypeArguments"); - } - - tsParseInterfaceDeclaration( - node: N.TsInterfaceDeclaration, - ): N.TsInterfaceDeclaration { - node.id = this.parseIdentifier(); - node.typeParameters = this.tsTryParseTypeParameters(); - if (this.eat(tt._extends)) { - node.extends = this.tsParseHeritageClause(); - } - const body: N.TSInterfaceBody = this.startNode(); - body.body = this.tsParseObjectTypeMembers(); - node.body = this.finishNode(body, "TSInterfaceBody"); - return this.finishNode(node, "TSInterfaceDeclaration"); - } - - tsParseTypeAliasDeclaration( - node: N.TsTypeAliasDeclaration, - ): N.TsTypeAliasDeclaration { - node.id = this.parseIdentifier(); - node.typeParameters = this.tsTryParseTypeParameters(); - node.typeAnnotation = this.tsExpectThenParseType(tt.eq); - this.semicolon(); - return this.finishNode(node, "TSTypeAliasDeclaration"); - } - - tsInNoContext(cb: () => T): T { - const oldContext = this.state.context; - this.state.context = [oldContext[0]]; - try { - return cb(); - } finally { - this.state.context = oldContext; - } - } - - /** - * Runs `cb` in a type context. - * This should be called one token *before* the first type token, - * so that the call to `next()` is run in type context. - */ - tsInType(cb: () => T): T { - const oldInType = this.state.inType; - this.state.inType = true; - try { - return cb(); - } finally { - this.state.inType = oldInType; - } - } - - tsEatThenParseType(token: TokenType): N.TsType | typeof undefined { - return !this.match(token) ? undefined : this.tsNextThenParseType(); - } - - tsExpectThenParseType(token: TokenType): N.TsType { - return this.tsDoThenParseType(() => this.expect(token)); - } - - tsNextThenParseType(): N.TsType { - return this.tsDoThenParseType(() => this.next()); - } - - tsDoThenParseType(cb: () => void): N.TsType { - return this.tsInType(() => { - cb(); - return this.tsParseType(); - }); - } - - tsParseEnumMember(): N.TsEnumMember { - const node: N.TsEnumMember = this.startNode(); - // Computed property names are grammar errors in an enum, so accept just string literal or identifier. - node.id = this.match(tt.string) - ? this.parseLiteral(this.state.value, "StringLiteral") - : this.parseIdentifier(/* liberal */ true); - if (this.eat(tt.eq)) { - node.initializer = this.parseMaybeAssign(); - } - return this.finishNode(node, "TSEnumMember"); - } - - tsParseEnumDeclaration( - node: N.TsEnumDeclaration, - isConst: boolean, - ): N.TsEnumDeclaration { - if (isConst) node.const = true; - node.id = this.parseIdentifier(); - this.expect(tt.braceL); - node.members = this.tsParseDelimitedList( - "EnumMembers", - this.tsParseEnumMember.bind(this), - ); - this.expect(tt.braceR); - return this.finishNode(node, "TSEnumDeclaration"); - } - - tsParseModuleBlock(): N.TsModuleBlock { - const node: N.TsModuleBlock = this.startNode(); - this.expect(tt.braceL); - // Inside of a module block is considered "top-level", meaning it can have imports and exports. - this.parseBlockOrModuleBlockBody( - (node.body = []), - /* directives */ undefined, - /* topLevel */ true, - /* end */ tt.braceR, - ); - return this.finishNode(node, "TSModuleBlock"); - } - - tsParseModuleOrNamespaceDeclaration( - node: N.TsModuleDeclaration, - ): N.TsModuleDeclaration { - node.id = this.parseIdentifier(); - if (this.eat(tt.dot)) { - const inner = this.startNode(); - this.tsParseModuleOrNamespaceDeclaration(inner); - node.body = inner; - } else { - node.body = this.tsParseModuleBlock(); - } - return this.finishNode(node, "TSModuleDeclaration"); - } - - tsParseAmbientExternalModuleDeclaration( - node: N.TsModuleDeclaration, - ): N.TsModuleDeclaration { - if (this.isContextual("global")) { - node.global = true; - node.id = this.parseIdentifier(); - } else if (this.match(tt.string)) { - node.id = this.parseExprAtom(); - } else { - this.unexpected(); - } - - if (this.match(tt.braceL)) { - node.body = this.tsParseModuleBlock(); - } else { - this.semicolon(); - } - - return this.finishNode(node, "TSModuleDeclaration"); - } - - tsParseImportEqualsDeclaration( - node: N.TsImportEqualsDeclaration, - isExport?: boolean, - ): N.TsImportEqualsDeclaration { - node.isExport = isExport || false; - node.id = this.parseIdentifier(); - this.expect(tt.eq); - node.moduleReference = this.tsParseModuleReference(); - this.semicolon(); - return this.finishNode(node, "TSImportEqualsDeclaration"); - } - - tsIsExternalModuleReference(): boolean { - return ( - this.isContextual("require") && this.lookahead().type === tt.parenL - ); - } - - tsParseModuleReference(): N.TsModuleReference { - return this.tsIsExternalModuleReference() - ? this.tsParseExternalModuleReference() - : this.tsParseEntityName(/* allowReservedWords */ false); - } - - tsParseExternalModuleReference(): N.TsExternalModuleReference { - const node: N.TsExternalModuleReference = this.startNode(); - this.expectContextual("require"); - this.expect(tt.parenL); - if (!this.match(tt.string)) { - throw this.unexpected(); - } - node.expression = this.parseLiteral(this.state.value, "StringLiteral"); - this.expect(tt.parenR); - return this.finishNode(node, "TSExternalModuleReference"); - } - - // Utilities - - tsLookAhead(f: () => T): T { - const state = this.state.clone(); - const res = f(); - this.state = state; - return res; - } - - tsTryParseAndCatch(f: () => T): ?T { - const state = this.state.clone(); - try { - return f(); - } catch (e) { - if (e instanceof SyntaxError) { - this.state = state; - return undefined; - } - throw e; - } - } - - tsTryParse(f: () => ?T): ?T { - const state = this.state.clone(); - const result = f(); - if (result !== undefined && result !== false) { - return result; - } else { - this.state = state; - return undefined; - } - } - - nodeWithSamePosition(original: N.Node, type: string): T { - const node = this.startNodeAtNode(original); - node.type = type; - node.end = original.end; - node.loc.end = original.loc.end; - - if (original.leadingComments) { - node.leadingComments = original.leadingComments; - } - if (original.trailingComments) { - node.trailingComments = original.trailingComments; - } - if (original.innerComments) node.innerComments = original.innerComments; - - return node; - } - - tsTryParseDeclare(nany: any): ?N.Declaration { - switch (this.state.type) { - case tt._function: - this.next(); - return this.parseFunction(nany, /* isStatement */ true); - case tt._class: - return this.parseClass( - nany, - /* isStatement */ true, - /* optionalId */ false, - ); - case tt._const: - if (this.match(tt._const) && this.isLookaheadContextual("enum")) { - // `const enum = 0;` not allowed because "enum" is a strict mode reserved word. - this.expect(tt._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(nany, /* isConst */ true); - } - // falls through - case tt._var: - case tt._let: - return this.parseVarStatement(nany, this.state.type); - case tt.name: { - const value = this.state.value; - if (value === "global") { - return this.tsParseAmbientExternalModuleDeclaration(nany); - } else { - return this.tsParseDeclaration(nany, value, /* next */ true); - } - } - } - } - - // Note: this won't be called unless the keyword is allowed in `shouldParseExportDeclaration`. - tsTryParseExportDeclaration(): ?N.Declaration { - return this.tsParseDeclaration( - this.startNode(), - this.state.value, - /* next */ true, - ); - } - - tsParseExpressionStatement(node: any, expr: N.Identifier): ?N.Declaration { - switch (expr.name) { - case "declare": { - const declaration = this.tsTryParseDeclare(node); - if (declaration) { - declaration.declare = true; - return declaration; - } - break; - } - case "global": - // `global { }` (with no `declare`) may appear inside an ambient module declaration. - // Would like to use tsParseAmbientExternalModuleDeclaration here, but already ran past "global". - if (this.match(tt.braceL)) { - const mod: N.TsModuleDeclaration = node; - mod.global = true; - mod.id = expr; - mod.body = this.tsParseModuleBlock(); - return this.finishNode(mod, "TSModuleDeclaration"); - } - break; - - default: - return this.tsParseDeclaration(node, expr.name, /* next */ false); - } - } - - // Common to tsTryParseDeclare, tsTryParseExportDeclaration, and tsParseExpressionStatement. - tsParseDeclaration( - node: any, - value: string, - next: boolean, - ): ?N.Declaration { - switch (value) { - case "abstract": - if (next || this.match(tt._class)) { - const cls: N.ClassDeclaration = node; - cls.abstract = true; - if (next) this.next(); - return this.parseClass( - cls, - /* isStatement */ true, - /* optionalId */ false, - ); - } - break; - - case "enum": - if (next || this.match(tt.name)) { - if (next) this.next(); - return this.tsParseEnumDeclaration(node, /* isConst */ false); - } - break; - - case "interface": - if (next || this.match(tt.name)) { - if (next) this.next(); - return this.tsParseInterfaceDeclaration(node); - } - break; - - case "module": - if (next) this.next(); - if (this.match(tt.string)) { - return this.tsParseAmbientExternalModuleDeclaration(node); - } else if (next || this.match(tt.name)) { - return this.tsParseModuleOrNamespaceDeclaration(node); - } - break; - - case "namespace": - if (next || this.match(tt.name)) { - if (next) this.next(); - return this.tsParseModuleOrNamespaceDeclaration(node); - } - break; - - case "type": - if (next || this.match(tt.name)) { - if (next) this.next(); - return this.tsParseTypeAliasDeclaration(node); - } - break; - } - } - - tsTryParseGenericAsyncArrowFunction( - startPos: number, - startLoc: Position, - ): ?N.ArrowFunctionExpression { - const res: ?N.ArrowFunctionExpression = this.tsTryParseAndCatch(() => { - const node: N.ArrowFunctionExpression = this.startNodeAt( - startPos, - startLoc, - ); - node.typeParameters = this.tsParseTypeParameters(); - // Don't use overloaded parseFunctionParams which would look for "<" again. - super.parseFunctionParams(node); - node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); - this.expect(tt.arrow); - return node; - }); - - if (!res) { - return undefined; - } - - res.id = null; - res.generator = false; - res.expression = true; // May be set again by parseFunctionBody. - res.async = true; - this.parseFunctionBody(res, true); - return this.finishNode(res, "ArrowFunctionExpression"); - } - - tsParseTypeArguments(): N.TsTypeParameterInstantiation { - const node = this.startNode(); - node.params = this.tsInType(() => - // Temporarily remove a JSX parsing context, which makes us scan different tokens. - this.tsInNoContext(() => { - this.expectRelational("<"); - return this.tsParseDelimitedList( - "TypeParametersOrArguments", - this.tsParseType.bind(this), - ); - }), - ); - // This reads the next token after the `>` too, so do this in the enclosing context. - // But be sure not to parse a regex in the jsx expression ` />`, so set exprAllowed = false - this.state.exprAllowed = false; - this.expectRelational(">"); - return this.finishNode(node, "TSTypeParameterInstantiation"); - } - - tsIsDeclarationStart(): boolean { - if (this.match(tt.name)) { - switch (this.state.value) { - case "abstract": - case "declare": - case "enum": - case "interface": - case "module": - case "namespace": - case "type": - return true; - } - } - - return false; - } - - // ====================================================== - // OVERRIDES - // ====================================================== - - isExportDefaultSpecifier(): boolean { - if (this.tsIsDeclarationStart()) return false; - return super.isExportDefaultSpecifier(); - } - - parseAssignableListItem( - allowModifiers: ?boolean, - decorators: N.Decorator[], - ): N.Pattern | N.TSParameterProperty { - let accessibility: ?N.Accessibility; - let readonly = false; - if (allowModifiers) { - accessibility = this.parseAccessModifier(); - readonly = !!this.tsParseModifier(["readonly"]); - } - - const left = this.parseMaybeDefault(); - this.parseAssignableListItemTypes(left); - const elt = this.parseMaybeDefault(left.start, left.loc.start, left); - if (accessibility || readonly) { - const pp: N.TSParameterProperty = this.startNodeAtNode(elt); - if (decorators.length) { - pp.decorators = decorators; - } - if (accessibility) pp.accessibility = accessibility; - if (readonly) pp.readonly = readonly; - if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { - throw this.raise( - pp.start, - "A parameter property may not be declared using a binding pattern.", - ); - } - pp.parameter = elt; - return this.finishNode(pp, "TSParameterProperty"); - } else { - if (decorators.length) { - left.decorators = decorators; - } - return elt; - } - } - - parseFunctionBodyAndFinish( - node: N.BodilessFunctionOrMethodBase, - type: string, - allowExpressionBody?: boolean, - ): void { - // For arrow functions, `parseArrow` handles the return type itself. - if (!allowExpressionBody && this.match(tt.colon)) { - node.returnType = this.tsParseTypeOrTypePredicateAnnotation(tt.colon); - } - - const bodilessType = - type === "FunctionDeclaration" - ? "TSDeclareFunction" - : type === "ClassMethod" - ? "TSDeclareMethod" - : undefined; - if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) { - this.finishNode(node, bodilessType); - return; - } - - super.parseFunctionBodyAndFinish(node, type, allowExpressionBody); - } - - parseSubscript( - base: N.Expression, - startPos: number, - startLoc: Position, - noCalls: ?boolean, - state: N.ParseSubscriptState, - ): N.Expression { - if (!this.hasPrecedingLineBreak() && this.match(tt.bang)) { - this.state.exprAllowed = false; - this.next(); - - const nonNullExpression: N.TsNonNullExpression = this.startNodeAt( - startPos, - startLoc, - ); - nonNullExpression.expression = base; - return this.finishNode(nonNullExpression, "TSNonNullExpression"); - } - - // There are number of things we are going to "maybe" parse, like type arguments on - // tagged template expressions. If any of them fail, walk it back and continue. - const result = this.tsTryParseAndCatch(() => { - if (this.isRelational("<")) { - if (!noCalls && this.atPossibleAsync(base)) { - // Almost certainly this is a generic async function `async () => ... - // But it might be a call with a type argument `async();` - const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction( - startPos, - startLoc, - ); - if (asyncArrowFn) { - return asyncArrowFn; - } - } - - const node: N.CallExpression = this.startNodeAt(startPos, startLoc); - node.callee = base; - - const typeArguments = this.tsParseTypeArguments(); - - if (typeArguments) { - if (!noCalls && this.eat(tt.parenL)) { - // possibleAsync always false here, because we would have handled it above. - // $FlowIgnore (won't be any undefined arguments) - node.arguments = this.parseCallExpressionArguments( - tt.parenR, - /* possibleAsync */ false, - ); - node.typeParameters = typeArguments; - return this.finishCallExpression(node); - } else if (this.match(tt.backQuote)) { - return this.parseTaggedTemplateExpression( - startPos, - startLoc, - base, - state, - typeArguments, - ); - } - } - } - - this.unexpected(); - }); - - if (result) return result; - - return super.parseSubscript(base, startPos, startLoc, noCalls, state); - } - - parseNewArguments(node: N.NewExpression): void { - if (this.isRelational("<")) { - // tsTryParseAndCatch is expensive, so avoid if not necessary. - // 99% certain this is `new C();`. But may be `new C < T;`, which is also legal. - const typeParameters = this.tsTryParseAndCatch(() => { - const args = this.tsParseTypeArguments(); - if (!this.match(tt.parenL)) this.unexpected(); - return args; - }); - if (typeParameters) { - node.typeParameters = typeParameters; - } - } - - super.parseNewArguments(node); - } - - parseExprOp( - left: N.Expression, - leftStartPos: number, - leftStartLoc: Position, - minPrec: number, - noIn: ?boolean, - ) { - if ( - nonNull(tt._in.binop) > minPrec && - !this.hasPrecedingLineBreak() && - this.isContextual("as") - ) { - const node: N.TsAsExpression = this.startNodeAt( - leftStartPos, - leftStartLoc, - ); - node.expression = left; - node.typeAnnotation = this.tsNextThenParseType(); - this.finishNode(node, "TSAsExpression"); - return this.parseExprOp( - node, - leftStartPos, - leftStartLoc, - minPrec, - noIn, - ); - } - - return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); - } - - checkReservedWord( - word: string, // eslint-disable-line no-unused-vars - startLoc: number, // eslint-disable-line no-unused-vars - checkKeywords: boolean, // eslint-disable-line no-unused-vars - // eslint-disable-next-line no-unused-vars - isBinding: boolean, - ): void { - // Don't bother checking for TypeScript code. - // Strict mode words may be allowed as in `declare namespace N { const static: number; }`. - // And we have a type checker anyway, so don't bother having the parser do it. - } - - /* - Don't bother doing this check in TypeScript code because: - 1. We may have a nested export statement with the same name: - export const x = 0; - export namespace N { - export const x = 1; - } - 2. We have a type checker to warn us about this sort of thing. - */ - checkDuplicateExports() {} - - parseImport( - node: N.Node, - ): N.ImportDeclaration | N.TsImportEqualsDeclaration { - if (this.match(tt.name) && this.lookahead().type === tt.eq) { - return this.tsParseImportEqualsDeclaration(node); - } - return super.parseImport(node); - } - - parseExport(node: N.Node): N.Node { - if (this.match(tt._import)) { - // `export import A = B;` - this.expect(tt._import); - return this.tsParseImportEqualsDeclaration(node, /* isExport */ true); - } else if (this.eat(tt.eq)) { - // `export = x;` - const assign: N.TsExportAssignment = node; - assign.expression = this.parseExpression(); - this.semicolon(); - return this.finishNode(assign, "TSExportAssignment"); - } else if (this.eatContextual("as")) { - // `export as namespace A;` - const decl: N.TsNamespaceExportDeclaration = node; - // See `parseNamespaceExportDeclaration` in TypeScript's own parser - this.expectContextual("namespace"); - decl.id = this.parseIdentifier(); - this.semicolon(); - return this.finishNode(decl, "TSNamespaceExportDeclaration"); - } else { - return super.parseExport(node); - } - } - - isAbstractClass(): boolean { - return ( - this.isContextual("abstract") && this.lookahead().type === tt._class - ); - } - - parseExportDefaultExpression(): N.Expression | N.Declaration { - if (this.isAbstractClass()) { - const cls = this.startNode(); - this.next(); // Skip "abstract" - this.parseClass(cls, true, true); - cls.abstract = true; - return cls; - } - - // export default interface allowed in: - // https://github.com/Microsoft/TypeScript/pull/16040 - if (this.state.value === "interface") { - const result = this.tsParseDeclaration( - this.startNode(), - this.state.value, - true, - ); - - if (result) return result; - } - - return super.parseExportDefaultExpression(); - } - - parseStatementContent( - declaration: boolean, - topLevel: ?boolean, - ): N.Statement { - if (this.state.type === tt._const) { - const ahead = this.lookahead(); - if (ahead.type === tt.name && ahead.value === "enum") { - const node: N.TsEnumDeclaration = this.startNode(); - this.expect(tt._const); - this.expectContextual("enum"); - return this.tsParseEnumDeclaration(node, /* isConst */ true); - } - } - return super.parseStatementContent(declaration, topLevel); - } - - parseAccessModifier(): ?N.Accessibility { - return this.tsParseModifier(["public", "protected", "private"]); - } - - parseClassMember( - classBody: N.ClassBody, - member: any, - state: { hadConstructor: boolean }, - ): void { - const accessibility = this.parseAccessModifier(); - if (accessibility) member.accessibility = accessibility; - - super.parseClassMember(classBody, member, state); - } - - parseClassMemberWithIsStatic( - classBody: N.ClassBody, - member: any, - state: { hadConstructor: boolean }, - isStatic: boolean, - ): void { - const methodOrProp: N.ClassMethod | N.ClassProperty = member; - const prop: N.ClassProperty = member; - const propOrIdx: N.ClassProperty | N.TsIndexSignature = member; - - let abstract = false, - readonly = false; - - const mod = this.tsParseModifier(["abstract", "readonly"]); - switch (mod) { - case "readonly": - readonly = true; - abstract = !!this.tsParseModifier(["abstract"]); - break; - case "abstract": - abstract = true; - readonly = !!this.tsParseModifier(["readonly"]); - break; - } - - if (abstract) methodOrProp.abstract = true; - if (readonly) propOrIdx.readonly = true; - - if (!abstract && !isStatic && !methodOrProp.accessibility) { - const idx = this.tsTryParseIndexSignature(member); - if (idx) { - classBody.body.push(idx); - return; - } - } - - if (readonly) { - // Must be a property (if not an index signature). - methodOrProp.static = isStatic; - this.parseClassPropertyName(prop); - this.parsePostMemberNameModifiers(methodOrProp); - this.pushClassProperty(classBody, prop); - return; - } - - super.parseClassMemberWithIsStatic(classBody, member, state, isStatic); - } - - parsePostMemberNameModifiers( - methodOrProp: N.ClassMethod | N.ClassProperty, - ): void { - const optional = this.eat(tt.question); - if (optional) methodOrProp.optional = true; - } - - // Note: The reason we do this in `parseExpressionStatement` and not `parseStatement` - // is that e.g. `type()` is valid JS, so we must try parsing that first. - // If it's really a type, we will parse `type` as the statement, and can correct it here - // by parsing the rest. - parseExpressionStatement( - node: N.ExpressionStatement, - expr: N.Expression, - ): N.Statement { - const decl = - expr.type === "Identifier" - ? this.tsParseExpressionStatement(node, expr) - : undefined; - return decl || super.parseExpressionStatement(node, expr); - } - - // export type - // Should be true for anything parsed by `tsTryParseExportDeclaration`. - shouldParseExportDeclaration(): boolean { - if (this.tsIsDeclarationStart()) return true; - return super.shouldParseExportDeclaration(); - } - - // An apparent conditional expression could actually be an optional parameter in an arrow function. - parseConditional( - expr: N.Expression, - noIn: ?boolean, - startPos: number, - startLoc: Position, - refNeedsArrowPos?: ?Pos, - ): N.Expression { - // only do the expensive clone if there is a question mark - // and if we come from inside parens - if (!refNeedsArrowPos || !this.match(tt.question)) { - return super.parseConditional( - expr, - noIn, - startPos, - startLoc, - refNeedsArrowPos, - ); - } - - const state = this.state.clone(); - try { - return super.parseConditional(expr, noIn, startPos, startLoc); - } catch (err) { - if (!(err instanceof SyntaxError)) { - // istanbul ignore next: no such error is expected - throw err; - } - - this.state = state; - refNeedsArrowPos.start = err.pos || this.state.start; - return expr; - } - } - - // Note: These "type casts" are *not* valid TS expressions. - // But we parse them here and change them when completing the arrow function. - parseParenItem( - node: N.Expression, - startPos: number, - startLoc: Position, - ): N.Expression { - node = super.parseParenItem(node, startPos, startLoc); - if (this.eat(tt.question)) { - node.optional = true; - } - - if (this.match(tt.colon)) { - const typeCastNode: N.TsTypeCastExpression = this.startNodeAt( - startPos, - startLoc, - ); - typeCastNode.expression = node; - typeCastNode.typeAnnotation = this.tsParseTypeAnnotation(); - - return this.finishNode(typeCastNode, "TSTypeCastExpression"); - } - - return node; - } - - parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration { - // "export declare" is equivalent to just "export". - const isDeclare = this.eatContextual("declare"); - - let declaration: ?N.Declaration; - if (this.match(tt.name)) { - declaration = this.tsTryParseExportDeclaration(); - } - if (!declaration) { - declaration = super.parseExportDeclaration(node); - } - - if (declaration && isDeclare) { - declaration.declare = true; - } - - return declaration; - } - - parseClassId( - node: N.Class, - isStatement: boolean, - optionalId: ?boolean, - ): void { - if ((!isStatement || optionalId) && this.isContextual("implements")) { - return; - } - - super.parseClassId(...arguments); - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; - } - - parseClassProperty(node: N.ClassProperty): N.ClassProperty { - if (!node.optional && this.eat(tt.bang)) { - node.definite = true; - } - - const type = this.tsTryParseTypeAnnotation(); - if (type) node.typeAnnotation = type; - return super.parseClassProperty(node); - } - - pushClassMethod( - classBody: N.ClassBody, - method: N.ClassMethod, - isGenerator: boolean, - isAsync: boolean, - isConstructor: boolean, - ): void { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassMethod( - classBody, - method, - isGenerator, - isAsync, - isConstructor, - ); - } - - pushClassPrivateMethod( - classBody: N.ClassBody, - method: N.ClassPrivateMethod, - isGenerator: boolean, - isAsync: boolean, - ): void { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) method.typeParameters = typeParameters; - super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); - } - - parseClassSuper(node: N.Class): void { - super.parseClassSuper(node); - if (node.superClass && this.isRelational("<")) { - node.superTypeParameters = this.tsParseTypeArguments(); - } - if (this.eatContextual("implements")) { - node.implements = this.tsParseHeritageClause(); - } - } - - parseObjPropValue(prop: N.ObjectMember, ...args): void { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) prop.typeParameters = typeParameters; - - super.parseObjPropValue(prop, ...args); - } - - parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { - const typeParameters = this.tsTryParseTypeParameters(); - if (typeParameters) node.typeParameters = typeParameters; - super.parseFunctionParams(node, allowModifiers); - } - - // `let x: number;` - parseVarHead(decl: N.VariableDeclarator): void { - super.parseVarHead(decl); - if (decl.id.type === "Identifier" && this.eat(tt.bang)) { - decl.definite = true; - } - - const type = this.tsTryParseTypeAnnotation(); - if (type) { - decl.id.typeAnnotation = type; - this.finishNode(decl.id, decl.id.type); // set end position to end of type - } - } - - // parse the return type of an async arrow function - let foo = (async (): number => {}); - parseAsyncArrowFromCallExpression( - node: N.ArrowFunctionExpression, - call: N.CallExpression, - ): N.ArrowFunctionExpression { - if (this.match(tt.colon)) { - node.returnType = this.tsParseTypeAnnotation(); - } - return super.parseAsyncArrowFromCallExpression(node, call); - } - - parseMaybeAssign(...args): N.Expression { - // Note: When the JSX plugin is on, type assertions (` x`) aren't valid syntax. - - let jsxError: ?SyntaxError; - - if (this.match(tt.jsxTagStart)) { - const context = this.curContext(); - assert(context === ct.j_oTag); - // Only time j_oTag is pushed is right after j_expr. - assert(this.state.context[this.state.context.length - 2] === ct.j_expr); - - // Prefer to parse JSX if possible. But may be an arrow fn. - const state = this.state.clone(); - try { - return super.parseMaybeAssign(...args); - } catch (err) { - if (!(err instanceof SyntaxError)) { - // istanbul ignore next: no such error is expected - throw err; - } - - this.state = state; - // Pop the context added by the jsxTagStart. - assert(this.curContext() === ct.j_oTag); - this.state.context.pop(); - assert(this.curContext() === ct.j_expr); - this.state.context.pop(); - jsxError = err; - } - } - - if (jsxError === undefined && !this.isRelational("<")) { - return super.parseMaybeAssign(...args); - } - - // Either way, we're looking at a '<': tt.jsxTagStart or relational. - - let arrowExpression; - let typeParameters: N.TsTypeParameterDeclaration; - const state = this.state.clone(); - try { - // This is similar to TypeScript's `tryParseParenthesizedArrowFunctionExpression`. - typeParameters = this.tsParseTypeParameters(); - arrowExpression = super.parseMaybeAssign(...args); - if (arrowExpression.type !== "ArrowFunctionExpression") { - this.unexpected(); // Go to the catch block (needs a SyntaxError). - } - } catch (err) { - if (!(err instanceof SyntaxError)) { - // istanbul ignore next: no such error is expected - throw err; - } - - if (jsxError) { - throw jsxError; - } - - // Try parsing a type cast instead of an arrow function. - // This will never happen outside of JSX. - // (Because in JSX the '<' should be a jsxTagStart and not a relational. - assert(!this.hasPlugin("jsx")); - // Parsing an arrow function failed, so try a type cast. - this.state = state; - // This will start with a type assertion (via parseMaybeUnary). - // But don't directly call `this.tsParseTypeAssertion` because we want to handle any binary after it. - return super.parseMaybeAssign(...args); - } - - // Correct TypeScript code should have at least 1 type parameter, but don't crash on bad code. - if (typeParameters && typeParameters.params.length !== 0) { - this.resetStartLocationFromNode( - arrowExpression, - typeParameters.params[0], - ); - } - arrowExpression.typeParameters = typeParameters; - return arrowExpression; - } - - // Handle type assertions - parseMaybeUnary(refShorthandDefaultPos?: ?Pos): N.Expression { - if (!this.hasPlugin("jsx") && this.eatRelational("<")) { - return this.tsParseTypeAssertion(); - } else { - return super.parseMaybeUnary(refShorthandDefaultPos); - } - } - - parseArrow(node: N.ArrowFunctionExpression): ?N.ArrowFunctionExpression { - if (this.match(tt.colon)) { - // This is different from how the TS parser does it. - // TS uses lookahead. The Babel Parser parses it as a parenthesized expression and converts. - const state = this.state.clone(); - try { - const returnType = this.tsParseTypeOrTypePredicateAnnotation( - tt.colon, - ); - if (this.canInsertSemicolon()) this.unexpected(); - if (!this.match(tt.arrow)) this.unexpected(); - node.returnType = returnType; - } catch (err) { - if (err instanceof SyntaxError) { - this.state = state; - } else { - // istanbul ignore next: no such error is expected - throw err; - } - } - } - - return super.parseArrow(node); - } - - // Allow type annotations inside of a parameter list. - parseAssignableListItemTypes(param: N.Pattern) { - if (this.eat(tt.question)) { - if (param.type !== "Identifier") { - throw this.raise( - param.start, - "A binding pattern parameter cannot be optional in an implementation signature.", - ); - } - - param.optional = true; - } - const type = this.tsTryParseTypeAnnotation(); - if (type) param.typeAnnotation = type; - return this.finishNode(param, param.type); - } - - toAssignable( - node: N.Node, - isBinding: ?boolean, - contextDescription: string, - ): N.Node { - switch (node.type) { - case "TSTypeCastExpression": - return super.toAssignable( - this.typeCastToParameter(node), - isBinding, - contextDescription, - ); - case "TSParameterProperty": - return super.toAssignable(node, isBinding, contextDescription); - case "TSAsExpression": - case "TSNonNullExpression": - case "TSTypeAssertion": - node.expression = this.toAssignable( - node.expression, - isBinding, - contextDescription, - ); - return node; - default: - return super.toAssignable(node, isBinding, contextDescription); - } - } - - checkLVal( - expr: N.Expression, - isBinding: ?boolean, - checkClashes: ?{ [key: string]: boolean }, - contextDescription: string, - ): void { - switch (expr.type) { - case "TSTypeCastExpression": - // Allow "typecasts" to appear on the left of assignment expressions, - // because it may be in an arrow function. - // e.g. `const f = (foo: number = 0) => foo;` - return; - case "TSParameterProperty": - this.checkLVal( - expr.parameter, - isBinding, - checkClashes, - "parameter property", - ); - return; - case "TSAsExpression": - case "TSNonNullExpression": - case "TSTypeAssertion": - this.checkLVal( - expr.expression, - isBinding, - checkClashes, - contextDescription, - ); - return; - default: - super.checkLVal(expr, isBinding, checkClashes, contextDescription); - return; - } - } - - parseBindingAtom(): N.Pattern { - switch (this.state.type) { - case tt._this: - // "this" may be the name of a parameter, so allow it. - return this.parseIdentifier(/* liberal */ true); - default: - return super.parseBindingAtom(); - } - } - - // === === === === === === === === === === === === === === === === - // Note: All below methods are duplicates of something in flow.js. - // Not sure what the best way to combine these is. - // === === === === === === === === === === === === === === === === - - isClassMethod(): boolean { - return this.isRelational("<") || super.isClassMethod(); - } - - isClassProperty(): boolean { - return ( - this.match(tt.bang) || this.match(tt.colon) || super.isClassProperty() - ); - } - - parseMaybeDefault(...args): N.Pattern { - const node = super.parseMaybeDefault(...args); - - if ( - node.type === "AssignmentPattern" && - node.typeAnnotation && - node.right.start < node.typeAnnotation.start - ) { - this.raise( - node.typeAnnotation.start, - "Type annotations must come before default assignments, " + - "e.g. instead of `age = 25: number` use `age: number = 25`", - ); - } - - return node; - } - - // ensure that inside types, we bypass the jsx parser plugin - readToken(code: number): void { - if (this.state.inType && (code === 62 || code === 60)) { - return this.finishOp(tt.relational, 1); - } else { - return super.readToken(code); - } - } - - toAssignableList( - exprList: N.Expression[], - isBinding: ?boolean, - contextDescription: string, - ): $ReadOnlyArray { - for (let i = 0; i < exprList.length; i++) { - const expr = exprList[i]; - if (expr && expr.type === "TSTypeCastExpression") { - exprList[i] = this.typeCastToParameter(expr); - } - } - return super.toAssignableList(exprList, isBinding, contextDescription); - } - - typeCastToParameter(node: N.TsTypeCastExpression): N.Node { - node.expression.typeAnnotation = node.typeAnnotation; - - return this.finishNodeAt( - node.expression, - node.expression.type, - node.typeAnnotation.end, - node.typeAnnotation.loc.end, - ); - } - - toReferencedList( - exprList: $ReadOnlyArray, - ): $ReadOnlyArray { - for (let i = 0; i < exprList.length; i++) { - const expr = exprList[i]; - if ( - expr && - expr._exprListItem && - expr.type === "TsTypeCastExpression" - ) { - this.raise(expr.start, "Did not expect a type annotation here."); - } - } - - return exprList; - } - - shouldParseArrow() { - return this.match(tt.colon) || super.shouldParseArrow(); - } - - shouldParseAsyncArrow(): boolean { - return this.match(tt.colon) || super.shouldParseAsyncArrow(); - } - - canHaveLeadingDecorator() { - // Avoid unnecessary lookahead in checking for abstract class unless needed! - return super.canHaveLeadingDecorator() || this.isAbstractClass(); - } - - jsxParseOpeningElementAfterName( - node: N.JSXOpeningElement, - ): N.JSXOpeningElement { - const typeArguments = this.tsTryParseAndCatch(() => - this.tsParseTypeArguments(), - ); - if (typeArguments) node.typeParameters = typeArguments; - return super.jsxParseOpeningElementAfterName(node); - } - }; diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js new file mode 100644 index 000000000000..fb6e8363a333 --- /dev/null +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -0,0 +1,2446 @@ +// @flow + +import type { TokenType } from "../../tokenizer/types"; +import { types as tt } from "../../tokenizer/types"; +import { types as ct } from "../../tokenizer/context"; +import * as N from "../../types"; +import type { Pos, Position } from "../../util/location"; +import type Parser from "../../parser"; +import { + type BindingTypes, + BIND_NONE, + SCOPE_OTHER, + BIND_TS_ENUM, + BIND_TS_CONST_ENUM, + BIND_TS_TYPE, + BIND_TS_INTERFACE, + BIND_TS_FN_TYPE, + BIND_TS_NAMESPACE, +} from "../../util/scopeflags"; +import TypeScriptScopeHandler from "./scope"; + +type TsModifier = + | "readonly" + | "abstract" + | "static" + | "public" + | "private" + | "protected"; + +function nonNull(x: ?T): T { + if (x == null) { + // $FlowIgnore + throw new Error(`Unexpected ${x} value.`); + } + return x; +} + +function assert(x: boolean): void { + if (!x) { + throw new Error("Assert fail"); + } +} + +type ParsingContext = + | "EnumMembers" + | "HeritageClauseElement" + | "TupleElementTypes" + | "TypeMembers" + | "TypeParametersOrArguments"; + +// Doesn't handle "void" or "null" because those are keywords, not identifiers. +function keywordTypeFromName( + value: string, +): N.TsKeywordTypeType | typeof undefined { + switch (value) { + case "any": + return "TSAnyKeyword"; + case "boolean": + return "TSBooleanKeyword"; + case "bigint": + return "TSBigIntKeyword"; + case "never": + return "TSNeverKeyword"; + case "number": + return "TSNumberKeyword"; + case "object": + return "TSObjectKeyword"; + case "string": + return "TSStringKeyword"; + case "symbol": + return "TSSymbolKeyword"; + case "undefined": + return "TSUndefinedKeyword"; + case "unknown": + return "TSUnknownKeyword"; + default: + return undefined; + } +} + +export default (superClass: Class): Class => + class extends superClass { + getScopeHandler(): Class { + return TypeScriptScopeHandler; + } + + tsIsIdentifier(): boolean { + // TODO: actually a bit more complex in TypeScript, but shouldn't matter. + // See https://github.com/Microsoft/TypeScript/issues/15008 + return this.match(tt.name); + } + + tsNextTokenCanFollowModifier() { + // Note: TypeScript's implementation is much more complicated because + // more things are considered modifiers there. + // This implementation only handles modifiers not handled by @babel/parser itself. And "static". + // TODO: Would be nice to avoid lookahead. Want a hasLineBreakUpNext() method... + this.next(); + return ( + !this.hasPrecedingLineBreak() && + !this.match(tt.parenL) && + !this.match(tt.parenR) && + !this.match(tt.colon) && + !this.match(tt.eq) && + !this.match(tt.question) && + !this.match(tt.bang) + ); + } + + /** Parses a modifier matching one the given modifier names. */ + tsParseModifier(allowedModifiers: T[]): ?T { + if (!this.match(tt.name)) { + return undefined; + } + + const modifier = this.state.value; + if ( + allowedModifiers.indexOf(modifier) !== -1 && + this.tsTryParse(this.tsNextTokenCanFollowModifier.bind(this)) + ) { + return modifier; + } + return undefined; + } + + tsIsListTerminator(kind: ParsingContext): boolean { + switch (kind) { + case "EnumMembers": + case "TypeMembers": + return this.match(tt.braceR); + case "HeritageClauseElement": + return this.match(tt.braceL); + case "TupleElementTypes": + return this.match(tt.bracketR); + case "TypeParametersOrArguments": + return this.isRelational(">"); + } + + throw new Error("Unreachable"); + } + + tsParseList(kind: ParsingContext, parseElement: () => T): T[] { + const result: T[] = []; + while (!this.tsIsListTerminator(kind)) { + // Skipping "parseListElement" from the TS source since that's just for error handling. + result.push(parseElement()); + } + return result; + } + + tsParseDelimitedList( + kind: ParsingContext, + parseElement: () => T, + ): T[] { + return nonNull( + this.tsParseDelimitedListWorker( + kind, + parseElement, + /* expectSuccess */ true, + ), + ); + } + + /** + * If !expectSuccess, returns undefined instead of failing to parse. + * If expectSuccess, parseElement should always return a defined value. + */ + tsParseDelimitedListWorker( + kind: ParsingContext, + parseElement: () => ?T, + expectSuccess: boolean, + ): ?(T[]) { + const result = []; + + while (true) { + if (this.tsIsListTerminator(kind)) { + break; + } + + const element = parseElement(); + if (element == null) { + return undefined; + } + result.push(element); + + if (this.eat(tt.comma)) { + continue; + } + + if (this.tsIsListTerminator(kind)) { + break; + } + + if (expectSuccess) { + // This will fail with an error about a missing comma + this.expect(tt.comma); + } + return undefined; + } + + return result; + } + + tsParseBracketedList( + kind: ParsingContext, + parseElement: () => T, + bracket: boolean, + skipFirstToken: boolean, + ): T[] { + if (!skipFirstToken) { + if (bracket) { + this.expect(tt.bracketL); + } else { + this.expectRelational("<"); + } + } + + const result = this.tsParseDelimitedList(kind, parseElement); + + if (bracket) { + this.expect(tt.bracketR); + } else { + this.expectRelational(">"); + } + + return result; + } + + tsParseImportType(): N.TsImportType { + const node: N.TsImportType = this.startNode(); + this.expect(tt._import); + this.expect(tt.parenL); + if (!this.match(tt.string)) { + throw this.unexpected( + null, + "Argument in a type import must be a string literal", + ); + } + + // For compatibility to estree we cannot call parseLiteral directly here + node.argument = this.parseExprAtom(); + this.expect(tt.parenR); + + if (this.eat(tt.dot)) { + node.qualifier = this.tsParseEntityName(/* allowReservedWords */ true); + } + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + return this.finishNode(node, "TSImportType"); + } + + tsParseEntityName(allowReservedWords: boolean): N.TsEntityName { + let entity: N.TsEntityName = this.parseIdentifier(); + while (this.eat(tt.dot)) { + const node: N.TsQualifiedName = this.startNodeAtNode(entity); + node.left = entity; + node.right = this.parseIdentifier(allowReservedWords); + entity = this.finishNode(node, "TSQualifiedName"); + } + return entity; + } + + tsParseTypeReference(): N.TsTypeReference { + const node: N.TsTypeReference = this.startNode(); + node.typeName = this.tsParseEntityName(/* allowReservedWords */ false); + if (!this.hasPrecedingLineBreak() && this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + return this.finishNode(node, "TSTypeReference"); + } + + tsParseThisTypePredicate(lhs: N.TsThisType): N.TsTypePredicate { + this.next(); + const node: N.TsTypePredicate = this.startNodeAtNode(lhs); + node.parameterName = lhs; + node.typeAnnotation = this.tsParseTypeAnnotation(/* eatColon */ false); + return this.finishNode(node, "TSTypePredicate"); + } + + tsParseThisTypeNode(): N.TsThisType { + const node: N.TsThisType = this.startNode(); + this.next(); + return this.finishNode(node, "TSThisType"); + } + + tsParseTypeQuery(): N.TsTypeQuery { + const node: N.TsTypeQuery = this.startNode(); + this.expect(tt._typeof); + if (this.match(tt._import)) { + node.exprName = this.tsParseImportType(); + } else { + node.exprName = this.tsParseEntityName(/* allowReservedWords */ true); + } + return this.finishNode(node, "TSTypeQuery"); + } + + tsParseTypeParameter(): N.TsTypeParameter { + const node: N.TsTypeParameter = this.startNode(); + node.name = this.parseIdentifierName(node.start); + node.constraint = this.tsEatThenParseType(tt._extends); + node.default = this.tsEatThenParseType(tt.eq); + return this.finishNode(node, "TSTypeParameter"); + } + + tsTryParseTypeParameters(): ?N.TsTypeParameterDeclaration { + if (this.isRelational("<")) { + return this.tsParseTypeParameters(); + } + } + + tsParseTypeParameters() { + const node: N.TsTypeParameterDeclaration = this.startNode(); + + if (this.isRelational("<") || this.match(tt.jsxTagStart)) { + this.next(); + } else { + this.unexpected(); + } + + node.params = this.tsParseBracketedList( + "TypeParametersOrArguments", + this.tsParseTypeParameter.bind(this), + /* bracket */ false, + /* skipFirstToken */ true, + ); + return this.finishNode(node, "TSTypeParameterDeclaration"); + } + + tsTryNextParseConstantContext(): ?N.TsTypeReference { + if (this.lookahead().type === tt._const) { + this.next(); + return this.tsParseTypeReference(); + } + return null; + } + + // Note: In TypeScript implementation we must provide `yieldContext` and `awaitContext`, + // but here it's always false, because this is only used for types. + tsFillSignature( + returnToken: TokenType, + signature: N.TsSignatureDeclaration, + ): void { + // Arrow fns *must* have return token (`=>`). Normal functions can omit it. + const returnTokenRequired = returnToken === tt.arrow; + signature.typeParameters = this.tsTryParseTypeParameters(); + this.expect(tt.parenL); + signature.parameters = this.tsParseBindingListForSignature(); + if (returnTokenRequired) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation( + returnToken, + ); + } else if (this.match(returnToken)) { + signature.typeAnnotation = this.tsParseTypeOrTypePredicateAnnotation( + returnToken, + ); + } + } + + tsParseBindingListForSignature(): $ReadOnlyArray< + N.Identifier | N.RestElement | N.ObjectPattern | N.ArrayPattern, + > { + return this.parseBindingList(tt.parenR).map(pattern => { + if ( + pattern.type !== "Identifier" && + pattern.type !== "RestElement" && + pattern.type !== "ObjectPattern" && + pattern.type !== "ArrayPattern" + ) { + throw this.unexpected( + pattern.start, + `Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${ + pattern.type + }`, + ); + } + return pattern; + }); + } + + tsParseTypeMemberSemicolon(): void { + if (!this.eat(tt.comma)) { + this.semicolon(); + } + } + + tsParseSignatureMember( + kind: "TSCallSignatureDeclaration" | "TSConstructSignatureDeclaration", + node: N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration, + ): N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration { + this.tsFillSignature(tt.colon, node); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(node, kind); + } + + tsIsUnambiguouslyIndexSignature() { + this.next(); // Skip '{' + return this.eat(tt.name) && this.match(tt.colon); + } + + tsTryParseIndexSignature(node: N.TsIndexSignature): ?N.TsIndexSignature { + if ( + !( + this.match(tt.bracketL) && + this.tsLookAhead(this.tsIsUnambiguouslyIndexSignature.bind(this)) + ) + ) { + return undefined; + } + + this.expect(tt.bracketL); + const id = this.parseIdentifier(); + id.typeAnnotation = this.tsParseTypeAnnotation(); + this.resetEndLocation(id); // set end position to end of type + + this.expect(tt.bracketR); + node.parameters = [id]; + + const type = this.tsTryParseTypeAnnotation(); + if (type) node.typeAnnotation = type; + this.tsParseTypeMemberSemicolon(); + return this.finishNode(node, "TSIndexSignature"); + } + + tsParsePropertyOrMethodSignature( + node: N.TsPropertySignature | N.TsMethodSignature, + readonly: boolean, + ): N.TsPropertySignature | N.TsMethodSignature { + if (this.eat(tt.question)) node.optional = true; + const nodeAny: any = node; + + if (!readonly && (this.match(tt.parenL) || this.isRelational("<"))) { + const method: N.TsMethodSignature = nodeAny; + this.tsFillSignature(tt.colon, method); + this.tsParseTypeMemberSemicolon(); + return this.finishNode(method, "TSMethodSignature"); + } else { + const property: N.TsPropertySignature = nodeAny; + if (readonly) property.readonly = true; + const type = this.tsTryParseTypeAnnotation(); + if (type) property.typeAnnotation = type; + this.tsParseTypeMemberSemicolon(); + return this.finishNode(property, "TSPropertySignature"); + } + } + + tsParseTypeMember(): N.TsTypeElement { + const node: any = this.startNode(); + + if (this.match(tt.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember("TSCallSignatureDeclaration", node); + } + + if (this.match(tt._new)) { + const id: N.Identifier = this.startNode(); + this.next(); + if (this.match(tt.parenL) || this.isRelational("<")) { + return this.tsParseSignatureMember( + "TSConstructSignatureDeclaration", + node, + ); + } else { + node.key = this.createIdentifier(id, "new"); + return this.tsParsePropertyOrMethodSignature(node, false); + } + } + + const readonly = !!this.tsParseModifier(["readonly"]); + + const idx = this.tsTryParseIndexSignature(node); + if (idx) { + if (readonly) node.readonly = true; + return idx; + } + + this.parsePropertyName(node); + return this.tsParsePropertyOrMethodSignature(node, readonly); + } + + tsParseTypeLiteral(): N.TsTypeLiteral { + const node: N.TsTypeLiteral = this.startNode(); + node.members = this.tsParseObjectTypeMembers(); + return this.finishNode(node, "TSTypeLiteral"); + } + + tsParseObjectTypeMembers(): $ReadOnlyArray { + this.expect(tt.braceL); + const members = this.tsParseList( + "TypeMembers", + this.tsParseTypeMember.bind(this), + ); + this.expect(tt.braceR); + return members; + } + + tsIsStartOfMappedType(): boolean { + this.next(); + if (this.eat(tt.plusMin)) { + return this.isContextual("readonly"); + } + if (this.isContextual("readonly")) { + this.next(); + } + if (!this.match(tt.bracketL)) { + return false; + } + this.next(); + if (!this.tsIsIdentifier()) { + return false; + } + this.next(); + return this.match(tt._in); + } + + tsParseMappedTypeParameter(): N.TsTypeParameter { + const node: N.TsTypeParameter = this.startNode(); + node.name = this.parseIdentifierName(node.start); + node.constraint = this.tsExpectThenParseType(tt._in); + return this.finishNode(node, "TSTypeParameter"); + } + + tsParseMappedType(): N.TsMappedType { + const node: N.TsMappedType = this.startNode(); + + this.expect(tt.braceL); + + if (this.match(tt.plusMin)) { + node.readonly = this.state.value; + this.next(); + this.expectContextual("readonly"); + } else if (this.eatContextual("readonly")) { + node.readonly = true; + } + + this.expect(tt.bracketL); + node.typeParameter = this.tsParseMappedTypeParameter(); + this.expect(tt.bracketR); + + if (this.match(tt.plusMin)) { + node.optional = this.state.value; + this.next(); + this.expect(tt.question); + } else if (this.eat(tt.question)) { + node.optional = true; + } + + node.typeAnnotation = this.tsTryParseType(); + this.semicolon(); + this.expect(tt.braceR); + + return this.finishNode(node, "TSMappedType"); + } + + tsParseTupleType(): N.TsTupleType { + const node: N.TsTupleType = this.startNode(); + node.elementTypes = this.tsParseBracketedList( + "TupleElementTypes", + this.tsParseTupleElementType.bind(this), + /* bracket */ true, + /* skipFirstToken */ false, + ); + + // Validate the elementTypes to ensure: + // No mandatory elements may follow optional elements + // If there's a rest element, it must be at the end of the tuple + let seenOptionalElement = false; + node.elementTypes.forEach(elementNode => { + if (elementNode.type === "TSOptionalType") { + seenOptionalElement = true; + } else if (seenOptionalElement && elementNode.type !== "TSRestType") { + this.raise( + elementNode.start, + "A required element cannot follow an optional element.", + ); + } + }); + + return this.finishNode(node, "TSTupleType"); + } + + tsParseTupleElementType(): N.TsType { + // parses `...TsType[]` + if (this.match(tt.ellipsis)) { + const restNode: N.TsRestType = this.startNode(); + this.next(); // skips ellipsis + restNode.typeAnnotation = this.tsParseType(); + this.checkCommaAfterRest(); + return this.finishNode(restNode, "TSRestType"); + } + + const type = this.tsParseType(); + // parses `TsType?` + if (this.eat(tt.question)) { + const optionalTypeNode: N.TsOptionalType = this.startNodeAtNode(type); + optionalTypeNode.typeAnnotation = type; + return this.finishNode(optionalTypeNode, "TSOptionalType"); + } + return type; + } + + tsParseParenthesizedType(): N.TsParenthesizedType { + const node = this.startNode(); + this.expect(tt.parenL); + node.typeAnnotation = this.tsParseType(); + this.expect(tt.parenR); + return this.finishNode(node, "TSParenthesizedType"); + } + + tsParseFunctionOrConstructorType( + type: "TSFunctionType" | "TSConstructorType", + ): N.TsFunctionOrConstructorType { + const node: N.TsFunctionOrConstructorType = this.startNode(); + if (type === "TSConstructorType") { + this.expect(tt._new); + } + this.tsFillSignature(tt.arrow, node); + return this.finishNode(node, type); + } + + tsParseLiteralTypeNode(): N.TsLiteralType { + const node: N.TsLiteralType = this.startNode(); + node.literal = (() => { + switch (this.state.type) { + case tt.num: + case tt.string: + case tt._true: + case tt._false: + // For compatibility to estree we cannot call parseLiteral directly here + return this.parseExprAtom(); + default: + throw this.unexpected(); + } + })(); + return this.finishNode(node, "TSLiteralType"); + } + + tsParseTemplateLiteralType(): N.TsType { + const node: N.TsLiteralType = this.startNode(); + const templateNode = this.parseTemplate(false); + if (templateNode.expressions.length > 0) { + throw this.raise( + templateNode.expressions[0].start, + "Template literal types cannot have any substitution", + ); + } + node.literal = templateNode; + return this.finishNode(node, "TSLiteralType"); + } + + tsParseNonArrayType(): N.TsType { + switch (this.state.type) { + case tt.name: + case tt._void: + case tt._null: { + const type = this.match(tt._void) + ? "TSVoidKeyword" + : this.match(tt._null) + ? "TSNullKeyword" + : keywordTypeFromName(this.state.value); + if (type !== undefined && this.lookahead().type !== tt.dot) { + const node: N.TsKeywordType = this.startNode(); + this.next(); + return this.finishNode(node, type); + } + return this.tsParseTypeReference(); + } + case tt.string: + case tt.num: + case tt._true: + case tt._false: + return this.tsParseLiteralTypeNode(); + case tt.plusMin: + if (this.state.value === "-") { + const node: N.TsLiteralType = this.startNode(); + if (this.lookahead().type !== tt.num) { + throw this.unexpected(); + } + node.literal = this.parseMaybeUnary(); + return this.finishNode(node, "TSLiteralType"); + } + break; + case tt._this: { + const thisKeyword = this.tsParseThisTypeNode(); + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + return this.tsParseThisTypePredicate(thisKeyword); + } else { + return thisKeyword; + } + } + case tt._typeof: + return this.tsParseTypeQuery(); + case tt._import: + return this.tsParseImportType(); + case tt.braceL: + return this.tsLookAhead(this.tsIsStartOfMappedType.bind(this)) + ? this.tsParseMappedType() + : this.tsParseTypeLiteral(); + case tt.bracketL: + return this.tsParseTupleType(); + case tt.parenL: + return this.tsParseParenthesizedType(); + case tt.backQuote: + return this.tsParseTemplateLiteralType(); + } + + throw this.unexpected(); + } + + tsParseArrayTypeOrHigher(): N.TsType { + let type = this.tsParseNonArrayType(); + while (!this.hasPrecedingLineBreak() && this.eat(tt.bracketL)) { + if (this.match(tt.bracketR)) { + const node: N.TsArrayType = this.startNodeAtNode(type); + node.elementType = type; + this.expect(tt.bracketR); + type = this.finishNode(node, "TSArrayType"); + } else { + const node: N.TsIndexedAccessType = this.startNodeAtNode(type); + node.objectType = type; + node.indexType = this.tsParseType(); + this.expect(tt.bracketR); + type = this.finishNode(node, "TSIndexedAccessType"); + } + } + return type; + } + + tsParseTypeOperator( + operator: "keyof" | "unique" | "readonly", + ): N.TsTypeOperator { + const node: N.TsTypeOperator = this.startNode(); + this.expectContextual(operator); + node.operator = operator; + node.typeAnnotation = this.tsParseTypeOperatorOrHigher(); + + if (operator === "readonly") { + this.tsCheckTypeAnnotationForReadOnly(node); + } + + return this.finishNode(node, "TSTypeOperator"); + } + + tsCheckTypeAnnotationForReadOnly(node: N.Node) { + switch (node.typeAnnotation.type) { + case "TSTupleType": + case "TSArrayType": + return; + default: + this.raise( + node.start, + "'readonly' type modifier is only permitted on array and tuple literal types.", + ); + } + } + + tsParseInferType(): N.TsInferType { + const node = this.startNode(); + this.expectContextual("infer"); + const typeParameter = this.startNode(); + typeParameter.name = this.parseIdentifierName(typeParameter.start); + node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter"); + return this.finishNode(node, "TSInferType"); + } + + tsParseTypeOperatorOrHigher(): N.TsType { + const operator = ["keyof", "unique", "readonly"].find(kw => + this.isContextual(kw), + ); + return operator + ? this.tsParseTypeOperator(operator) + : this.isContextual("infer") + ? this.tsParseInferType() + : this.tsParseArrayTypeOrHigher(); + } + + tsParseUnionOrIntersectionType( + kind: "TSUnionType" | "TSIntersectionType", + parseConstituentType: () => N.TsType, + operator: TokenType, + ): N.TsType { + this.eat(operator); + let type = parseConstituentType(); + if (this.match(operator)) { + const types = [type]; + while (this.eat(operator)) { + types.push(parseConstituentType()); + } + const node: N.TsUnionType | N.TsIntersectionType = this.startNodeAtNode( + type, + ); + node.types = types; + type = this.finishNode(node, kind); + } + return type; + } + + tsParseIntersectionTypeOrHigher(): N.TsType { + return this.tsParseUnionOrIntersectionType( + "TSIntersectionType", + this.tsParseTypeOperatorOrHigher.bind(this), + tt.bitwiseAND, + ); + } + + tsParseUnionTypeOrHigher() { + return this.tsParseUnionOrIntersectionType( + "TSUnionType", + this.tsParseIntersectionTypeOrHigher.bind(this), + tt.bitwiseOR, + ); + } + + tsIsStartOfFunctionType() { + if (this.isRelational("<")) { + return true; + } + return ( + this.match(tt.parenL) && + this.tsLookAhead(this.tsIsUnambiguouslyStartOfFunctionType.bind(this)) + ); + } + + tsSkipParameterStart(): boolean { + if (this.match(tt.name) || this.match(tt._this)) { + this.next(); + return true; + } + + if (this.match(tt.braceL)) { + let braceStackCounter = 1; + this.next(); + + while (braceStackCounter > 0) { + if (this.match(tt.braceL)) { + ++braceStackCounter; + } else if (this.match(tt.braceR)) { + --braceStackCounter; + } + this.next(); + } + return true; + } + + if (this.match(tt.bracketL)) { + let braceStackCounter = 1; + this.next(); + + while (braceStackCounter > 0) { + if (this.match(tt.bracketL)) { + ++braceStackCounter; + } else if (this.match(tt.bracketR)) { + --braceStackCounter; + } + this.next(); + } + return true; + } + + return false; + } + + tsIsUnambiguouslyStartOfFunctionType(): boolean { + this.next(); + if (this.match(tt.parenR) || this.match(tt.ellipsis)) { + // ( ) + // ( ... + return true; + } + if (this.tsSkipParameterStart()) { + if ( + this.match(tt.colon) || + this.match(tt.comma) || + this.match(tt.question) || + this.match(tt.eq) + ) { + // ( xxx : + // ( xxx , + // ( xxx ? + // ( xxx = + return true; + } + if (this.match(tt.parenR)) { + this.next(); + if (this.match(tt.arrow)) { + // ( xxx ) => + return true; + } + } + } + return false; + } + + tsParseTypeOrTypePredicateAnnotation( + returnToken: TokenType, + ): N.TsTypeAnnotation { + return this.tsInType(() => { + const t: N.TsTypeAnnotation = this.startNode(); + this.expect(returnToken); + + const typePredicateVariable = + this.tsIsIdentifier() && + this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); + + if (!typePredicateVariable) { + return this.tsParseTypeAnnotation(/* eatColon */ false, t); + } + + const type = this.tsParseTypeAnnotation(/* eatColon */ false); + + const node: N.TsTypePredicate = this.startNodeAtNode( + typePredicateVariable, + ); + node.parameterName = typePredicateVariable; + node.typeAnnotation = type; + t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); + return this.finishNode(t, "TSTypeAnnotation"); + }); + } + + tsTryParseTypeOrTypePredicateAnnotation(): ?N.TsTypeAnnotation { + return this.match(tt.colon) + ? this.tsParseTypeOrTypePredicateAnnotation(tt.colon) + : undefined; + } + + tsTryParseTypeAnnotation(): ?N.TsTypeAnnotation { + return this.match(tt.colon) ? this.tsParseTypeAnnotation() : undefined; + } + + tsTryParseType(): ?N.TsType { + return this.tsEatThenParseType(tt.colon); + } + + tsParseTypePredicatePrefix(): ?N.Identifier { + const id = this.parseIdentifier(); + if (this.isContextual("is") && !this.hasPrecedingLineBreak()) { + this.next(); + return id; + } + } + + tsParseTypeAnnotation( + eatColon = true, + t: N.TsTypeAnnotation = this.startNode(), + ): N.TsTypeAnnotation { + this.tsInType(() => { + if (eatColon) this.expect(tt.colon); + t.typeAnnotation = this.tsParseType(); + }); + return this.finishNode(t, "TSTypeAnnotation"); + } + + /** Be sure to be in a type context before calling this, using `tsInType`. */ + tsParseType(): N.TsType { + // Need to set `state.inType` so that we don't parse JSX in a type context. + assert(this.state.inType); + const type = this.tsParseNonConditionalType(); + if (this.hasPrecedingLineBreak() || !this.eat(tt._extends)) { + return type; + } + const node: N.TsConditionalType = this.startNodeAtNode(type); + node.checkType = type; + node.extendsType = this.tsParseNonConditionalType(); + this.expect(tt.question); + node.trueType = this.tsParseType(); + this.expect(tt.colon); + node.falseType = this.tsParseType(); + return this.finishNode(node, "TSConditionalType"); + } + + tsParseNonConditionalType(): N.TsType { + if (this.tsIsStartOfFunctionType()) { + return this.tsParseFunctionOrConstructorType("TSFunctionType"); + } + if (this.match(tt._new)) { + // As in `new () => Date` + return this.tsParseFunctionOrConstructorType("TSConstructorType"); + } + return this.tsParseUnionTypeOrHigher(); + } + + tsParseTypeAssertion(): N.TsTypeAssertion { + const node: N.TsTypeAssertion = this.startNode(); + const _const = this.tsTryNextParseConstantContext(); + node.typeAnnotation = _const || this.tsNextThenParseType(); + this.expectRelational(">"); + node.expression = this.parseMaybeUnary(); + return this.finishNode(node, "TSTypeAssertion"); + } + + tsParseHeritageClause( + descriptor: string, + ): $ReadOnlyArray { + const originalStart = this.state.start; + + const delimitedList = this.tsParseDelimitedList( + "HeritageClauseElement", + this.tsParseExpressionWithTypeArguments.bind(this), + ); + + if (!delimitedList.length) { + this.raise(originalStart, `'${descriptor}' list cannot be empty.`); + } + + return delimitedList; + } + + tsParseExpressionWithTypeArguments(): N.TsExpressionWithTypeArguments { + const node: N.TsExpressionWithTypeArguments = this.startNode(); + // Note: TS uses parseLeftHandSideExpressionOrHigher, + // then has grammar errors later if it's not an EntityName. + node.expression = this.tsParseEntityName(/* allowReservedWords */ false); + if (this.isRelational("<")) { + node.typeParameters = this.tsParseTypeArguments(); + } + + return this.finishNode(node, "TSExpressionWithTypeArguments"); + } + + tsParseInterfaceDeclaration( + node: N.TsInterfaceDeclaration, + ): N.TsInterfaceDeclaration { + node.id = this.parseIdentifier(); + this.checkLVal( + node.id, + BIND_TS_INTERFACE, + undefined, + "typescript interface declaration", + ); + node.typeParameters = this.tsTryParseTypeParameters(); + if (this.eat(tt._extends)) { + node.extends = this.tsParseHeritageClause("extends"); + } + const body: N.TSInterfaceBody = this.startNode(); + body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this)); + node.body = this.finishNode(body, "TSInterfaceBody"); + return this.finishNode(node, "TSInterfaceDeclaration"); + } + + tsParseTypeAliasDeclaration( + node: N.TsTypeAliasDeclaration, + ): N.TsTypeAliasDeclaration { + node.id = this.parseIdentifier(); + this.checkLVal(node.id, BIND_TS_TYPE, undefined, "typescript type alias"); + + node.typeParameters = this.tsTryParseTypeParameters(); + node.typeAnnotation = this.tsExpectThenParseType(tt.eq); + this.semicolon(); + return this.finishNode(node, "TSTypeAliasDeclaration"); + } + + tsInNoContext(cb: () => T): T { + const oldContext = this.state.context; + this.state.context = [oldContext[0]]; + try { + return cb(); + } finally { + this.state.context = oldContext; + } + } + + /** + * Runs `cb` in a type context. + * This should be called one token *before* the first type token, + * so that the call to `next()` is run in type context. + */ + tsInType(cb: () => T): T { + const oldInType = this.state.inType; + this.state.inType = true; + try { + return cb(); + } finally { + this.state.inType = oldInType; + } + } + + tsEatThenParseType(token: TokenType): N.TsType | typeof undefined { + return !this.match(token) ? undefined : this.tsNextThenParseType(); + } + + tsExpectThenParseType(token: TokenType): N.TsType { + return this.tsDoThenParseType(() => this.expect(token)); + } + + tsNextThenParseType(): N.TsType { + return this.tsDoThenParseType(() => this.next()); + } + + tsDoThenParseType(cb: () => void): N.TsType { + return this.tsInType(() => { + cb(); + return this.tsParseType(); + }); + } + + tsParseEnumMember(): N.TsEnumMember { + const node: N.TsEnumMember = this.startNode(); + // Computed property names are grammar errors in an enum, so accept just string literal or identifier. + node.id = this.match(tt.string) + ? this.parseExprAtom() + : this.parseIdentifier(/* liberal */ true); + if (this.eat(tt.eq)) { + node.initializer = this.parseMaybeAssign(); + } + return this.finishNode(node, "TSEnumMember"); + } + + tsParseEnumDeclaration( + node: N.TsEnumDeclaration, + isConst: boolean, + ): N.TsEnumDeclaration { + if (isConst) node.const = true; + node.id = this.parseIdentifier(); + this.checkLVal( + node.id, + isConst ? BIND_TS_CONST_ENUM : BIND_TS_ENUM, + undefined, + "typescript enum declaration", + ); + + this.expect(tt.braceL); + node.members = this.tsParseDelimitedList( + "EnumMembers", + this.tsParseEnumMember.bind(this), + ); + this.expect(tt.braceR); + return this.finishNode(node, "TSEnumDeclaration"); + } + + tsParseModuleBlock(): N.TsModuleBlock { + const node: N.TsModuleBlock = this.startNode(); + this.scope.enter(SCOPE_OTHER); + + this.expect(tt.braceL); + // Inside of a module block is considered "top-level", meaning it can have imports and exports. + this.parseBlockOrModuleBlockBody( + (node.body = []), + /* directives */ undefined, + /* topLevel */ true, + /* end */ tt.braceR, + ); + this.scope.exit(); + return this.finishNode(node, "TSModuleBlock"); + } + + tsParseModuleOrNamespaceDeclaration( + node: N.TsModuleDeclaration, + nested?: boolean = false, + ): N.TsModuleDeclaration { + node.id = this.parseIdentifier(); + + if (!nested) { + this.checkLVal( + node.id, + BIND_TS_NAMESPACE, + null, + "module or namespace declaration", + ); + } + + if (this.eat(tt.dot)) { + const inner = this.startNode(); + this.tsParseModuleOrNamespaceDeclaration(inner, true); + node.body = inner; + } else { + node.body = this.tsParseModuleBlock(); + } + return this.finishNode(node, "TSModuleDeclaration"); + } + + tsParseAmbientExternalModuleDeclaration( + node: N.TsModuleDeclaration, + ): N.TsModuleDeclaration { + if (this.isContextual("global")) { + node.global = true; + node.id = this.parseIdentifier(); + } else if (this.match(tt.string)) { + node.id = this.parseExprAtom(); + } else { + this.unexpected(); + } + + if (this.match(tt.braceL)) { + node.body = this.tsParseModuleBlock(); + } else { + this.semicolon(); + } + + return this.finishNode(node, "TSModuleDeclaration"); + } + + tsParseImportEqualsDeclaration( + node: N.TsImportEqualsDeclaration, + isExport?: boolean, + ): N.TsImportEqualsDeclaration { + node.isExport = isExport || false; + node.id = this.parseIdentifier(); + this.expect(tt.eq); + node.moduleReference = this.tsParseModuleReference(); + this.semicolon(); + return this.finishNode(node, "TSImportEqualsDeclaration"); + } + + tsIsExternalModuleReference(): boolean { + return ( + this.isContextual("require") && this.lookahead().type === tt.parenL + ); + } + + tsParseModuleReference(): N.TsModuleReference { + return this.tsIsExternalModuleReference() + ? this.tsParseExternalModuleReference() + : this.tsParseEntityName(/* allowReservedWords */ false); + } + + tsParseExternalModuleReference(): N.TsExternalModuleReference { + const node: N.TsExternalModuleReference = this.startNode(); + this.expectContextual("require"); + this.expect(tt.parenL); + if (!this.match(tt.string)) { + throw this.unexpected(); + } + // For compatibility to estree we cannot call parseLiteral directly here + node.expression = this.parseExprAtom(); + this.expect(tt.parenR); + return this.finishNode(node, "TSExternalModuleReference"); + } + + // Utilities + + tsLookAhead(f: () => T): T { + const state = this.state.clone(); + const res = f(); + this.state = state; + return res; + } + + tsTryParseAndCatch(f: () => T): ?T { + const state = this.state.clone(); + try { + return f(); + } catch (e) { + if (e instanceof SyntaxError) { + this.state = state; + return undefined; + } + throw e; + } + } + + tsTryParse(f: () => ?T): ?T { + const state = this.state.clone(); + const result = f(); + if (result !== undefined && result !== false) { + return result; + } else { + this.state = state; + return undefined; + } + } + + tsTryParseDeclare(nany: any): ?N.Declaration { + if (this.isLineTerminator()) { + return; + } + let starttype = this.state.type; + let kind; + + if (this.isContextual("let")) { + starttype = tt._var; + kind = "let"; + } + + switch (starttype) { + case tt._function: + return this.parseFunctionStatement( + nany, + /* async */ false, + /* declarationPosition */ true, + ); + case tt._class: + return this.parseClass( + nany, + /* isStatement */ true, + /* optionalId */ false, + ); + case tt._const: + if (this.match(tt._const) && this.isLookaheadContextual("enum")) { + // `const enum = 0;` not allowed because "enum" is a strict mode reserved word. + this.expect(tt._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(nany, /* isConst */ true); + } + // falls through + case tt._var: + kind = kind || this.state.value; + return this.parseVarStatement(nany, kind); + case tt.name: { + const value = this.state.value; + if (value === "global") { + return this.tsParseAmbientExternalModuleDeclaration(nany); + } else { + return this.tsParseDeclaration(nany, value, /* next */ true); + } + } + } + } + + // Note: this won't be called unless the keyword is allowed in `shouldParseExportDeclaration`. + tsTryParseExportDeclaration(): ?N.Declaration { + return this.tsParseDeclaration( + this.startNode(), + this.state.value, + /* next */ true, + ); + } + + tsParseExpressionStatement(node: any, expr: N.Identifier): ?N.Declaration { + switch (expr.name) { + case "declare": { + const declaration = this.tsTryParseDeclare(node); + if (declaration) { + declaration.declare = true; + return declaration; + } + break; + } + case "global": + // `global { }` (with no `declare`) may appear inside an ambient module declaration. + // Would like to use tsParseAmbientExternalModuleDeclaration here, but already ran past "global". + if (this.match(tt.braceL)) { + const mod: N.TsModuleDeclaration = node; + mod.global = true; + mod.id = expr; + mod.body = this.tsParseModuleBlock(); + return this.finishNode(mod, "TSModuleDeclaration"); + } + break; + + default: + return this.tsParseDeclaration(node, expr.name, /* next */ false); + } + } + + // Common to tsTryParseDeclare, tsTryParseExportDeclaration, and tsParseExpressionStatement. + tsParseDeclaration( + node: any, + value: string, + next: boolean, + ): ?N.Declaration { + switch (value) { + case "abstract": + if (this.tsCheckLineTerminatorAndMatch(tt._class, next)) { + const cls: N.ClassDeclaration = node; + cls.abstract = true; + if (next) { + this.next(); + if (!this.match(tt._class)) { + this.unexpected(null, tt._class); + } + } + return this.parseClass( + cls, + /* isStatement */ true, + /* optionalId */ false, + ); + } + break; + + case "enum": + if (next || this.match(tt.name)) { + if (next) this.next(); + return this.tsParseEnumDeclaration(node, /* isConst */ false); + } + break; + + case "interface": + if (this.tsCheckLineTerminatorAndMatch(tt.name, next)) { + if (next) this.next(); + return this.tsParseInterfaceDeclaration(node); + } + break; + + case "module": + if (next) this.next(); + if (this.match(tt.string)) { + return this.tsParseAmbientExternalModuleDeclaration(node); + } else if (this.tsCheckLineTerminatorAndMatch(tt.name, next)) { + return this.tsParseModuleOrNamespaceDeclaration(node); + } + break; + + case "namespace": + if (this.tsCheckLineTerminatorAndMatch(tt.name, next)) { + if (next) this.next(); + return this.tsParseModuleOrNamespaceDeclaration(node); + } + break; + + case "type": + if (this.tsCheckLineTerminatorAndMatch(tt.name, next)) { + if (next) this.next(); + return this.tsParseTypeAliasDeclaration(node); + } + break; + } + } + + tsCheckLineTerminatorAndMatch(tokenType: TokenType, next: boolean) { + return (next || this.match(tokenType)) && !this.isLineTerminator(); + } + + tsTryParseGenericAsyncArrowFunction( + startPos: number, + startLoc: Position, + ): ?N.ArrowFunctionExpression { + if (!this.isRelational("<")) { + return undefined; + } + const res: ?N.ArrowFunctionExpression = this.tsTryParseAndCatch(() => { + const node: N.ArrowFunctionExpression = this.startNodeAt( + startPos, + startLoc, + ); + node.typeParameters = this.tsParseTypeParameters(); + // Don't use overloaded parseFunctionParams which would look for "<" again. + super.parseFunctionParams(node); + node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); + this.expect(tt.arrow); + return node; + }); + + if (!res) { + return undefined; + } + + return this.parseArrowExpression( + res, + /* params are already set */ null, + /* async */ true, + ); + } + + tsParseTypeArguments(): N.TsTypeParameterInstantiation { + const node = this.startNode(); + node.params = this.tsInType(() => + // Temporarily remove a JSX parsing context, which makes us scan different tokens. + this.tsInNoContext(() => { + this.expectRelational("<"); + return this.tsParseDelimitedList( + "TypeParametersOrArguments", + this.tsParseType.bind(this), + ); + }), + ); + // This reads the next token after the `>` too, so do this in the enclosing context. + // But be sure not to parse a regex in the jsx expression ` />`, so set exprAllowed = false + this.state.exprAllowed = false; + this.expectRelational(">"); + return this.finishNode(node, "TSTypeParameterInstantiation"); + } + + tsIsDeclarationStart(): boolean { + if (this.match(tt.name)) { + switch (this.state.value) { + case "abstract": + case "declare": + case "enum": + case "interface": + case "module": + case "namespace": + case "type": + return true; + } + } + + return false; + } + + // ====================================================== + // OVERRIDES + // ====================================================== + + isExportDefaultSpecifier(): boolean { + if (this.tsIsDeclarationStart()) return false; + return super.isExportDefaultSpecifier(); + } + + parseAssignableListItem( + allowModifiers: ?boolean, + decorators: N.Decorator[], + ): N.Pattern | N.TSParameterProperty { + // Store original location/position to include modifiers in range + const startPos = this.state.start; + const startLoc = this.state.startLoc; + + let accessibility: ?N.Accessibility; + let readonly = false; + if (allowModifiers) { + accessibility = this.parseAccessModifier(); + readonly = !!this.tsParseModifier(["readonly"]); + } + + const left = this.parseMaybeDefault(); + this.parseAssignableListItemTypes(left); + const elt = this.parseMaybeDefault(left.start, left.loc.start, left); + if (accessibility || readonly) { + const pp: N.TSParameterProperty = this.startNodeAt(startPos, startLoc); + if (decorators.length) { + pp.decorators = decorators; + } + if (accessibility) pp.accessibility = accessibility; + if (readonly) pp.readonly = readonly; + if (elt.type !== "Identifier" && elt.type !== "AssignmentPattern") { + throw this.raise( + pp.start, + "A parameter property may not be declared using a binding pattern.", + ); + } + pp.parameter = elt; + return this.finishNode(pp, "TSParameterProperty"); + } + + if (decorators.length) { + left.decorators = decorators; + } + + return elt; + } + + parseFunctionBodyAndFinish( + node: N.BodilessFunctionOrMethodBase, + type: string, + isMethod?: boolean = false, + ): void { + if (this.match(tt.colon)) { + node.returnType = this.tsParseTypeOrTypePredicateAnnotation(tt.colon); + } + + const bodilessType = + type === "FunctionDeclaration" + ? "TSDeclareFunction" + : type === "ClassMethod" + ? "TSDeclareMethod" + : undefined; + if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) { + this.finishNode(node, bodilessType); + return; + } + + super.parseFunctionBodyAndFinish(node, type, isMethod); + } + + checkFunctionStatementId(node: N.Function): void { + if (!node.body && node.id) { + this.checkLVal(node.id, BIND_TS_FN_TYPE, null, "function name"); + } else { + super.checkFunctionStatementId(...arguments); + } + } + + parseSubscript( + base: N.Expression, + startPos: number, + startLoc: Position, + noCalls: ?boolean, + state: N.ParseSubscriptState, + maybeAsyncArrow: boolean, + ): N.Expression { + if (!this.hasPrecedingLineBreak() && this.match(tt.bang)) { + this.state.exprAllowed = false; + this.next(); + + const nonNullExpression: N.TsNonNullExpression = this.startNodeAt( + startPos, + startLoc, + ); + nonNullExpression.expression = base; + return this.finishNode(nonNullExpression, "TSNonNullExpression"); + } + + if (this.isRelational("<")) { + // tsTryParseAndCatch is expensive, so avoid if not necessary. + // There are number of things we are going to "maybe" parse, like type arguments on + // tagged template expressions. If any of them fail, walk it back and continue. + const result = this.tsTryParseAndCatch(() => { + if (!noCalls && this.atPossibleAsync(base)) { + // Almost certainly this is a generic async function `async () => ... + // But it might be a call with a type argument `async();` + const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction( + startPos, + startLoc, + ); + if (asyncArrowFn) { + return asyncArrowFn; + } + } + + const node: N.CallExpression = this.startNodeAt(startPos, startLoc); + node.callee = base; + + const typeArguments = this.tsParseTypeArguments(); + + if (typeArguments) { + if (!noCalls && this.eat(tt.parenL)) { + // possibleAsync always false here, because we would have handled it above. + // $FlowIgnore (won't be any undefined arguments) + node.arguments = this.parseCallExpressionArguments( + tt.parenR, + /* possibleAsync */ false, + ); + node.typeParameters = typeArguments; + return this.finishCallExpression(node); + } else if (this.match(tt.backQuote)) { + return this.parseTaggedTemplateExpression( + startPos, + startLoc, + base, + state, + typeArguments, + ); + } + } + + this.unexpected(); + }); + + if (result) return result; + } + + return super.parseSubscript( + base, + startPos, + startLoc, + noCalls, + state, + maybeAsyncArrow, + ); + } + + parseNewArguments(node: N.NewExpression): void { + if (this.isRelational("<")) { + // tsTryParseAndCatch is expensive, so avoid if not necessary. + // 99% certain this is `new C();`. But may be `new C < T;`, which is also legal. + const typeParameters = this.tsTryParseAndCatch(() => { + const args = this.tsParseTypeArguments(); + if (!this.match(tt.parenL)) this.unexpected(); + return args; + }); + if (typeParameters) { + node.typeParameters = typeParameters; + } + } + + super.parseNewArguments(node); + } + + parseExprOp( + left: N.Expression, + leftStartPos: number, + leftStartLoc: Position, + minPrec: number, + noIn: ?boolean, + ) { + if ( + nonNull(tt._in.binop) > minPrec && + !this.hasPrecedingLineBreak() && + this.isContextual("as") + ) { + const node: N.TsAsExpression = this.startNodeAt( + leftStartPos, + leftStartLoc, + ); + node.expression = left; + const _const = this.tsTryNextParseConstantContext(); + if (_const) { + node.typeAnnotation = _const; + } else { + node.typeAnnotation = this.tsNextThenParseType(); + } + this.finishNode(node, "TSAsExpression"); + return this.parseExprOp( + node, + leftStartPos, + leftStartLoc, + minPrec, + noIn, + ); + } + + return super.parseExprOp(left, leftStartPos, leftStartLoc, minPrec, noIn); + } + + checkReservedWord( + word: string, // eslint-disable-line no-unused-vars + startLoc: number, // eslint-disable-line no-unused-vars + checkKeywords: boolean, // eslint-disable-line no-unused-vars + // eslint-disable-next-line no-unused-vars + isBinding: boolean, + ): void { + // Don't bother checking for TypeScript code. + // Strict mode words may be allowed as in `declare namespace N { const static: number; }`. + // And we have a type checker anyway, so don't bother having the parser do it. + } + + /* + Don't bother doing this check in TypeScript code because: + 1. We may have a nested export statement with the same name: + export const x = 0; + export namespace N { + export const x = 1; + } + 2. We have a type checker to warn us about this sort of thing. + */ + checkDuplicateExports() {} + + parseImport(node: N.Node): N.AnyImport { + if (this.match(tt.name) && this.lookahead().type === tt.eq) { + return this.tsParseImportEqualsDeclaration(node); + } + return super.parseImport(node); + } + + parseExport(node: N.Node): N.AnyExport { + if (this.match(tt._import)) { + // `export import A = B;` + this.expect(tt._import); + return this.tsParseImportEqualsDeclaration(node, /* isExport */ true); + } else if (this.eat(tt.eq)) { + // `export = x;` + const assign: N.TsExportAssignment = node; + assign.expression = this.parseExpression(); + this.semicolon(); + return this.finishNode(assign, "TSExportAssignment"); + } else if (this.eatContextual("as")) { + // `export as namespace A;` + const decl: N.TsNamespaceExportDeclaration = node; + // See `parseNamespaceExportDeclaration` in TypeScript's own parser + this.expectContextual("namespace"); + decl.id = this.parseIdentifier(); + this.semicolon(); + return this.finishNode(decl, "TSNamespaceExportDeclaration"); + } else { + return super.parseExport(node); + } + } + + isAbstractClass(): boolean { + return ( + this.isContextual("abstract") && this.lookahead().type === tt._class + ); + } + + parseExportDefaultExpression(): N.Expression | N.Declaration { + if (this.isAbstractClass()) { + const cls = this.startNode(); + this.next(); // Skip "abstract" + this.parseClass(cls, true, true); + cls.abstract = true; + return cls; + } + + // export default interface allowed in: + // https://github.com/Microsoft/TypeScript/pull/16040 + if (this.state.value === "interface") { + const result = this.tsParseDeclaration( + this.startNode(), + this.state.value, + true, + ); + + if (result) return result; + } + + return super.parseExportDefaultExpression(); + } + + parseStatementContent(context: ?string, topLevel: ?boolean): N.Statement { + if (this.state.type === tt._const) { + const ahead = this.lookahead(); + if (ahead.type === tt.name && ahead.value === "enum") { + const node: N.TsEnumDeclaration = this.startNode(); + this.expect(tt._const); + this.expectContextual("enum"); + return this.tsParseEnumDeclaration(node, /* isConst */ true); + } + } + return super.parseStatementContent(context, topLevel); + } + + parseAccessModifier(): ?N.Accessibility { + return this.tsParseModifier(["public", "protected", "private"]); + } + + parseClassMember( + classBody: N.ClassBody, + member: any, + state: { hadConstructor: boolean }, + constructorAllowsSuper: boolean, + ): void { + const accessibility = this.parseAccessModifier(); + if (accessibility) member.accessibility = accessibility; + + super.parseClassMember(classBody, member, state, constructorAllowsSuper); + } + + parseClassMemberWithIsStatic( + classBody: N.ClassBody, + member: any, + state: { hadConstructor: boolean }, + isStatic: boolean, + constructorAllowsSuper: boolean, + ): void { + const methodOrProp: N.ClassMethod | N.ClassProperty = member; + const prop: N.ClassProperty = member; + const propOrIdx: N.ClassProperty | N.TsIndexSignature = member; + + let abstract = false, + readonly = false; + + const mod = this.tsParseModifier(["abstract", "readonly"]); + switch (mod) { + case "readonly": + readonly = true; + abstract = !!this.tsParseModifier(["abstract"]); + break; + case "abstract": + abstract = true; + readonly = !!this.tsParseModifier(["readonly"]); + break; + } + + if (abstract) methodOrProp.abstract = true; + if (readonly) propOrIdx.readonly = true; + + if (!abstract && !isStatic && !methodOrProp.accessibility) { + const idx = this.tsTryParseIndexSignature(member); + if (idx) { + classBody.body.push(idx); + return; + } + } + + if (readonly) { + // Must be a property (if not an index signature). + methodOrProp.static = isStatic; + this.parseClassPropertyName(prop); + this.parsePostMemberNameModifiers(methodOrProp); + this.pushClassProperty(classBody, prop); + return; + } + + super.parseClassMemberWithIsStatic( + classBody, + member, + state, + isStatic, + constructorAllowsSuper, + ); + } + + parsePostMemberNameModifiers( + methodOrProp: N.ClassMethod | N.ClassProperty, + ): void { + const optional = this.eat(tt.question); + if (optional) methodOrProp.optional = true; + } + + // Note: The reason we do this in `parseExpressionStatement` and not `parseStatement` + // is that e.g. `type()` is valid JS, so we must try parsing that first. + // If it's really a type, we will parse `type` as the statement, and can correct it here + // by parsing the rest. + parseExpressionStatement( + node: N.ExpressionStatement, + expr: N.Expression, + ): N.Statement { + const decl = + expr.type === "Identifier" + ? this.tsParseExpressionStatement(node, expr) + : undefined; + return decl || super.parseExpressionStatement(node, expr); + } + + // export type + // Should be true for anything parsed by `tsTryParseExportDeclaration`. + shouldParseExportDeclaration(): boolean { + if (this.tsIsDeclarationStart()) return true; + return super.shouldParseExportDeclaration(); + } + + // An apparent conditional expression could actually be an optional parameter in an arrow function. + parseConditional( + expr: N.Expression, + noIn: ?boolean, + startPos: number, + startLoc: Position, + refNeedsArrowPos?: ?Pos, + ): N.Expression { + // only do the expensive clone if there is a question mark + // and if we come from inside parens + if (!refNeedsArrowPos || !this.match(tt.question)) { + return super.parseConditional( + expr, + noIn, + startPos, + startLoc, + refNeedsArrowPos, + ); + } + + const state = this.state.clone(); + try { + return super.parseConditional(expr, noIn, startPos, startLoc); + } catch (err) { + if (!(err instanceof SyntaxError)) { + // istanbul ignore next: no such error is expected + throw err; + } + + this.state = state; + refNeedsArrowPos.start = err.pos || this.state.start; + return expr; + } + } + + // Note: These "type casts" are *not* valid TS expressions. + // But we parse them here and change them when completing the arrow function. + parseParenItem( + node: N.Expression, + startPos: number, + startLoc: Position, + ): N.Expression { + node = super.parseParenItem(node, startPos, startLoc); + if (this.eat(tt.question)) { + node.optional = true; + // Include questionmark in location of node + // Don't use this.finishNode() as otherwise we might process comments twice and + // include already consumed parens + this.resetEndLocation(node); + } + + if (this.match(tt.colon)) { + const typeCastNode: N.TsTypeCastExpression = this.startNodeAt( + startPos, + startLoc, + ); + typeCastNode.expression = node; + typeCastNode.typeAnnotation = this.tsParseTypeAnnotation(); + + return this.finishNode(typeCastNode, "TSTypeCastExpression"); + } + + return node; + } + + parseExportDeclaration(node: N.ExportNamedDeclaration): ?N.Declaration { + // Store original location/position + const startPos = this.state.start; + const startLoc = this.state.startLoc; + + // "export declare" is equivalent to just "export". + const isDeclare = this.eatContextual("declare"); + + let declaration: ?N.Declaration; + + if (this.match(tt.name)) { + declaration = this.tsTryParseExportDeclaration(); + } + if (!declaration) { + declaration = super.parseExportDeclaration(node); + } + + if (declaration && isDeclare) { + // Reset location to include `declare` in range + this.resetStartLocation(declaration, startPos, startLoc); + + declaration.declare = true; + } + + return declaration; + } + + parseClassId( + node: N.Class, + isStatement: boolean, + optionalId: ?boolean, + ): void { + if ((!isStatement || optionalId) && this.isContextual("implements")) { + return; + } + + super.parseClassId(...arguments); + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + } + + parseClassProperty(node: N.ClassProperty): N.ClassProperty { + if (!node.optional && this.eat(tt.bang)) { + node.definite = true; + } + + const type = this.tsTryParseTypeAnnotation(); + if (type) node.typeAnnotation = type; + return super.parseClassProperty(node); + } + + pushClassMethod( + classBody: N.ClassBody, + method: N.ClassMethod, + isGenerator: boolean, + isAsync: boolean, + isConstructor: boolean, + allowsDirectSuper: boolean, + ): void { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassMethod( + classBody, + method, + isGenerator, + isAsync, + isConstructor, + allowsDirectSuper, + ); + } + + pushClassPrivateMethod( + classBody: N.ClassBody, + method: N.ClassPrivateMethod, + isGenerator: boolean, + isAsync: boolean, + ): void { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) method.typeParameters = typeParameters; + super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); + } + + parseClassSuper(node: N.Class): void { + super.parseClassSuper(node); + if (node.superClass && this.isRelational("<")) { + node.superTypeParameters = this.tsParseTypeArguments(); + } + if (this.eatContextual("implements")) { + node.implements = this.tsParseHeritageClause("implements"); + } + } + + parseObjPropValue(prop: N.ObjectMember, ...args): void { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) prop.typeParameters = typeParameters; + + super.parseObjPropValue(prop, ...args); + } + + parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { + const typeParameters = this.tsTryParseTypeParameters(); + if (typeParameters) node.typeParameters = typeParameters; + super.parseFunctionParams(node, allowModifiers); + } + + // `let x: number;` + parseVarId( + decl: N.VariableDeclarator, + kind: "var" | "let" | "const", + ): void { + super.parseVarId(decl, kind); + if (decl.id.type === "Identifier" && this.eat(tt.bang)) { + decl.definite = true; + } + + const type = this.tsTryParseTypeAnnotation(); + if (type) { + decl.id.typeAnnotation = type; + this.resetEndLocation(decl.id); // set end position to end of type + } + } + + // parse the return type of an async arrow function - let foo = (async (): number => {}); + parseAsyncArrowFromCallExpression( + node: N.ArrowFunctionExpression, + call: N.CallExpression, + ): N.ArrowFunctionExpression { + if (this.match(tt.colon)) { + node.returnType = this.tsParseTypeAnnotation(); + } + return super.parseAsyncArrowFromCallExpression(node, call); + } + + parseMaybeAssign(...args): N.Expression { + // Note: When the JSX plugin is on, type assertions (` x`) aren't valid syntax. + + let jsxError: ?SyntaxError; + + if (this.match(tt.jsxTagStart)) { + const context = this.curContext(); + assert(context === ct.j_oTag); + // Only time j_oTag is pushed is right after j_expr. + assert(this.state.context[this.state.context.length - 2] === ct.j_expr); + + // Prefer to parse JSX if possible. But may be an arrow fn. + const state = this.state.clone(); + try { + return super.parseMaybeAssign(...args); + } catch (err) { + if (!(err instanceof SyntaxError)) { + // istanbul ignore next: no such error is expected + throw err; + } + + this.state = state; + // Pop the context added by the jsxTagStart. + assert(this.curContext() === ct.j_oTag); + this.state.context.pop(); + assert(this.curContext() === ct.j_expr); + this.state.context.pop(); + jsxError = err; + } + } + + if (jsxError === undefined && !this.isRelational("<")) { + return super.parseMaybeAssign(...args); + } + + // Either way, we're looking at a '<': tt.jsxTagStart or relational. + + let arrowExpression; + let typeParameters: N.TsTypeParameterDeclaration; + const state = this.state.clone(); + try { + // This is similar to TypeScript's `tryParseParenthesizedArrowFunctionExpression`. + typeParameters = this.tsParseTypeParameters(); + arrowExpression = super.parseMaybeAssign(...args); + if ( + arrowExpression.type !== "ArrowFunctionExpression" || + (arrowExpression.extra && arrowExpression.extra.parenthesized) + ) { + this.unexpected(); // Go to the catch block (needs a SyntaxError). + } + } catch (err) { + if (!(err instanceof SyntaxError)) { + // istanbul ignore next: no such error is expected + throw err; + } + + if (jsxError) { + throw jsxError; + } + + // Try parsing a type cast instead of an arrow function. + // This will never happen outside of JSX. + // (Because in JSX the '<' should be a jsxTagStart and not a relational. + assert(!this.hasPlugin("jsx")); + // Parsing an arrow function failed, so try a type cast. + this.state = state; + // This will start with a type assertion (via parseMaybeUnary). + // But don't directly call `this.tsParseTypeAssertion` because we want to handle any binary after it. + return super.parseMaybeAssign(...args); + } + + // Correct TypeScript code should have at least 1 type parameter, but don't crash on bad code. + if (typeParameters && typeParameters.params.length !== 0) { + this.resetStartLocationFromNode(arrowExpression, typeParameters); + } + arrowExpression.typeParameters = typeParameters; + return arrowExpression; + } + + // Handle type assertions + parseMaybeUnary(refShorthandDefaultPos?: ?Pos): N.Expression { + if (!this.hasPlugin("jsx") && this.isRelational("<")) { + return this.tsParseTypeAssertion(); + } else { + return super.parseMaybeUnary(refShorthandDefaultPos); + } + } + + parseArrow(node: N.ArrowFunctionExpression): ?N.ArrowFunctionExpression { + if (this.match(tt.colon)) { + // This is different from how the TS parser does it. + // TS uses lookahead. The Babel Parser parses it as a parenthesized expression and converts. + const state = this.state.clone(); + try { + const returnType = this.tsParseTypeOrTypePredicateAnnotation( + tt.colon, + ); + if (this.canInsertSemicolon() || !this.match(tt.arrow)) { + this.state = state; + return undefined; + } + node.returnType = returnType; + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + } else { + // istanbul ignore next: no such error is expected + throw err; + } + } + } + + return super.parseArrow(node); + } + + // Allow type annotations inside of a parameter list. + parseAssignableListItemTypes(param: N.Pattern) { + if (this.eat(tt.question)) { + if (param.type !== "Identifier") { + throw this.raise( + param.start, + "A binding pattern parameter cannot be optional in an implementation signature.", + ); + } + + param.optional = true; + } + const type = this.tsTryParseTypeAnnotation(); + if (type) param.typeAnnotation = type; + this.resetEndLocation(param); + + return param; + } + + toAssignable( + node: N.Node, + isBinding: ?boolean, + contextDescription: string, + ): N.Node { + switch (node.type) { + case "TSTypeCastExpression": + return super.toAssignable( + this.typeCastToParameter(node), + isBinding, + contextDescription, + ); + case "TSParameterProperty": + return super.toAssignable(node, isBinding, contextDescription); + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + node.expression = this.toAssignable( + node.expression, + isBinding, + contextDescription, + ); + return node; + default: + return super.toAssignable(node, isBinding, contextDescription); + } + } + + checkLVal( + expr: N.Expression, + bindingType: BindingTypes = BIND_NONE, + checkClashes: ?{ [key: string]: boolean }, + contextDescription: string, + ): void { + switch (expr.type) { + case "TSTypeCastExpression": + // Allow "typecasts" to appear on the left of assignment expressions, + // because it may be in an arrow function. + // e.g. `const f = (foo: number = 0) => foo;` + return; + case "TSParameterProperty": + this.checkLVal( + expr.parameter, + bindingType, + checkClashes, + "parameter property", + ); + return; + case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": + this.checkLVal( + expr.expression, + bindingType, + checkClashes, + contextDescription, + ); + return; + default: + super.checkLVal(expr, bindingType, checkClashes, contextDescription); + return; + } + } + + parseBindingAtom(): N.Pattern { + switch (this.state.type) { + case tt._this: + // "this" may be the name of a parameter, so allow it. + return this.parseIdentifier(/* liberal */ true); + default: + return super.parseBindingAtom(); + } + } + + parseMaybeDecoratorArguments(expr: N.Expression): N.Expression { + if (this.isRelational("<")) { + const typeArguments = this.tsParseTypeArguments(); + + if (this.match(tt.parenL)) { + const call = super.parseMaybeDecoratorArguments(expr); + call.typeParameters = typeArguments; + return call; + } + + this.unexpected(this.state.start, tt.parenL); + } + + return super.parseMaybeDecoratorArguments(expr); + } + + // === === === === === === === === === === === === === === === === + // Note: All below methods are duplicates of something in flow.js. + // Not sure what the best way to combine these is. + // === === === === === === === === === === === === === === === === + + isClassMethod(): boolean { + return this.isRelational("<") || super.isClassMethod(); + } + + isClassProperty(): boolean { + return ( + this.match(tt.bang) || this.match(tt.colon) || super.isClassProperty() + ); + } + + parseMaybeDefault(...args): N.Pattern { + const node = super.parseMaybeDefault(...args); + + if ( + node.type === "AssignmentPattern" && + node.typeAnnotation && + node.right.start < node.typeAnnotation.start + ) { + this.raise( + node.typeAnnotation.start, + "Type annotations must come before default assignments, " + + "e.g. instead of `age = 25: number` use `age: number = 25`", + ); + } + + return node; + } + + // ensure that inside types, we bypass the jsx parser plugin + getTokenFromCode(code: number): void { + if (this.state.inType && (code === 62 || code === 60)) { + return this.finishOp(tt.relational, 1); + } else { + return super.getTokenFromCode(code); + } + } + + toAssignableList( + exprList: N.Expression[], + isBinding: ?boolean, + contextDescription: string, + ): $ReadOnlyArray { + for (let i = 0; i < exprList.length; i++) { + const expr = exprList[i]; + if (!expr) continue; + switch (expr.type) { + case "TSTypeCastExpression": + exprList[i] = this.typeCastToParameter(expr); + break; + case "TSAsExpression": + case "TSTypeAssertion": + this.raise( + expr.start, + "Unexpected type cast in parameter position.", + ); + break; + } + } + return super.toAssignableList(exprList, isBinding, contextDescription); + } + + typeCastToParameter(node: N.TsTypeCastExpression): N.Node { + node.expression.typeAnnotation = node.typeAnnotation; + + this.resetEndLocation( + node.expression, + node.typeAnnotation.end, + node.typeAnnotation.loc.end, + ); + + return node.expression; + } + + toReferencedList( + exprList: $ReadOnlyArray, + isInParens?: boolean, // eslint-disable-line no-unused-vars + ): $ReadOnlyArray { + for (let i = 0; i < exprList.length; i++) { + const expr = exprList[i]; + if ( + expr && + expr._exprListItem && + expr.type === "TsTypeCastExpression" + ) { + this.raise(expr.start, "Did not expect a type annotation here."); + } + } + + return exprList; + } + + shouldParseArrow() { + return this.match(tt.colon) || super.shouldParseArrow(); + } + + shouldParseAsyncArrow(): boolean { + return this.match(tt.colon) || super.shouldParseAsyncArrow(); + } + + canHaveLeadingDecorator() { + // Avoid unnecessary lookahead in checking for abstract class unless needed! + return super.canHaveLeadingDecorator() || this.isAbstractClass(); + } + + jsxParseOpeningElementAfterName( + node: N.JSXOpeningElement, + ): N.JSXOpeningElement { + if (this.isRelational("<")) { + const typeArguments = this.tsTryParseAndCatch(() => + this.tsParseTypeArguments(), + ); + if (typeArguments) node.typeParameters = typeArguments; + } + return super.jsxParseOpeningElementAfterName(node); + } + + getGetterSetterExpectedParamCount( + method: N.ObjectMethod | N.ClassMethod, + ): number { + const baseCount = super.getGetterSetterExpectedParamCount(method); + const firstParam = method.params[0]; + const hasContextParam = + firstParam && + firstParam.type === "Identifier" && + firstParam.name === "this"; + + return hasContextParam ? baseCount + 1 : baseCount; + } + }; diff --git a/packages/babel-parser/src/plugins/typescript/scope.js b/packages/babel-parser/src/plugins/typescript/scope.js new file mode 100644 index 000000000000..f706f1e88e99 --- /dev/null +++ b/packages/babel-parser/src/plugins/typescript/scope.js @@ -0,0 +1,105 @@ +// @flow + +import ScopeHandler, { Scope } from "../../util/scope"; +import { + BIND_KIND_TYPE, + BIND_FLAGS_TS_ENUM, + BIND_FLAGS_TS_CONST_ENUM, + BIND_FLAGS_TS_EXPORT_ONLY, + BIND_KIND_VALUE, + BIND_FLAGS_CLASS, + type ScopeFlags, + type BindingTypes, +} from "../../util/scopeflags"; +import * as N from "../../types"; + +class TypeScriptScope extends Scope { + types: string[] = []; + + // enums (which are also in .types) + enums: string[] = []; + + // const enums (which are also in .enums and .types) + constEnums: string[] = []; + + // classes (which are also in .lexical) and interface (which are also in .types) + classes: string[] = []; + + // namespaces and bodyless-functions are too difficult to track, + // especially without type analysis. + // We need to track them anyway, to avoid "X is not defined" errors + // when exporting them. + exportOnlyBindings: string[] = []; +} + +// See https://github.com/babel/babel/pull/9766#discussion_r268920730 for an +// explanation of how typescript handles scope. + +export default class TypeScriptScopeHandler extends ScopeHandler { + createScope(flags: ScopeFlags): TypeScriptScope { + return new TypeScriptScope(flags); + } + + declareName(name: string, bindingType: BindingTypes, pos: number) { + const scope = this.currentScope(); + if (bindingType & BIND_FLAGS_TS_EXPORT_ONLY) { + this.maybeExportDefined(scope, name); + scope.exportOnlyBindings.push(name); + return; + } + + super.declareName(...arguments); + + if (bindingType & BIND_KIND_TYPE) { + if (!(bindingType & BIND_KIND_VALUE)) { + // "Value" bindings have already been registered by the superclass. + this.checkRedeclarationInScope(scope, name, bindingType, pos); + this.maybeExportDefined(scope, name); + } + scope.types.push(name); + } + if (bindingType & BIND_FLAGS_TS_ENUM) scope.enums.push(name); + if (bindingType & BIND_FLAGS_TS_CONST_ENUM) scope.constEnums.push(name); + if (bindingType & BIND_FLAGS_CLASS) scope.classes.push(name); + } + + isRedeclaredInScope( + scope: TypeScriptScope, + name: string, + bindingType: BindingTypes, + ): boolean { + if (scope.enums.indexOf(name) > -1) { + if (bindingType & BIND_FLAGS_TS_ENUM) { + // Enums can be merged with other enums if they are both + // const or both non-const. + const isConst = !!(bindingType & BIND_FLAGS_TS_CONST_ENUM); + const wasConst = scope.constEnums.indexOf(name) > -1; + return isConst !== wasConst; + } + return true; + } + if (bindingType & BIND_FLAGS_CLASS && scope.classes.indexOf(name) > -1) { + if (scope.lexical.indexOf(name) > -1) { + // Classes can be merged with interfaces + return !!(bindingType & BIND_KIND_VALUE); + } else { + // Interface can be merged with other classes or interfaces + return false; + } + } + if (bindingType & BIND_KIND_TYPE && scope.types.indexOf(name) > -1) { + return true; + } + + return super.isRedeclaredInScope(...arguments); + } + + checkLocalExport(id: N.Identifier) { + if ( + this.scopeStack[0].types.indexOf(id.name) === -1 && + this.scopeStack[0].exportOnlyBindings.indexOf(id.name) === -1 + ) { + super.checkLocalExport(id); + } + } +} diff --git a/packages/babel-parser/src/tokenizer/context.js b/packages/babel-parser/src/tokenizer/context.js index 11fe53d2d207..1d8108874f4a 100644 --- a/packages/babel-parser/src/tokenizer/context.js +++ b/packages/babel-parser/src/tokenizer/context.js @@ -12,7 +12,7 @@ export class TokContext { token: string, isExpr?: boolean, preserveSpace?: boolean, - override?: Function, // Takes a Tokenizer as a this-parameter, and returns void. + override?: ?Function, // Takes a Tokenizer as a this-parameter, and returns void. ) { this.token = token; this.isExpr = !!isExpr; @@ -31,11 +31,12 @@ export const types: { } = { braceStatement: new TokContext("{", false), braceExpression: new TokContext("{", true), - templateQuasi: new TokContext("${", true), + templateQuasi: new TokContext("${", false), parenStatement: new TokContext("(", false), parenExpression: new TokContext("(", true), template: new TokContext("`", true, true, p => p.readTmplToken()), functionExpression: new TokContext("function", true), + functionStatement: new TokContext("function", false), }; // Token-specific context update code @@ -46,33 +47,26 @@ tt.parenR.updateContext = tt.braceR.updateContext = function() { return; } - const out = this.state.context.pop(); - if ( - out === types.braceStatement && - this.curContext() === types.functionExpression - ) { - this.state.context.pop(); - this.state.exprAllowed = false; - } else if (out === types.templateQuasi) { - this.state.exprAllowed = true; - } else { - this.state.exprAllowed = !out.isExpr; + let out = this.state.context.pop(); + if (out === types.braceStatement && this.curContext().token === "function") { + out = this.state.context.pop(); } + + this.state.exprAllowed = !out.isExpr; }; tt.name.updateContext = function(prevType) { - if (this.state.value === "of" && this.curContext() === types.parenStatement) { - this.state.exprAllowed = !prevType.beforeExpr; - return; - } - - this.state.exprAllowed = false; - - if (prevType === tt._let || prevType === tt._const || prevType === tt._var) { - if (lineBreak.test(this.input.slice(this.state.end))) { - this.state.exprAllowed = true; + let allowed = false; + if (prevType !== tt.dot) { + if ( + (this.state.value === "of" && !this.state.exprAllowed) || + (this.state.value === "yield" && this.scope.inGenerator) + ) { + allowed = true; } } + this.state.exprAllowed = allowed; + if (this.state.isIterator) { this.state.isIterator = false; } @@ -106,9 +100,23 @@ tt.incDec.updateContext = function() { // tokExprAllowed stays unchanged }; -tt._function.updateContext = function(prevType) { - if (this.state.exprAllowed && !this.braceIsBlock(prevType)) { +tt._function.updateContext = tt._class.updateContext = function(prevType) { + if ( + prevType.beforeExpr && + prevType !== tt.semi && + prevType !== tt._else && + !( + prevType === tt._return && + lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)) + ) && + !( + (prevType === tt.colon || prevType === tt.braceL) && + this.curContext() === types.b_stat + ) + ) { this.state.context.push(types.functionExpression); + } else { + this.state.context.push(types.functionStatement); } this.state.exprAllowed = false; diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 2b6cc06db3a4..ffb8cba8ca6f 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -3,11 +3,7 @@ import type { Options } from "../options"; import type { Position } from "../util/location"; import * as charCodes from "charcodes"; -import { - isIdentifierStart, - isIdentifierChar, - isKeyword, -} from "../util/identifier"; +import { isIdentifierStart, isIdentifierChar } from "../util/identifier"; import { types as tt, keywords as keywordTypes, type TokenType } from "./types"; import { type TokContext, types as ct } from "./context"; import LocationParser from "../parser/location"; @@ -20,7 +16,7 @@ import { } from "../util/whitespace"; import State from "./state"; -const VALID_REGEX_FLAGS = "gmsiyu"; +const VALID_REGEX_FLAGS = new Set(["g", "m", "s", "i", "y", "u"]); // The following character codes are forbidden from being // an immediate sibling of NumericLiteralSeparator _ @@ -120,7 +116,9 @@ export default class Tokenizer extends LocationParser { constructor(options: Options, input: string) { super(); this.state = new State(); - this.state.init(options, input); + this.state.init(options); + this.input = input; + this.length = input.length; this.isLookahead = false; } @@ -157,12 +155,6 @@ export default class Tokenizer extends LocationParser { // TODO - isKeyword(word: string): boolean { - return isKeyword(word); - } - - // TODO - lookahead(): State { const old = this.state; this.state = old.clone(true); @@ -206,7 +198,7 @@ export default class Tokenizer extends LocationParser { this.state.octalPosition = null; this.state.start = this.state.pos; this.state.startLoc = this.state.curPosition(); - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.finishToken(tt.eof); return; } @@ -214,17 +206,7 @@ export default class Tokenizer extends LocationParser { if (curContext.override) { curContext.override(this); } else { - this.readToken(this.input.codePointAt(this.state.pos)); - } - } - - readToken(code: number): void { - // Identifier or keyword. '\uXXXX' sequences are allowed in - // identifiers, so '\' also dispatches to that. - if (isIdentifierStart(code) || code === charCodes.backslash) { - this.readWord(); - } else { - this.getTokenFromCode(code); + this.getTokenFromCode(this.input.codePointAt(this.state.pos)); } } @@ -244,11 +226,9 @@ export default class Tokenizer extends LocationParser { loc: new SourceLocation(startLoc, endLoc), }; - if (!this.isLookahead) { - if (this.options.tokens) this.state.tokens.push(comment); - this.state.comments.push(comment); - this.addComment(comment); - } + if (this.options.tokens) this.state.tokens.push(comment); + this.state.comments.push(comment); + this.addComment(comment); } skipBlockComment(): void { @@ -268,6 +248,10 @@ export default class Tokenizer extends LocationParser { this.state.lineStart = match.index + match[0].length; } + // If we are doing a lookahead right now we need to advance the position (above code) + // but we do not want to push the comment to the state. + if (this.isLookahead) return; + this.pushComment( true, this.input.slice(start + 2, end), @@ -282,18 +266,22 @@ export default class Tokenizer extends LocationParser { const start = this.state.pos; const startLoc = this.state.curPosition(); let ch = this.input.charCodeAt((this.state.pos += startSkip)); - if (this.state.pos < this.input.length) { + if (this.state.pos < this.length) { while ( ch !== charCodes.lineFeed && ch !== charCodes.carriageReturn && ch !== charCodes.lineSeparator && ch !== charCodes.paragraphSeparator && - ++this.state.pos < this.input.length + ++this.state.pos < this.length ) { ch = this.input.charCodeAt(this.state.pos); } } + // If we are doing a lookahead right now we need to advance the position (above code) + // but we do not want to push the comment to the state. + if (this.isLookahead) return; + this.pushComment( false, this.input.slice(start + startSkip, this.state.pos), @@ -308,9 +296,14 @@ export default class Tokenizer extends LocationParser { // whitespace and comments, and. skipSpace(): void { - loop: while (this.state.pos < this.input.length) { + loop: while (this.state.pos < this.length) { const ch = this.input.charCodeAt(this.state.pos); switch (ch) { + case charCodes.space: + case charCodes.nonBreakingSpace: + case charCodes.tab: + ++this.state.pos; + break; case charCodes.carriageReturn: if ( this.input.charCodeAt(this.state.pos + 1) === charCodes.lineFeed @@ -363,7 +356,7 @@ export default class Tokenizer extends LocationParser { this.state.type = type; this.state.value = val; - this.updateContext(prevType); + if (!this.isLookahead) this.updateContext(prevType); } // ### Token reading @@ -374,7 +367,36 @@ export default class Tokenizer extends LocationParser { // into it. // // All in the name of speed. - // + + // number sign is "#" + readToken_numberSign(): void { + if (this.state.pos === 0 && this.readToken_interpreter()) { + return; + } + + const nextPos = this.state.pos + 1; + const next = this.input.charCodeAt(nextPos); + if (next >= charCodes.digit0 && next <= charCodes.digit9) { + this.raise(this.state.pos, "Unexpected digit after hash token"); + } + + if ( + (this.hasPlugin("classPrivateProperties") || + this.hasPlugin("classPrivateMethods")) && + this.state.classLevel > 0 + ) { + ++this.state.pos; + this.finishToken(tt.hash); + return; + } else if ( + this.getPluginOption("pipelineOperator", "proposal") === "smart" + ) { + this.finishOp(tt.hash, 1); + } else { + this.raise(this.state.pos, "Unexpected character '#'"); + } + } + readToken_dot(): void { const next = this.input.charCodeAt(this.state.pos + 1); if (next >= charCodes.digit0 && next <= charCodes.digit9) { @@ -409,7 +431,7 @@ export default class Tokenizer extends LocationParser { } readToken_interpreter(): boolean { - if (this.state.pos !== 0 || this.state.input.length < 2) return false; + if (this.state.pos !== 0 || this.length < 2) return false; const start = this.state.pos; this.state.pos += 1; @@ -422,7 +444,7 @@ export default class Tokenizer extends LocationParser { ch !== charCodes.carriageReturn && ch !== charCodes.lineSeparator && ch !== charCodes.paragraphSeparator && - ++this.state.pos < this.input.length + ++this.state.pos < this.length ) { ch = this.input.charCodeAt(this.state.pos); } @@ -457,7 +479,7 @@ export default class Tokenizer extends LocationParser { } readToken_pipe_amp(code: number): void { - // '|&' + // '||' '&&' '||=' '&&=' const next = this.input.charCodeAt(this.state.pos + 1); if (next === code) { @@ -477,10 +499,6 @@ export default class Tokenizer extends LocationParser { if (next === charCodes.greaterThan) { this.finishOp(tt.pipeline, 2); return; - } else if (next === charCodes.rightCurlyBrace && this.hasPlugin("flow")) { - // '|}' - this.finishOp(tt.braceBarR, 2); - return; } } @@ -514,7 +532,10 @@ export default class Tokenizer extends LocationParser { next === charCodes.dash && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan && - lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos)) + (this.state.lastTokEnd === 0 || + lineBreak.test( + this.input.slice(this.state.lastTokEnd, this.state.pos), + )) ) { // A `-->` line comment this.skipLineComment(3); @@ -622,26 +643,6 @@ export default class Tokenizer extends LocationParser { getTokenFromCode(code: number): void { switch (code) { - case charCodes.numberSign: - if (this.state.pos === 0 && this.readToken_interpreter()) { - return; - } - - if ( - (this.hasPlugin("classPrivateProperties") || - this.hasPlugin("classPrivateMethods")) && - this.state.classLevel > 0 - ) { - ++this.state.pos; - this.finishToken(tt.hash); - return; - } else { - this.raise( - this.state.pos, - `Unexpected character '${String.fromCodePoint(code)}'`, - ); - } - // The interpretation of a dot depends on whether it is followed // by a digit or another two dots. @@ -674,19 +675,10 @@ export default class Tokenizer extends LocationParser { ++this.state.pos; this.finishToken(tt.bracketR); return; - case charCodes.leftCurlyBrace: - if ( - this.hasPlugin("flow") && - this.input.charCodeAt(this.state.pos + 1) === charCodes.verticalBar - ) { - this.finishOp(tt.braceBarL, 2); - } else { - ++this.state.pos; - this.finishToken(tt.braceL); - } + ++this.state.pos; + this.finishToken(tt.braceL); return; - case charCodes.rightCurlyBrace: ++this.state.pos; this.finishToken(tt.braceR); @@ -707,10 +699,6 @@ export default class Tokenizer extends LocationParser { case charCodes.questionMark: this.readToken_question(); return; - case charCodes.atSign: - ++this.state.pos; - this.finishToken(tt.at); - return; case charCodes.graveAccent: ++this.state.pos; @@ -796,6 +784,25 @@ export default class Tokenizer extends LocationParser { case charCodes.tilde: this.finishOp(tt.tilde, 1); return; + + case charCodes.atSign: + ++this.state.pos; + this.finishToken(tt.at); + return; + + case charCodes.numberSign: + this.readToken_numberSign(); + return; + + case charCodes.backslash: + this.readWord(); + return; + + default: + if (isIdentifierStart(code)) { + this.readWord(); + return; + } } this.raise( @@ -814,7 +821,7 @@ export default class Tokenizer extends LocationParser { const start = this.state.pos; let escaped, inClass; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.raise(start, "Unterminated regular expression"); } const ch = this.input.charAt(this.state.pos); @@ -840,11 +847,11 @@ export default class Tokenizer extends LocationParser { let mods = ""; - while (this.state.pos < this.input.length) { + while (this.state.pos < this.length) { const char = this.input[this.state.pos]; const charCode = this.input.codePointAt(this.state.pos); - if (VALID_REGEX_FLAGS.indexOf(char) > -1) { + if (VALID_REGEX_FLAGS.has(char)) { if (mods.indexOf(char) > -1) { this.raise(this.state.pos + 1, "Duplicate regular expression flag"); } @@ -881,10 +888,10 @@ export default class Tokenizer extends LocationParser { radix === 16 ? allowedNumericSeparatorSiblings.hex : radix === 10 - ? allowedNumericSeparatorSiblings.dec - : radix === 8 - ? allowedNumericSeparatorSiblings.oct - : allowedNumericSeparatorSiblings.bin; + ? allowedNumericSeparatorSiblings.dec + : radix === 8 + ? allowedNumericSeparatorSiblings.oct + : allowedNumericSeparatorSiblings.bin; let total = 0; @@ -971,14 +978,26 @@ export default class Tokenizer extends LocationParser { readNumber(startsWithDot: boolean): void { const start = this.state.pos; - let octal = this.input.charCodeAt(start) === charCodes.digit0; let isFloat = false; let isBigInt = false; if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); } - if (octal && this.state.pos == start + 1) octal = false; // number === 0 + let octal = + this.state.pos - start >= 2 && + this.input.charCodeAt(start) === charCodes.digit0; + if (octal) { + if (this.state.strict) { + this.raise( + start, + "Legacy octal literals are not allowed in strict mode", + ); + } + if (/[89]/.test(this.input.slice(start, this.state.pos))) { + octal = false; + } + } let next = this.input.charCodeAt(this.state.pos); if (next === charCodes.dot && !octal) { @@ -1022,18 +1041,7 @@ export default class Tokenizer extends LocationParser { return; } - let val; - if (isFloat) { - val = parseFloat(str); - } else if (!octal || str.length === 1) { - val = parseInt(str, 10); - } else if (this.state.strict) { - this.raise(start, "Invalid number"); - } else if (/[89]/.test(str)) { - val = parseInt(str, 10); - } else { - val = parseInt(str, 8); - } + const val = octal ? parseInt(str, 8) : parseFloat(str); this.finishToken(tt.num, val); } @@ -1070,9 +1078,8 @@ export default class Tokenizer extends LocationParser { readString(quote: number): void { let out = "", chunkStart = ++this.state.pos; - const hasJsonStrings = this.hasPlugin("jsonStrings"); for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated string constant"); } const ch = this.input.charCodeAt(this.state.pos); @@ -1083,10 +1090,11 @@ export default class Tokenizer extends LocationParser { out += this.readEscapedChar(false); chunkStart = this.state.pos; } else if ( - hasJsonStrings && - (ch === charCodes.lineSeparator || ch === charCodes.paragraphSeparator) + ch === charCodes.lineSeparator || + ch === charCodes.paragraphSeparator ) { ++this.state.pos; + ++this.state.curLine; } else if (isNewLine(ch)) { this.raise(this.state.start, "Unterminated string constant"); } else { @@ -1104,7 +1112,7 @@ export default class Tokenizer extends LocationParser { chunkStart = this.state.pos, containsInvalid = false; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.length) { this.raise(this.state.start, "Unterminated template"); } const ch = this.input.charCodeAt(this.state.pos); @@ -1196,6 +1204,8 @@ export default class Tokenizer extends LocationParser { case charCodes.lineFeed: this.state.lineStart = this.state.pos; ++this.state.curLine; + case charCodes.lineSeparator: + case charCodes.paragraphSeparator: return ""; default: if (ch >= charCodes.digit0 && ch <= charCodes.digit7) { @@ -1209,7 +1219,13 @@ export default class Tokenizer extends LocationParser { octalStr = octalStr.slice(0, -1); octal = parseInt(octalStr, 8); } - if (octal > 0) { + this.state.pos += octalStr.length - 1; + const next = this.input.charCodeAt(this.state.pos); + if ( + octalStr !== "0" || + next === charCodes.digit8 || + next === charCodes.digit9 + ) { if (inTemplate) { this.state.invalidTemplateEscapePosition = codePos; return null; @@ -1222,9 +1238,10 @@ export default class Tokenizer extends LocationParser { this.state.octalPosition = codePos; } } - this.state.pos += octalStr.length - 1; + return String.fromCharCode(octal); } + return String.fromCharCode(ch); } } @@ -1252,21 +1269,24 @@ export default class Tokenizer extends LocationParser { // as a micro-optimization. readWord1(): string { + let word = ""; this.state.containsEsc = false; - let word = "", - first = true, - chunkStart = this.state.pos; - while (this.state.pos < this.input.length) { + const start = this.state.pos; + let chunkStart = this.state.pos; + + while (this.state.pos < this.length) { const ch = this.input.codePointAt(this.state.pos); if (isIdentifierChar(ch)) { this.state.pos += ch <= 0xffff ? 1 : 2; } else if (this.state.isIterator && ch === charCodes.atSign) { - this.state.pos += 1; + ++this.state.pos; } else if (ch === charCodes.backslash) { this.state.containsEsc = true; word += this.input.slice(chunkStart, this.state.pos); const escStart = this.state.pos; + const identifierCheck = + this.state.pos === start ? isIdentifierStart : isIdentifierChar; if (this.input.charCodeAt(++this.state.pos) !== charCodes.lowercaseU) { this.raise( @@ -1277,8 +1297,11 @@ export default class Tokenizer extends LocationParser { ++this.state.pos; const esc = this.readCodePoint(true); - // $FlowFixMe (thinks esc may be null, but throwOnInvalid is true) - if (!(first ? isIdentifierStart : isIdentifierChar)(esc, true)) { + + if ( + // $FlowFixMe (thinks esc may be null, but throwOnInvalid is true) + !identifierCheck(esc, true) + ) { this.raise(escStart, "Invalid Unicode escape"); } @@ -1288,7 +1311,6 @@ export default class Tokenizer extends LocationParser { } else { break; } - first = false; } return word + this.input.slice(chunkStart, this.state.pos); } @@ -1302,14 +1324,10 @@ export default class Tokenizer extends LocationParser { readWord(): void { const word = this.readWord1(); - let type = tt.name; - - if (this.isKeyword(word)) { - if (this.state.containsEsc) { - this.raise(this.state.pos, `Escape sequence in keyword ${word}`); - } + const type = keywordTypes.get(word) || tt.name; - type = keywordTypes[word]; + if (type.keyword && this.state.containsEsc) { + this.raise(this.state.pos, `Escape sequence in keyword ${word}`); } // Allow @@iterator and @@asyncIterator as a identifier only inside type @@ -1324,14 +1342,24 @@ export default class Tokenizer extends LocationParser { } braceIsBlock(prevType: TokenType): boolean { - if (prevType === tt.colon) { - const parent = this.curContext(); - if (parent === ct.braceStatement || parent === ct.braceExpression) { - return !parent.isExpr; - } + const parent = this.curContext(); + if (parent === ct.functionExpression || parent === ct.functionStatement) { + return true; + } + if ( + prevType === tt.colon && + (parent === ct.braceStatement || parent === ct.braceExpression) + ) { + return !parent.isExpr; } - if (prevType === tt._return) { + // The check for `tt.name && exprAllowed` detects whether we are + // after a `yield` or `of` construct. See the `updateContext` for + // `tt.name`. + if ( + prevType === tt._return || + (prevType === tt.name && this.state.exprAllowed) + ) { return lineBreak.test( this.input.slice(this.state.lastTokEnd, this.state.start), ); @@ -1341,13 +1369,22 @@ export default class Tokenizer extends LocationParser { prevType === tt._else || prevType === tt.semi || prevType === tt.eof || - prevType === tt.parenR + prevType === tt.parenR || + prevType === tt.arrow ) { return true; } if (prevType === tt.braceL) { - return this.curContext() === ct.braceStatement; + return parent === ct.braceStatement; + } + + if ( + prevType === tt._var || + prevType === tt._const || + prevType === tt.name + ) { + return false; } if (prevType === tt.relational) { diff --git a/packages/babel-parser/src/tokenizer/state.js b/packages/babel-parser/src/tokenizer/state.js index 364ceec96d32..80842fbc5103 100644 --- a/packages/babel-parser/src/tokenizer/state.js +++ b/packages/babel-parser/src/tokenizer/state.js @@ -8,86 +8,44 @@ import { types as ct, type TokContext } from "./context"; import type { Token } from "./index"; import { types as tt, type TokenType } from "./types"; -export default class State { - init(options: Options, input: string): void { - this.strict = - options.strictMode === false ? false : options.sourceType === "module"; - - this.input = input; - - this.potentialArrowAt = -1; - - this.noArrowAt = []; - this.noArrowParamsConversionAt = []; - - this.inMethod = false; - this.inFunction = false; - this.inParameters = false; - this.maybeInArrowParameters = false; - this.inGenerator = false; - this.inAsync = false; - this.inPropertyName = false; - this.inType = false; - this.inClassProperty = false; - this.noAnonFunctionType = false; - this.hasFlowComment = false; - this.isIterator = false; - - this.classLevel = 0; - - this.labels = []; - - this.decoratorStack = [[]]; +type TopicContextState = { + // When a topic binding has been currently established, + // then this is 1. Otherwise, it is 0. This is forwards compatible + // with a future plugin for multiple lexical topics. + maxNumOfResolvableTopics: number, + + // When a topic binding has been currently established, and if that binding + // has been used as a topic reference `#`, then this is 0. Otherwise, it is + // `null`. This is forwards compatible with a future plugin for multiple + // lexical topics. + maxTopicIndex: null | 0, +}; - this.yieldInPossibleArrowParameters = null; - - this.tokens = []; +export default class State { + strict: boolean; + curLine: number; - this.comments = []; + // And, if locations are used, the {line, column} object + // corresponding to those offsets + startLoc: Position; + endLoc: Position; - this.trailingComments = []; - this.leadingComments = []; - this.commentStack = []; - // $FlowIgnore - this.commentPreviousNode = null; + init(options: Options): void { + this.strict = + options.strictMode === false ? false : options.sourceType === "module"; - this.pos = this.lineStart = 0; this.curLine = options.startLine; - - this.type = tt.eof; - this.value = null; - this.start = this.end = this.pos; this.startLoc = this.endLoc = this.curPosition(); - - // $FlowIgnore - this.lastTokEndLoc = this.lastTokStartLoc = null; - this.lastTokStart = this.lastTokEnd = this.pos; - - this.context = [ct.braceStatement]; - this.exprAllowed = true; - - this.containsEsc = this.containsOctal = false; - this.octalPosition = null; - - this.invalidTemplateEscapePosition = null; - - this.exportedIdentifiers = []; } - // TODO - strict: boolean; - - // TODO - input: string; - // Used to signify the start of a potential arrow function - potentialArrowAt: number; + potentialArrowAt: number = -1; // Used to signify the start of an expression which looks like a // typed arrow function, but it isn't // e.g. a ? (b) : c => d // ^ - noArrowAt: number[]; + noArrowAt: number[] = []; // Used to signify the start of an expression whose params, if it looks like // an arrow function, shouldn't be converted to assignable nodes. @@ -95,106 +53,114 @@ export default class State { // conditional expressions. // e.g. a ? (b) : c => d // ^ - noArrowParamsConversionAt: number[]; - - // Flags to track whether we are in a function, a generator. - inFunction: boolean; - inParameters: boolean; - maybeInArrowParameters: boolean; - inGenerator: boolean; - inMethod: boolean | N.MethodKind; - inAsync: boolean; - inType: boolean; - noAnonFunctionType: boolean; - inPropertyName: boolean; - inClassProperty: boolean; - hasFlowComment: boolean; - isIterator: boolean; + noArrowParamsConversionAt: number[] = []; + + // A comma after "...a" is only allowed in spread, but not in rest. + // Since we parse destructuring patterns as array/object literals + // and then convert them, we need to track it. + commaAfterSpreadAt: number = -1; + + // Flags to track + inParameters: boolean = false; + maybeInArrowParameters: boolean = false; + inPipeline: boolean = false; + inType: boolean = false; + noAnonFunctionType: boolean = false; + inPropertyName: boolean = false; + inClassProperty: boolean = false; + hasFlowComment: boolean = false; + isIterator: boolean = false; + + // For the smartPipelines plugin: + topicContext: TopicContextState = { + maxNumOfResolvableTopics: 0, + maxTopicIndex: null, + }; + + // For the F# plugin + soloAwait: boolean = false; + inFSharpPipelineDirectBody: boolean = false; // Check whether we are in a (nested) class or not. - classLevel: number; + classLevel: number = 0; // Labels in scope. labels: Array<{ kind: ?("loop" | "switch"), name?: ?string, statementStart?: number, - }>; + }> = []; // Leading decorators. Last element of the stack represents the decorators in current context. // Supports nesting of decorators, e.g. @foo(@bar class inner {}) class outer {} // where @foo belongs to the outer class and @bar to the inner - decoratorStack: Array>; + decoratorStack: Array> = [[]]; - // The first yield expression inside parenthesized expressions and arrow - // function parameters. It is used to disallow yield in arrow function - // parameters. - yieldInPossibleArrowParameters: ?N.YieldExpression; + // Positions to delayed-check that yield/await does not exist in default parameters. + yieldPos: number = 0; + awaitPos: number = 0; // Token store. - tokens: Array; + tokens: Array = []; // Comment store. - comments: Array; + comments: Array = []; // Comment attachment store - trailingComments: Array; - leadingComments: Array; + trailingComments: Array = []; + leadingComments: Array = []; commentStack: Array<{ start: number, leadingComments: ?Array, trailingComments: ?Array, type: string, - }>; - commentPreviousNode: N.Node; + }> = []; + // $FlowIgnore this is initialized when the parser starts. + commentPreviousNode: N.Node = null; // The current position of the tokenizer in the input. - pos: number; - lineStart: number; - curLine: number; + pos: number = 0; + lineStart: number = 0; // Properties of the current token: // Its type - type: TokenType; + type: TokenType = tt.eof; // For tokens that include more information than their type, the value - value: any; + value: any = null; // Its start and end offset - start: number; - end: number; - - // And, if locations are used, the {line, column} object - // corresponding to those offsets - startLoc: Position; - endLoc: Position; + start: number = 0; + end: number = 0; // Position information for the previous token - lastTokEndLoc: Position; - lastTokStartLoc: Position; - lastTokStart: number; - lastTokEnd: number; + // $FlowIgnore this is initialized when generating the second token. + lastTokEndLoc: Position = null; + // $FlowIgnore this is initialized when generating the second token. + lastTokStartLoc: Position = null; + lastTokStart: number = 0; + lastTokEnd: number = 0; // The context stack is used to superficially track syntactic // context to predict whether a regular expression is allowed in a // given position. - context: Array; - exprAllowed: boolean; + context: Array = [ct.braceStatement]; + exprAllowed: boolean = true; // Used to signal to callers of `readWord1` whether the word // contained any escape sequences. This is needed because words with // escape sequences must not be interpreted as keywords. - containsEsc: boolean; + containsEsc: boolean = false; // TODO - containsOctal: boolean; - octalPosition: ?number; + containsOctal: boolean = false; + octalPosition: ?number = null; // Names of exports store. `default` is stored as a name for both // `export default foo;` and `export { foo as default };`. - exportedIdentifiers: Array; + exportedIdentifiers: Array = []; - invalidTemplateEscapePosition: ?number; + invalidTemplateEscapePosition: ?number = null; curPosition(): Position { return new Position(this.curLine, this.pos - this.lineStart); @@ -202,17 +168,20 @@ export default class State { clone(skipArrays?: boolean): State { const state = new State(); - Object.keys(this).forEach(key => { + const keys = Object.keys(this); + for (let i = 0, length = keys.length; i < length; i++) { + const key = keys[i]; // $FlowIgnore let val = this[key]; - if ((!skipArrays || key === "context") && Array.isArray(val)) { + if (!skipArrays && Array.isArray(val)) { val = val.slice(); } // $FlowIgnore state[key] = val; - }); + } + return state; } } diff --git a/packages/babel-parser/src/tokenizer/types.js b/packages/babel-parser/src/tokenizer/types.js index 14e94d32ab09..34fd891c9256 100644 --- a/packages/babel-parser/src/tokenizer/types.js +++ b/packages/babel-parser/src/tokenizer/types.js @@ -13,7 +13,12 @@ // expressions and divisions. It is set on all token types that can // be followed by an expression (thus, a slash after them would be a // regular expression). -// + +// The `startsExpr` property is used to determine whether an expression +// may be the “argument” subexpression of a `yield` expression or +// `yield` statement. It is set on all token types that may be at the +// start of a subexpression. + // `isLoop` marks a keyword as starting a loop, which is important // to know when parsing a label, in order to allow or disallow // continue jumps to that label. @@ -27,7 +32,6 @@ const postfix = true; type TokenOptions = { keyword?: string, - beforeExpr?: boolean, startsExpr?: boolean, rightAssociative?: boolean, @@ -61,16 +65,21 @@ export class TokenType { this.isAssign = !!conf.isAssign; this.prefix = !!conf.prefix; this.postfix = !!conf.postfix; - this.binop = conf.binop === 0 ? 0 : conf.binop || null; + this.binop = conf.binop != null ? conf.binop : null; this.updateContext = null; } } -function KeywordTokenType(keyword: string, options: TokenOptions = {}) { - return new TokenType(keyword, { ...options, keyword }); +export const keywords = new Map(); + +function createKeyword(name: string, options: TokenOptions = {}): TokenType { + options.keyword = name; + const token = new TokenType(name, options); + keywords.set(name, token); + return token; } -function BinopTokenType(name: string, binop: number) { +function createBinop(name: string, binop: number) { return new TokenType(name, { beforeExpr, binop }); } @@ -104,7 +113,7 @@ export const types: { [name: string]: TokenType } = { backQuote: new TokenType("`", { startsExpr }), dollarBraceL: new TokenType("${", { beforeExpr, startsExpr }), at: new TokenType("@"), - hash: new TokenType("#"), + hash: new TokenType("#", { startsExpr }), // Special hashbang token. interpreterDirective: new TokenType("#!..."), @@ -128,68 +137,60 @@ export const types: { [name: string]: TokenType } = { incDec: new TokenType("++/--", { prefix, postfix, startsExpr }), bang: new TokenType("!", { beforeExpr, prefix, startsExpr }), tilde: new TokenType("~", { beforeExpr, prefix, startsExpr }), - pipeline: new BinopTokenType("|>", 0), - nullishCoalescing: new BinopTokenType("??", 1), - logicalOR: new BinopTokenType("||", 1), - logicalAND: new BinopTokenType("&&", 2), - bitwiseOR: new BinopTokenType("|", 3), - bitwiseXOR: new BinopTokenType("^", 4), - bitwiseAND: new BinopTokenType("&", 5), - equality: new BinopTokenType("==/!=", 6), - relational: new BinopTokenType("", 7), - bitShift: new BinopTokenType("<>", 8), + pipeline: createBinop("|>", 0), + nullishCoalescing: createBinop("??", 1), + logicalOR: createBinop("||", 1), + logicalAND: createBinop("&&", 2), + bitwiseOR: createBinop("|", 3), + bitwiseXOR: createBinop("^", 4), + bitwiseAND: createBinop("&", 5), + equality: createBinop("==/!=/===/!==", 6), + relational: createBinop("/<=/>=", 7), + bitShift: createBinop("<>/>>>", 8), plusMin: new TokenType("+/-", { beforeExpr, binop: 9, prefix, startsExpr }), - modulo: new BinopTokenType("%", 10), - star: new BinopTokenType("*", 10), - slash: new BinopTokenType("/", 10), + modulo: createBinop("%", 10), + star: createBinop("*", 10), + slash: createBinop("/", 10), exponent: new TokenType("**", { beforeExpr, binop: 11, rightAssociative: true, }), -}; -export const keywords = { - break: new KeywordTokenType("break"), - case: new KeywordTokenType("case", { beforeExpr }), - catch: new KeywordTokenType("catch"), - continue: new KeywordTokenType("continue"), - debugger: new KeywordTokenType("debugger"), - default: new KeywordTokenType("default", { beforeExpr }), - do: new KeywordTokenType("do", { isLoop, beforeExpr }), - else: new KeywordTokenType("else", { beforeExpr }), - finally: new KeywordTokenType("finally"), - for: new KeywordTokenType("for", { isLoop }), - function: new KeywordTokenType("function", { startsExpr }), - if: new KeywordTokenType("if"), - return: new KeywordTokenType("return", { beforeExpr }), - switch: new KeywordTokenType("switch"), - throw: new KeywordTokenType("throw", { beforeExpr, prefix, startsExpr }), - try: new KeywordTokenType("try"), - var: new KeywordTokenType("var"), - let: new KeywordTokenType("let"), - const: new KeywordTokenType("const"), - while: new KeywordTokenType("while", { isLoop }), - with: new KeywordTokenType("with"), - new: new KeywordTokenType("new", { beforeExpr, startsExpr }), - this: new KeywordTokenType("this", { startsExpr }), - super: new KeywordTokenType("super", { startsExpr }), - class: new KeywordTokenType("class"), - extends: new KeywordTokenType("extends", { beforeExpr }), - export: new KeywordTokenType("export"), - import: new KeywordTokenType("import", { startsExpr }), - yield: new KeywordTokenType("yield", { beforeExpr, startsExpr }), - null: new KeywordTokenType("null", { startsExpr }), - true: new KeywordTokenType("true", { startsExpr }), - false: new KeywordTokenType("false", { startsExpr }), - in: new KeywordTokenType("in", { beforeExpr, binop: 7 }), - instanceof: new KeywordTokenType("instanceof", { beforeExpr, binop: 7 }), - typeof: new KeywordTokenType("typeof", { beforeExpr, prefix, startsExpr }), - void: new KeywordTokenType("void", { beforeExpr, prefix, startsExpr }), - delete: new KeywordTokenType("delete", { beforeExpr, prefix, startsExpr }), + // Keywords + _break: createKeyword("break"), + _case: createKeyword("case", { beforeExpr }), + _catch: createKeyword("catch"), + _continue: createKeyword("continue"), + _debugger: createKeyword("debugger"), + _default: createKeyword("default", { beforeExpr }), + _do: createKeyword("do", { isLoop, beforeExpr }), + _else: createKeyword("else", { beforeExpr }), + _finally: createKeyword("finally"), + _for: createKeyword("for", { isLoop }), + _function: createKeyword("function", { startsExpr }), + _if: createKeyword("if"), + _return: createKeyword("return", { beforeExpr }), + _switch: createKeyword("switch"), + _throw: createKeyword("throw", { beforeExpr, prefix, startsExpr }), + _try: createKeyword("try"), + _var: createKeyword("var"), + _const: createKeyword("const"), + _while: createKeyword("while", { isLoop }), + _with: createKeyword("with"), + _new: createKeyword("new", { beforeExpr, startsExpr }), + _this: createKeyword("this", { startsExpr }), + _super: createKeyword("super", { startsExpr }), + _class: createKeyword("class", { startsExpr }), + _extends: createKeyword("extends", { beforeExpr }), + _export: createKeyword("export"), + _import: createKeyword("import", { startsExpr }), + _null: createKeyword("null", { startsExpr }), + _true: createKeyword("true", { startsExpr }), + _false: createKeyword("false", { startsExpr }), + _in: createKeyword("in", { beforeExpr, binop: 7 }), + _instanceof: createKeyword("instanceof", { beforeExpr, binop: 7 }), + _typeof: createKeyword("typeof", { beforeExpr, prefix, startsExpr }), + _void: createKeyword("void", { beforeExpr, prefix, startsExpr }), + _delete: createKeyword("delete", { beforeExpr, prefix, startsExpr }), }; - -// Map keyword names to token types. -Object.keys(keywords).forEach(name => { - types["_" + name] = keywords[name]; -}); diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 0e872275633a..2c5992d2ba6c 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -3,6 +3,7 @@ import type { SourceType } from "./options"; import type { Token } from "./tokenizer"; import type { SourceLocation } from "./util/location"; +import type { PlaceholderTypes } from "./plugins/placeholders"; /* * If making any changes to the AST, update: @@ -45,6 +46,7 @@ export type Pattern = | ArrayPattern | RestElement | AssignmentPattern; +//| Placeholder<"Pattern">; export type Declaration = | VariableDeclaration | ClassDeclaration @@ -53,6 +55,8 @@ export type Declaration = | TsTypeAliasDeclaration | TsEnumDeclaration | TsModuleDeclaration; +// | Placeholder<"Declaration">; + export type DeclarationBase = NodeBase & { // TypeScript allows declarations to be prefixed by `declare`. //TODO: a FunctionDeclaration is never "declare", because it's a TSDeclareFunction instead. @@ -78,6 +82,7 @@ export type Identifier = PatternBase & { // TypeScript only. Used in case of an optional parameter. optional?: ?true, }; +// | Placeholder<"Identifier">; export type PrivateName = NodeBase & { type: "PrivateName", @@ -188,6 +193,7 @@ export type BlockStatement = NodeBase & { body: Array, // TODO: $ReadOnlyArray directives: $ReadOnlyArray, }; +// | Placeholder<"BlockStatement">; export type EmptyStatement = NodeBase & { type: "EmptyStatement", @@ -257,8 +263,6 @@ export type TryStatement = NodeBase & { block: BlockStatement, handler: CatchClause | null, finalizer: BlockStatement | null, - - guardedHandlers: $ReadOnlyArray, // TODO: Not in spec }; export type CatchClause = NodeBase & { @@ -340,6 +344,8 @@ export type VariableDeclarator = NodeBase & { // Misc +export type ArgumentPlaceholder = NodeBase & { type: "ArgumentPlaceholder" }; + export type Decorator = NodeBase & { type: "Decorator", expression: Expression, @@ -398,7 +404,7 @@ export type ObjectMemberBase = NodeBase & { decorators: $ReadOnlyArray, kind?: "get" | "set" | "method", method: boolean, // TODO: Not in spec - + typeParameters?: ?TypeParameterInstantiationBase, // TODO: Not in spec variance?: ?FlowVariance, // TODO: Not in spec }; @@ -566,6 +572,43 @@ export type SequenceExpression = NodeBase & { expressions: $ReadOnlyArray, }; +export type ParenthesizedExpression = NodeBase & { + type: "ParenthesizedExpression", + expression: Expression, +}; + +// Pipelines + +export type PipelineBody = NodeBase & { + type: "PipelineBody", +}; + +export type PipelineBareFunctionBody = NodeBase & { + type: "PipelineBareFunctionBody", + callee: Expression, +}; + +export type PipelineBareConstructorBody = NodeBase & { + type: "PipelineBareConstructorBody", + callee: Expression, +}; + +export type PipelineBareAwaitedFunctionBody = NodeBase & { + type: "PipelineBareAwaitedFunctionBody", + callee: Expression, +}; + +export type PipelineTopicBody = NodeBase & { + type: "PipelineTopicBody", + expression: Expression, +}; + +export type PipelineStyle = + | "PipelineBareFunction" + | "PipelineBareConstructor" + | "PipelineBareAwaitedFunction" + | "PipelineTopicExpression"; + // Template Literals export type TemplateLiteral = NodeBase & { @@ -648,6 +691,7 @@ export type ClassBody = NodeBase & { type: "ClassBody", body: Array, // TODO: $ReadOnlyArray }; +// | Placeholder<"ClassBody">; export type ClassMemberBase = NodeBase & HasDecorators & { @@ -751,7 +795,9 @@ export type AnyExport = | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration - | TsExportAssignment; + | TsExportAssignment + | TsImportEqualsDeclaration + | TsNamespaceExportDeclaration; export type ModuleSpecifier = NodeBase & { local: Identifier, @@ -788,7 +834,7 @@ export type ImportNamespaceSpecifier = ModuleSpecifier & { export type ExportNamedDeclaration = NodeBase & { type: "ExportNamedDeclaration", declaration: ?Declaration, - specifiers: $ReadOnlyArray, + specifiers: $ReadOnlyArray, source: ?Literal, exportKind?: "type" | "value", // TODO: Not in spec @@ -797,6 +843,12 @@ export type ExportNamedDeclaration = NodeBase & { export type ExportSpecifier = NodeBase & { type: "ExportSpecifier", exported: Identifier, + local: Identifier, +}; + +export type ExportDefaultSpecifier = NodeBase & { + type: "ExportDefaultSpecifier", + exported: Identifier, }; export type ExportDefaultDeclaration = NodeBase & { @@ -1037,7 +1089,9 @@ export type TsSignatureDeclaration = export type TsSignatureDeclarationOrIndexSignatureBase = NodeBase & { // Not using TypeScript's "ParameterDeclaration" here, since it's inconsistent with regular functions. - parameters: $ReadOnlyArray, + parameters: $ReadOnlyArray< + Identifier | RestElement | ObjectPattern | ArrayPattern, + >, typeAnnotation: ?TsTypeAnnotation, }; @@ -1104,6 +1158,8 @@ export type TsType = | TsTypeLiteral | TsArrayType | TsTupleType + | TsOptionalType + | TsRestType | TsUnionOrIntersectionType | TsConditionalType | TsInferType @@ -1112,6 +1168,7 @@ export type TsType = | TsIndexedAccessType | TsMappedType | TsLiteralType + | TsImportType // TODO: This probably shouldn't be included here. | TsTypePredicate; @@ -1119,9 +1176,11 @@ export type TsTypeBase = NodeBase; export type TsKeywordTypeType = | "TSAnyKeyword" + | "TSUnknownKeyword" | "TSNumberKeyword" | "TSObjectKeyword" | "TSBooleanKeyword" + | "TSBigIntKeyword" | "TSStringKeyword" | "TSSymbolKeyword" | "TSVoidKeyword" @@ -1165,7 +1224,7 @@ export type TsTypePredicate = TsTypeBase & { // `typeof` operator export type TsTypeQuery = TsTypeBase & { type: "TSTypeQuery", - exprName: TsEntityName, + exprName: TsEntityName | TsImportType, }; export type TsTypeLiteral = TsTypeBase & { @@ -1183,6 +1242,16 @@ export type TsTupleType = TsTypeBase & { elementTypes: $ReadOnlyArray, }; +export type TsOptionalType = TsTypeBase & { + type: "TSOptionalType", + typeAnnotation: TsType, +}; + +export type TsRestType = TsTypeBase & { + type: "TSRestType", + typeAnnotation: TsType, +}; + export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType; export type TsUnionOrIntersectionTypeBase = TsTypeBase & { @@ -1217,7 +1286,7 @@ export type TsParenthesizedType = TsTypeBase & { export type TsTypeOperator = TsTypeBase & { type: "TSTypeOperator", - operator: "keyof" | "unique", + operator: "keyof" | "unique" | "readonly", typeAnnotation: TsType, }; @@ -1237,7 +1306,14 @@ export type TsMappedType = TsTypeBase & { export type TsLiteralType = TsTypeBase & { type: "TSLiteralType", - literal: NumericLiteral | StringLiteral | BooleanLiteral, + literal: NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral, +}; + +export type TsImportType = TsTypeBase & { + type: "TsImportType", + argument: StringLiteral, + qualifier?: TsEntityName, + typeParameters?: TsTypeParameterInstantiation, }; // ================ @@ -1355,6 +1431,16 @@ export type TsNonNullExpression = NodeBase & { expression: Expression, }; +// ================ +// Babel placeholders %%foo%% +// ================ + +export type Placeholder = NodeBase & { + type: "Placeholder", + id: Identifier, + expectedNode: N, +}; + // ================ // Other // ================ diff --git a/packages/babel-parser/src/util/identifier.js b/packages/babel-parser/src/util/identifier.js index 1c50fcaf278e..7fda0e27de71 100644 --- a/packages/babel-parser/src/util/identifier.js +++ b/packages/babel-parser/src/util/identifier.js @@ -3,42 +3,74 @@ // @flow import * as charCodes from "charcodes"; +import { keywords } from "../tokenizer/types"; + +const reservedWords = { + strict: [ + "implements", + "interface", + "let", + "package", + "private", + "protected", + "public", + "static", + "yield", + ], + strictBind: ["eval", "arguments"], +}; -function makePredicate(words: string): (str: string) => boolean { - const wordsArr = words.split(" "); - return function(str) { - return wordsArr.indexOf(str) >= 0; - }; -} - -// Reserved word lists for various dialects of the language +const reservedWordsStrictSet = new Set(reservedWords.strict); +const reservedWordsStrictBindSet = new Set( + reservedWords.strict.concat(reservedWords.strictBind), +); -export const reservedWords = { - "6": makePredicate("enum await"), - strict: makePredicate( - "implements interface let package private protected public static yield", - ), - strictBind: makePredicate("eval arguments"), +/** + * Checks if word is a reserved word in non-strict mode + */ +export const isReservedWord = (word: string, inModule: boolean): boolean => { + return (inModule && word === "await") || word === "enum"; }; -// And the keywords +/** + * Checks if word is a reserved word in non-binding strict mode + * + * Includes non-strict reserved words + */ +export function isStrictReservedWord(word: string, inModule: boolean): boolean { + return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word); +} + +/** + * Checks if word is a reserved word in binding strict mode + * + * Includes non-strict reserved words and non-binding strict reserved words + */ +export function isStrictBindReservedWord( + word: string, + inModule: boolean, +): boolean { + return isReservedWord(word, inModule) || reservedWordsStrictBindSet.has(word); +} -export const isKeyword = makePredicate( - "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this let const class extends export import yield super", -); +export function isKeyword(word: string): boolean { + return keywords.has(word); +} + +export const keywordRelationalOperator = /^in(stanceof)?$/; // ## Character categories -// Big ugly regular expressions that matches characters in the +// Big ugly regular expressions that match characters in the // whitespace, identifier, and identifier-start categories. These // are only applied when a character is found to actually have a // code point above 0x80. // Generated by `scripts/generate-identifier-regex.js`. /* prettier-ignore */ -let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7b9\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; +let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; /* prettier-ignore */ -let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; +let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; const nonASCIIidentifierStart = new RegExp( "[" + nonASCIIidentifierStartChars + "]", @@ -55,16 +87,16 @@ nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; // offset to the next range, and then a size of the range. They were // generated by `scripts/generate-identifier-regex.js`. /* prettier-ignore */ -const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541]; +const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,155,22,13,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,0,33,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,0,161,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,754,9486,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541]; /* prettier-ignore */ -const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239]; +const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,232,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,792487,239]; // This has a complexity linear to the value of the code. The // assumption is that looking up astral identifier characters is // rare. function isInAstralSet(code: number, set: $ReadOnlyArray): boolean { let pos = 0x10000; - for (let i = 0; i < set.length; i += 2) { + for (let i = 0, length = set.length; i < length; i += 2) { pos += set[i]; if (pos > code) return false; diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js new file mode 100644 index 000000000000..e40cb53e3e33 --- /dev/null +++ b/packages/babel-parser/src/util/scope.js @@ -0,0 +1,215 @@ +// @flow +import { + SCOPE_ARROW, + SCOPE_ASYNC, + SCOPE_DIRECT_SUPER, + SCOPE_FUNCTION, + SCOPE_GENERATOR, + SCOPE_SIMPLE_CATCH, + SCOPE_SUPER, + SCOPE_PROGRAM, + SCOPE_VAR, + SCOPE_CLASS, + BIND_SCOPE_FUNCTION, + BIND_SCOPE_VAR, + BIND_SCOPE_LEXICAL, + BIND_KIND_VALUE, + type ScopeFlags, + type BindingTypes, +} from "./scopeflags"; +import * as N from "../types"; + +// Start an AST node, attaching a start offset. +export class Scope { + flags: ScopeFlags; + // A list of var-declared names in the current lexical scope + var: string[] = []; + // A list of lexically-declared names in the current lexical scope + lexical: string[] = []; + // A list of lexically-declared FunctionDeclaration names in the current lexical scope + functions: string[] = []; + + constructor(flags: ScopeFlags) { + this.flags = flags; + } +} + +type raiseFunction = (number, string) => void; + +// The functions in this module keep track of declared variables in the +// current scope in order to detect duplicate variable names. +export default class ScopeHandler { + scopeStack: Array = []; + raise: raiseFunction; + inModule: boolean; + undefinedExports: Map = new Map(); + + constructor(raise: raiseFunction, inModule: boolean) { + this.raise = raise; + this.inModule = inModule; + } + + get inFunction() { + return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0; + } + get inGenerator() { + return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0; + } + get inAsync() { + return (this.currentVarScope().flags & SCOPE_ASYNC) > 0; + } + get allowSuper() { + return (this.currentThisScope().flags & SCOPE_SUPER) > 0; + } + get allowDirectSuper() { + return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0; + } + get inNonArrowFunction() { + return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0; + } + get treatFunctionsAsVar() { + return this.treatFunctionsAsVarInScope(this.currentScope()); + } + + createScope(flags: ScopeFlags): Scope { + return new Scope(flags); + } + // This method will be overwritten by subclasses + +createScope: (flags: ScopeFlags) => IScope; + + enter(flags: ScopeFlags) { + this.scopeStack.push(this.createScope(flags)); + } + + exit() { + this.scopeStack.pop(); + } + + // The spec says: + // > At the top level of a function, or script, function declarations are + // > treated like var declarations rather than like lexical declarations. + treatFunctionsAsVarInScope(scope: IScope): boolean { + return !!( + scope.flags & SCOPE_FUNCTION || + (!this.inModule && scope.flags & SCOPE_PROGRAM) + ); + } + + declareName(name: string, bindingType: BindingTypes, pos: number) { + let scope = this.currentScope(); + if (bindingType & BIND_SCOPE_LEXICAL || bindingType & BIND_SCOPE_FUNCTION) { + this.checkRedeclarationInScope(scope, name, bindingType, pos); + + if (bindingType & BIND_SCOPE_FUNCTION) { + scope.functions.push(name); + } else { + scope.lexical.push(name); + } + + if (bindingType & BIND_SCOPE_LEXICAL) { + this.maybeExportDefined(scope, name); + } + } else if (bindingType & BIND_SCOPE_VAR) { + for (let i = this.scopeStack.length - 1; i >= 0; --i) { + scope = this.scopeStack[i]; + this.checkRedeclarationInScope(scope, name, bindingType, pos); + scope.var.push(name); + this.maybeExportDefined(scope, name); + + if (scope.flags & SCOPE_VAR) break; + } + } + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } + } + + maybeExportDefined(scope: IScope, name: string) { + if (this.inModule && scope.flags & SCOPE_PROGRAM) { + this.undefinedExports.delete(name); + } + } + + checkRedeclarationInScope( + scope: IScope, + name: string, + bindingType: BindingTypes, + pos: number, + ) { + if (this.isRedeclaredInScope(scope, name, bindingType)) { + this.raise(pos, `Identifier '${name}' has already been declared`); + } + } + + isRedeclaredInScope( + scope: IScope, + name: string, + bindingType: BindingTypes, + ): boolean { + if (!(bindingType & BIND_KIND_VALUE)) return false; + + if (bindingType & BIND_SCOPE_LEXICAL) { + return ( + scope.lexical.indexOf(name) > -1 || + scope.functions.indexOf(name) > -1 || + scope.var.indexOf(name) > -1 + ); + } + + if (bindingType & BIND_SCOPE_FUNCTION) { + return ( + scope.lexical.indexOf(name) > -1 || + (!this.treatFunctionsAsVarInScope(scope) && + scope.var.indexOf(name) > -1) + ); + } + + return ( + (scope.lexical.indexOf(name) > -1 && + !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical[0] === name)) || + (!this.treatFunctionsAsVarInScope(scope) && + scope.functions.indexOf(name) > -1) + ); + } + + checkLocalExport(id: N.Identifier) { + if ( + this.scopeStack[0].lexical.indexOf(id.name) === -1 && + this.scopeStack[0].var.indexOf(id.name) === -1 && + // In strict mode, scope.functions will always be empty. + // Modules are strict by default, but the `scriptMode` option + // can overwrite this behavior. + this.scopeStack[0].functions.indexOf(id.name) === -1 + ) { + this.undefinedExports.set(id.name, id.start); + } + } + + currentScope(): IScope { + return this.scopeStack[this.scopeStack.length - 1]; + } + + // $FlowIgnore + currentVarScope(): IScope { + for (let i = this.scopeStack.length - 1; ; i--) { + const scope = this.scopeStack[i]; + if (scope.flags & SCOPE_VAR) { + return scope; + } + } + } + + // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. + // $FlowIgnore + currentThisScope(): IScope { + for (let i = this.scopeStack.length - 1; ; i--) { + const scope = this.scopeStack[i]; + if ( + (scope.flags & SCOPE_VAR || scope.flags & SCOPE_CLASS) && + !(scope.flags & SCOPE_ARROW) + ) { + return scope; + } + } + } +} diff --git a/packages/babel-parser/src/util/scopeflags.js b/packages/babel-parser/src/util/scopeflags.js new file mode 100644 index 000000000000..8c9697b3a416 --- /dev/null +++ b/packages/babel-parser/src/util/scopeflags.js @@ -0,0 +1,85 @@ +// @flow + +// Each scope gets a bitset that may contain these flags +// prettier-ignore +export const SCOPE_OTHER = 0b000000000, + SCOPE_PROGRAM = 0b000000001, + SCOPE_FUNCTION = 0b000000010, + SCOPE_ASYNC = 0b000000100, + SCOPE_GENERATOR = 0b000001000, + SCOPE_ARROW = 0b000010000, + SCOPE_SIMPLE_CATCH = 0b000100000, + SCOPE_SUPER = 0b001000000, + SCOPE_DIRECT_SUPER = 0b010000000, + SCOPE_CLASS = 0b100000000, + SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION; + +export type ScopeFlags = + | typeof SCOPE_OTHER + | typeof SCOPE_PROGRAM + | typeof SCOPE_FUNCTION + | typeof SCOPE_VAR + | typeof SCOPE_ASYNC + | typeof SCOPE_GENERATOR + | typeof SCOPE_ARROW + | typeof SCOPE_SIMPLE_CATCH + | typeof SCOPE_SUPER + | typeof SCOPE_DIRECT_SUPER + | typeof SCOPE_CLASS; + +export function functionFlags(isAsync: boolean, isGenerator: boolean) { + return ( + SCOPE_FUNCTION | + (isAsync ? SCOPE_ASYNC : 0) | + (isGenerator ? SCOPE_GENERATOR : 0) + ); +} + +// These flags are meant to be _only_ used inside the Scope class (or subclasses). +// prettier-ignore +export const BIND_KIND_VALUE = 0b00000_0000_01, + BIND_KIND_TYPE = 0b00000_0000_10, + // Used in checkLVal and declareName to determine the type of a binding + BIND_SCOPE_VAR = 0b00000_0001_00, // Var-style binding + BIND_SCOPE_LEXICAL = 0b00000_0010_00, // Let- or const-style binding + BIND_SCOPE_FUNCTION = 0b00000_0100_00, // Function declaration + BIND_SCOPE_OUTSIDE = 0b00000_1000_00, // Special case for function names as + // bound inside the function + // Misc flags + BIND_FLAGS_NONE = 0b00001_0000_00, + BIND_FLAGS_CLASS = 0b00010_0000_00, + BIND_FLAGS_TS_ENUM = 0b00100_0000_00, + BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_00, + BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_00; + +// These flags are meant to be _only_ used by Scope consumers +// prettier-ignore +/* = is value? | is type? | scope | misc flags */ +export const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_CLASS , + BIND_LEXICAL = BIND_KIND_VALUE | 0 | BIND_SCOPE_LEXICAL | 0 , + BIND_VAR = BIND_KIND_VALUE | 0 | BIND_SCOPE_VAR | 0 , + BIND_FUNCTION = BIND_KIND_VALUE | 0 | BIND_SCOPE_FUNCTION | 0 , + BIND_TS_INTERFACE = 0 | BIND_KIND_TYPE | 0 | BIND_FLAGS_CLASS , + BIND_TS_TYPE = 0 | BIND_KIND_TYPE | 0 | 0 , + BIND_TS_ENUM = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_LEXICAL | BIND_FLAGS_TS_ENUM, + BIND_TS_FN_TYPE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY, + // These bindings don't introduce anything in the scope. They are used for assignments and + // function expressions IDs. + BIND_NONE = 0 | 0 | 0 | BIND_FLAGS_NONE , + BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE , + + BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM, + BIND_TS_NAMESPACE = BIND_TS_FN_TYPE; + +export type BindingTypes = + | typeof BIND_NONE + | typeof BIND_OUTSIDE + | typeof BIND_VAR + | typeof BIND_LEXICAL + | typeof BIND_CLASS + | typeof BIND_FUNCTION + | typeof BIND_TS_INTERFACE + | typeof BIND_TS_TYPE + | typeof BIND_TS_ENUM + | typeof BIND_TS_FN_TYPE + | typeof BIND_TS_NAMESPACE; diff --git a/packages/babel-parser/src/util/whitespace.js b/packages/babel-parser/src/util/whitespace.js index d82d87413d90..2fdbc3d423f5 100644 --- a/packages/babel-parser/src/util/whitespace.js +++ b/packages/babel-parser/src/util/whitespace.js @@ -4,7 +4,7 @@ import * as charCodes from "charcodes"; // Matches a whole line break (where CRLF is considered a single // line break). Used to count lines. -export const lineBreak = /\r\n?|\n|\u2028|\u2029/; +export const lineBreak = /\r\n?|[\n\u2028\u2029]/; export const lineBreakG = new RegExp(lineBreak.source, "g"); // https://tc39.github.io/ecma262/#sec-line-terminators diff --git a/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/7/options.json b/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/7/options.json index d58bb015bf01..12b18792fcc4 100644 --- a/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/7/options.json +++ b/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/7/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:10)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/8/options.json b/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/8/options.json index e2125b704132..5f24fc4399ed 100644 --- a/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/8/options.json +++ b/packages/babel-parser/test/expressions/is-expression-babel-parser/fail/8/options.json @@ -1,4 +1,4 @@ { "strictMode": true, - "throws": "public is a reserved word in strict mode (2:0)" + "throws": "Unexpected reserved word 'public' (2:0)" } diff --git a/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/input.js b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/input.js new file mode 100644 index 000000000000..753a9cfbb2b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/input.js @@ -0,0 +1,12 @@ +// One +(1); + +/* Two */ +(2); + +( + // Three + 3 +); + +(/* Four */ 4); diff --git a/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/options.json b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/options.json new file mode 100644 index 000000000000..0861962d889d --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/options.json @@ -0,0 +1,3 @@ +{ + "createParenthesizedExpressions": true +} diff --git a/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/output.json b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/output.json new file mode 100644 index 000000000000..761463790803 --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/basic/create-parenthesized-expressions/output.json @@ -0,0 +1,391 @@ +{ + "type": "File", + "start": 0, + "end": 65, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 65, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 7, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "expression": { + "type": "ParenthesizedExpression", + "start": 7, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " One", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + } + ], + "trailingComments": [ + { + "type": "CommentBlock", + "value": " Two ", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + } + ] + }, + { + "type": "ExpressionStatement", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 4 + } + }, + "expression": { + "type": "ParenthesizedExpression", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "leadingComments": [ + { + "type": "CommentBlock", + "value": " Two ", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + } + ] + }, + { + "type": "ExpressionStatement", + "start": 29, + "end": 48, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "expression": { + "type": "ParenthesizedExpression", + "start": 29, + "end": 47, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3, + "leadingComments": [ + { + "type": "CommentLine", + "value": " Three", + "start": 33, + "end": 41, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 10 + } + } + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start": 50, + "end": 65, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 15 + } + }, + "expression": { + "type": "ParenthesizedExpression", + "start": 50, + "end": 64, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 14 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 12, + "column": 13 + } + }, + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4, + "leadingComments": [ + { + "type": "CommentBlock", + "value": " Four ", + "start": 51, + "end": 61, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 11 + } + } + } + ] + } + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " One", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "CommentBlock", + "value": " Two ", + "start": 13, + "end": 22, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "CommentLine", + "value": " Three", + "start": 33, + "end": 41, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + { + "type": "CommentBlock", + "value": " Four ", + "start": 51, + "end": 61, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 11 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/comments/html/first-line/input.js b/packages/babel-parser/test/fixtures/comments/html/first-line/input.js new file mode 100644 index 000000000000..9fe3a97d3a3a --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/html/first-line/input.js @@ -0,0 +1 @@ +/**/ --> comment diff --git a/packages/babel-parser/test/fixtures/comments/html/first-line/output.json b/packages/babel-parser/test/fixtures/comments/html/first-line/output.json new file mode 100644 index 000000000000..d42874927c64 --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/html/first-line/output.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [], + "innerComments": [ + { + "type": "CommentBlock", + "value": "", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "CommentLine", + "value": " comment", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ] + }, + "comments": [ + { + "type": "CommentBlock", + "value": "", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "CommentLine", + "value": " comment", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/330/input.js b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-inside-loop/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/es2015/uncategorised/330/input.js rename to packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-inside-loop/input.js diff --git a/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-inside-loop/options.json b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-inside-loop/options.json new file mode 100644 index 000000000000..05a7826ae8ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-inside-loop/options.json @@ -0,0 +1,3 @@ +{ + "throws": "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js new file mode 100644 index 000000000000..241ddc1cde1c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/input.js @@ -0,0 +1 @@ +while (1) foo: bar: function foo(){} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/options.json b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/options.json new file mode 100644 index 000000000000..395620bfa2f8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/categorized/invalid-fn-decl-labeled-inside-loop/options.json @@ -0,0 +1,3 @@ +{ + "throws": "In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement (1:20)" +} diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/input.js b/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/input.js new file mode 100644 index 000000000000..208cd4d559e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/input.js @@ -0,0 +1 @@ +({ ge\u0074 x() {} }) diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/options.json b/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/options.json new file mode 100644 index 000000000000..0cd822570731 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/object/invalid-escape-get/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/input.js b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/input.js new file mode 100644 index 000000000000..3e4ef35fdb8f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/input.js @@ -0,0 +1 @@ +for await (const i of imports) {} diff --git a/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/options.json b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/options.json new file mode 100644 index 000000000000..40babbccd785 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-false/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \"(\" (1:4)" +} diff --git a/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/input.js b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/input.js new file mode 100644 index 000000000000..3e4ef35fdb8f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/input.js @@ -0,0 +1 @@ +for await (const i of imports) {} diff --git a/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/options.json b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/options.json new file mode 100644 index 000000000000..40360d582b73 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/options.json @@ -0,0 +1,3 @@ +{ + "allowAwaitOutsideFunction": true +} diff --git a/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/output.json b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/output.json new file mode 100644 index 000000000000..259b3ffcf47c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowAwaitOutsideFunction-true/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForOfStatement", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "await": true, + "left": { + "type": "VariableDeclaration", + "start": 11, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": null + } + ], + "kind": "const" + }, + "right": { + "type": "Identifier", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "imports" + }, + "name": "imports" + }, + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/input.js b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/input.js new file mode 100644 index 000000000000..f604032cb6d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/input.js @@ -0,0 +1 @@ +export { foo }; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/options.json b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/options.json new file mode 100644 index 000000000000..2de0f0b2d678 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "allowUndeclaredExports": true +} diff --git a/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/output.json b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/output.json new file mode 100644 index 000000000000..a454ef5bbdb2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/opts/allowUndeclaredExports/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "exported": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/regression/9374/input.js b/packages/babel-parser/test/fixtures/core/regression/9374/input.js new file mode 100644 index 000000000000..bce5ddf8e157 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/9374/input.js @@ -0,0 +1,3 @@ +function* test() { + yield new Foo(); +} diff --git a/packages/babel-parser/test/fixtures/core/regression/9374/output.json b/packages/babel-parser/test/fixtures/core/regression/9374/output.json new file mode 100644 index 000000000000..c32f37d64bc1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/9374/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": { + "type": "YieldExpression", + "start": 21, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "delegate": false, + "argument": { + "type": "NewExpression", + "start": 27, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "callee": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "arguments": [] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/input.js b/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/input.js new file mode 100644 index 000000000000..cbc4507bfeae --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/input.js @@ -0,0 +1 @@ +09.5 diff --git a/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/options.json b/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/options.json new file mode 100644 index 000000000000..8ac5b45f7194 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/non-octal-float-strict-mode/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Legacy octal literals are not allowed in strict mode (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/core/regression/non-octal-float/input.js b/packages/babel-parser/test/fixtures/core/regression/non-octal-float/input.js new file mode 100644 index 000000000000..cbc4507bfeae --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/non-octal-float/input.js @@ -0,0 +1 @@ +09.5 diff --git a/packages/babel-parser/test/fixtures/core/regression/non-octal-float/output.json b/packages/babel-parser/test/fixtures/core/regression/non-octal-float/output.json new file mode 100644 index 000000000000..f48f7a786775 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/non-octal-float/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 9.5, + "raw": "09.5" + }, + "value": 9.5 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/input.js b/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/input.js new file mode 100644 index 000000000000..80b817b29181 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/input.js @@ -0,0 +1 @@ +07.5 diff --git a/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/options.json b/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/options.json new file mode 100644 index 000000000000..a89de70c61e5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/octal-float-fail/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/input.js b/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/input.js new file mode 100644 index 000000000000..b6452ebfc3ad --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/input.js @@ -0,0 +1,3 @@ +function a ([a] = []) { + ; 'use strict'; with ({}) {} +} diff --git a/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/output.json b/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/output.json new file mode 100644 index 000000000000..694c18f640d7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/regression/use-strict-with-pre-semi/output.json @@ -0,0 +1,252 @@ +{ + "type": "File", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 12, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "ArrayPattern", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "a" + }, + "name": "a" + } + ] + }, + "right": { + "type": "ArrayExpression", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "elements": [] + } + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "EmptyStatement", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + { + "type": "ExpressionStatement", + "start": 27, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "expression": { + "type": "StringLiteral", + "start": 27, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "use strict", + "raw": "'use strict'" + }, + "value": "use strict" + } + }, + { + "type": "WithStatement", + "start": 41, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "object": { + "type": "ObjectExpression", + "start": 47, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "properties": [] + }, + "body": { + "type": "BlockStatement", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js new file mode 100644 index 000000000000..9c289f87c3ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js @@ -0,0 +1,5 @@ +{ + let bar; + var foo = 1; + let foo = 1; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json new file mode 100644 index 000000000000..b09098cda9c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (4:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js new file mode 100644 index 000000000000..512f6888653d --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js @@ -0,0 +1,3 @@ +let bar; +var foo = 1; +let foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json new file mode 100644 index 000000000000..37dd7bff7207 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js new file mode 100644 index 000000000000..59ae63e301b7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js @@ -0,0 +1,5 @@ +{ + let bar; + let foo = 1; + var foo = 1; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json new file mode 100644 index 000000000000..b09098cda9c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (4:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js new file mode 100644 index 000000000000..aebd03c05710 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js @@ -0,0 +1,3 @@ +let bar; +let foo = 1; +var foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json new file mode 100644 index 000000000000..37dd7bff7207 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/input.js new file mode 100644 index 000000000000..0ed8680e4854 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/input.js @@ -0,0 +1,3 @@ +try { +} catch ([foo, foo]) { +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/options.json new file mode 100644 index 000000000000..70121ca46ead --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-arr-destr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/input.js new file mode 100644 index 000000000000..5ccd99323ac8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/input.js @@ -0,0 +1 @@ +let foo; try {} catch (foo) {} let foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/options.json new file mode 100644 index 000000000000..386e81ecdc4c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-dbl-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (1:35)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/input.js new file mode 100644 index 000000000000..c53b6b3d03fc --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { + function foo() {} +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/options.json new file mode 100644 index 000000000000..62b0c73eb164 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/input.js new file mode 100644 index 000000000000..32d85119a543 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { + if (1) function foo() {} +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/output.json new file mode 100644 index 000000000000..a465e0c09fb0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-hang-func/output.json @@ -0,0 +1,206 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 24, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "test": { + "type": "NumericLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "FunctionDeclaration", + "start": 31, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 40, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 21 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "body": [], + "directives": [] + } + }, + "alternate": null + } + ], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/input.js new file mode 100644 index 000000000000..f223972849fe --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { +} +let foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/output.json new file mode 100644 index 000000000000..8c0ce7e4c006 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let-outside/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 8, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [], + "directives": [] + } + }, + "finalizer": null + }, + { + "type": "VariableDeclaration", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/input.js new file mode 100644 index 000000000000..8e4af00ffaed --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { + let foo; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/options.json new file mode 100644 index 000000000000..254a763e653e --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:6)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/input.js new file mode 100644 index 000000000000..b8a800685aa4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/input.js @@ -0,0 +1,3 @@ +try { +} catch ({ a: foo, b: { c: [foo] } }) { +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/options.json new file mode 100644 index 000000000000..a00c2989e1b1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-obj-destr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:28)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/input.js new file mode 100644 index 000000000000..0c5630af7e93 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/input.js @@ -0,0 +1,4 @@ +try { +} catch ([foo]) { + var foo; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/options.json new file mode 100644 index 000000000000..ff69adb0860a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-arr-destr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/input.js new file mode 100644 index 000000000000..6cdcb267c2b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/input.js @@ -0,0 +1,7 @@ +try { +} catch (foo) { + try { + } catch (_) { + var foo; + } +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/output.json new file mode 100644 index 000000000000..1baae9250df9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-nested/output.json @@ -0,0 +1,252 @@ +{ + "type": "File", + "start": 0, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 8, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 24, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "block": { + "type": "BlockStatement", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 34, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "param": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "_" + }, + "name": "_" + }, + "body": { + "type": "BlockStatement", + "start": 44, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 50, + "end": 58, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 11 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/input.js new file mode 100644 index 000000000000..a93f6a37bda5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/input.js @@ -0,0 +1,4 @@ +try { +} catch ({ foo }) { + var foo; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/options.json new file mode 100644 index 000000000000..ff69adb0860a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-obj-destr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/input.js new file mode 100644 index 000000000000..cd2df9964963 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { +} +var foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/output.json new file mode 100644 index 000000000000..f9626718bb97 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var-outside/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 8, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [], + "directives": [] + } + }, + "finalizer": null + }, + { + "type": "VariableDeclaration", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/input.js new file mode 100644 index 000000000000..e2983d96dca8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/input.js @@ -0,0 +1,4 @@ +try { +} catch (foo) { + var foo; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/output.json new file mode 100644 index 000000000000..54bc80b8062d --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-catch-var/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 8, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "param": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/input.js new file mode 100644 index 000000000000..3996f21e1238 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/input.js @@ -0,0 +1,2 @@ +class foo {}; +class foo {}; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/options.json new file mode 100644 index 000000000000..cdd0ac832c57 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-class/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/input.js new file mode 100644 index 000000000000..0f7aaf2b6905 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/input.js @@ -0,0 +1,2 @@ +class foo {}; +const foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/options.json new file mode 100644 index 000000000000..c45b9bf38290 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-const/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/input.js new file mode 100644 index 000000000000..0953b37d0ca1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/input.js @@ -0,0 +1,2 @@ +class foo {}; +function foo () {}; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/options.json new file mode 100644 index 000000000000..58aaf9d99d22 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/input.js new file mode 100644 index 000000000000..970f577a71e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/input.js @@ -0,0 +1,2 @@ +class foo {}; +let foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/options.json new file mode 100644 index 000000000000..bf89e4692c99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/input.js new file mode 100644 index 000000000000..0cbd916cdb6b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/input.js @@ -0,0 +1,2 @@ +class foo {}; +var foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/options.json new file mode 100644 index 000000000000..bf89e4692c99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-class-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (2:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/input.js new file mode 100644 index 000000000000..206de74b498c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/input.js @@ -0,0 +1 @@ +const foo=1, foo=2; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/options.json new file mode 100644 index 000000000000..d62aabfd1b07 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-const-const/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/input.js new file mode 100644 index 000000000000..b5a6ac21d8aa --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/input.js @@ -0,0 +1 @@ +{ function f() {} function* f() {} } diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/options.json new file mode 100644 index 000000000000..c083e3d4c063 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-gen/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'f' has already been declared (1:28)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/input.js new file mode 100644 index 000000000000..31ea14cffbb8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/input.js @@ -0,0 +1 @@ +{ function foo() {} function foo() {} } diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/options.json new file mode 100644 index 000000000000..3f4250fbe917 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module-sloppy/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'foo' has already been declared (1:29)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/input.js new file mode 100644 index 000000000000..11a6da2a7eb8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/input.js @@ -0,0 +1,2 @@ +function foo() {} +function foo() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/options.json new file mode 100644 index 000000000000..23553cce3705 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-module/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws":"Identifier 'foo' has already been declared (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/input.js new file mode 100644 index 000000000000..31ea14cffbb8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/input.js @@ -0,0 +1 @@ +{ function foo() {} function foo() {} } diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/output.json new file mode 100644 index 000000000000..94ae24d249a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script-sloppy/output.json @@ -0,0 +1,157 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "body": [ + { + "type": "FunctionDeclaration", + "start": 2, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start": 20, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/input.js new file mode 100644 index 000000000000..11a6da2a7eb8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/input.js @@ -0,0 +1,2 @@ +function foo() {} +function foo() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/output.json new file mode 100644 index 000000000000..af377ce80461 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-script/output.json @@ -0,0 +1,139 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start": 18, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/input.js new file mode 100644 index 000000000000..7f32f625bccf --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/input.js @@ -0,0 +1,4 @@ +{ + function foo() {} + var foo = 1; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/options.json new file mode 100644 index 000000000000..ff69adb0860a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var-sloppy/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/input.js new file mode 100644 index 000000000000..3248c1cf455b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/input.js @@ -0,0 +1,2 @@ +function foo() {} +var foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/output.json new file mode 100644 index 000000000000..d2a2c6f9982d --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-func-var/output.json @@ -0,0 +1,157 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "VariableDeclaration", + "start": 18, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "NumericLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/input.js new file mode 100644 index 000000000000..cc9c09466785 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/input.js @@ -0,0 +1 @@ +{ function* f() {} function f() {} } diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/options.json new file mode 100644 index 000000000000..c083e3d4c063 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'f' has already been declared (1:28)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/input.js new file mode 100644 index 000000000000..a43e0c8581d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/input.js @@ -0,0 +1,2 @@ +function *foo() {}; +function *foo() {}; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/output.json new file mode 100644 index 000000000000..e5bce9fb21da --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-gen-gen-script/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "FunctionDeclaration", + "start": 20, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/input.js new file mode 100644 index 000000000000..60494395b6a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/input.js @@ -0,0 +1 @@ +let foo, foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/options.json new file mode 100644 index 000000000000..714354e14501 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-let-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/input.js new file mode 100644 index 000000000000..79a65c0ee2de --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/input.js @@ -0,0 +1,4 @@ +{ + let a; + { var a; } +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/options.json new file mode 100644 index 000000000000..a0925d495610 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-let-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'a' has already been declared (3:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/input.js new file mode 100644 index 000000000000..b5bbb6d44168 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/input.js @@ -0,0 +1,4 @@ +{ + var a; + { let a; } +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/output.json new file mode 100644 index 000000000000..239db26973c2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-nested-var-let/output.json @@ -0,0 +1,173 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 4, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "BlockStatement", + "start": 13, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } + ], + "directives": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/input.js new file mode 100644 index 000000000000..260da8ced85a --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/input.js @@ -0,0 +1 @@ +var foo, foo; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/output.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/output.json new file mode 100644 index 000000000000..0be8a0eea29f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-var-var/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/for-let/input.js b/packages/babel-parser/test/fixtures/core/scope/for-let/input.js new file mode 100644 index 000000000000..a169b4038040 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-let/input.js @@ -0,0 +1,3 @@ +for (let i = 0;;) { + let i; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/for-let/output.json b/packages/babel-parser/test/fixtures/core/scope/for-let/output.json new file mode 100644 index 000000000000..8af98b16aa63 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-let/output.json @@ -0,0 +1,191 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "init": { + "type": "VariableDeclaration", + "start": 5, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "kind": "let" + }, + "test": null, + "update": null, + "body": { + "type": "BlockStatement", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/for-var/input.js b/packages/babel-parser/test/fixtures/core/scope/for-var/input.js new file mode 100644 index 000000000000..400b636e5c84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-var/input.js @@ -0,0 +1,3 @@ +for (let i = 0;;) { + var i; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/for-var/options.json b/packages/babel-parser/test/fixtures/core/scope/for-var/options.json new file mode 100644 index 000000000000..10e45adf4560 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'i' has already been declared (2:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/let-assign/input.js b/packages/babel-parser/test/fixtures/core/scope/let-assign/input.js new file mode 100644 index 000000000000..a66eb5ab6774 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/let-assign/input.js @@ -0,0 +1 @@ +let x = 1; x = 2; diff --git a/packages/babel-parser/test/fixtures/core/scope/let-assign/output.json b/packages/babel-parser/test/fixtures/core/scope/let-assign/output.json new file mode 100644 index 000000000000..508af9fc85d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/let-assign/output.json @@ -0,0 +1,173 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "NumericLiteral", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start": 11, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js new file mode 100644 index 000000000000..df3d92761397 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/input.js @@ -0,0 +1 @@ +export { encrypt as default }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json new file mode 100644 index 000000000000..8448889cf253 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as-default/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js new file mode 100644 index 000000000000..f14dc079868b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/input.js @@ -0,0 +1,2 @@ +export { encrypt as decrypt }; +function decrypt() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json new file mode 100644 index 000000000000..8448889cf253 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-as/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js new file mode 100644 index 000000000000..1e993e373a01 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/input.js @@ -0,0 +1,4 @@ +{ + function encrypt() {} +} +export { encrypt } diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json new file mode 100644 index 000000000000..0844d3e80e68 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-block/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (4:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js new file mode 100644 index 000000000000..2ab393fc2343 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/input.js @@ -0,0 +1 @@ +export { Object as Obj }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json new file mode 100644 index 000000000000..cbab70613300 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin-as/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'Object' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js new file mode 100644 index 000000000000..8ddd96dff319 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/input.js @@ -0,0 +1 @@ +export { Object }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json new file mode 100644 index 000000000000..cbab70613300 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-builtin/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'Object' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/input.js new file mode 100644 index 000000000000..87d3720d82fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/input.js @@ -0,0 +1,3 @@ +function a() {} + +export { a }; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/options.json new file mode 100644 index 000000000000..0580fdad26f5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "strictMode": false +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/output.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/output.json new file mode 100644 index 000000000000..e59b53b2e0ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-1/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 17, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "local": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "exported": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/input.js new file mode 100644 index 000000000000..aacd737fb7b9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/input.js @@ -0,0 +1,2 @@ +export { a }; +function a() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/options.json new file mode 100644 index 000000000000..0580fdad26f5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "strictMode": false +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/output.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/output.json new file mode 100644 index 000000000000..16b50c7b3875 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-function-loose-mode-2/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "exported": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "source": null, + "declaration": null + }, + { + "type": "FunctionDeclaration", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js new file mode 100644 index 000000000000..6d6c87fb7a38 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/input.js @@ -0,0 +1,2 @@ +export { encrypt }; +if (true) function encrypt() {} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json new file mode 100644 index 000000000000..2c97b3ce5a78 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-if/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "In strict mode code, functions can only be declared at top level or inside a block (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js new file mode 100644 index 000000000000..b8a0b5223551 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/input.js @@ -0,0 +1,4 @@ +{ + var encrypt +} +export { encrypt } diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json new file mode 100644 index 000000000000..91e34252dbc5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export-var/output.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "BlockStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 4, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "init": null + } + ], + "kind": "var" + } + ], + "directives": [] + }, + { + "type": "ExportNamedDeclaration", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "local": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "exported": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js b/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js new file mode 100644 index 000000000000..7ec871cd2f99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export/input.js @@ -0,0 +1 @@ +export { encrypt }; diff --git a/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json b/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json new file mode 100644 index 000000000000..8448889cf253 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/undecl-export/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Export 'encrypt' is not defined (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/276/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/276/output.json index d363a5d4cc63..7124a7ba6fff 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/276/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/276/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/277/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/277/output.json index 80dde4eca487..0f104da5ae82 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/277/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/277/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/278/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/278/output.json index 4b11f881deec..8721f9d98403 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/278/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/278/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/279/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/279/output.json index fbcb70be2667..49094bb0e6bd 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/279/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/279/output.json @@ -176,7 +176,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/280/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/280/output.json index ea48a4030059..b1589f69dcee 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/280/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/280/output.json @@ -61,7 +61,6 @@ "directives": [] }, "handler": null, - "guardedHandlers": [], "finalizer": { "type": "BlockStatement", "start": 16, diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/281/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/281/output.json index bc19c5698fbf..7bb5acfbedbb 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/281/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/281/output.json @@ -225,7 +225,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/282/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/282/output.json index dc667d97efc5..91b008540089 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/282/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/282/output.json @@ -225,7 +225,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": { "type": "BlockStatement", "start": 47, diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/382/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/382/options.json index 27a7b64d71d4..2b91be8d5115 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/382/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/382/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'if' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/396/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/396/options.json index 570ef651fb67..2e1b1cc3aa43 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/396/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/396/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \")\" (1:18)" + "throws": "Rest element must be last element (1:18)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/397/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/397/options.json index cb6c66081ebf..f9543317a817 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/397/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/397/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:11)" + "throws": "Unexpected keyword 'if' (1:11)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/398/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/398/options.json index cb6c66081ebf..bba7a057d842 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/398/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/398/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:11)" + "throws": "Unexpected keyword 'true' (1:11)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/399/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/399/options.json index cb6c66081ebf..b04b18396af1 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/399/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/399/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:11)" + "throws": "Unexpected keyword 'false' (1:11)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/400/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/400/options.json index cb6c66081ebf..667f2cc8816d 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/400/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/400/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:11)" + "throws": "Unexpected keyword 'null' (1:11)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/401/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/401/options.json index 2a28555f76db..fa57d4f43f70 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/401/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/401/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected keyword 'null' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/402/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/402/options.json index 2a28555f76db..c4a7ead13704 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/402/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/402/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected keyword 'true' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/403/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/403/options.json index 2a28555f76db..0e9cf8962aae 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/403/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/403/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected keyword 'false' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/404/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/404/options.json index 2a28555f76db..a87aa98c0e01 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/404/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/404/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected keyword 'if' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/468/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/468/options.json index 28f88106148b..b463f315f9eb 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/468/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/468/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:36)" -} + "throws": "Binding 'eval' in strict mode (1:36)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/469/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/469/options.json index 913c7bb59f38..9e9f875dfbb5 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/469/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/469/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:36)" -} + "throws": "Binding 'arguments' in strict mode (1:36)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/470/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/470/options.json index 0306783e6eef..b5fd79ff5ff1 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/470/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/470/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'eval' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/471/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/471/options.json index d1ae2825366a..15b7ac855374 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/471/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/471/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'arguments' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/472/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/472/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/472/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/472/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/473/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/473/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/473/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/473/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/474/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/474/options.json index 48fd4ff41936..2783b68b3d58 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/474/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/474/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'eval' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/475/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/475/options.json index 48fd4ff41936..2783b68b3d58 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/475/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/475/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'eval' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/476/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/476/options.json index d579a92e2358..fe2654496fc9 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/476/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/476/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'arguments' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/477/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/477/options.json index d579a92e2358..fe2654496fc9 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/477/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/477/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'arguments' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/478/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/478/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/478/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/478/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/479/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/479/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/479/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/479/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/480/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/480/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/480/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/480/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/481/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/481/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/481/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/481/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/482/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/482/options.json index 71bbcc0b9c1c..6db4ae7bf008 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/482/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/482/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'eval' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/483/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/483/options.json index 544d28f50291..b02fb725c767 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/483/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/483/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'arguments' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/484/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/484/options.json index bf851387b4c6..a7490f9321d4 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/484/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/484/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'eval' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/485/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/485/options.json index e4d477b8e4ec..80b8b2d85caa 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/485/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/485/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'arguments' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/486/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/486/options.json index f6c8eea4b0d3..706ba8380c70 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/486/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/486/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:42)" -} + "throws": "Binding 'eval' in strict mode (1:42)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/487/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/487/options.json index d26216e0a364..d0e461af3911 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/487/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/487/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:42)" -} + "throws": "Binding 'arguments' in strict mode (1:42)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/488/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/488/options.json index 69e4925a3ffd..ee2e7d7c7745 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/488/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/488/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'eval' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/489/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/489/options.json index fbdc57cfc8fa..bb4b812bab32 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/489/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/489/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'arguments' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/490/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/490/options.json index 0306783e6eef..b5fd79ff5ff1 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/490/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/490/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'eval' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/491/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/491/options.json index c2d1e1a69b41..ff90f09173c4 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/491/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/491/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'package' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/492/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/492/options.json index 92828dc4f1c9..b8f97ca4fe56 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/492/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/492/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'eval' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/493/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/493/options.json index 71bbcc0b9c1c..6db4ae7bf008 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/493/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/493/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'eval' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/494/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/494/options.json index 241eccc1bf6d..e80a856d48a0 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/494/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/494/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:49)" -} + "throws": "Binding 'eval' in strict mode (1:49)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/495/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/495/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/495/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/495/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/496/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/496/options.json index 0e1962195156..5d2dc563b16e 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/496/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/496/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'arguments' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/497/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/497/options.json index 92828dc4f1c9..b8f97ca4fe56 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/497/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/497/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'eval' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/498/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/498/options.json index e9f6bf4d32ff..ab7000409bab 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/498/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/498/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'arguments' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/500/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/500/options.json index ec4ea95dc9cb..45ca229c1e8e 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/500/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/500/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:33)" + "throws": "Legacy octal literals are not allowed in strict mode (1:33)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/502/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/502/options.json index dd200e16e5bf..8f6c8218f747 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/502/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/502/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:36)" + "throws": "Legacy octal literals are not allowed in strict mode (1:36)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/504/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/504/options.json index 2748b9f03d9e..0641de45e29a 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/504/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/504/options.json @@ -1,3 +1,3 @@ { - "throws": "implements is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'implements' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/505/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/505/options.json index 6efaf057ca5c..859238d0423f 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/505/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/505/options.json @@ -1,3 +1,3 @@ { - "throws": "interface is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'interface' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/506/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/506/options.json index 61578ad8f860..344c7075f4bf 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/506/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/506/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'package' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/507/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/507/options.json index da502d0daa6a..9fb9deaf9cba 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/507/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/507/options.json @@ -1,3 +1,3 @@ { - "throws": "private is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'private' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/508/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/508/options.json index 6fd44c0e1ba5..292fb56f1cf3 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/508/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/508/options.json @@ -1,3 +1,3 @@ { - "throws": "protected is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'protected' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/509/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/509/options.json index 3a41c740eaac..d5f48446906a 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/509/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/509/options.json @@ -1,3 +1,3 @@ { - "throws": "public is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'public' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/510/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/510/options.json index 764205122e0f..0f41ff2e6f24 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/510/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/510/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'static' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/511/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/511/options.json index e316c4fc64fd..fff472344fd7 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/511/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/511/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'static' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/512/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/512/options.json index 9b6fddd2ebba..d4d0a96bfb64 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/512/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/512/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'static' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/513/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/513/options.json index a2eac88ba69d..91bc36d3f360 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/513/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/513/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:23)" + "throws": "Unexpected reserved word 'static' (1:23)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/514/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/514/options.json index e23388601bb0..8b20b9a7df36 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/514/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/514/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:14)" + "throws": "Argument name clash (1:14)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/515/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/515/options.json index 0bb96c96d88e..e227bd1a6b74 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/515/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/515/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:11)" -} + "throws": "Binding 'eval' in strict mode (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/516/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/516/options.json index 7551a61b9e0b..8e1f9af4ec47 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/516/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/516/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:11)" -} + "throws": "Binding 'package' in strict mode (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/517/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/517/options.json index 660e54ca2a82..9d2a58081596 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/517/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/517/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:43)" + "throws": "Argument name clash (1:43)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/518/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/518/options.json index 28545ded1456..61c3bbb5abe0 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/518/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/518/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:15)" + "throws": "Argument name clash (1:15)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/519/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/519/options.json index 0f592c74a35b..ae469fbd59da 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/519/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/519/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:44)" + "throws": "Argument name clash (1:44)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/520/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/520/options.json index b52d2d2e1520..3c24c608c88a 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/520/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/520/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:12)" -} + "throws": "Binding 'eval' in strict mode (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/521/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/521/options.json index 7b80f0e455ce..96d524816cc9 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/521/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/521/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:12)" -} + "throws": "Binding 'package' in strict mode (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/522/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/522/options.json index 3696be182d05..0b443b9bacfa 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/522/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/522/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:65)" + "throws": "Legacy octal literals are not allowed in strict mode (1:65)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/523/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/523/options.json index 27a7b64d71d4..60a9d5934bd2 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/523/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/523/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'this' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/544/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/544/options.json index 8874a76e59d1..37c243afff2a 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/544/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/544/options.json @@ -1,3 +1,3 @@ { - "throws": "public is a reserved word in strict mode (2:8)" + "throws": "Unexpected reserved word 'public' (2:8)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/545/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/545/options.json index 560bb8988152..b09fdddc9d0a 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/545/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/545/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "public is a reserved word in strict mode (1:8)" + "throws": "Unexpected reserved word 'public' (1:8)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/547/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/547/options.json index 20c9b2493e67..c2fb6377e80d 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/547/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/547/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (2:8)" + "throws": "Unexpected reserved word 'arguments' (2:8)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/548/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/548/options.json index d2dd99623cd3..4183c2e22534 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/548/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/548/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "arguments is a reserved word in strict mode (1:8)" + "throws": "Unexpected reserved word 'arguments' (1:8)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/550/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/550/options.json index f635fb88c5c9..5cee88d901e4 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/550/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/550/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (2:10)" + "throws": "Legacy octal literals are not allowed in strict mode (2:10)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/552/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/552/options.json index f635fb88c5c9..5cee88d901e4 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/552/options.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/552/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (2:10)" + "throws": "Legacy octal literals are not allowed in strict mode (2:10)" } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/555/input.js b/packages/babel-parser/test/fixtures/core/uncategorised/555/input.js new file mode 100644 index 000000000000..2c262ab21189 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/555/input.js @@ -0,0 +1,6 @@ +function foo ( + first, + ...second, + third, +) { +}; diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/555/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/555/options.json new file mode 100644 index 000000000000..c1c6450ba3c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/555/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (3:13)" +} diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/556/input.js b/packages/babel-parser/test/fixtures/core/uncategorised/556/input.js new file mode 100644 index 000000000000..13cfa4015d22 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/556/input.js @@ -0,0 +1 @@ +({x}) = {x: 1}; diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/556/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/556/options.json new file mode 100644 index 000000000000..eff49cbfba64 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/556/options.json @@ -0,0 +1,4 @@ +{ + "createParenthesizedExpressions": true, + "throws": "You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/557/input.js b/packages/babel-parser/test/fixtures/core/uncategorised/557/input.js new file mode 100644 index 000000000000..40d925520dfa --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/557/input.js @@ -0,0 +1 @@ +("hello"); diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/557/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/557/options.json new file mode 100644 index 000000000000..0861962d889d --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/557/options.json @@ -0,0 +1,3 @@ +{ + "createParenthesizedExpressions": true +} diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/557/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/557/output.json new file mode 100644 index 000000000000..b1f49f00e99f --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/557/output.json @@ -0,0 +1,85 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "ParenthesizedExpression", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "expression": { + "type": "StringLiteral", + "start": 1, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": "hello", + "raw": "\"hello\"" + }, + "value": "hello" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/558/input.js b/packages/babel-parser/test/fixtures/core/uncategorised/558/input.js new file mode 100644 index 000000000000..2cf717d47db3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/558/input.js @@ -0,0 +1 @@ +([a]) = [] diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/558/options.json b/packages/babel-parser/test/fixtures/core/uncategorised/558/options.json new file mode 100644 index 000000000000..f37c4bc95c57 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/uncategorised/558/options.json @@ -0,0 +1,4 @@ +{ + "createParenthesizedExpressions": true, + "throws": "You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/core/valid-escape/async/input.js b/packages/babel-parser/test/fixtures/core/valid-escape/async/input.js new file mode 100644 index 000000000000..2e12a7c8d0a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/valid-escape/async/input.js @@ -0,0 +1 @@ +(\u0061sync ()) diff --git a/packages/babel-parser/test/fixtures/core/valid-escape/async/output.json b/packages/babel-parser/test/fixtures/core/valid-escape/async/output.json new file mode 100644 index 000000000000..e220d3207f6b --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/valid-escape/async/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "CallExpression", + "start": 1, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "callee": { + "type": "Identifier", + "start": 1, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "async" + }, + "name": "async" + }, + "arguments": [], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/input.js b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/input.js new file mode 100644 index 000000000000..d4aba7bf5562 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/input.js @@ -0,0 +1 @@ +[...a,] = []; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/options.json b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/options.json new file mode 100644 index 000000000000..daa827f45cc4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-rest/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/input.js b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/input.js new file mode 100644 index 000000000000..7161cc852a5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/input.js @@ -0,0 +1 @@ +[...a,]; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/output.json b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/output.json new file mode 100644 index 000000000000..5874666e2695 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/comma-after-spread/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "ArrayExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "elements": [ + { + "type": "SpreadElement", + "start": 1, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "argument": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/invalid-location/options.json b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/invalid-location/options.json index 97dce207c844..0dac59b7a808 100644 --- a/packages/babel-parser/test/fixtures/es2015/array-rest-spread/invalid-location/options.json +++ b/packages/babel-parser/test/fixtures/es2015/array-rest-spread/invalid-location/options.json @@ -1,4 +1,3 @@ { - "throws": - "The rest element has to be the last element when destructuring (1:1)" + "throws": "Rest element must be last element (1:1)" } diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/input.js b/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/input.js new file mode 100644 index 000000000000..d06c522c05b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/input.js @@ -0,0 +1 @@ +(...rest,) => {} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/options.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/options.json new file mode 100644 index 000000000000..65ed8c638978 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/comma-after-rest-param/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:8)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/input.js b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/input.js new file mode 100644 index 000000000000..6626a35389c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/input.js @@ -0,0 +1 @@ +(foo) => {} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/options.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/options.json new file mode 100644 index 000000000000..0861962d889d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/options.json @@ -0,0 +1,3 @@ +{ + "createParenthesizedExpressions": true +} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/output.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/output.json new file mode 100644 index 000000000000..09568c70bbb9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/create-parenthesized-expressions/output.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "foo" + }, + "name": "foo" + } + ], + "body": { + "type": "BlockStatement", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/input.js b/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/input.js new file mode 100644 index 000000000000..c13825de4f0a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/input.js @@ -0,0 +1,5 @@ +( + first, + ...second, + third +) => {}; diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/options.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/options.json new file mode 100644 index 000000000000..c1c6450ba3c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-rest-in-params/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (3:13)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/object-rest-spread/options.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/object-rest-spread/options.json deleted file mode 100644 index 4de042a69733..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/arrow-functions/object-rest-spread/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["objectRestSpread"] -} diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/input.js b/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/input.js deleted file mode 100644 index d55ef5bce0b8..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/input.js +++ /dev/null @@ -1 +0,0 @@ -(...a,) => {}; diff --git a/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/options.json b/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/options.json deleted file mode 100644 index a85e470aeb8b..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/arrow-functions/params-invalid-rest-trailing-comma/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "A trailing comma is not permitted after the rest element (1:5)" -} diff --git a/packages/babel-parser/test/fixtures/es2015/class-methods/direct-super-outside-constructor/options.json b/packages/babel-parser/test/fixtures/es2015/class-methods/direct-super-outside-constructor/options.json index 96ed06f4ca3e..9461325c423a 100644 --- a/packages/babel-parser/test/fixtures/es2015/class-methods/direct-super-outside-constructor/options.json +++ b/packages/babel-parser/test/fixtures/es2015/class-methods/direct-super-outside-constructor/options.json @@ -1,4 +1,3 @@ { - "throws": - "super() is only valid inside a class constructor. Make sure the method name is spelled exactly as 'constructor'. (2:8)" + "throws": "super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class? (2:8)" } diff --git a/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/input.js b/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/input.js new file mode 100644 index 000000000000..101e2b77cc79 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/input.js @@ -0,0 +1,3 @@ +class Foo { + bar(a, a) {} +} diff --git a/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/options.json b/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/options.json new file mode 100644 index 000000000000..c7a2c3ba50a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class-methods/disallow-duplicate-method-params/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Argument name clash (2:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/division/input.js b/packages/babel-parser/test/fixtures/es2015/class/division/input.js new file mode 100644 index 000000000000..590fe776ecf6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/division/input.js @@ -0,0 +1,9 @@ +x = class{} / foo + +x = class{} +/ foo / g + +(x = class{} / foo) + +(x = class{} +/ foo / g) diff --git a/packages/babel-parser/test/fixtures/es2015/class/division/output.json b/packages/babel-parser/test/fixtures/es2015/class/division/output.json new file mode 100644 index 000000000000..0a4a21ad4d20 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/division/output.json @@ -0,0 +1,561 @@ +{ + "type": "File", + "start": 0, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 86, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "left": { + "type": "ClassExpression", + "start": 4, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + }, + { + "type": "ExpressionStatement", + "start": 19, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 19, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 23, + "end": 86, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "left": { + "type": "BinaryExpression", + "start": 23, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "left": { + "type": "ClassExpression", + "start": 23, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + } + }, + "operator": "/", + "right": { + "type": "CallExpression", + "start": 39, + "end": 86, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "callee": { + "type": "CallExpression", + "start": 39, + "end": 61, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "callee": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 43, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 47, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "left": { + "type": "ClassExpression", + "start": 47, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 52, + "end": 54, + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 57, + "end": 60, + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 18 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + ] + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 64, + "end": 85, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 68, + "end": 85, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "left": { + "type": "BinaryExpression", + "start": 68, + "end": 81, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "left": { + "type": "ClassExpression", + "start": 68, + "end": 75, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 73, + "end": 75, + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 12 + } + }, + "body": [] + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 78, + "end": 81, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + } + }, + "operator": "/", + "right": { + "type": "Identifier", + "start": 84, + "end": 85, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/extends-strict/input.js b/packages/babel-parser/test/fixtures/es2015/class/extends-strict/input.js new file mode 100644 index 000000000000..2bc6c813e8ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/extends-strict/input.js @@ -0,0 +1,4 @@ +class C extends (function B() { + with ({}); + return B; +}()) {} diff --git a/packages/babel-parser/test/fixtures/es2015/class/extends-strict/options.json b/packages/babel-parser/test/fixtures/es2015/class/extends-strict/options.json new file mode 100644 index 000000000000..09a1c52e4354 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/extends-strict/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'with' in strict mode (2:2)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/input.js b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/input.js new file mode 100644 index 000000000000..dca801f8de29 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/input.js @@ -0,0 +1 @@ +class X { ge\u0074 x() {} } diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/options.json b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/options.json new file mode 100644 index 000000000000..1e730e170733 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-get/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:19)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/input.js b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/input.js new file mode 100644 index 000000000000..fafbe9ab9f4d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/input.js @@ -0,0 +1 @@ +class X { se\u0074 x(value) {} } diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/options.json b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/options.json new file mode 100644 index 000000000000..1e730e170733 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-set/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:19)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/input.js b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/input.js new file mode 100644 index 000000000000..a561f8c32135 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/input.js @@ -0,0 +1 @@ +class X { st\u0061tic y() {} } diff --git a/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/options.json b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/options.json new file mode 100644 index 000000000000..b23f881870cf --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/class/invalid-escape-static/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:22)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-this/options.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-this/options.json index bc51e124a0f3..1b54b61689e7 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-this/options.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-this/options.json @@ -1,3 +1,3 @@ { - "throws": "this is a reserved word (1:6)" + "throws": "Unexpected keyword 'this' (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/options.json b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/options.json index 6b5d54181044..dfcad1b5cbf0 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/options.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-array/options.json @@ -1,4 +1,3 @@ { - "throws": - "You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)" + "throws": "You're trying to assign to a parenthesized expression, eg. instead of `([a]) = 0` use `([a] = 0)` (1:1)" } diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/options.json b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/options.json index 783a56a70523..d0fb48924093 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/options.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/parenthesized-lhs-object/options.json @@ -1,4 +1,3 @@ { - "throws": - "You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)" + "throws": "You're trying to assign to a parenthesized expression, eg. instead of `({a}) = 0` use `({a} = 0)` (1:1)" } diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/options.json new file mode 100644 index 000000000000..f5710cd7a9c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid left-hand side in for-loop (2:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/output.json b/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/output.json deleted file mode 100644 index 5a1b605cbce2..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/for-in/bare-initializer/output.json +++ /dev/null @@ -1,184 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - }, - "identifierName": "a" - }, - "name": "a" - }, - "init": null - } - ], - "kind": "var" - }, - { - "type": "ForInStatement", - "start": 7, - "end": 25, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 18 - } - }, - "left": { - "type": "AssignmentPattern", - "start": 12, - "end": 17, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 10 - } - }, - "left": { - "type": "Identifier", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "a" - }, - "name": "a" - }, - "right": { - "type": "NumericLiteral", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 10 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - } - }, - "right": { - "type": "ObjectExpression", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "properties": [] - }, - "body": { - "type": "EmptyStatement", - "start": 24, - "end": 25, - "loc": { - "start": { - "line": 2, - "column": 17 - }, - "end": { - "line": 2, - "column": 18 - } - } - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/const-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/const-initializer/options.json index 85e8252d6fda..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/es2015/for-in/const-initializer/options.json +++ b/packages/babel-parser/test/fixtures/es2015/for-in/const-initializer/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:17)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/let-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/let-initializer/options.json index a717ca0fa7e7..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/es2015/for-in/let-initializer/options.json +++ b/packages/babel-parser/test/fixtures/es2015/for-in/let-initializer/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:15)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/strict-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/strict-initializer/options.json index 497c2b2bde92..0048427255c0 100644 --- a/packages/babel-parser/test/fixtures/es2015/for-in/strict-initializer/options.json +++ b/packages/babel-parser/test/fixtures/es2015/for-in/strict-initializer/options.json @@ -1,3 +1,3 @@ { - "throws": "for-in initializer in strict mode (2:15)" -} + "throws": "for-in loop variable declaration may not have an initializer (2:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/var-arraybindingpattern-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/var-arraybindingpattern-initializer/options.json index 85e8252d6fda..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/es2015/for-in/var-arraybindingpattern-initializer/options.json +++ b/packages/babel-parser/test/fixtures/es2015/for-in/var-arraybindingpattern-initializer/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:17)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-in/var-objectbindingpattern-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-in/var-objectbindingpattern-initializer/options.json index 85e8252d6fda..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/es2015/for-in/var-objectbindingpattern-initializer/options.json +++ b/packages/babel-parser/test/fixtures/es2015/for-in/var-objectbindingpattern-initializer/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:17)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/input.js new file mode 100644 index 000000000000..1afade4a7fd9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/input.js @@ -0,0 +1,2 @@ +var a; +for (a = 0 of {}); diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/options.json b/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/options.json new file mode 100644 index 000000000000..f5710cd7a9c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/bare-initializer/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid left-hand side in for-loop (2:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/input.js new file mode 100644 index 000000000000..fc8fecda1a78 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/input.js @@ -0,0 +1 @@ +for (const {a} of /b/) {} diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/output.json b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/output.json new file mode 100644 index 000000000000..e6724bdbc964 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-const/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForOfStatement", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "await": false, + "left": { + "type": "VariableDeclaration", + "start": 5, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": { + "type": "ObjectPattern", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": null + } + ], + "kind": "const" + }, + "right": { + "type": "RegExpLiteral", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "raw": "/b/" + }, + "pattern": "b", + "flags": "" + }, + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/input.js new file mode 100644 index 000000000000..0bf988b293f8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/input.js @@ -0,0 +1 @@ +for (let {a} of /b/) {} diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/output.json b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/output.json new file mode 100644 index 000000000000..6c74fa327abb --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-let/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForOfStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "await": false, + "left": { + "type": "VariableDeclaration", + "start": 5, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "ObjectPattern", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": null + } + ], + "kind": "let" + }, + "right": { + "type": "RegExpLiteral", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "raw": "/b/" + }, + "pattern": "b", + "flags": "" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/input.js new file mode 100644 index 000000000000..cef3e0ee5228 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/input.js @@ -0,0 +1 @@ +for (var {a} of /b/) {} diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/output.json b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/output.json new file mode 100644 index 000000000000..507f3b6495e3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/brackets-var/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForOfStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "await": false, + "left": { + "type": "VariableDeclaration", + "start": 5, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "ObjectPattern", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": null + } + ], + "kind": "var" + }, + "right": { + "type": "RegExpLiteral", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "raw": "/b/" + }, + "pattern": "b", + "flags": "" + }, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/input.js new file mode 100644 index 000000000000..7d8403183214 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/input.js @@ -0,0 +1 @@ +for (x \u006ff y) {} diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/options.json b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/options.json new file mode 100644 index 000000000000..6b9933a77108 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-escape-of/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:7)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/input.js b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/input.js new file mode 100644 index 000000000000..90f5a5a32748 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/input.js @@ -0,0 +1 @@ +for (let x of y, z) {} diff --git a/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/options.json b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/options.json new file mode 100644 index 000000000000..e4ff6fef3cde --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/for-of/invalid-expr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \")\" (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/input.js b/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/input.js new file mode 100644 index 000000000000..521b91facbbc --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/input.js @@ -0,0 +1 @@ +(function* () { y\u0069eld 10 }) diff --git a/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/options.json b/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/options.json new file mode 100644 index 000000000000..dcd45c9b9715 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/generators/invalid-escape-yield/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can not use 'yield' as identifier inside a generator (1:16)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/input.js b/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/input.js new file mode 100644 index 000000000000..b6864d7c339c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/input.js @@ -0,0 +1 @@ +if (1) function *foo() {} diff --git a/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/options.json b/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/options.json new file mode 100644 index 000000000000..8cdac51705a1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/generators/invalid-hanging/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Generators can only be declared at the top level or inside a block (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/input.js b/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/input.js new file mode 100644 index 000000000000..b5cc585a2a7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/input.js @@ -0,0 +1 @@ +le\u0074 x = 5 diff --git a/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/options.json b/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/options.json new file mode 100644 index 000000000000..410ecd16fddf --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/invalid-escape/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/input.js new file mode 100644 index 000000000000..2b8952b97363 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/input.js @@ -0,0 +1 @@ +let + 1 diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/output.json new file mode 100644 index 000000000000..d5896aa4d598 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-1/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "let" + }, + "name": "let" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/input.js new file mode 100644 index 000000000000..15ea1476df39 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/input.js @@ -0,0 +1 @@ +var let = 1 diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/output.json new file mode 100644 index 000000000000..dc261c3dcbfb --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-2/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "let" + }, + "name": "let" + }, + "init": { + "type": "NumericLiteral", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/input.js new file mode 100644 index 000000000000..bf4301ea135c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/input.js @@ -0,0 +1 @@ +let instanceof Foo diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/output.json new file mode 100644 index 000000000000..b0f5399086e7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-3/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "let" + }, + "name": "let" + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/input.js new file mode 100644 index 000000000000..8b1ded17c053 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/input.js @@ -0,0 +1 @@ +let in {} diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/output.json new file mode 100644 index 000000000000..96851ba7aa04 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-4/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "let" + }, + "name": "let" + }, + "operator": "in", + "right": { + "type": "ObjectExpression", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "properties": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/input.js new file mode 100644 index 000000000000..5ddea3e168cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/input.js @@ -0,0 +1,2 @@ +if (1) let +{} diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/output.json new file mode 100644 index 000000000000..ade78031a623 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-5/output.json @@ -0,0 +1,120 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "test": { + "type": "NumericLiteral", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "consequent": { + "type": "ExpressionStatement", + "start": 7, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "Identifier", + "start": 7, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "let" + }, + "name": "let" + } + }, + "alternate": null + }, + { + "type": "BlockStatement", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "body": [], + "directives": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/input.js new file mode 100644 index 000000000000..2ebfa83ecf36 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/input.js @@ -0,0 +1,2 @@ +while (0) let +foo diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/output.json new file mode 100644 index 000000000000..c51c3538f169 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-6/output.json @@ -0,0 +1,134 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "WhileStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "test": { + "type": "NumericLiteral", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "body": { + "type": "ExpressionStatement", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "let" + }, + "name": "let" + } + } + }, + { + "type": "ExpressionStatement", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/input.js new file mode 100644 index 000000000000..7036d1f8e435 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/input.js @@ -0,0 +1,2 @@ +while (0) let +instanceof Foo diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/output.json new file mode 100644 index 000000000000..721e29212ee3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-7/output.json @@ -0,0 +1,135 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "WhileStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "test": { + "type": "NumericLiteral", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "body": { + "type": "ExpressionStatement", + "start": 10, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 10, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "let" + }, + "name": "let" + }, + "operator": "instanceof", + "right": { + "type": "Identifier", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/input.js new file mode 100644 index 000000000000..dc734683c900 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/input.js @@ -0,0 +1,2 @@ +"use strict"; +let + 1 diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/options.json new file mode 100644 index 000000000000..ab238c8bbff9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-as-identifier-strict-fail/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected reserved word 'let' (2:0)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/input.js new file mode 100644 index 000000000000..c1eb32d32577 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/input.js @@ -0,0 +1 @@ +let { let } = {}; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/options.json new file mode 100644 index 000000000000..f57eb3dfe6c2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/input.js new file mode 100644 index 000000000000..24c395ad2c48 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/input.js @@ -0,0 +1 @@ +const { let } = {}; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/options.json new file mode 100644 index 000000000000..365d76ddf46e --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/input.js new file mode 100644 index 000000000000..346cb602094b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/input.js @@ -0,0 +1 @@ +let [let] = []; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/options.json new file mode 100644 index 000000000000..d83275e4a85a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/input.js new file mode 100644 index 000000000000..8c5f4099aed6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/input.js @@ -0,0 +1 @@ +const [let] = []; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/options.json new file mode 100644 index 000000000000..456948bdd272 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-4/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:7)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/input.js new file mode 100644 index 000000000000..27fcc4afa2f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/input.js @@ -0,0 +1 @@ +let let diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/options.json new file mode 100644 index 000000000000..4ca932f989ae --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-5/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/input.js new file mode 100644 index 000000000000..9514d67a4443 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/input.js @@ -0,0 +1 @@ +const let = '' diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/options.json b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/options.json new file mode 100644 index 000000000000..f57eb3dfe6c2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-at-binding-list-fail-6/options.json @@ -0,0 +1,3 @@ +{ + "throws": "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/input.js new file mode 100644 index 000000000000..37a324ee20da --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/input.js @@ -0,0 +1,4 @@ +if (false) { + L: let // ASI + {} +} diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/output.json new file mode 100644 index 000000000000..c2a68fccc8ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-block-with-newline/output.json @@ -0,0 +1,220 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": false + }, + "consequent": { + "type": "BlockStatement", + "start": 11, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "LabeledStatement", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "body": { + "type": "ExpressionStatement", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "expression": { + "type": "Identifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "let" + }, + "name": "let" + } + }, + "label": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "L" + }, + "name": "L" + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " ASI", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ] + }, + { + "type": "BlockStatement", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "body": [], + "directives": [], + "leadingComments": [ + { + "type": "CommentLine", + "value": " ASI", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ] + } + ], + "directives": [] + }, + "alternate": null + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " ASI", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/input.js new file mode 100644 index 000000000000..7edb379b842f --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/input.js @@ -0,0 +1,2 @@ +let + [a] = [1]; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/output.json new file mode 100644 index 000000000000..f21958466322 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-arr-dstrk/output.json @@ -0,0 +1,139 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "id": { + "type": "ArrayPattern", + "start": 8, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + } + ] + }, + "init": { + "type": "ArrayExpression", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "elements": [ + { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + ] + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/input.js new file mode 100644 index 000000000000..ba8c8801a664 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/input.js @@ -0,0 +1,2 @@ +let + { a } = { a: 1 }; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/output.json new file mode 100644 index 000000000000..3b6eb431c234 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak-obj-dstrk/output.json @@ -0,0 +1,212 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "id": { + "type": "ObjectPattern", + "start": 8, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "init": { + "type": "ObjectExpression", + "start": 16, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/input.js b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/input.js new file mode 100644 index 000000000000..e1e10c74e656 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/input.js @@ -0,0 +1,2 @@ +let + a; diff --git a/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/output.json b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/output.json new file mode 100644 index 000000000000..53f9ebb8102c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/let/let-with-linebreak/output.json @@ -0,0 +1,86 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/input.js b/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/input.js new file mode 100644 index 000000000000..932ee841bdb3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/input.js @@ -0,0 +1,3 @@ +const A = function() { + new.target; +}; diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/output.json b/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/output.json new file mode 100644 index 000000000000..f5f3e41b514d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/expression/output.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "init": { + "type": "FunctionExpression", + "start": 10, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 25, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "expression": { + "type": "MetaProperty", + "start": 25, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "meta": { + "type": "Identifier", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 29, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/input.js new file mode 100644 index 000000000000..f13bdd7175a1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/input.js @@ -0,0 +1,3 @@ +const A = () => { + new.target; +} diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/options.json new file mode 100644 index 000000000000..4be1533d8e29 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/invalid-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "new.target can only be used in functions (2:2)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/input.js new file mode 100644 index 000000000000..a3f74c60f128 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/input.js @@ -0,0 +1 @@ +function A() { return () => new.target } diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/output.json b/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/output.json new file mode 100644 index 000000000000..447bc2741c32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/nested-arrow-function/output.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "A" + }, + "name": "A" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 15, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "argument": { + "type": "ArrowFunctionExpression", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "MetaProperty", + "start": 28, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "meta": { + "type": "Identifier", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 32, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 38 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/input.js b/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/input.js new file mode 100644 index 000000000000..70a512c677a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/input.js @@ -0,0 +1 @@ +function f() { new.ta\u0072get; } diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/options.json b/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/options.json new file mode 100644 index 000000000000..4f4b2be4c186 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/new-target-invalid-escaped-target/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The only valid meta property for new is new.target (1:19)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/input.js b/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/input.js new file mode 100644 index 000000000000..ecd7c772f6c6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/input.js @@ -0,0 +1,3 @@ +function A() { + new.target; +} diff --git a/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/output.json b/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/output.json new file mode 100644 index 000000000000..80af5ec9a8db --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/meta-properties/statement/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "A" + }, + "name": "A" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 17, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "expression": { + "type": "MetaProperty", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "meta": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "new" + }, + "name": "new" + }, + "property": { + "type": "Identifier", + "start": 21, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "target" + }, + "name": "target" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js index 01d2b22e0b82..30c0f0d29bb5 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/input.js @@ -1 +1,3 @@ +const toString = 1; + export { toString }; diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json index 190e09b28697..7d37c8dcb67b 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-builtin/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 19, "loc": { "start": { "line": 1, @@ -40,36 +40,105 @@ }, "end": { "line": 1, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "toString" + }, + "name": "toString" + }, + "init": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ], + "kind": "const" + }, + { + "type": "ExportNamedDeclaration", + "start": 21, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, "column": 20 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 17, + "start": 30, + "end": 38, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 17 } }, "local": { "type": "Identifier", - "start": 9, - "end": 17, + "start": 30, + "end": 38, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 17 }, "identifierName": "toString" @@ -78,15 +147,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 17, + "start": 30, + "end": 38, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 17 }, "identifierName": "toString" @@ -95,7 +164,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-class-declaration/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-class-declaration/options.json index da02d625454d..3bdafe893282 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-class-declaration/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-class-declaration/options.json @@ -1,4 +1,3 @@ { - "throws": - "`Foo` has already been exported. Exported identifiers must be unique. (2:0)" + "throws": "`Foo` has already been exported. Exported identifiers must be unique. (2:0)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/input.js b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/input.js new file mode 100644 index 000000000000..9e0ccdcfd313 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/input.js @@ -0,0 +1,2 @@ +export { foo }; +export const { foo = 1 } = bar; diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/options.json new file mode 100644 index 000000000000..d3d3a199e6e0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring-assignment/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "`foo` has already been exported. Exported identifiers must be unique. (2:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring10/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring10/options.json index 949358ec6eed..446a980f5409 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring10/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring10/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:20)" + "throws": "Identifier 'foo' has already been declared (2:20)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring11/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring11/options.json index 57351167b6d8..09b3fa97a0d1 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring11/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring11/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo4` has already been exported. Exported identifiers must be unique. (2:50)" + "throws": "Identifier 'foo4' has already been declared (2:50)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring12/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring12/options.json index 0e56c6bc93c2..3a7173c837e3 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring12/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring12/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo4` has already been exported. Exported identifiers must be unique. (2:49)" + "throws": "Identifier 'foo4' has already been declared (2:49)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring13/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring13/options.json index 31e5df6a02d6..d3fc42a61ba1 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring13/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring13/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo4` has already been exported. Exported identifiers must be unique. (2:58)" + "throws": "Identifier 'foo4' has already been declared (2:58)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring14/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring14/options.json index e83f7864857e..80640e0ce127 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring14/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring14/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:21)" + "throws": "Identifier 'foo' has already been declared (2:21)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring15/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring15/options.json index ec6423f048d4..ea3a9b62f493 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring15/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring15/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo2` has already been exported. Exported identifiers must be unique. (2:13)" + "throws": "Identifier 'foo2' has already been declared (2:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring16/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring16/options.json index 0e5dcf8f6136..42c862ad273a 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring16/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring16/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:22)" + "throws": "Identifier 'foo' has already been declared (2:22)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring17/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring17/options.json index ec41da52d1ef..125c2618435d 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring17/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring17/options.json @@ -1,4 +1,3 @@ { - "throws": - "`bar` has already been exported. Exported identifiers must be unique. (2:13)" + "throws": "Identifier 'bar' has already been declared (2:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring18/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring18/options.json index 6485ac8dc189..bf345ea77127 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring18/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring18/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:28)" + "throws": "Identifier 'foo' has already been declared (2:28)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring19/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring19/options.json index 8fd67e8c9c92..bf2483362193 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring19/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring19/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:29)" + "throws": "Identifier 'foo' has already been declared (2:29)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring2/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring2/options.json index 9589d0397278..2cbe06c40914 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring2/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring2/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:15)" + "throws": "Identifier 'foo' has already been declared (2:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring3/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring3/options.json index 46ee12ba139d..d36390356990 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring3/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring3/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:0)" + "throws": "Identifier 'foo' has already been declared (2:16)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring4/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring4/options.json index 96a5f1f604b3..46358493589c 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring4/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring4/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:14)" + "throws": "Identifier 'foo' has already been declared (2:14)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring5/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring5/options.json index 46ee12ba139d..d36390356990 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring5/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring5/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:0)" + "throws": "Identifier 'foo' has already been declared (2:16)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring6/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring6/options.json index 96a5f1f604b3..46358493589c 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring6/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring6/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:14)" + "throws": "Identifier 'foo' has already been declared (2:14)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring7/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring7/options.json index 9589d0397278..2cbe06c40914 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring7/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring7/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:15)" + "throws": "Identifier 'foo' has already been declared (2:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring8/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring8/options.json index 6d16161f43e1..982078d803c6 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring8/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring8/options.json @@ -1,4 +1,3 @@ { - "throws": - "`Foo` has already been exported. Exported identifiers must be unique. (2:15)" + "throws": "Identifier 'Foo' has already been declared (2:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring9/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring9/options.json index beeef9dfc6d2..f79b5469b1c0 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring9/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-destructuring9/options.json @@ -1,4 +1,3 @@ { - "throws": - "`Foo` has already been exported. Exported identifiers must be unique. (2:14)" + "throws": "Identifier 'Foo' has already been declared (2:14)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-function-declaration/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-function-declaration/options.json index 46ee12ba139d..1923e4752336 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-function-declaration/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-function-declaration/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:0)" + "throws": "`foo` has already been exported. Exported identifiers must be unique. (2:0)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-variable-declaration/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-variable-declaration/options.json index be53f65c5065..9fdf7082da17 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export-variable-declaration/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:13)" + "throws": "`foo` has already been exported. Exported identifiers must be unique. (2:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export/options.json b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export/options.json index b18b70590683..9bb46f4778eb 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/duplicate-named-export/options.json @@ -1,4 +1,3 @@ { - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:9)" + "throws": "`foo` has already been exported. Exported identifiers must be unique. (2:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration/options.json b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration/options.json index d8dbb9adfc3e..734063430a9e 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration/options.json @@ -1,4 +1,3 @@ { - "throws": - "Only expressions, functions or classes are allowed as the `default` export. (1:15)" + "throws": "Only expressions, functions or classes are allowed as the `default` export. (1:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration2/options.json b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration2/options.json index d8dbb9adfc3e..734063430a9e 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration2/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration2/options.json @@ -1,4 +1,3 @@ { - "throws": - "Only expressions, functions or classes are allowed as the `default` export. (1:15)" + "throws": "Only expressions, functions or classes are allowed as the `default` export. (1:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration3/options.json b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration3/options.json index d8dbb9adfc3e..734063430a9e 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration3/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/export-default-variable-declaration3/options.json @@ -1,4 +1,3 @@ { - "throws": - "Only expressions, functions or classes are allowed as the `default` export. (1:15)" + "throws": "Only expressions, functions or classes are allowed as the `default` export. (1:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/input.js b/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/input.js new file mode 100644 index 000000000000..0248bf7b6bd9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/input.js @@ -0,0 +1 @@ +export { if } from 'foo' diff --git a/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/output.json b/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/output.json new file mode 100644 index 000000000000..5455a5287944 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/export-from-valid-reserved-word/output.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "if" + }, + "name": "if" + }, + "exported": { + "type": "Identifier", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "if" + }, + "name": "if" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-flow/options.json b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-flow/options.json index 243fc2686d70..379fb1f86234 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-flow/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-flow/options.json @@ -1,4 +1,4 @@ { "plugins": ["flow"], - "throws": "default is a reserved word (1:9)" + "throws": "Unexpected keyword 'default' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof-flow/options.json b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof-flow/options.json index fa0493b7e1e2..cda01e8412c3 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof-flow/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof-flow/options.json @@ -1,4 +1,4 @@ { "plugins": ["flow"], - "throws": "typeof is a reserved word (1:9)" + "throws": "Unexpected keyword 'typeof' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof/options.json b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof/options.json index 0f27b53e91cb..a45cdb986dd1 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword-typeof/options.json @@ -1,3 +1,3 @@ { - "throws": "typeof is a reserved word (1:9)" + "throws": "Unexpected keyword 'typeof' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword/options.json b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword/options.json index 96dff35646b5..2c6a46df3f6e 100644 --- a/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword/options.json +++ b/packages/babel-parser/test/fixtures/es2015/modules/import-invalid-keyword/options.json @@ -1,3 +1,3 @@ { - "throws": "debugger is a reserved word (1:9)" + "throws": "Unexpected keyword 'debugger' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/input.js b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/input.js new file mode 100644 index 000000000000..bce203058944 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/input.js @@ -0,0 +1 @@ +export { X \u0061s Y } diff --git a/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/options.json b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/options.json new file mode 100644 index 000000000000..16c061d4dfd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-export-as/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token, expected \",\" (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/input.js b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/input.js new file mode 100644 index 000000000000..3f4408ab6e4c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/input.js @@ -0,0 +1 @@ +import X fro\u006d 'x' diff --git a/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/options.json b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/options.json new file mode 100644 index 000000000000..6dab969b1115 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/modules/invalid-escape-import-from/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Unexpected token (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/input.js b/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/input.js new file mode 100644 index 000000000000..f50ae43d068a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/input.js @@ -0,0 +1,4 @@ +({ + async + foo() {} +}) diff --git a/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/options.json b/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/options.json new file mode 100644 index 000000000000..978486d6a57c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/async-method-linebreak/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (3:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/input.js b/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/input.js new file mode 100644 index 000000000000..b916cd4df9b4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/input.js @@ -0,0 +1,3 @@ +({ + bar(a, a) {} +}) diff --git a/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/options.json b/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/options.json new file mode 100644 index 000000000000..c7a2c3ba50a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/disallow-duplicate-method-params/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Argument name clash (2:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/1/options.json b/packages/babel-parser/test/fixtures/es2015/shorthand/1/options.json index a618f5e2ef1b..eaa26955dc77 100644 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/1/options.json +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/1/options.json @@ -1,3 +1,3 @@ { - "throws": "const is a reserved word (1:11)" + "throws": "Unexpected keyword 'const' (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/2/options.json b/packages/babel-parser/test/fixtures/es2015/shorthand/2/options.json index 7691eb820fec..be39a4451388 100644 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/2/options.json +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/2/options.json @@ -1,3 +1,3 @@ { - "throws": "this is a reserved word (1:8)" + "throws": "Unexpected keyword 'this' (1:8)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-class/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-class/options.json index b283ca722e0c..91b308200e05 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-class/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-class/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:5)" + "throws": "Unexpected token (1:5)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-const/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-const/options.json index b283ca722e0c..a064a678e553 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-const/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-const/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:5)" + "throws": "Lexical declaration cannot appear in a single-statement context (1:5)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-async/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-async/options.json index b283ca722e0c..95aaacb458f8 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-async/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-async/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:5)" + "throws": "Async functions can only be declared at the top level or inside a block (1:5)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-generator/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-generator/options.json index b283ca722e0c..3f6e90c7cd27 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-generator/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-generator/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:5)" + "throws": "Generators can only be declared at the top level or inside a block (1:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-strict/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-strict/options.json index e54e8652f3dc..1eebe15c408e 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-strict/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-func-strict/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:35)" + "throws": "In strict mode code, functions can only be declared at top level or inside a block (1:35)" } diff --git a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-let/options.json b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-let/options.json index b283ca722e0c..e4ae9a99d01b 100644 --- a/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-let/options.json +++ b/packages/babel-parser/test/fixtures/es2015/statements/label-invalid-let/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid labeled declaration (1:5)" + "throws": "Unexpected token, expected \";\" (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/109/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/109/options.json index 715f71e32a2e..c145a86bc613 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/109/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/109/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:16)" -} + "throws": "for-of loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/123/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/123/options.json new file mode 100644 index 000000000000..fdf74cefe1b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/123/options.json @@ -0,0 +1,3 @@ +{ + "throws": "super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class? (1:40)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/123/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/123/output.json deleted file mode 100644 index 56f49a7b6964..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/123/output.json +++ /dev/null @@ -1,243 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 51, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 51 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 51, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 51 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start": 14, - "end": 51, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 51 - } - }, - "expression": { - "type": "ClassExpression", - "start": 15, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 50 - } - }, - "id": { - "type": "Identifier", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 22 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 23, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 50 - } - }, - "body": [ - { - "type": "ClassMethod", - "start": 24, - "end": 49, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 49 - } - }, - "static": false, - "key": { - "type": "Identifier", - "start": 24, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 35 - }, - "identifierName": "constructor" - }, - "name": "constructor" - }, - "computed": false, - "kind": "constructor", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 38, - "end": 49, - "loc": { - "start": { - "line": 1, - "column": 38 - }, - "end": { - "line": 1, - "column": 49 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 40, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 47 - } - }, - "expression": { - "type": "CallExpression", - "start": 40, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 47 - } - }, - "callee": { - "type": "Super", - "start": 40, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 45 - } - } - }, - "arguments": [] - } - } - ], - "directives": [] - } - } - ] - }, - "extra": { - "parenthesized": true, - "parenStart": 14 - } - } - } - ], - "directives": [ - { - "type": "Directive", - "start": 0, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "value": { - "type": "DirectiveLiteral", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "value": "use strict", - "extra": { - "raw": "\"use strict\"", - "rawValue": "use strict" - } - } - } - ] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/166/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/166/options.json new file mode 100644 index 000000000000..3481bedf3cc1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/166/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Argument name clash (1:16)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/166/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/166/output.json deleted file mode 100644 index 8f278a52ae1e..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/166/output.json +++ /dev/null @@ -1,177 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "FunctionDeclaration", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "id": { - "type": "Identifier", - "start": 9, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "x" - }, - "name": "x" - }, - "generator": false, - "async": false, - "params": [ - { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - }, - "identifierName": "a" - }, - "name": "a" - }, - { - "type": "ObjectPattern", - "start": 14, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "properties": [ - { - "type": "ObjectProperty", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "method": false, - "key": { - "type": "Identifier", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 17 - }, - "identifierName": "a" - }, - "name": "a" - }, - "computed": false, - "shorthand": true, - "value": { - "type": "Identifier", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 17 - }, - "identifierName": "a" - }, - "name": "a" - }, - "extra": { - "shorthand": true - } - } - ] - } - ], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js index 7db23de554b2..4fa5abf7ff0d 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js @@ -1,3 +1,3 @@ `\n\r\b\v\t\f\ \ -` \ No newline at end of file +\
\
` \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json index 7152cd61dec3..0dff1ff533a1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "sourceType": "script", @@ -32,7 +32,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -40,13 +40,13 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "expression": { "type": "TemplateLiteral", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -54,7 +54,7 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "expressions": [], @@ -62,7 +62,7 @@ { "type": "TemplateElement", "start": 1, - "end": 17, + "end": 21, "loc": { "start": { "line": 1, @@ -70,11 +70,11 @@ }, "end": { "line": 3, - "column": 0 + "column": 4 } }, "value": { - "raw": "\\n\\r\\b\\v\\t\\f\\\n\\\n", + "raw": "\\n\\r\\b\\v\\t\\f\\\n\\\n\\\u2028\\\u2029", "cooked": "\n\r\b\u000b\t\f" }, "tail": true @@ -85,4 +85,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/226/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/226/options.json index 2a28555f76db..74c1a72d5030 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/226/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/226/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected keyword 'default' (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/227/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/227/options.json index c83fb4f88207..6c907b0a7009 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/227/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/227/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:44)" -} + "throws": "Binding 'eval' in strict mode (1:44)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/228/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/228/options.json index 9f34dba23230..a33dde469094 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/228/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/228/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:37)" + "throws": "Argument name clash (1:37)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/229/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/229/options.json index 27a7b64d71d4..5c79fd4f4ff2 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/229/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/229/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'super' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/230/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/230/options.json index 27a7b64d71d4..8a17d90eba69 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/230/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/230/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'default' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/231/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/231/options.json index 27a7b64d71d4..8a17d90eba69 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/231/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/231/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'default' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/232/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/232/options.json index 158f0af7b450..d91e2a5bbc25 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/232/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/232/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:6)" + "throws": "Unexpected keyword 'default' (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/233/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/233/options.json index 36804413e800..178fa1e528b2 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/233/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/233/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:20)" -} + "throws": "Assigning to 'eval' in strict mode (1:20)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/234/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/234/options.json index 058a7e41389f..4ca97da7ca86 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/234/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/234/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:20)" -} + "throws": "Assigning to 'arguments' in strict mode (1:20)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/235/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/235/options.json index 715f71e32a2e..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/235/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/235/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:16)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/236/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/236/options.json index 715f71e32a2e..c145a86bc613 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/236/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/236/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:16)" -} + "throws": "for-of loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/242/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/242/options.json index f56e7311d854..02a0eafbbbbe 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/242/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/242/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Assigning to 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/243/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/243/options.json index c5e6f0e62338..e4abe279ab29 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/243/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/243/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:14)" -} + "throws": "Binding 'eval' in strict mode (1:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/244/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/244/options.json index 3168d40d55f8..c2a4aaec255e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/244/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/244/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:14)" -} + "throws": "Binding 'arguments' in strict mode (1:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/245/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/245/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/245/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/245/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/246/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/246/options.json index 0e1962195156..5d2dc563b16e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/246/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/246/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'arguments' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/247/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/247/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/247/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/247/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/248/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/248/options.json index 6d0445e20eb7..b99fd35222b1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/248/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/248/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:18)" + "throws": "Argument name clash (1:18)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/249/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/249/options.json index 0f2c1bee90b0..79a05e62290e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/249/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/249/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:21)" + "throws": "Legacy octal literals are not allowed in strict mode (1:21)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/277/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/277/options.json index 570ef651fb67..2e1b1cc3aa43 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/277/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/277/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \")\" (1:18)" + "throws": "Rest element must be last element (1:18)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/280/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/280/options.json index 0c0a9d0136e3..5cbee309bd50 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/280/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/280/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:30)" + "throws": "Argument name clash (1:30)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/281/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/281/options.json index 4773c60e5b99..8dba9882c0dc 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/281/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/281/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:47)" + "throws": "Argument name clash (1:47)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/283/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/283/options.json index 2da83bcd6f69..daa827f45cc4 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/283/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/283/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \")\" (1:5)" + "throws": "Rest element must be last element (1:5)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/289/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/289/options.json index bcd69af2d7fe..8ed5553896c1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/289/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/289/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:5)" -} + "throws": "Binding 'eval' in strict mode (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/292/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/292/input.js deleted file mode 100644 index e15ba6bf99fa..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/292/input.js +++ /dev/null @@ -1 +0,0 @@ -[...a, ] = b \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/292/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/292/output.json deleted file mode 100644 index 6a0709961325..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/292/output.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "expression": { - "type": "AssignmentExpression", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "operator": "=", - "left": { - "type": "ArrayPattern", - "start": 0, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "elements": [ - { - "type": "RestElement", - "start": 1, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 5 - } - }, - "argument": { - "type": "Identifier", - "start": 4, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - }, - "identifierName": "a" - }, - "name": "a" - } - } - ] - }, - "right": { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - }, - "identifierName": "b" - }, - "name": "b" - } - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/296/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/296/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/296/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/296/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/297/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/297/options.json index 12e8741b8a16..224716db8070 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/297/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/297/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:1)" -} + "throws": "Binding 'eval' in strict mode (1:1)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/313/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/313/output.json index a66c95114fd8..1714f8b7d8a3 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/313/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/313/output.json @@ -164,7 +164,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/328/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/328/options.json index c958665c03e2..b98beb83593e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/328/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/328/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:7)" + "throws": "Unexpected token, expected \";\" (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/329/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/329/options.json index 2a28555f76db..97818d2eea7e 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/329/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/329/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Lexical declaration cannot appear in a single-statement context (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/330/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/330/options.json deleted file mode 100644 index 89bfc2d73f8a..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/330/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:10)" -} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/332/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/332/options.json index b346a7872ac8..610884bb674c 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/332/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/332/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:18)" -} + "throws": "Assigning to 'eval' in strict mode (1:18)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/333/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/333/options.json index 46c5c8d53f1b..567e40541c5b 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/333/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/333/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:16)" + "throws": "Unexpected reserved word 'eval' (1:16)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/334/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/334/options.json index 92b68ac333f4..e45ea16ee8a4 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/334/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/334/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "eval is a reserved word in strict mode (1:4)" -} + "throws": "Assigning to 'eval' in strict mode (1:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/353/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/353/input.js deleted file mode 100644 index 727c567cc1bd..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/353/input.js +++ /dev/null @@ -1 +0,0 @@ -({ __proto__, __proto__: 2 }) \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/353/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/353/options.json deleted file mode 100644 index a8b5ad2f5b20..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/353/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:14)" -} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json index d295c5a3a3ea..c148ada0c73a 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:0)" + "throws": "Can not use keyword 'await' outside an async function (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json index dfa11a2d85f2..fa250ba921b1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:6)" + "throws": "Can not use keyword 'await' outside an async function (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json index 6a60772f964c..fd81c5071d1d 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:8)" + "throws": "Can not use keyword 'await' outside an async function (1:8)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json index e9917bc90876..a72d4ab0ff7f 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:15)" + "throws": "Can not use keyword 'await' outside an async function (1:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json index e703907857e2..18d9310bd147 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:9)" + "throws": "Can not use keyword 'await' outside an async function (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json index dfa11a2d85f2..fa250ba921b1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:6)" + "throws": "Can not use keyword 'await' outside an async function (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/368/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/368/options.json index be7cb5854a46..bd449d1a1743 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/368/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/368/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:0)" -} + "throws": "Unexpected reserved word 'enum' (1:0)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/369/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/369/options.json index 471868697d3c..a8c4888490b6 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/369/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/369/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:0)" -} + "throws": "Unexpected reserved word 'enum' (1:0)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/370/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/370/options.json index b792a5158df3..eb23932ac559 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/370/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/370/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:6)" -} + "throws": "Unexpected reserved word 'enum' (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/371/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/371/options.json index 4a7908c1fb06..caa406928d15 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/371/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/371/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:6)" -} + "throws": "Unexpected reserved word 'enum' (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/372/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/372/options.json index 67b6ff2f165c..1b022077e7c6 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/372/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/372/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:8)" -} + "throws": "Unexpected reserved word 'enum' (1:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/373/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/373/options.json index 5c2c250e155f..dd3434fd06e4 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/373/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/373/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:8)" -} + "throws": "Unexpected reserved word 'enum' (1:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/374/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/374/options.json index b10f9979f560..e8900a801461 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/374/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/374/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:15)" -} + "throws": "Unexpected reserved word 'enum' (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/375/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/375/options.json index dc427ad7ef35..8169da7d9069 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/375/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/375/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:15)" -} + "throws": "Unexpected reserved word 'enum' (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/376/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/376/options.json index 8d226ef8ec1d..24b609367ea8 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/376/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/376/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:9)" -} + "throws": "Unexpected reserved word 'enum' (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/377/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/377/options.json index cdfa39cc09b9..51b7612a6eef 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/377/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/377/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:9)" -} + "throws": "Unexpected reserved word 'enum' (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/378/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/378/options.json index b792a5158df3..eb23932ac559 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/378/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/378/options.json @@ -1,4 +1,4 @@ { "sourceType": "script", - "throws": "enum is a reserved word (1:6)" -} + "throws": "Unexpected reserved word 'enum' (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/379/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/379/options.json index 4a7908c1fb06..caa406928d15 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/379/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/379/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "enum is a reserved word (1:6)" -} + "throws": "Unexpected reserved word 'enum' (1:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/392/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/392/options.json index 3b74c452196d..9f52ab64aeef 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/392/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/392/options.json @@ -1,5 +1,4 @@ { - "throws": - "ES2015 named imports do not destructure. Use another statement for destructuring after the import. (1:19)", + "throws": "ES2015 named imports do not destructure. Use another statement for destructuring after the import. (1:19)", "sourceType": "module" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/394/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/input.js new file mode 100644 index 000000000000..d6a05dcf09c2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/input.js @@ -0,0 +1,4 @@ +var a; +(a) = {}; +(a.b) = {}; +(a['c']) = {}; diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/394/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/options.json new file mode 100644 index 000000000000..0861962d889d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/options.json @@ -0,0 +1,3 @@ +{ + "createParenthesizedExpressions": true +} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/394/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/output.json new file mode 100644 index 000000000000..3eccd63cbd63 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/394/output.json @@ -0,0 +1,392 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExpressionStatement", + "start": 7, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "operator": "=", + "left": { + "type": "ParenthesizedExpression", + "start": 7, + "end": 10, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + "right": { + "type": "ObjectExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "properties": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 17, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 17, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "operator": "=", + "left": { + "type": "ParenthesizedExpression", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "expression": { + "type": "MemberExpression", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "object": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + }, + "identifierName": "a" + }, + "name": "a" + }, + "property": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false + } + }, + "right": { + "type": "ObjectExpression", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "properties": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 29, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "operator": "=", + "left": { + "type": "ParenthesizedExpression", + "start": 29, + "end": 37, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "expression": { + "type": "MemberExpression", + "start": 30, + "end": 36, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + }, + "identifierName": "a" + }, + "name": "a" + }, + "property": { + "type": "StringLiteral", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "extra": { + "rawValue": "c", + "raw": "'c'" + }, + "value": "c" + }, + "computed": true + } + }, + "right": { + "type": "ObjectExpression", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 13 + } + }, + "properties": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/395/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/395/input.js new file mode 100644 index 000000000000..874dec75a9cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/395/input.js @@ -0,0 +1 @@ +([a.a]) => 42 \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/395/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/395/options.json new file mode 100644 index 000000000000..db72a6af957d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/395/options.json @@ -0,0 +1,4 @@ +{ + "createParenthesizedExpressions": true, + "throws": "Invalid left-hand side in arrow function parameters (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js index ebdd242449e5..bc9adbfd19cc 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/input.js @@ -1 +1,2 @@ -export { encrypt } \ No newline at end of file +export { encrypt } +function encrypt () {} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json index 6f2e67893ccb..7e4ade49890c 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/86/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 18, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 2, + "column": 22 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 41, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 2, + "column": 22 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 18 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -95,7 +94,60 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "FunctionDeclaration", + "start": 19, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "body": [], + "directives": [] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js index 04615d4b6f31..9e82122a4077 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/input.js @@ -1 +1,3 @@ -export { encrypt, decrypt } \ No newline at end of file +function encrypt () {} +class decrypt{} +export { encrypt, decrypt } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json index f7a0baef7991..28e7320743b9 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/87/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 27, + "end": 66, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 27 } }, "program": { "type": "Program", "start": 0, - "end": 27, + "end": 66, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 27 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "FunctionDeclaration", "start": 0, - "end": 27, + "end": 22, "loc": { "start": { "line": 1, @@ -40,36 +40,136 @@ }, "end": { "line": 1, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassDeclaration", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "decrypt" + }, + "name": "decrypt" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "body": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 39, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, "column": 27 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +178,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -96,29 +196,29 @@ }, { "type": "ExportSpecifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 } }, "local": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -127,15 +227,15 @@ }, "exported": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -144,7 +244,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js index 9f663623f952..1f9f9289b167 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/input.js @@ -1 +1,2 @@ -export { encrypt as default } \ No newline at end of file +import encrypt from ""; +export { encrypt as default } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json index 425419eb9509..25b0fd97418a 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/88/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 29, + "end": 53, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 29 } }, "program": { "type": "Program", "start": 0, - "end": 29, + "end": 53, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 29 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "ImportDeclaration", "start": 0, - "end": 29, + "end": 23, "loc": { "start": { "line": 1, @@ -40,36 +40,104 @@ }, "end": { "line": 1, + "column": 23 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "local": { + "type": "Identifier", + "start": 7, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "extra": { + "rawValue": "", + "raw": "\"\"" + }, + "value": "" + } + }, + { + "type": "ExportNamedDeclaration", + "start": 24, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 29 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 27, + "start": 33, + "end": 51, "loc": { "start": { - "line": 1, + "line": 2, "column": 9 }, "end": { - "line": 1, + "line": 2, "column": 27 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 33, + "end": 40, "loc": { "start": { - "line": 1, + "line": 2, "column": 9 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +146,15 @@ }, "exported": { "type": "Identifier", - "start": 20, - "end": 27, + "start": 44, + "end": 51, "loc": { "start": { - "line": 1, + "line": 2, "column": 20 }, "end": { - "line": 1, + "line": 2, "column": 27 }, "identifierName": "default" @@ -95,7 +163,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js index fec65aa2e838..f1526616e3f4 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/input.js @@ -1 +1,3 @@ -export { encrypt, decrypt as dec } \ No newline at end of file +function encrypt() {} +class decrypt {} +export { encrypt, decrypt as dec } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json index 7f1186d778ed..6e52c6fd4d1f 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/89/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 34, + "end": 73, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 34 } }, "program": { "type": "Program", "start": 0, - "end": 34, + "end": 73, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 3, "column": 34 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "FunctionDeclaration", "start": 0, - "end": 34, + "end": 21, "loc": { "start": { "line": 1, @@ -40,36 +40,136 @@ }, "end": { "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "encrypt" + }, + "name": "encrypt" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassDeclaration", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "decrypt" + }, + "name": "decrypt" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [] + } + }, + { + "type": "ExportNamedDeclaration", + "start": 39, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, "column": 34 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 } }, "local": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -78,15 +178,15 @@ }, "exported": { "type": "Identifier", - "start": 9, - "end": 16, + "start": 48, + "end": 55, "loc": { "start": { - "line": 1, + "line": 3, "column": 9 }, "end": { - "line": 1, + "line": 3, "column": 16 }, "identifierName": "encrypt" @@ -96,29 +196,29 @@ }, { "type": "ExportSpecifier", - "start": 18, - "end": 32, + "start": 57, + "end": 71, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 32 } }, "local": { "type": "Identifier", - "start": 18, - "end": 25, + "start": 57, + "end": 64, "loc": { "start": { - "line": 1, + "line": 3, "column": 18 }, "end": { - "line": 1, + "line": 3, "column": 25 }, "identifierName": "decrypt" @@ -127,15 +227,15 @@ }, "exported": { "type": "Identifier", - "start": 29, - "end": 32, + "start": 68, + "end": 71, "loc": { "start": { - "line": 1, + "line": 3, "column": 29 }, "end": { - "line": 1, + "line": 3, "column": 32 }, "identifierName": "dec" @@ -144,7 +244,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/input.js b/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/input.js new file mode 100644 index 000000000000..c1ce97544cdb --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/input.js @@ -0,0 +1,9 @@ +var yieldSet, C, iter; +function* g() { + class C_ { + get [yield]() { return 'get yield'; } + set [yield](param) { yieldSet = param; } + } + + C = C_; +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/output.json b/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/output.json new file mode 100644 index 000000000000..1082894c21d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/accessor-name-inst-computed-yield-expr/output.json @@ -0,0 +1,552 @@ +{ + "type": "File", + "start": 0, + "end": 155, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 155, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "yieldSet" + }, + "name": "yieldSet" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "C" + }, + "name": "C" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "iter" + }, + "name": "iter" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "FunctionDeclaration", + "start": 23, + "end": 155, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "g" + }, + "name": "g" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 37, + "end": 155, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 41, + "end": 142, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 47, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "C_" + }, + "name": "C_" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 50, + "end": 142, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 56, + "end": 93, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 41 + } + }, + "static": false, + "key": { + "type": "YieldExpression", + "start": 61, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "delegate": false, + "argument": null + }, + "computed": true, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 70, + "end": 93, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 41 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 72, + "end": 91, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 39 + } + }, + "argument": { + "type": "StringLiteral", + "start": 79, + "end": 90, + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 38 + } + }, + "extra": { + "rawValue": "get yield", + "raw": "'get yield'" + }, + "value": "get yield" + } + } + ], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start": 98, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 44 + } + }, + "static": false, + "key": { + "type": "YieldExpression", + "start": 103, + "end": 108, + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "delegate": false, + "argument": null + }, + "computed": true, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 110, + "end": 115, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 21 + }, + "identifierName": "param" + }, + "name": "param" + } + ], + "body": { + "type": "BlockStatement", + "start": 117, + "end": 138, + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 44 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 119, + "end": 136, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 42 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 119, + "end": 135, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 41 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 119, + "end": 127, + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 33 + }, + "identifierName": "yieldSet" + }, + "name": "yieldSet" + }, + "right": { + "type": "Identifier", + "start": 130, + "end": 135, + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 5, + "column": 41 + }, + "identifierName": "param" + }, + "name": "param" + } + } + } + ], + "directives": [] + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 146, + "end": 153, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 146, + "end": 152, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 146, + "end": 147, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + }, + "identifierName": "C" + }, + "name": "C" + }, + "right": { + "type": "Identifier", + "start": 150, + "end": 152, + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 8 + }, + "identifierName": "C_" + }, + "name": "C_" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/asi2/input.js b/packages/babel-parser/test/fixtures/es2015/yield/asi2/input.js new file mode 100644 index 000000000000..137d219c49ac --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/asi2/input.js @@ -0,0 +1,3 @@ +function *f() { yield +{}/1/g +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/asi2/output.json b/packages/babel-parser/test/fixtures/es2015/yield/asi2/output.json new file mode 100644 index 000000000000..2d86b5998e19 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/asi2/output.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 14, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "expression": { + "type": "YieldExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "delegate": false, + "argument": null + } + }, + { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "body": [], + "directives": [] + }, + { + "type": "ExpressionStatement", + "start": 24, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "expression": { + "type": "RegExpLiteral", + "start": 24, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "extra": { + "raw": "/1/g" + }, + "pattern": "1", + "flags": "g" + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js new file mode 100644 index 000000000000..49ee007baab6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js @@ -0,0 +1,3 @@ +function* wrap() { + class A {*yield() {}} +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json new file mode 100644 index 000000000000..c646340e65e3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "wrap" + }, + "name": "wrap" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 23, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 31, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 32, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "static": false, + "kind": "method", + "key": { + "type": "Identifier", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "computed": false, + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json index f14f9cb5405b..37d7f62549c6 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (2:11)" + "throws": "Can not use 'yield' as identifier inside a generator (2:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json index 9a7dc6156a16..72f8d0e0e4c3 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:11)" + "throws": "Can not use 'yield' as identifier inside a generator (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js new file mode 100644 index 000000000000..40ee514dea77 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js @@ -0,0 +1,3 @@ +function* wrap() { + ({*yield() {}}) +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json new file mode 100644 index 000000000000..6856b64eb17a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json @@ -0,0 +1,180 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "wrap" + }, + "name": "wrap" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 24, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 25, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "method": true, + "key": { + "type": "Identifier", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 23 + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict-body/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict-body/options.json index cf06e871cca3..091e7958db52 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict-body/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict-body/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'yield' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict/options.json index 18a54259fa2b..320734ea2ef7 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-strict/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (2:9)" + "throws": "Unexpected reserved word 'yield' (2:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/in-class-heritage/options.json b/packages/babel-parser/test/fixtures/es2015/yield/in-class-heritage/options.json index 7fc68d96502e..e817f30acb5c 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/in-class-heritage/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/in-class-heritage/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \"{\" (1:22)" + "throws": "Unexpected reserved word 'yield' (1:16)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/input.js b/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/input.js new file mode 100644 index 000000000000..0fcdd4ad2801 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/input.js @@ -0,0 +1,3 @@ +function* g() { + for (yield '' in {}; ; ) ; +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/options.json b/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/options.json new file mode 100644 index 000000000000..ad46a65e5082 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/in-iterator-stmt/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid left-hand side in for-in statement (2:7)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js new file mode 100644 index 000000000000..da0a10b54aec --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js @@ -0,0 +1 @@ +function *f2() { () => yield / 1 } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json new file mode 100644 index 000000000000..7b6b61f8c0b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "f2" + }, + "name": "f2" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 17, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 17, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 23, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "operator": "/", + "right": { + "type": "NumericLiteral", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-1/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-1/options.json index 7ef6a50f452a..75b3f62fdacb 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-1/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-1/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:7)" + "throws": "Yield cannot be used as name inside a generator function (2:7)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-2/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-2/options.json index f688f165a938..9d35f54190c8 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-2/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-2/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:15)" + "throws": "Yield cannot be used as name inside a generator function (2:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-3/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-3/options.json index 7ef6a50f452a..75b3f62fdacb 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-3/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-3/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:7)" + "throws": "Yield cannot be used as name inside a generator function (2:7)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-4/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-4/options.json index d1db2cc80935..b3ac060855bb 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-4/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-4/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:17)" + "throws": "Yield cannot be used as name inside a generator function (2:17)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-5/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-5/options.json index 5722b6eb30f3..379c08c57e90 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-5/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-5/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:8)" + "throws": "Yield cannot be used as name inside a generator function (2:8)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/input.js b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/input.js new file mode 100644 index 000000000000..896d8fcb5cf9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/input.js @@ -0,0 +1,3 @@ +function* fn() { + (x = (yield)) => {}; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/options.json new file mode 100644 index 000000000000..379c08c57e90 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-inside-arrow-inside-generator-6/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Yield cannot be used as name inside a generator function (2:8)" +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-strict/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-strict/options.json index 4654361314fb..ecc179f974cb 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-strict/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-default-strict/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (2:16)" + "throws": "Unexpected reserved word 'yield' (2:16)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-1/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-1/options.json index 120123c80f54..b566d4944c2c 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-1/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-1/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:3)" + "throws": "Yield cannot be used as name inside a generator function (2:3)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-2/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-2/options.json index 120123c80f54..b566d4944c2c 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-2/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-2/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:3)" + "throws": "Yield cannot be used as name inside a generator function (2:3)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-3/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-3/options.json index 46a75b41eb84..479a9a79f900 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-3/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-arrow-inside-generator-3/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (2:9)" + "throws": "Yield cannot be used as name inside a generator function (2:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json index 9a7dc6156a16..72f8d0e0e4c3 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:11)" + "throws": "Can not use 'yield' as identifier inside a generator (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json index 6cd6ffe02ca9..dcab4205d32f 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:13)" + "throws": "Can not use 'yield' as identifier inside a generator (1:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict-body/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict-body/options.json index 37e79f9fb8c7..cb8efaaa0aff 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict-body/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict-body/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:12)" -} + "throws": "Binding 'yield' in strict mode (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict/options.json index e65626183cd2..75bdf3d53d6e 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-strict/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (2:12)" + "throws": "Unexpected reserved word 'yield' (2:12)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield class/input.js b/packages/babel-parser/test/fixtures/es2015/yield/yield class/input.js new file mode 100644 index 000000000000..ea7121a71eae --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield class/input.js @@ -0,0 +1 @@ +function* bar() { yield class {} } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield class/output.json b/packages/babel-parser/test/fixtures/es2015/yield/yield class/output.json new file mode 100644 index 000000000000..e4526ece7675 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield class/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "YieldExpression", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "delegate": false, + "argument": { + "type": "ClassExpression", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "body": [] + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js new file mode 100644 index 000000000000..79676acd5f12 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js @@ -0,0 +1 @@ +var yield = 2 diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json new file mode 100644 index 000000000000..b0139b0da807 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "init": { + "type": "NumericLiteral", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/10/options.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/10/options.json index 73054f4644b0..2c624e8cec70 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/10/options.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/10/options.json @@ -1,4 +1,3 @@ { - "throws": - "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:1)" + "throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:1)" } diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/11/options.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/11/options.json index f6d96ba3a1f7..f04c5c035abb 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/11/options.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/11/options.json @@ -1,4 +1,3 @@ { - "throws": - "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" + "throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" } diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/12/options.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/12/options.json index f6d96ba3a1f7..f04c5c035abb 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/12/options.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/12/options.json @@ -1,4 +1,3 @@ { - "throws": - "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" + "throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" } diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/input.js b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/input.js new file mode 100644 index 000000000000..63fce35a8a19 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/input.js @@ -0,0 +1 @@ +-(5) ** 6; diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/options.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/options.json new file mode 100644 index 000000000000..c694133bf2b1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/15/options.json @@ -0,0 +1,4 @@ +{ + "createParenthesizedExpressions": true, + "throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/input.js b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/input.js new file mode 100644 index 000000000000..47b91d35a849 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/input.js @@ -0,0 +1 @@ +(-5 ** 6); diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/options.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/options.json new file mode 100644 index 000000000000..19687fbe197a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/16/options.json @@ -0,0 +1,4 @@ +{ + "createParenthesizedExpressions": true, + "throws": "Illegal expression. Wrap left hand side or entire exponentiation in parentheses. (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/2/output.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/2/output.json index e4e9ecd32a5d..e840aecbd18a 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/2/output.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/2/output.json @@ -124,4 +124,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/7/output.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/7/output.json index c4f295eacffd..2fb85f363b06 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/7/output.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/7/output.json @@ -160,4 +160,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/8/output.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/8/output.json index fd863ac0f6f6..56c71d7d2533 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/8/output.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/8/output.json @@ -156,4 +156,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/9/output.json b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/9/output.json index c3f4e42e1c0c..2691c6433738 100644 --- a/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/9/output.json +++ b/packages/babel-parser/test/fixtures/es2016/exponentiation-operator/9/output.json @@ -124,4 +124,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json index 2e6ae0771c86..089b542c3704 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:9)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:8)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json index 0c31636171e0..089b542c3704 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:15)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:8)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-function/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-function/options.json index ff8a46ae1aec..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-function/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/async-function/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:17)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/default/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/default/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/default/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/default/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-function/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-function/options.json index 65ff709b5f39..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-function/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-function/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:12)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-method/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-method/options.json index dd467e6578aa..9908b496fd2a 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-method/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/generator-method/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (2:6)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (2:5)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/method/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/method/options.json index ac620235e917..5d0e394f2b9d 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/method/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/method/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (2:4)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (2:3)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/rest/options.json b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/rest/options.json index 5a257f4e5d33..12b18792fcc4 100644 --- a/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/rest/options.json +++ b/packages/babel-parser/test/fixtures/es2016/simple-parameter-list/rest/options.json @@ -1,3 +1,3 @@ { - "throws": "Non-simple parameter in strict mode (1:11)" + "throws": "Illegal 'use strict' directive in function with non-simple parameter list (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/2/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/2/options.json index 1525fbf2506c..c6f19067ee66 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/2/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/2/options.json @@ -1,4 +1,3 @@ { - "throws": - "await* has been removed from the async functions proposal. Use Promise.all() instead. (2:2)" + "throws": "await* has been removed from the async functions proposal. Use Promise.all() instead. (2:2)" } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/input.js new file mode 100644 index 000000000000..60b70d4a68e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/input.js @@ -0,0 +1 @@ +async function await() {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/output.json new file mode 100644 index 000000000000..2d128072e784 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-declaration-name/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "await" + }, + "name": "await" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/input.js new file mode 100644 index 000000000000..5102f04c3f84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/input.js @@ -0,0 +1 @@ +(async function await() {}); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json new file mode 100644 index 000000000000..022428647fee --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can not use 'await' as identifier inside an async function (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/input.js new file mode 100644 index 000000000000..1df99191e510 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/input.js @@ -0,0 +1,3 @@ +async function foo() { + function await() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json new file mode 100644 index 000000000000..d45274982dc1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can not use 'await' as identifier inside an async function (2:11)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/input.js new file mode 100644 index 000000000000..97183151654b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/input.js @@ -0,0 +1,3 @@ +async function fn() { + (function await() {}); +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/output.json new file mode 100644 index 000000000000..701abef485a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-expression-name-inside-async-function/output.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 24, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 25, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "await" + }, + "name": "await" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "body": [], + "directives": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 24 + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/input.js new file mode 100644 index 000000000000..ec2205553408 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/input.js @@ -0,0 +1,3 @@ +async function fn() { + function g(x = await) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/output.json new file mode 100644 index 000000000000..1ad9f719af7c --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-identifier-inside-parameters-of-nested-function/output.json @@ -0,0 +1,190 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "FunctionDeclaration", + "start": 24, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "g" + }, + "name": "g" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 35, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "Identifier", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "await" + }, + "name": "await" + } + } + ], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/input.js new file mode 100644 index 000000000000..b27b79ef4ae1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/input.js @@ -0,0 +1,3 @@ +async function fn() { + async (x = async(y = await 2)) => {}; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/options.json new file mode 100644 index 000000000000..9a4cb65743b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-call-inside-parameters-of-async-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Await cannot be used as name inside an async function (2:23)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/input.js new file mode 100644 index 000000000000..d41288f1156b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/input.js @@ -0,0 +1,3 @@ +async function fn() { + async(x = await 2); +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/output.json new file mode 100644 index 000000000000..39c5735ec936 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arguments-of-async-function-call/output.json @@ -0,0 +1,205 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 24, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "expression": { + "type": "CallExpression", + "start": 24, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "callee": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "async" + }, + "name": "async" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 30, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "AwaitExpression", + "start": 34, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "argument": { + "type": "NumericLiteral", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + ] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/input.js new file mode 100644 index 000000000000..5f0476d83191 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/input.js @@ -0,0 +1 @@ +() => { await x } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/options.json new file mode 100644 index 000000000000..6079f56395bd --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:14)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/input.js new file mode 100644 index 000000000000..cbc9d51ace79 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/input.js @@ -0,0 +1 @@ +() => { await } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/options.json new file mode 100644 index 000000000000..b412ffe6712f --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "script" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/output.json new file mode 100644 index 000000000000..f6ca7cfa0d20 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-arrow-identifier-allowed/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 6, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "Identifier", + "start": 8, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "await" + }, + "name": "await" + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/input.js new file mode 100644 index 000000000000..f137977faf1d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/input.js @@ -0,0 +1 @@ +async (x = await 2) => {}; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/options.json new file mode 100644 index 000000000000..ceaee67ee6b4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:17)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/input.js new file mode 100644 index 000000000000..39aea232a5ce --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/input.js @@ -0,0 +1,3 @@ +async function fn() { + (x = await 2) => {}; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/options.json new file mode 100644 index 000000000000..7cec39290c2a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Await cannot be used as name inside an async function (2:7)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/input.js new file mode 100644 index 000000000000..7571a193f836 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/input.js @@ -0,0 +1,3 @@ +async function fn() { + async (x = await 2) => {}; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/options.json new file mode 100644 index 000000000000..b45bba7cab4a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-async-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Await cannot be used as name inside an async function (2:13)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/input.js new file mode 100644 index 000000000000..f9a4ebddb333 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/input.js @@ -0,0 +1,3 @@ +async function foo() { + function bar(x = await 2) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/options.json new file mode 100644 index 000000000000..b260169ecd70 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters-of-nested-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (2:25)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/input.js new file mode 100644 index 000000000000..52459e1a27a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/input.js @@ -0,0 +1 @@ +async function fn(x = await 2) {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/options.json new file mode 100644 index 000000000000..f4af75f31164 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parameters/options.json @@ -0,0 +1,3 @@ +{ + "throws": "await is not allowed in async function parameters (1:22)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/input.js new file mode 100644 index 000000000000..fd46caa54ce3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/input.js @@ -0,0 +1,3 @@ +async function fn() { + (x = await 2); +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/output.json new file mode 100644 index 000000000000..76cec56e0208 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-inside-parenthesized-assign/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 24, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 25, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "AwaitExpression", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "argument": { + "type": "NumericLiteral", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + }, + "extra": { + "parenthesized": true, + "parenStart": 24 + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/export-invalid/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/export-invalid/options.json index 5da632286fbb..758834b289e0 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/export-invalid/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/export-invalid/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "Unexpected token, expected \"function\" (1:21)" + "throws": "Unexpected token, expected \"=>\" (1:31)" } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/input.js new file mode 100644 index 000000000000..4dd0cd76e362 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/input.js @@ -0,0 +1 @@ +class X { \u0061sync x() { await x } } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/options.json new file mode 100644 index 000000000000..b81bee7fa2e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-class-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:21)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/input.js new file mode 100644 index 000000000000..0807ff125175 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/input.js @@ -0,0 +1 @@ +({ \u0061sync x() { await x } }) diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/options.json new file mode 100644 index 000000000000..f0907a448458 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-obj-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/input.js new file mode 100644 index 000000000000..a5b20dfebcfe --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/input.js @@ -0,0 +1 @@ +class X { static \u0061sync x() { await x } } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/options.json new file mode 100644 index 000000000000..f55830c1c373 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-async-static-class-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:28)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/input.js new file mode 100644 index 000000000000..824b1c37725b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/input.js @@ -0,0 +1 @@ +(async function() { aw\u0061it x }) diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/options.json new file mode 100644 index 000000000000..ac6c5914cec6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-await/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Can not use 'await' as identifier inside an async function (1:20)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/input.js new file mode 100644 index 000000000000..0d2ad1b32309 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/input.js @@ -0,0 +1 @@ +export \u0061sync function y() { await x } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/options.json new file mode 100644 index 000000000000..9d60866b80c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-async-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \"{\" (1:7)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/input.js new file mode 100644 index 000000000000..d14f4188a0b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/input.js @@ -0,0 +1 @@ +export default \u0061sync function y() { await x } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/options.json new file mode 100644 index 000000000000..b0e5516212f3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-export-dflt-async-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:26)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/input.js new file mode 100644 index 000000000000..55506a887224 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/input.js @@ -0,0 +1 @@ +(\u0061sync x => { await x }) diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/options.json new file mode 100644 index 000000000000..0cd822570731 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow-list/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/input.js new file mode 100644 index 000000000000..1989072f30de --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/input.js @@ -0,0 +1 @@ +\u0061sync x => { await x } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/options.json new file mode 100644 index 000000000000..f6eb197b1dd8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-arrow/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/input.js new file mode 100644 index 000000000000..978637393061 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/input.js @@ -0,0 +1 @@ +(\u0061sync function() { await x }) diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/options.json new file mode 100644 index 000000000000..0cd822570731 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function-list/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/input.js new file mode 100644 index 000000000000..a44cfbb62d1a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/input.js @@ -0,0 +1 @@ +\u0061sync function() { await x } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/options.json new file mode 100644 index 000000000000..f6eb197b1dd8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-escape-sequence-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/input.js new file mode 100644 index 000000000000..c519d6ea261a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/input.js @@ -0,0 +1 @@ +while (1) async function foo(){} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/options.json new file mode 100644 index 000000000000..4bcd823e98be --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-inside-loop/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Async functions can only be declared at the top level or inside a block (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/input.js new file mode 100644 index 000000000000..52a0795cf08a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/input.js @@ -0,0 +1,2 @@ +async (x) +=> {} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/options.json new file mode 100644 index 000000000000..0361d7c7d2b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-newline-after-params/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:0)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/input.js new file mode 100644 index 000000000000..33dbaaa09e00 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/input.js @@ -0,0 +1 @@ +(async)(a) => {} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/options.json new file mode 100644 index 000000000000..f6eb197b1dd8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-arrow/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/input.js new file mode 100644 index 000000000000..0af564cef72b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/input.js @@ -0,0 +1 @@ +(async) function x (a) {} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/options.json new file mode 100644 index 000000000000..c2fcdb08cf9f --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/invalid-parens-async-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \";\" (1:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/input.js b/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/input.js new file mode 100644 index 000000000000..200a1447669b --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/input.js @@ -0,0 +1,2 @@ +async +x => x diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/output.json new file mode 100644 index 000000000000..4c44c118638d --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/newline-arrow/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "async" + }, + "name": "async" + } + }, + { + "type": "ExpressionStatement", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/no-method-asi/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/no-method-asi/options.json index f3c78ddb4f02..7348c12f9e90 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/no-method-asi/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/no-method-asi/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'classProperties' (3:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'classProperties' (3:2)" } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/params-invalid-rest-trailing-comma/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/params-invalid-rest-trailing-comma/options.json index 52560b0a85b7..f686fb60b45e 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/params-invalid-rest-trailing-comma/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/params-invalid-rest-trailing-comma/options.json @@ -1,3 +1,3 @@ { - "throws": "A trailing comma is not permitted after the rest element (1:11)" + "throws": "Rest element must be last element (1:11)" } diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-2/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-2/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/class-method-2/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/class-method-2/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-2/output.json b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-2/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/class-method-2/output.json rename to packages/babel-parser/test/fixtures/es2018/async-generators/class-method-2/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-no-asi/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-no-asi/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/class-method-no-asi/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/class-method-no-asi/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-no-asi/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-no-asi/options.json new file mode 100644 index 000000000000..7348c12f9e90 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method-no-asi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'classProperties' (3:2)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/class-method/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/class-method/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method/output.json b/packages/babel-parser/test/fixtures/es2018/async-generators/class-method/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/class-method/output.json rename to packages/babel-parser/test/fixtures/es2018/async-generators/class-method/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-async-context/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-async-context/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-async-context/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-async-context/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-async-context/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-async-context/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-async-context/options.json rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-async-context/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-in/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-in/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-in/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-in/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-in/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-in/options.json new file mode 100644 index 000000000000..f86bbd48e917 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-in/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-1/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-1/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-1/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-1/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-1/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-1/options.json new file mode 100644 index 000000000000..9660494a29ea --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-2/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-2/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-2/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-2/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-2/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-2/options.json new file mode 100644 index 000000000000..9660494a29ea --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-3/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-3/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-3/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-3/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-3/options.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-3/options.json new file mode 100644 index 000000000000..9660494a29ea --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await-no-semi-3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await/output.json b/packages/babel-parser/test/fixtures/es2018/async-generators/for-await/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/for-await/output.json rename to packages/babel-parser/test/fixtures/es2018/async-generators/for-await/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/object-method/input.js b/packages/babel-parser/test/fixtures/es2018/async-generators/object-method/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/object-method/input.js rename to packages/babel-parser/test/fixtures/es2018/async-generators/object-method/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/object-method/output.json b/packages/babel-parser/test/fixtures/es2018/async-generators/object-method/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/async-generators/object-method/output.json rename to packages/babel-parser/test/fixtures/es2018/async-generators/object-method/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/1/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/1/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/1/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/1/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/1/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/1/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/1/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/1/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/10/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/10/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/10/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/10/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/10/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/10/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/10/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/10/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/11/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/11/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/11/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/11/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/11/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/11/options.json new file mode 100644 index 000000000000..6dad74eebd16 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/11/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'foo' has already been declared (2:23)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/12/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/12/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/12/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/12/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/12/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/12/options.json new file mode 100644 index 000000000000..165223a448a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/12/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'bar' has already been declared (2:13)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/13/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/13/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/13/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/13/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/13/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/13/options.json new file mode 100644 index 000000000000..68df28e41c41 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/13/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'foo' has already been declared (2:30)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/14/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/14/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/14/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/14/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/14/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/14/options.json new file mode 100644 index 000000000000..280073b140f0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/14/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'foo' has already been declared (2:29)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/15/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/15/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/15/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/15/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/15/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/15/options.json new file mode 100644 index 000000000000..68df28e41c41 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/15/options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "throws": "Identifier 'foo' has already been declared (2:30)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/16/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/16/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/16/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/16/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0033/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/16/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0033/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/16/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/17/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/17/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/17/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/17/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0108/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/17/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0108/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/17/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/18/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/18/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/18/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/18/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/18/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/18/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/18/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/18/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/19/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/19/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/19/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/19/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0041/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/19/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0041/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/19/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/2/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/2/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/2/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/2/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/2/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/2/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/2/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/2/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/20/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/20/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/20/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/20/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0044/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/20/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0044/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/20/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/21/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/21/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/21/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/21/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/21/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/21/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/21/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/21/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/22/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/22/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/22/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/22/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/22/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/22/options.json new file mode 100644 index 000000000000..08b79c43d6cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/22/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/23/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/23/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/23/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/23/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/23/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/23/options.json new file mode 100644 index 000000000000..81e7a97e3f7e --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/23/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:20)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/24/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/24/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/24/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/24/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/24/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/24/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/24/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/24/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/25/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/25/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/25/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/25/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0034/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/25/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0034/options.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/25/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/26/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/26/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/26/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/26/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/26/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/26/options.json new file mode 100644 index 000000000000..b8b06c3a03ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/26/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:18)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/3/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/3/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/3/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/3/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/3/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/3/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/3/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/3/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/4/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/4/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/4/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/4/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/4/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/4/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/4/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/4/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/5/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/5/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/5/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/5/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/5/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/5/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/5/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/5/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/6/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/6/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/6/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/6/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/6/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/6/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/6/output.json rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/6/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/7/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/7/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/7/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/7/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/7/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/7/options.json new file mode 100644 index 000000000000..b86f80dc4a72 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/7/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/8/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/8/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/8/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/8/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/8/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/8/options.json new file mode 100644 index 000000000000..c49db16e2821 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/8/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/9/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/9/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/9/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/9/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/9/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/9/options.json new file mode 100644 index 000000000000..e9effa60cb30 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/9/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/input.js new file mode 100644 index 000000000000..aef29a7f3bb7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/input.js @@ -0,0 +1 @@ +({...a,} = {}); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/options.json new file mode 100644 index 000000000000..935d087d7ee5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-rest/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:6)" +} diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/input.js new file mode 100644 index 000000000000..d8dd574f40cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/input.js @@ -0,0 +1 @@ +({...a,}); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/output.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/output.json new file mode 100644 index 000000000000..ffb978345c27 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/comma-after-spread/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "properties": [ + { + "type": "SpreadElement", + "start": 2, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "argument": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/expression-rest-not-last-invalid/input.js b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/expression-rest-not-last-invalid/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/object-rest-spread/expression-rest-not-last-invalid/input.js rename to packages/babel-parser/test/fixtures/es2018/object-rest-spread/expression-rest-not-last-invalid/input.js diff --git a/packages/babel-parser/test/fixtures/es2018/object-rest-spread/expression-rest-not-last-invalid/options.json b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/expression-rest-not-last-invalid/options.json new file mode 100644 index 000000000000..b708967fd223 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2018/object-rest-spread/expression-rest-not-last-invalid/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Rest element must be last element (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-line-separator/input.js b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-line-separator/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/json-strings/directive-line-separator/input.js rename to packages/babel-parser/test/fixtures/es2019/json-strings/directive-line-separator/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/json-strings/directive-line-separator/output.json b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-line-separator/output.json new file mode 100644 index 000000000000..8bf9f02e8706 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-line-separator/output.json @@ -0,0 +1,106 @@ +{ + "type": "File", + "start": 0, + "end": 98, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 82 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 98, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 82 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": "before
after", + "extra": { + "raw": "\"before
after\"", + "rawValue": "before
after" + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 16, + "end": 98, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 82 + } + } + } + ] + } + ] + }, + "comments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 16, + "end": 98, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 82 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-paragraph-separator/input.js b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-paragraph-separator/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/json-strings/directive-paragraph-separator/input.js rename to packages/babel-parser/test/fixtures/es2019/json-strings/directive-paragraph-separator/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/json-strings/directive-paragraph-separator/output.json b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-paragraph-separator/output.json new file mode 100644 index 000000000000..f83d867447e7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/json-strings/directive-paragraph-separator/output.json @@ -0,0 +1,106 @@ +{ + "type": "File", + "start": 0, + "end": 103, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 87 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 103, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 87 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": "before
after", + "extra": { + "raw": "\"before
after\"", + "rawValue": "before
after" + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 16, + "end": 103, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 87 + } + } + } + ] + } + ] + }, + "comments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 16, + "end": 103, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 87 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/string-line-separator/input.js b/packages/babel-parser/test/fixtures/es2019/json-strings/string-line-separator/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/json-strings/string-line-separator/input.js rename to packages/babel-parser/test/fixtures/es2019/json-strings/string-line-separator/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/json-strings/string-line-separator/output.json b/packages/babel-parser/test/fixtures/es2019/json-strings/string-line-separator/output.json new file mode 100644 index 000000000000..388733cc206a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/json-strings/string-line-separator/output.json @@ -0,0 +1,108 @@ +{ + "type": "File", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 83 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 101, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 83 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "expression": { + "type": "StringLiteral", + "start": 1, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "before
after", + "raw": "\"before
after\"", + "parenthesized": true, + "parenStart": 0 + }, + "value": "before
after" + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 18, + "end": 101, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 83 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 18, + "end": 101, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 83 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/string-paragraph-separator/input.js b/packages/babel-parser/test/fixtures/es2019/json-strings/string-paragraph-separator/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/json-strings/string-paragraph-separator/input.js rename to packages/babel-parser/test/fixtures/es2019/json-strings/string-paragraph-separator/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/json-strings/string-paragraph-separator/output.json b/packages/babel-parser/test/fixtures/es2019/json-strings/string-paragraph-separator/output.json new file mode 100644 index 000000000000..a482ccfb266a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/json-strings/string-paragraph-separator/output.json @@ -0,0 +1,108 @@ +{ + "type": "File", + "start": 0, + "end": 106, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 88 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 106, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 88 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "expression": { + "type": "StringLiteral", + "start": 1, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": "before
after", + "raw": "\"before
after\"", + "parenthesized": true, + "parenStart": 0 + }, + "value": "before
after" + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 18, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 88 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", + "start": 18, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 88 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding-finally/input.js b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding-finally/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding-finally/input.js rename to packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding-finally/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding-finally/output.json b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding-finally/output.json new file mode 100644 index 000000000000..564ba035b454 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding-finally/output.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 9, + "end": 19, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "param": null, + "body": { + "type": "BlockStatement", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [], + "directives": [] + } + }, + "finalizer": { + "type": "BlockStatement", + "start": 28, + "end": 34, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding/input.js b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding/input.js rename to packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding/input.js diff --git a/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding/output.json b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding/output.json new file mode 100644 index 000000000000..0948185b8e4e --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2019/optional-catch-binding/no-binding/output.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 9, + "end": 21, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "param": null, + "body": { + "type": "BlockStatement", + "start": 15, + "end": 21, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/declaration-function/dupe-param/options.json b/packages/babel-parser/test/fixtures/esprima/declaration-function/dupe-param/options.json index e23388601bb0..8b20b9a7df36 100644 --- a/packages/babel-parser/test/fixtures/esprima/declaration-function/dupe-param/options.json +++ b/packages/babel-parser/test/fixtures/esprima/declaration-function/dupe-param/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:14)" + "throws": "Argument name clash (1:14)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-binding-pattern/invalid-dup-param/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-binding-pattern/invalid-dup-param/options.json index 34197d2efee7..a4a6e207d28c 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-binding-pattern/invalid-dup-param/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-binding-pattern/invalid-dup-param/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:11)" + "throws": "Argument name clash (1:11)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-1/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-1/options.json index d498cd8bd087..49e8d8e86314 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-1/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-1/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (2:14)" + "throws": "Argument name clash (2:14)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-2/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-2/options.json index e3176a8e57eb..3829082a4878 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-2/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-2/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (2:17)" + "throws": "Argument name clash (2:17)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-3/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-3/options.json index 2d74a95450d0..782073313a19 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-3/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/dupe-param-3/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (2:19)" + "throws": "Argument name clash (2:19)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/empty-pattern-catch-param/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/empty-pattern-catch-param/output.json index 3074e479af9d..91b847669991 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/empty-pattern-catch-param/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/empty-pattern-catch-param/output.json @@ -108,7 +108,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/input.js deleted file mode 100644 index 417d6fc8492f..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/input.js +++ /dev/null @@ -1 +0,0 @@ -try {} catch ([a,a]) {} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/options.json deleted file mode 100644 index 7d5bec6e9b7b..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch-dupe/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Argument name clash in strict mode (1:17)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch/output.json index 3dd5d0d3ca93..48dd0332f9cd 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/patterned-catch/output.json @@ -476,7 +476,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param/output.json index 7a2f7e482fae..3ea9eda80fdc 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-array-pattern/with-default-catch-param/output.json @@ -161,7 +161,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/arrow-with-multiple-rest/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/arrow-with-multiple-rest/options.json index 2da83bcd6f69..daa827f45cc4 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/arrow-with-multiple-rest/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/arrow-with-multiple-rest/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \")\" (1:5)" + "throws": "Rest element must be last element (1:5)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/complex-rest-in-arrow-not-allowed/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/complex-rest-in-arrow-not-allowed/options.json index 4ebe77e8fc2b..fd74c5228531 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/complex-rest-in-arrow-not-allowed/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/complex-rest-in-arrow-not-allowed/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:7)" + "throws": "Argument name clash (1:7)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-duplicated-params/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-duplicated-params/options.json index 0590c2b7e6bf..368006ae58bd 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-duplicated-params/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-duplicated-params/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:4)" + "throws": "Argument name clash (1:4)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-param-strict-mode/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-param-strict-mode/options.json index e0027065afb7..2e6d7156cf57 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-param-strict-mode/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/invalid-param-strict-mode/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:0)" -} + "throws": "Binding 'eval' in strict mode (1:0)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/object-binding-pattern-01.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-01/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/object-binding-pattern-01.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-01/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-01/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-01/output.json new file mode 100644 index 000000000000..04622ffb5ea7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-01/output.json @@ -0,0 +1,370 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "left": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "b" + }, + "name": "b" + }, + "right": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 8, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "c" + }, + "name": "c" + } + }, + { + "type": "ObjectProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "computed": true, + "key": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "a" + }, + "name": "a" + }, + "shorthand": false, + "value": { + "type": "ArrayPattern", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "d" + }, + "name": "d" + } + ] + } + } + ] + } + ], + "body": { + "type": "NumericLiteral", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/object-binding-pattern-empty.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-empty/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/object-binding-pattern-empty.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-empty/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-empty/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-empty/output.json new file mode 100644 index 000000000000..6a745736a149 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-empty/output.json @@ -0,0 +1,106 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "properties": [] + } + ], + "body": { + "type": "NumericLiteral", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-member-expr.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-member-expr/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-member-expr.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-member-expr/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-member-expr/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-member-expr/options.json new file mode 100644 index 000000000000..bf0f292caad2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-member-expr/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid left-hand side in object destructuring pattern (1:4)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-method-in-pattern.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-method-in-pattern/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-method-in-pattern.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-method-in-pattern/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-method-in-pattern/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-method-in-pattern/options.json new file mode 100644 index 000000000000..559cc4e11a41 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-method-in-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Object pattern can't contain getter or setter (1:6)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-nested-param.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-nested-param/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-nested-param.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-nested-param/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-nested-param/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-nested-param/options.json new file mode 100644 index 000000000000..30f209db8f07 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-nested-param/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid left-hand side in object destructuring pattern (1:24)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-pattern-without-parenthesis.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-pattern-without-parenthesis/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-pattern-without-parenthesis.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-pattern-without-parenthesis/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-pattern-without-parenthesis/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-pattern-without-parenthesis/options.json new file mode 100644 index 000000000000..e24c4dce39b6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-pattern-without-parenthesis/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:3)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-rest-in-object-pattern.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-rest-in-object-pattern/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-rest-in-object-pattern.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-rest-in-object-pattern/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-rest-in-object-pattern/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-rest-in-object-pattern/output.json new file mode 100644 index 000000000000..7061f23c0fb3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-invalid-rest-in-object-pattern/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestElement", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "argument": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ] + } + ], + "body": { + "type": "NumericLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/nested-cover-grammar.js b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-nested-cover-grammar/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/nested-cover-grammar.js rename to packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-nested-cover-grammar/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-nested-cover-grammar/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-nested-cover-grammar/output.json new file mode 100644 index 000000000000..81e10cda57c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern-nested-cover-grammar/output.json @@ -0,0 +1,534 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 1, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 2, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 3, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 4, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 5, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 6, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 7, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 8, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 9, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 10, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 11, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 12, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 13, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 14, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 15, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 16, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 17, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 18, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "elements": [ + { + "type": "ArrayPattern", + "start": 20, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "elements": [ + { + "type": "ObjectPattern", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "left": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ], + "body": { + "type": "NumericLiteral", + "start": 49, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-member-expr.failure.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-member-expr.failure.json deleted file mode 100755 index 8245542d3dc4..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-member-expr.failure.json +++ /dev/null @@ -1 +0,0 @@ -{"index":10,"lineNumber":1,"column":11,"message":"Error: Line 1: Unexpected token =>","description":"Unexpected token =>"} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-method-in-pattern.failure.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-method-in-pattern.failure.json deleted file mode 100755 index 030f8f3752df..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-method-in-pattern.failure.json +++ /dev/null @@ -1 +0,0 @@ -{"index":14,"lineNumber":1,"column":15,"message":"Error: Line 1: Unexpected token =>","description":"Unexpected token =>"} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-nested-param.failure.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-nested-param.failure.json deleted file mode 100755 index 08ba5aca74a1..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-nested-param.failure.json +++ /dev/null @@ -1 +0,0 @@ -{"index":50,"lineNumber":1,"column":51,"message":"Error: Line 1: Unexpected token =>","description":"Unexpected token =>"} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-pattern-without-parenthesis.failure.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-pattern-without-parenthesis.failure.json deleted file mode 100755 index b0c1b45f778c..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-pattern-without-parenthesis.failure.json +++ /dev/null @@ -1 +0,0 @@ -{"index":3,"lineNumber":1,"column":4,"message":"Error: Line 1: Unexpected token =>","description":"Unexpected token =>"} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-rest-in-object-pattern.failure.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-rest-in-object-pattern.failure.json deleted file mode 100755 index 6551a4757991..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/invalid-rest-in-object-pattern.failure.json +++ /dev/null @@ -1 +0,0 @@ -{"index":4,"lineNumber":1,"column":5,"message":"Error: Line 1: Unexpected token ...","description":"Unexpected token ..."} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/output.json deleted file mode 100644 index 145f80b57b91..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-arrow-function/object-binding-pattern/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js index 5d32a24de0a9..974ab55e4371 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/input.js @@ -1 +1,2 @@ export {foo as default}; +var foo; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json index c3d6819265c2..ab9dd47bd5f1 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-default/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 24, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 24 + "line": 2, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 24, + "end": 33, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 24 + "line": 2, + "column": 8 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 24 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -95,7 +94,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 25, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js index e7820a6f027c..1d873bf86024 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/input.js @@ -1 +1,2 @@ +var foo, bar; export {foo as bar}; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json index e1652693b14f..0b8670ce2ef3 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 34, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 34, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 13, "loc": { "start": { "line": 1, @@ -40,36 +40,119 @@ }, "end": { "line": 1, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 20 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 8, - "end": 18, + "start": 22, + "end": 32, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 18 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +161,15 @@ }, "exported": { "type": "Identifier", - "start": 15, - "end": 18, + "start": 29, + "end": 32, "loc": { "start": { - "line": 1, + "line": 2, "column": 15 }, "end": { - "line": 1, + "line": 2, "column": 18 }, "identifierName": "bar" @@ -95,7 +178,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js index ff57927839e8..f0218dfca8ab 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/input.js @@ -1 +1,2 @@ export {foo as default, bar}; +var foo, bar; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json index 8114c32e2924..2a876f042ed1 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-as-specifiers/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 29, + "end": 43, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 29 + "line": 2, + "column": 13 } }, "program": { "type": "Program", "start": 0, - "end": 29, + "end": 43, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 29 + "line": 2, + "column": 13 } }, "sourceType": "module", @@ -43,7 +43,6 @@ "column": 29 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -144,7 +143,92 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 30, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js index df5f5e609e93..1c36f4346199 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/input.js @@ -1 +1,2 @@ +let foo; export {foo}; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json index 49c37926ad3c..4faa60a28feb 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 13, + "end": 22, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 13 } }, "program": { "type": "Program", "start": 0, - "end": 13, + "end": 22, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 13 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 13, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 13 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -95,7 +145,8 @@ } } ], - "source": null + "source": null, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js index 61bc40fd77ea..12c55903d5e5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/input.js @@ -1 +1,3 @@ +var bar; export {foo, bar,}; +var foo; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json index 0c439126a9ac..3616570c157d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers-comma/output.json @@ -1,38 +1,38 @@ { "type": "File", "start": 0, - "end": 19, + "end": 37, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 19 + "line": 3, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 19, + "end": 37, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 19 + "line": 3, + "column": 8 } }, "sourceType": "module", "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 19, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 19 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -96,29 +146,29 @@ }, { "type": "ExportSpecifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 } }, "local": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -127,15 +177,15 @@ }, "exported": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -144,7 +194,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 29, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js index fdbc94275097..8e2977a9e757 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/input.js @@ -1 +1,3 @@ +var foo; export {foo, bar}; +var bar; diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json index b28aaf0d65e4..51d2d56a1f4d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/export-named-specifiers/output.json @@ -1,38 +1,38 @@ { "type": "File", "start": 0, - "end": 18, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 3, + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 36, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 18 + "line": 3, + "column": 8 } }, "sourceType": "module", "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 18, + "end": 8, "loc": { "start": { "line": 1, @@ -40,36 +40,86 @@ }, "end": { "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 18 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 } }, "local": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -78,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 8, - "end": 11, + "start": 17, + "end": 20, "loc": { "start": { - "line": 1, + "line": 2, "column": 8 }, "end": { - "line": 1, + "line": 2, "column": 11 }, "identifierName": "foo" @@ -96,29 +146,29 @@ }, { "type": "ExportSpecifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 } }, "local": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -127,15 +177,15 @@ }, "exported": { "type": "Identifier", - "start": 13, - "end": 16, + "start": 22, + "end": 25, "loc": { "start": { - "line": 1, + "line": 2, "column": 13 }, "end": { - "line": 1, + "line": 2, "column": 16 }, "identifierName": "bar" @@ -144,7 +194,59 @@ } } ], - "source": null + "source": null, + "declaration": null + }, + { + "type": "VariableDeclaration", + "start": 28, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default-token/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default-token/options.json index e806dd7b3a52..b6ce2c43af87 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default-token/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default-token/options.json @@ -1,3 +1,4 @@ { - "throws": "Unexpected token (1:17)" -} + "sourceType": "module", + "throws": "Unexpected token, expected \";\" (1:17)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default/options.json index a477c8ff309f..689ff73f73f7 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-default/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)" + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-named-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-named-default/options.json index 4c07f39d1731..e03d273fdcd5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-named-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-export-declaration/invalid-export-named-default/options.json @@ -1,3 +1,4 @@ { - "throws": "Unexpected token (1:16)" -} + "sourceType": "module", + "throws": "Unexpected keyword 'default' (1:8)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-const-init/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-const-init/options.json index 85e8252d6fda..c145a86bc613 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-const-init/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-const-init/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:17)" -} + "throws": "for-of loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-let-init/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-let-init/options.json index a717ca0fa7e7..c145a86bc613 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-let-init/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-let-init/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:15)" -} + "throws": "for-of loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-var-init/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-var-init/options.json index a717ca0fa7e7..c145a86bc613 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-var-init/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-for-of/invalid-var-init/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:15)" -} + "throws": "for-of loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/input.js index e66fe1911ad6..2c0ed701dcf9 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/input.js @@ -1 +1 @@ -var source = '\uD800!'; +\uD800! diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/options.json index 1bc235c3d934..afbed324e92a 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_expression_await/options.json @@ -1,4 +1,3 @@ { - "throws": - "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" + "throws": "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/options.json index 1bc235c3d934..afbed324e92a 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-identifier/invalid_var_await/options.json @@ -1,4 +1,3 @@ { - "throws": - "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" + "throws": "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_const_forin/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_const_forin/options.json index 85e8252d6fda..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_const_forin/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_const_forin/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:17)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_let_forin/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_let_forin/options.json index a717ca0fa7e7..dd3b73e5d533 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_let_forin/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-lexical-declaration/invalid_let_forin/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \";\" (1:15)" -} + "throws": "for-in loop variable declaration may not have an initializer (1:5)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/options.json deleted file mode 100644 index 5c966843f4fa..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:20)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/options.json deleted file mode 100644 index e19950ad14df..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:22)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/options.json deleted file mode 100644 index a8b5ad2f5b20..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:14)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/options.json deleted file mode 100644 index a8b5ad2f5b20..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:14)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/options.json deleted file mode 100644 index a8b5ad2f5b20..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Redefinition of __proto__ property (1:14)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-shorthand/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/input.js rename to packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-shorthand/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-shorthand/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-shorthand/output.json new file mode 100644 index 000000000000..20867c4f1d25 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-shorthand/output.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NullLiteral", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + } + } + }, + { + "type": "ObjectProperty", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-literal-shorthand/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/input.js rename to packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-literal-shorthand/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-literal-shorthand/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-literal-shorthand/output.json new file mode 100644 index 000000000000..43f28e81ab32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-literal-shorthand/output.json @@ -0,0 +1,179 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 3, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": "__proto__", + "raw": "\"__proto__\"" + }, + "value": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NullLiteral", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + } + } + }, + { + "type": "ObjectProperty", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-identifier/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/input.js rename to packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-identifier/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-identifier/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-identifier/output.json new file mode 100644 index 000000000000..28fc9127cd03 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-identifier/output.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NullLiteral", + "start": 25, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 29 + } + } + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-literal/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/input.js rename to packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-literal/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-literal/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-literal/output.json new file mode 100644 index 000000000000..5bfefd1a3925 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthand-literal/output.json @@ -0,0 +1,179 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 14, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 14, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "extra": { + "rawValue": "__proto__", + "raw": "\"__proto__\"" + }, + "value": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NullLiteral", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 31 + } + } + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthands/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/input.js rename to packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthands/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthands/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthands/output.json new file mode 100644 index 000000000000..23f3d43707e1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-initialiser/proto-shorthands/output.json @@ -0,0 +1,181 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-object-pattern/empty-catch-param/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-object-pattern/empty-catch-param/output.json index 8cd3932ae874..528fb144b23c 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-object-pattern/empty-catch-param/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-object-pattern/empty-catch-param/output.json @@ -108,7 +108,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/input.js index 2f6bc5fc687d..c0cf1cd90706 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/input.js @@ -1 +1 @@ -var source = '`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`'; +`\\n\\r\\b\\v\\t\\f\\\n\\\r\n` diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/output.json index c18d75ba278e..27c7864d3380 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/escape-sequences/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, "program": { "type": "Program", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -23,16 +23,16 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, "sourceType": "script", "interpreter": null, "body": [ { - "type": "VariableDeclaration", + "type": "ExpressionStatement", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -40,64 +40,47 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 45 - } + "expression": { + "type": "TemplateLiteral", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 45, + "end": { + "line": 1, + "column": 30 + } + }, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 1, + "end": 29, "loc": { "start": { "line": 1, - "column": 13 + "column": 1 }, "end": { "line": 1, - "column": 45 + "column": 29 } }, - "extra": { - "rawValue": "`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`", - "raw": "'`\\\\n\\\\r\\\\b\\\\v\\\\t\\\\f\\\\\\n\\\\\\r\\n`'" + "value": { + "raw": "\\\\n\\\\r\\\\b\\\\v\\\\t\\\\f\\\\\\n\\\\\\r\\n", + "cooked": "\\n\\r\\b\\v\\t\\f\\\n\\\r\n" }, - "value": "`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`" + "tail": true } - } - ], - "kind": "var" + ] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/input.js index c5468af67d5c..b4cd5b9e3fe3 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/input.js @@ -1 +1 @@ -var source = '`\n\r\n`'; +`\n\r\n` diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/output.json index 14e7c4f0b58a..3987e50bf77c 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/line-terminators/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 24, + "end": 8, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 24 + "column": 8 } }, "program": { "type": "Program", "start": 0, - "end": 24, + "end": 8, "loc": { "start": { "line": 1, @@ -23,16 +23,16 @@ }, "end": { "line": 1, - "column": 24 + "column": 8 } }, "sourceType": "script", "interpreter": null, "body": [ { - "type": "VariableDeclaration", + "type": "ExpressionStatement", "start": 0, - "end": 24, + "end": 8, "loc": { "start": { "line": 1, @@ -40,64 +40,47 @@ }, "end": { "line": 1, - "column": 24 + "column": 8 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 23 - } + "expression": { + "type": "TemplateLiteral", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 23, + "end": { + "line": 1, + "column": 8 + } + }, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 1, + "end": 7, "loc": { "start": { "line": 1, - "column": 13 + "column": 1 }, "end": { "line": 1, - "column": 23 + "column": 7 } }, - "extra": { - "rawValue": "`\n\r\n`", - "raw": "'`\\n\\r\\n`'" + "value": { + "raw": "\\n\\r\\n", + "cooked": "\n\r\n" }, - "value": "`\n\r\n`" + "tail": true } - } - ], - "kind": "var" + ] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/input.js index f8f6e9a34efd..5e0285e4f5ef 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/input.js @@ -1 +1 @@ -var source = '`\\u{000042}\\u0042\\x42\\u0\\A\\0`'; +`\\u{000042}\\u0042\\x42\\u0\\A\\0` diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/output.json index 05b8880ba5c8..5aa224c4dff5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-template-literals/literal-escape-sequences/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 51, + "end": 35, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 51 + "column": 35 } }, "program": { "type": "Program", "start": 0, - "end": 51, + "end": 35, "loc": { "start": { "line": 1, @@ -23,16 +23,16 @@ }, "end": { "line": 1, - "column": 51 + "column": 35 } }, "sourceType": "script", "interpreter": null, "body": [ { - "type": "VariableDeclaration", + "type": "ExpressionStatement", "start": 0, - "end": 51, + "end": 35, "loc": { "start": { "line": 1, @@ -40,64 +40,47 @@ }, "end": { "line": 1, - "column": 51 + "column": 35 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 50 - } + "expression": { + "type": "TemplateLiteral", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 50, + "end": { + "line": 1, + "column": 35 + } + }, + "expressions": [], + "quasis": [ + { + "type": "TemplateElement", + "start": 1, + "end": 34, "loc": { "start": { "line": 1, - "column": 13 + "column": 1 }, "end": { "line": 1, - "column": 50 + "column": 34 } }, - "extra": { - "rawValue": "`\\u{000042}\\u0042\\x42\\u0\\A\\0`", - "raw": "'`\\\\u{000042}\\\\u0042\\\\x42\\\\u0\\\\A\\\\0`'" + "value": { + "raw": "\\\\u{000042}\\\\u0042\\\\x42\\\\u0\\\\A\\\\0", + "cooked": "\\u{000042}\\u0042\\x42\\u0\\A\\0" }, - "value": "`\\u{000042}\\u0042\\x42\\u0\\A\\0`" + "tail": true } - } - ], - "kind": "var" + ] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/input.js index 1d5ecf6f7c79..73c930d32dd2 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/input.js @@ -1 +1 @@ -var source = '"\\u{714E}\\u{8336}"'; +"\\u{714E}\\u{8336}" diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/output.json index 65a14f7cbe7b..6cf40d966283 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0000/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 36, + "end": 20, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 36 + "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 36, + "end": 20, "loc": { "start": { "line": 1, @@ -23,16 +23,17 @@ }, "end": { "line": 1, - "column": 36 + "column": 20 } }, "sourceType": "script", "interpreter": null, - "body": [ + "body": [], + "directives": [ { - "type": "VariableDeclaration", + "type": "Directive", "start": 0, - "end": 36, + "end": 20, "loc": { "start": { "line": 1, @@ -40,66 +41,30 @@ }, "end": { "line": 1, - "column": 36 + "column": 20 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 35 - } + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 35 - } - }, - "extra": { - "rawValue": "\"\\u{714E}\\u{8336}\"", - "raw": "'\"\\\\u{714E}\\\\u{8336}\"'" - }, - "value": "\"\\u{714E}\\u{8336}\"" + "end": { + "line": 1, + "column": 20 } + }, + "value": "\\\\u{714E}\\\\u{8336}", + "extra": { + "raw": "\"\\\\u{714E}\\\\u{8336}\"", + "rawValue": "\\\\u{714E}\\\\u{8336}" } - ], - "kind": "var" + } } - ], - "directives": [] + ] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/input.js index fd2a94179aac..38330ee5cadd 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/input.js @@ -1 +1 @@ -var source = '"\\u{20BB7}\\u{91CE}\\u{5BB6}"'; +"\\u{20BB7}\\u{91CE}\\u{5BB6}" diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/output.json index 66ef7c611364..3f3b3439082c 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0001/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, "program": { "type": "Program", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -23,16 +23,17 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, "sourceType": "script", "interpreter": null, - "body": [ + "body": [], + "directives": [ { - "type": "VariableDeclaration", + "type": "Directive", "start": 0, - "end": 46, + "end": 30, "loc": { "start": { "line": 1, @@ -40,66 +41,30 @@ }, "end": { "line": 1, - "column": 46 + "column": 30 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 45 - } + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 45 - } - }, - "extra": { - "rawValue": "\"\\u{20BB7}\\u{91CE}\\u{5BB6}\"", - "raw": "'\"\\\\u{20BB7}\\\\u{91CE}\\\\u{5BB6}\"'" - }, - "value": "\"\\u{20BB7}\\u{91CE}\\u{5BB6}\"" + "end": { + "line": 1, + "column": 30 } + }, + "value": "\\\\u{20BB7}\\\\u{91CE}\\\\u{5BB6}", + "extra": { + "raw": "\"\\\\u{20BB7}\\\\u{91CE}\\\\u{5BB6}\"", + "rawValue": "\\\\u{20BB7}\\\\u{91CE}\\\\u{5BB6}" } - ], - "kind": "var" + } } - ], - "directives": [] + ] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/input.js b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/input.js index 582b9f3ab9a0..a7d9d668ad2d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/input.js +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/input.js @@ -1 +1 @@ -var source = '"\\u{00000000034}"'; +"\\u{00000000034}" diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/output.json index 9f9f834e880b..4331e2b8c367 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-unicode-code-point-escape-sequence/migrated_0002/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 34, + "end": 18, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 1, - "column": 34 + "column": 18 } }, "program": { "type": "Program", "start": 0, - "end": 34, + "end": 18, "loc": { "start": { "line": 1, @@ -23,16 +23,17 @@ }, "end": { "line": 1, - "column": 34 + "column": 18 } }, "sourceType": "script", "interpreter": null, - "body": [ + "body": [], + "directives": [ { - "type": "VariableDeclaration", + "type": "Directive", "start": 0, - "end": 34, + "end": 18, "loc": { "start": { "line": 1, @@ -40,66 +41,30 @@ }, "end": { "line": 1, - "column": 34 + "column": 18 } }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 33 - } + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "extra": { - "rawValue": "\"\\u{00000000034}\"", - "raw": "'\"\\\\u{00000000034}\"'" - }, - "value": "\"\\u{00000000034}\"" + "end": { + "line": 1, + "column": 18 } + }, + "value": "\\\\u{00000000034}", + "extra": { + "raw": "\"\\\\u{00000000034}\"", + "rawValue": "\\\\u{00000000034}" } - ], - "kind": "var" + } } - ], - "directives": [] + ] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json index 31d78f2e57b9..f81e206da65d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (1:21)" + "throws": "Yield cannot be used as name inside a generator function (1:21)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameter/options.json index 352b04da202c..efa8ac523c48 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameter/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (1:16)" + "throws": "Yield cannot be used as name inside a generator function (1:16)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameters/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameters/options.json index 6d7cdbc432ee..185008241333 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameters/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-parameters/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (1:25)" + "throws": "Yield cannot be used as name inside a generator function (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json index f6b6c33f1a52..8c287a1d5b36 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:30)" + "throws": "Can not use 'yield' as identifier inside a generator (1:30)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json index afe3c715ca41..3ceff8546d37 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:26)" + "throws": "Can not use 'yield' as identifier inside a generator (1:26)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json index 1bc235c3d934..23a96f285fe4 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json @@ -1,4 +1,4 @@ { - "throws": - "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" + "sourceType": "module", + "throws": "Unexpected reserved word 'yield' (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json index 5dcc4a89231c..c32eaf81f281 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:10)" + "throws": "Can not use 'yield' as identifier inside a generator (1:10)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json index 0db4ce4adca9..28b734910647 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:12)" + "throws": "Can not use 'yield' as identifier inside a generator (1:12)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json index c689509a341b..aef4d7f4f9a2 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:18)" + "throws": "Can not use 'yield' as identifier inside a generator (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json index c6514361e1d4..6993832643f1 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:25)" + "throws": "Can not use 'yield' as identifier inside a generator (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json index f5e8c7d85f54..ad818f81f136 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:20)" + "throws": "Can not use 'yield' as identifier inside a generator (1:20)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json index 0db4ce4adca9..28b734910647 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:12)" + "throws": "Can not use 'yield' as identifier inside a generator (1:12)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json index 3d2ca09a6034..c811689d9abd 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:24)" + "throws": "Can not use 'yield' as identifier inside a generator (1:24)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-expression/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-expression/options.json index 525575147202..865e081676d6 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-expression/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-expression/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:46)" + "throws": "Unexpected reserved word 'yield' (1:46)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-parameter/options.json index 4fab5560e7dd..21348af52377 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-strict-function-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:47)" + "throws": "Unexpected reserved word 'yield' (1:47)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json index f5e8c7d85f54..ad818f81f136 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:20)" + "throws": "Can not use 'yield' as identifier inside a generator (1:20)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json index a2857a14add7..e817f30acb5c 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:16)" + "throws": "Unexpected reserved word 'yield' (1:16)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json index 1de2e87eff65..e80b46c31b86 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:19)" + "throws": "Unexpected reserved word 'yield' (1:19)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json index 05cab66d4e02..27b38d28f986 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:15)" + "throws": "Unexpected reserved word 'yield' (1:15)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-binding-element/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-binding-element/options.json index 997d8d34daa8..5d111aab9319 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-binding-element/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-binding-element/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:23)" + "throws": "Unexpected reserved word 'yield' (1:23)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-catch-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-catch-parameter/options.json index 84c444f0cd15..01aca4591cea 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-catch-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-catch-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:28)" + "throws": "Unexpected reserved word 'yield' (1:28)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-formal-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-formal-parameter/options.json index eadb0124014d..a4a677fb3136 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-formal-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-formal-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:25)" + "throws": "Unexpected reserved word 'yield' (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-declaration/options.json index cf06e871cca3..091e7958db52 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'yield' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-expression/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-expression/options.json index c0b0db5cc9f9..1c3817f8e018 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-expression/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-function-expression/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'yield' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-identifier/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-identifier/options.json index 0fa96eb13cd8..412431249548 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-identifier/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-identifier/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:29)" + "throws": "Unexpected reserved word 'yield' (1:29)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-lexical-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-lexical-declaration/options.json index 773a6f2a5d9c..53a8921cb309 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-lexical-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-lexical-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:18)" + "throws": "Unexpected reserved word 'yield' (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-rest-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-rest-parameter/options.json index 84c444f0cd15..01aca4591cea 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-rest-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-rest-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:28)" + "throws": "Unexpected reserved word 'yield' (1:28)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-variable-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-variable-declaration/options.json index 773a6f2a5d9c..53a8921cb309 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-strict-variable-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:18)" + "throws": "Unexpected reserved word 'yield' (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-catch-parameter/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-catch-parameter/output.json index 310a6b5e033c..1fad434f6ac5 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-catch-parameter/output.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-catch-parameter/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/options.json index 31d78f2e57b9..f81e206da65d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/options.json @@ -1,4 +1,3 @@ { - "throws": - "yield is not allowed in the parameters of an arrow function inside a generator (1:21)" + "throws": "Yield cannot be used as name inside a generator function (1:21)" } diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0000/output.json new file mode 100644 index 000000000000..9446cbbae1c5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0000/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0001/output.json new file mode 100644 index 000000000000..138fcb2e6263 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0001/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0002.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0002/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0002.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0002/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0002/output.json new file mode 100644 index 000000000000..ef826212c27b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0002/output.json @@ -0,0 +1,120 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "elements": [ + { + "type": "NumericLiteral", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0003/output.json new file mode 100644 index 000000000000..3f7e070ca3ac --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0003/output.json @@ -0,0 +1,120 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "elements": [ + { + "type": "NumericLiteral", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0004.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0004/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0004.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0004/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0004/output.json new file mode 100644 index 000000000000..b0025ea3388c --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0004/output.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "elements": [ + null, + null, + { + "type": "NumericLiteral", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0005.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0005/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0005.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0005/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0005/output.json new file mode 100644 index 000000000000..573eda5bfa9f --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0005/output.json @@ -0,0 +1,160 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "elements": [ + { + "type": "NumericLiteral", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + { + "type": "NumericLiteral", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + { + "type": "NumericLiteral", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0006.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0006/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0006.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0006/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0006/output.json new file mode 100644 index 000000000000..34c8d7e15c8e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0006/output.json @@ -0,0 +1,161 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ArrayExpression", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "elements": [ + { + "type": "NumericLiteral", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + { + "type": "NumericLiteral", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + null, + { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0007.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0007/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0007.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0007/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0007/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0007/output.json new file mode 100644 index 000000000000..4a76c9ff3935 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0007/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "日本語" + }, + "name": "日本語" + }, + "right": { + "type": "ArrayExpression", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/input.js new file mode 100755 index 000000000000..9d3bfbcfb224 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/input.js @@ -0,0 +1 @@ +T\u203F = [] diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/output.json new file mode 100644 index 000000000000..5aa9eb08425a --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0008/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "T‿" + }, + "name": "T‿" + }, + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/input.js new file mode 100755 index 000000000000..ff386945cd53 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/input.js @@ -0,0 +1 @@ +T\u200C = [] diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/output.json new file mode 100644 index 000000000000..d6c768be8953 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0009/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "T‌" + }, + "name": "T‌" + }, + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/input.js new file mode 100755 index 000000000000..49b79b4d531b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/input.js @@ -0,0 +1 @@ +T\u200D = [] diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/output.json new file mode 100644 index 000000000000..ff1dbdcfacbe --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0010/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "T‍" + }, + "name": "T‍" + }, + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/input.js new file mode 100755 index 000000000000..ae334de44745 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/input.js @@ -0,0 +1 @@ +\u2163\u2161 = [] diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/output.json new file mode 100644 index 000000000000..d48fa35f8a00 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0011/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "ⅣⅡ" + }, + "name": "ⅣⅡ" + }, + "right": { + "type": "ArrayExpression", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "elements": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/input.js new file mode 100755 index 000000000000..79581f8529b7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/input.js @@ -0,0 +1 @@ +\u2163\u2161\u200A=\u2009[] diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/options.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/options.json new file mode 100644 index 000000000000..abe9f835b84b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-array/migrated_0012/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid Unicode escape (1:12)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0000/output.json new file mode 100644 index 000000000000..3b0df6852fce --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0000/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0001/output.json new file mode 100644 index 000000000000..20849b383b65 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0001/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0002.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0002/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0002.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0002/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0002/output.json new file mode 100644 index 000000000000..b21e99bf2e8a --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0002/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0003/output.json new file mode 100644 index 000000000000..a10e4151e34b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0003/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "extra": { + "rawValue": 5, + "raw": "5" + }, + "value": 5 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0004.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0004/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0004.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0004/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0004/output.json new file mode 100644 index 000000000000..a5255d5fce90 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0004/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "extra": { + "rawValue": 0.14, + "raw": ".14" + }, + "value": 0.14 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0005.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0005/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0005.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0005/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0005/output.json new file mode 100644 index 000000000000..bcb0e150eda3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0005/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 3.14159, + "raw": "3.14159" + }, + "value": 3.14159 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0006.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0006/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0006.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0006/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0006/output.json new file mode 100644 index 000000000000..85fdb9eb27f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0006/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 6.02214179e+23, + "raw": "6.02214179e+23" + }, + "value": 6.02214179e+23 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0007.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0007/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0007.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0007/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0007/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0007/output.json new file mode 100644 index 000000000000..570feb3f99a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0007/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 1.49241783e-10, + "raw": "1.492417830e-10" + }, + "value": 1.49241783e-10 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0008.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0008/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0008.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0008/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0008/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0008/output.json new file mode 100644 index 000000000000..5dab1af37b3e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0008/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "extra": { + "rawValue": 0, + "raw": "0x0" + }, + "value": 0 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0009.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0009/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0009.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0009/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0009/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0009/output.json new file mode 100644 index 000000000000..2c80770e1150 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0009/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "extra": { + "rawValue": 0, + "raw": "0x0" + }, + "value": 0 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0010.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0010/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0010.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0010/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0010/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0010/output.json new file mode 100644 index 000000000000..4d36c6d5cebb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0010/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": "0e+100" + }, + "value": 0 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0011.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0011/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0011.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0011/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0011/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0011/output.json new file mode 100644 index 000000000000..4d36c6d5cebb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0011/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "extra": { + "rawValue": 0, + "raw": "0e+100" + }, + "value": 0 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0012.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0012/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0012.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0012/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0012/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0012/output.json new file mode 100644 index 000000000000..ffa4e3f03d34 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0012/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 2748, + "raw": "0xabc" + }, + "value": 2748 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0013.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0013/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0013.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0013/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0013/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0013/output.json new file mode 100644 index 000000000000..ca378cfb321e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0013/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 3567, + "raw": "0xdef" + }, + "value": 3567 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0014.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0014/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0014.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0014/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0014/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0014/output.json new file mode 100644 index 000000000000..e88d6a6431f2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0014/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 26, + "raw": "0X1A" + }, + "value": 26 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0015.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0015/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0015.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0015/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0015/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0015/output.json new file mode 100644 index 000000000000..da0f5a5a077e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0015/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 16, + "raw": "0x10" + }, + "value": 16 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0016.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0016/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0016.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0016/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0016/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0016/output.json new file mode 100644 index 000000000000..3aeb059890fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0016/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 256, + "raw": "0x100" + }, + "value": 256 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0017.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0017/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0017.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0017/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0017/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0017/output.json new file mode 100644 index 000000000000..508faca10fbb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0017/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 4, + "raw": "0X04" + }, + "value": 4 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0018.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0018/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0018.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0018/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0018/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0018/output.json new file mode 100644 index 000000000000..32add9ef9dc3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0018/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "extra": { + "rawValue": 2, + "raw": "02" + }, + "value": 2 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0019.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0019/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0019.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0019/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0019/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0019/output.json new file mode 100644 index 000000000000..25cd08d3e7e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0019/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "extra": { + "rawValue": 10, + "raw": "012" + }, + "value": 10 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0020.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0020/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0020.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0020/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0020/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0020/output.json new file mode 100644 index 000000000000..3c9b2c223f85 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0020/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 10, + "raw": "0012" + }, + "value": 10 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0021.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0021/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0021.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0021/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0021/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0021/output.json new file mode 100644 index 000000000000..877e589c1492 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0021/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "extra": { + "rawValue": 8, + "raw": "08" + }, + "value": 8 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0022.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0022/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0022.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0022/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0022/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0022/output.json new file mode 100644 index 000000000000..cb6c2286193c --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0022/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 8, + "raw": "0008" + }, + "value": 8 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0023.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0023/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0023.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0023/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0023/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0023/output.json new file mode 100644 index 000000000000..22fa47db887b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0023/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "extra": { + "rawValue": 9, + "raw": "09" + }, + "value": 9 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0024.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0024/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/numeric/migrated_0024.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0024/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0024/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0024/output.json new file mode 100644 index 000000000000..f48f7a786775 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-numeric/migrated_0024/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "rawValue": 9.5, + "raw": "09.5" + }, + "value": 9.5 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0005/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0005/input.js new file mode 100755 index 000000000000..ceaf3d176e0d --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0005/input.js @@ -0,0 +1 @@ +var x = /[\\u{0000000000000061}-\\u{7A}]/u diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0006/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0006/input.js new file mode 100755 index 000000000000..8bd61e18921e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.migrated_0006/input.js @@ -0,0 +1 @@ +var x = /\\u{110000}/u diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-4-hex.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.u-flag-invalid-range-4-hex/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-4-hex.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.u-flag-invalid-range-4-hex/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-var-hex.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.u-flag-invalid-range-var-hex/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-var-hex.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/.u-flag-invalid-range-var-hex/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0000/output.json new file mode 100644 index 000000000000..a6d0d7facf75 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0000/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "RegExpLiteral", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "extra": { + "raw": "/p/" + }, + "pattern": "p", + "flags": "" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0001/output.json new file mode 100644 index 000000000000..118076195367 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0001/output.json @@ -0,0 +1,87 @@ +{ + "type": "File", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "expression": { + "type": "ArrayExpression", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "elements": [ + { + "type": "RegExpLiteral", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "extra": { + "raw": "/q/" + }, + "pattern": "q", + "flags": "" + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0002.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0002/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0002.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0002/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0002/output.json new file mode 100644 index 000000000000..edf979f658a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0002/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "raw": "/[a-z]/i" + }, + "pattern": "[a-z]", + "flags": "i" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0003/output.json new file mode 100644 index 000000000000..06f89a41d6c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0003/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "raw": "/[a-z]/y" + }, + "pattern": "[a-z]", + "flags": "y" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0004.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0004/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0004.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0004/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0004/output.json new file mode 100644 index 000000000000..8c5d9482f12d --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0004/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "raw": "/[a-z]/u" + }, + "pattern": "[a-z]", + "flags": "u" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0007.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0007/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0007.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0007/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0007/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0007/output.json new file mode 100644 index 000000000000..4ec3778aaff6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0007/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "raw": "/[x-z]/i" + }, + "pattern": "[x-z]", + "flags": "i" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0008.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0008/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0008.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0008/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0008/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0008/output.json new file mode 100644 index 000000000000..7c5bfd0d7d4b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0008/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "raw": "/[a-c]/i" + }, + "pattern": "[a-c]", + "flags": "i" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0009.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0009/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0009.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0009/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0009/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0009/output.json new file mode 100644 index 000000000000..c79985fcb2bb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0009/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "extra": { + "raw": "/[P QR]/i" + }, + "pattern": "[P QR]", + "flags": "i" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0010.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0010/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0010.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0010/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0010/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0010/output.json new file mode 100644 index 000000000000..bc5ceb3e0e4b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0010/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "raw": "/[\\]/]/" + }, + "pattern": "[\\]/]", + "flags": "" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0011.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0011/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0011.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0011/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0011/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0011/output.json new file mode 100644 index 000000000000..abec94d30ee3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0011/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "raw": "/foo\\/bar/" + }, + "pattern": "foo\\/bar", + "flags": "" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0012.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0012/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0012.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0012/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0012/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0012/output.json new file mode 100644 index 000000000000..311090fd6ab9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0012/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "raw": "/=([^=\\s])+/g" + }, + "pattern": "=([^=\\s])+", + "flags": "g" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0013.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0013/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0013.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0013/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0013/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0013/output.json new file mode 100644 index 000000000000..1dc2cf3956e3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/migrated_0013/output.json @@ -0,0 +1,138 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "MemberExpression", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "object": { + "type": "RegExpLiteral", + "start": 8, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "raw": "/42/g" + }, + "pattern": "42", + "flags": "g" + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "test" + }, + "name": "test" + }, + "computed": false + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-surrogate-pair.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-surrogate-pair/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-surrogate-pair.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-surrogate-pair/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-surrogate-pair/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-surrogate-pair/output.json new file mode 100644 index 000000000000..b94b022ea7c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-surrogate-pair/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "extra": { + "raw": "/[\\uD834\\uDF06-\\uD834\\uDF08a-z]/u" + }, + "pattern": "[\\uD834\\uDF06-\\uD834\\uDF08a-z]", + "flags": "u" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-valid-range.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-valid-range/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-valid-range.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-valid-range/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-valid-range/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-valid-range/output.json new file mode 100644 index 000000000000..20d499776ad9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-regular-expression/u-flag-valid-range/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 61 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 61 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 61, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 61 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 60, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 60 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "RegExpLiteral", + "start": 8, + "end": 60, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 60 + } + }, + "extra": { + "raw": "/[\\u{61}-b][\\u0061-b][a-\\u{62}][a-\\u0062]\\u{1ffff}/u" + }, + "pattern": "[\\u{61}-b][\\u0061-b][a-\\u{62}][a-\\u0062]\\u{1ffff}", + "flags": "u" + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0000/output.json new file mode 100644 index 000000000000..decc68148f95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0000/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "Hello", + "extra": { + "raw": "\"Hello\"", + "rawValue": "Hello" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0001/output.json new file mode 100644 index 000000000000..13ba3c4eb97c --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0001/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "value": "\\n\\r\\t\\v\\b\\f\\\\\\'\\\"\\0", + "extra": { + "raw": "\"\\n\\r\\t\\v\\b\\f\\\\\\'\\\"\\0\"", + "rawValue": "\\n\\r\\t\\v\\b\\f\\\\\\'\\\"\\0" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/input.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/input.js new file mode 100755 index 000000000000..3acde555b1ff --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/input.js @@ -0,0 +1 @@ +"\\u0061" diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/output.json new file mode 100644 index 000000000000..d9fbb2b999e5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0002/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "\\\\u0061", + "extra": { + "raw": "\"\\\\u0061\"", + "rawValue": "\\\\u0061" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0003/output.json new file mode 100644 index 000000000000..2b81d94ea76b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0003/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "\\x61", + "extra": { + "raw": "\"\\x61\"", + "rawValue": "\\x61" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0006.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0006/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0006.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0006/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0006/output.json new file mode 100644 index 000000000000..166849449336 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0006/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "Hello\\nworld", + "extra": { + "raw": "\"Hello\\nworld\"", + "rawValue": "Hello\\nworld" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0007.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0007/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0007.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0007/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0007/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0007/output.json new file mode 100644 index 000000000000..69ff486c62d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0007/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "Hello\\\nworld", + "extra": { + "raw": "\"Hello\\\nworld\"", + "rawValue": "Hello\\\nworld" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0008.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0008/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0008.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0008/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0008/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0008/output.json new file mode 100644 index 000000000000..f3046102c20f --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0008/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "value": "Hello\\02World", + "extra": { + "raw": "\"Hello\\02World\"", + "rawValue": "Hello\\02World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0009.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0009/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0009.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0009/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0009/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0009/output.json new file mode 100644 index 000000000000..5f31b1a576f3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0009/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "Hello\\012World", + "extra": { + "raw": "\"Hello\\012World\"", + "rawValue": "Hello\\012World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0010.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0010/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0010.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0010/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0010/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0010/output.json new file mode 100644 index 000000000000..9656f26c45a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0010/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "Hello\\122World", + "extra": { + "raw": "\"Hello\\122World\"", + "rawValue": "Hello\\122World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0011.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0011/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0011.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0011/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0011/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0011/output.json new file mode 100644 index 000000000000..5a8ab1f21115 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0011/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "value": "Hello\\0122World", + "extra": { + "raw": "\"Hello\\0122World\"", + "rawValue": "Hello\\0122World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0012.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0012/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0012.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0012/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0012/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0012/output.json new file mode 100644 index 000000000000..e3470fcb4ec5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0012/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "Hello\\312World", + "extra": { + "raw": "\"Hello\\312World\"", + "rawValue": "Hello\\312World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0013.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0013/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0013.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0013/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0013/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0013/output.json new file mode 100644 index 000000000000..04f8c8c1df7b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0013/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "Hello\\412World", + "extra": { + "raw": "\"Hello\\412World\"", + "rawValue": "Hello\\412World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0015.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0015/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0015.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0015/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0015/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0015/output.json new file mode 100644 index 000000000000..88a3f339c132 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0015/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": "Hello\\712World", + "extra": { + "raw": "\"Hello\\712World\"", + "rawValue": "Hello\\712World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0016.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0016/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0016.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0016/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0016/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0016/output.json new file mode 100644 index 000000000000..d73cfa2bd010 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0016/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "Hello\\0World", + "extra": { + "raw": "\"Hello\\0World\"", + "rawValue": "Hello\\0World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0017.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0017/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0017.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0017/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0017/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0017/output.json new file mode 100644 index 000000000000..69ff486c62d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0017/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "Hello\\\nworld", + "extra": { + "raw": "\"Hello\\\nworld\"", + "rawValue": "Hello\\\nworld" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0018.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0018/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0018.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0018/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0018/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0018/output.json new file mode 100644 index 000000000000..e95ac9779c07 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-literal-string/migrated_0018/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "Hello\\1World", + "extra": { + "raw": "\"Hello\\1World\"", + "rawValue": "Hello\\1World" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0000/output.json new file mode 100644 index 000000000000..ace60cd560f2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0000/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "properties": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0001/output.json new file mode 100644 index 000000000000..475c1afc13f2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0001/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "properties": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0002.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0002/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0002.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0002/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0002/output.json new file mode 100644 index 000000000000..245feff142cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0002/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "answer" + }, + "name": "answer" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0003/output.json new file mode 100644 index 000000000000..87c6c0164063 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0003/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "if" + }, + "name": "if" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0004.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0004/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0004.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0004/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0004/output.json new file mode 100644 index 000000000000..3a19ed468dc6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0004/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "true" + }, + "name": "true" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0005.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0005/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0005.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0005/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0005/output.json new file mode 100644 index 000000000000..dbb1747c7888 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0005/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "false" + }, + "name": "false" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0006.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0006/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0006.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0006/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0006/output.json new file mode 100644 index 000000000000..2918b16e85cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0006/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "null" + }, + "name": "null" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0007.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0007/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0007.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0007/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0007/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0007/output.json new file mode 100644 index 000000000000..367eac531099 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0007/output.json @@ -0,0 +1,158 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 6, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": "answer", + "raw": "\"answer\"" + }, + "value": "answer" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0008.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0008/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0008.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0008/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0008/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0008/output.json new file mode 100644 index 000000000000..81194dadc77a --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0008/output.json @@ -0,0 +1,210 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ObjectProperty", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0009.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0009/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0009.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0009/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0009/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0009/output.json new file mode 100644 index 000000000000..ea4245152521 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0009/output.json @@ -0,0 +1,189 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "width" + }, + "name": "width" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "argument": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "m_width" + }, + "name": "m_width" + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0010.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0010/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0010.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0010/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0010/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0010/output.json new file mode 100644 index 000000000000..9392a4586df7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0010/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "undef" + }, + "name": "undef" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0011.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0011/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0011.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0011/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0011/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0011/output.json new file mode 100644 index 000000000000..96fd3b7e93cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0011/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "if" + }, + "name": "if" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0012.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0012/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0012.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0012/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0012/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0012/output.json new file mode 100644 index 000000000000..b3ef7da7cabf --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0012/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "true" + }, + "name": "true" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0013.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0013/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0013.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0013/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0013/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0013/output.json new file mode 100644 index 000000000000..e055a31d0008 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0013/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "false" + }, + "name": "false" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0014.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0014/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0014.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0014/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0014/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0014/output.json new file mode 100644 index 000000000000..2ba79ca36077 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0014/output.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "null" + }, + "name": "null" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0015.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0015/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0015.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0015/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0015/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0015/output.json new file mode 100644 index 000000000000..ea3146a858b9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0015/output.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "extra": { + "rawValue": "undef", + "raw": "\"undef\"" + }, + "value": "undef" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0016.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0016/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0016.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0016/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0016/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0016/output.json new file mode 100644 index 000000000000..c02bf897d3a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0016/output.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "method": false, + "key": { + "type": "NumericLiteral", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0017.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0017/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0017.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0017/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0017/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0017/output.json new file mode 100644 index 000000000000..a15882b52dae --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0017/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "width" + }, + "name": "width" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 21, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 21, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "m_width" + }, + "name": "m_width" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0018.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0018/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0018.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0018/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0018/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0018/output.json new file mode 100644 index 000000000000..d672770fbcdf --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0018/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "if" + }, + "name": "if" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 22 + }, + "identifierName": "m_if" + }, + "name": "m_if" + }, + "right": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0019.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0019/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0019.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0019/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0019/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0019/output.json new file mode 100644 index 000000000000..3322d7a98a38 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0019/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "true" + }, + "name": "true" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "m_true" + }, + "name": "m_true" + }, + "right": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0020.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0020/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0020.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0020/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0020/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0020/output.json new file mode 100644 index 000000000000..a26b8b4009e1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0020/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "false" + }, + "name": "false" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 21, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 21, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "m_false" + }, + "name": "m_false" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0021.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0021/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0021.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0021/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0021/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0021/output.json new file mode 100644 index 000000000000..96e1bccd5184 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0021/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "null" + }, + "name": "null" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 20, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "m_null" + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0022.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0022/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0022.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0022/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0022/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0022/output.json new file mode 100644 index 000000000000..2fa4b803dd1d --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0022/output.json @@ -0,0 +1,243 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 10, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": "null", + "raw": "\"null\"" + }, + "value": "null" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 22, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "m_null" + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0023.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0023/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0023.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0023/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0023/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0023/output.json new file mode 100644 index 000000000000..21dd434a7ad0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0023/output.json @@ -0,0 +1,243 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "method": false, + "key": { + "type": "NumericLiteral", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "w" + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 18, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 18, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "m_null" + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "w" + }, + "name": "w" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0024.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0024/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0024.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0024/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0024/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0024/output.json new file mode 100644 index 000000000000..1a0a1b954720 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0024/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "get" + }, + "name": "get" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0025.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0025/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0025.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0025/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0025/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0025/output.json new file mode 100644 index 000000000000..8caddf6f2a1e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0025/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "set" + }, + "name": "set" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 43, + "raw": "43" + }, + "value": 43 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0026.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0026/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0026.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0026/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0026/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0026/output.json new file mode 100644 index 000000000000..52ea78d41c51 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0026/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "__proto__" + }, + "name": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0027.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0027/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0027.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0027/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0027/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0027/output.json new file mode 100644 index 000000000000..bf57bae53f88 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0027/output.json @@ -0,0 +1,158 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": "__proto__", + "raw": "\"__proto__\"" + }, + "value": "__proto__" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0028.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0028/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0028.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0028/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0028/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0028/output.json new file mode 100644 index 000000000000..e68e602741d1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0028/output.json @@ -0,0 +1,329 @@ +{ + "type": "File", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 77 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 6, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "width" + }, + "name": "width" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "argument": { + "type": "Identifier", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "m_width" + }, + "name": "m_width" + } + } + ], + "directives": [] + } + }, + { + "type": "ObjectMethod", + "start": 38, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 75 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 42, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 47 + }, + "identifierName": "width" + }, + "name": "width" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 53 + }, + "identifierName": "width" + }, + "name": "width" + } + ], + "body": { + "type": "BlockStatement", + "start": 55, + "end": 75, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 75 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 57, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 57, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 72 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 57, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 64 + }, + "identifierName": "m_width" + }, + "name": "m_width" + }, + "right": { + "type": "Identifier", + "start": 67, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 67 + }, + "end": { + "line": 1, + "column": 72 + }, + "identifierName": "width" + }, + "name": "width" + } + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0029.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0029/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0029.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0029/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0029/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0029/output.json new file mode 100644 index 000000000000..157cf63a8362 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0029/output.json @@ -0,0 +1,182 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 3, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ObjectProperty", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0030.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0030/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0030.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0030/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0030/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0030/output.json new file mode 100644 index 000000000000..9000ad963094 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0030/output.json @@ -0,0 +1,246 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 13, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 13, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 15, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ObjectProperty", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "y" + }, + "name": "y" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + ] + } + } + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0031.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0031/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0031.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0031/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0031/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0031/output.json new file mode 100644 index 000000000000..7754e9f31d1b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0031/output.json @@ -0,0 +1,250 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 14, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 18, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "start": 22, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 24, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ObjectMethod", + "start": 36, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "kind": "var" + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0032.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0032/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0032.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0032/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0032/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0032/output.json new file mode 100644 index 000000000000..d6a2610514cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0032/output.json @@ -0,0 +1,249 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 14, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 18, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "start": 22, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + }, + { + "type": "ObjectMethod", + "start": 31, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "kind": "var" + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0033.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0033/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0033.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0033/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0033/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0033/output.json new file mode 100644 index 000000000000..93bb4ad6958e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0033/output.json @@ -0,0 +1,267 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 14, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 18, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "start": 22, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 24, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BlockStatement", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ObjectProperty", + "start": 37, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 38 + }, + "identifierName": "i" + }, + "name": "i" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + ], + "kind": "var" + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0034.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0034/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0034.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0034/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0034/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0034/output.json new file mode 100644 index 000000000000..1dc5a28897fa --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0034/output.json @@ -0,0 +1,127 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 2, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "method": true, + "computed": true, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0035.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0035/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0035.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0035/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0035/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0035/output.json new file mode 100644 index 000000000000..2b50d0f0aea2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0035/output.json @@ -0,0 +1,142 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 2, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "computed": true, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0036.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0036/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0036.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0036/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0036/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0036/output.json new file mode 100644 index 000000000000..8ecd159198d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0036/output.json @@ -0,0 +1,187 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 2, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "method": false, + "computed": true, + "key": { + "type": "StringLiteral", + "start": 3, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": "__proto__", + "raw": "\"__proto__\"" + }, + "value": "__proto__" + }, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ObjectProperty", + "start": 19, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "computed": true, + "key": { + "type": "StringLiteral", + "start": 20, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "extra": { + "rawValue": "__proto__", + "raw": "\"__proto__\"" + }, + "value": "__proto__" + }, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0037.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0037/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0037.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0037/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0037/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0037/output.json new file mode 100644 index 000000000000..5fcc5ff585f6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0037/output.json @@ -0,0 +1,129 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 2, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "method": false, + "key": { + "type": "StringLiteral", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": "[", + "raw": "\"[\"" + }, + "value": "[" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "NumericLiteral", + "start": 7, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0038.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0038/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/object/migrated_0038.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0038/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0038/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0038/output.json new file mode 100644 index 000000000000..925deed2a00b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-object/migrated_0038/output.json @@ -0,0 +1,180 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 2, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 8, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "left": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + "right": { + "type": "NumericLiteral", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "body": { + "type": "BlockStatement", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0000.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0000/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0000.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0000/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0000/output.json new file mode 100644 index 000000000000..1cf6441fffc6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0000/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "ThisExpression", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0001.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0001/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0001.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0001/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0001/output.json new file mode 100644 index 000000000000..3d18314470cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0001/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "NullLiteral", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0002.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0002/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0002.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0002/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0002/output.json new file mode 100644 index 000000000000..bf57e074ccea --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0002/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 5, + "end": 7, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 5, + "end": 7, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0003.js b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0003/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/expression-primary/other/migrated_0003.js rename to packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0003/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0003/output.json new file mode 100644 index 000000000000..e05c37f12629 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/expression-primary-other/migrated_0003/output.json @@ -0,0 +1,146 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "left": { + "type": "BinaryExpression", + "start": 1, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "left": { + "type": "NumericLiteral", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0008.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0008.source.js deleted file mode 100755 index f0f44705bf8d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0008.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'T\u203F = []'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0009.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0009.source.js deleted file mode 100755 index e2eb52f9c7df..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0009.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'T\u200C = []'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0010.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0010.source.js deleted file mode 100755 index bafe63b052e8..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0010.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'T\u200D = []'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0011.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0011.source.js deleted file mode 100755 index 307b0667e7c1..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0011.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\u2163\u2161 = []'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0012.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0012.source.js deleted file mode 100755 index b24f8e1c8272..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/migrated_0012.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\u2163\u2161\u200A=\u2009[]'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/array/output.json deleted file mode 100644 index 145f80b57b91..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/array/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/output.json deleted file mode 100644 index 145f80b57b91..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0005.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0005.source.js deleted file mode 100755 index b2b646e23ee3..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0005.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /[\\u{0000000000000061}-\\u{7A}]/u'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.failure.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.failure.json deleted file mode 100755 index 55cbc7a399d2..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.failure.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "index": 21, - "lineNumber": 1, - "column": 22, - "message": "Error: Line 1: Invalid regular expression" -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.source.js deleted file mode 100755 index 964850a64ee6..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/migrated_0006.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /\\u{110000}/u'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-4-hex.failure.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-4-hex.failure.json deleted file mode 100755 index 9bfbe69a020a..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-4-hex.failure.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "index": 21, - "lineNumber": 1, - "column": 22, - "message": "Error: Line 1: Invalid regular expression" -} diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-var-hex.failure.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-var-hex.failure.json deleted file mode 100755 index 9bfbe69a020a..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/regular-expression/u-flag-invalid-range-var-hex.failure.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "index": 21, - "lineNumber": 1, - "column": 22, - "message": "Error: Line 1: Invalid regular expression" -} diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0002.source.js b/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0002.source.js deleted file mode 100755 index 0447afbd6fde..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/literal/string/migrated_0002.source.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u0061"'; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/object/output.json deleted file mode 100644 index 145f80b57b91..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/object/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/output.json b/packages/babel-parser/test/fixtures/esprima/expression-primary/other/output.json deleted file mode 100644 index 145f80b57b91..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/expression-primary/other/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0033/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0033/input.js deleted file mode 100644 index 0faf8dc92a46..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0033/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'x\\u005c'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0034/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0034/input.js deleted file mode 100644 index ac96b7835455..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0034/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'x\\u002a'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json index 3e2f5ee264d5..3c289784c021 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json @@ -1,4 +1,3 @@ { - "throws": - "Error parsing regular expression: Invalid regular expression: /(s/: Unterminated group (1:9)" + "throws": "Error parsing regular expression: Invalid regular expression: /(s/: Unterminated group (1:9)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/input.js deleted file mode 100644 index e7f145a8d03c..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'a\\u'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/options.json deleted file mode 100644 index 27a7b64d71d4..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0036/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:4)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/input.js deleted file mode 100644 index 5ced27a43a4e..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\\ua'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/options.json deleted file mode 100644 index 27a7b64d71d4..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0037/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:4)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0041/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0041/input.js deleted file mode 100644 index 21543eba12eb..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0041/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /[a-z]/\\ux'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/input.js deleted file mode 100644 index a7b0d9a4656d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /[a-z\n]/\\ux'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/options.json deleted file mode 100644 index 98d712379010..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0042/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:15)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/input.js deleted file mode 100644 index 42552d48074d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /[a-z]/\\\\ux'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/options.json deleted file mode 100644 index e806dd7b3a52..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0043/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:17)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0044/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0044/input.js deleted file mode 100644 index eabe2cb40a69..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0044/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = 'var x = /[P QR]/\\\\u0067'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/input.js deleted file mode 100644 index 32714507554e..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u{110000}"'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/options.json deleted file mode 100644 index 9e093bfdcd96..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0048/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:12)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/input.js deleted file mode 100644 index 1a2de200fe42..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u{}"'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/options.json deleted file mode 100644 index 91b308200e05..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0049/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:5)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/input.js deleted file mode 100644 index eac5bf2ce6e9..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u{FFFF"'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/options.json deleted file mode 100644 index 89bfc2d73f8a..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0050/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:10)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/input.js deleted file mode 100644 index b190f73e12b9..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u{FFZ}"'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/options.json deleted file mode 100644 index 9ce9658f7dfa..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0051/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:8)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0075/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0075/options.json deleted file mode 100644 index e3a1ba7e8296..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0075/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "setter should have exactly one param (1:8)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/input.js deleted file mode 100644 index 93e2a300f15d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\u203F = 10'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/options.json deleted file mode 100644 index b5b75f41875c..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0137/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:1)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/input.js deleted file mode 100644 index cd1103629db1..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\\u005c'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/options.json deleted file mode 100644 index c958665c03e2..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0163/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:7)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/input.js deleted file mode 100644 index aa31feb7eccb..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\\u0000'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/options.json deleted file mode 100644 index c958665c03e2..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0165/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:7)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/input.js deleted file mode 100644 index 29a288bee4bb..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\u200C = []'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/options.json deleted file mode 100644 index b5b75f41875c..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0166/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:1)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/input.js deleted file mode 100644 index ec9a56e78cf0..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '\u200D = []'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/options.json deleted file mode 100644 index b5b75f41875c..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0167/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:1)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/input.js deleted file mode 100644 index 481ef9c80833..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/input.js +++ /dev/null @@ -1 +0,0 @@ -var source = '"\\u'; diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/options.json deleted file mode 100644 index 27a7b64d71d4..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0169/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:4)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0277/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0277/options.json deleted file mode 100644 index 9e093bfdcd96..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0277/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:12)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/input.js new file mode 100644 index 000000000000..fff580f2044f --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/input.js @@ -0,0 +1 @@ +x\\u005c diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/options.json new file mode 100644 index 000000000000..18c53b997b56 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0033/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/input.js new file mode 100644 index 000000000000..17112246786b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/input.js @@ -0,0 +1 @@ +x\\u002a diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/options.json new file mode 100644 index 000000000000..18c53b997b56 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0034/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/input.js new file mode 100644 index 000000000000..3177052a225a --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/input.js @@ -0,0 +1 @@ +a\\u diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/options.json new file mode 100644 index 000000000000..18c53b997b56 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0036/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/input.js new file mode 100644 index 000000000000..d56d7c190d02 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/input.js @@ -0,0 +1 @@ +\\ua diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0037/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/input.js new file mode 100644 index 000000000000..9a2dc1767685 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/input.js @@ -0,0 +1 @@ +var x = /[a-z]/\\ux diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/options.json new file mode 100644 index 000000000000..adf556b0a352 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0041/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid regular expression flag (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/input.js new file mode 100644 index 000000000000..fdbf86f1d023 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/input.js @@ -0,0 +1 @@ +var x = /[a-z\n]/\\ux diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/options.json new file mode 100644 index 000000000000..eae3757f4451 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0042/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid regular expression flag (1:18)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/input.js new file mode 100644 index 000000000000..e2a2d371e229 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/input.js @@ -0,0 +1 @@ +var x = /[a-z]/\\\\ux diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/options.json new file mode 100644 index 000000000000..adf556b0a352 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0043/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid regular expression flag (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/input.js new file mode 100644 index 000000000000..fc48dffd74dc --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/input.js @@ -0,0 +1 @@ +var x = /[P QR]/\\\\u0067 diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/options.json new file mode 100644 index 000000000000..080cb0eaaa8a --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0044/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid regular expression flag (1:17)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/input.js new file mode 100644 index 000000000000..2bbf7ac4d47c --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/input.js @@ -0,0 +1 @@ +\\u{110000} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0048/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/input.js new file mode 100644 index 000000000000..9943cc7906a5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/input.js @@ -0,0 +1 @@ +\\u{} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0049/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/input.js new file mode 100644 index 000000000000..5d4f24cb8271 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/input.js @@ -0,0 +1 @@ +\\u{FFFF diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0050/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/input.js new file mode 100644 index 000000000000..11e05c81c1e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/input.js @@ -0,0 +1 @@ +\\u{FFZ} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0051/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0064/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0064/options.json index 27a7b64d71d4..2b91be8d5115 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0064/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0064/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:4)" + "throws": "Unexpected keyword 'if' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0075/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0075/input.js rename to packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/options.json new file mode 100644 index 000000000000..aa55ec4f840f --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0075/options.json @@ -0,0 +1,3 @@ +{ + "throws": "setter must have exactly one formal parameter (1:3)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0087/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0087/options.json index f56e7311d854..02a0eafbbbbe 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0087/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0087/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Assigning to 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0088/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0088/options.json index c5e6f0e62338..e4abe279ab29 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0088/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0088/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:14)" -} + "throws": "Binding 'eval' in strict mode (1:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0089/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0089/options.json index 3168d40d55f8..c2a4aaec255e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0089/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0089/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:14)" -} + "throws": "Binding 'arguments' in strict mode (1:14)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0090/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0090/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0090/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0090/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0091/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0091/options.json index 0e1962195156..5d2dc563b16e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0091/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0091/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'arguments' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0092/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0092/options.json index 0590c2b7e6bf..368006ae58bd 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0092/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0092/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:4)" + "throws": "Argument name clash (1:4)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0093/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0093/options.json index 6d0445e20eb7..b99fd35222b1 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0093/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0093/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:18)" + "throws": "Argument name clash (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0094/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0094/options.json index 0f2c1bee90b0..79a05e62290e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0094/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0094/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:21)" + "throws": "Legacy octal literals are not allowed in strict mode (1:21)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0100/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0100/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0100/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0100/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0101/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0101/options.json index 12e8741b8a16..224716db8070 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0101/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0101/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:1)" -} + "throws": "Binding 'eval' in strict mode (1:1)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/input.js deleted file mode 100644 index 9d44939080f0..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/input.js +++ /dev/null @@ -1 +0,0 @@ -function t(if) { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/options.json deleted file mode 100644 index cb6c66081ebf..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0104/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:11)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/input.js deleted file mode 100644 index d7516ce611ed..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/input.js +++ /dev/null @@ -1 +0,0 @@ -function t(true) { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/options.json deleted file mode 100644 index cb6c66081ebf..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0105/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:11)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/input.js deleted file mode 100644 index e8edce823989..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/input.js +++ /dev/null @@ -1 +0,0 @@ -function t(false) { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/options.json deleted file mode 100644 index cb6c66081ebf..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0106/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:11)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/input.js deleted file mode 100644 index 86c3d224d014..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/input.js +++ /dev/null @@ -1 +0,0 @@ -function t(null) { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/options.json deleted file mode 100644 index cb6c66081ebf..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0107/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:11)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0108/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0108/input.js deleted file mode 100644 index 6cafc792756d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0108/input.js +++ /dev/null @@ -1 +0,0 @@ -function null() { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/input.js deleted file mode 100644 index bc1d04c212e3..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/input.js +++ /dev/null @@ -1 +0,0 @@ -function true() { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/options.json deleted file mode 100644 index 2a28555f76db..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0109/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/input.js deleted file mode 100644 index 4480e07b7d5d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/input.js +++ /dev/null @@ -1 +0,0 @@ -function false() { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/options.json deleted file mode 100644 index 2a28555f76db..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0110/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/input.js deleted file mode 100644 index df1aa5f56166..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/input.js +++ /dev/null @@ -1 +0,0 @@ -function if() { } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/options.json deleted file mode 100644 index 2a28555f76db..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0111/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/input.js new file mode 100644 index 000000000000..a63b2d2bdd7e --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/input.js @@ -0,0 +1 @@ +\u203F = 10 diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/options.json new file mode 100644 index 000000000000..82bcfe621c49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0137/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid Unicode escape (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0141/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0141/options.json index 2a28555f76db..a74ca2305e84 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0141/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0141/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Unexpected token, expected \";\" (1:13)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0142/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0142/options.json index 2a28555f76db..97818d2eea7e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0142/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0142/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:9)" + "throws": "Lexical declaration cannot appear in a single-statement context (1:9)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/input.js new file mode 100644 index 000000000000..b9e12b2eff54 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/input.js @@ -0,0 +1 @@ +\\u005c diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0163/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/input.js new file mode 100644 index 000000000000..a6e819ccd18b --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/input.js @@ -0,0 +1 @@ +\\u0000 diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0165/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/input.js new file mode 100644 index 000000000000..7884927364d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/input.js @@ -0,0 +1 @@ +\u200C = [] diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/options.json new file mode 100644 index 000000000000..82bcfe621c49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0166/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid Unicode escape (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/input.js new file mode 100644 index 000000000000..ade8012e1e92 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/input.js @@ -0,0 +1 @@ +\u200D = [] diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/options.json new file mode 100644 index 000000000000..82bcfe621c49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0167/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid Unicode escape (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/input.js new file mode 100644 index 000000000000..2775e915bb92 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/input.js @@ -0,0 +1 @@ +"\\u diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/options.json new file mode 100644 index 000000000000..d732a1630991 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0169/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unterminated string constant (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0185/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0185/options.json index 28f88106148b..b463f315f9eb 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0185/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0185/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:36)" -} + "throws": "Binding 'eval' in strict mode (1:36)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0186/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0186/options.json index 913c7bb59f38..9e9f875dfbb5 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0186/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0186/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:36)" -} + "throws": "Binding 'arguments' in strict mode (1:36)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0187/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0187/options.json index 0306783e6eef..b5fd79ff5ff1 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0187/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0187/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'eval' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0188/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0188/options.json index d1ae2825366a..15b7ac855374 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0188/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0188/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'arguments' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0189/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0189/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0189/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0189/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0190/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0190/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0190/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0190/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0191/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0191/options.json index 48fd4ff41936..2783b68b3d58 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0191/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0191/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'eval' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0192/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0192/options.json index 48fd4ff41936..2783b68b3d58 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0192/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0192/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'eval' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0193/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0193/options.json index d579a92e2358..fe2654496fc9 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0193/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0193/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'arguments' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0194/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0194/options.json index d579a92e2358..fe2654496fc9 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0194/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0194/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:34)" -} + "throws": "Assigning to 'arguments' in strict mode (1:34)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0195/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0195/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0195/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0195/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0196/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0196/options.json index 3bcd668ab1b1..95f470aed511 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0196/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0196/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'eval' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0197/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0197/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0197/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0197/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0198/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0198/options.json index 04db3a217825..ef45890ab53f 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0198/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0198/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:32)" -} + "throws": "Assigning to 'arguments' in strict mode (1:32)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0199/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0199/options.json index 71bbcc0b9c1c..6db4ae7bf008 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0199/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0199/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'eval' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0200/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0200/options.json index 544d28f50291..b02fb725c767 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0200/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0200/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'arguments' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0201/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0201/options.json index bf851387b4c6..a7490f9321d4 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0201/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0201/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'eval' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0202/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0202/options.json index e4d477b8e4ec..80b8b2d85caa 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0202/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0202/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'arguments' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0203/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0203/options.json index f6c8eea4b0d3..706ba8380c70 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0203/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0203/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:42)" -} + "throws": "Binding 'eval' in strict mode (1:42)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0204/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0204/options.json index d26216e0a364..d0e461af3911 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0204/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0204/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:42)" -} + "throws": "Binding 'arguments' in strict mode (1:42)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0205/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0205/options.json index 69e4925a3ffd..ee2e7d7c7745 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0205/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0205/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'eval' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0206/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0206/options.json index fbdc57cfc8fa..bb4b812bab32 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0206/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0206/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'arguments' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0207/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0207/options.json index 0306783e6eef..b5fd79ff5ff1 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0207/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0207/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:47)" -} + "throws": "Binding 'eval' in strict mode (1:47)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0208/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0208/options.json index c2d1e1a69b41..ff90f09173c4 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0208/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0208/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:10)" -} + "throws": "Binding 'package' in strict mode (1:10)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0209/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0209/options.json index 92828dc4f1c9..b8f97ca4fe56 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0209/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0209/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'eval' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0210/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0210/options.json index 71bbcc0b9c1c..6db4ae7bf008 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0210/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0210/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:41)" -} + "throws": "Binding 'eval' in strict mode (1:41)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0211/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0211/options.json index 241eccc1bf6d..e80a856d48a0 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0211/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0211/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:49)" -} + "throws": "Binding 'eval' in strict mode (1:49)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0212/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0212/options.json index f56e7311d854..d93d5b2aa62e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0212/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0212/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'eval' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0213/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0213/options.json index 0e1962195156..5d2dc563b16e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0213/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0213/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'arguments' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0214/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0214/options.json index 92828dc4f1c9..b8f97ca4fe56 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0214/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0214/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'eval' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0215/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0215/options.json index e9f6bf4d32ff..ab7000409bab 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0215/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0215/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:48)" -} + "throws": "Binding 'arguments' in strict mode (1:48)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0218/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0218/options.json index ec4ea95dc9cb..45ca229c1e8e 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0218/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0218/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:33)" + "throws": "Legacy octal literals are not allowed in strict mode (1:33)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0220/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0220/options.json index dd200e16e5bf..8f6c8218f747 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0220/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0220/options.json @@ -1,3 +1,3 @@ { - "throws": "Invalid number (1:36)" + "throws": "Legacy octal literals are not allowed in strict mode (1:36)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0224/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0224/options.json index 2748b9f03d9e..0641de45e29a 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0224/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0224/options.json @@ -1,3 +1,3 @@ { - "throws": "implements is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'implements' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0225/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0225/options.json index 6efaf057ca5c..859238d0423f 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0225/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0225/options.json @@ -1,3 +1,3 @@ { - "throws": "interface is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'interface' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0226/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0226/options.json index 61578ad8f860..344c7075f4bf 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0226/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0226/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'package' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0227/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0227/options.json index da502d0daa6a..9fb9deaf9cba 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0227/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0227/options.json @@ -1,3 +1,3 @@ { - "throws": "private is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'private' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0228/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0228/options.json index 6fd44c0e1ba5..292fb56f1cf3 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0228/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0228/options.json @@ -1,3 +1,3 @@ { - "throws": "protected is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'protected' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0229/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0229/options.json index 3a41c740eaac..d5f48446906a 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0229/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0229/options.json @@ -1,3 +1,3 @@ { - "throws": "public is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'public' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0230/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0230/options.json index 764205122e0f..0f41ff2e6f24 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0230/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0230/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'static' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0231/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0231/options.json index b31373dfb730..6ab197f35dc9 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0231/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0231/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word in strict mode (1:37)" + "throws": "Unexpected reserved word 'yield' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0232/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0232/options.json index 9fa1302689e1..d2f3cbc2e116 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0232/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0232/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:37)" + "throws": "Unexpected reserved word 'let' (1:37)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0233/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0233/options.json index e316c4fc64fd..fff472344fd7 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0233/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0233/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:15)" -} + "throws": "Binding 'static' in strict mode (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0234/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0234/options.json index 9b6fddd2ebba..d4d0a96bfb64 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0234/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0234/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'static' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0235/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0235/options.json index bf851387b4c6..a7490f9321d4 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0235/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0235/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'eval' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0236/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0236/options.json index e4d477b8e4ec..80b8b2d85caa 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0236/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0236/options.json @@ -1,3 +1,3 @@ { - "throws": "arguments is a reserved word in strict mode (1:9)" -} + "throws": "Binding 'arguments' in strict mode (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/input.js deleted file mode 100644 index c87b8eaaf43d..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/input.js +++ /dev/null @@ -1 +0,0 @@ -var let diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/options.json deleted file mode 100644 index 27a7b64d71d4..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0238/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:4)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0239/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0239/options.json index a2eac88ba69d..91bc36d3f360 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0239/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0239/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:23)" + "throws": "Unexpected reserved word 'static' (1:23)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0240/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0240/options.json index e23388601bb0..8b20b9a7df36 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0240/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0240/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:14)" + "throws": "Argument name clash (1:14)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0241/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0241/options.json index 0bb96c96d88e..e227bd1a6b74 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0241/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0241/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:11)" -} + "throws": "Binding 'eval' in strict mode (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0242/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0242/options.json index 7551a61b9e0b..8e1f9af4ec47 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0242/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0242/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:11)" -} + "throws": "Binding 'package' in strict mode (1:11)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0243/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0243/options.json index 660e54ca2a82..9d2a58081596 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0243/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0243/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:43)" + "throws": "Argument name clash (1:43)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0244/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0244/options.json index 28545ded1456..61c3bbb5abe0 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0244/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0244/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:15)" + "throws": "Argument name clash (1:15)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0245/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0245/options.json index 0f592c74a35b..ae469fbd59da 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0245/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0245/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:44)" + "throws": "Argument name clash (1:44)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0246/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0246/options.json index b52d2d2e1520..3c24c608c88a 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0246/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0246/options.json @@ -1,3 +1,3 @@ { - "throws": "eval is a reserved word in strict mode (1:12)" -} + "throws": "Binding 'eval' in strict mode (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0247/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0247/options.json index 7b80f0e455ce..96d524816cc9 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0247/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0247/options.json @@ -1,3 +1,3 @@ { - "throws": "package is a reserved word in strict mode (1:12)" -} + "throws": "Binding 'package' in strict mode (1:12)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0249/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0249/options.json index 172760cf2cf6..505798d5a203 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0249/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0249/options.json @@ -1,3 +1,3 @@ { - "throws": "Argument name clash in strict mode (1:36)" + "throws": "Argument name clash (1:36)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/input.js deleted file mode 100644 index 564a1caa1ce5..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/input.js +++ /dev/null @@ -1 +0,0 @@ -let diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/options.json deleted file mode 100644 index 05dbd26b33ce..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0253/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:3)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0258/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0258/options.json index 570ef651fb67..2e1b1cc3aa43 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0258/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0258/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \")\" (1:18)" + "throws": "Rest element must be last element (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0277/input.js b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/esprima/invalid-syntax/.migrated_0277/input.js rename to packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/input.js diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/options.json new file mode 100644 index 000000000000..aef7f56007e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected reserved word 'enum' (1:11)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0278/options.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0278/options.json index a07e958c4de0..757b207f0ef2 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0278/options.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0278/options.json @@ -1,3 +1,3 @@ { - "throws": "static is a reserved word in strict mode (1:17)" + "throws": "Unexpected reserved word 'static' (1:17)" } diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/input.js b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/input.js index 389d74582517..acd373a4ae35 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/input.js +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/input.js @@ -1 +1 @@ -var source = '\\u0061'; +\\u0061 diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/options.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/output.json deleted file mode 100644 index 0fb9d2b43217..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0002/output.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "extra": { - "rawValue": "\\u0061", - "raw": "'\\\\u0061'" - }, - "value": "\\u0061" - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/input.js b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/input.js index 6524a1c4cfd2..97f921cd1e29 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/input.js +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/input.js @@ -1 +1 @@ -var source = 'a\\u0061'; +a\\u0061 diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/options.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/options.json new file mode 100644 index 000000000000..18c53b997b56 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json deleted file mode 100644 index cc312ab67a75..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "extra": { - "rawValue": "a\\u0061", - "raw": "'a\\\\u0061'" - }, - "value": "a\\u0061" - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/input.js b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/input.js index d4941e9313e9..b57febcb64d5 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/input.js +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/input.js @@ -1 +1 @@ -var source = '\\u0061a'; +\\u0061a diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/options.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/output.json deleted file mode 100644 index 01650ee4aa69..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0004/output.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "extra": { - "rawValue": "\\u0061a", - "raw": "'\\\\u0061a'" - }, - "value": "\\u0061a" - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/input.js b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/input.js index 8e5a088c93c2..bf2962a6a9ec 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/input.js +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/input.js @@ -1 +1 @@ -var source = '\\u0061a '; +\\u0061a diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/options.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/options.json new file mode 100644 index 000000000000..381fd12ce2d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Expecting Unicode escape sequence \\uXXXX (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/output.json deleted file mode 100644 index 5c72b8a79068..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0005/output.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 10 - }, - "identifierName": "source" - }, - "name": "source" - }, - "init": { - "type": "StringLiteral", - "start": 13, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "extra": { - "rawValue": "\\u0061a ", - "raw": "'\\\\u0061a '" - }, - "value": "\\u0061a " - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0000/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0000/output.json index d363a5d4cc63..7124a7ba6fff 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0000/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0000/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0001/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0001/output.json index 80dde4eca487..0f104da5ae82 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0001/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0001/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0002/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0002/output.json index 4b11f881deec..8721f9d98403 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0002/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0002/output.json @@ -109,7 +109,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0003/output.json index fbcb70be2667..49094bb0e6bd 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0003/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0003/output.json @@ -176,7 +176,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0004/output.json index ea48a4030059..b1589f69dcee 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0004/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0004/output.json @@ -61,7 +61,6 @@ "directives": [] }, "handler": null, - "guardedHandlers": [], "finalizer": { "type": "BlockStatement", "start": 16, diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0005/output.json index bc19c5698fbf..7bb5acfbedbb 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0005/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0005/output.json @@ -225,7 +225,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": null } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0006/output.json index dc667d97efc5..91b008540089 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0006/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-try/migrated_0006/output.json @@ -225,7 +225,6 @@ "directives": [] } }, - "guardedHandlers": [], "finalizer": { "type": "BlockStatement", "start": 47, diff --git a/packages/babel-parser/test/fixtures/estree/class-method/typescript/input.js b/packages/babel-parser/test/fixtures/estree/class-method/typescript/input.js new file mode 100644 index 000000000000..06058b566778 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/class-method/typescript/input.js @@ -0,0 +1,3 @@ +abstract class TSAbstractClass { + abstract foo(name: string): boolean; +} diff --git a/packages/babel-parser/test/fixtures/estree/class-method/typescript/options.json b/packages/babel-parser/test/fixtures/estree/class-method/typescript/options.json new file mode 100644 index 000000000000..d69381825ce5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/class-method/typescript/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["typescript", "estree"] +} diff --git a/packages/babel-parser/test/fixtures/estree/class-method/typescript/output.json b/packages/babel-parser/test/fixtures/estree/class-method/typescript/output.json new file mode 100644 index 000000000000..83a633725788 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/class-method/typescript/output.json @@ -0,0 +1,219 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "abstract": true, + "id": { + "type": "Identifier", + "start": 15, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "TSAbstractClass" + }, + "name": "TSAbstractClass" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 31, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "MethodDefinition", + "start": 35, + "end": 71, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "abstract": true, + "static": false, + "key": { + "type": "Identifier", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "value": { + "type": "FunctionExpression", + "start": 47, + "end": 71, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 48, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "name" + }, + "name": "name", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 52, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "start": 54, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 27 + } + } + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "start": 61, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "typeAnnotation": { + "type": "TSBooleanKeyword", + "start": 63, + "end": 70, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 37 + } + } + } + } + } + } + ] + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js b/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js new file mode 100644 index 000000000000..cf0b94467025 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js @@ -0,0 +1,4 @@ +enum A { + a, + "r" +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json b/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json new file mode 100644 index 000000000000..7a0e9a0cbb8d --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/enum/output.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TSEnumDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "A" + }, + "name": "A" + }, + "members": [ + { + "type": "TSEnumMember", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + { + "type": "TSEnumMember", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "id": { + "type": "Literal", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "value": "r", + "raw": "\"r\"" + } + } + ] + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js b/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js new file mode 100644 index 000000000000..6801238e6ff4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js @@ -0,0 +1 @@ +import x = require ("asdfasdf"); diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json b/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json new file mode 100644 index 000000000000..2104ca43283f --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json b/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json new file mode 100644 index 000000000000..65361fdc837c --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import-require/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSImportEqualsDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "isExport": false, + "id": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "moduleReference": { + "type": "TSExternalModuleReference", + "start": 11, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "Literal", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "value": "asdfasdf", + "raw": "\"asdfasdf\"" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import/input.js b/packages/babel-parser/test/fixtures/estree/typescript/import/input.js new file mode 100644 index 000000000000..7bae7e8301b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import/input.js @@ -0,0 +1,3 @@ +let x: typeof import('./x'); +let Y: import('./y').Y; +let z: import("/z").foo.bar; diff --git a/packages/babel-parser/test/fixtures/estree/typescript/import/output.json b/packages/babel-parser/test/fixtures/estree/typescript/import/output.json new file mode 100644 index 000000000000..48ff04ded091 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/import/output.json @@ -0,0 +1,441 @@ +{ + "type": "File", + "start": 0, + "end": 89, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 89, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 5, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeAnnotation": { + "type": "TSTypeQuery", + "start": 7, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "exprName": { + "type": "TSImportType", + "start": 14, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "argument": { + "type": "Literal", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "value": "./x", + "raw": "'./x'" + } + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 29, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "Y" + }, + "name": "Y", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 34, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TSImportType", + "start": 36, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "argument": { + "type": "Literal", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "./y", + "raw": "'./y'" + }, + "qualifier": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "Y" + }, + "name": "Y" + } + } + } + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 53, + "end": 89, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 57, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 35 + }, + "identifierName": "z" + }, + "name": "z", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 58, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "typeAnnotation": { + "type": "TSImportType", + "start": 60, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "argument": { + "type": "Literal", + "start": 67, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "/z", + "raw": "\"/z\"" + }, + "qualifier": { + "type": "TSQualifiedName", + "start": 73, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 73, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "right": { + "type": "Identifier", + "start": 77, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 27 + }, + "identifierName": "bar" + }, + "name": "bar" + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "start": 80, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "params": [ + { + "type": "TSStringKeyword", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 34 + } + } + } + ] + } + } + } + }, + "init": null + } + ], + "kind": "let" + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js b/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js new file mode 100644 index 000000000000..ba1ece47de5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js @@ -0,0 +1,7 @@ +type Foo = false; +type Foo2 = true; +type Foo3 = "string"; +type Foo4 = 123; +type Foo5 = 123.4; +type Foo6 = -123; +type Foo7 = -123.5; diff --git a/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json b/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json new file mode 100644 index 000000000000..e08c9b31db6d --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/literals/output.json @@ -0,0 +1,516 @@ +{ + "type": "File", + "start": 0, + "end": 131, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 131, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "literal": { + "type": "Literal", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "value": false, + "raw": "false" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 18, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo2" + }, + "name": "Foo2" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 30, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "literal": { + "type": "Literal", + "start": 30, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": true, + "raw": "true" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 36, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "Foo3" + }, + "name": "Foo3" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 48, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "literal": { + "type": "Literal", + "start": 48, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "value": "string", + "raw": "\"string\"" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 58, + "end": 74, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "id": { + "type": "Identifier", + "start": 63, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 9 + }, + "identifierName": "Foo4" + }, + "name": "Foo4" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "literal": { + "type": "Literal", + "start": 70, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "value": 123, + "raw": "123" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 75, + "end": 93, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 80, + "end": 84, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 9 + }, + "identifierName": "Foo5" + }, + "name": "Foo5" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 87, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "literal": { + "type": "Literal", + "start": 87, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 17 + } + }, + "value": 123.4, + "raw": "123.4" + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 94, + "end": 111, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 99, + "end": 103, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 9 + }, + "identifierName": "Foo6" + }, + "name": "Foo6" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "literal": { + "type": "UnaryExpression", + "start": 106, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "Literal", + "start": 107, + "end": 110, + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": 123, + "raw": "123" + } + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "start": 112, + "end": 131, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 117, + "end": 121, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "Foo7" + }, + "name": "Foo7" + }, + "typeAnnotation": { + "type": "TSLiteralType", + "start": 124, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "literal": { + "type": "UnaryExpression", + "start": 124, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "operator": "-", + "prefix": true, + "argument": { + "type": "Literal", + "start": 125, + "end": 130, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": 123.5, + "raw": "123.5" + } + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/estree/typescript/options.json b/packages/babel-parser/test/fixtures/estree/typescript/options.json new file mode 100644 index 000000000000..d69381825ce5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/estree/typescript/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["typescript", "estree"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.bigint/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.bigint/options.json index 20096726d620..8e44fabed2f5 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.bigint/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.bigint/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'bigInt' (1:1)", + "throws": "This experimental syntax requires enabling the parser plugin: 'bigInt' (1:1)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.class-private-properties/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.class-private-properties/options.json index 16521eb656b1..85d7fee65f66 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.class-private-properties/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.class-private-properties/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'classPrivateProperties' (2:3)", + "throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateProperties' (2:3)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.numeric-separator/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.numeric-separator/options.json index 06642e156345..6996ba6f1573 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/.numeric-separator/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/.numeric-separator/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:17)", + "throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:17)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/input.js deleted file mode 100644 index 6d06ef263a91..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/input.js +++ /dev/null @@ -1 +0,0 @@ -async function * f () {} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/options.json deleted file mode 100644 index e55164203df2..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/async-generators/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "throws": - "This experimental syntax requires enabling the parser plugin: 'asyncGenerators' (1:15)", - "plugins": [] -} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer-and-type/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer-and-type/options.json index 6dc7d63208aa..a4e85bf033a7 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer-and-type/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer-and-type/options.json @@ -1,5 +1,4 @@ { "plugins": ["flow"], - "throws": - "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:14)" + "throws": "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:14)" } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer/options.json index 44726ea60083..aaa6e8068648 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-with-initializer/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:6)", + "throws": "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:6)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-without-initializer/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-without-initializer/options.json index 4d708dc64434..bbec0b1850ba 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-without-initializer/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/class-properties-without-initializer/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:5)", + "throws": "This experimental syntax requires enabling the parser plugin: 'classProperties' (2:5)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json index b8382f9c0850..11f94afa3b7a 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (1:0)", + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (1:0)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/do-expressions/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/do-expressions/options.json index b7fe32fb80f0..0aaae18db824 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/do-expressions/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/do-expressions/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'doExpressions' (1:1)", + "throws": "This experimental syntax requires enabling the parser plugin: 'doExpressions' (1:1)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/dynamic-import/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/dynamic-import/options.json index ee35343694f9..90bbfd5623c9 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/dynamic-import/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/dynamic-import/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'dynamicImport' (1:8)", + "throws": "This experimental syntax requires enabling the parser plugin: 'dynamicImport' (1:8)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-default/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-default/options.json index 7d30825d8387..e306a4f34cbf 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-default/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-default/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-namespace/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-namespace/options.json index ff150bf97657..b8b7c829daad 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-namespace/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/export-namespace/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'exportNamespaceFrom' (1:9)", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportNamespaceFrom' (1:9)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/import-meta/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/import-meta/options.json index ae56b0d5e7fe..48ce55a15d05 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/import-meta/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/import-meta/options.json @@ -1,6 +1,5 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:17)", + "throws": "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:17)", "sourceType": "module", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/input.js deleted file mode 100644 index 93e64fb4cac9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/input.js +++ /dev/null @@ -1 +0,0 @@ -({...x}) diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/options.json deleted file mode 100644 index e56fe7d7df85..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/object-rest-spread/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "throws": - "This experimental syntax requires enabling the parser plugin: 'objectRestSpread' (1:2)", - "plugins": [] -} diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining/options.json index 9a205fc1d32e..b8e170c94adb 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/optional-chaining/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'optionalChaining' (1:1)" + "throws": "This experimental syntax requires enabling the parser plugin: 'optionalChaining' (1:1)" } diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-no-asi/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-no-asi/options.json deleted file mode 100644 index f3c78ddb4f02..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/class-method-no-asi/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": - "This experimental syntax requires enabling the parser plugin: 'classProperties' (3:2)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-in/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-in/options.json deleted file mode 100644 index f8dd5c55d98e..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-in/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:19)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-1/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-1/options.json deleted file mode 100644 index f45f06d72ed4..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-1/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:13)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-2/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-2/options.json deleted file mode 100644 index c2c8f56374f4..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-2/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:22)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-3/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-3/options.json deleted file mode 100644 index ae405ee221c3..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/for-await-no-semi-3/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:18)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/async-generators/options.json b/packages/babel-parser/test/fixtures/experimental/async-generators/options.json deleted file mode 100644 index eea8c9d9d384..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/async-generators/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["asyncGenerators"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/options.json index 4b249f0aaaaa..8d265ec66c23 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/options.json @@ -1,3 +1,3 @@ { - "plugins": ["classPrivateMethods", "asyncGenerators"] + "plugins": ["classPrivateMethods"] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/output.json index 2ec8a62bd6d2..15456d810c09 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/async-generator/output.json @@ -523,7 +523,6 @@ "directives": [] }, "handler": null, - "guardedHandlers": [], "finalizer": { "type": "BlockStatement", "start": 173, diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json index 568c1237e9d6..15cf5cc8d413 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-no-plugin/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:2)", + "throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:2)", "plugins": ["classPrivateProperties"] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/input.js new file mode 100644 index 000000000000..b49e1327f4c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/input.js @@ -0,0 +1,5 @@ +class Spaces { + # wrongSpaces() { + return fail(); + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json new file mode 100644 index 000000000000..9914950b66fe --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Unexpected space between # and identifier (2:3)", + "plugins": ["classPrivateMethods"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json index 714877566f00..2ba960820f02 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-literal/options.json @@ -1,4 +1,4 @@ { - "throws": "Unexpected token (2:3)", + "throws": "Unexpected digit after hash token (2:2)", "plugins": ["classPrivateProperties"] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json index c1de1d488c13..2ba960820f02 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-numeric-start-identifier/options.json @@ -1,4 +1,4 @@ { - "throws": "Identifier directly after number (2:4)", + "throws": "Unexpected digit after hash token (2:2)", "plugins": ["classPrivateProperties"] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/input.js new file mode 100644 index 000000000000..023684c53e80 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/input.js @@ -0,0 +1,3 @@ +class Spaces { + # wrongSpaces; +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json new file mode 100644 index 000000000000..9914950b66fe --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json @@ -0,0 +1,4 @@ +{ + "throws": "Unexpected space between # and identifier (2:3)", + "plugins": ["classPrivateMethods"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/super-call/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/super-call/options.json index c4e5a9947939..2154c844bfd7 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/super-call/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/super-call/options.json @@ -1,5 +1,4 @@ { "plugins": ["classPrivateProperties"], - "throws": - "super() is only valid inside a class constructor. Make sure the method name is spelled exactly as 'constructor'. (4:13)" + "throws": "super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class? (4:13)" } diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/input.js b/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/input.js index 2e57778bbb21..91a95beaa1f9 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/input.js +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/input.js @@ -3,7 +3,7 @@ class Foo { y } -class Foo { +class Foo2 { p [m] () {} } diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/output.json b/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/output.json index 6f798008cbcf..1b75f5865de8 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/asi-success/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 52, + "end": 53, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 52, + "end": 53, "loc": { "start": { "line": 1, @@ -152,7 +152,7 @@ { "type": "ClassDeclaration", "start": 23, - "end": 52, + "end": 53, "loc": { "start": { "line": 6, @@ -166,7 +166,7 @@ "id": { "type": "Identifier", "start": 29, - "end": 32, + "end": 33, "loc": { "start": { "line": 6, @@ -174,21 +174,21 @@ }, "end": { "line": 6, - "column": 9 + "column": 10 }, - "identifierName": "Foo" + "identifierName": "Foo2" }, - "name": "Foo" + "name": "Foo2" }, "superClass": null, "body": { "type": "ClassBody", - "start": 33, - "end": 52, + "start": 34, + "end": 53, "loc": { "start": { "line": 6, - "column": 10 + "column": 11 }, "end": { "line": 9, @@ -198,8 +198,8 @@ "body": [ { "type": "ClassProperty", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 7, @@ -213,8 +213,8 @@ "static": false, "key": { "type": "Identifier", - "start": 37, - "end": 38, + "start": 38, + "end": 39, "loc": { "start": { "line": 7, @@ -233,8 +233,8 @@ }, { "type": "ClassMethod", - "start": 41, - "end": 50, + "start": 42, + "end": 51, "loc": { "start": { "line": 8, @@ -249,8 +249,8 @@ "computed": true, "key": { "type": "Identifier", - "start": 42, - "end": 43, + "start": 43, + "end": 44, "loc": { "start": { "line": 8, @@ -271,8 +271,8 @@ "params": [], "body": { "type": "BlockStatement", - "start": 48, - "end": 50, + "start": 49, + "end": 51, "loc": { "start": { "line": 8, diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/computed/input.js b/packages/babel-parser/test/fixtures/experimental/class-properties/computed/input.js index d3bc5e5d6fc6..a712d16ba66e 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/computed/input.js +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/computed/input.js @@ -3,7 +3,7 @@ class Foo { ['y'] } -class Foo { +class Foo2 { [p] [m] () {} } diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/computed/output.json b/packages/babel-parser/test/fixtures/experimental/class-properties/computed/output.json index 4b12933c424c..40771337a35f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/computed/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/computed/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 60, + "end": 61, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 60, + "end": 61, "loc": { "start": { "line": 1, @@ -155,7 +155,7 @@ { "type": "ClassDeclaration", "start": 29, - "end": 60, + "end": 61, "loc": { "start": { "line": 6, @@ -169,7 +169,7 @@ "id": { "type": "Identifier", "start": 35, - "end": 38, + "end": 39, "loc": { "start": { "line": 6, @@ -177,21 +177,21 @@ }, "end": { "line": 6, - "column": 9 + "column": 10 }, - "identifierName": "Foo" + "identifierName": "Foo2" }, - "name": "Foo" + "name": "Foo2" }, "superClass": null, "body": { "type": "ClassBody", - "start": 39, - "end": 60, + "start": 40, + "end": 61, "loc": { "start": { "line": 6, - "column": 10 + "column": 11 }, "end": { "line": 9, @@ -201,8 +201,8 @@ "body": [ { "type": "ClassProperty", - "start": 43, - "end": 46, + "start": 44, + "end": 47, "loc": { "start": { "line": 7, @@ -217,8 +217,8 @@ "computed": true, "key": { "type": "Identifier", - "start": 44, - "end": 45, + "start": 45, + "end": 46, "loc": { "start": { "line": 7, @@ -236,8 +236,8 @@ }, { "type": "ClassMethod", - "start": 49, - "end": 58, + "start": 50, + "end": 59, "loc": { "start": { "line": 8, @@ -252,8 +252,8 @@ "computed": true, "key": { "type": "Identifier", - "start": 50, - "end": 51, + "start": 51, + "end": 52, "loc": { "start": { "line": 8, @@ -274,8 +274,8 @@ "params": [], "body": { "type": "BlockStatement", - "start": 56, - "end": 58, + "start": 57, + "end": 59, "loc": { "start": { "line": 8, diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/super-call/options.json b/packages/babel-parser/test/fixtures/experimental/class-properties/super-call/options.json index 615953e7b7bb..e8d509e27740 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/super-call/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/super-call/options.json @@ -1,5 +1,4 @@ { "plugins": ["classProperties"], - "throws": - "super() is only valid inside a class constructor. Make sure the method name is spelled exactly as 'constructor'. (4:12)" + "throws": "super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class? (4:12)" } diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/input.js b/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/input.js index 6cc3a4087ca6..bcbcd17cdb47 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/input.js +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/input.js @@ -1,3 +1,3 @@ -class A { +class A extends B { foo = () => super.x(); } diff --git a/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/output.json b/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/output.json index bf0e39a95089..d411c6ff6e6f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/output.json +++ b/packages/babel-parser/test/fixtures/experimental/class-properties/super-inside-arrow-function/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 36, + "end": 46, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 36, + "end": 46, "loc": { "start": { "line": 1, @@ -32,7 +32,7 @@ { "type": "ClassDeclaration", "start": 0, - "end": 36, + "end": 46, "loc": { "start": { "line": 1, @@ -60,15 +60,31 @@ }, "name": "A" }, - "superClass": null, + "superClass": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "B" + }, + "name": "B" + }, "body": { "type": "ClassBody", - "start": 8, - "end": 36, + "start": 18, + "end": 46, "loc": { "start": { "line": 1, - "column": 8 + "column": 18 }, "end": { "line": 3, @@ -78,8 +94,8 @@ "body": [ { "type": "ClassProperty", - "start": 12, - "end": 34, + "start": 22, + "end": 44, "loc": { "start": { "line": 2, @@ -93,8 +109,8 @@ "static": false, "key": { "type": "Identifier", - "start": 12, - "end": 15, + "start": 22, + "end": 25, "loc": { "start": { "line": 2, @@ -111,8 +127,8 @@ "computed": false, "value": { "type": "ArrowFunctionExpression", - "start": 18, - "end": 33, + "start": 28, + "end": 43, "loc": { "start": { "line": 2, @@ -129,8 +145,8 @@ "params": [], "body": { "type": "CallExpression", - "start": 24, - "end": 33, + "start": 34, + "end": 43, "loc": { "start": { "line": 2, @@ -143,8 +159,8 @@ }, "callee": { "type": "MemberExpression", - "start": 24, - "end": 31, + "start": 34, + "end": 41, "loc": { "start": { "line": 2, @@ -157,8 +173,8 @@ }, "object": { "type": "Super", - "start": 24, - "end": 29, + "start": 34, + "end": 39, "loc": { "start": { "line": 2, @@ -172,8 +188,8 @@ }, "property": { "type": "Identifier", - "start": 30, - "end": 31, + "start": 40, + "end": 41, "loc": { "start": { "line": 2, diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-export-default-decorated-expression-without-parens/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-export-default-decorated-expression-without-parens/options.json index 2228d3b663d8..39592e4eb294 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-export-default-decorated-expression-without-parens/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-export-default-decorated-expression-without-parens/options.json @@ -1,6 +1,5 @@ { "sourceType": "module", "plugins": [["decorators", { "decoratorsBeforeExport": true }]], - "throws": - "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax (1:15)" + "throws": "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax (1:15)" } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-required/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-required/options.json index d4ebe6ec4190..3a1e80661a8f 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-required/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-required/options.json @@ -1,5 +1,4 @@ { "plugins": ["decorators"], - "throws": - "The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'." + "throws": "The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'." } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-true-decorator-after-export/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-true-decorator-after-export/options.json index bf5b0882589b..8fc06b1b8c69 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-true-decorator-after-export/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/decoratorsBeforeExport-true-decorator-after-export/options.json @@ -1,6 +1,5 @@ { "sourceType": "module", "plugins": [["decorators", { "decoratorsBeforeExport": true }]], - "throws": - "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax (1:7)" + "throws": "Decorators must be placed *before* the 'export' keyword. You can set the 'decoratorsBeforeExport' option to false to use the 'export @decorator class {}' syntax (1:7)" } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json index c3ea9d200b1b..5a8bd1e83883 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/export-decorated-class-without-plugin/options.json @@ -1,6 +1,5 @@ { "sourceType": "module", - "throws": - "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators, decorators-legacy' (1:7)", + "throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'decorators, decorators-legacy' (1:7)", "plugins": null } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json index ddf4b1f47c8b..cb54fc794402 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-export-decorators-on-class/options.json @@ -1,5 +1,4 @@ { "sourceType": "module", - "throws": - "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead. (2:0)" + "throws": "Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead. (2:0)" } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json index e885f2c0176d..7dd4ed9e2837 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json @@ -1,4 +1,3 @@ { - "throws": - "Stage 2 decorators disallow object literal property decorators (2:2)" + "throws": "Stage 2 decorators disallow object literal property decorators (2:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/input.js b/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/input.js new file mode 100644 index 000000000000..fe45bb8682d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/input.js @@ -0,0 +1,4 @@ +class Foo { + @deco + *generatorMethod() {} +} diff --git a/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/output.json b/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/output.json new file mode 100644 index 000000000000..8fb4c84a2e60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators/method-generator-decorator/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 14, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "deco" + }, + "name": "deco" + } + } + ], + "static": false, + "kind": "method", + "key": { + "type": "Identifier", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 18 + }, + "identifierName": "generatorMethod" + }, + "name": "generatorMethod" + }, + "computed": false, + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json b/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json index bf5a1cc8a75a..61c2c23daaae 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators-without-class/options.json @@ -1,5 +1,4 @@ { - "throws": - "You can only use decorators on an export when exporting a class (2:0)", + "throws": "You can only use decorators on an export when exporting a class (2:0)", "sourceType": "module" } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators/options.json b/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators/options.json index bf5a1cc8a75a..61c2c23daaae 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators/no-export-decorators/options.json @@ -1,5 +1,4 @@ { - "throws": - "You can only use decorators on an export when exporting a class (2:0)", + "throws": "You can only use decorators on an export when exporting a class (2:0)", "sourceType": "module" } diff --git a/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/input.js b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/input.js new file mode 100644 index 000000000000..eb88f1a997e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/input.js @@ -0,0 +1 @@ +new import("foo"); diff --git a/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/options.json b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/options.json new file mode 100644 index 000000000000..26e64ffc5d96 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-new/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot use new with import(...) (1:4)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/input.js b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/input.js new file mode 100644 index 000000000000..6596802add47 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/input.js @@ -0,0 +1 @@ +import("foo",); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/options.json b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/options.json new file mode 100644 index 000000000000..770750c7f91f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-trailing-comma/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Trailing comma is disallowed inside import(...) arguments (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/dynamic-import/no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/dynamic-import/no-plugin/options.json index 09561b2d687e..8036724beed2 100644 --- a/packages/babel-parser/test/fixtures/experimental/dynamic-import/no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/dynamic-import/no-plugin/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'dynamicImport' (1:0)", + "throws": "This experimental syntax requires enabling the parser plugin: 'dynamicImport' (1:0)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/export-extensions/default-and-named/output.json b/packages/babel-parser/test/fixtures/experimental/export-extensions/default-and-named/output.json index e4c389eba105..e65a50b154b0 100644 --- a/packages/babel-parser/test/fixtures/experimental/export-extensions/default-and-named/output.json +++ b/packages/babel-parser/test/fixtures/experimental/export-extensions/default-and-named/output.json @@ -145,7 +145,8 @@ "raw": "\"bar\"" }, "value": "bar" - } + }, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/experimental/export-extensions/export-with-ts/output.json b/packages/babel-parser/test/fixtures/experimental/export-extensions/export-with-ts/output.json index 1c9388e7c02b..912eb1b41745 100644 --- a/packages/babel-parser/test/fixtures/experimental/export-extensions/export-with-ts/output.json +++ b/packages/babel-parser/test/fixtures/experimental/export-extensions/export-with-ts/output.json @@ -114,12 +114,12 @@ "source": null, "declaration": { "type": "TSInterfaceDeclaration", - "start": 42, + "start": 34, "end": 56, "loc": { "start": { "line": 2, - "column": 15 + "column": 7 }, "end": { "line": 2, diff --git a/packages/babel-parser/test/fixtures/experimental/export-extensions/ns-and-named/output.json b/packages/babel-parser/test/fixtures/experimental/export-extensions/ns-and-named/output.json index 0cdcb04cb459..0c6d34007629 100644 --- a/packages/babel-parser/test/fixtures/experimental/export-extensions/ns-and-named/output.json +++ b/packages/babel-parser/test/fixtures/experimental/export-extensions/ns-and-named/output.json @@ -145,7 +145,8 @@ "raw": "\"bar\"" }, "value": "bar" - } + }, + "declaration": null } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json index 51cc8d68ea3f..991da279e599 100644 --- a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json +++ b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:11)" + "throws": "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:11)" } diff --git a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json index ec48aeabce6b..eee5abbf1f93 100644 --- a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json +++ b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:12)" + "throws": "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:12)" } diff --git a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json index 3cb65d1733f1..9ce89a133dca 100644 --- a/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json +++ b/packages/babel-parser/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:18)" + "throws": "This experimental syntax requires enabling the parser plugin: 'functionSent' (2:18)" } diff --git a/packages/babel-parser/test/fixtures/experimental/import-meta/without-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/import-meta/without-plugin/options.json index f53f788ae5ce..5956ed25f3dd 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-meta/without-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/import-meta/without-plugin/options.json @@ -1,5 +1,4 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:7)", + "throws": "This experimental syntax requires enabling the parser plugin: 'importMeta' (1:7)", "plugins": [] } diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-line-separator/output.json b/packages/babel-parser/test/fixtures/experimental/json-strings/directive-line-separator/output.json deleted file mode 100644 index 0a597e806399..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-line-separator/output.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 98, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 82 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 98, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 82 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [ - { - "type": "Directive", - "start": 0, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "value": { - "type": "DirectiveLiteral", - "start": 0, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "value": "before
after", - "extra": { - "raw": "\"before
after\"", - "rawValue": "before
after" - } - }, - "trailingComments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 16, - "end": 98, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 82 - } - } - } - ] - } - ] - }, - "comments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 16, - "end": 98, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 82 - } - } - } - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-paragraph-separator/output.json b/packages/babel-parser/test/fixtures/experimental/json-strings/directive-paragraph-separator/output.json deleted file mode 100644 index ad5a48a14c37..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/json-strings/directive-paragraph-separator/output.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 103, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 87 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 103, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 87 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [], - "directives": [ - { - "type": "Directive", - "start": 0, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "value": { - "type": "DirectiveLiteral", - "start": 0, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "value": "before
after", - "extra": { - "raw": "\"before
after\"", - "rawValue": "before
after" - } - }, - "trailingComments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 16, - "end": 103, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 87 - } - } - } - ] - } - ] - }, - "comments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 16, - "end": 103, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 87 - } - } - } - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/options.json b/packages/babel-parser/test/fixtures/experimental/json-strings/options.json deleted file mode 100644 index 81996860335a..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/json-strings/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["jsonStrings"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/string-line-separator/output.json b/packages/babel-parser/test/fixtures/experimental/json-strings/string-line-separator/output.json deleted file mode 100644 index 7dde2fc8ab29..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/json-strings/string-line-separator/output.json +++ /dev/null @@ -1,108 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 101, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 83 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 101, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 83 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start": 0, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "expression": { - "type": "StringLiteral", - "start": 1, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "extra": { - "rawValue": "before
after", - "raw": "\"before
after\"", - "parenthesized": true, - "parenStart": 0 - }, - "value": "before
after" - }, - "trailingComments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 18, - "end": 101, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 83 - } - } - } - ] - } - ], - "directives": [] - }, - "comments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 18, - "end": 101, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 83 - } - } - } - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/json-strings/string-paragraph-separator/output.json b/packages/babel-parser/test/fixtures/experimental/json-strings/string-paragraph-separator/output.json deleted file mode 100644 index d7dab40405e9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/json-strings/string-paragraph-separator/output.json +++ /dev/null @@ -1,108 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 106, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 88 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 106, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 88 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start": 0, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "expression": { - "type": "StringLiteral", - "start": 1, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "extra": { - "rawValue": "before
after", - "raw": "\"before
after\"", - "parenthesized": true, - "parenStart": 0 - }, - "value": "before
after" - }, - "trailingComments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 18, - "end": 106, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 88 - } - } - } - ] - } - ], - "directives": [] - }, - "comments": [ - { - "type": "CommentLine", - "value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')", - "start": 18, - "end": 106, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 88 - } - } - } - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/and-and-equals-no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/and-and-equals-no-plugin/options.json index dca714007eba..5b674fdee42e 100644 --- a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/and-and-equals-no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/and-and-equals-no-plugin/options.json @@ -1,5 +1,4 @@ { "plugins": [], - "throws": - "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/mallet-no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/mallet-no-plugin/options.json index dca714007eba..5b674fdee42e 100644 --- a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/mallet-no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/mallet-no-plugin/options.json @@ -1,5 +1,4 @@ { "plugins": [], - "throws": - "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-null-coalesce-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-null-coalesce-plugin/options.json index 4aab2b254ee7..3cb238ee4af0 100644 --- a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-null-coalesce-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-null-coalesce-plugin/options.json @@ -1,5 +1,4 @@ { "plugins": ["logicalAssignment"], - "throws": - "This experimental syntax requires enabling the parser plugin: 'nullishCoalescingOperator' (1:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'nullishCoalescingOperator' (1:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-plugin/options.json index a1cf5c9fda7c..f5e977775daf 100644 --- a/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/logical-assignment-operator/qq-equals-no-plugin/options.json @@ -1,5 +1,4 @@ { "plugins": ["nullishCoalescingOperator"], - "throws": - "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'logicalAssignment' (1:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/nullish-coalescing-operator/no-plugin-error/options.json b/packages/babel-parser/test/fixtures/experimental/nullish-coalescing-operator/no-plugin-error/options.json index 0904e05d8c5e..9ae9a3d8a5d1 100644 --- a/packages/babel-parser/test/fixtures/experimental/nullish-coalescing-operator/no-plugin-error/options.json +++ b/packages/babel-parser/test/fixtures/experimental/nullish-coalescing-operator/no-plugin-error/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'nullishCoalescingOperator' (1:4)" + "throws": "This experimental syntax requires enabling the parser plugin: 'nullishCoalescingOperator' (1:4)" } diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/11/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/11/options.json deleted file mode 100644 index 7c9cd8106fd9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/11/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sourceType": "module", - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:23)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/12/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/12/options.json deleted file mode 100644 index 566d19621890..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/12/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sourceType": "module", - "throws": - "`bar` has already been exported. Exported identifiers must be unique. (2:13)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/13/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/13/options.json deleted file mode 100644 index eef913e6fd20..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/13/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sourceType": "module", - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:30)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/14/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/14/options.json deleted file mode 100644 index 2c69619f7140..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/14/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sourceType": "module", - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:29)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/15/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/15/options.json deleted file mode 100644 index eef913e6fd20..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/15/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sourceType": "module", - "throws": - "`foo` has already been exported. Exported identifiers must be unique. (2:30)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/16/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/16/options.json deleted file mode 100644 index f65c23001ff1..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/16/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:8)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/17/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/17/options.json deleted file mode 100644 index bf0116a7b09f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/17/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/19/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/19/options.json deleted file mode 100644 index 6a9895dd9d8c..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/19/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:18)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/20/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/20/options.json deleted file mode 100644 index 6a9895dd9d8c..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/20/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:18)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/22/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/22/options.json deleted file mode 100644 index f65c23001ff1..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/22/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:8)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/23/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/23/options.json deleted file mode 100644 index 6a9895dd9d8c..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/23/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:18)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/25/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/25/options.json deleted file mode 100644 index f65c23001ff1..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/25/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:8)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/26/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/26/options.json deleted file mode 100644 index 6a9895dd9d8c..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/26/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Invalid rest operator's argument (1:18)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/7/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/7/options.json deleted file mode 100644 index eef8a7af3839..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/7/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": - "The rest element has to be the last element when destructuring (1:10)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/8/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/8/options.json deleted file mode 100644 index 4a97ac85eafa..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/8/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "A trailing comma is not permitted after the rest element (1:16)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/9/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/9/options.json deleted file mode 100644 index 03ba1e37e899..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/9/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Cannot have multiple rest elements when destructuring (1:13)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/expression-rest-not-last-invalid/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/expression-rest-not-last-invalid/options.json deleted file mode 100644 index 87b6e1b20fed..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/expression-rest-not-last-invalid/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": - "The rest element has to be the last element when destructuring (1:2)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/options.json b/packages/babel-parser/test/fixtures/experimental/object-rest-spread/options.json deleted file mode 100644 index 4de042a69733..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/object-rest-spread/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["objectRestSpread"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding-finally/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding-finally/options.json deleted file mode 100644 index e89b07f66d80..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding-finally/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": - "This experimental syntax requires enabling the parser plugin: 'optionalCatchBinding' (4:6)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding/options.json deleted file mode 100644 index e89b07f66d80..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-no-binding/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": - "This experimental syntax requires enabling the parser plugin: 'optionalCatchBinding' (4:6)" -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/input.js deleted file mode 100644 index e0a74b86fa60..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/input.js +++ /dev/null @@ -1,4 +0,0 @@ -try { -} catch (err) { -} finally { -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/output.json deleted file mode 100644 index c8261f6ba30f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding-finally/output.json +++ /dev/null @@ -1,134 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 8, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "param": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "err" - }, - "name": "err" - }, - "body": { - "type": "BlockStatement", - "start": 20, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": { - "type": "BlockStatement", - "start": 32, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/input.js deleted file mode 100644 index c68ec0293881..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/input.js +++ /dev/null @@ -1,2 +0,0 @@ -try { -} catch (err) {} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/output.json deleted file mode 100644 index f99c9541a456..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/no-plugin-yes-binding/output.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 8, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "param": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "err" - }, - "name": "err" - }, - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": null - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/input.js deleted file mode 100644 index 9faba4b001dc..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/input.js +++ /dev/null @@ -1,9 +0,0 @@ -try { - -} -catch { - -} -finally { - -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/options.json deleted file mode 100644 index b937a8bb5d2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["optionalCatchBinding"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/output.json deleted file mode 100644 index 4ebb1d0cb5c5..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding-finally/output.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 9, - "column": 1 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 9, - "end": 19, - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "param": null, - "body": { - "type": "BlockStatement", - "start": 15, - "end": 19, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": { - "type": "BlockStatement", - "start": 28, - "end": 34, - "loc": { - "start": { - "line": 7, - "column": 8 - }, - "end": { - "line": 9, - "column": 1 - } - }, - "body": [], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/input.js deleted file mode 100644 index 2550d2c262b7..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/input.js +++ /dev/null @@ -1,6 +0,0 @@ -try { - -} -catch { - -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/options.json deleted file mode 100644 index b937a8bb5d2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["optionalCatchBinding"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/output.json deleted file mode 100644 index 5124fdabae39..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-no-binding/output.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 9, - "end": 21, - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "param": null, - "body": { - "type": "BlockStatement", - "start": 15, - "end": 21, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": null - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/input.js deleted file mode 100644 index e0a74b86fa60..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/input.js +++ /dev/null @@ -1,4 +0,0 @@ -try { -} catch (err) { -} finally { -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/options.json deleted file mode 100644 index b937a8bb5d2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["optionalCatchBinding"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/output.json deleted file mode 100644 index c8261f6ba30f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding-finally/output.json +++ /dev/null @@ -1,134 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 8, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "param": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "err" - }, - "name": "err" - }, - "body": { - "type": "BlockStatement", - "start": 20, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": { - "type": "BlockStatement", - "start": 32, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [], - "directives": [] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/input.js b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/input.js deleted file mode 100644 index c68ec0293881..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/input.js +++ /dev/null @@ -1,2 +0,0 @@ -try { -} catch (err) {} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/options.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/options.json deleted file mode 100644 index b937a8bb5d2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["optionalCatchBinding"] -} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/output.json b/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/output.json deleted file mode 100644 index f99c9541a456..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/optional-catch-binding/yes-plugin-yes-binding/output.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "TryStatement", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "block": { - "type": "BlockStatement", - "start": 4, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 2, - "column": 1 - } - }, - "body": [], - "directives": [] - }, - "handler": { - "type": "CatchClause", - "start": 8, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "param": { - "type": "Identifier", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 9 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "err" - }, - "name": "err" - }, - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 2, - "column": 14 - }, - "end": { - "line": 2, - "column": 16 - } - }, - "body": [], - "directives": [] - } - }, - "guardedHandlers": [], - "finalizer": null - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/input.js b/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/input.js index 31dcb716ca78..c3fc230296b4 100644 --- a/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/input.js +++ b/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/input.js @@ -1,5 +1,5 @@ -class A{ +class A extends B { constructor(){ super()?.b; } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/output.json b/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/output.json index 877e7f493a3e..890c6f2248d6 100644 --- a/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/output.json +++ b/packages/babel-parser/test/fixtures/experimental/optional-chaining/super-method-class/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 55, + "end": 66, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 55, + "end": 66, "loc": { "start": { "line": 1, @@ -32,7 +32,7 @@ { "type": "ClassDeclaration", "start": 0, - "end": 55, + "end": 66, "loc": { "start": { "line": 1, @@ -60,15 +60,31 @@ }, "name": "A" }, - "superClass": null, + "superClass": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "B" + }, + "name": "B" + }, "body": { "type": "ClassBody", - "start": 7, - "end": 55, + "start": 18, + "end": 66, "loc": { "start": { "line": 1, - "column": 7 + "column": 18 }, "end": { "line": 5, @@ -78,8 +94,8 @@ "body": [ { "type": "ClassMethod", - "start": 13, - "end": 53, + "start": 24, + "end": 64, "loc": { "start": { "line": 2, @@ -93,8 +109,8 @@ "static": false, "key": { "type": "Identifier", - "start": 13, - "end": 24, + "start": 24, + "end": 35, "loc": { "start": { "line": 2, @@ -116,8 +132,8 @@ "params": [], "body": { "type": "BlockStatement", - "start": 26, - "end": 53, + "start": 37, + "end": 64, "loc": { "start": { "line": 2, @@ -131,8 +147,8 @@ "body": [ { "type": "ExpressionStatement", - "start": 36, - "end": 47, + "start": 47, + "end": 58, "loc": { "start": { "line": 3, @@ -145,8 +161,8 @@ }, "expression": { "type": "OptionalMemberExpression", - "start": 36, - "end": 46, + "start": 47, + "end": 57, "loc": { "start": { "line": 3, @@ -159,8 +175,8 @@ }, "object": { "type": "CallExpression", - "start": 36, - "end": 43, + "start": 47, + "end": 54, "loc": { "start": { "line": 3, @@ -173,8 +189,8 @@ }, "callee": { "type": "Super", - "start": 36, - "end": 41, + "start": 47, + "end": 52, "loc": { "start": { "line": 3, @@ -190,8 +206,8 @@ }, "property": { "type": "Identifier", - "start": 45, - "end": 46, + "start": 56, + "end": 57, "loc": { "start": { "line": 3, diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/input.js new file mode 100644 index 000000000000..74512f8aace5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/input.js @@ -0,0 +1 @@ +foo(?) diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/options.json new file mode 100644 index 000000000000..87414aef43de --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["partialApplication"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/output.json b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/output.json new file mode 100644 index 000000000000..ac7ce3111be1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-expr/output.json @@ -0,0 +1,99 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/input.js new file mode 100644 index 000000000000..ed9915fb3ccb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/input.js @@ -0,0 +1,5 @@ +class foo { + constructor() { + baz(this, () => super.bar(?)); + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/options.json new file mode 100644 index 000000000000..87414aef43de --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["partialApplication"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/output.json b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/output.json new file mode 100644 index 000000000000..39bdbf743956 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/call-on-SuperProperty/output.json @@ -0,0 +1,305 @@ +{ + "type": "File", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 78, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 16, + "end": 76, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 16, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "constructor" + }, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 30, + "end": 76, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 40, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "expression": { + "type": "CallExpression", + "start": 40, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "callee": { + "type": "Identifier", + "start": 40, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "baz" + }, + "name": "baz" + }, + "arguments": [ + { + "type": "ThisExpression", + "start": 44, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "ArrowFunctionExpression", + "start": 50, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "CallExpression", + "start": 56, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "callee": { + "type": "MemberExpression", + "start": 56, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 33 + } + }, + "object": { + "type": "Super", + "start": 56, + "end": 61, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + "property": { + "type": "Identifier", + "start": 62, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 33 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "computed": false + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ] + } + } + ] + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/input.js new file mode 100644 index 000000000000..58db6e91a913 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/input.js @@ -0,0 +1,3 @@ +foo(?,x,?) + +bar.foo(?, x, ?) diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/options.json new file mode 100644 index 000000000000..87414aef43de --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["partialApplication"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/output.json b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/output.json new file mode 100644 index 000000000000..61338f165056 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/for-any-arg/output.json @@ -0,0 +1,260 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "ArgumentPlaceholder", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 12, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "expression": { + "type": "CallExpression", + "start": 12, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "callee": { + "type": "MemberExpression", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "property": { + "type": "Identifier", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "ArgumentPlaceholder", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/input.js new file mode 100644 index 000000000000..c689537246d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/input.js @@ -0,0 +1,3 @@ +foo(x,?) + +bar.foo(x,?) diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/options.json new file mode 100644 index 000000000000..87414aef43de --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["partialApplication"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/output.json b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/output.json new file mode 100644 index 000000000000..59529de050d1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-left/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "ArgumentPlaceholder", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "expression": { + "type": "CallExpression", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "callee": { + "type": "MemberExpression", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "ArgumentPlaceholder", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/input.js new file mode 100644 index 000000000000..b566c1df5b1b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/input.js @@ -0,0 +1,3 @@ +foo(?,x) + +bar.foo(?,x) diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/options.json new file mode 100644 index 000000000000..87414aef43de --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["partialApplication"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/output.json b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/output.json new file mode 100644 index 000000000000..3b558a170e5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/from-right/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + } + ] + } + }, + { + "type": "ExpressionStatement", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "expression": { + "type": "CallExpression", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "callee": { + "type": "MemberExpression", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "object": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "property": { + "type": "Identifier", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false + }, + "arguments": [ + { + "type": "ArgumentPlaceholder", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/input.js new file mode 100644 index 000000000000..eac2ab9cb775 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/input.js @@ -0,0 +1,6 @@ +class Foo extends Bar { + constructor(x){ + super(x, 1, ?, ?); + this.x = x; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/options.json new file mode 100644 index 000000000000..58192a87fd99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/in-SuperCall/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["partialApplication"], + "throws": "Unexpected argument placeholder (3:16)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/input.js new file mode 100644 index 000000000000..36314ea52964 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/input.js @@ -0,0 +1 @@ +new bar(x, ?, 2, ?) diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/options.json new file mode 100644 index 000000000000..3b09c84c03eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/in-new/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["partialApplication"], + "throws": "Unexpected argument placeholder (1:11)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/input.js new file mode 100644 index 000000000000..a511c8bf7d89 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/input.js @@ -0,0 +1 @@ +? + x diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/options.json new file mode 100644 index 000000000000..8abbd078986f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-binary-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["partialApplication"], + "throws": "Unexpected token (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/input.js b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/input.js new file mode 100644 index 000000000000..3308d8780855 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/input.js @@ -0,0 +1 @@ +?.f() diff --git a/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/options.json b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/options.json new file mode 100644 index 000000000000..8abbd078986f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/partial-application/top-level-argument-method-call/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["partialApplication"], + "throws": "Unexpected token (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json index b6e4db397e22..d8fca74323cf 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/invalid-proposal/options.json @@ -1,5 +1,4 @@ { "plugins": [["pipelineOperator", { "proposal": "invalid" }]], - "throws": - "'pipelineOperator' requires 'proposal' option whose value should be one of: minimal" + "throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: 'minimal', 'smart', 'fsharp'" } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/no-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/no-plugin/options.json index aaaa3350b6fe..5d8a6bb1204c 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/no-plugin/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/no-plugin/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'pipelineOperator' (1:2)" + "throws": "This experimental syntax requires enabling the parser plugin: 'pipelineOperator' (1:2)" } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js new file mode 100644 index 000000000000..f06c47069191 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/input.js @@ -0,0 +1 @@ +x => x |> [y => y + 1 |> z => z * 2] diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json new file mode 100644 index 000000000000..0ed567f15eea --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body-with-operator/output.json @@ -0,0 +1,333 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "elements": [ + { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "left": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 25, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 30, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "left": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js new file mode 100644 index 000000000000..a61aacfe0129 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js @@ -0,0 +1 @@ +x => x |> [y => y + 1] |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json new file mode 100644 index 000000000000..ef37548ee98f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/output.json @@ -0,0 +1,333 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrayExpression", + "start": 10, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "elements": [ + { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ] + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 26, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js new file mode 100644 index 000000000000..a760dc479126 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/input.js @@ -0,0 +1 @@ +x => x |> foo(x = 1 |> foo); diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json new file mode 100644 index 000000000000..5f2e34747dfa --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-assignment-in-body/output.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "CallExpression", + "start": 10, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "callee": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "AssignmentExpression", + "start": 14, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "BinaryExpression", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "NumericLiteral", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js new file mode 100644 index 000000000000..bf7747377ff1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/input.js @@ -0,0 +1 @@ +x => x |> { method: y => y + 1 |> z => z * 2 } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json new file mode 100644 index 000000000000..de8143714401 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body-with-operator/output.json @@ -0,0 +1,368 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ObjectExpression", + "start": 10, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 12, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "method" + }, + "name": "method" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 20, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 25, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "left": { + "type": "BinaryExpression", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "left": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js new file mode 100644 index 000000000000..e797fb636228 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/input.js @@ -0,0 +1 @@ +x => x |> { method: y => y + 1 } |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json new file mode 100644 index 000000000000..d1e39e6ccea4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-object-in-body/output.json @@ -0,0 +1,368 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ObjectExpression", + "start": 10, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "method" + }, + "name": "method" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "left": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ] + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 36, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 41, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js new file mode 100644 index 000000000000..894495272a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/input.js @@ -0,0 +1 @@ +x => x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json new file mode 100644 index 000000000000..4f7a815237e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head-indented/output.json @@ -0,0 +1,170 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js new file mode 100644 index 000000000000..894495272a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/input.js @@ -0,0 +1 @@ +x => x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json new file mode 100644 index 000000000000..4f7a815237e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-at-head/output.json @@ -0,0 +1,170 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js new file mode 100644 index 000000000000..dcac94775c2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/input.js @@ -0,0 +1 @@ +x => x |> (y => y + 3 |> (b => y + b)) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json new file mode 100644 index 000000000000..fee1e93abafb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-alt-parens/output.json @@ -0,0 +1,321 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "left": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 26, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "b" + }, + "name": "b" + } + ], + "body": { + "type": "BinaryExpression", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + "extra": { + "parenthesized": true, + "parenStart": 25 + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 10 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js new file mode 100644 index 000000000000..f0867e85b19c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js @@ -0,0 +1,3 @@ +(x) => x + |> (y) => y + 1 + |> (z) => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json new file mode 100644 index 000000000000..313e3fa4b8cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 7, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "BinaryExpression", + "start": 7, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 14, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 32, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js new file mode 100644 index 000000000000..8e08f24df1fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/input.js @@ -0,0 +1,3 @@ +x => x + |> y => y + 1 + |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json new file mode 100644 index 000000000000..cf3c546e748d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js new file mode 100644 index 000000000000..dc05467170af --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/input.js @@ -0,0 +1 @@ +(x) => x |> (y) => y + 1 |> (z) => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json new file mode 100644 index 000000000000..06ac009ecf09 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-with-arg-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 7, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "left": { + "type": "BinaryExpression", + "start": 7, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "left": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js new file mode 100644 index 000000000000..010117c93787 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/input.js @@ -0,0 +1 @@ +x => x |> y => y + 1 |> z => z * 2 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json new file mode 100644 index 000000000000..31cd9f27dc38 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-in-body-no-parens/output.json @@ -0,0 +1,316 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "body": { + "type": "BinaryExpression", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "y" + }, + "name": "y" + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + }, + "operator": "|>", + "right": { + "type": "ArrowFunctionExpression", + "start": 24, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "z" + }, + "name": "z" + } + ], + "body": { + "type": "BinaryExpression", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "left": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "z" + }, + "name": "z" + }, + "operator": "*", + "right": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js new file mode 100644 index 000000000000..75e12145a31d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json new file mode 100644 index 000000000000..49c1e410dc02 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await-end/output.json @@ -0,0 +1,151 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 27, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "AwaitExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js new file mode 100644 index 000000000000..fb50c9400ea6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await |> f; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json new file mode 100644 index 000000000000..fa743ed7e4ad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json @@ -0,0 +1,184 @@ +{ + "type": "File", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "test" + }, + "name": "test" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 27, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 34, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "left": { + "type": "BinaryExpression", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "AwaitExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + }, + "identifierName": "f" + }, + "name": "f" + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js new file mode 100644 index 000000000000..380040513fd5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/input.js @@ -0,0 +1,3 @@ +async function test () { + return x |> await f; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json new file mode 100644 index 000000000000..b743604f7e0f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-ban-await-f/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]], + "throws": "Unexpected token, expected \";\" (2:20)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js new file mode 100644 index 000000000000..cf3443941ff0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/input.js @@ -0,0 +1 @@ +a |> b diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json new file mode 100644 index 000000000000..fbf187592a3e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-base/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "a" + }, + "name": "a" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js new file mode 100644 index 000000000000..0d1e8411dd06 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/input.js @@ -0,0 +1 @@ +x |> inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json new file mode 100644 index 000000000000..f95ecc7d6c23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "fsharp" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json new file mode 100644 index 000000000000..797dec673387 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-chain/output.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "inc" + }, + "name": "inc" + } + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await-f/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await-f/options.json index 7f92d28237e0..98b0d71d084e 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await-f/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await-f/options.json @@ -1,5 +1,4 @@ { "plugins": [["pipelineOperator", { "proposal": "minimal" }]], - "throws": - "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)" + "throws": "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)" } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await/options.json index 7f92d28237e0..98b0d71d084e 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await/options.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-minimal-ban-await/options.json @@ -1,5 +1,4 @@ { "plugins": [["pipelineOperator", { "proposal": "minimal" }]], - "throws": - "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)" + "throws": "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)" } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/input.js new file mode 100644 index 000000000000..49a8129b058f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/input.js @@ -0,0 +1,4 @@ +let result = "hello" +|> doubleSay +|> text.capitalize +|> a.b.exclaim; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/output.json new file mode 100644 index 000000000000..889bb7a69b62 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-multiline/output.json @@ -0,0 +1,348 @@ +{ + "type": "File", + "start": 0, + "end": 68, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 68, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 68, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 67, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "result" + }, + "name": "result" + }, + "init": { + "type": "BinaryExpression", + "start": 13, + "end": 67, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "left": { + "type": "BinaryExpression", + "start": 13, + "end": 52, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "left": { + "type": "BinaryExpression", + "start": 13, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "left": { + "type": "StringLiteral", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "extra": { + "rawValue": "hello", + "raw": "\"hello\"" + }, + "value": "hello" + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 24, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 24, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "doubleSay" + }, + "name": "doubleSay" + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 37, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "callee": { + "type": "MemberExpression", + "start": 37, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 37, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "text" + }, + "name": "text" + }, + "property": { + "type": "Identifier", + "start": 42, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 18 + }, + "identifierName": "capitalize" + }, + "name": "capitalize" + }, + "computed": false + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 56, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "callee": { + "type": "MemberExpression", + "start": 56, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "object": { + "type": "MemberExpression", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "object": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "property": { + "type": "Identifier", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "start": 60, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 14 + }, + "identifierName": "exclaim" + }, + "name": "exclaim" + }, + "computed": false + } + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/input.js new file mode 100644 index 000000000000..253a8fdfddf9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/input.js @@ -0,0 +1 @@ +x => x |> number.inc |> double diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/output.json new file mode 100644 index 000000000000..71953d9db9ce --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-chained,-single-line-arrow-function/output.json @@ -0,0 +1,233 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + ], + "body": { + "type": "BinaryExpression", + "start": 5, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "left": { + "type": "BinaryExpression", + "start": 5, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "left": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "callee": { + "type": "MemberExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "object": { + "type": "Identifier", + "start": 10, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "number" + }, + "name": "number" + }, + "property": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "inc" + }, + "name": "inc" + }, + "computed": false + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "callee": { + "type": "Identifier", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "double" + }, + "name": "double" + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/input.js new file mode 100644 index 000000000000..15a3d7657b9c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/input.js @@ -0,0 +1 @@ +value |> f diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/output.json new file mode 100644 index 000000000000..0aef90100fb5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-identifier/output.json @@ -0,0 +1,115 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "f" + }, + "name": "f" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/input.js new file mode 100644 index 000000000000..9f9ac30d8f48 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/input.js @@ -0,0 +1 @@ +value |> a.b.c.f diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/output.json new file mode 100644 index 000000000000..0fbd40308b71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-bare-style,-function-calls,-single,-property/output.json @@ -0,0 +1,214 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "callee": { + "type": "MemberExpression", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "object": { + "type": "MemberExpression", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "object": { + "type": "MemberExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "object": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "a" + }, + "name": "a" + }, + "property": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "b" + }, + "name": "b" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "c" + }, + "name": "c" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "f" + }, + "name": "f" + }, + "computed": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/input.js new file mode 100644 index 000000000000..a93aa77bbd74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/input.js @@ -0,0 +1 @@ +(1, 2) |> f; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/options.json new file mode 100644 index 000000000000..cc2c16a778e7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-bare-style,-head-with-topic-reference-pair/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline head should not be a comma-separated sequence expression (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/input.js new file mode 100644 index 000000000000..b18a6404b537 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/input.js @@ -0,0 +1 @@ +x |> #42; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json new file mode 100644 index 000000000000..a2f6f625f90c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-invalid-hash-token,-followed-by-digit/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Unexpected digit after hash token (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/input.js new file mode 100644 index 000000000000..194b4e64ed1f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/input.js @@ -0,0 +1 @@ +x |> ($ => $ |> f) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/options.json new file mode 100644 index 000000000000..d2b32f77521a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-bare-style,-no-outer-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/input.js new file mode 100644 index 000000000000..98e99a4493f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/input.js @@ -0,0 +1 @@ +x |> ($ => # |> $ + 1) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/options.json new file mode 100644 index 000000000000..e9eab6b46fe9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-inner-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:16)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/input.js new file mode 100644 index 000000000000..a4723737f3b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/input.js @@ -0,0 +1 @@ +x |> ($ => $ |> #) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/options.json new file mode 100644 index 000000000000..d2b32f77521a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-arrow-function-with-topic-style,-no-outer-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/input.js new file mode 100644 index 000000000000..50b90bb9adf9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/input.js @@ -0,0 +1 @@ +x |> (# |> f()) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/options.json new file mode 100644 index 000000000000..bdf0547df8f9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-inner-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:11)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/input.js new file mode 100644 index 000000000000..9d00837048ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/input.js @@ -0,0 +1 @@ +x |> ($ |> f) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/options.json new file mode 100644 index 000000000000..d2b32f77521a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-nested-pipelines,-topic-style-with-inner-topic-style,-no-outer-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/input.js new file mode 100644 index 000000000000..a6146afadab6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/input.js @@ -0,0 +1 @@ +10 |> (#, #) |> h; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/options.json new file mode 100644 index 000000000000..fe3873ecc67f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-followed-by-bare-style-pipeline-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline body may not be a comma-separated sequence expression (1:6)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/input.js new file mode 100644 index 000000000000..7da42e013c11 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/input.js @@ -0,0 +1 @@ +10 |> (#, #); diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/options.json new file mode 100644 index 000000000000..fe3873ecc67f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-sequence-style,-body-with-topic-reference-pair-then-end/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline body may not be a comma-separated sequence expression (1:6)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/input.js new file mode 100644 index 000000000000..5a02dee8ec60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/input.js @@ -0,0 +1 @@ +value |> a[b] diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/options.json new file mode 100644 index 000000000000..7a4451381c91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-computed,-no-topic-reference/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/input.js new file mode 100644 index 000000000000..e952adac15fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/input.js @@ -0,0 +1 @@ +value |> a + b diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/options.json new file mode 100644 index 000000000000..7a4451381c91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-addition/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/input.js new file mode 100644 index 000000000000..6ccb6ca13351 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/input.js @@ -0,0 +1 @@ +value |> class { } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/options.json new file mode 100644 index 000000000000..7a4451381c91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-class-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/input.js new file mode 100644 index 000000000000..faf09879d637 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/input.js @@ -0,0 +1 @@ +value |> function (x) { return; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/options.json new file mode 100644 index 000000000000..7a4451381c91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-no-topic-reference,-function-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Pipeline is in topic style but does not use topic reference (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..c1005576b7d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1 @@ +value |> do { do x += # while (x < 50); } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..3b7a52d71cf7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:22)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..261f95e4c7d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1,3 @@ +async function af () { + value |> do { for await (const e of sequence) #; } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..d117d235099d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + ["pipelineOperator", { "proposal": "smart" }], + "doExpressions", + "asyncGenerators" + ], + "throws": "Topic reference was used in a lexical context without topic binding (2:48)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..e0eb815c73fb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1 @@ +value |> do { for (let i = 0; i < n; i += 1) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..35e8658a93da --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:45)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..f6ebfaf94818 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1 @@ +value |> do { for (e in object) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..6e8b4a6f0d95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:32)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..b3350a5ad5e0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1 @@ +value |> do { for (e of sequence) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..a3707cc91710 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:34)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/input.js new file mode 100644 index 000000000000..bd64c4dd8768 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/input.js @@ -0,0 +1,4 @@ +value |> do { + try { JSON.parse(#); } + catch (error) { console.error(#); } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/options.json new file mode 100644 index 000000000000..0f40a90d2204 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-try-statement,-outer-topic-reference-in-catch-clause/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (3:32)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/input.js new file mode 100644 index 000000000000..06cfc1f2bed0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/input.js @@ -0,0 +1 @@ +value |> do { while (x < 50) x += #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/options.json new file mode 100644 index 000000000000..a3707cc91710 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-while-loop,-outer-topic-reference-in-loop-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:34)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/input.js new file mode 100644 index 000000000000..4872290c9926 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/input.js @@ -0,0 +1 @@ +value |> do { with ({}) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/options.json new file mode 100644 index 000000000000..fee1ffebc044 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unbound-topic,-do-expression,-with-statement,-outer-topic-reference-in-with-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"], + "throws": "Topic reference was used in a lexical context without topic binding (1:24)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/input.js new file mode 100644 index 000000000000..00d1c2320d2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/input.js @@ -0,0 +1 @@ +10 |> x => x + #; diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/options.json new file mode 100644 index 000000000000..a684795fbfb9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-topic-style,-unparenthesized-arrow-function-with-bare-parameter-and-bare-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Unexpected arrow \"=>\" after pipeline body; arrow function in pipeline body must be parenthesized (1:8)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/input.js new file mode 100644 index 000000000000..a905d1b71159 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/input.js @@ -0,0 +1 @@ +x |> class { constructor () { this.x = #; } } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/options.json new file mode 100644 index 000000000000..6401af97db12 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-class-in-pipeline-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Topic reference was used in a lexical context without topic binding (1:39)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/input.js new file mode 100644 index 000000000000..8af92dbefe4a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/input.js @@ -0,0 +1 @@ +x |> function () { # } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/options.json new file mode 100644 index 000000000000..e6731253189f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-inner-function-in-pipeline-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Topic reference was used in a lexical context without topic binding (1:19)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/input.js new file mode 100644 index 000000000000..818748040ed7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/input.js @@ -0,0 +1 @@ +x |> function () { # |> # } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/options.json new file mode 100644 index 000000000000..e6731253189f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-pipeline-head-in-inner-function-in-pipeline-body/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Topic reference was used in a lexical context without topic binding (1:19)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/input.js new file mode 100644 index 000000000000..2d07bd7883dc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/input.js @@ -0,0 +1 @@ +1 + # diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/options.json new file mode 100644 index 000000000000..736cde0e101d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-error,-unbound-topic,-simple/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]], + "throws": "Unexpected token (1:4)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/input.js new file mode 100644 index 000000000000..a5a21763a8eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/input.js @@ -0,0 +1 @@ +x |> (() => # |> f) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/output.json new file mode 100644 index 000000000000..20fef485fd61 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-bare-style/output.json @@ -0,0 +1,184 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "f" + }, + "name": "f" + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 5 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/input.js new file mode 100644 index 000000000000..e8fc8e430b8e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/input.js @@ -0,0 +1 @@ +x |> ($ => # |> f(#, $)) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/output.json new file mode 100644 index 000000000000..ae7bef130c84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-arrow-function-with-topic-style/output.json @@ -0,0 +1,251 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 5, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 6, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "$" + }, + "name": "$" + } + ], + "body": { + "type": "BinaryExpression", + "start": 11, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "CallExpression", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "callee": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + }, + "identifierName": "$" + }, + "name": "$" + } + ] + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 5 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/input.js new file mode 100644 index 000000000000..a462b80cbbd8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/input.js @@ -0,0 +1 @@ +x |> (# |> f) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/output.json new file mode 100644 index 000000000000..51d79d3318da --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-bare-style/output.json @@ -0,0 +1,165 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineBareFunction", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "f" + }, + "name": "f" + } + }, + "extra": { + "parenthesized": true, + "parenStart": 5 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/input.js new file mode 100644 index 000000000000..2668daa465d1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/input.js @@ -0,0 +1 @@ +x |> (# |> f(#, x)) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/output.json new file mode 100644 index 000000000000..7b38baf9008c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-nested-pipelines,-topic-style-with-inner-topic-style/output.json @@ -0,0 +1,214 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 6, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 11, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "CallExpression", + "start": 11, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "x" + }, + "name": "x" + } + ] + } + }, + "extra": { + "parenthesized": true, + "parenStart": 5 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/input.js new file mode 100644 index 000000000000..9d3fa9212120 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/input.js @@ -0,0 +1 @@ +value |> # + 1 diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/output.json new file mode 100644 index 000000000000..195e3bb795f5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-first/output.json @@ -0,0 +1,149 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/input.js new file mode 100644 index 000000000000..64ea7f0bcd1e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/input.js @@ -0,0 +1 @@ +value |> 1 + # diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/output.json new file mode 100644 index 000000000000..3a206964c2bd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-addition,-single-line-arrow-function,-topic-reference-last/output.json @@ -0,0 +1,149 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "left": { + "type": "NumericLiteral", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "operator": "+", + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/input.js new file mode 100644 index 000000000000..ea421c59a0f3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/input.js @@ -0,0 +1,3 @@ +async function f () { + return x |> await #; +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/output.json new file mode 100644 index 000000000000..9337eb29bf60 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-async-await/output.json @@ -0,0 +1,181 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 24, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 31, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 36, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "expression": { + "type": "AwaitExpression", + "start": 36, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "argument": { + "type": "PipelinePrimaryTopicReference", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..e5917937bc70 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1 @@ +value |> do { do x += 1; while (x < #); } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..18b3068859d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-do-while-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,262 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "body": [ + { + "type": "DoWhileStatement", + "start": 14, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "body": { + "type": "ExpressionStatement", + "start": 17, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "operator": "+=", + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + }, + "test": { + "type": "BinaryExpression", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "left": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "<", + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + } + } + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..197761dcd742 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1,3 @@ +async function af () { + value |> do { for await (const e of #) e; } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..680f780892b7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + ["pipelineOperator", { "proposal": "smart" }], + "doExpressions", + "asyncGenerators" + ] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..15b7a61ce7ba --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-await-of-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,298 @@ +{ + "type": "File", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "af" + }, + "name": "af" + }, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 70, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 25, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 25, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "left": { + "type": "Identifier", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 34, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "expression": { + "type": "DoExpression", + "start": 34, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "body": { + "type": "BlockStatement", + "start": 37, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "body": [ + { + "type": "ForOfStatement", + "start": 39, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "await": true, + "left": { + "type": "VariableDeclaration", + "start": 50, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + }, + "identifierName": "e" + }, + "name": "e" + }, + "init": null + } + ], + "kind": "const" + }, + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + } + }, + "body": { + "type": "ExpressionStatement", + "start": 64, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "expression": { + "type": "Identifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + }, + "identifierName": "e" + }, + "name": "e" + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..1e14a50cda84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1 @@ +value |> do { for (let i = #; predicate(i, #); i += #) i; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..2fb6945eeb76 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-classic-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,357 @@ +{ + "type": "File", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 59, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 59 + } + }, + "body": [ + { + "type": "ForStatement", + "start": 14, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 57 + } + }, + "init": { + "type": "VariableDeclaration", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": { + "type": "PipelinePrimaryTopicReference", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + } + ], + "kind": "let" + }, + "test": { + "type": "CallExpression", + "start": 30, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "callee": { + "type": "Identifier", + "start": 30, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 39 + }, + "identifierName": "predicate" + }, + "name": "predicate" + }, + "arguments": [ + { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + }, + "identifierName": "i" + }, + "name": "i" + }, + { + "type": "PipelinePrimaryTopicReference", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 44 + } + } + } + ] + }, + "update": { + "type": "AssignmentExpression", + "start": 47, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "operator": "+=", + "left": { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 48 + }, + "identifierName": "i" + }, + "name": "i" + }, + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 53 + } + } + } + }, + "body": { + "type": "ExpressionStatement", + "start": 55, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 57 + } + }, + "expression": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 56 + }, + "identifierName": "i" + }, + "name": "i" + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..096c359535e5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1 @@ +value |> do { for (e in #) e; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..4571a8f3b91e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-in-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,210 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "body": [ + { + "type": "ForInStatement", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "e" + }, + "name": "e" + }, + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + "body": { + "type": "ExpressionStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "e" + }, + "name": "e" + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..b3e5f40ef7fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1 @@ +value |> do { for (e of #) e; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..25757328ebef --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-for-of-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,211 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "body": [ + { + "type": "ForOfStatement", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "await": false, + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "e" + }, + "name": "e" + }, + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + "body": { + "type": "ExpressionStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "e" + }, + "name": "e" + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/input.js new file mode 100644 index 000000000000..f78ceb724f12 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/input.js @@ -0,0 +1 @@ +value |> do { #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json new file mode 100644 index 000000000000..d0c29a3cc724 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-identity/output.json @@ -0,0 +1,161 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/input.js new file mode 100644 index 000000000000..b4c8778046ed --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/input.js @@ -0,0 +1 @@ +value |> do { if (yes) null; else if (no) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json new file mode 100644 index 000000000000..be74d493c27c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-body/output.json @@ -0,0 +1,256 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 14, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "test": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "yes" + }, + "name": "yes" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "NullLiteral", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + }, + "alternate": { + "type": "IfStatement", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "test": { + "type": "Identifier", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "no" + }, + "name": "no" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 43 + } + } + } + }, + "alternate": null + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/input.js new file mode 100644 index 000000000000..0b1fd66aaa3c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/input.js @@ -0,0 +1 @@ +value |> do { if (yes) null; else #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json new file mode 100644 index 000000000000..eb53ce59a775 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-else-if-body/output.json @@ -0,0 +1,223 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 14, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "test": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "yes" + }, + "name": "yes" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "expression": { + "type": "NullLiteral", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + }, + "alternate": { + "type": "ExpressionStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + } + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/input.js new file mode 100644 index 000000000000..bd64bfb5b763 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/input.js @@ -0,0 +1 @@ +value |> do { if (yes) #; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json new file mode 100644 index 000000000000..501bbac6fa08 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-body/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 14, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "test": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "yes" + }, + "name": "yes" + }, + "consequent": { + "type": "ExpressionStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + } + }, + "alternate": null + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/input.js new file mode 100644 index 000000000000..8457c4e57f71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/input.js @@ -0,0 +1 @@ +value |> do { if (#) 1; else 0; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json new file mode 100644 index 000000000000..e2fb435ec82b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-if-statement,-outer-topic-reference-in-if-head/output.json @@ -0,0 +1,231 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 14, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "test": { + "type": "PipelinePrimaryTopicReference", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "consequent": { + "type": "ExpressionStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "alternate": { + "type": "ExpressionStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/input.js new file mode 100644 index 000000000000..c9562d43181c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/input.js @@ -0,0 +1,7 @@ +value |> do { + switch (number) { + case 0: #; + case 1: # + 1; + default: # + 10; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json new file mode 100644 index 000000000000..7ab18f8fbcfc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-body/output.json @@ -0,0 +1,419 @@ +{ + "type": "File", + "start": 0, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 94, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "SwitchStatement", + "start": 16, + "end": 92, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "discriminant": { + "type": "Identifier", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "number" + }, + "name": "number" + }, + "cases": [ + { + "type": "SwitchCase", + "start": 38, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + } + ], + "test": { + "type": "NumericLiteral", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "SwitchCase", + "start": 53, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 61, + "end": 67, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 61, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "test": { + "type": "NumericLiteral", + "start": 58, + "end": 59, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "SwitchCase", + "start": 72, + "end": 88, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 81, + "end": 88, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 20 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 81, + "end": 87, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 85, + "end": 87, + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 19 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + } + } + ], + "test": null + } + ] + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/input.js new file mode 100644 index 000000000000..77e4a2ddcf2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/input.js @@ -0,0 +1,7 @@ +value |> do { + switch (#) { + case 0: 50; + case 1: 60; + default: 70; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json new file mode 100644 index 000000000000..75c247866713 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-switch-statement,-outer-topic-reference-in-switch-head/output.json @@ -0,0 +1,360 @@ +{ + "type": "File", + "start": 0, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 83, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "SwitchStatement", + "start": 16, + "end": 81, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "discriminant": { + "type": "PipelinePrimaryTopicReference", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "cases": [ + { + "type": "SwitchCase", + "start": 33, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 41, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "extra": { + "rawValue": 50, + "raw": "50" + }, + "value": 50 + } + } + ], + "test": { + "type": "NumericLiteral", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "SwitchCase", + "start": 49, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 57, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 57, + "end": 59, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "extra": { + "rawValue": 60, + "raw": "60" + }, + "value": 60 + } + } + ], + "test": { + "type": "NumericLiteral", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "SwitchCase", + "start": 65, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "consequent": [ + { + "type": "ExpressionStatement", + "start": 74, + "end": 77, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 74, + "end": 76, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "extra": { + "rawValue": 70, + "raw": "70" + }, + "value": 70 + } + } + ], + "test": null + } + ] + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/input.js new file mode 100644 index 000000000000..46ec28c2e777 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/input.js @@ -0,0 +1,5 @@ +value |> do { + try { JSON.parse(whatever); } + catch (error) { console.error(error); } + finally { something(#); } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json new file mode 100644 index 000000000000..a2feff08dcac --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-finally-clause-with-catch-and-finally/output.json @@ -0,0 +1,494 @@ +{ + "type": "File", + "start": 0, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 117, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 16, + "end": 115, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "block": { + "type": "BlockStatement", + "start": 20, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 22, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "CallExpression", + "start": 22, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "callee": { + "type": "MemberExpression", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "JSON" + }, + "name": "JSON" + }, + "property": { + "type": "Identifier", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "parse" + }, + "name": "parse" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 33, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "whatever" + }, + "name": "whatever" + } + ] + } + } + ], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 48, + "end": 87, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "param": { + "type": "Identifier", + "start": 55, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "error" + }, + "name": "error" + }, + "body": { + "type": "BlockStatement", + "start": 62, + "end": 87, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 64, + "end": 85, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "expression": { + "type": "CallExpression", + "start": 64, + "end": 84, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "callee": { + "type": "MemberExpression", + "start": 64, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "object": { + "type": "Identifier", + "start": 64, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 25 + }, + "identifierName": "console" + }, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 72, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + }, + "identifierName": "error" + }, + "name": "error" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 78, + "end": 83, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 37 + }, + "identifierName": "error" + }, + "name": "error" + } + ] + } + } + ], + "directives": [] + } + }, + "finalizer": { + "type": "BlockStatement", + "start": 98, + "end": 115, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 100, + "end": 113, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "expression": { + "type": "CallExpression", + "start": 100, + "end": 112, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "callee": { + "type": "Identifier", + "start": 100, + "end": 109, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 21 + }, + "identifierName": "something" + }, + "name": "something" + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 110, + "end": 111, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + } + } + } + ] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/input.js new file mode 100644 index 000000000000..dd034b608161 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/input.js @@ -0,0 +1,5 @@ +value |> do { + try { JSON.parse(#); } + catch (error) { console.error(error); } + finally { something(); } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json new file mode 100644 index 000000000000..95c03c8c90e3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch-and-finally/output.json @@ -0,0 +1,476 @@ +{ + "type": "File", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 16, + "end": 107, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "block": { + "type": "BlockStatement", + "start": 20, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "start": 22, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "callee": { + "type": "MemberExpression", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "JSON" + }, + "name": "JSON" + }, + "property": { + "type": "Identifier", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "parse" + }, + "name": "parse" + }, + "computed": false + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ] + } + } + ], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 41, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "param": { + "type": "Identifier", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "error" + }, + "name": "error" + }, + "body": { + "type": "BlockStatement", + "start": 55, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 57, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "expression": { + "type": "CallExpression", + "start": 57, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "callee": { + "type": "MemberExpression", + "start": 57, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "object": { + "type": "Identifier", + "start": 57, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 25 + }, + "identifierName": "console" + }, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 65, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + }, + "identifierName": "error" + }, + "name": "error" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 71, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 37 + }, + "identifierName": "error" + }, + "name": "error" + } + ] + } + } + ], + "directives": [] + } + }, + "finalizer": { + "type": "BlockStatement", + "start": 91, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 93, + "end": 105, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "expression": { + "type": "CallExpression", + "start": 93, + "end": 104, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "callee": { + "type": "Identifier", + "start": 93, + "end": 102, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 21 + }, + "identifierName": "something" + }, + "name": "something" + }, + "arguments": [] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/input.js new file mode 100644 index 000000000000..70eb5263f217 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/input.js @@ -0,0 +1,4 @@ +value |> do { + try { JSON.parse(#); } + catch (error) { console.error(error); } +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json new file mode 100644 index 000000000000..cf2f95415e23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-try-statement,-outer-topic-reference-in-try-clause-with-catch/output.json @@ -0,0 +1,411 @@ +{ + "type": "File", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 82, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "TryStatement", + "start": 16, + "end": 80, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "block": { + "type": "BlockStatement", + "start": 20, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "start": 22, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "callee": { + "type": "MemberExpression", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "object": { + "type": "Identifier", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "JSON" + }, + "name": "JSON" + }, + "property": { + "type": "Identifier", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + }, + "identifierName": "parse" + }, + "name": "parse" + }, + "computed": false + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ] + } + } + ], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 41, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "param": { + "type": "Identifier", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "error" + }, + "name": "error" + }, + "body": { + "type": "BlockStatement", + "start": 55, + "end": 80, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 41 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 57, + "end": 78, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "expression": { + "type": "CallExpression", + "start": 57, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "callee": { + "type": "MemberExpression", + "start": 57, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "object": { + "type": "Identifier", + "start": 57, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 25 + }, + "identifierName": "console" + }, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 65, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + }, + "identifierName": "error" + }, + "name": "error" + }, + "computed": false + }, + "arguments": [ + { + "type": "Identifier", + "start": 71, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 37 + }, + "identifierName": "error" + }, + "name": "error" + } + ] + } + } + ], + "directives": [] + } + }, + "finalizer": null + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/input.js new file mode 100644 index 000000000000..be802107159e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/input.js @@ -0,0 +1 @@ +value |> do { while (x < #) x += 1; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/options.json new file mode 100644 index 000000000000..edb7679c6a74 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json new file mode 100644 index 000000000000..e3714c89c3b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-do-expression,-while-loop,-outer-topic-reference-in-loop-head/output.json @@ -0,0 +1,262 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "expression": { + "type": "DoExpression", + "start": 9, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "body": [ + { + "type": "WhileStatement", + "start": 14, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "test": { + "type": "BinaryExpression", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "<", + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + } + }, + "body": { + "type": "ExpressionStatement", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 28, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "operator": "+=", + "left": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/input.js new file mode 100644 index 000000000000..e8678f6a2bb1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/input.js @@ -0,0 +1 @@ +value |> f(#) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/output.json new file mode 100644 index 000000000000..3ee59b9da5c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-call,-identifier-with-topic-reference/output.json @@ -0,0 +1,147 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "CallExpression", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [ + { + "type": "PipelinePrimaryTopicReference", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + } + ] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/input.js new file mode 100644 index 000000000000..432d1c9ed8c7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/input.js @@ -0,0 +1 @@ +value |> function (x = #) { return x; } diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/output.json new file mode 100644 index 000000000000..c5ba3fb13a9c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-function-definition,-outer-topic-reference-in-default-parameter-expression/output.json @@ -0,0 +1,215 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 9, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "left": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "PipelinePrimaryTopicReference", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 26, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 28, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "argument": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ], + "directives": [] + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/input.js new file mode 100644 index 000000000000..c35ae3c9db32 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/input.js @@ -0,0 +1,3 @@ +function * f () { + return x |> (yield #); +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/output.json new file mode 100644 index 000000000000..ad59accc2de2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-generator-yield/output.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 20, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "argument": { + "type": "BinaryExpression", + "start": 27, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "left": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 32, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "expression": { + "type": "YieldExpression", + "start": 33, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "delegate": false, + "argument": { + "type": "PipelinePrimaryTopicReference", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 32 + } + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/input.js new file mode 100644 index 000000000000..a7abc2dc18f7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/input.js @@ -0,0 +1 @@ +value |> (#) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/output.json new file mode 100644 index 000000000000..3d951c7dcb90 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-parenthesized/output.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "extra": { + "parenthesized": true, + "parenStart": 9 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/input.js new file mode 100644 index 000000000000..a18cbd0f1bb2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/input.js @@ -0,0 +1 @@ +value |> # diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/output.json new file mode 100644 index 000000000000..147e066345a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-identity,-unparenthesized/output.json @@ -0,0 +1,113 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/input.js new file mode 100644 index 000000000000..a18cbd0f1bb2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/input.js @@ -0,0 +1 @@ +value |> # diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/options.json new file mode 100644 index 000000000000..887155e27e68 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }], "pipelineOperator"] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/output.json new file mode 100644 index 000000000000..147e066345a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-mixed-pipeline-plugins/output.json @@ -0,0 +1,113 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "PipelinePrimaryTopicReference", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/input.js b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/input.js new file mode 100644 index 000000000000..7f3f814efd71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/input.js @@ -0,0 +1 @@ +value |> (() => # + 1) diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/options.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/options.json new file mode 100644 index 000000000000..17e4e327bbad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["pipelineOperator", { "proposal": "smart" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/output.json new file mode 100644 index 000000000000..23ba6b6a9dd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-smart-topic-style,-parenthesized-single-line-arrow-function,-with-empty-parameter-list-and-bare-addition-body/output.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "value" + }, + "name": "value" + }, + "operator": "|>", + "right": { + "type": "PipelineTopicExpression", + "start": 9, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "PipelinePrimaryTopicReference", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "parenthesized": true, + "parenStart": 9 + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/throw-expression/not-enabled/options.json b/packages/babel-parser/test/fixtures/experimental/throw-expression/not-enabled/options.json index 9b86aff45968..47934f708223 100644 --- a/packages/babel-parser/test/fixtures/experimental/throw-expression/not-enabled/options.json +++ b/packages/babel-parser/test/fixtures/experimental/throw-expression/not-enabled/options.json @@ -1,4 +1,3 @@ { - "throws": - "This experimental syntax requires enabling the parser plugin: 'throwExpressions' (2:3)" + "throws": "This experimental syntax requires enabling the parser plugin: 'throwExpressions' (2:3)" } diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/input.js b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/input.js new file mode 100644 index 000000000000..7d3fa382c436 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/input.js @@ -0,0 +1 @@ +type T = Array<(string) => number> \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json new file mode 100644 index 000000000000..3b566aaa7fc0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json @@ -0,0 +1,183 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "T" + }, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "GenericTypeAnnotation", + "start": 9, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "params": [ + { + "type": "FunctionTypeAnnotation", + "start": 15, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 16, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 16, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + } + } + } + ], + "rest": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "typeParameters": null + } + ] + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "Array" + }, + "name": "Array" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/input.js b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/input.js new file mode 100644 index 000000000000..f27573896521 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/input.js @@ -0,0 +1 @@ +let x = (): Array<(string) => number> => [] \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json new file mode 100644 index 000000000000..fb3eb337bc92 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json @@ -0,0 +1,251 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "predicate": null, + "returnType": { + "type": "TypeAnnotation", + "start": 10, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 12, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 17, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "params": [ + { + "type": "FunctionTypeAnnotation", + "start": 18, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "params": [ + { + "type": "FunctionTypeParam", + "start": 19, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 19, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 25 + } + } + } + } + ], + "rest": null, + "returnType": { + "type": "NumberTypeAnnotation", + "start": 30, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 36 + } + } + }, + "typeParameters": null + } + ] + }, + "id": { + "type": "Identifier", + "start": 12, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "Array" + }, + "name": "Array" + } + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "ArrayExpression", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "elements": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json index f106eb4dc399..41dbc2be1068 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json @@ -156,7 +156,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json index bdd238b2985d..9b2e1c34ab13 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json @@ -156,7 +156,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json index b37fa6335539..edb622d15e0c 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json @@ -308,7 +308,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json index 6f1b515556c4..718dab31950f 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json @@ -256,7 +256,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/class-properties/invalid-named-static/output.json b/packages/babel-parser/test/fixtures/flow/class-properties/invalid-named-static/output.json deleted file mode 100644 index 3a2bf08816ad..000000000000 --- a/packages/babel-parser/test/fixtures/flow/class-properties/invalid-named-static/output.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 0, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 0 - } - }, - "sourceType": "module", - "interpreter": null, - "body": [], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/input.js b/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/input.js index b42988128e04..0d7178b7b682 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/input.js @@ -1,3 +1,4 @@ class MyClass { /*:: prop: string; */ + /* :: foo: number; */ } diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/output.json b/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/output.json index 618209f10c9a..42033b969ac4 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/01-type-include/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 41, + "end": 68, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 41, + "end": 68, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -32,14 +32,14 @@ { "type": "ClassDeclaration", "start": 0, - "end": 41, + "end": 68, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -64,14 +64,14 @@ "body": { "type": "ClassBody", "start": 14, - "end": 41, + "end": 68, "loc": { "start": { "line": 1, "column": 14 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -92,6 +92,22 @@ "column": 23 } } + }, + { + "type": "CommentBlock", + "value": " :: foo: number; ", + "start": 42, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 26 + } + } } ] } @@ -115,6 +131,22 @@ "column": 23 } } + }, + { + "type": "CommentBlock", + "value": " :: foo: number; ", + "start": 42, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 26 + } + } } ] } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/input.js b/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/input.js index d1644a305b88..5391c499ba5f 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/input.js @@ -1,4 +1,4 @@ -/*flow-include +/* flow-include type Foo = { foo: number, bar: boolean, diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/output.json b/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/output.json index ed5a0e7b58b3..39c844aa9f01 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/03-type-flow-include/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, @@ -33,9 +33,9 @@ "innerComments": [ { "type": "CommentBlock", - "value": "flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n", + "value": " flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, @@ -52,9 +52,9 @@ "comments": [ { "type": "CommentBlock", - "value": "flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n", + "value": " flow-include\ntype Foo = {\n foo: number,\n bar: boolean,\n baz: string\n};\n", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/input.js b/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/input.js index 6dc6ca809bfa..0e2022bb2d59 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/input.js @@ -1,3 +1,4 @@ class MyClass { /*flow-include prop: string; */ + /* flow-include foo: number; */ } diff --git a/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/output.json b/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/output.json index fb2a67dd8393..8c2727c7eb82 100644 --- a/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment-disabled/04-type-flow-include/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 51, + "end": 90, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 51, + "end": 90, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -32,14 +32,14 @@ { "type": "ClassDeclaration", "start": 0, - "end": 51, + "end": 90, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -64,14 +64,14 @@ "body": { "type": "ClassBody", "start": 14, - "end": 51, + "end": 90, "loc": { "start": { "line": 1, "column": 14 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -92,6 +92,22 @@ "column": 33 } } + }, + { + "type": "CommentBlock", + "value": " flow-include foo: number; ", + "start": 52, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 38 + } + } } ] } @@ -115,6 +131,22 @@ "column": 33 } } + }, + { + "type": "CommentBlock", + "value": " flow-include foo: number; ", + "start": 52, + "end": 88, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 38 + } + } } ] } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/comment/01-type-include/input.js b/packages/babel-parser/test/fixtures/flow/comment/01-type-include/input.js index b42988128e04..cca6b81303bf 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/01-type-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment/01-type-include/input.js @@ -1,3 +1,4 @@ class MyClass { - /*:: prop: string; */ + /* :: prop: string; */ + /* :: prop2: number; */ } diff --git a/packages/babel-parser/test/fixtures/flow/comment/01-type-include/output.json b/packages/babel-parser/test/fixtures/flow/comment/01-type-include/output.json index 4f80907e1de9..b31ea80c63cf 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/01-type-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment/01-type-include/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 41, + "end": 74, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 41, + "end": 74, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -32,14 +32,14 @@ { "type": "ClassDeclaration", "start": 0, - "end": 41, + "end": 74, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -64,45 +64,45 @@ "body": { "type": "ClassBody", "start": 14, - "end": 41, + "end": 74, "loc": { "start": { "line": 1, "column": 14 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, "body": [ { "type": "ClassProperty", - "start": 23, - "end": 36, + "start": 26, + "end": 39, "loc": { "start": { "line": 2, - "column": 7 + "column": 10 }, "end": { "line": 2, - "column": 20 + "column": 23 } }, "static": false, "key": { "type": "Identifier", - "start": 23, - "end": 27, + "start": 26, + "end": 30, "loc": { "start": { "line": 2, - "column": 7 + "column": 10 }, "end": { "line": 2, - "column": 11 + "column": 14 }, "identifierName": "prop" }, @@ -112,30 +112,96 @@ "variance": null, "typeAnnotation": { "type": "TypeAnnotation", - "start": 27, - "end": 35, + "start": 30, + "end": 38, "loc": { "start": { "line": 2, - "column": 11 + "column": 14 }, "end": { "line": 2, - "column": 19 + "column": 22 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 29, - "end": 35, + "start": 32, + "end": 38, "loc": { "start": { "line": 2, - "column": 13 + "column": 16 }, "end": { "line": 2, + "column": 22 + } + } + } + }, + "value": null + }, + { + "type": "ClassProperty", + "start": 55, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 55, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "prop2" + }, + "name": "prop2" + }, + "computed": false, + "variance": null, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 60, + "end": 68, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 62, + "end": 68, + "loc": { + "start": { + "line": 3, "column": 19 + }, + "end": { + "line": 3, + "column": 25 } } } diff --git a/packages/babel-parser/test/fixtures/flow/comment/02-type-include/output.json b/packages/babel-parser/test/fixtures/flow/comment/02-type-include/output.json index 81661e9066f7..0eb104082d54 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/02-type-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment/02-type-include/output.json @@ -239,7 +239,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/input.js b/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/input.js index d1644a305b88..5391c499ba5f 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/input.js @@ -1,4 +1,4 @@ -/*flow-include +/* flow-include type Foo = { foo: number, bar: boolean, diff --git a/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/output.json b/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/output.json index 3a740e6c1c30..567f48a615b3 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment/03-type-flow-include/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 78, + "end": 79, "loc": { "start": { "line": 1, @@ -31,8 +31,8 @@ "body": [ { "type": "TypeAlias", - "start": 15, - "end": 75, + "start": 16, + "end": 76, "loc": { "start": { "line": 2, @@ -45,8 +45,8 @@ }, "id": { "type": "Identifier", - "start": 20, - "end": 23, + "start": 21, + "end": 24, "loc": { "start": { "line": 2, @@ -63,8 +63,8 @@ "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 26, - "end": 74, + "start": 27, + "end": 75, "loc": { "start": { "line": 2, @@ -79,8 +79,8 @@ "properties": [ { "type": "ObjectTypeProperty", - "start": 30, - "end": 41, + "start": 31, + "end": 42, "loc": { "start": { "line": 3, @@ -93,8 +93,8 @@ }, "key": { "type": "Identifier", - "start": 30, - "end": 33, + "start": 31, + "end": 34, "loc": { "start": { "line": 3, @@ -114,8 +114,8 @@ "method": false, "value": { "type": "NumberTypeAnnotation", - "start": 35, - "end": 41, + "start": 36, + "end": 42, "loc": { "start": { "line": 3, @@ -132,8 +132,8 @@ }, { "type": "ObjectTypeProperty", - "start": 45, - "end": 57, + "start": 46, + "end": 58, "loc": { "start": { "line": 4, @@ -146,8 +146,8 @@ }, "key": { "type": "Identifier", - "start": 45, - "end": 48, + "start": 46, + "end": 49, "loc": { "start": { "line": 4, @@ -167,8 +167,8 @@ "method": false, "value": { "type": "BooleanTypeAnnotation", - "start": 50, - "end": 57, + "start": 51, + "end": 58, "loc": { "start": { "line": 4, @@ -185,8 +185,8 @@ }, { "type": "ObjectTypeProperty", - "start": 61, - "end": 72, + "start": 62, + "end": 73, "loc": { "start": { "line": 5, @@ -199,8 +199,8 @@ }, "key": { "type": "Identifier", - "start": 61, - "end": 64, + "start": 62, + "end": 65, "loc": { "start": { "line": 5, @@ -220,8 +220,8 @@ "method": false, "value": { "type": "StringTypeAnnotation", - "start": 66, - "end": 72, + "start": 67, + "end": 73, "loc": { "start": { "line": 5, @@ -239,7 +239,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/input.js b/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/input.js index 6dc6ca809bfa..7c3c07ea0945 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/input.js @@ -1,3 +1,4 @@ class MyClass { - /*flow-include prop: string; */ + /* flow-include prop: string; */ + /* flow-include prop2: number; */ } diff --git a/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/output.json b/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/output.json index fb2a67dd8393..908bfa823b79 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/output.json +++ b/packages/babel-parser/test/fixtures/flow/comment/04-type-flow-include/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 51, + "end": 99, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 51, + "end": 99, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -32,14 +32,14 @@ { "type": "ClassDeclaration", "start": 0, - "end": 51, + "end": 99, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, @@ -64,57 +64,154 @@ "body": { "type": "ClassBody", "start": 14, - "end": 51, + "end": 99, "loc": { "start": { "line": 1, "column": 14 }, "end": { - "line": 3, + "line": 4, "column": 1 } }, - "body": [], - "innerComments": [ + "body": [ { - "type": "CommentBlock", - "value": "flow-include prop: string; ", - "start": 18, - "end": 49, + "type": "ClassProperty", + "start": 39, + "end": 52, "loc": { "start": { "line": 2, - "column": 2 + "column": 23 }, "end": { "line": 2, - "column": 33 + "column": 36 } - } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 39, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 27 + }, + "identifierName": "prop" + }, + "name": "prop" + }, + "computed": false, + "variance": null, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 43, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 45, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 35 + } + } + } + }, + "value": null + }, + { + "type": "ClassProperty", + "start": 80, + "end": 94, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 80, + "end": 85, + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 29 + }, + "identifierName": "prop2" + }, + "name": "prop2" + }, + "computed": false, + "variance": null, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 85, + "end": 93, + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 37 + } + } + } + }, + "value": null } ] } } ], "directives": [] - }, - "comments": [ - { - "type": "CommentBlock", - "value": "flow-include prop: string; ", - "start": 18, - "end": 49, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 33 - } - } - } - ] + } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/comment/06-type-include-error/input.js b/packages/babel-parser/test/fixtures/flow/comment/06-type-include-error/input.js index 24b92dba6ee5..38ca508e980d 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/06-type-include-error/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment/06-type-include-error/input.js @@ -1,3 +1,3 @@ class MyClass { - /*:: prop: string; + /* :: prop: string; } diff --git a/packages/babel-parser/test/fixtures/flow/comment/08-type-flow-include-error/input.js b/packages/babel-parser/test/fixtures/flow/comment/08-type-flow-include-error/input.js index 495661d6a0ac..e876bde46b18 100644 --- a/packages/babel-parser/test/fixtures/flow/comment/08-type-flow-include-error/input.js +++ b/packages/babel-parser/test/fixtures/flow/comment/08-type-flow-include-error/input.js @@ -1,4 +1,4 @@ -/*flow-include +/* flow-include type Foo = { foo: number, bar: boolean, diff --git a/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/input.js b/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/input.js new file mode 100644 index 000000000000..6af1c10d91fe --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/input.js @@ -0,0 +1 @@ +/*:: /*asd */ diff --git a/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/options.json b/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/options.json new file mode 100644 index 000000000000..8b8fde928397 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/11-nested-comments-invalid/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unterminated comment (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/input.js b/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/input.js new file mode 100644 index 000000000000..127da20d59af --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/input.js @@ -0,0 +1 @@ +/*:: //asd */ diff --git a/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/options.json b/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/options.json new file mode 100644 index 000000000000..9a7e0e3402af --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/12-line-comment-nested-invalid/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unterminated flow-comment (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/input.js b/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/input.js new file mode 100644 index 000000000000..e5ec97f06ed7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/input.js @@ -0,0 +1 @@ +/*:: /*flow-include */ diff --git a/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/options.json b/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/options.json new file mode 100644 index 000000000000..fb8fdf85eed0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/comment/13-nested-flow-comments-invalid/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Cannot have a flow comment inside another flow comment (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js index 6a25a1836566..9c00baefd079 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/input.js @@ -1 +1,2 @@ declare module "foo" { declare export {a,}; } +var a; diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json index dda5b894d12c..c3b63e8c2365 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-named-pattern/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 45, + "end": 52, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 6 } }, "program": { "type": "Program", "start": 0, - "end": 45, + "end": 52, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 6 } }, "sourceType": "module", @@ -92,7 +92,6 @@ "column": 43 } }, - "declaration": null, "specifiers": [ { "type": "ExportSpecifier", @@ -145,11 +144,63 @@ } ], "source": null, + "declaration": null, "default": false } ] }, "kind": "ES" + }, + { + "type": "VariableDeclaration", + "start": 46, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": null + } + ], + "kind": "var" } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json index 9201b1e54299..2f2a34e73580 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-declare-export-type/options.json @@ -1,4 +1,3 @@ { - "throws": - "`declare export type` is not supported. Use `export type` instead (1:15)" + "throws": "`declare export type` is not supported. Use `export type` instead (1:15)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-const/options.json b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-const/options.json index a0f1f54296d1..8466e2ca853c 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-const/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-const/options.json @@ -1,4 +1,3 @@ { - "throws": - "`declare export const` is not supported. Use `declare export var` instead (1:15)" + "throws": "`declare export const` is not supported. Use `declare export var` instead (1:15)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-default-var/options.json b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-default-var/options.json index 562afcef4837..bdbbf5a8eefd 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-default-var/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-default-var/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token (1:23)" + "throws": "Unexpected token, expected \";\" (1:27)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-interface/options.json b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-interface/options.json index 7dfccf9590eb..3977f3c48054 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-interface/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-interface/options.json @@ -1,4 +1,3 @@ { - "throws": - "`declare export interface` is not supported. Use `export interface` instead (1:15)" + "throws": "`declare export interface` is not supported. Use `export interface` instead (1:15)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-let/options.json b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-let/options.json index 22611154f158..745a711f1178 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-let/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/invalid-export-let/options.json @@ -1,4 +1,3 @@ { - "throws": - "`declare export let` is not supported. Use `declare export var` instead (1:15)" + "throws": "`declare export let` is not supported. Use `declare export var` instead (1:15)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json index 563b25f29e43..84347d7d5618 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json @@ -146,7 +146,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json index 33f1898db552..e2a2f288cbb5 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json @@ -192,7 +192,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/8/options.json b/packages/babel-parser/test/fixtures/flow/declare-module/8/options.json index 774cdb5a2ce4..32826163f102 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/8/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/8/options.json @@ -1,4 +1,3 @@ { - "throws": - "Only declares and type imports are allowed inside declare module (2:2)" + "throws": "Only declares and type imports are allowed inside declare module (2:2)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js b/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js index 58b33359229d..2ea3d918132d 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js +++ b/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js @@ -1 +1,4 @@ -declare module "M" { import type T from "TM"; } +declare module "M" { + import type T from "TM"; + import typeof U from "UM"; +} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json index 0cfbb39aac09..f7bb57172e32 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "sourceType": "module", @@ -32,15 +32,15 @@ { "type": "DeclareModule", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "id": { @@ -66,59 +66,59 @@ "body": { "type": "BlockStatement", "start": 19, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 19 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "body": [ { "type": "ImportDeclaration", - "start": 21, - "end": 45, + "start": 23, + "end": 47, "loc": { "start": { - "line": 1, - "column": 21 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 26 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 1, - "column": 33 + "line": 2, + "column": 14 }, "end": { - "line": 1, - "column": 34 + "line": 2, + "column": 15 } }, "local": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 1, - "column": 33 + "line": 2, + "column": 14 }, "end": { - "line": 1, - "column": 34 + "line": 2, + "column": 15 }, "identifierName": "T" }, @@ -129,16 +129,16 @@ "importKind": "type", "source": { "type": "StringLiteral", - "start": 40, - "end": 44, + "start": 42, + "end": 46, "loc": { "start": { - "line": 1, - "column": 40 + "line": 2, + "column": 21 }, "end": { - "line": 1, - "column": 44 + "line": 2, + "column": 25 } }, "extra": { @@ -147,6 +147,76 @@ }, "value": "TM" } + }, + { + "type": "ImportDeclaration", + "start": 50, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "local": { + "type": "Identifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "U" + }, + "name": "U" + } + } + ], + "importKind": "typeof", + "source": { + "type": "StringLiteral", + "start": 71, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "extra": { + "rawValue": "UM", + "raw": "\"UM\"" + }, + "value": "UM" + } } ] }, diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json index 0d61c152b68d..adfde3236356 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-commonjs-module/options.json @@ -1,4 +1,3 @@ { - "throws": - "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:55)" + "throws": "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:55)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-es-module/options.json b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-es-module/options.json index bf1bde22fcbf..b40239a5609c 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-es-module/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-es-module/options.json @@ -1,4 +1,3 @@ { - "throws": - "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:53)" + "throws": "Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module (1:53)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-import/options.json b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-import/options.json index ffd120e2cdfe..c237bb99a73b 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-import/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-import/options.json @@ -1,4 +1,3 @@ { - "throws": - "Imports within a `declare module` body must always be `import type` or `import typeof` (1:21)" + "throws": "Imports within a `declare module` body must always be `import type` or `import typeof` (1:21)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-module-in-module/options.json b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-module-in-module/options.json index ecaf35fa621a..cd823bd7c4e0 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/invalid-module-in-module/options.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/invalid-module-in-module/options.json @@ -1,4 +1,3 @@ { - "throws": - "`declare module` cannot be used inside another `declare module` (1:27)" + "throws": "`declare module` cannot be used inside another `declare module` (1:27)" } diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/14/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/14/output.json index b34f2531a1a7..a7b76763db42 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/14/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/14/output.json @@ -243,7 +243,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/15/input.js b/packages/babel-parser/test/fixtures/flow/declare-statements/15/input.js index e5d2353e55bd..63a4ecdb5b7e 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/15/input.js +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/15/input.js @@ -1,2 +1,2 @@ declare interface I { foo: string } -declare interface I { foo: T } +declare interface I2 { foo: T } diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/15/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/15/output.json index 6af031abc60f..619a44a76feb 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/15/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/15/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 69, + "end": 70, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 33 + "column": 34 } }, "program": { "type": "Program", "start": 0, - "end": 69, + "end": 70, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 33 + "column": 34 } }, "sourceType": "module", @@ -142,7 +142,7 @@ { "type": "DeclareInterface", "start": 36, - "end": 69, + "end": 70, "loc": { "start": { "line": 2, @@ -150,13 +150,13 @@ }, "end": { "line": 2, - "column": 33 + "column": 34 } }, "id": { "type": "Identifier", "start": 54, - "end": 55, + "end": 56, "loc": { "start": { "line": 2, @@ -164,39 +164,39 @@ }, "end": { "line": 2, - "column": 19 + "column": 20 }, - "identifierName": "I" + "identifierName": "I2" }, - "name": "I" + "name": "I2" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 55, - "end": 58, + "start": 56, + "end": 59, "loc": { "start": { "line": 2, - "column": 19 + "column": 20 }, "end": { "line": 2, - "column": 22 + "column": 23 } }, "params": [ { "type": "TypeParameter", - "start": 56, - "end": 57, + "start": 57, + "end": 58, "loc": { "start": { "line": 2, - "column": 20 + "column": 21 }, "end": { "line": 2, - "column": 21 + "column": 22 } }, "name": "T", @@ -209,46 +209,46 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 59, - "end": 69, + "start": 60, + "end": 70, "loc": { "start": { "line": 2, - "column": 23 + "column": 24 }, "end": { "line": 2, - "column": 33 + "column": 34 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 61, - "end": 67, + "start": 62, + "end": 68, "loc": { "start": { "line": 2, - "column": 25 + "column": 26 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "key": { "type": "Identifier", - "start": 61, - "end": 64, + "start": 62, + "end": 65, "loc": { "start": { "line": 2, - "column": 25 + "column": 26 }, "end": { "line": 2, - "column": 28 + "column": 29 }, "identifierName": "foo" }, @@ -260,31 +260,31 @@ "method": false, "value": { "type": "GenericTypeAnnotation", - "start": 66, - "end": 67, + "start": 67, + "end": 68, "loc": { "start": { "line": 2, - "column": 30 + "column": 31 }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 66, - "end": 67, + "start": 67, + "end": 68, "loc": { "start": { "line": 2, - "column": 30 + "column": 31 }, "end": { "line": 2, - "column": 31 + "column": 32 }, "identifierName": "T" }, diff --git a/packages/babel-parser/test/fixtures/flow/def-site-variance/1/output.json b/packages/babel-parser/test/fixtures/flow/def-site-variance/1/output.json index 8455526f655d..938196ebcdb6 100644 --- a/packages/babel-parser/test/fixtures/flow/def-site-variance/1/output.json +++ b/packages/babel-parser/test/fixtures/flow/def-site-variance/1/output.json @@ -422,7 +422,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/input.js new file mode 100644 index 000000000000..c3ef0ff53256 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/input.js @@ -0,0 +1,4 @@ +//@flow +declare class A { + ...; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/options.json new file mode 100644 index 000000000000..c9188366d4e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects1/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (3:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/input.js new file mode 100644 index 000000000000..fcc33d36c05b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/input.js @@ -0,0 +1,5 @@ +//@flow +declare class B { + foo: number; + ...; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/options.json new file mode 100644 index 000000000000..658f8c434773 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects2/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (4:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/input.js new file mode 100644 index 000000000000..1f5df6b39ff9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/input.js @@ -0,0 +1,5 @@ +//@flow +declare class C { + ...; + foo: number; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/options.json new file mode 100644 index 000000000000..c9188366d4e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects3/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (3:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/input.js new file mode 100644 index 000000000000..7d0e44fc00c2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/input.js @@ -0,0 +1,6 @@ +//@flow +declare class D { + foo: number; + ...; + bar: number; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/options.json new file mode 100644 index 000000000000..658f8c434773 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects4/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (4:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/input.js new file mode 100644 index 000000000000..938efa8b5797 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/input.js @@ -0,0 +1,5 @@ +//@flow +interface F { + foo: number; + ...; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/options.json new file mode 100644 index 000000000000..658f8c434773 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects5/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (4:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/input.js new file mode 100644 index 000000000000..59c4a399c358 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/input.js @@ -0,0 +1,5 @@ +//@flow +interface G { + ...; + foo: number; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/options.json new file mode 100644 index 000000000000..c9188366d4e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects6/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (3:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/input.js new file mode 100644 index 000000000000..4dde1fd3b04e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/input.js @@ -0,0 +1,6 @@ +//@flow +interface H { + foo: number; + ...; + bar: number; +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/options.json new file mode 100644 index 000000000000..658f8c434773 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_disallowed_in_non_objects7/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Spread operator cannot appear in class or interface definitions (4:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/input.js new file mode 100644 index 000000000000..289513d4e480 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/input.js @@ -0,0 +1,2 @@ +//@flow +type T = {| foo: number, ... |} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/options.json new file mode 100644 index 000000000000..49936ac94990 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_forbidden_in_exact/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Explicit inexact syntax cannot appear inside an explicit exact object type (2:29)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/input.js new file mode 100644 index 000000000000..93c854cac282 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/input.js @@ -0,0 +1,2 @@ +//@flow +type T = {..., foo: number}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/options.json new file mode 100644 index 000000000000..ebb74417a527 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_must_appear_last/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Explicit inexact syntax must appear at the end of an inexact object (2:15)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/input.js new file mode 100644 index 000000000000..2fb3e7249593 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/input.js @@ -0,0 +1,4 @@ +//@flow +type T = {...}; +type U = {x: number, ...}; +type V = {x: number, ...V, ...U}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/output.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/output.json new file mode 100644 index 000000000000..7e32ace8159d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object/output.json @@ -0,0 +1,437 @@ +{ + "type": "File", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start": 8, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "T" + }, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + }, + { + "type": "TypeAlias", + "start": 24, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "U" + }, + "name": "U" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 33, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 34, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "key": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "NumberTypeAnnotation", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + } + }, + { + "type": "TypeAlias", + "start": 51, + "end": 84, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "id": { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + }, + "identifierName": "V" + }, + "name": "V" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 60, + "end": 83, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 32 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 61, + "end": 70, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "key": { + "type": "Identifier", + "start": 61, + "end": 62, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "NumberTypeAnnotation", + "start": 64, + "end": 70, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + "variance": null, + "optional": false + }, + { + "type": "ObjectTypeSpreadProperty", + "start": 72, + "end": 76, + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + }, + "identifierName": "V" + }, + "name": "V" + } + } + }, + { + "type": "ObjectTypeSpreadProperty", + "start": 78, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "argument": { + "type": "GenericTypeAnnotation", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 30 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 81, + "end": 82, + "loc": { + "start": { + "line": 4, + "column": 30 + }, + "end": { + "line": 4, + "column": 31 + }, + "identifierName": "U" + }, + "name": "U" + } + } + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/input.js new file mode 100644 index 000000000000..84742c465959 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/input.js @@ -0,0 +1,2 @@ +//@flow +type T = {x: number, ..., y: number}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/options.json new file mode 100644 index 000000000000..6d703769bf61 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid1/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Explicit inexact syntax must appear at the end of an inexact object (2:26)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/input.js new file mode 100644 index 000000000000..15e4d01a74e6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/input.js @@ -0,0 +1,2 @@ +//@flow +type U = {x: number, ..., ...}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/options.json new file mode 100644 index 000000000000..6d703769bf61 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid2/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Explicit inexact syntax must appear at the end of an inexact object (2:26)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/input.js new file mode 100644 index 000000000000..d9037ecf24a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/input.js @@ -0,0 +1,2 @@ +//@flow +type V = {x: number, ..., ...X}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/options.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/options.json new file mode 100644 index 000000000000..6d703769bf61 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_object_invalid3/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Explicit inexact syntax must appear at the end of an inexact object (2:26)" +} diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/input.js b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/input.js new file mode 100644 index 000000000000..2b439cf934f8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/input.js @@ -0,0 +1,11 @@ +//@flow +type T = { ..., }; +type U = { ...; }; +type V = { + x: number, + ..., +}; +type W = { + x: number; + ...; +}; diff --git a/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/output.json b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/output.json new file mode 100644 index 000000000000..3c39bdc107f5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/explicit-inexact-object/explicit_inexact_trailing_comma/output.json @@ -0,0 +1,395 @@ +{ + "type": "File", + "start": 0, + "end": 113, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 113, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start": 8, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "T" + }, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + }, + { + "type": "TypeAlias", + "start": 27, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "U" + }, + "name": "U" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + } + }, + { + "type": "TypeAlias", + "start": 46, + "end": 79, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + }, + "identifierName": "V" + }, + "name": "V" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 55, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 59, + "end": 68, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "key": { + "type": "Identifier", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "NumberTypeAnnotation", + "start": 62, + "end": 68, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + } + }, + { + "type": "TypeAlias", + "start": 80, + "end": 113, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 85, + "end": 86, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 6 + }, + "identifierName": "W" + }, + "name": "W" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start": 89, + "end": 112, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 93, + "end": 102, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "key": { + "type": "Identifier", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "NumberTypeAnnotation", + "start": 96, + "end": 102, + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 11 + } + } + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": true + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/id-reserved-type-invalid/options.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/id-reserved-type-invalid/options.json index b67b9224d4c0..b945b9a0a123 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/id-reserved-type-invalid/options.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/id-reserved-type-invalid/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:10)" + "throws": "Cannot overwrite reserved type string (1:10)" } diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/options.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/options.json index 3eddc82b13a2..7aecee1ff0ae 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/options.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/implements-reserved-type-invalid/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:21)" + "throws": "Cannot overwrite reserved type string (1:21)" } diff --git a/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json b/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json index 2be1cc35f8ee..b42f9eacce91 100644 --- a/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json @@ -166,7 +166,8 @@ } } ], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/internal-slot/object-optional/output.json b/packages/babel-parser/test/fixtures/flow/internal-slot/object-optional/output.json index 9a422ace0dab..605db54c850a 100644 --- a/packages/babel-parser/test/fixtures/flow/internal-slot/object-optional/output.json +++ b/packages/babel-parser/test/fixtures/flow/internal-slot/object-optional/output.json @@ -148,7 +148,8 @@ } } ], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/internal-slot/object/output.json b/packages/babel-parser/test/fixtures/flow/internal-slot/object/output.json index dd474f9d3903..6ff31113bc57 100644 --- a/packages/babel-parser/test/fixtures/flow/internal-slot/object/output.json +++ b/packages/babel-parser/test/fixtures/flow/internal-slot/object/output.json @@ -147,7 +147,8 @@ } } ], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/iterator/12/output.json b/packages/babel-parser/test/fixtures/flow/iterator/12/output.json index 523dd9f5cbe4..865bb503288f 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/12/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/12/output.json @@ -168,7 +168,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, "body": { diff --git a/packages/babel-parser/test/fixtures/flow/iterator/13/output.json b/packages/babel-parser/test/fixtures/flow/iterator/13/output.json index 7162d07e7f7e..a21fcad31e10 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/13/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/13/output.json @@ -168,7 +168,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, "body": { diff --git a/packages/babel-parser/test/fixtures/flow/literal-types/invalid-number-negative/options.json b/packages/babel-parser/test/fixtures/flow/literal-types/invalid-number-negative/options.json index 5667a8ffb0c0..d4fadede72f8 100644 --- a/packages/babel-parser/test/fixtures/flow/literal-types/invalid-number-negative/options.json +++ b/packages/babel-parser/test/fixtures/flow/literal-types/invalid-number-negative/options.json @@ -1,3 +1,3 @@ { - "throws": "Unexpected token, expected \"number\" (1:8)" + "throws": "Unexpected token, expected \"number\" or \"bigint\" (1:8)" } diff --git a/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json b/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json index 4bd3e696e5d6..c6357989dc29 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json @@ -233,7 +233,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json b/packages/babel-parser/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json index 6bf62df4a991..0c2cdd4d777c 100644 --- a/packages/babel-parser/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json +++ b/packages/babel-parser/test/fixtures/flow/opaque-type-alias/reserved-type-invalid/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:12)" + "throws": "Cannot overwrite reserved type string (1:12)" } diff --git a/packages/babel-parser/test/fixtures/flow/optional-type/1/output.json b/packages/babel-parser/test/fixtures/flow/optional-type/1/output.json index 49478ac47acf..75f31bbbe6bd 100644 --- a/packages/babel-parser/test/fixtures/flow/optional-type/1/output.json +++ b/packages/babel-parser/test/fixtures/flow/optional-type/1/output.json @@ -96,7 +96,7 @@ { "type": "Identifier", "start": 11, - "end": 12, + "end": 13, "loc": { "start": { "line": 1, @@ -104,7 +104,7 @@ }, "end": { "line": 1, - "column": 12 + "column": 13 }, "identifierName": "x" }, diff --git a/packages/babel-parser/test/fixtures/flow/optional-type/3/output.json b/packages/babel-parser/test/fixtures/flow/optional-type/3/output.json index ebf35e7fd7db..38e2cb2fb8cd 100644 --- a/packages/babel-parser/test/fixtures/flow/optional-type/3/output.json +++ b/packages/babel-parser/test/fixtures/flow/optional-type/3/output.json @@ -96,7 +96,7 @@ { "type": "Identifier", "start": 11, - "end": 12, + "end": 13, "loc": { "start": { "line": 1, @@ -104,7 +104,7 @@ }, "end": { "line": 1, - "column": 12 + "column": 13 }, "identifierName": "x" }, diff --git a/packages/babel-parser/test/fixtures/flow/optional-type/4/output.json b/packages/babel-parser/test/fixtures/flow/optional-type/4/output.json index 550ba7b633d7..61dd29778966 100644 --- a/packages/babel-parser/test/fixtures/flow/optional-type/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/optional-type/4/output.json @@ -96,7 +96,7 @@ { "type": "RestElement", "start": 11, - "end": 15, + "end": 16, "loc": { "start": { "line": 1, @@ -104,7 +104,7 @@ }, "end": { "line": 1, - "column": 15 + "column": 16 } }, "argument": { diff --git a/packages/babel-parser/test/fixtures/flow/optional-type/6/options.json b/packages/babel-parser/test/fixtures/flow/optional-type/6/options.json index fd783ce26e13..fb2831d6188b 100644 --- a/packages/babel-parser/test/fixtures/flow/optional-type/6/options.json +++ b/packages/babel-parser/test/fixtures/flow/optional-type/6/options.json @@ -1,4 +1,3 @@ { - "throws": - "A binding pattern parameter cannot be optional in an implementation signature. (1:11)" + "throws": "A binding pattern parameter cannot be optional in an implementation signature. (1:11)" } diff --git a/packages/babel-parser/test/fixtures/flow/pragma/1/input.js b/packages/babel-parser/test/fixtures/flow/pragma/1/input.js new file mode 100644 index 000000000000..f8d6e7e30a24 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/1/input.js @@ -0,0 +1,3 @@ +foo(y); +// @flow +foo(y); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/1/output.json b/packages/babel-parser/test/fixtures/flow/pragma/1/output.json new file mode 100644 index 000000000000..f74bc34124e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/1/output.json @@ -0,0 +1,293 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "left": { + "type": "BinaryExpression", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "left": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y", + "extra": { + "parenthesized": true, + "parenStart": 6 + } + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 11, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] + }, + { + "type": "ExpressionStatement", + "start": 20, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "left": { + "type": "BinaryExpression", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "left": { + "type": "Identifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "operator": "<", + "right": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "operator": ">", + "right": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y", + "extra": { + "parenthesized": true, + "parenStart": 26 + } + } + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 11, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 11, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/2/input.js b/packages/babel-parser/test/fixtures/flow/pragma/2/input.js new file mode 100644 index 000000000000..df8b2dd733fb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/2/input.js @@ -0,0 +1,3 @@ +'use strict'; +// @flow +foo(y); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/2/output.json b/packages/babel-parser/test/fixtures/flow/pragma/2/output.json new file mode 100644 index 000000000000..d97623a0a101 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/2/output.json @@ -0,0 +1,241 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 23, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 14, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "'use strict'", + "rawValue": "use strict" + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 14, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] + } + ] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start": 14, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/3/input.js b/packages/babel-parser/test/fixtures/flow/pragma/3/input.js new file mode 100644 index 000000000000..cf49c8b96de4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/3/input.js @@ -0,0 +1,3 @@ +// arbitrary comment +// @flow +foo(y); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/3/output.json b/packages/babel-parser/test/fixtures/flow/pragma/3/output.json new file mode 100644 index 000000000000..5baf19ddf253 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/3/output.json @@ -0,0 +1,219 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 30, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 30, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/4/input.js b/packages/babel-parser/test/fixtures/flow/pragma/4/input.js new file mode 100644 index 000000000000..458f7c2b9460 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/4/input.js @@ -0,0 +1,4 @@ +'use strict'; +// arbitrary comment +// @flow +foo(y); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/4/output.json b/packages/babel-parser/test/fixtures/flow/pragma/4/output.json new file mode 100644 index 000000000000..46325d1919a8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/4/output.json @@ -0,0 +1,289 @@ +{ + "type": "File", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 44, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 44, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 47, + "end": 50, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 35, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + } + } + ] + } + ], + "directives": [ + { + "type": "Directive", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "'use strict'", + "rawValue": "use strict" + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 35, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + } + } + ] + } + ] + }, + "comments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 14, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 35, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/5/input.js b/packages/babel-parser/test/fixtures/flow/pragma/5/input.js new file mode 100644 index 000000000000..e2ee3d87b6ef --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/5/input.js @@ -0,0 +1,5 @@ +#!/usr/bin/env node +'use strict'; +// arbitrary comment +// @flow +foo(y); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/pragma/5/output.json b/packages/babel-parser/test/fixtures/flow/pragma/5/output.json new file mode 100644 index 000000000000..c59fb12c869d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/pragma/5/output.json @@ -0,0 +1,304 @@ +{ + "type": "File", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 74, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": { + "type": "InterpreterDirective", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "/usr/bin/env node" + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 64, + "end": 74, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 64, + "end": 73, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 64, + "end": 67, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 67, + "end": 70, + "loc": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ] + }, + "arguments": [ + { + "type": "Identifier", + "start": 71, + "end": 72, + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + }, + "identifierName": "y" + }, + "name": "y" + } + ] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 34, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 55, + "end": 63, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + } + } + ] + } + ], + "directives": [ + { + "type": "Directive", + "start": 20, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": { + "type": "DirectiveLiteral", + "start": 20, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": "use strict", + "extra": { + "raw": "'use strict'", + "rawValue": "use strict" + } + }, + "trailingComments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 34, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 55, + "end": 63, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + } + } + ] + } + ] + }, + "comments": [ + { + "type": "CommentLine", + "value": " arbitrary comment", + "start": 34, + "end": 54, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "CommentLine", + "value": " @flow", + "start": 55, + "end": 63, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/input.js b/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/input.js new file mode 100644 index 000000000000..5868c4e2feda --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/input.js @@ -0,0 +1,2 @@ +async (f) +: t => { } diff --git a/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/output.json b/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/output.json new file mode 100644 index 000000000000..acc286d064ad --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/regression/arrow-function-with-newline/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "t" + }, + "name": "t" + } + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "f" + }, + "name": "f" + } + ], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/regression/issue-321/input.js b/packages/babel-parser/test/fixtures/flow/regression/issue-321/input.js index c4d6e74d8452..42132cbb00d6 100644 --- a/packages/babel-parser/test/fixtures/flow/regression/issue-321/input.js +++ b/packages/babel-parser/test/fixtures/flow/regression/issue-321/input.js @@ -1,2 +1,2 @@ const fn: ( Object, ?Object ) => void = ( o1, o2 ) => o1; -const fn: ( Object, ?Object, ) => void = ( o1, o2, ) => o1; +const fn2: ( Object, ?Object, ) => void = ( o1, o2, ) => o1; diff --git a/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json b/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json index 8d458c08f4f8..1af4cfcdc000 100644 --- a/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json +++ b/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 117, + "end": 118, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 59 + "column": 60 } }, "program": { "type": "Program", "start": 0, - "end": 117, + "end": 118, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 59 + "column": 60 } }, "sourceType": "module", @@ -317,7 +317,7 @@ { "type": "VariableDeclaration", "start": 58, - "end": 117, + "end": 118, "loc": { "start": { "line": 2, @@ -325,14 +325,14 @@ }, "end": { "line": 2, - "column": 59 + "column": 60 } }, "declarations": [ { "type": "VariableDeclarator", "start": 64, - "end": 116, + "end": 117, "loc": { "start": { "line": 2, @@ -340,13 +340,13 @@ }, "end": { "line": 2, - "column": 58 + "column": 59 } }, "id": { "type": "Identifier", "start": 64, - "end": 96, + "end": 97, "loc": { "start": { "line": 2, @@ -354,83 +354,83 @@ }, "end": { "line": 2, - "column": 38 + "column": 39 }, - "identifierName": "fn" + "identifierName": "fn2" }, - "name": "fn", + "name": "fn2", "typeAnnotation": { "type": "TypeAnnotation", - "start": 66, - "end": 96, + "start": 67, + "end": 97, "loc": { "start": { "line": 2, - "column": 8 + "column": 9 }, "end": { "line": 2, - "column": 38 + "column": 39 } }, "typeAnnotation": { "type": "FunctionTypeAnnotation", - "start": 68, - "end": 96, + "start": 69, + "end": 97, "loc": { "start": { "line": 2, - "column": 10 + "column": 11 }, "end": { "line": 2, - "column": 38 + "column": 39 } }, "params": [ { "type": "FunctionTypeParam", - "start": 70, - "end": 77, + "start": 71, + "end": 78, "loc": { "start": { "line": 2, - "column": 12 + "column": 13 }, "end": { "line": 2, - "column": 19 + "column": 20 } }, "name": null, "optional": false, "typeAnnotation": { "type": "GenericTypeAnnotation", - "start": 70, - "end": 76, + "start": 71, + "end": 77, "loc": { "start": { "line": 2, - "column": 12 + "column": 13 }, "end": { "line": 2, - "column": 18 + "column": 19 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 70, - "end": 76, + "start": 71, + "end": 77, "loc": { "start": { "line": 2, - "column": 12 + "column": 13 }, "end": { "line": 2, - "column": 18 + "column": 19 }, "identifierName": "Object" }, @@ -440,61 +440,61 @@ }, { "type": "FunctionTypeParam", - "start": 78, - "end": 85, + "start": 79, + "end": 86, "loc": { "start": { "line": 2, - "column": 20 + "column": 21 }, "end": { "line": 2, - "column": 27 + "column": 28 } }, "name": null, "optional": false, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 78, - "end": 85, + "start": 79, + "end": 86, "loc": { "start": { "line": 2, - "column": 20 + "column": 21 }, "end": { "line": 2, - "column": 27 + "column": 28 } }, "typeAnnotation": { "type": "GenericTypeAnnotation", - "start": 79, - "end": 85, + "start": 80, + "end": 86, "loc": { "start": { "line": 2, - "column": 21 + "column": 22 }, "end": { "line": 2, - "column": 27 + "column": 28 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 79, - "end": 85, + "start": 80, + "end": 86, "loc": { "start": { "line": 2, - "column": 21 + "column": 22 }, "end": { "line": 2, - "column": 27 + "column": 28 }, "identifierName": "Object" }, @@ -507,16 +507,16 @@ "rest": null, "returnType": { "type": "VoidTypeAnnotation", - "start": 92, - "end": 96, + "start": 93, + "end": 97, "loc": { "start": { "line": 2, - "column": 34 + "column": 35 }, "end": { "line": 2, - "column": 38 + "column": 39 } } }, @@ -526,16 +526,16 @@ }, "init": { "type": "ArrowFunctionExpression", - "start": 99, - "end": 116, + "start": 100, + "end": 117, "loc": { "start": { "line": 2, - "column": 41 + "column": 42 }, "end": { "line": 2, - "column": 58 + "column": 59 } }, "id": null, @@ -544,16 +544,16 @@ "params": [ { "type": "Identifier", - "start": 101, - "end": 103, + "start": 102, + "end": 104, "loc": { "start": { "line": 2, - "column": 43 + "column": 44 }, "end": { "line": 2, - "column": 45 + "column": 46 }, "identifierName": "o1" }, @@ -561,16 +561,16 @@ }, { "type": "Identifier", - "start": 105, - "end": 107, + "start": 106, + "end": 108, "loc": { "start": { "line": 2, - "column": 47 + "column": 48 }, "end": { "line": 2, - "column": 49 + "column": 50 }, "identifierName": "o2" }, @@ -579,16 +579,16 @@ ], "body": { "type": "Identifier", - "start": 114, - "end": 116, + "start": 115, + "end": 117, "loc": { "start": { "line": 2, - "column": 56 + "column": 57 }, "end": { "line": 2, - "column": 58 + "column": 59 }, "identifierName": "o1" }, diff --git a/packages/babel-parser/test/fixtures/flow/regression/issue-58-ambiguous/options.json b/packages/babel-parser/test/fixtures/flow/regression/issue-58-ambiguous/options.json index 59a47050c4df..49dc6c3d5a6a 100644 --- a/packages/babel-parser/test/fixtures/flow/regression/issue-58-ambiguous/options.json +++ b/packages/babel-parser/test/fixtures/flow/regression/issue-58-ambiguous/options.json @@ -1,4 +1,3 @@ { - "throws": - "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate. (4:4)" + "throws": "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate. (4:4)" } diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/input.js new file mode 100644 index 000000000000..6165683a9167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/input.js @@ -0,0 +1,2 @@ +const A = 1; +declare class A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/options.json new file mode 100644 index 000000000000..4a1b4e5c5cd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-class/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:14)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/input.js new file mode 100644 index 000000000000..c432acb46b72 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/input.js @@ -0,0 +1,2 @@ +const A = 1; +declare interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/options.json new file mode 100644 index 000000000000..187fea591b95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-declare-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:18)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/input.js new file mode 100644 index 000000000000..a03017e55c99 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/input.js @@ -0,0 +1,2 @@ +const A = 1; +interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/options.json new file mode 100644 index 000000000000..04242bd1565b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-const-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-class/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-class/input.js new file mode 100644 index 000000000000..32acf9e66e25 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-class/input.js @@ -0,0 +1,2 @@ +declare class A {} +declare class A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/input.js new file mode 100644 index 000000000000..99bf15306148 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/input.js @@ -0,0 +1,2 @@ +declare class A {} +declare interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/options.json new file mode 100644 index 000000000000..187fea591b95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-class-declare-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:18)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/input.js new file mode 100644 index 000000000000..c3a6f63af3b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/input.js @@ -0,0 +1,2 @@ +declare function A(): void; +declare function A(): void; diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/output.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/output.json new file mode 100644 index 000000000000..c4c86f1991cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-func/output.json @@ -0,0 +1,197 @@ +{ + "type": "File", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareFunction", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "A" + }, + "name": "A", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 18, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "typeParameters": null, + "params": [], + "rest": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 26 + } + } + } + } + } + }, + "predicate": null + }, + { + "type": "DeclareFunction", + "start": 28, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 45, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 26 + }, + "identifierName": "A" + }, + "name": "A", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 46, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start": 46, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "typeParameters": null, + "params": [], + "rest": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 50, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 26 + } + } + } + } + } + }, + "predicate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/input.js new file mode 100644 index 000000000000..e1e2e647fa89 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/input.js @@ -0,0 +1,2 @@ +declare function A(): void; +declare var A: number; diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-declare-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/input.js new file mode 100644 index 000000000000..ccce4b510933 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/input.js @@ -0,0 +1,2 @@ +declare function A(): void; +function A() {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/options.json new file mode 100644 index 000000000000..5f6027f8dd3b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:9)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/input.js new file mode 100644 index 000000000000..58df0295d818 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/input.js @@ -0,0 +1,2 @@ +declare function A(): number; +let A; diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-func-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/input.js new file mode 100644 index 000000000000..ab4fe6e51ff7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/input.js @@ -0,0 +1,2 @@ +declare interface A {} +declare class A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/options.json new file mode 100644 index 000000000000..4a1b4e5c5cd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-interface-declare-class/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:14)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/input.js new file mode 100644 index 000000000000..7e5419c9a6c5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/input.js @@ -0,0 +1,2 @@ +declare var A: number; +declare var A: number; diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/output.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/output.json new file mode 100644 index 000000000000..532ca8848c0b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-declare-var/output.json @@ -0,0 +1,159 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareVariable", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 12, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "A" + }, + "name": "A", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 13, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 15, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 21 + } + } + } + } + } + }, + { + "type": "DeclareVariable", + "start": 23, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 21 + }, + "identifierName": "A" + }, + "name": "A", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 38, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/input.js new file mode 100644 index 000000000000..8e7279314635 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/input.js @@ -0,0 +1,2 @@ +declare var A: number; +let A; diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-declare-var-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/input.js new file mode 100644 index 000000000000..5f780ecff9a5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/input.js @@ -0,0 +1,2 @@ +interface A {} +interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/options.json new file mode 100644 index 000000000000..04242bd1565b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-interface-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/input.js new file mode 100644 index 000000000000..61596821e374 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/input.js @@ -0,0 +1,2 @@ +let A = 1; +declare class A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/options.json new file mode 100644 index 000000000000..4a1b4e5c5cd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-class/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:14)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/input.js new file mode 100644 index 000000000000..97428603f0e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/input.js @@ -0,0 +1,2 @@ +let A = 1; +declare interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/options.json new file mode 100644 index 000000000000..187fea591b95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-declare-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:18)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/input.js new file mode 100644 index 000000000000..2e575bbc693d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/input.js @@ -0,0 +1,2 @@ +let A = 1; +interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/options.json new file mode 100644 index 000000000000..04242bd1565b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-let-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/input.js new file mode 100644 index 000000000000..38b60058911b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/input.js @@ -0,0 +1,2 @@ +type A = number; +interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/options.json new file mode 100644 index 000000000000..04242bd1565b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-type-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/input.js new file mode 100644 index 000000000000..c534e4739b49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/input.js @@ -0,0 +1,2 @@ +var A = 1; +declare class A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/options.json new file mode 100644 index 000000000000..4a1b4e5c5cd4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-class/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:14)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/input.js new file mode 100644 index 000000000000..07a1fa47aab2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/input.js @@ -0,0 +1,2 @@ +var A = 1; +declare interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/options.json new file mode 100644 index 000000000000..187fea591b95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-declare-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:18)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/input.js b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/input.js new file mode 100644 index 000000000000..70f7e73cc0ae --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/input.js @@ -0,0 +1,2 @@ +var A = 1; +interface A {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/options.json b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/options.json new file mode 100644 index 000000000000..04242bd1565b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/.dupl-decl-var-interface/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/abcdef/input.js b/packages/babel-parser/test/fixtures/flow/scope/abcdef/input.js new file mode 100644 index 000000000000..10c5350cb9b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/abcdef/input.js @@ -0,0 +1,5 @@ +function f() { + const g = true ? foo => {}: null; + + const foo = 'foo' +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/abcdef/output.json b/packages/babel-parser/test/fixtures/flow/scope/abcdef/output.json new file mode 100644 index 000000000000..e743dd0477a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/abcdef/output.json @@ -0,0 +1,308 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 17, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 23, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "g" + }, + "name": "g" + }, + "init": { + "type": "ConditionalExpression", + "start": 27, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": true + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 34, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "foo" + }, + "name": "foo" + } + ], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "body": [], + "directives": [] + } + }, + "alternate": { + "type": "NullLiteral", + "start": 45, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + } + } + ], + "kind": "const" + }, + { + "type": "VariableDeclaration", + "start": 54, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 60, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "start": 60, + "end": 63, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 11 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "StringLiteral", + "start": 66, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + } + } + ], + "kind": "const" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/scope/declare-module/input.js b/packages/babel-parser/test/fixtures/flow/scope/declare-module/input.js new file mode 100644 index 000000000000..3b25537ffca6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/declare-module/input.js @@ -0,0 +1,5 @@ +declare module A { + declare class X {} +} + +class X {} diff --git a/packages/babel-parser/test/fixtures/flow/scope/declare-module/output.json b/packages/babel-parser/test/fixtures/flow/scope/declare-module/output.json new file mode 100644 index 000000000000..672f98d0ad8c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/declare-module/output.json @@ -0,0 +1,190 @@ +{ + "type": "File", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareModule", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "A" + }, + "name": "A" + }, + "body": { + "type": "BlockStatement", + "start": 17, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "DeclareClass", + "start": 21, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "X" + }, + "name": "X" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "internalSlots": [], + "exact": false + } + } + ] + }, + "kind": "CommonJS" + }, + { + "type": "ClassDeclaration", + "start": 43, + "end": 53, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "id": { + "type": "Identifier", + "start": 49, + "end": 50, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + }, + "identifierName": "X" + }, + "name": "X" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/input.js new file mode 100644 index 000000000000..22286388e087 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/input.js @@ -0,0 +1,2 @@ +const A = 1; +opaque type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-opaque-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/input.js new file mode 100644 index 000000000000..09676cc69535 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/input.js @@ -0,0 +1,2 @@ +const A = 1; +type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/options.json new file mode 100644 index 000000000000..1eed93f49a0e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-const-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/input.js new file mode 100644 index 000000000000..f388a626baa6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/input.js @@ -0,0 +1,2 @@ +let A = 1; +opaque type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-opaque-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/input.js new file mode 100644 index 000000000000..acd0aedaa643 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/input.js @@ -0,0 +1,2 @@ +let A = 1; +type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/options.json new file mode 100644 index 000000000000..1eed93f49a0e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-let-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/input.js new file mode 100644 index 000000000000..68252d13d604 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/input.js @@ -0,0 +1,2 @@ +opaque type A = {}; +const A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/options.json new file mode 100644 index 000000000000..336686170eb0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-const/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/input.js new file mode 100644 index 000000000000..cb701d75b873 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/input.js @@ -0,0 +1,2 @@ +opaque type A = {}; +let A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/input.js new file mode 100644 index 000000000000..ea475eaf7548 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/input.js @@ -0,0 +1,2 @@ +opaque type A = {}; +opaque type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-opaque-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/input.js new file mode 100644 index 000000000000..9f3827951edb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/input.js @@ -0,0 +1,2 @@ +opaque type A = {}; +type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/options.json new file mode 100644 index 000000000000..1eed93f49a0e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/input.js new file mode 100644 index 000000000000..265278011940 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/input.js @@ -0,0 +1,2 @@ +opaque type A = {}; +var A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-opaque-type-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/input.js new file mode 100644 index 000000000000..2b045e915ada --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/input.js @@ -0,0 +1,2 @@ +type A = {}; +const A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/options.json new file mode 100644 index 000000000000..336686170eb0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-const/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:6)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/input.js new file mode 100644 index 000000000000..c827929c6d17 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/input.js @@ -0,0 +1,2 @@ +type A = {}; +let A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-let/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/input.js new file mode 100644 index 000000000000..03d17d1612aa --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/input.js @@ -0,0 +1,2 @@ +type A = {}; +opaque type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-opaque-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/input.js new file mode 100644 index 000000000000..72146f415607 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/input.js @@ -0,0 +1,2 @@ +type A = {}; +type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/options.json new file mode 100644 index 000000000000..1eed93f49a0e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/input.js new file mode 100644 index 000000000000..04e932fa9c8a --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/input.js @@ -0,0 +1,2 @@ +type A = {}; +var A = 1; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/options.json new file mode 100644 index 000000000000..b6ff3a4b0987 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-type-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:4)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/input.js new file mode 100644 index 000000000000..e4d5ab41ec30 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/input.js @@ -0,0 +1,2 @@ +var A = 1; +opaque type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/options.json new file mode 100644 index 000000000000..81dc2c90799f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-opaque-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:12)" +} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/input.js b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/input.js new file mode 100644 index 000000000000..3427e135d606 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/input.js @@ -0,0 +1,2 @@ +var A = 1; +type A = {}; diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/options.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/options.json new file mode 100644 index 000000000000..1eed93f49a0e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-var-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'A' has already been declared (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/input.js b/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/input.js index f0afdd16f8e5..cd488659aca6 100644 --- a/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/input.js +++ b/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/input.js @@ -1,2 +1,2 @@ export type Foo = number; -export opaque type Foo = number; +export opaque type Foo2 = number; diff --git a/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/output.json b/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/output.json index fc72d6467694..70d30bbe8a92 100644 --- a/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/output.json +++ b/packages/babel-parser/test/fixtures/flow/sourcetype-script/export-named/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 58, + "end": 59, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 2, - "column": 32 + "column": 33 } }, "program": { "type": "Program", "start": 0, - "end": 58, + "end": 59, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 2, - "column": 32 + "column": 33 } }, "sourceType": "script", @@ -98,7 +98,7 @@ { "type": "ExportNamedDeclaration", "start": 26, - "end": 58, + "end": 59, "loc": { "start": { "line": 2, @@ -106,7 +106,7 @@ }, "end": { "line": 2, - "column": 32 + "column": 33 } }, "specifiers": [], @@ -115,7 +115,7 @@ "declaration": { "type": "OpaqueType", "start": 33, - "end": 58, + "end": 59, "loc": { "start": { "line": 2, @@ -123,13 +123,13 @@ }, "end": { "line": 2, - "column": 32 + "column": 33 } }, "id": { "type": "Identifier", "start": 45, - "end": 48, + "end": 49, "loc": { "start": { "line": 2, @@ -137,26 +137,26 @@ }, "end": { "line": 2, - "column": 22 + "column": 23 }, - "identifierName": "Foo" + "identifierName": "Foo2" }, - "name": "Foo" + "name": "Foo2" }, "typeParameters": null, "supertype": null, "impltype": { "type": "NumberTypeAnnotation", - "start": 51, - "end": 57, + "start": 52, + "end": 58, "loc": { "start": { "line": 2, - "column": 25 + "column": 26 }, "end": { "line": 2, - "column": 31 + "column": 32 } } } diff --git a/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json b/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json index c7bc62245446..a1ff7e2786c1 100644 --- a/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json @@ -153,7 +153,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, { "type": "ObjectTypeAnnotation", @@ -232,7 +233,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } ] } @@ -626,7 +628,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, { "type": "ObjectTypeAnnotation", @@ -705,7 +708,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } ] }, @@ -715,7 +719,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { @@ -893,7 +898,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, { "type": "ObjectTypeAnnotation", @@ -972,7 +978,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } ] }, @@ -982,7 +989,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-alias/5/5.js b/packages/babel-parser/test/fixtures/flow/type-alias/5/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/flow/type-alias/5/5.js rename to packages/babel-parser/test/fixtures/flow/type-alias/5/input.js diff --git a/packages/babel-parser/test/fixtures/flow/type-alias/5/output.json b/packages/babel-parser/test/fixtures/flow/type-alias/5/output.json index 3a2bf08816ad..75a8bc8b79e1 100644 --- a/packages/babel-parser/test/fixtures/flow/type-alias/5/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-alias/5/output.json @@ -1,34 +1,553 @@ { "type": "File", "start": 0, - "end": 0, + "end": 98, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 0 + "line": 9, + "column": 2 } }, "program": { "type": "Program", "start": 0, - "end": 0, + "end": 98, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 0 + "line": 9, + "column": 2 } }, "sourceType": "module", "interpreter": null, - "body": [], + "body": [ + { + "type": "TypeAlias", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": null, + "right": { + "type": "GenericTypeAnnotation", + "start": 9, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "params": [ + { + "type": "UnionTypeAnnotation", + "start": 16, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "types": [ + { + "type": "ObjectTypeAnnotation", + "start": 18, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "key": { + "type": "Identifier", + "start": 19, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "type" + }, + "name": "type" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "extra": { + "rawValue": "A", + "raw": "\"A\"" + }, + "value": "A" + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + }, + { + "type": "ObjectTypeAnnotation", + "start": 34, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 35, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "key": { + "type": "Identifier", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "type" + }, + "name": "type" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 41, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "extra": { + "rawValue": "B", + "raw": "\"B\"" + }, + "value": "B" + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + ] + } + ] + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + } + }, + { + "type": "TypeAlias", + "start": 50, + "end": 98, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + }, + "identifierName": "B" + }, + "name": "B" + }, + "typeParameters": null, + "right": { + "type": "GenericTypeAnnotation", + "start": 59, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 62, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "params": [ + { + "type": "IntersectionTypeAnnotation", + "start": 66, + "end": 95, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "types": [ + { + "type": "ObjectTypeAnnotation", + "start": 68, + "end": 79, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 15 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 69, + "end": 78, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "key": { + "type": "Identifier", + "start": 69, + "end": 73, + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "type" + }, + "name": "type" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 75, + "end": 78, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "extra": { + "rawValue": "A", + "raw": "\"A\"" + }, + "value": "A" + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + }, + { + "type": "ObjectTypeAnnotation", + "start": 84, + "end": 95, + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 15 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 85, + "end": 94, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "key": { + "type": "Identifier", + "start": 85, + "end": 89, + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 9 + }, + "identifierName": "type" + }, + "name": "type" + }, + "static": false, + "proto": false, + "kind": "init", + "method": false, + "value": { + "type": "StringLiteralTypeAnnotation", + "start": 91, + "end": 94, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 14 + } + }, + "extra": { + "rawValue": "B", + "raw": "\"B\"" + }, + "value": "B" + }, + "variance": null, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + ] + } + ] + }, + "id": { + "type": "Identifier", + "start": 59, + "end": 62, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 12 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + } + } + ], "directives": [] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/108/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/108/output.json index 59d32d37d0fb..a3e8ba642bf2 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/108/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/108/output.json @@ -213,7 +213,8 @@ ], "indexers": [], "internalSlots": [], - "exact": true + "exact": true, + "inexact": false } } }, @@ -532,7 +533,8 @@ ], "indexers": [], "internalSlots": [], - "exact": true + "exact": true, + "inexact": false } } }, @@ -744,7 +746,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": true + "exact": true, + "inexact": false } } }, @@ -1003,7 +1006,8 @@ ], "indexers": [], "internalSlots": [], - "exact": true + "exact": true, + "inexact": false }, "variance": null, "optional": false @@ -1064,7 +1068,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, @@ -1537,7 +1542,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, "variance": null, "optional": false @@ -1598,7 +1604,8 @@ ], "indexers": [], "internalSlots": [], - "exact": true + "exact": true, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/110/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/110/output.json index 4929bc3d478f..4b3587d4c8a8 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/110/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/110/output.json @@ -166,7 +166,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/111/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/111/output.json index afb693e33614..ec02ec57394d 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/111/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/111/output.json @@ -166,7 +166,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/114/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/114/output.json index 0cb28d6e0fd3..ed6301370237 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/114/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/114/output.json @@ -195,7 +195,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/115/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/115/output.json index da040897ade4..df1f40c30646 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/115/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/115/output.json @@ -195,7 +195,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/127/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/127/output.json index 4d08cf624407..165aac2e4caa 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/127/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/127/output.json @@ -128,7 +128,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/128/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/128/output.json index cf23e569d27c..345675c7e135 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/128/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/128/output.json @@ -160,7 +160,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/131/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/131/options.json index bb5c8425acd9..50bea8a5db27 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/131/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/131/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type number (1:5)" + "throws": "Cannot overwrite reserved type number (1:5)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/132/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/132/options.json index 0148048697b7..257d651b33e2 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/132/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/132/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type number (1:9)" + "throws": "Cannot overwrite reserved type number (1:9)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/133/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/133/options.json index fb0222c596f6..2c7a5836d8bc 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/133/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/133/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:11)" + "throws": "Cannot overwrite reserved type string (1:11)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/134/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/134/options.json index 839b0e04eff9..396a14ca22d4 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/134/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/134/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type bool (1:13)" + "throws": "Cannot overwrite reserved type bool (1:13)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/135/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/135/output.json index aa8891c0b701..ce7e04fe7836 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/135/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/135/output.json @@ -110,7 +110,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/136/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/136/output.json index f2a1f069cffc..bdd81eaa2c09 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/136/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/136/output.json @@ -130,7 +130,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, "variance": null, "optional": false @@ -167,13 +168,15 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/137/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/137/options.json index f4cabf034ae4..786acad32af0 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/137/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/137/options.json @@ -1,4 +1,3 @@ { - "throws": - "Spread operator cannot appear in class or interface definitions (2:1)" + "throws": "Spread operator cannot appear in class or interface definitions (2:1)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/138/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/138/output.json index 1987550217b1..6e48beeb05dc 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/138/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/138/output.json @@ -276,7 +276,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/16/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/16/output.json index 4db03aa8f5aa..59fe3a8d364e 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/16/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/16/output.json @@ -96,7 +96,8 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, "body": { diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/32/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/32/output.json index 6e85ab61db4e..70cbbd4fef08 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/32/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/32/output.json @@ -160,7 +160,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/33/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/33/output.json index 5b4664821d6c..1ef29b3b8bb6 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/33/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/33/output.json @@ -160,7 +160,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/34/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/34/output.json index e0cef862f368..b389c49201ad 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/34/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/34/output.json @@ -225,7 +225,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/35/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/35/output.json index 42d9e07ef5fd..cc227490d30a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/35/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/35/output.json @@ -174,7 +174,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/36/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/36/output.json index fee4f6be4559..431aa501bc4d 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/36/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/36/output.json @@ -213,7 +213,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/37/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/37/output.json index 24897a890d17..428bb08cb9aa 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/37/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/37/output.json @@ -211,7 +211,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false }, "variance": null, "optional": false @@ -219,7 +220,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/38/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/38/output.json index 537525fd5058..0e133ba1cfbc 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/38/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/38/output.json @@ -225,7 +225,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, "variance": null, @@ -234,7 +235,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/39/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/39/output.json index fe3cbacc4b91..03cc703ab871 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/39/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/39/output.json @@ -213,7 +213,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/40/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/40/output.json index ed33244fe9cb..2cfc8de95973 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/40/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/40/output.json @@ -213,7 +213,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/41/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/41/output.json index 9e2c759153b9..2f073e822eff 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/41/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/41/output.json @@ -235,7 +235,8 @@ } ], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json index 446275326eff..b918a1e51b0a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json @@ -322,7 +322,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json index 027091719c88..05ff2466b98b 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json @@ -295,7 +295,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/60/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/60/output.json index 1f013f7840a1..cfa5f6db54cc 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/60/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/60/output.json @@ -215,7 +215,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/61/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/61/output.json index c26e02abf8ad..25d46071b872 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/61/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/61/output.json @@ -215,7 +215,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/63/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/63/output.json index 7311b8c2411e..e9fb827b5b7d 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/63/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/63/output.json @@ -220,7 +220,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/98/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/98/output.json index 669cab2fd5e9..6a24cf2f1e35 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/98/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/98/output.json @@ -266,7 +266,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } }, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/input.js index 777868f31ed8..04fd627b994e 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/input.js @@ -1,16 +1,16 @@ // bounds -type T = any; -type T = mixed; -type T = empty; +type T1 = any; +type T2 = mixed; +type T3 = empty; // builtins -type T = void; -type T = number; -type T = string; -type T = bool; -type T = boolean; +type T4 = void; +type T5 = number; +type T6 = string; +type T7 = bool; +type T8 = boolean; // literal type annotations -type T = null; -type T = ""; -type T = 0; -type T = true; -type T = false; +type T9 = null; +type T10 = ""; +type T11 = 0; +type T12 = true; +type T13 = false; diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/output.json index 379ea71424c4..9b3179172293 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/builtin/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 248, + "end": 265, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 16, - "column": 15 + "column": 17 } }, "program": { "type": "Program", "start": 0, - "end": 248, + "end": 265, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 17 } }, "sourceType": "module", @@ -32,7 +32,7 @@ { "type": "TypeAlias", "start": 10, - "end": 23, + "end": 24, "loc": { "start": { "line": 2, @@ -40,13 +40,13 @@ }, "end": { "line": 2, - "column": 13 + "column": 14 } }, "id": { "type": "Identifier", "start": 15, - "end": 16, + "end": 17, "loc": { "start": { "line": 2, @@ -54,25 +54,25 @@ }, "end": { "line": 2, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T1" }, - "name": "T" + "name": "T1" }, "typeParameters": null, "right": { "type": "AnyTypeAnnotation", - "start": 19, - "end": 22, + "start": 20, + "end": 23, "loc": { "start": { "line": 2, - "column": 9 + "column": 10 }, "end": { "line": 2, - "column": 12 + "column": 13 } } }, @@ -97,8 +97,8 @@ }, { "type": "TypeAlias", - "start": 24, - "end": 39, + "start": 25, + "end": 41, "loc": { "start": { "line": 3, @@ -106,13 +106,13 @@ }, "end": { "line": 3, - "column": 15 + "column": 16 } }, "id": { "type": "Identifier", - "start": 29, - "end": 30, + "start": 30, + "end": 32, "loc": { "start": { "line": 3, @@ -120,33 +120,33 @@ }, "end": { "line": 3, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T2" }, - "name": "T" + "name": "T2" }, "typeParameters": null, "right": { "type": "MixedTypeAnnotation", - "start": 33, - "end": 38, + "start": 35, + "end": 40, "loc": { "start": { "line": 3, - "column": 9 + "column": 10 }, "end": { "line": 3, - "column": 14 + "column": 15 } } } }, { "type": "TypeAlias", - "start": 40, - "end": 55, + "start": 42, + "end": 58, "loc": { "start": { "line": 4, @@ -154,13 +154,13 @@ }, "end": { "line": 4, - "column": 15 + "column": 16 } }, "id": { "type": "Identifier", - "start": 45, - "end": 46, + "start": 47, + "end": 49, "loc": { "start": { "line": 4, @@ -168,25 +168,25 @@ }, "end": { "line": 4, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T3" }, - "name": "T" + "name": "T3" }, "typeParameters": null, "right": { "type": "EmptyTypeAnnotation", - "start": 49, - "end": 54, + "start": 52, + "end": 57, "loc": { "start": { "line": 4, - "column": 9 + "column": 10 }, "end": { "line": 4, - "column": 14 + "column": 15 } } }, @@ -194,8 +194,8 @@ { "type": "CommentLine", "value": " builtins", - "start": 56, - "end": 67, + "start": 59, + "end": 70, "loc": { "start": { "line": 5, @@ -211,8 +211,8 @@ }, { "type": "TypeAlias", - "start": 68, - "end": 82, + "start": 71, + "end": 86, "loc": { "start": { "line": 6, @@ -220,13 +220,13 @@ }, "end": { "line": 6, - "column": 14 + "column": 15 } }, "id": { "type": "Identifier", - "start": 73, - "end": 74, + "start": 76, + "end": 78, "loc": { "start": { "line": 6, @@ -234,25 +234,25 @@ }, "end": { "line": 6, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T4" }, - "name": "T" + "name": "T4" }, "typeParameters": null, "right": { "type": "VoidTypeAnnotation", - "start": 77, - "end": 81, + "start": 81, + "end": 85, "loc": { "start": { "line": 6, - "column": 9 + "column": 10 }, "end": { "line": 6, - "column": 13 + "column": 14 } } }, @@ -260,8 +260,8 @@ { "type": "CommentLine", "value": " builtins", - "start": 56, - "end": 67, + "start": 59, + "end": 70, "loc": { "start": { "line": 5, @@ -277,8 +277,8 @@ }, { "type": "TypeAlias", - "start": 83, - "end": 99, + "start": 87, + "end": 104, "loc": { "start": { "line": 7, @@ -286,13 +286,13 @@ }, "end": { "line": 7, - "column": 16 + "column": 17 } }, "id": { "type": "Identifier", - "start": 88, - "end": 89, + "start": 92, + "end": 94, "loc": { "start": { "line": 7, @@ -300,33 +300,33 @@ }, "end": { "line": 7, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T5" }, - "name": "T" + "name": "T5" }, "typeParameters": null, "right": { "type": "NumberTypeAnnotation", - "start": 92, - "end": 98, + "start": 97, + "end": 103, "loc": { "start": { "line": 7, - "column": 9 + "column": 10 }, "end": { "line": 7, - "column": 15 + "column": 16 } } } }, { "type": "TypeAlias", - "start": 100, - "end": 116, + "start": 105, + "end": 122, "loc": { "start": { "line": 8, @@ -334,13 +334,13 @@ }, "end": { "line": 8, - "column": 16 + "column": 17 } }, "id": { "type": "Identifier", - "start": 105, - "end": 106, + "start": 110, + "end": 112, "loc": { "start": { "line": 8, @@ -348,33 +348,33 @@ }, "end": { "line": 8, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T6" }, - "name": "T" + "name": "T6" }, "typeParameters": null, "right": { "type": "StringTypeAnnotation", - "start": 109, - "end": 115, + "start": 115, + "end": 121, "loc": { "start": { "line": 8, - "column": 9 + "column": 10 }, "end": { "line": 8, - "column": 15 + "column": 16 } } } }, { "type": "TypeAlias", - "start": 117, - "end": 131, + "start": 123, + "end": 138, "loc": { "start": { "line": 9, @@ -382,13 +382,13 @@ }, "end": { "line": 9, - "column": 14 + "column": 15 } }, "id": { "type": "Identifier", - "start": 122, - "end": 123, + "start": 128, + "end": 130, "loc": { "start": { "line": 9, @@ -396,33 +396,33 @@ }, "end": { "line": 9, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T7" }, - "name": "T" + "name": "T7" }, "typeParameters": null, "right": { "type": "BooleanTypeAnnotation", - "start": 126, - "end": 130, + "start": 133, + "end": 137, "loc": { "start": { "line": 9, - "column": 9 + "column": 10 }, "end": { "line": 9, - "column": 13 + "column": 14 } } } }, { "type": "TypeAlias", - "start": 132, - "end": 149, + "start": 139, + "end": 157, "loc": { "start": { "line": 10, @@ -430,13 +430,13 @@ }, "end": { "line": 10, - "column": 17 + "column": 18 } }, "id": { "type": "Identifier", - "start": 137, - "end": 138, + "start": 144, + "end": 146, "loc": { "start": { "line": 10, @@ -444,25 +444,25 @@ }, "end": { "line": 10, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T8" }, - "name": "T" + "name": "T8" }, "typeParameters": null, "right": { "type": "BooleanTypeAnnotation", - "start": 141, - "end": 148, + "start": 149, + "end": 156, "loc": { "start": { "line": 10, - "column": 9 + "column": 10 }, "end": { "line": 10, - "column": 16 + "column": 17 } } }, @@ -470,8 +470,8 @@ { "type": "CommentLine", "value": " literal type annotations", - "start": 150, - "end": 177, + "start": 158, + "end": 185, "loc": { "start": { "line": 11, @@ -487,8 +487,8 @@ }, { "type": "TypeAlias", - "start": 178, - "end": 192, + "start": 186, + "end": 201, "loc": { "start": { "line": 12, @@ -496,13 +496,13 @@ }, "end": { "line": 12, - "column": 14 + "column": 15 } }, "id": { "type": "Identifier", - "start": 183, - "end": 184, + "start": 191, + "end": 193, "loc": { "start": { "line": 12, @@ -510,25 +510,25 @@ }, "end": { "line": 12, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T9" }, - "name": "T" + "name": "T9" }, "typeParameters": null, "right": { "type": "NullLiteralTypeAnnotation", - "start": 187, - "end": 191, + "start": 196, + "end": 200, "loc": { "start": { "line": 12, - "column": 9 + "column": 10 }, "end": { "line": 12, - "column": 13 + "column": 14 } } }, @@ -536,8 +536,8 @@ { "type": "CommentLine", "value": " literal type annotations", - "start": 150, - "end": 177, + "start": 158, + "end": 185, "loc": { "start": { "line": 11, @@ -553,8 +553,8 @@ }, { "type": "TypeAlias", - "start": 193, - "end": 205, + "start": 202, + "end": 216, "loc": { "start": { "line": 13, @@ -562,13 +562,13 @@ }, "end": { "line": 13, - "column": 12 + "column": 14 } }, "id": { "type": "Identifier", - "start": 198, - "end": 199, + "start": 207, + "end": 210, "loc": { "start": { "line": 13, @@ -576,25 +576,25 @@ }, "end": { "line": 13, - "column": 6 + "column": 8 }, - "identifierName": "T" + "identifierName": "T10" }, - "name": "T" + "name": "T10" }, "typeParameters": null, "right": { "type": "StringLiteralTypeAnnotation", - "start": 202, - "end": 204, + "start": 213, + "end": 215, "loc": { "start": { "line": 13, - "column": 9 + "column": 11 }, "end": { "line": 13, - "column": 11 + "column": 13 } }, "extra": { @@ -606,8 +606,8 @@ }, { "type": "TypeAlias", - "start": 206, - "end": 217, + "start": 217, + "end": 230, "loc": { "start": { "line": 14, @@ -615,13 +615,13 @@ }, "end": { "line": 14, - "column": 11 + "column": 13 } }, "id": { "type": "Identifier", - "start": 211, - "end": 212, + "start": 222, + "end": 225, "loc": { "start": { "line": 14, @@ -629,25 +629,25 @@ }, "end": { "line": 14, - "column": 6 + "column": 8 }, - "identifierName": "T" + "identifierName": "T11" }, - "name": "T" + "name": "T11" }, "typeParameters": null, "right": { "type": "NumberLiteralTypeAnnotation", - "start": 215, - "end": 216, + "start": 228, + "end": 229, "loc": { "start": { "line": 14, - "column": 9 + "column": 11 }, "end": { "line": 14, - "column": 10 + "column": 12 } }, "extra": { @@ -659,8 +659,8 @@ }, { "type": "TypeAlias", - "start": 218, - "end": 232, + "start": 231, + "end": 247, "loc": { "start": { "line": 15, @@ -668,13 +668,13 @@ }, "end": { "line": 15, - "column": 14 + "column": 16 } }, "id": { "type": "Identifier", - "start": 223, - "end": 224, + "start": 236, + "end": 239, "loc": { "start": { "line": 15, @@ -682,25 +682,25 @@ }, "end": { "line": 15, - "column": 6 + "column": 8 }, - "identifierName": "T" + "identifierName": "T12" }, - "name": "T" + "name": "T12" }, "typeParameters": null, "right": { "type": "BooleanLiteralTypeAnnotation", - "start": 227, - "end": 231, + "start": 242, + "end": 246, "loc": { "start": { "line": 15, - "column": 9 + "column": 11 }, "end": { "line": 15, - "column": 13 + "column": 15 } }, "value": true @@ -708,8 +708,8 @@ }, { "type": "TypeAlias", - "start": 233, - "end": 248, + "start": 248, + "end": 265, "loc": { "start": { "line": 16, @@ -717,13 +717,13 @@ }, "end": { "line": 16, - "column": 15 + "column": 17 } }, "id": { "type": "Identifier", - "start": 238, - "end": 239, + "start": 253, + "end": 256, "loc": { "start": { "line": 16, @@ -731,25 +731,25 @@ }, "end": { "line": 16, - "column": 6 + "column": 8 }, - "identifierName": "T" + "identifierName": "T13" }, - "name": "T" + "name": "T13" }, "typeParameters": null, "right": { "type": "BooleanLiteralTypeAnnotation", - "start": 242, - "end": 247, + "start": 259, + "end": 264, "loc": { "start": { "line": 16, - "column": 9 + "column": 11 }, "end": { "line": 16, - "column": 14 + "column": 16 } }, "value": false @@ -778,8 +778,8 @@ { "type": "CommentLine", "value": " builtins", - "start": 56, - "end": 67, + "start": 59, + "end": 70, "loc": { "start": { "line": 5, @@ -794,8 +794,8 @@ { "type": "CommentLine", "value": " literal type annotations", - "start": 150, - "end": 177, + "start": 158, + "end": 185, "loc": { "start": { "line": 11, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/input.js new file mode 100644 index 000000000000..0a30a10d7808 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/input.js @@ -0,0 +1 @@ +function foo(a:function) {} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/output.json new file mode 100644 index 000000000000..056dc7de7b00 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/output.json @@ -0,0 +1,137 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "typeAnnotation": { + "type": "Identifier", + "start": 15, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "function" + }, + "name": "function" + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/input.js b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/input.js index 216a4222b3bb..435219343e08 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/input.js @@ -1,12 +1,12 @@ type T = { a: () => void }; -type T = { a: () => void }; -type T = { a(): void }; -type T = { a(): void }; +type T1 = { a: () => void }; +type T2 = { a(): void }; +type T3 = { a(): void }; -type T = { (): number }; -type T = { (x: T): number; } +type T4 = { (): number }; +type T5 = { (x: T): number; } -declare class T { foo(): number; } -declare class T { static foo(): number; } -declare class T { (): number } -declare class T { static (): number } +declare class T6 { foo(): number; } +declare class T7 { static foo(): number; } +declare class T8 { (): number } +declare class T9 { static (): number } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json index 61c974a71802..49fb1b3a7b0d 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 314, + "end": 323, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 12, - "column": 37 + "column": 38 } }, "program": { "type": "Program", "start": 0, - "end": 314, + "end": 323, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 12, - "column": 37 + "column": 38 } }, "sourceType": "module", @@ -151,13 +151,14 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "TypeAlias", "start": 28, - "end": 58, + "end": 59, "loc": { "start": { "line": 2, @@ -165,13 +166,13 @@ }, "end": { "line": 2, - "column": 30 + "column": 31 } }, "id": { "type": "Identifier", "start": 33, - "end": 34, + "end": 35, "loc": { "start": { "line": 2, @@ -179,55 +180,55 @@ }, "end": { "line": 2, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T1" }, - "name": "T" + "name": "T1" }, "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 37, - "end": 57, + "start": 38, + "end": 58, "loc": { "start": { "line": 2, - "column": 9 + "column": 10 }, "end": { "line": 2, - "column": 29 + "column": 30 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 39, - "end": 55, + "start": 40, + "end": 56, "loc": { "start": { "line": 2, - "column": 11 + "column": 12 }, "end": { "line": 2, - "column": 27 + "column": 28 } }, "key": { "type": "Identifier", - "start": 39, - "end": 40, + "start": 40, + "end": 41, "loc": { "start": { "line": 2, - "column": 11 + "column": 12 }, "end": { "line": 2, - "column": 12 + "column": 13 }, "identifierName": "a" }, @@ -239,45 +240,45 @@ "method": false, "value": { "type": "FunctionTypeAnnotation", - "start": 42, - "end": 55, + "start": 43, + "end": 56, "loc": { "start": { "line": 2, - "column": 14 + "column": 15 }, "end": { "line": 2, - "column": 27 + "column": 28 } }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 42, - "end": 45, + "start": 43, + "end": 46, "loc": { "start": { "line": 2, - "column": 14 + "column": 15 }, "end": { "line": 2, - "column": 17 + "column": 18 } }, "params": [ { "type": "TypeParameter", - "start": 43, - "end": 44, + "start": 44, + "end": 45, "loc": { "start": { "line": 2, - "column": 15 + "column": 16 }, "end": { "line": 2, - "column": 16 + "column": 17 } }, "name": "T", @@ -289,16 +290,16 @@ "rest": null, "returnType": { "type": "VoidTypeAnnotation", - "start": 51, - "end": 55, + "start": 52, + "end": 56, "loc": { "start": { "line": 2, - "column": 23 + "column": 24 }, "end": { "line": 2, - "column": 27 + "column": 28 } } } @@ -309,13 +310,14 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "TypeAlias", - "start": 59, - "end": 82, + "start": 60, + "end": 84, "loc": { "start": { "line": 3, @@ -323,13 +325,13 @@ }, "end": { "line": 3, - "column": 23 + "column": 24 } }, "id": { "type": "Identifier", - "start": 64, - "end": 65, + "start": 65, + "end": 67, "loc": { "start": { "line": 3, @@ -337,55 +339,55 @@ }, "end": { "line": 3, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T2" }, - "name": "T" + "name": "T2" }, "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 68, - "end": 81, + "start": 70, + "end": 83, "loc": { "start": { "line": 3, - "column": 9 + "column": 10 }, "end": { "line": 3, - "column": 22 + "column": 23 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 70, - "end": 79, + "start": 72, + "end": 81, "loc": { "start": { "line": 3, - "column": 11 + "column": 12 }, "end": { "line": 3, - "column": 20 + "column": 21 } }, "key": { "type": "Identifier", - "start": 70, - "end": 71, + "start": 72, + "end": 73, "loc": { "start": { "line": 3, - "column": 11 + "column": 12 }, "end": { "line": 3, - "column": 12 + "column": 13 }, "identifierName": "a" }, @@ -397,16 +399,16 @@ "method": true, "value": { "type": "FunctionTypeAnnotation", - "start": 70, - "end": 79, + "start": 72, + "end": 81, "loc": { "start": { "line": 3, - "column": 11 + "column": 12 }, "end": { "line": 3, - "column": 20 + "column": 21 } }, "params": [], @@ -414,16 +416,16 @@ "typeParameters": null, "returnType": { "type": "VoidTypeAnnotation", - "start": 75, - "end": 79, + "start": 77, + "end": 81, "loc": { "start": { "line": 3, - "column": 16 + "column": 17 }, "end": { "line": 3, - "column": 20 + "column": 21 } } } @@ -433,13 +435,14 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "TypeAlias", - "start": 83, - "end": 109, + "start": 85, + "end": 112, "loc": { "start": { "line": 4, @@ -447,13 +450,13 @@ }, "end": { "line": 4, - "column": 26 + "column": 27 } }, "id": { "type": "Identifier", - "start": 88, - "end": 89, + "start": 90, + "end": 92, "loc": { "start": { "line": 4, @@ -461,55 +464,55 @@ }, "end": { "line": 4, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T3" }, - "name": "T" + "name": "T3" }, "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 92, - "end": 108, + "start": 95, + "end": 111, "loc": { "start": { "line": 4, - "column": 9 + "column": 10 }, "end": { "line": 4, - "column": 25 + "column": 26 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 94, - "end": 106, + "start": 97, + "end": 109, "loc": { "start": { "line": 4, - "column": 11 + "column": 12 }, "end": { "line": 4, - "column": 23 + "column": 24 } }, "key": { "type": "Identifier", - "start": 94, - "end": 95, + "start": 97, + "end": 98, "loc": { "start": { "line": 4, - "column": 11 + "column": 12 }, "end": { "line": 4, - "column": 12 + "column": 13 }, "identifierName": "a" }, @@ -521,47 +524,47 @@ "method": true, "value": { "type": "FunctionTypeAnnotation", - "start": 94, - "end": 106, + "start": 97, + "end": 109, "loc": { "start": { "line": 4, - "column": 11 + "column": 12 }, "end": { "line": 4, - "column": 23 + "column": 24 } }, "params": [], "rest": null, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 95, - "end": 98, + "start": 98, + "end": 101, "loc": { "start": { "line": 4, - "column": 12 + "column": 13 }, "end": { "line": 4, - "column": 15 + "column": 16 } }, "params": [ { "type": "TypeParameter", - "start": 96, - "end": 97, + "start": 99, + "end": 100, "loc": { "start": { "line": 4, - "column": 13 + "column": 14 }, "end": { "line": 4, - "column": 14 + "column": 15 } }, "name": "T", @@ -571,16 +574,16 @@ }, "returnType": { "type": "VoidTypeAnnotation", - "start": 102, - "end": 106, + "start": 105, + "end": 109, "loc": { "start": { "line": 4, - "column": 19 + "column": 20 }, "end": { "line": 4, - "column": 23 + "column": 24 } } } @@ -590,13 +593,14 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "TypeAlias", - "start": 111, - "end": 135, + "start": 114, + "end": 139, "loc": { "start": { "line": 6, @@ -604,13 +608,13 @@ }, "end": { "line": 6, - "column": 24 + "column": 25 } }, "id": { "type": "Identifier", - "start": 116, - "end": 117, + "start": 119, + "end": 121, "loc": { "start": { "line": 6, @@ -618,55 +622,55 @@ }, "end": { "line": 6, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T4" }, - "name": "T" + "name": "T4" }, "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 120, - "end": 134, + "start": 124, + "end": 138, "loc": { "start": { "line": 6, - "column": 9 + "column": 10 }, "end": { "line": 6, - "column": 23 + "column": 24 } }, "callProperties": [ { "type": "ObjectTypeCallProperty", - "start": 122, - "end": 132, + "start": 126, + "end": 136, "loc": { "start": { "line": 6, - "column": 11 + "column": 12 }, "end": { "line": 6, - "column": 21 + "column": 22 } }, "static": false, "value": { "type": "FunctionTypeAnnotation", - "start": 122, - "end": 132, + "start": 126, + "end": 136, "loc": { "start": { "line": 6, - "column": 11 + "column": 12 }, "end": { "line": 6, - "column": 21 + "column": 22 } }, "params": [], @@ -674,16 +678,16 @@ "typeParameters": null, "returnType": { "type": "NumberTypeAnnotation", - "start": 126, - "end": 132, + "start": 130, + "end": 136, "loc": { "start": { "line": 6, - "column": 15 + "column": 16 }, "end": { "line": 6, - "column": 21 + "column": 22 } } } @@ -693,13 +697,14 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "TypeAlias", - "start": 136, - "end": 167, + "start": 140, + "end": 172, "loc": { "start": { "line": 7, @@ -707,13 +712,13 @@ }, "end": { "line": 7, - "column": 31 + "column": 32 } }, "id": { "type": "Identifier", - "start": 141, - "end": 142, + "start": 145, + "end": 147, "loc": { "start": { "line": 7, @@ -721,84 +726,84 @@ }, "end": { "line": 7, - "column": 6 + "column": 7 }, - "identifierName": "T" + "identifierName": "T5" }, - "name": "T" + "name": "T5" }, "typeParameters": null, "right": { "type": "ObjectTypeAnnotation", - "start": 145, - "end": 167, + "start": 150, + "end": 172, "loc": { "start": { "line": 7, - "column": 9 + "column": 10 }, "end": { "line": 7, - "column": 31 + "column": 32 } }, "callProperties": [ { "type": "ObjectTypeCallProperty", - "start": 147, - "end": 164, + "start": 152, + "end": 169, "loc": { "start": { "line": 7, - "column": 11 + "column": 12 }, "end": { "line": 7, - "column": 28 + "column": 29 } }, "static": false, "value": { "type": "FunctionTypeAnnotation", - "start": 147, - "end": 164, + "start": 152, + "end": 169, "loc": { "start": { "line": 7, - "column": 11 + "column": 12 }, "end": { "line": 7, - "column": 28 + "column": 29 } }, "params": [ { "type": "FunctionTypeParam", - "start": 151, - "end": 155, + "start": 156, + "end": 160, "loc": { "start": { "line": 7, - "column": 15 + "column": 16 }, "end": { "line": 7, - "column": 19 + "column": 20 } }, "name": { "type": "Identifier", - "start": 151, - "end": 152, + "start": 156, + "end": 157, "loc": { "start": { "line": 7, - "column": 15 + "column": 16 }, "end": { "line": 7, - "column": 16 + "column": 17 }, "identifierName": "x" }, @@ -807,31 +812,31 @@ "optional": false, "typeAnnotation": { "type": "GenericTypeAnnotation", - "start": 154, - "end": 155, + "start": 159, + "end": 160, "loc": { "start": { "line": 7, - "column": 18 + "column": 19 }, "end": { "line": 7, - "column": 19 + "column": 20 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 154, - "end": 155, + "start": 159, + "end": 160, "loc": { "start": { "line": 7, - "column": 18 + "column": 19 }, "end": { "line": 7, - "column": 19 + "column": 20 }, "identifierName": "T" }, @@ -843,31 +848,31 @@ "rest": null, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 147, - "end": 150, + "start": 152, + "end": 155, "loc": { "start": { "line": 7, - "column": 11 + "column": 12 }, "end": { "line": 7, - "column": 14 + "column": 15 } }, "params": [ { "type": "TypeParameter", - "start": 148, - "end": 149, + "start": 153, + "end": 154, "loc": { "start": { "line": 7, - "column": 12 + "column": 13 }, "end": { "line": 7, - "column": 13 + "column": 14 } }, "name": "T", @@ -877,16 +882,16 @@ }, "returnType": { "type": "NumberTypeAnnotation", - "start": 158, - "end": 164, + "start": 163, + "end": 169, "loc": { "start": { "line": 7, - "column": 22 + "column": 23 }, "end": { "line": 7, - "column": 28 + "column": 29 } } } @@ -896,13 +901,14 @@ "properties": [], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, { "type": "DeclareClass", - "start": 169, - "end": 203, + "start": 174, + "end": 209, "loc": { "start": { "line": 9, @@ -910,13 +916,13 @@ }, "end": { "line": 9, - "column": 34 + "column": 35 } }, "id": { "type": "Identifier", - "start": 183, - "end": 184, + "start": 188, + "end": 190, "loc": { "start": { "line": 9, @@ -924,11 +930,11 @@ }, "end": { "line": 9, - "column": 15 + "column": 16 }, - "identifierName": "T" + "identifierName": "T6" }, - "name": "T" + "name": "T6" }, "typeParameters": null, "extends": [], @@ -936,46 +942,46 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 185, - "end": 203, + "start": 191, + "end": 209, "loc": { "start": { "line": 9, - "column": 16 + "column": 17 }, "end": { "line": 9, - "column": 34 + "column": 35 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 187, - "end": 200, + "start": 193, + "end": 206, "loc": { "start": { "line": 9, - "column": 18 + "column": 19 }, "end": { "line": 9, - "column": 31 + "column": 32 } }, "key": { "type": "Identifier", - "start": 187, - "end": 190, + "start": 193, + "end": 196, "loc": { "start": { "line": 9, - "column": 18 + "column": 19 }, "end": { "line": 9, - "column": 21 + "column": 22 }, "identifierName": "foo" }, @@ -987,16 +993,16 @@ "method": true, "value": { "type": "FunctionTypeAnnotation", - "start": 187, - "end": 200, + "start": 193, + "end": 206, "loc": { "start": { "line": 9, - "column": 18 + "column": 19 }, "end": { "line": 9, - "column": 31 + "column": 32 } }, "params": [], @@ -1004,16 +1010,16 @@ "typeParameters": null, "returnType": { "type": "NumberTypeAnnotation", - "start": 194, - "end": 200, + "start": 200, + "end": 206, "loc": { "start": { "line": 9, - "column": 25 + "column": 26 }, "end": { "line": 9, - "column": 31 + "column": 32 } } } @@ -1028,8 +1034,8 @@ }, { "type": "DeclareClass", - "start": 204, - "end": 245, + "start": 210, + "end": 252, "loc": { "start": { "line": 10, @@ -1037,13 +1043,13 @@ }, "end": { "line": 10, - "column": 41 + "column": 42 } }, "id": { "type": "Identifier", - "start": 218, - "end": 219, + "start": 224, + "end": 226, "loc": { "start": { "line": 10, @@ -1051,11 +1057,11 @@ }, "end": { "line": 10, - "column": 15 + "column": 16 }, - "identifierName": "T" + "identifierName": "T7" }, - "name": "T" + "name": "T7" }, "typeParameters": null, "extends": [], @@ -1063,46 +1069,46 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 220, - "end": 245, + "start": 227, + "end": 252, "loc": { "start": { "line": 10, - "column": 16 + "column": 17 }, "end": { "line": 10, - "column": 41 + "column": 42 } }, "callProperties": [], "properties": [ { "type": "ObjectTypeProperty", - "start": 222, - "end": 242, + "start": 229, + "end": 249, "loc": { "start": { "line": 10, - "column": 18 + "column": 19 }, "end": { "line": 10, - "column": 38 + "column": 39 } }, "key": { "type": "Identifier", - "start": 229, - "end": 232, + "start": 236, + "end": 239, "loc": { "start": { "line": 10, - "column": 25 + "column": 26 }, "end": { "line": 10, - "column": 28 + "column": 29 }, "identifierName": "foo" }, @@ -1114,16 +1120,16 @@ "method": true, "value": { "type": "FunctionTypeAnnotation", - "start": 222, - "end": 242, + "start": 229, + "end": 249, "loc": { "start": { "line": 10, - "column": 18 + "column": 19 }, "end": { "line": 10, - "column": 38 + "column": 39 } }, "params": [], @@ -1131,16 +1137,16 @@ "typeParameters": null, "returnType": { "type": "NumberTypeAnnotation", - "start": 236, - "end": 242, + "start": 243, + "end": 249, "loc": { "start": { "line": 10, - "column": 32 + "column": 33 }, "end": { "line": 10, - "column": 38 + "column": 39 } } } @@ -1155,8 +1161,8 @@ }, { "type": "DeclareClass", - "start": 246, - "end": 276, + "start": 253, + "end": 284, "loc": { "start": { "line": 11, @@ -1164,13 +1170,13 @@ }, "end": { "line": 11, - "column": 30 + "column": 31 } }, "id": { "type": "Identifier", - "start": 260, - "end": 261, + "start": 267, + "end": 269, "loc": { "start": { "line": 11, @@ -1178,11 +1184,11 @@ }, "end": { "line": 11, - "column": 15 + "column": 16 }, - "identifierName": "T" + "identifierName": "T8" }, - "name": "T" + "name": "T8" }, "typeParameters": null, "extends": [], @@ -1190,46 +1196,46 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 262, - "end": 276, + "start": 270, + "end": 284, "loc": { "start": { "line": 11, - "column": 16 + "column": 17 }, "end": { "line": 11, - "column": 30 + "column": 31 } }, "callProperties": [ { "type": "ObjectTypeCallProperty", - "start": 264, - "end": 274, + "start": 272, + "end": 282, "loc": { "start": { "line": 11, - "column": 18 + "column": 19 }, "end": { "line": 11, - "column": 28 + "column": 29 } }, "static": false, "value": { "type": "FunctionTypeAnnotation", - "start": 264, - "end": 274, + "start": 272, + "end": 282, "loc": { "start": { "line": 11, - "column": 18 + "column": 19 }, "end": { "line": 11, - "column": 28 + "column": 29 } }, "params": [], @@ -1237,16 +1243,16 @@ "typeParameters": null, "returnType": { "type": "NumberTypeAnnotation", - "start": 268, - "end": 274, + "start": 276, + "end": 282, "loc": { "start": { "line": 11, - "column": 22 + "column": 23 }, "end": { "line": 11, - "column": 28 + "column": 29 } } } @@ -1261,8 +1267,8 @@ }, { "type": "DeclareClass", - "start": 277, - "end": 314, + "start": 285, + "end": 323, "loc": { "start": { "line": 12, @@ -1270,13 +1276,13 @@ }, "end": { "line": 12, - "column": 37 + "column": 38 } }, "id": { "type": "Identifier", - "start": 291, - "end": 292, + "start": 299, + "end": 301, "loc": { "start": { "line": 12, @@ -1284,11 +1290,11 @@ }, "end": { "line": 12, - "column": 15 + "column": 16 }, - "identifierName": "T" + "identifierName": "T9" }, - "name": "T" + "name": "T9" }, "typeParameters": null, "extends": [], @@ -1296,46 +1302,46 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 293, - "end": 314, + "start": 302, + "end": 323, "loc": { "start": { "line": 12, - "column": 16 + "column": 17 }, "end": { "line": 12, - "column": 37 + "column": 38 } }, "callProperties": [ { "type": "ObjectTypeCallProperty", - "start": 295, - "end": 312, + "start": 304, + "end": 321, "loc": { "start": { "line": 12, - "column": 18 + "column": 19 }, "end": { "line": 12, - "column": 35 + "column": 36 } }, "static": true, "value": { "type": "FunctionTypeAnnotation", - "start": 302, - "end": 312, + "start": 311, + "end": 321, "loc": { "start": { "line": 12, - "column": 25 + "column": 26 }, "end": { "line": 12, - "column": 35 + "column": 36 } }, "params": [], @@ -1343,16 +1349,16 @@ "typeParameters": null, "returnType": { "type": "NumberTypeAnnotation", - "start": 306, - "end": 312, + "start": 315, + "end": 321, "loc": { "start": { "line": 12, - "column": 29 + "column": 30 }, "end": { "line": 12, - "column": 35 + "column": 36 } } } diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/with-default-invalid/options.json b/packages/babel-parser/test/fixtures/flow/type-annotations/with-default-invalid/options.json index aedf72ddb707..24792311b3e9 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/with-default-invalid/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/with-default-invalid/options.json @@ -1,4 +1,3 @@ { - "throws": - "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25` (1:20)" + "throws": "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25` (1:20)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js index e34ea63759dc..168e2cff4a3e 100644 --- a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/input.js @@ -1 +1,2 @@ +let foo; export type { foo }; diff --git a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json index 4481726d786b..f4d18be8251b 100644 --- a/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-exports/specifier/output.json @@ -1,28 +1,28 @@ { "type": "File", "start": 0, - "end": 20, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, "program": { "type": "Program", "start": 0, - "end": 20, + "end": 29, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, + "line": 2, "column": 20 } }, @@ -30,9 +30,9 @@ "interpreter": null, "body": [ { - "type": "ExportNamedDeclaration", + "type": "VariableDeclaration", "start": 0, - "end": 20, + "end": 8, "loc": { "start": { "line": 1, @@ -40,35 +40,86 @@ }, "end": { "line": 1, + "column": 8 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": null + } + ], + "kind": "let" + }, + { + "type": "ExportNamedDeclaration", + "start": 9, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, "column": 20 } }, "specifiers": [ { "type": "ExportSpecifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 } }, "local": { "type": "Identifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 }, "identifierName": "foo" @@ -77,15 +128,15 @@ }, "exported": { "type": "Identifier", - "start": 14, - "end": 17, + "start": 23, + "end": 26, "loc": { "start": { - "line": 1, + "line": 2, "column": 14 }, "end": { - "line": 1, + "line": 2, "column": 17 }, "identifierName": "foo" diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/input.js b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/input.js new file mode 100644 index 000000000000..34f185e05fe4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/input.js @@ -0,0 +1 @@ +import type, { foo } from "bar"; diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/output.json b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/output.json new file mode 100644 index 000000000000..f5fc078a42ce --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-2/output.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "local": { + "type": "Identifier", + "start": 7, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "type" + }, + "name": "type" + } + }, + { + "type": "ImportSpecifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "imported": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "importKind": null, + "local": { + "type": "Identifier", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "importKind": "value", + "source": { + "type": "StringLiteral", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "extra": { + "rawValue": "bar", + "raw": "\"bar\"" + }, + "value": "bar" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/input.js b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/input.js index 43d6942549b4..8dcd1106d55e 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/input.js @@ -5,7 +5,7 @@ import {type as as foo} from "foo"; import {type t as u} from "foo"; import {type switch} from "foo"; -import {typeof t} from "foo"; -import {typeof as} from "foo"; -import {typeof t as u} from "foo"; -import {typeof switch} from "foo"; +import {typeof t2} from "foo"; +import {typeof as2} from "foo"; +import {typeof t as u2} from "foo"; +import {typeof switch2} from "foo"; diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/output.json b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/output.json index f464931404cd..aeb7eded0711 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 316, + "end": 320, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 11, - "column": 34 + "column": 35 } }, "program": { "type": "Program", "start": 0, - "end": 316, + "end": 320, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 11, - "column": 34 + "column": 35 } }, "sourceType": "module", @@ -560,7 +560,7 @@ { "type": "ImportDeclaration", "start": 186, - "end": 215, + "end": 216, "loc": { "start": { "line": 8, @@ -568,14 +568,14 @@ }, "end": { "line": 8, - "column": 29 + "column": 30 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 194, - "end": 202, + "end": 203, "loc": { "start": { "line": 8, @@ -583,13 +583,13 @@ }, "end": { "line": 8, - "column": 16 + "column": 17 } }, "imported": { "type": "Identifier", "start": 201, - "end": 202, + "end": 203, "loc": { "start": { "line": 8, @@ -597,17 +597,17 @@ }, "end": { "line": 8, - "column": 16 + "column": 17 }, - "identifierName": "t" + "identifierName": "t2" }, - "name": "t" + "name": "t2" }, "importKind": "typeof", "local": { "type": "Identifier", "start": 201, - "end": 202, + "end": 203, "loc": { "start": { "line": 8, @@ -615,27 +615,27 @@ }, "end": { "line": 8, - "column": 16 + "column": 17 }, - "identifierName": "t" + "identifierName": "t2" }, - "name": "t" + "name": "t2" } } ], "importKind": "value", "source": { "type": "StringLiteral", - "start": 209, - "end": 214, + "start": 210, + "end": 215, "loc": { "start": { "line": 8, - "column": 23 + "column": 24 }, "end": { "line": 8, - "column": 28 + "column": 29 } }, "extra": { @@ -647,8 +647,8 @@ }, { "type": "ImportDeclaration", - "start": 216, - "end": 246, + "start": 217, + "end": 248, "loc": { "start": { "line": 9, @@ -656,14 +656,14 @@ }, "end": { "line": 9, - "column": 30 + "column": 31 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 224, - "end": 233, + "start": 225, + "end": 235, "loc": { "start": { "line": 9, @@ -671,13 +671,13 @@ }, "end": { "line": 9, - "column": 17 + "column": 18 } }, "imported": { "type": "Identifier", - "start": 231, - "end": 233, + "start": 232, + "end": 235, "loc": { "start": { "line": 9, @@ -685,17 +685,17 @@ }, "end": { "line": 9, - "column": 17 + "column": 18 }, - "identifierName": "as" + "identifierName": "as2" }, - "name": "as" + "name": "as2" }, "importKind": "typeof", "local": { "type": "Identifier", - "start": 231, - "end": 233, + "start": 232, + "end": 235, "loc": { "start": { "line": 9, @@ -703,27 +703,27 @@ }, "end": { "line": 9, - "column": 17 + "column": 18 }, - "identifierName": "as" + "identifierName": "as2" }, - "name": "as" + "name": "as2" } } ], "importKind": "value", "source": { "type": "StringLiteral", - "start": 240, - "end": 245, + "start": 242, + "end": 247, "loc": { "start": { "line": 9, - "column": 24 + "column": 25 }, "end": { "line": 9, - "column": 29 + "column": 30 } }, "extra": { @@ -735,8 +735,8 @@ }, { "type": "ImportDeclaration", - "start": 247, - "end": 281, + "start": 249, + "end": 284, "loc": { "start": { "line": 10, @@ -744,14 +744,14 @@ }, "end": { "line": 10, - "column": 34 + "column": 35 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 255, - "end": 268, + "start": 257, + "end": 271, "loc": { "start": { "line": 10, @@ -759,13 +759,13 @@ }, "end": { "line": 10, - "column": 21 + "column": 22 } }, "imported": { "type": "Identifier", - "start": 262, - "end": 263, + "start": 264, + "end": 265, "loc": { "start": { "line": 10, @@ -782,8 +782,8 @@ "importKind": "typeof", "local": { "type": "Identifier", - "start": 267, - "end": 268, + "start": 269, + "end": 271, "loc": { "start": { "line": 10, @@ -791,27 +791,27 @@ }, "end": { "line": 10, - "column": 21 + "column": 22 }, - "identifierName": "u" + "identifierName": "u2" }, - "name": "u" + "name": "u2" } } ], "importKind": "value", "source": { "type": "StringLiteral", - "start": 275, - "end": 280, + "start": 278, + "end": 283, "loc": { "start": { "line": 10, - "column": 28 + "column": 29 }, "end": { "line": 10, - "column": 33 + "column": 34 } }, "extra": { @@ -823,8 +823,8 @@ }, { "type": "ImportDeclaration", - "start": 282, - "end": 316, + "start": 285, + "end": 320, "loc": { "start": { "line": 11, @@ -832,14 +832,14 @@ }, "end": { "line": 11, - "column": 34 + "column": 35 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 290, - "end": 303, + "start": 293, + "end": 307, "loc": { "start": { "line": 11, @@ -847,13 +847,13 @@ }, "end": { "line": 11, - "column": 21 + "column": 22 } }, "imported": { "type": "Identifier", - "start": 297, - "end": 303, + "start": 300, + "end": 307, "loc": { "start": { "line": 11, @@ -861,17 +861,17 @@ }, "end": { "line": 11, - "column": 21 + "column": 22 }, - "identifierName": "switch" + "identifierName": "switch2" }, - "name": "switch" + "name": "switch2" }, "importKind": "typeof", "local": { "type": "Identifier", - "start": 297, - "end": 303, + "start": 300, + "end": 307, "loc": { "start": { "line": 11, @@ -879,27 +879,27 @@ }, "end": { "line": 11, - "column": 21 + "column": 22 }, - "identifierName": "switch" + "identifierName": "switch2" }, - "name": "switch" + "name": "switch2" } } ], "importKind": "value", "source": { "type": "StringLiteral", - "start": 310, - "end": 315, + "start": 314, + "end": 319, "loc": { "start": { "line": 11, - "column": 28 + "column": 29 }, "end": { "line": 11, - "column": 33 + "column": 34 } }, "extra": { diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type/input.js b/packages/babel-parser/test/fixtures/flow/type-imports/import-type/input.js index 70d71926f930..c2a9d4360fa8 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/import-type/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type/input.js @@ -1,14 +1,13 @@ -import type Def from "foo"; -import type {named} from "foo"; -import type Def, {named} from "foo"; -import type switch from "foo"; -import type { switch } from "foo"; -import type { foo, bar } from "baz"; +import type Def1 from "foo"; +import type {named1} from "foo"; +import type Def2, {named2} from "foo"; +import type switch1 from "foo"; +import type { switch2 } from "foo"; +import type { foo1, bar1 } from "baz"; import type from "foo"; -import type, { foo } from "bar"; -import typeof foo from "bar"; -import typeof switch from "foo"; -import typeof { switch } from "foo"; -import typeof { foo as bar } from "baz"; -import typeof * as ns from "foo"; -import typeof * as switch from "foo"; +import typeof foo3 from "bar"; +import typeof switch4 from "foo"; +import typeof { switch5 } from "foo"; +import typeof { foo as bar6 } from "baz"; +import typeof * as ns7 from "foo"; +import typeof * as switch8 from "foo"; diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/import-type/output.json b/packages/babel-parser/test/fixtures/flow/type-imports/import-type/output.json index 904bcfab268f..8e626c8ad0a5 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/import-type/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/import-type/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 469, + "end": 450, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, - "column": 37 + "line": 13, + "column": 38 } }, "program": { "type": "Program", "start": 0, - "end": 469, + "end": 450, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 14, - "column": 37 + "line": 13, + "column": 38 } }, "sourceType": "module", @@ -32,7 +32,7 @@ { "type": "ImportDeclaration", "start": 0, - "end": 27, + "end": 28, "loc": { "start": { "line": 1, @@ -40,14 +40,14 @@ }, "end": { "line": 1, - "column": 27 + "column": 28 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 12, - "end": 15, + "end": 16, "loc": { "start": { "line": 1, @@ -55,13 +55,13 @@ }, "end": { "line": 1, - "column": 15 + "column": 16 } }, "local": { "type": "Identifier", "start": 12, - "end": 15, + "end": 16, "loc": { "start": { "line": 1, @@ -69,27 +69,27 @@ }, "end": { "line": 1, - "column": 15 + "column": 16 }, - "identifierName": "Def" + "identifierName": "Def1" }, - "name": "Def" + "name": "Def1" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 21, - "end": 26, + "start": 22, + "end": 27, "loc": { "start": { "line": 1, - "column": 21 + "column": 22 }, "end": { "line": 1, - "column": 26 + "column": 27 } }, "extra": { @@ -101,8 +101,8 @@ }, { "type": "ImportDeclaration", - "start": 28, - "end": 59, + "start": 29, + "end": 61, "loc": { "start": { "line": 2, @@ -110,14 +110,14 @@ }, "end": { "line": 2, - "column": 31 + "column": 32 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 41, - "end": 46, + "start": 42, + "end": 48, "loc": { "start": { "line": 2, @@ -125,13 +125,13 @@ }, "end": { "line": 2, - "column": 18 + "column": 19 } }, "imported": { "type": "Identifier", - "start": 41, - "end": 46, + "start": 42, + "end": 48, "loc": { "start": { "line": 2, @@ -139,17 +139,17 @@ }, "end": { "line": 2, - "column": 18 + "column": 19 }, - "identifierName": "named" + "identifierName": "named1" }, - "name": "named" + "name": "named1" }, "importKind": null, "local": { "type": "Identifier", - "start": 41, - "end": 46, + "start": 42, + "end": 48, "loc": { "start": { "line": 2, @@ -157,27 +157,27 @@ }, "end": { "line": 2, - "column": 18 + "column": 19 }, - "identifierName": "named" + "identifierName": "named1" }, - "name": "named" + "name": "named1" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 53, - "end": 58, + "start": 55, + "end": 60, "loc": { "start": { "line": 2, - "column": 25 + "column": 26 }, "end": { "line": 2, - "column": 30 + "column": 31 } }, "extra": { @@ -189,8 +189,8 @@ }, { "type": "ImportDeclaration", - "start": 60, - "end": 96, + "start": 62, + "end": 100, "loc": { "start": { "line": 3, @@ -198,14 +198,14 @@ }, "end": { "line": 3, - "column": 36 + "column": 38 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 72, - "end": 75, + "start": 74, + "end": 78, "loc": { "start": { "line": 3, @@ -213,13 +213,13 @@ }, "end": { "line": 3, - "column": 15 + "column": 16 } }, "local": { "type": "Identifier", - "start": 72, - "end": 75, + "start": 74, + "end": 78, "loc": { "start": { "line": 3, @@ -227,77 +227,77 @@ }, "end": { "line": 3, - "column": 15 + "column": 16 }, - "identifierName": "Def" + "identifierName": "Def2" }, - "name": "Def" + "name": "Def2" } }, { "type": "ImportSpecifier", - "start": 78, - "end": 83, + "start": 81, + "end": 87, "loc": { "start": { "line": 3, - "column": 18 + "column": 19 }, "end": { "line": 3, - "column": 23 + "column": 25 } }, "imported": { "type": "Identifier", - "start": 78, - "end": 83, + "start": 81, + "end": 87, "loc": { "start": { "line": 3, - "column": 18 + "column": 19 }, "end": { "line": 3, - "column": 23 + "column": 25 }, - "identifierName": "named" + "identifierName": "named2" }, - "name": "named" + "name": "named2" }, "importKind": null, "local": { "type": "Identifier", - "start": 78, - "end": 83, + "start": 81, + "end": 87, "loc": { "start": { "line": 3, - "column": 18 + "column": 19 }, "end": { "line": 3, - "column": 23 + "column": 25 }, - "identifierName": "named" + "identifierName": "named2" }, - "name": "named" + "name": "named2" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 90, - "end": 95, + "start": 94, + "end": 99, "loc": { "start": { "line": 3, - "column": 30 + "column": 32 }, "end": { "line": 3, - "column": 35 + "column": 37 } }, "extra": { @@ -309,8 +309,8 @@ }, { "type": "ImportDeclaration", - "start": 97, - "end": 127, + "start": 101, + "end": 132, "loc": { "start": { "line": 4, @@ -318,14 +318,14 @@ }, "end": { "line": 4, - "column": 30 + "column": 31 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 109, - "end": 115, + "start": 113, + "end": 120, "loc": { "start": { "line": 4, @@ -333,13 +333,13 @@ }, "end": { "line": 4, - "column": 18 + "column": 19 } }, "local": { "type": "Identifier", - "start": 109, - "end": 115, + "start": 113, + "end": 120, "loc": { "start": { "line": 4, @@ -347,27 +347,27 @@ }, "end": { "line": 4, - "column": 18 + "column": 19 }, - "identifierName": "switch" + "identifierName": "switch1" }, - "name": "switch" + "name": "switch1" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 121, - "end": 126, + "start": 126, + "end": 131, "loc": { "start": { "line": 4, - "column": 24 + "column": 25 }, "end": { "line": 4, - "column": 29 + "column": 30 } }, "extra": { @@ -379,8 +379,8 @@ }, { "type": "ImportDeclaration", - "start": 128, - "end": 162, + "start": 133, + "end": 168, "loc": { "start": { "line": 5, @@ -388,14 +388,14 @@ }, "end": { "line": 5, - "column": 34 + "column": 35 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 142, - "end": 148, + "start": 147, + "end": 154, "loc": { "start": { "line": 5, @@ -403,13 +403,13 @@ }, "end": { "line": 5, - "column": 20 + "column": 21 } }, "imported": { "type": "Identifier", - "start": 142, - "end": 148, + "start": 147, + "end": 154, "loc": { "start": { "line": 5, @@ -417,17 +417,17 @@ }, "end": { "line": 5, - "column": 20 + "column": 21 }, - "identifierName": "switch" + "identifierName": "switch2" }, - "name": "switch" + "name": "switch2" }, "importKind": null, "local": { "type": "Identifier", - "start": 142, - "end": 148, + "start": 147, + "end": 154, "loc": { "start": { "line": 5, @@ -435,27 +435,27 @@ }, "end": { "line": 5, - "column": 20 + "column": 21 }, - "identifierName": "switch" + "identifierName": "switch2" }, - "name": "switch" + "name": "switch2" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 156, - "end": 161, + "start": 162, + "end": 167, "loc": { "start": { "line": 5, - "column": 28 + "column": 29 }, "end": { "line": 5, - "column": 33 + "column": 34 } }, "extra": { @@ -467,8 +467,8 @@ }, { "type": "ImportDeclaration", - "start": 163, - "end": 199, + "start": 169, + "end": 207, "loc": { "start": { "line": 6, @@ -476,14 +476,14 @@ }, "end": { "line": 6, - "column": 36 + "column": 38 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 177, - "end": 180, + "start": 183, + "end": 187, "loc": { "start": { "line": 6, @@ -491,13 +491,13 @@ }, "end": { "line": 6, - "column": 17 + "column": 18 } }, "imported": { "type": "Identifier", - "start": 177, - "end": 180, + "start": 183, + "end": 187, "loc": { "start": { "line": 6, @@ -505,17 +505,17 @@ }, "end": { "line": 6, - "column": 17 + "column": 18 }, - "identifierName": "foo" + "identifierName": "foo1" }, - "name": "foo" + "name": "foo1" }, "importKind": null, "local": { "type": "Identifier", - "start": 177, - "end": 180, + "start": 183, + "end": 187, "loc": { "start": { "line": 6, @@ -523,77 +523,77 @@ }, "end": { "line": 6, - "column": 17 + "column": 18 }, - "identifierName": "foo" + "identifierName": "foo1" }, - "name": "foo" + "name": "foo1" } }, { "type": "ImportSpecifier", - "start": 182, - "end": 185, + "start": 189, + "end": 193, "loc": { "start": { "line": 6, - "column": 19 + "column": 20 }, "end": { "line": 6, - "column": 22 + "column": 24 } }, "imported": { "type": "Identifier", - "start": 182, - "end": 185, + "start": 189, + "end": 193, "loc": { "start": { "line": 6, - "column": 19 + "column": 20 }, "end": { "line": 6, - "column": 22 + "column": 24 }, - "identifierName": "bar" + "identifierName": "bar1" }, - "name": "bar" + "name": "bar1" }, "importKind": null, "local": { "type": "Identifier", - "start": 182, - "end": 185, + "start": 189, + "end": 193, "loc": { "start": { "line": 6, - "column": 19 + "column": 20 }, "end": { "line": 6, - "column": 22 + "column": 24 }, - "identifierName": "bar" + "identifierName": "bar1" }, - "name": "bar" + "name": "bar1" } } ], "importKind": "type", "source": { "type": "StringLiteral", - "start": 193, - "end": 198, + "start": 201, + "end": 206, "loc": { "start": { "line": 6, - "column": 30 + "column": 32 }, "end": { "line": 6, - "column": 35 + "column": 37 } }, "extra": { @@ -605,8 +605,8 @@ }, { "type": "ImportDeclaration", - "start": 200, - "end": 223, + "start": 208, + "end": 231, "loc": { "start": { "line": 7, @@ -620,8 +620,8 @@ "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 207, - "end": 211, + "start": 215, + "end": 219, "loc": { "start": { "line": 7, @@ -634,8 +634,8 @@ }, "local": { "type": "Identifier", - "start": 207, - "end": 211, + "start": 215, + "end": 219, "loc": { "start": { "line": 7, @@ -654,8 +654,8 @@ "importKind": "value", "source": { "type": "StringLiteral", - "start": 217, - "end": 222, + "start": 225, + "end": 230, "loc": { "start": { "line": 7, @@ -675,8 +675,8 @@ }, { "type": "ImportDeclaration", - "start": 224, - "end": 256, + "start": 232, + "end": 262, "loc": { "start": { "line": 8, @@ -684,106 +684,56 @@ }, "end": { "line": 8, - "column": 32 + "column": 30 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 231, - "end": 235, - "loc": { - "start": { - "line": 8, - "column": 7 - }, - "end": { - "line": 8, - "column": 11 - } - }, - "local": { - "type": "Identifier", - "start": 231, - "end": 235, - "loc": { - "start": { - "line": 8, - "column": 7 - }, - "end": { - "line": 8, - "column": 11 - }, - "identifierName": "type" - }, - "name": "type" - } - }, - { - "type": "ImportSpecifier", - "start": 239, - "end": 242, + "start": 246, + "end": 250, "loc": { "start": { "line": 8, - "column": 15 + "column": 14 }, "end": { "line": 8, "column": 18 } }, - "imported": { - "type": "Identifier", - "start": 239, - "end": 242, - "loc": { - "start": { - "line": 8, - "column": 15 - }, - "end": { - "line": 8, - "column": 18 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "importKind": null, "local": { "type": "Identifier", - "start": 239, - "end": 242, + "start": 246, + "end": 250, "loc": { "start": { "line": 8, - "column": 15 + "column": 14 }, "end": { "line": 8, "column": 18 }, - "identifierName": "foo" + "identifierName": "foo3" }, - "name": "foo" + "name": "foo3" } } ], - "importKind": "value", + "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 250, - "end": 255, + "start": 256, + "end": 261, "loc": { "start": { "line": 8, - "column": 26 + "column": 24 }, "end": { "line": 8, - "column": 31 + "column": 29 } }, "extra": { @@ -795,8 +745,8 @@ }, { "type": "ImportDeclaration", - "start": 257, - "end": 286, + "start": 263, + "end": 296, "loc": { "start": { "line": 9, @@ -804,14 +754,14 @@ }, "end": { "line": 9, - "column": 29 + "column": 33 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 271, - "end": 274, + "start": 277, + "end": 284, "loc": { "start": { "line": 9, @@ -819,13 +769,13 @@ }, "end": { "line": 9, - "column": 17 + "column": 21 } }, "local": { "type": "Identifier", - "start": 271, - "end": 274, + "start": 277, + "end": 284, "loc": { "start": { "line": 9, @@ -833,40 +783,40 @@ }, "end": { "line": 9, - "column": 17 + "column": 21 }, - "identifierName": "foo" + "identifierName": "switch4" }, - "name": "foo" + "name": "switch4" } } ], "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 280, - "end": 285, + "start": 290, + "end": 295, "loc": { "start": { "line": 9, - "column": 23 + "column": 27 }, "end": { "line": 9, - "column": 28 + "column": 32 } }, "extra": { - "rawValue": "bar", - "raw": "\"bar\"" + "rawValue": "foo", + "raw": "\"foo\"" }, - "value": "bar" + "value": "foo" } }, { "type": "ImportDeclaration", - "start": 287, - "end": 319, + "start": 297, + "end": 334, "loc": { "start": { "line": 10, @@ -874,56 +824,74 @@ }, "end": { "line": 10, - "column": 32 + "column": 37 } }, "specifiers": [ { - "type": "ImportDefaultSpecifier", - "start": 301, - "end": 307, + "type": "ImportSpecifier", + "start": 313, + "end": 320, "loc": { "start": { "line": 10, - "column": 14 + "column": 16 }, "end": { "line": 10, - "column": 20 + "column": 23 } }, + "imported": { + "type": "Identifier", + "start": 313, + "end": 320, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 23 + }, + "identifierName": "switch5" + }, + "name": "switch5" + }, + "importKind": null, "local": { "type": "Identifier", - "start": 301, - "end": 307, + "start": 313, + "end": 320, "loc": { "start": { "line": 10, - "column": 14 + "column": 16 }, "end": { "line": 10, - "column": 20 + "column": 23 }, - "identifierName": "switch" + "identifierName": "switch5" }, - "name": "switch" + "name": "switch5" } } ], "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 313, - "end": 318, + "start": 328, + "end": 333, "loc": { "start": { "line": 10, - "column": 26 + "column": 31 }, "end": { "line": 10, - "column": 31 + "column": 36 } }, "extra": { @@ -935,8 +903,8 @@ }, { "type": "ImportDeclaration", - "start": 320, - "end": 356, + "start": 335, + "end": 376, "loc": { "start": { "line": 11, @@ -944,14 +912,14 @@ }, "end": { "line": 11, - "column": 36 + "column": 41 } }, "specifiers": [ { "type": "ImportSpecifier", - "start": 336, - "end": 342, + "start": 351, + "end": 362, "loc": { "start": { "line": 11, @@ -959,13 +927,13 @@ }, "end": { "line": 11, - "column": 22 + "column": 27 } }, "imported": { "type": "Identifier", - "start": 336, - "end": 342, + "start": 351, + "end": 354, "loc": { "start": { "line": 11, @@ -973,58 +941,58 @@ }, "end": { "line": 11, - "column": 22 + "column": 19 }, - "identifierName": "switch" + "identifierName": "foo" }, - "name": "switch" + "name": "foo" }, "importKind": null, "local": { "type": "Identifier", - "start": 336, - "end": 342, + "start": 358, + "end": 362, "loc": { "start": { "line": 11, - "column": 16 + "column": 23 }, "end": { "line": 11, - "column": 22 + "column": 27 }, - "identifierName": "switch" + "identifierName": "bar6" }, - "name": "switch" + "name": "bar6" } } ], "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 350, - "end": 355, + "start": 370, + "end": 375, "loc": { "start": { "line": 11, - "column": 30 + "column": 35 }, "end": { "line": 11, - "column": 35 + "column": 40 } }, "extra": { - "rawValue": "foo", - "raw": "\"foo\"" + "rawValue": "baz", + "raw": "\"baz\"" }, - "value": "foo" + "value": "baz" } }, { "type": "ImportDeclaration", - "start": 357, - "end": 397, + "start": 377, + "end": 411, "loc": { "start": { "line": 12, @@ -1032,87 +1000,69 @@ }, "end": { "line": 12, - "column": 40 + "column": 34 } }, "specifiers": [ { - "type": "ImportSpecifier", - "start": 373, - "end": 383, + "type": "ImportNamespaceSpecifier", + "start": 391, + "end": 399, "loc": { "start": { "line": 12, - "column": 16 + "column": 14 }, "end": { "line": 12, - "column": 26 + "column": 22 } }, - "imported": { - "type": "Identifier", - "start": 373, - "end": 376, - "loc": { - "start": { - "line": 12, - "column": 16 - }, - "end": { - "line": 12, - "column": 19 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "importKind": null, "local": { "type": "Identifier", - "start": 380, - "end": 383, + "start": 396, + "end": 399, "loc": { "start": { "line": 12, - "column": 23 + "column": 19 }, "end": { "line": 12, - "column": 26 + "column": 22 }, - "identifierName": "bar" + "identifierName": "ns7" }, - "name": "bar" + "name": "ns7" } } ], "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 391, - "end": 396, + "start": 405, + "end": 410, "loc": { "start": { "line": 12, - "column": 34 + "column": 28 }, "end": { "line": 12, - "column": 39 + "column": 33 } }, "extra": { - "rawValue": "baz", - "raw": "\"baz\"" + "rawValue": "foo", + "raw": "\"foo\"" }, - "value": "baz" + "value": "foo" } }, { "type": "ImportDeclaration", - "start": 398, - "end": 431, + "start": 412, + "end": 450, "loc": { "start": { "line": 13, @@ -1120,14 +1070,14 @@ }, "end": { "line": 13, - "column": 33 + "column": 38 } }, "specifiers": [ { "type": "ImportNamespaceSpecifier", - "start": 412, - "end": 419, + "start": 426, + "end": 438, "loc": { "start": { "line": 13, @@ -1135,13 +1085,13 @@ }, "end": { "line": 13, - "column": 21 + "column": 26 } }, "local": { "type": "Identifier", - "start": 417, - "end": 419, + "start": 431, + "end": 438, "loc": { "start": { "line": 13, @@ -1149,97 +1099,27 @@ }, "end": { "line": 13, - "column": 21 + "column": 26 }, - "identifierName": "ns" + "identifierName": "switch8" }, - "name": "ns" + "name": "switch8" } } ], "importKind": "typeof", "source": { "type": "StringLiteral", - "start": 425, - "end": 430, + "start": 444, + "end": 449, "loc": { "start": { - "line": 13, - "column": 27 - }, - "end": { "line": 13, "column": 32 - } - }, - "extra": { - "rawValue": "foo", - "raw": "\"foo\"" - }, - "value": "foo" - } - }, - { - "type": "ImportDeclaration", - "start": 432, - "end": 469, - "loc": { - "start": { - "line": 14, - "column": 0 - }, - "end": { - "line": 14, - "column": 37 - } - }, - "specifiers": [ - { - "type": "ImportNamespaceSpecifier", - "start": 446, - "end": 457, - "loc": { - "start": { - "line": 14, - "column": 14 - }, - "end": { - "line": 14, - "column": 25 - } - }, - "local": { - "type": "Identifier", - "start": 451, - "end": 457, - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 25 - }, - "identifierName": "switch" - }, - "name": "switch" - } - } - ], - "importKind": "typeof", - "source": { - "type": "StringLiteral", - "start": 463, - "end": 468, - "loc": { - "start": { - "line": 14, - "column": 31 }, "end": { - "line": 14, - "column": 36 + "line": 13, + "column": 37 } }, "extra": { diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-2/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-2/options.json index 7f4fe7d13efb..7624c4d3b99a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-2/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-2/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:14)" + "throws": "Cannot overwrite reserved type string (1:14)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-3/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-3/options.json index 7f4fe7d13efb..7624c4d3b99a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-3/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-3/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:14)" + "throws": "Cannot overwrite reserved type string (1:14)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-4/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-4/options.json index 39481cdad495..d64a5d353bf8 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-4/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-4/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:19)" + "throws": "Cannot overwrite reserved type string (1:19)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-as/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-as/options.json index 011c7d25dad5..5133797973d2 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-as/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-as/options.json @@ -1,3 +1,3 @@ { - "throws": "debugger is a reserved word (1:17)" + "throws": "Unexpected keyword 'debugger' (1:17)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-2/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-2/options.json index 132b4a19ec67..036229c5b95a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-2/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-2/options.json @@ -1,4 +1,3 @@ { - "throws": - "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements (1:13)" + "throws": "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements (1:13)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-3/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-3/options.json index bb13e8023fa8..e425b795f180 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-3/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-3/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:16)" + "throws": "Cannot overwrite reserved type string (1:16)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-4/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-4/options.json index 7f4fe7d13efb..7624c4d3b99a 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-4/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand-4/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:14)" + "throws": "Cannot overwrite reserved type string (1:14)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json index 4ee840273c10..7aa4274c7160 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json @@ -1,4 +1,3 @@ { - "throws": - "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements (1:15)" + "throws": "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements (1:15)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type/options.json b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type/options.json index 6bf62df4a991..0c2cdd4d777c 100644 --- a/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-imports/invalid-import-type/options.json @@ -1,3 +1,3 @@ { - "throws": "Cannot overwrite primitive type string (1:12)" + "throws": "Cannot overwrite reserved type string (1:12)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json index c349e4e3999e..cf72e7dfcad7 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/arrow_error_without_jsx/options.json @@ -1,5 +1,4 @@ { "plugins": ["flow"], - "throws": - "Expected an arrow function after this type parameter declaration (1:0)" + "throws": "Expected an arrow function after this type parameter declaration (1:0)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js deleted file mode 100644 index e85753f1bf25..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/input.js +++ /dev/null @@ -1,3 +0,0 @@ -(class A { - foo() {} -}); diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json deleted file mode 100644 index ef2b7c682fba..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-1/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:8)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js deleted file mode 100644 index 088051643fa2..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/input.js +++ /dev/null @@ -1 +0,0 @@ -({ foo() {} }); diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json deleted file mode 100644 index 2a28555f76db..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-2/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js deleted file mode 100644 index 742685c460ec..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/input.js +++ /dev/null @@ -1 +0,0 @@ -declare class A { foo(): void } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json deleted file mode 100644 index fa579aa83145..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-3/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:24)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js deleted file mode 100644 index a35315333a49..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/input.js +++ /dev/null @@ -1,3 +0,0 @@ -class A { - foo() {} -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json deleted file mode 100644 index ef2b7c682fba..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-4/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:8)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js deleted file mode 100644 index 3223246d3979..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/input.js +++ /dev/null @@ -1 +0,0 @@ -function foo() {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json deleted file mode 100644 index 98d712379010..000000000000 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-5/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:15)" -} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/input.js new file mode 100644 index 000000000000..2b40a1ba03fc --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/input.js @@ -0,0 +1 @@ +class A extends B {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/options.json new file mode 100644 index 000000000000..6f017e5a5919 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-class-extends/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:20)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/input.js new file mode 100644 index 000000000000..018ada1c550e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/input.js @@ -0,0 +1 @@ +declare function foo() {} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/options.json new file mode 100644 index 000000000000..161afd296dc4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-declare-func/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \":\" (1:35)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/input.js new file mode 100644 index 000000000000..646522dea3d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/input.js @@ -0,0 +1 @@ +var x: Array diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/options.json new file mode 100644 index 000000000000..fbfad415eebf --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-invalid-var-type/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected \",\" (1:15)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-missing/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-missing/options.json index 3c2ac7c9b913..022607b81797 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-missing/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default-missing/options.json @@ -1,4 +1,3 @@ { - "throws": - "Type parameter declaration needs a default, since a preceding type parameter declaration has a default. (1:28)" + "throws": "Type parameter declaration needs a default, since a preceding type parameter declaration has a default. (1:28)" } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js index faa1bc88aeb7..4feffe1038d6 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/input.js @@ -1,22 +1,32 @@ -type A = T -type A = T -type A = T -type A = T -type A = T -class A {} -class A {} -class A {} -class A {} -;(class A {}) -;(class A {}) -;(class A {}) -;(class A {}) -declare class A {} -declare class A {} -declare class A {} -declare class A {} -interface A {} -interface A {} -interface A {} -interface A {} -type A = T +type A1 = T +type A2 = T +type A3 = T +type A4 = T +type A5 = T +class A6 {} +class A7 {} +class A8 {} +class A9 {} +;(class A10 {}) +;(class A11 {}) +;(class A12 {}) +;(class A13 {}) +declare class A14 {} +declare class A15 {} +declare class A16 {} +declare class A17 {} +interface A18 {} +interface A19 {} +interface A20 {} +interface A21 {} +type A22 = T +function A26() {} +;({ A28() {} }); +class A29 { + foo() {} +} +;(class A30 { + foo() {} +}); +declare class A31 { foo(): void } +() => 123; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json index 28f3fe73841a..8b2db5858c66 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 768, + "end": 1009, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 22, - "column": 20 + "line": 32, + "column": 22 } }, "program": { "type": "Program", "start": 0, - "end": 768, + "end": 1009, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 22, - "column": 20 + "line": 32, + "column": 22 } }, "sourceType": "module", @@ -32,7 +32,7 @@ { "type": "TypeAlias", "start": 0, - "end": 22, + "end": 23, "loc": { "start": { "line": 1, @@ -40,13 +40,13 @@ }, "end": { "line": 1, - "column": 22 + "column": 23 } }, "id": { "type": "Identifier", "start": 5, - "end": 6, + "end": 7, "loc": { "start": { "line": 1, @@ -54,55 +54,55 @@ }, "end": { "line": 1, - "column": 6 + "column": 7 }, - "identifierName": "A" + "identifierName": "A1" }, - "name": "A" + "name": "A1" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 6, - "end": 18, + "start": 7, + "end": 19, "loc": { "start": { "line": 1, - "column": 6 + "column": 7 }, "end": { "line": 1, - "column": 18 + "column": 19 } }, "params": [ { "type": "TypeParameter", - "start": 7, - "end": 17, + "start": 8, + "end": 18, "loc": { "start": { "line": 1, - "column": 7 + "column": 8 }, "end": { "line": 1, - "column": 17 + "column": 18 } }, "name": "T", "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 11, - "end": 17, + "start": 12, + "end": 18, "loc": { "start": { "line": 1, - "column": 11 + "column": 12 }, "end": { "line": 1, - "column": 17 + "column": 18 } } } @@ -111,31 +111,31 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 21, - "end": 22, + "start": 22, + "end": 23, "loc": { "start": { "line": 1, - "column": 21 + "column": 22 }, "end": { "line": 1, - "column": 22 + "column": 23 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 21, - "end": 22, + "start": 22, + "end": 23, "loc": { "start": { "line": 1, - "column": 21 + "column": 22 }, "end": { "line": 1, - "column": 22 + "column": 23 }, "identifierName": "T" }, @@ -145,8 +145,8 @@ }, { "type": "TypeAlias", - "start": 23, - "end": 40, + "start": 24, + "end": 42, "loc": { "start": { "line": 2, @@ -154,13 +154,13 @@ }, "end": { "line": 2, - "column": 17 + "column": 18 } }, "id": { "type": "Identifier", - "start": 28, - "end": 29, + "start": 29, + "end": 31, "loc": { "start": { "line": 2, @@ -168,55 +168,55 @@ }, "end": { "line": 2, - "column": 6 + "column": 7 }, - "identifierName": "A" + "identifierName": "A2" }, - "name": "A" + "name": "A2" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 29, - "end": 36, + "start": 31, + "end": 38, "loc": { "start": { "line": 2, - "column": 6 + "column": 7 }, "end": { "line": 2, - "column": 13 + "column": 14 } }, "params": [ { "type": "TypeParameter", - "start": 30, - "end": 35, + "start": 32, + "end": 37, "loc": { "start": { "line": 2, - "column": 7 + "column": 8 }, "end": { "line": 2, - "column": 12 + "column": 13 } }, "name": "T", "variance": null, "default": { "type": "ExistsTypeAnnotation", - "start": 34, - "end": 35, + "start": 36, + "end": 37, "loc": { "start": { "line": 2, - "column": 11 + "column": 12 }, "end": { "line": 2, - "column": 12 + "column": 13 } } } @@ -225,31 +225,31 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 39, - "end": 40, + "start": 41, + "end": 42, "loc": { "start": { "line": 2, - "column": 16 + "column": 17 }, "end": { "line": 2, - "column": 17 + "column": 18 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 39, - "end": 40, + "start": 41, + "end": 42, "loc": { "start": { "line": 2, - "column": 16 + "column": 17 }, "end": { "line": 2, - "column": 17 + "column": 18 }, "identifierName": "T" }, @@ -259,8 +259,8 @@ }, { "type": "TypeAlias", - "start": 41, - "end": 72, + "start": 43, + "end": 75, "loc": { "start": { "line": 3, @@ -268,13 +268,13 @@ }, "end": { "line": 3, - "column": 31 + "column": 32 } }, "id": { "type": "Identifier", - "start": 46, - "end": 47, + "start": 48, + "end": 50, "loc": { "start": { "line": 3, @@ -282,83 +282,83 @@ }, "end": { "line": 3, - "column": 6 + "column": 7 }, - "identifierName": "A" + "identifierName": "A3" }, - "name": "A" + "name": "A3" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 47, - "end": 68, + "start": 50, + "end": 71, "loc": { "start": { "line": 3, - "column": 6 + "column": 7 }, "end": { "line": 3, - "column": 27 + "column": 28 } }, "params": [ { "type": "TypeParameter", - "start": 48, - "end": 67, + "start": 51, + "end": 70, "loc": { "start": { "line": 3, - "column": 7 + "column": 8 }, "end": { "line": 3, - "column": 26 + "column": 27 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 49, - "end": 58, + "start": 52, + "end": 61, "loc": { "start": { "line": 3, - "column": 8 + "column": 9 }, "end": { "line": 3, - "column": 17 + "column": 18 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 51, - "end": 58, + "start": 54, + "end": 61, "loc": { "start": { "line": 3, - "column": 10 + "column": 11 }, "end": { "line": 3, - "column": 17 + "column": 18 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 52, - "end": 58, + "start": 55, + "end": 61, "loc": { "start": { "line": 3, - "column": 11 + "column": 12 }, "end": { "line": 3, - "column": 17 + "column": 18 } } } @@ -366,16 +366,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 61, - "end": 67, + "start": 64, + "end": 70, "loc": { "start": { "line": 3, - "column": 20 + "column": 21 }, "end": { "line": 3, - "column": 26 + "column": 27 } } } @@ -384,31 +384,31 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 71, - "end": 72, + "start": 74, + "end": 75, "loc": { "start": { "line": 3, - "column": 30 + "column": 31 }, "end": { "line": 3, - "column": 31 + "column": 32 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 71, - "end": 72, + "start": 74, + "end": 75, "loc": { "start": { "line": 3, - "column": 30 + "column": 31 }, "end": { "line": 3, - "column": 31 + "column": 32 }, "identifierName": "T" }, @@ -418,8 +418,8 @@ }, { "type": "TypeAlias", - "start": 73, - "end": 107, + "start": 76, + "end": 111, "loc": { "start": { "line": 4, @@ -427,13 +427,13 @@ }, "end": { "line": 4, - "column": 34 + "column": 35 } }, "id": { "type": "Identifier", - "start": 78, - "end": 79, + "start": 81, + "end": 83, "loc": { "start": { "line": 4, @@ -441,39 +441,39 @@ }, "end": { "line": 4, - "column": 6 + "column": 7 }, - "identifierName": "A" + "identifierName": "A4" }, - "name": "A" + "name": "A4" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 79, - "end": 103, + "start": 83, + "end": 107, "loc": { "start": { "line": 4, - "column": 6 + "column": 7 }, "end": { "line": 4, - "column": 30 + "column": 31 } }, "params": [ { "type": "TypeParameter", - "start": 80, - "end": 81, + "start": 84, + "end": 85, "loc": { "start": { "line": 4, - "column": 7 + "column": 8 }, "end": { "line": 4, - "column": 8 + "column": 9 } }, "name": "S", @@ -481,60 +481,60 @@ }, { "type": "TypeParameter", - "start": 83, - "end": 102, + "start": 87, + "end": 106, "loc": { "start": { "line": 4, - "column": 10 + "column": 11 }, "end": { "line": 4, - "column": 29 + "column": 30 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 84, - "end": 93, + "start": 88, + "end": 97, "loc": { "start": { "line": 4, - "column": 11 + "column": 12 }, "end": { "line": 4, - "column": 20 + "column": 21 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 86, - "end": 93, + "start": 90, + "end": 97, "loc": { "start": { "line": 4, - "column": 13 + "column": 14 }, "end": { "line": 4, - "column": 20 + "column": 21 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 87, - "end": 93, + "start": 91, + "end": 97, "loc": { "start": { "line": 4, - "column": 14 + "column": 15 }, "end": { "line": 4, - "column": 20 + "column": 21 } } } @@ -542,16 +542,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 96, - "end": 102, + "start": 100, + "end": 106, "loc": { "start": { "line": 4, - "column": 23 + "column": 24 }, "end": { "line": 4, - "column": 29 + "column": 30 } } } @@ -560,31 +560,31 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 106, - "end": 107, + "start": 110, + "end": 111, "loc": { "start": { "line": 4, - "column": 33 + "column": 34 }, "end": { "line": 4, - "column": 34 + "column": 35 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 106, - "end": 107, + "start": 110, + "end": 111, "loc": { "start": { "line": 4, - "column": 33 + "column": 34 }, "end": { "line": 4, - "column": 34 + "column": 35 }, "identifierName": "T" }, @@ -594,8 +594,8 @@ }, { "type": "TypeAlias", - "start": 108, - "end": 151, + "start": 112, + "end": 156, "loc": { "start": { "line": 5, @@ -603,13 +603,13 @@ }, "end": { "line": 5, - "column": 43 + "column": 44 } }, "id": { "type": "Identifier", - "start": 113, - "end": 114, + "start": 117, + "end": 119, "loc": { "start": { "line": 5, @@ -617,115 +617,115 @@ }, "end": { "line": 5, - "column": 6 + "column": 7 }, - "identifierName": "A" + "identifierName": "A5" }, - "name": "A" + "name": "A5" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 114, - "end": 147, + "start": 119, + "end": 152, "loc": { "start": { "line": 5, - "column": 6 + "column": 7 }, "end": { "line": 5, - "column": 39 + "column": 40 } }, "params": [ { "type": "TypeParameter", - "start": 115, - "end": 125, + "start": 120, + "end": 130, "loc": { "start": { "line": 5, - "column": 7 + "column": 8 }, "end": { "line": 5, - "column": 17 + "column": 18 } }, "name": "S", "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 119, - "end": 125, + "start": 124, + "end": 130, "loc": { "start": { "line": 5, - "column": 11 + "column": 12 }, "end": { "line": 5, - "column": 17 + "column": 18 } } } }, { "type": "TypeParameter", - "start": 127, - "end": 146, + "start": 132, + "end": 151, "loc": { "start": { "line": 5, - "column": 19 + "column": 20 }, "end": { "line": 5, - "column": 38 + "column": 39 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 128, - "end": 137, + "start": 133, + "end": 142, "loc": { "start": { "line": 5, - "column": 20 + "column": 21 }, "end": { "line": 5, - "column": 29 + "column": 30 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 130, - "end": 137, + "start": 135, + "end": 142, "loc": { "start": { "line": 5, - "column": 22 + "column": 23 }, "end": { "line": 5, - "column": 29 + "column": 30 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 131, - "end": 137, + "start": 136, + "end": 142, "loc": { "start": { "line": 5, - "column": 23 + "column": 24 }, "end": { "line": 5, - "column": 29 + "column": 30 } } } @@ -733,16 +733,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 140, - "end": 146, + "start": 145, + "end": 151, "loc": { "start": { "line": 5, - "column": 32 + "column": 33 }, "end": { "line": 5, - "column": 38 + "column": 39 } } } @@ -751,31 +751,31 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 150, - "end": 151, + "start": 155, + "end": 156, "loc": { "start": { "line": 5, - "column": 42 + "column": 43 }, "end": { "line": 5, - "column": 43 + "column": 44 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 150, - "end": 151, + "start": 155, + "end": 156, "loc": { "start": { "line": 5, - "column": 42 + "column": 43 }, "end": { "line": 5, - "column": 43 + "column": 44 }, "identifierName": "T" }, @@ -785,8 +785,8 @@ }, { "type": "ClassDeclaration", - "start": 152, - "end": 174, + "start": 157, + "end": 180, "loc": { "start": { "line": 6, @@ -794,13 +794,13 @@ }, "end": { "line": 6, - "column": 22 + "column": 23 } }, "id": { "type": "Identifier", - "start": 158, - "end": 159, + "start": 163, + "end": 165, "loc": { "start": { "line": 6, @@ -808,55 +808,55 @@ }, "end": { "line": 6, - "column": 7 + "column": 8 }, - "identifierName": "A" + "identifierName": "A6" }, - "name": "A" + "name": "A6" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 159, - "end": 171, + "start": 165, + "end": 177, "loc": { "start": { "line": 6, - "column": 7 + "column": 8 }, "end": { "line": 6, - "column": 19 + "column": 20 } }, "params": [ { "type": "TypeParameter", - "start": 160, - "end": 170, + "start": 166, + "end": 176, "loc": { "start": { "line": 6, - "column": 8 + "column": 9 }, "end": { "line": 6, - "column": 18 + "column": 19 } }, "name": "T", "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 164, - "end": 170, + "start": 170, + "end": 176, "loc": { "start": { "line": 6, - "column": 12 + "column": 13 }, "end": { "line": 6, - "column": 18 + "column": 19 } } } @@ -866,16 +866,16 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 172, - "end": 174, + "start": 178, + "end": 180, "loc": { "start": { "line": 6, - "column": 20 + "column": 21 }, "end": { "line": 6, - "column": 22 + "column": 23 } }, "body": [] @@ -883,8 +883,8 @@ }, { "type": "ClassDeclaration", - "start": 175, - "end": 206, + "start": 181, + "end": 213, "loc": { "start": { "line": 7, @@ -892,13 +892,13 @@ }, "end": { "line": 7, - "column": 31 + "column": 32 } }, "id": { "type": "Identifier", - "start": 181, - "end": 182, + "start": 187, + "end": 189, "loc": { "start": { "line": 7, @@ -906,83 +906,83 @@ }, "end": { "line": 7, - "column": 7 + "column": 8 }, - "identifierName": "A" + "identifierName": "A7" }, - "name": "A" + "name": "A7" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 182, - "end": 203, + "start": 189, + "end": 210, "loc": { "start": { "line": 7, - "column": 7 + "column": 8 }, "end": { "line": 7, - "column": 28 + "column": 29 } }, "params": [ { "type": "TypeParameter", - "start": 183, - "end": 202, + "start": 190, + "end": 209, "loc": { "start": { "line": 7, - "column": 8 + "column": 9 }, "end": { "line": 7, - "column": 27 + "column": 28 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 184, - "end": 193, + "start": 191, + "end": 200, "loc": { "start": { "line": 7, - "column": 9 + "column": 10 }, "end": { "line": 7, - "column": 18 + "column": 19 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 186, - "end": 193, + "start": 193, + "end": 200, "loc": { "start": { "line": 7, - "column": 11 + "column": 12 }, "end": { "line": 7, - "column": 18 + "column": 19 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 187, - "end": 193, + "start": 194, + "end": 200, "loc": { "start": { "line": 7, - "column": 12 + "column": 13 }, "end": { "line": 7, - "column": 18 + "column": 19 } } } @@ -990,16 +990,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 196, - "end": 202, + "start": 203, + "end": 209, "loc": { "start": { "line": 7, - "column": 21 + "column": 22 }, "end": { "line": 7, - "column": 27 + "column": 28 } } } @@ -1009,16 +1009,16 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 204, - "end": 206, + "start": 211, + "end": 213, "loc": { "start": { "line": 7, - "column": 29 + "column": 30 }, "end": { "line": 7, - "column": 31 + "column": 32 } }, "body": [] @@ -1026,8 +1026,8 @@ }, { "type": "ClassDeclaration", - "start": 207, - "end": 241, + "start": 214, + "end": 249, "loc": { "start": { "line": 8, @@ -1035,13 +1035,13 @@ }, "end": { "line": 8, - "column": 34 + "column": 35 } }, "id": { "type": "Identifier", - "start": 213, - "end": 214, + "start": 220, + "end": 222, "loc": { "start": { "line": 8, @@ -1049,39 +1049,39 @@ }, "end": { "line": 8, - "column": 7 + "column": 8 }, - "identifierName": "A" + "identifierName": "A8" }, - "name": "A" + "name": "A8" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 214, - "end": 238, + "start": 222, + "end": 246, "loc": { "start": { "line": 8, - "column": 7 + "column": 8 }, "end": { "line": 8, - "column": 31 + "column": 32 } }, "params": [ { "type": "TypeParameter", - "start": 215, - "end": 216, + "start": 223, + "end": 224, "loc": { "start": { "line": 8, - "column": 8 + "column": 9 }, "end": { "line": 8, - "column": 9 + "column": 10 } }, "name": "S", @@ -1089,60 +1089,60 @@ }, { "type": "TypeParameter", - "start": 218, - "end": 237, + "start": 226, + "end": 245, "loc": { "start": { "line": 8, - "column": 11 + "column": 12 }, "end": { "line": 8, - "column": 30 + "column": 31 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 219, - "end": 228, + "start": 227, + "end": 236, "loc": { "start": { "line": 8, - "column": 12 + "column": 13 }, "end": { "line": 8, - "column": 21 + "column": 22 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 221, - "end": 228, + "start": 229, + "end": 236, "loc": { "start": { "line": 8, - "column": 14 + "column": 15 }, "end": { "line": 8, - "column": 21 + "column": 22 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 222, - "end": 228, + "start": 230, + "end": 236, "loc": { "start": { "line": 8, - "column": 15 + "column": 16 }, "end": { "line": 8, - "column": 21 + "column": 22 } } } @@ -1150,16 +1150,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 231, - "end": 237, + "start": 239, + "end": 245, "loc": { "start": { "line": 8, - "column": 24 + "column": 25 }, "end": { "line": 8, - "column": 30 + "column": 31 } } } @@ -1169,16 +1169,16 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 239, - "end": 241, + "start": 247, + "end": 249, "loc": { "start": { "line": 8, - "column": 32 + "column": 33 }, "end": { "line": 8, - "column": 34 + "column": 35 } }, "body": [] @@ -1186,8 +1186,8 @@ }, { "type": "ClassDeclaration", - "start": 242, - "end": 285, + "start": 250, + "end": 294, "loc": { "start": { "line": 9, @@ -1195,13 +1195,13 @@ }, "end": { "line": 9, - "column": 43 + "column": 44 } }, "id": { "type": "Identifier", - "start": 248, - "end": 249, + "start": 256, + "end": 258, "loc": { "start": { "line": 9, @@ -1209,115 +1209,115 @@ }, "end": { "line": 9, - "column": 7 + "column": 8 }, - "identifierName": "A" + "identifierName": "A9" }, - "name": "A" + "name": "A9" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 249, - "end": 282, + "start": 258, + "end": 291, "loc": { "start": { "line": 9, - "column": 7 + "column": 8 }, "end": { "line": 9, - "column": 40 + "column": 41 } }, "params": [ { "type": "TypeParameter", - "start": 250, - "end": 260, + "start": 259, + "end": 269, "loc": { "start": { "line": 9, - "column": 8 + "column": 9 }, "end": { "line": 9, - "column": 18 + "column": 19 } }, "name": "S", "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 254, - "end": 260, + "start": 263, + "end": 269, "loc": { "start": { "line": 9, - "column": 12 + "column": 13 }, "end": { "line": 9, - "column": 18 + "column": 19 } } } }, { "type": "TypeParameter", - "start": 262, - "end": 281, + "start": 271, + "end": 290, "loc": { "start": { "line": 9, - "column": 20 + "column": 21 }, "end": { "line": 9, - "column": 39 + "column": 40 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 263, - "end": 272, + "start": 272, + "end": 281, "loc": { "start": { "line": 9, - "column": 21 + "column": 22 }, "end": { "line": 9, - "column": 30 + "column": 31 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 265, - "end": 272, + "start": 274, + "end": 281, "loc": { "start": { "line": 9, - "column": 23 + "column": 24 }, "end": { "line": 9, - "column": 30 + "column": 31 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 266, - "end": 272, + "start": 275, + "end": 281, "loc": { "start": { "line": 9, - "column": 24 + "column": 25 }, "end": { "line": 9, - "column": 30 + "column": 31 } } } @@ -1325,16 +1325,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 275, - "end": 281, + "start": 284, + "end": 290, "loc": { "start": { "line": 9, - "column": 33 + "column": 34 }, "end": { "line": 9, - "column": 39 + "column": 40 } } } @@ -1344,16 +1344,16 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 283, - "end": 285, + "start": 292, + "end": 294, "loc": { "start": { "line": 9, - "column": 41 + "column": 42 }, "end": { "line": 9, - "column": 43 + "column": 44 } }, "body": [] @@ -1361,8 +1361,8 @@ }, { "type": "EmptyStatement", - "start": 286, - "end": 287, + "start": 295, + "end": 296, "loc": { "start": { "line": 10, @@ -1376,8 +1376,8 @@ }, { "type": "ExpressionStatement", - "start": 287, - "end": 313, + "start": 296, + "end": 324, "loc": { "start": { "line": 10, @@ -1390,8 +1390,8 @@ }, "expression": { "type": "ClassExpression", - "start": 288, - "end": 310, + "start": 297, + "end": 321, "loc": { "start": { "line": 10, @@ -1399,13 +1399,13 @@ }, "end": { "line": 10, - "column": 24 + "column": 26 } }, "id": { "type": "Identifier", - "start": 294, - "end": 295, + "start": 303, + "end": 306, "loc": { "start": { "line": 10, @@ -1413,55 +1413,55 @@ }, "end": { "line": 10, - "column": 9 + "column": 11 }, - "identifierName": "A" + "identifierName": "A10" }, - "name": "A" + "name": "A10" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 295, - "end": 307, + "start": 306, + "end": 318, "loc": { "start": { "line": 10, - "column": 9 + "column": 11 }, "end": { "line": 10, - "column": 21 + "column": 23 } }, "params": [ { "type": "TypeParameter", - "start": 296, - "end": 306, + "start": 307, + "end": 317, "loc": { "start": { "line": 10, - "column": 10 + "column": 12 }, "end": { "line": 10, - "column": 20 + "column": 22 } }, "name": "T", "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 300, - "end": 306, + "start": 311, + "end": 317, "loc": { "start": { "line": 10, - "column": 14 + "column": 16 }, "end": { "line": 10, - "column": 20 + "column": 22 } } } @@ -1471,30 +1471,30 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 308, - "end": 310, + "start": 319, + "end": 321, "loc": { "start": { "line": 10, - "column": 22 + "column": 24 }, "end": { "line": 10, - "column": 24 + "column": 26 } }, "body": [] }, "extra": { "parenthesized": true, - "parenStart": 287 + "parenStart": 296 } } }, { "type": "ExpressionStatement", - "start": 313, - "end": 348, + "start": 324, + "end": 361, "loc": { "start": { "line": 11, @@ -1507,8 +1507,8 @@ }, "expression": { "type": "ClassExpression", - "start": 314, - "end": 345, + "start": 325, + "end": 358, "loc": { "start": { "line": 11, @@ -1516,13 +1516,13 @@ }, "end": { "line": 11, - "column": 33 + "column": 35 } }, "id": { "type": "Identifier", - "start": 320, - "end": 321, + "start": 331, + "end": 334, "loc": { "start": { "line": 11, @@ -1530,83 +1530,83 @@ }, "end": { "line": 11, - "column": 9 + "column": 11 }, - "identifierName": "A" + "identifierName": "A11" }, - "name": "A" + "name": "A11" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 321, - "end": 342, + "start": 334, + "end": 355, "loc": { "start": { "line": 11, - "column": 9 + "column": 11 }, "end": { "line": 11, - "column": 30 + "column": 32 } }, "params": [ { "type": "TypeParameter", - "start": 322, - "end": 341, + "start": 335, + "end": 354, "loc": { "start": { "line": 11, - "column": 10 + "column": 12 }, "end": { "line": 11, - "column": 29 + "column": 31 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 323, - "end": 332, + "start": 336, + "end": 345, "loc": { "start": { "line": 11, - "column": 11 + "column": 13 }, "end": { "line": 11, - "column": 20 + "column": 22 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 325, - "end": 332, + "start": 338, + "end": 345, "loc": { "start": { "line": 11, - "column": 13 + "column": 15 }, "end": { "line": 11, - "column": 20 + "column": 22 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 326, - "end": 332, + "start": 339, + "end": 345, "loc": { "start": { "line": 11, - "column": 14 + "column": 16 }, "end": { "line": 11, - "column": 20 + "column": 22 } } } @@ -1614,16 +1614,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 335, - "end": 341, + "start": 348, + "end": 354, "loc": { "start": { "line": 11, - "column": 23 + "column": 25 }, "end": { "line": 11, - "column": 29 + "column": 31 } } } @@ -1633,30 +1633,30 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 343, - "end": 345, + "start": 356, + "end": 358, "loc": { "start": { "line": 11, - "column": 31 + "column": 33 }, "end": { "line": 11, - "column": 33 + "column": 35 } }, "body": [] }, "extra": { "parenthesized": true, - "parenStart": 313 + "parenStart": 324 } } }, { "type": "ExpressionStatement", - "start": 348, - "end": 386, + "start": 361, + "end": 401, "loc": { "start": { "line": 12, @@ -1669,8 +1669,8 @@ }, "expression": { "type": "ClassExpression", - "start": 349, - "end": 383, + "start": 362, + "end": 398, "loc": { "start": { "line": 12, @@ -1678,13 +1678,13 @@ }, "end": { "line": 12, - "column": 36 + "column": 38 } }, "id": { "type": "Identifier", - "start": 355, - "end": 356, + "start": 368, + "end": 371, "loc": { "start": { "line": 12, @@ -1692,39 +1692,39 @@ }, "end": { "line": 12, - "column": 9 + "column": 11 }, - "identifierName": "A" + "identifierName": "A12" }, - "name": "A" + "name": "A12" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 356, - "end": 380, + "start": 371, + "end": 395, "loc": { "start": { "line": 12, - "column": 9 + "column": 11 }, "end": { "line": 12, - "column": 33 + "column": 35 } }, "params": [ { "type": "TypeParameter", - "start": 357, - "end": 358, + "start": 372, + "end": 373, "loc": { "start": { "line": 12, - "column": 10 + "column": 12 }, "end": { "line": 12, - "column": 11 + "column": 13 } }, "name": "S", @@ -1732,60 +1732,60 @@ }, { "type": "TypeParameter", - "start": 360, - "end": 379, + "start": 375, + "end": 394, "loc": { "start": { "line": 12, - "column": 13 + "column": 15 }, "end": { "line": 12, - "column": 32 + "column": 34 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 361, - "end": 370, + "start": 376, + "end": 385, "loc": { "start": { "line": 12, - "column": 14 + "column": 16 }, "end": { "line": 12, - "column": 23 + "column": 25 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 363, - "end": 370, + "start": 378, + "end": 385, "loc": { "start": { "line": 12, - "column": 16 + "column": 18 }, "end": { "line": 12, - "column": 23 + "column": 25 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 364, - "end": 370, + "start": 379, + "end": 385, "loc": { "start": { "line": 12, - "column": 17 + "column": 19 }, "end": { "line": 12, - "column": 23 + "column": 25 } } } @@ -1793,16 +1793,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 373, - "end": 379, + "start": 388, + "end": 394, "loc": { "start": { "line": 12, - "column": 26 + "column": 28 }, "end": { "line": 12, - "column": 32 + "column": 34 } } } @@ -1812,30 +1812,30 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 381, - "end": 383, + "start": 396, + "end": 398, "loc": { "start": { "line": 12, - "column": 34 + "column": 36 }, "end": { "line": 12, - "column": 36 + "column": 38 } }, "body": [] }, "extra": { "parenthesized": true, - "parenStart": 348 + "parenStart": 361 } } }, { "type": "ExpressionStatement", - "start": 386, - "end": 431, + "start": 401, + "end": 448, "loc": { "start": { "line": 13, @@ -1843,13 +1843,13 @@ }, "end": { "line": 13, - "column": 46 + "column": 48 } }, "expression": { "type": "ClassExpression", - "start": 387, - "end": 430, + "start": 402, + "end": 447, "loc": { "start": { "line": 13, @@ -1857,13 +1857,13 @@ }, "end": { "line": 13, - "column": 45 + "column": 47 } }, "id": { "type": "Identifier", - "start": 393, - "end": 394, + "start": 408, + "end": 411, "loc": { "start": { "line": 13, @@ -1871,115 +1871,115 @@ }, "end": { "line": 13, - "column": 9 + "column": 11 }, - "identifierName": "A" + "identifierName": "A13" }, - "name": "A" + "name": "A13" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 394, - "end": 427, + "start": 411, + "end": 444, "loc": { "start": { "line": 13, - "column": 9 + "column": 11 }, "end": { "line": 13, - "column": 42 + "column": 44 } }, "params": [ { "type": "TypeParameter", - "start": 395, - "end": 405, + "start": 412, + "end": 422, "loc": { "start": { "line": 13, - "column": 10 + "column": 12 }, "end": { "line": 13, - "column": 20 + "column": 22 } }, "name": "S", "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 399, - "end": 405, + "start": 416, + "end": 422, "loc": { "start": { "line": 13, - "column": 14 + "column": 16 }, "end": { "line": 13, - "column": 20 + "column": 22 } } } }, { "type": "TypeParameter", - "start": 407, - "end": 426, + "start": 424, + "end": 443, "loc": { "start": { "line": 13, - "column": 22 + "column": 24 }, "end": { "line": 13, - "column": 41 + "column": 43 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 408, - "end": 417, + "start": 425, + "end": 434, "loc": { "start": { "line": 13, - "column": 23 + "column": 25 }, "end": { "line": 13, - "column": 32 + "column": 34 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 410, - "end": 417, + "start": 427, + "end": 434, "loc": { "start": { "line": 13, - "column": 25 + "column": 27 }, "end": { "line": 13, - "column": 32 + "column": 34 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 411, - "end": 417, + "start": 428, + "end": 434, "loc": { "start": { "line": 13, - "column": 26 + "column": 28 }, "end": { "line": 13, - "column": 32 + "column": 34 } } } @@ -1987,16 +1987,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 420, - "end": 426, + "start": 437, + "end": 443, "loc": { "start": { "line": 13, - "column": 35 + "column": 37 }, "end": { "line": 13, - "column": 41 + "column": 43 } } } @@ -2006,30 +2006,30 @@ "superClass": null, "body": { "type": "ClassBody", - "start": 428, - "end": 430, + "start": 445, + "end": 447, "loc": { "start": { "line": 13, - "column": 43 + "column": 45 }, "end": { "line": 13, - "column": 45 + "column": 47 } }, "body": [] }, "extra": { "parenthesized": true, - "parenStart": 386 + "parenStart": 401 } } }, { "type": "DeclareClass", - "start": 432, - "end": 462, + "start": 449, + "end": 481, "loc": { "start": { "line": 14, @@ -2037,13 +2037,13 @@ }, "end": { "line": 14, - "column": 30 + "column": 32 } }, "id": { "type": "Identifier", - "start": 446, - "end": 447, + "start": 463, + "end": 466, "loc": { "start": { "line": 14, @@ -2051,55 +2051,55 @@ }, "end": { "line": 14, - "column": 15 + "column": 17 }, - "identifierName": "A" + "identifierName": "A14" }, - "name": "A" + "name": "A14" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 447, - "end": 459, + "start": 466, + "end": 478, "loc": { "start": { "line": 14, - "column": 15 + "column": 17 }, "end": { "line": 14, - "column": 27 + "column": 29 } }, "params": [ { "type": "TypeParameter", - "start": 448, - "end": 458, + "start": 467, + "end": 477, "loc": { "start": { "line": 14, - "column": 16 + "column": 18 }, "end": { "line": 14, - "column": 26 + "column": 28 } }, "name": "T", "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 452, - "end": 458, + "start": 471, + "end": 477, "loc": { "start": { "line": 14, - "column": 20 + "column": 22 }, "end": { "line": 14, - "column": 26 + "column": 28 } } } @@ -2111,16 +2111,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 460, - "end": 462, + "start": 479, + "end": 481, "loc": { "start": { "line": 14, - "column": 28 + "column": 30 }, "end": { "line": 14, - "column": 30 + "column": 32 } }, "callProperties": [], @@ -2132,8 +2132,8 @@ }, { "type": "DeclareClass", - "start": 463, - "end": 502, + "start": 482, + "end": 523, "loc": { "start": { "line": 15, @@ -2141,13 +2141,13 @@ }, "end": { "line": 15, - "column": 39 + "column": 41 } }, "id": { "type": "Identifier", - "start": 477, - "end": 478, + "start": 496, + "end": 499, "loc": { "start": { "line": 15, @@ -2155,83 +2155,83 @@ }, "end": { "line": 15, - "column": 15 + "column": 17 }, - "identifierName": "A" + "identifierName": "A15" }, - "name": "A" + "name": "A15" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 478, - "end": 499, + "start": 499, + "end": 520, "loc": { "start": { "line": 15, - "column": 15 + "column": 17 }, "end": { "line": 15, - "column": 36 + "column": 38 } }, "params": [ { "type": "TypeParameter", - "start": 479, - "end": 498, + "start": 500, + "end": 519, "loc": { "start": { "line": 15, - "column": 16 + "column": 18 }, "end": { "line": 15, - "column": 35 + "column": 37 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 480, - "end": 489, + "start": 501, + "end": 510, "loc": { "start": { "line": 15, - "column": 17 + "column": 19 }, "end": { "line": 15, - "column": 26 + "column": 28 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 482, - "end": 489, + "start": 503, + "end": 510, "loc": { "start": { "line": 15, - "column": 19 + "column": 21 }, "end": { "line": 15, - "column": 26 + "column": 28 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 483, - "end": 489, + "start": 504, + "end": 510, "loc": { "start": { "line": 15, - "column": 20 + "column": 22 }, "end": { "line": 15, - "column": 26 + "column": 28 } } } @@ -2239,16 +2239,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 492, - "end": 498, + "start": 513, + "end": 519, "loc": { "start": { "line": 15, - "column": 29 + "column": 31 }, "end": { "line": 15, - "column": 35 + "column": 37 } } } @@ -2260,16 +2260,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 500, - "end": 502, + "start": 521, + "end": 523, "loc": { "start": { "line": 15, - "column": 37 + "column": 39 }, "end": { "line": 15, - "column": 39 + "column": 41 } }, "callProperties": [], @@ -2281,8 +2281,8 @@ }, { "type": "DeclareClass", - "start": 503, - "end": 545, + "start": 524, + "end": 568, "loc": { "start": { "line": 16, @@ -2290,13 +2290,13 @@ }, "end": { "line": 16, - "column": 42 + "column": 44 } }, "id": { "type": "Identifier", - "start": 517, - "end": 518, + "start": 538, + "end": 541, "loc": { "start": { "line": 16, @@ -2304,39 +2304,39 @@ }, "end": { "line": 16, - "column": 15 + "column": 17 }, - "identifierName": "A" + "identifierName": "A16" }, - "name": "A" + "name": "A16" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 518, - "end": 542, + "start": 541, + "end": 565, "loc": { "start": { "line": 16, - "column": 15 + "column": 17 }, "end": { "line": 16, - "column": 39 + "column": 41 } }, "params": [ { "type": "TypeParameter", - "start": 519, - "end": 520, + "start": 542, + "end": 543, "loc": { "start": { "line": 16, - "column": 16 + "column": 18 }, "end": { "line": 16, - "column": 17 + "column": 19 } }, "name": "S", @@ -2344,60 +2344,60 @@ }, { "type": "TypeParameter", - "start": 522, - "end": 541, + "start": 545, + "end": 564, "loc": { "start": { "line": 16, - "column": 19 + "column": 21 }, "end": { "line": 16, - "column": 38 + "column": 40 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 523, - "end": 532, + "start": 546, + "end": 555, "loc": { "start": { "line": 16, - "column": 20 + "column": 22 }, "end": { "line": 16, - "column": 29 + "column": 31 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 525, - "end": 532, + "start": 548, + "end": 555, "loc": { "start": { "line": 16, - "column": 22 + "column": 24 }, "end": { "line": 16, - "column": 29 + "column": 31 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 526, - "end": 532, + "start": 549, + "end": 555, "loc": { "start": { "line": 16, - "column": 23 + "column": 25 }, "end": { "line": 16, - "column": 29 + "column": 31 } } } @@ -2405,16 +2405,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 535, - "end": 541, + "start": 558, + "end": 564, "loc": { "start": { "line": 16, - "column": 32 + "column": 34 }, "end": { "line": 16, - "column": 38 + "column": 40 } } } @@ -2426,16 +2426,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 543, - "end": 545, + "start": 566, + "end": 568, "loc": { "start": { "line": 16, - "column": 40 + "column": 42 }, "end": { "line": 16, - "column": 42 + "column": 44 } }, "callProperties": [], @@ -2447,8 +2447,8 @@ }, { "type": "DeclareClass", - "start": 546, - "end": 597, + "start": 569, + "end": 622, "loc": { "start": { "line": 17, @@ -2456,13 +2456,13 @@ }, "end": { "line": 17, - "column": 51 + "column": 53 } }, "id": { "type": "Identifier", - "start": 560, - "end": 561, + "start": 583, + "end": 586, "loc": { "start": { "line": 17, @@ -2470,115 +2470,115 @@ }, "end": { "line": 17, - "column": 15 + "column": 17 }, - "identifierName": "A" + "identifierName": "A17" }, - "name": "A" + "name": "A17" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 561, - "end": 594, + "start": 586, + "end": 619, "loc": { "start": { "line": 17, - "column": 15 + "column": 17 }, "end": { "line": 17, - "column": 48 + "column": 50 } }, "params": [ { "type": "TypeParameter", - "start": 562, - "end": 572, + "start": 587, + "end": 597, "loc": { "start": { "line": 17, - "column": 16 + "column": 18 }, "end": { "line": 17, - "column": 26 + "column": 28 } }, "name": "S", "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 566, - "end": 572, + "start": 591, + "end": 597, "loc": { "start": { "line": 17, - "column": 20 + "column": 22 }, "end": { "line": 17, - "column": 26 + "column": 28 } } } }, { "type": "TypeParameter", - "start": 574, - "end": 593, + "start": 599, + "end": 618, "loc": { "start": { "line": 17, - "column": 28 + "column": 30 }, "end": { "line": 17, - "column": 47 + "column": 49 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 575, - "end": 584, + "start": 600, + "end": 609, "loc": { "start": { "line": 17, - "column": 29 + "column": 31 }, "end": { "line": 17, - "column": 38 + "column": 40 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 577, - "end": 584, + "start": 602, + "end": 609, "loc": { "start": { "line": 17, - "column": 31 + "column": 33 }, "end": { "line": 17, - "column": 38 + "column": 40 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 578, - "end": 584, + "start": 603, + "end": 609, "loc": { "start": { "line": 17, - "column": 32 + "column": 34 }, "end": { "line": 17, - "column": 38 + "column": 40 } } } @@ -2586,16 +2586,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 587, - "end": 593, + "start": 612, + "end": 618, "loc": { "start": { "line": 17, - "column": 41 + "column": 43 }, "end": { "line": 17, - "column": 47 + "column": 49 } } } @@ -2607,16 +2607,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 595, - "end": 597, + "start": 620, + "end": 622, "loc": { "start": { "line": 17, - "column": 49 + "column": 51 }, "end": { "line": 17, - "column": 51 + "column": 53 } }, "callProperties": [], @@ -2628,8 +2628,8 @@ }, { "type": "InterfaceDeclaration", - "start": 598, - "end": 624, + "start": 623, + "end": 651, "loc": { "start": { "line": 18, @@ -2637,13 +2637,13 @@ }, "end": { "line": 18, - "column": 26 + "column": 28 } }, "id": { "type": "Identifier", - "start": 608, - "end": 609, + "start": 633, + "end": 636, "loc": { "start": { "line": 18, @@ -2651,55 +2651,55 @@ }, "end": { "line": 18, - "column": 11 + "column": 13 }, - "identifierName": "A" + "identifierName": "A18" }, - "name": "A" + "name": "A18" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 609, - "end": 621, + "start": 636, + "end": 648, "loc": { "start": { "line": 18, - "column": 11 + "column": 13 }, "end": { "line": 18, - "column": 23 + "column": 25 } }, "params": [ { "type": "TypeParameter", - "start": 610, - "end": 620, + "start": 637, + "end": 647, "loc": { "start": { "line": 18, - "column": 12 + "column": 14 }, "end": { "line": 18, - "column": 22 + "column": 24 } }, "name": "T", "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 614, - "end": 620, + "start": 641, + "end": 647, "loc": { "start": { "line": 18, - "column": 16 + "column": 18 }, "end": { "line": 18, - "column": 22 + "column": 24 } } } @@ -2711,16 +2711,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 622, - "end": 624, + "start": 649, + "end": 651, "loc": { "start": { "line": 18, - "column": 24 + "column": 26 }, "end": { "line": 18, - "column": 26 + "column": 28 } }, "callProperties": [], @@ -2732,8 +2732,8 @@ }, { "type": "InterfaceDeclaration", - "start": 625, - "end": 660, + "start": 652, + "end": 689, "loc": { "start": { "line": 19, @@ -2741,13 +2741,13 @@ }, "end": { "line": 19, - "column": 35 + "column": 37 } }, "id": { "type": "Identifier", - "start": 635, - "end": 636, + "start": 662, + "end": 665, "loc": { "start": { "line": 19, @@ -2755,83 +2755,83 @@ }, "end": { "line": 19, - "column": 11 + "column": 13 }, - "identifierName": "A" + "identifierName": "A19" }, - "name": "A" + "name": "A19" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 636, - "end": 657, + "start": 665, + "end": 686, "loc": { "start": { "line": 19, - "column": 11 + "column": 13 }, "end": { "line": 19, - "column": 32 + "column": 34 } }, "params": [ { "type": "TypeParameter", - "start": 637, - "end": 656, + "start": 666, + "end": 685, "loc": { "start": { "line": 19, - "column": 12 + "column": 14 }, "end": { "line": 19, - "column": 31 + "column": 33 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 638, - "end": 647, + "start": 667, + "end": 676, "loc": { "start": { "line": 19, - "column": 13 + "column": 15 }, "end": { "line": 19, - "column": 22 + "column": 24 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 640, - "end": 647, + "start": 669, + "end": 676, "loc": { "start": { "line": 19, - "column": 15 + "column": 17 }, "end": { "line": 19, - "column": 22 + "column": 24 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 641, - "end": 647, + "start": 670, + "end": 676, "loc": { "start": { "line": 19, - "column": 16 + "column": 18 }, "end": { "line": 19, - "column": 22 + "column": 24 } } } @@ -2839,16 +2839,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 650, - "end": 656, + "start": 679, + "end": 685, "loc": { "start": { "line": 19, - "column": 25 + "column": 27 }, "end": { "line": 19, - "column": 31 + "column": 33 } } } @@ -2860,16 +2860,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 658, - "end": 660, + "start": 687, + "end": 689, "loc": { "start": { "line": 19, - "column": 33 + "column": 35 }, "end": { "line": 19, - "column": 35 + "column": 37 } }, "callProperties": [], @@ -2881,8 +2881,8 @@ }, { "type": "InterfaceDeclaration", - "start": 661, - "end": 699, + "start": 690, + "end": 730, "loc": { "start": { "line": 20, @@ -2890,13 +2890,13 @@ }, "end": { "line": 20, - "column": 38 + "column": 40 } }, "id": { "type": "Identifier", - "start": 671, - "end": 672, + "start": 700, + "end": 703, "loc": { "start": { "line": 20, @@ -2904,39 +2904,39 @@ }, "end": { "line": 20, - "column": 11 + "column": 13 }, - "identifierName": "A" + "identifierName": "A20" }, - "name": "A" + "name": "A20" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 672, - "end": 696, + "start": 703, + "end": 727, "loc": { "start": { "line": 20, - "column": 11 + "column": 13 }, "end": { "line": 20, - "column": 35 + "column": 37 } }, "params": [ { "type": "TypeParameter", - "start": 673, - "end": 674, + "start": 704, + "end": 705, "loc": { "start": { "line": 20, - "column": 12 + "column": 14 }, "end": { "line": 20, - "column": 13 + "column": 15 } }, "name": "S", @@ -2944,60 +2944,60 @@ }, { "type": "TypeParameter", - "start": 676, - "end": 695, + "start": 707, + "end": 726, "loc": { "start": { "line": 20, - "column": 15 + "column": 17 }, "end": { "line": 20, - "column": 34 + "column": 36 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 677, - "end": 686, + "start": 708, + "end": 717, "loc": { "start": { "line": 20, - "column": 16 + "column": 18 }, "end": { "line": 20, - "column": 25 + "column": 27 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 679, - "end": 686, + "start": 710, + "end": 717, "loc": { "start": { "line": 20, - "column": 18 + "column": 20 }, "end": { "line": 20, - "column": 25 + "column": 27 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 680, - "end": 686, + "start": 711, + "end": 717, "loc": { "start": { "line": 20, - "column": 19 + "column": 21 }, "end": { "line": 20, - "column": 25 + "column": 27 } } } @@ -3005,16 +3005,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 689, - "end": 695, + "start": 720, + "end": 726, "loc": { "start": { "line": 20, - "column": 28 + "column": 30 }, "end": { "line": 20, - "column": 34 + "column": 36 } } } @@ -3026,16 +3026,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 697, - "end": 699, + "start": 728, + "end": 730, "loc": { "start": { "line": 20, - "column": 36 + "column": 38 }, "end": { "line": 20, - "column": 38 + "column": 40 } }, "callProperties": [], @@ -3047,8 +3047,8 @@ }, { "type": "InterfaceDeclaration", - "start": 700, - "end": 747, + "start": 731, + "end": 780, "loc": { "start": { "line": 21, @@ -3056,13 +3056,13 @@ }, "end": { "line": 21, - "column": 47 + "column": 49 } }, "id": { "type": "Identifier", - "start": 710, - "end": 711, + "start": 741, + "end": 744, "loc": { "start": { "line": 21, @@ -3070,115 +3070,115 @@ }, "end": { "line": 21, - "column": 11 + "column": 13 }, - "identifierName": "A" + "identifierName": "A21" }, - "name": "A" + "name": "A21" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 711, - "end": 744, + "start": 744, + "end": 777, "loc": { "start": { "line": 21, - "column": 11 + "column": 13 }, "end": { "line": 21, - "column": 44 + "column": 46 } }, "params": [ { "type": "TypeParameter", - "start": 712, - "end": 722, + "start": 745, + "end": 755, "loc": { "start": { "line": 21, - "column": 12 + "column": 14 }, "end": { "line": 21, - "column": 22 + "column": 24 } }, "name": "S", "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 716, - "end": 722, + "start": 749, + "end": 755, "loc": { "start": { "line": 21, - "column": 16 + "column": 18 }, "end": { "line": 21, - "column": 22 + "column": 24 } } } }, { "type": "TypeParameter", - "start": 724, - "end": 743, + "start": 757, + "end": 776, "loc": { "start": { "line": 21, - "column": 24 + "column": 26 }, "end": { "line": 21, - "column": 43 + "column": 45 } }, "name": "T", "variance": null, "bound": { "type": "TypeAnnotation", - "start": 725, - "end": 734, + "start": 758, + "end": 767, "loc": { "start": { "line": 21, - "column": 25 + "column": 27 }, "end": { "line": 21, - "column": 34 + "column": 36 } }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 727, - "end": 734, + "start": 760, + "end": 767, "loc": { "start": { "line": 21, - "column": 27 + "column": 29 }, "end": { "line": 21, - "column": 34 + "column": 36 } }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 728, - "end": 734, + "start": 761, + "end": 767, "loc": { "start": { "line": 21, - "column": 28 + "column": 30 }, "end": { "line": 21, - "column": 34 + "column": 36 } } } @@ -3186,16 +3186,16 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 737, - "end": 743, + "start": 770, + "end": 776, "loc": { "start": { "line": 21, - "column": 37 + "column": 39 }, "end": { "line": 21, - "column": 43 + "column": 45 } } } @@ -3207,16 +3207,16 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 745, - "end": 747, + "start": 778, + "end": 780, "loc": { "start": { "line": 21, - "column": 45 + "column": 47 }, "end": { "line": 21, - "column": 47 + "column": 49 } }, "callProperties": [], @@ -3228,8 +3228,8 @@ }, { "type": "TypeAlias", - "start": 748, - "end": 768, + "start": 781, + "end": 803, "loc": { "start": { "line": 22, @@ -3237,13 +3237,13 @@ }, "end": { "line": 22, - "column": 20 + "column": 22 } }, "id": { "type": "Identifier", - "start": 753, - "end": 754, + "start": 786, + "end": 789, "loc": { "start": { "line": 22, @@ -3251,55 +3251,55 @@ }, "end": { "line": 22, - "column": 6 + "column": 8 }, - "identifierName": "A" + "identifierName": "A22" }, - "name": "A" + "name": "A22" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 754, - "end": 764, + "start": 789, + "end": 799, "loc": { "start": { "line": 22, - "column": 6 + "column": 8 }, "end": { "line": 22, - "column": 16 + "column": 18 } }, "params": [ { "type": "TypeParameter", - "start": 755, - "end": 763, + "start": 790, + "end": 798, "loc": { "start": { "line": 22, - "column": 7 + "column": 9 }, "end": { "line": 22, - "column": 15 + "column": 17 } }, "name": "T", "variance": null, "default": { "type": "VoidTypeAnnotation", - "start": 759, - "end": 763, + "start": 794, + "end": 798, "loc": { "start": { "line": 22, - "column": 11 + "column": 13 }, "end": { "line": 22, - "column": 15 + "column": 17 } } } @@ -3308,37 +3308,916 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 767, - "end": 768, + "start": 802, + "end": 803, "loc": { "start": { "line": 22, - "column": 19 + "column": 21 }, "end": { "line": 22, - "column": 20 + "column": 22 } }, "typeParameters": null, "id": { "type": "Identifier", - "start": 767, - "end": 768, + "start": 802, + "end": 803, "loc": { "start": { "line": 22, - "column": 19 + "column": 21 }, "end": { "line": 22, - "column": 20 + "column": 22 }, "identifierName": "T" }, "name": "T" } } + }, + { + "type": "FunctionDeclaration", + "start": 804, + "end": 833, + "loc": { + "start": { + "line": 23, + "column": 0 + }, + "end": { + "line": 23, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 813, + "end": 816, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 12 + }, + "identifierName": "A26" + }, + "name": "A26" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 816, + "end": 828, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 24 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 817, + "end": 827, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 23 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 821, + "end": 827, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 23 + } + } + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start": 831, + "end": 833, + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 29 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "EmptyStatement", + "start": 834, + "end": 835, + "loc": { + "start": { + "line": 24, + "column": 0 + }, + "end": { + "line": 24, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start": 835, + "end": 862, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 28 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 836, + "end": 860, + "loc": { + "start": { + "line": 24, + "column": 2 + }, + "end": { + "line": 24, + "column": 26 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 838, + "end": 858, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 24 + } + }, + "method": true, + "key": { + "type": "Identifier", + "start": 838, + "end": 841, + "loc": { + "start": { + "line": 24, + "column": 4 + }, + "end": { + "line": 24, + "column": 7 + }, + "identifierName": "A28" + }, + "name": "A28" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 856, + "end": 858, + "loc": { + "start": { + "line": 24, + "column": 22 + }, + "end": { + "line": 24, + "column": 24 + } + }, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 841, + "end": 853, + "loc": { + "start": { + "line": 24, + "column": 7 + }, + "end": { + "line": 24, + "column": 19 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 842, + "end": 852, + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 18 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 846, + "end": 852, + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 18 + } + } + } + } + ] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 835 + } + } + }, + { + "type": "ClassDeclaration", + "start": 863, + "end": 899, + "loc": { + "start": { + "line": 25, + "column": 0 + }, + "end": { + "line": 27, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 869, + "end": 872, + "loc": { + "start": { + "line": 25, + "column": 6 + }, + "end": { + "line": 25, + "column": 9 + }, + "identifierName": "A29" + }, + "name": "A29" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 873, + "end": 899, + "loc": { + "start": { + "line": 25, + "column": 10 + }, + "end": { + "line": 27, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 877, + "end": 897, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 22 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 877, + "end": 880, + "loc": { + "start": { + "line": 26, + "column": 2 + }, + "end": { + "line": 26, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 880, + "end": 892, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 17 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 881, + "end": 891, + "loc": { + "start": { + "line": 26, + "column": 6 + }, + "end": { + "line": 26, + "column": 16 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 885, + "end": 891, + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 16 + } + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 895, + "end": 897, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 22 + } + }, + "body": [], + "directives": [] + } + } + ] + } + }, + { + "type": "EmptyStatement", + "start": 900, + "end": 901, + "loc": { + "start": { + "line": 28, + "column": 0 + }, + "end": { + "line": 28, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start": 901, + "end": 940, + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 30, + "column": 3 + } + }, + "expression": { + "type": "ClassExpression", + "start": 902, + "end": 938, + "loc": { + "start": { + "line": 28, + "column": 2 + }, + "end": { + "line": 30, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 908, + "end": 911, + "loc": { + "start": { + "line": 28, + "column": 8 + }, + "end": { + "line": 28, + "column": 11 + }, + "identifierName": "A30" + }, + "name": "A30" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 912, + "end": 938, + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 30, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 916, + "end": 936, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 22 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 916, + "end": 919, + "loc": { + "start": { + "line": 29, + "column": 2 + }, + "end": { + "line": 29, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 919, + "end": 931, + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 17 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 920, + "end": 930, + "loc": { + "start": { + "line": 29, + "column": 6 + }, + "end": { + "line": 29, + "column": 16 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 924, + "end": 930, + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 16 + } + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 934, + "end": 936, + "loc": { + "start": { + "line": 29, + "column": 20 + }, + "end": { + "line": 29, + "column": 22 + } + }, + "body": [], + "directives": [] + } + } + ] + }, + "extra": { + "parenthesized": true, + "parenStart": 901 + } + } + }, + { + "type": "DeclareClass", + "start": 941, + "end": 986, + "loc": { + "start": { + "line": 31, + "column": 0 + }, + "end": { + "line": 31, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 955, + "end": 958, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 17 + }, + "identifierName": "A31" + }, + "name": "A31" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 959, + "end": 986, + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 45 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 961, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 43 + } + }, + "key": { + "type": "Identifier", + "start": 961, + "end": 964, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 23 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start": 961, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 20 + }, + "end": { + "line": 31, + "column": 43 + } + }, + "params": [], + "rest": null, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 964, + "end": 976, + "loc": { + "start": { + "line": 31, + "column": 23 + }, + "end": { + "line": 31, + "column": 35 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 965, + "end": 975, + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 31, + "column": 34 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 969, + "end": 975, + "loc": { + "start": { + "line": 31, + "column": 28 + }, + "end": { + "line": 31, + "column": 34 + } + } + } + } + ] + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 980, + "end": 984, + "loc": { + "start": { + "line": 31, + "column": 39 + }, + "end": { + "line": 31, + "column": 43 + } + } + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false + } + }, + { + "type": "ExpressionStatement", + "start": 987, + "end": 1009, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 22 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 987, + "end": 1008, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 21 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "NumericLiteral", + "start": 1005, + "end": 1008, + "loc": { + "start": { + "line": 32, + "column": 18 + }, + "end": { + "line": 32, + "column": 21 + } + }, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 987, + "end": 999, + "loc": { + "start": { + "line": 32, + "column": 0 + }, + "end": { + "line": 32, + "column": 12 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 988, + "end": 998, + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 32, + "column": 11 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 992, + "end": 998, + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 11 + } + } + } + } + ] + } + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/reserved-word-class-name-failure/options.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/reserved-word-class-name-failure/options.json index e8aeb07ed731..f45196d78df9 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/reserved-word-class-name-failure/options.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/reserved-word-class-name-failure/options.json @@ -1,4 +1,4 @@ { - "throws": "delete is a reserved word (1:14)", + "throws": "Unexpected keyword 'delete' (1:14)", "plugins": ["flow", "jsx"] } diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json index 0b9e5fd724bd..d817f6ed4713 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json @@ -492,7 +492,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } } ], diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/input.js new file mode 100644 index 000000000000..364601fa788d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/input.js @@ -0,0 +1,8 @@ +//@flow +test< + _, + _, + number, + _, + _, +>(); diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/output.json new file mode 100644 index 000000000000..e30f8a938f73 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_allowed_trailing_commas/output.json @@ -0,0 +1,283 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "expression": { + "type": "CallExpression", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "callee": { + "type": "Identifier", + "start": 8, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "test" + }, + "name": "test" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "NumberTypeAnnotation", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "GenericTypeAnnotation", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + }, + "identifierName": "_" + }, + "name": "_" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/input.js new file mode 100644 index 000000000000..7886a45bd928 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/input.js @@ -0,0 +1,2 @@ +//@flow +var x: Generic<_> = 3; diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/options.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/options.json new file mode 100644 index 000000000000..101e77f3861c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_param_instantiation_otherwise/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "`_` is only allowed as a type argument to call or new (2:16)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/input.js new file mode 100644 index 000000000000..3f9596914f16 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/input.js @@ -0,0 +1,2 @@ +//@flow +type _ = number; diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json new file mode 100644 index 000000000000..85a0456eceff --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_name/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Cannot overwrite reserved type _ (2:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/input.js new file mode 100644 index 000000000000..849ac4c23b18 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/input.js @@ -0,0 +1,2 @@ +//@flow +type Generic<_> = _; diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/options.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/options.json new file mode 100644 index 000000000000..872ad2f73408 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_illegal_type_param_name/options.json @@ -0,0 +1,5 @@ +{ + "sourceType": "module", + "plugins": ["jsx", "flow"], + "throws": "Cannot overwrite reserved type _ (2:13)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/input.js new file mode 100644 index 000000000000..b9aaa5913aa2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/input.js @@ -0,0 +1,2 @@ +//@flow +test(); diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/output.json new file mode 100644 index 000000000000..7b90b530ad65 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_anywhere_in_list/output.json @@ -0,0 +1,397 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "expression": { + "type": "CallExpression", + "start": 8, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "callee": { + "type": "Identifier", + "start": 8, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "test" + }, + "name": "test" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 47 + } + }, + "params": [ + { + "type": "NumberTypeAnnotation", + "start": 13, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "GenericTypeAnnotation", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "StringTypeAnnotation", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "GenericTypeAnnotation", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + }, + "identifierName": "_" + }, + "name": "_" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 41, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 41, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 36 + }, + "identifierName": "Foo" + }, + "name": "Foo" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 46, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 46, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + }, + "identifierName": "Bar" + }, + "name": "Bar" + } + }, + { + "type": "GenericTypeAnnotation", + "start": 51, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 51, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 46 + }, + "identifierName": "Baz" + }, + "name": "Baz" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/input.js new file mode 100644 index 000000000000..51ba34d9c1d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/input.js @@ -0,0 +1,2 @@ +//@flow +test<_>(); diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/output.json new file mode 100644 index 000000000000..6d1aceded869 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_calls/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 8, + "end": 17, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 8, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "test" + }, + "name": "test" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "_" + }, + "name": "_" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/input.js new file mode 100644 index 000000000000..27f8acf9165a --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/input.js @@ -0,0 +1,2 @@ +//@flow +instance.method()<_>(); diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/output.json new file mode 100644 index 000000000000..26c9a3ee4039 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_methods/output.json @@ -0,0 +1,218 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "expression": { + "type": "CallExpression", + "start": 8, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "callee": { + "type": "CallExpression", + "start": 8, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "callee": { + "type": "MemberExpression", + "start": 8, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "object": { + "type": "Identifier", + "start": 8, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "instance" + }, + "name": "instance" + }, + "property": { + "type": "Identifier", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "method" + }, + "name": "method" + }, + "computed": false + }, + "arguments": [] + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "_" + }, + "name": "_" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/input.js b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/input.js new file mode 100644 index 000000000000..4805c6ee75cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/input.js @@ -0,0 +1,2 @@ +//@flow +new test<_>(); diff --git a/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/output.json b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/output.json new file mode 100644 index 000000000000..6c48948afe6a --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typeapp-call/underscore_is_implicit_in_new/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "NewExpression", + "start": 8, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "callee": { + "type": "Identifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "test" + }, + "name": "test" + }, + "typeArguments": { + "type": "TypeParameterInstantiation", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + } + ] + }, + "arguments": [] + }, + "leadingComments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": "@flow", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/2/output.json b/packages/babel-parser/test/fixtures/flow/typecasts/2/output.json index 45638f476d7a..4d9f9da74bf5 100644 --- a/packages/babel-parser/test/fixtures/flow/typecasts/2/output.json +++ b/packages/babel-parser/test/fixtures/flow/typecasts/2/output.json @@ -323,7 +323,8 @@ ], "indexers": [], "internalSlots": [], - "exact": false + "exact": false, + "inexact": false } }, "extra": { diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/input.js new file mode 100644 index 000000000000..33bdb94b5828 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/input.js @@ -0,0 +1 @@ +funccall(b: string); diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/options.json new file mode 100644 index 000000000000..e4012a53ad5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls-with-one-arg/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/input.js new file mode 100644 index 000000000000..56208a86b2b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/input.js @@ -0,0 +1 @@ +funccall(a, b: string); diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/options.json new file mode 100644 index 000000000000..3f861de320eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-in-calls/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/input.js new file mode 100644 index 000000000000..767b0cba53b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/input.js @@ -0,0 +1 @@ +(A, B: T) diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/options.json new file mode 100644 index 000000000000..847e987ef0af --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fail-without-parens/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/input.js new file mode 100644 index 000000000000..499e10703f06 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/input.js @@ -0,0 +1 @@ +[a: string]; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/options.json new file mode 100644 index 000000000000..18cdf0d35e40 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-1/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/input.js new file mode 100644 index 000000000000..e71b5b600092 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/input.js @@ -0,0 +1 @@ +([a: string]); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/options.json new file mode 100644 index 000000000000..624681c0d415 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-2/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:3)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/input.js new file mode 100644 index 000000000000..21e59fd647b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/input.js @@ -0,0 +1 @@ +([a, [b: string]]); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/options.json new file mode 100644 index 000000000000..7f8da08031af --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-3/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/input.js new file mode 100644 index 000000000000..6335f1fb022d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/input.js @@ -0,0 +1 @@ +async ([a: string]); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/options.json new file mode 100644 index 000000000000..23c75013dad4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-4/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:9)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/input.js new file mode 100644 index 000000000000..5e04cb830166 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/input.js @@ -0,0 +1 @@ +async ([a, [b: string]]); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/options.json b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/options.json new file mode 100644 index 000000000000..3f861de320eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/fails-in-array-expression-5/options.json @@ -0,0 +1,3 @@ +{ + "throws": "The type cast expression is expected to be wrapped with parenthesis (1:13)" +} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/input.js b/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/input.js new file mode 100644 index 000000000000..89c03246bbc8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/input.js @@ -0,0 +1,14 @@ +([a: string]) => {}; +([a, [b: string]]) => {}; +([a: string] = []) => {}; +({ x: [a: string] }) => {}; + +async ([a: string]) => {}; +async ([a, [b: string]]) => {}; +async ([a: string] = []) => {}; +async ({ x: [a: string] }) => {}; + +let [a1: string] = c; +let [a2, [b: string]] = c; +let [a3: string] = c; +let { x: [a4: string] } = c; diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/output.json b/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/output.json new file mode 100644 index 000000000000..0dc34605bead --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/typecasts/works-in-array-pattern/output.json @@ -0,0 +1,1739 @@ +{ + "type": "File", + "start": 0, + "end": 327, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 327, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 1, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 2, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 3, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 5, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + } + } + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 21, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 21, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "start": 22, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "ArrayPattern", + "start": 26, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 27, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 28, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 30, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 + } + } + } + } + } + ] + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 47, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 47, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 48, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "ArrayPattern", + "start": 48, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 49, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 50, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 52, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 11 + } + } + } + } + } + ] + }, + "right": { + "type": "ArrayExpression", + "start": 62, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "elements": [] + } + } + ], + "body": { + "type": "BlockStatement", + "start": 69, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 73, + "end": 100, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 73, + "end": 99, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 74, + "end": 92, + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 76, + "end": 90, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 76, + "end": 77, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrayPattern", + "start": 79, + "end": 90, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 80, + "end": 89, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 16 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 81, + "end": 89, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 83, + "end": 89, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 16 + } + } + } + } + } + ] + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 97, + "end": 99, + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 102, + "end": 128, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 102, + "end": 127, + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "ArrayPattern", + "start": 109, + "end": 120, + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 110, + "end": 119, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 17 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 111, + "end": 119, + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 113, + "end": 119, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 17 + } + } + } + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 125, + "end": 127, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 129, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 129, + "end": 159, + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 30 + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "ArrayPattern", + "start": 136, + "end": 152, + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 137, + "end": 138, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "ArrayPattern", + "start": 140, + "end": 151, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 141, + "end": 150, + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 21 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 142, + "end": 150, + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 21 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 144, + "end": 150, + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 21 + } + } + } + } + } + ] + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 157, + "end": 159, + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 161, + "end": 192, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 31 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 161, + "end": 191, + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 30 + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "AssignmentPattern", + "start": 168, + "end": 184, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "left": { + "type": "ArrayPattern", + "start": 168, + "end": 179, + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 169, + "end": 178, + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 17 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 170, + "end": 178, + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 172, + "end": 178, + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 17 + } + } + } + } + } + ] + }, + "right": { + "type": "ArrayExpression", + "start": 182, + "end": 184, + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 23 + } + }, + "elements": [] + } + } + ], + "body": { + "type": "BlockStatement", + "start": 189, + "end": 191, + "loc": { + "start": { + "line": 8, + "column": 28 + }, + "end": { + "line": 8, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "ExpressionStatement", + "start": 193, + "end": 226, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 33 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 193, + "end": 225, + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 32 + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "ObjectPattern", + "start": 200, + "end": 218, + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 25 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 202, + "end": 216, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 202, + "end": 203, + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrayPattern", + "start": 205, + "end": 216, + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 206, + "end": 215, + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 22 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 207, + "end": 215, + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 209, + "end": 215, + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 22 + } + } + } + } + } + ] + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 223, + "end": 225, + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 32 + } + }, + "body": [], + "directives": [] + } + } + }, + { + "type": "VariableDeclaration", + "start": 228, + "end": 249, + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 232, + "end": 248, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "id": { + "type": "ArrayPattern", + "start": 232, + "end": 244, + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 233, + "end": 243, + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 15 + }, + "identifierName": "a1" + }, + "name": "a1", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 235, + "end": 243, + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 15 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 237, + "end": 243, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 15 + } + } + } + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 247, + "end": 248, + "loc": { + "start": { + "line": 11, + "column": 19 + }, + "end": { + "line": 11, + "column": 20 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 250, + "end": 276, + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 26 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 254, + "end": 275, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 25 + } + }, + "id": { + "type": "ArrayPattern", + "start": 254, + "end": 271, + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 21 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 255, + "end": 257, + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 7 + }, + "identifierName": "a2" + }, + "name": "a2" + }, + { + "type": "ArrayPattern", + "start": 259, + "end": 270, + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 20 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 260, + "end": 269, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 19 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 261, + "end": 269, + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 19 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 263, + "end": 269, + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 19 + } + } + } + } + } + ] + } + ] + }, + "init": { + "type": "Identifier", + "start": 274, + "end": 275, + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 25 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 277, + "end": 298, + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 281, + "end": 297, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 20 + } + }, + "id": { + "type": "ArrayPattern", + "start": 281, + "end": 293, + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 282, + "end": 292, + "loc": { + "start": { + "line": 13, + "column": 5 + }, + "end": { + "line": 13, + "column": 15 + }, + "identifierName": "a3" + }, + "name": "a3", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 284, + "end": 292, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 15 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 286, + "end": 292, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 15 + } + } + } + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 296, + "end": 297, + "loc": { + "start": { + "line": 13, + "column": 19 + }, + "end": { + "line": 13, + "column": 20 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "kind": "let" + }, + { + "type": "VariableDeclaration", + "start": 299, + "end": 327, + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 303, + "end": 326, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 27 + } + }, + "id": { + "type": "ObjectPattern", + "start": 303, + "end": 322, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 23 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 305, + "end": 320, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 21 + } + }, + "method": false, + "key": { + "type": "Identifier", + "start": 305, + "end": 306, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ArrayPattern", + "start": 308, + "end": 320, + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 21 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 309, + "end": 319, + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 20 + }, + "identifierName": "a4" + }, + "name": "a4", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 311, + "end": 319, + "loc": { + "start": { + "line": 14, + "column": 12 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 313, + "end": 319, + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 20 + } + } + } + } + } + ] + } + } + ] + }, + "init": { + "type": "Identifier", + "start": 325, + "end": 326, + "loc": { + "start": { + "line": 14, + "column": 26 + }, + "end": { + "line": 14, + "column": 27 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json b/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json index a87c9c653817..182a3a9016d8 100644 --- a/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json +++ b/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json @@ -1,4 +1,3 @@ { - "throws": - "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...? (1:22)" + "throws": "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...? (1:22)" } diff --git a/packages/babel-parser/test/fixtures/jsx/errors/attribute-arbitrary-expression/options.json b/packages/babel-parser/test/fixtures/jsx/errors/attribute-arbitrary-expression/options.json index ed93e1882a40..19a214000ffc 100644 --- a/packages/babel-parser/test/fixtures/jsx/errors/attribute-arbitrary-expression/options.json +++ b/packages/babel-parser/test/fixtures/jsx/errors/attribute-arbitrary-expression/options.json @@ -1,4 +1,3 @@ { - "throws": - "JSX value should be either an expression or a quoted JSX text (1:9)" + "throws": "JSX value should be either an expression or a quoted JSX text (1:9)" } diff --git a/packages/babel-parser/test/fixtures/jsx/errors/html-comment/input.js b/packages/babel-parser/test/fixtures/jsx/errors/html-comment/input.js new file mode 100644 index 000000000000..5190fb0e1d65 --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/html-comment/input.js @@ -0,0 +1 @@ +