diff --git a/.eslintignore b/.eslintignore index 5ea6066c60..02e6e29eb7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,6 +6,7 @@ packages/*/node_modules packages/*/lib packages/*/dist packages/*/test/fixtures +packages/*/test/tmp vendor _babel.github.io Gulpfile.js diff --git a/.eslintrc b/.eslintrc index 00dd6a98ad..b081e2ce24 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,11 @@ { "extends": "babel", "rules": { - "max-len": 0 + "comma-dangle": ["error", "always-multiline"], + "curly": ["error", "multi-line"], + "func-call-spacing": "error", + "key-spacing": "error", + "no-multi-spaces": "error" }, "env": { "node": true, diff --git a/.gitignore b/.gitignore index 7e25e4ad05..12a252a120 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ node_modules test/tmp *.log *.cache +/.eslintcache /templates.json /tests.json /browser.js @@ -13,7 +14,9 @@ dist /.package.json /packages/babel-runtime/core-js /packages/babel-runtime/helpers/*.js +/packages/babel-register/test/.babel /packages/*/lib _babel.github.io /tests/.browser-build.js .nyc_output +/babel.sublime-workspace diff --git a/.mention-bot b/.mention-bot new file mode 100644 index 0000000000..671103a31c --- /dev/null +++ b/.mention-bot @@ -0,0 +1,12 @@ +{ + "userBlacklist": [ + "amasad", + "greenkeeperio-bot", + "jmm", + "kittens", + "thejameskyle" + ], + "fileBlacklist": ["*.md"], + "skipAlreadyAssignedPR": true, + "createReviewRequest": true +} diff --git a/.travis.yml b/.travis.yml index edc8e157cb..7a74acbc31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,30 +3,34 @@ git: sudo: false language: node_js cache: + yarn: true directories: - node_modules node_js: -- '6' -- '5' -- '4' -- '0.12' -script: - - 'if [ -n "${LINT-}" ]; then make lint ; fi' - - 'if [ -z "${LINT-}" ]; then make test-ci ; fi' - - 'if [ -n "${FLOW-}" ]; then make flow ; fi' + - '7' + - '6' + - '4' + +env: + - JOB=test + +script: + - 'if [ "$JOB" = "test" ]; then make test-ci; fi' + - 'if [ "$JOB" = "test-coverage" ]; then make test-ci-coverage; fi' + - 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi' matrix: fast_finish: true include: + - node_js: "7" + env: JOB=test-coverage - node_js: "node" - env: - - LINT: true - - FLOW: true - + env: JOB=lint + notifications: - on_success: change - on_failure: always slack: + on_success: change + on_failure: always rooms: # Generate with # travis encrypt "babeljs:#activity" --add notifications.slack.rooms diff --git a/CHANGELOG.md b/CHANGELOG.md index e9c0c57728..96d28278e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,298 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog. +## 6.23.0 (2017-02-13) + +#### :rocket: New Feature +* `babel-plugin-transform-react-constant-elements` + * [#4812](https://github.com/babel/babel/pull/4812) feature: Support pure expressions in transform-react-constant-elements. ([@STRML](https://github.com/STRML)) +* `babel-preset-flow`, `babel-preset-react` + * [#5288](https://github.com/babel/babel/pull/5288) Add new flow preset. ([@thejameskyle](https://github.com/thejameskyle)) +* `babel-traverse` + * [#5230](https://github.com/babel/babel/pull/5230) Add path/family sibling traversal methods. ([@chitchu](https://github.com/chitchu)) +* `babel-plugin-transform-es2015-block-scoping` + * [#5236](https://github.com/babel/babel/pull/5236) Add option to block-scoping to throw on slow code. ([@spicyj](https://github.com/spicyj)) + +#### :bug: Bug Fix +* `babel-core`, `babel-traverse` + * [#5050](https://github.com/babel/babel/pull/5050) Rewrite Hub as interface #5047. ([@yongxu](https://github.com/yongxu)) +* `babel-plugin-transform-es2015-for-of` + * [#5298](https://github.com/babel/babel/pull/5298) Fix loose for-of with label. ([@jridgewell](https://github.com/jridgewell)) +* `babel-plugin-transform-react-constant-elements`, `babel-traverse` + * [#5153](https://github.com/babel/babel/pull/5153) Fix react constant elements bindings. ([@STRML](https://github.com/STRML)) + * [#5143](https://github.com/babel/babel/pull/5143) Fix PathHoister hoisting JSX member expressions on "this".. ([@STRML](https://github.com/STRML)) +* `babel-plugin-transform-do-expressions`, `babel-traverse` + * [#5030](https://github.com/babel/babel/pull/5030) Prevent multiple return statements in a loop when replacing expressions. ([@existentialism](https://github.com/existentialism)) +* `babel-register` + * [#5260](https://github.com/babel/babel/pull/5260) Fix TypeError with babel-register's cache. ([@xtuc](https://github.com/xtuc)) +* `babel-traverse` + * [#5206](https://github.com/babel/babel/pull/5206) Deopt evaluation of undefined with a local binding. Closes [#5204](https://github.com/babel/babel/issues/5204). ([@boopathi](https://github.com/boopathi)) +* `babel-plugin-transform-runtime` + * [#5195](https://github.com/babel/babel/pull/5195) Don't transpile ES7 symbol properties. ([@taion](https://github.com/taion)) +* `babel` + * [#5258](https://github.com/babel/babel/pull/5258) checks if babel is installed globally and displays correct cli message. ([@xtina-starr](https://github.com/xtina-starr)) +* `babel-generator` + * [#5270](https://github.com/babel/babel/pull/5270) Emit parens for await of ternary expressions. ([@erikdesjardins](https://github.com/erikdesjardins)) + * [#5193](https://github.com/babel/babel/pull/5193) Fix missing parens when function expressions is tag. ([@existentialism](https://github.com/existentialism)) +* `babel-plugin-transform-es2015-modules-commonjs` + * [#5235](https://github.com/babel/babel/pull/5235) Limit export node default assignment stack size #4323. ([@mattste](https://github.com/mattste)) + +#### :memo: Documentation +* `babel-*` + * [#5244](https://github.com/babel/babel/pull/5244) Normalize options sections in docs [skip ci]. ([@existentialism](https://github.com/existentialism)) + * [#5216](https://github.com/babel/babel/pull/5216) Remove link to REPL. ([@xtuc](https://github.com/xtuc)) +* Other + * [#5242](https://github.com/babel/babel/pull/5242) Add our business model [skip ci]. ([@hzoo](https://github.com/hzoo)) +* `babel-plugin-transform-es2015-spread` + * [#5227](https://github.com/babel/babel/pull/5227) Add example to spread README [skip ci]. ([@finkef](https://github.com/finkef)) +* `babel-plugin-transform-flow-strip-types` + * [#5212](https://github.com/babel/babel/pull/5212) Remove REPL link transform-flow-strip-types doc. ([@xtuc](https://github.com/xtuc)) +* `babel-plugin-transform-regenerator` + * [#5202](https://github.com/babel/babel/pull/5202) Fix transform-regenerator README. ([@xtuc](https://github.com/xtuc)) +* `babel-plugin-transform-es2015-arrow-functions` + * [#5200](https://github.com/babel/babel/pull/5200) Fix transform-es2015-arrow-functions code blocks on the website. ([@xtuc](https://github.com/xtuc)) + * [#5194](https://github.com/babel/babel/pull/5194) Fix transform-es2015-arrow-functions README. ([@xtuc](https://github.com/xtuc)) + +#### :house: Internal +* `babel-core` + * [#5302](https://github.com/babel/babel/pull/5302) Add charset so tests work with convert-source-map@>1.4. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-core`, `babel-traverse` + * [#5050](https://github.com/babel/babel/pull/5050) Rewrite Hub as interface #5047. ([@yongxu](https://github.com/yongxu)) +* `babel-generator` + * [#5255](https://github.com/babel/babel/pull/5255) codegen performance: use trim instead of lodash/trimEnd. ([@jwbay](https://github.com/jwbay)) +* `babel-types` + * [#5181](https://github.com/babel/babel/pull/5181) Remove uses of lodash/compact. ([@zertosh](https://github.com/zertosh)) +* `babel-*` + * [#5265](https://github.com/babel/babel/pull/5265) Re-enable the max-len ESLint rule.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* Other + * [#5264](https://github.com/babel/babel/pull/5264) Add a sublime project file. ([@loganfsmyth](https://github.com/loganfsmyth)) + * [#5182](https://github.com/babel/babel/pull/5182) Run coverage only once. ([@existentialism](https://github.com/existentialism)) + * [#5165](https://github.com/babel/babel/pull/5165) Add Node 7 to CI. ([@chicoxyzzy](https://github.com/chicoxyzzy)) + +#### Committers: 20 +- Andres Suarez ([zertosh](https://github.com/zertosh)) +- Ben Alpert ([spicyj](https://github.com/spicyj)) +- Boopathi Rajaa ([boopathi](https://github.com/boopathi)) +- Brian Ng ([existentialism](https://github.com/existentialism)) +- Christina ([xtina-starr](https://github.com/xtina-starr)) +- Erik Desjardins ([erikdesjardins](https://github.com/erikdesjardins)) +- Fabian Finke ([finkef](https://github.com/finkef)) +- Henry Zhu ([hzoo](https://github.com/hzoo)) +- Jimmy Jia ([taion](https://github.com/taion)) +- Justin Ridgewell ([jridgewell](https://github.com/jridgewell)) +- Logan Smyth ([loganfsmyth](https://github.com/loganfsmyth)) +- Matt Stewart ([mattste](https://github.com/mattste)) +- Samuel Reed ([STRML](https://github.com/STRML)) +- Sergey Rubanov ([chicoxyzzy](https://github.com/chicoxyzzy)) +- Sven SAULEAU ([xtuc](https://github.com/xtuc)) +- Vicente Jr Yuchitcho ([chitchu](https://github.com/chitchu)) +- Yongxu Ren ([yongxu](https://github.com/yongxu)) +- [jwbay](https://github.com/jwbay) +- james kyle ([thejameskyle](https://github.com/thejameskyle)) +- Łukasz Lityński ([hex13](https://github.com/hex13)) + +## 6.22.2 (2017-01-19) + +#### :bug: Bug Fix + +* `babel-cli` + * Fix issue with `babel-node` throwing errors when passed non-"-" args [#5162](https://github.com/babel/babel/pull/5162). + +## 6.22.1 (2017-01-19) + +#### :bug: Bug Fix + +* `babel-traverse` + * Temporary fix with `babel-traverse` via [#5019](https://github.com/babel/babel/pull/5019) for transform-react-constant-elements. + +## 6.22.0 (2017-01-19) + +A quick update since it's been over a month already: adds support for shorthand import syntax in Flow + some fixes! + +We'll be merging in our current 7.0 PRs on a 7.0 branch soon and I'l be making some more issues (most should be beginner-friendly). + +To follow our progress check out our [7.0 milestone](https://github.com/babel/babel/milestone/9), the [wiki](https://github.com/babel/babel/wiki/Babel-7) and upcoming announcements on [twitter](https://twitter.com/babeljs)! + +We support stripping out and generating the new shorthand import syntax in Flow (parser support was added in [babylon@6.15.0](https://github.com/babel/babylon/releases/tag/v6.15.0). + +```js +import { + someValue, + type someType, + typeof someOtherValue, +} from "blah"; +``` + +#### :rocket: New Feature +* `babel-generator`, `babel-types` + * [#5110](https://github.com/babel/babel/pull/5110) Validate importKind and ensure code generation exists.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-plugin-transform-flow-strip-types`, `babel-traverse` + * [#5035](https://github.com/babel/babel/pull/5035) Strip Flow's new shorthand import-type specifiers. ([@jeffmo](https://github.com/jeffmo)) +* `babel-core` + * [#4729](https://github.com/babel/babel/pull/4729) Add resolvePlugin and resolvePreset methods to babel-core API. ([@rmacklin](https://github.com/rmacklin)) + +#### :bug: Bug Fix +* `babel-plugin-transform-object-rest-spread` + * [#5151](https://github.com/babel/babel/pull/5151) Avoid duplicating impure expressions in object rest destructuring. ([@erikdesjardins](https://github.com/erikdesjardins)) + +```js +const { x, ...y } = foo(); +``` + +Old Behavior + +```js +const { x } = foo(); +const y = _objectWithoutProperties(foo(), ["x"]); +``` + +New/Expected Behavior + +```js +const _ref = foo(); // should only be called once +const { x } = _ref; +const y = _objectWithoutProperties(_ref, ["x"]); +``` + +* `babel-cli` + * [#4790](https://github.com/babel/babel/pull/4790) fixes invalid line offsets in merged sourcemaps. ([@peterm0x](https://github.com/peterm0x)) +* `babel-plugin-transform-object-rest-spread` + * [#5088](https://github.com/babel/babel/pull/5088) fix: plugin-transform-object-rest-spread param with default value. ([@christophehurpeau](https://github.com/christophehurpeau)) + +Accounts for default values in object rest params + +```js +function fn({a = 1, ...b} = {}) { + return {a, b}; +} +``` + +* `babel-plugin-transform-es2015-destructuring` + * [#5093](https://github.com/babel/babel/pull/5093) Ensure array is always copied during destructure. ([@existentialism](https://github.com/existentialism)) + +```js +const assign = ([...arr], index, value) => { + arr[index] = value + return arr +} + +const arr = [1, 2, 3] +assign(arr, 1, 42) +console.log(arr) // [1, 2, 3] +``` + +* `babel-plugin-transform-es2015-function-name` + * [#5008](https://github.com/babel/babel/pull/5008) Don't try to visit ArrowFunctionExpression, they cannot be named. ([@Kovensky](https://github.com/Kovensky)) + +Input + +```js +export const x = ({ x }) => x; +export const y = function () {}; +``` + +Output + +```js +export const x = ({ x }) => x; +export const y = function y() {}; +``` + +* `babel-types` + * [#5068](https://github.com/babel/babel/pull/5068) Fix getBindingIdentifiers in babel-types. ([@rtsao](https://github.com/rtsao)) +* `babel-cli` + * [#3698](https://github.com/babel/babel/pull/3698) Watch mode should wait for file write. (T7411) ([@hayeah](https://github.com/hayeah)) + +#### :nail_care: Polish +* `babel-traverse` + * [#5076](https://github.com/babel/babel/pull/5076) Optimize removal-hooks for ArrowFunctions. ([@danez](https://github.com/danez)) +* `babel-generator`, `babel-plugin-transform-exponentiation-operator` + * [#5026](https://github.com/babel/babel/pull/5026) Remove unnecessary spaces around template element. ([@chicoxyzzy](https://github.com/chicoxyzzy)) + +#### :memo: Documentation +* Other + * [#5144](https://github.com/babel/babel/pull/5144) Fix dependency status extension.. ([@yavorsky](https://github.com/yavorsky)) + * [#5136](https://github.com/babel/babel/pull/5136) Add babel-preset-env to maintained list.. ([@yavorsky](https://github.com/yavorsky)) +* `babel-core` + * [#5101](https://github.com/babel/babel/pull/5101) Document babelrc option. ([@novemberborn](https://github.com/novemberborn)) + * [#5114](https://github.com/babel/babel/pull/5114) Update babel-core options in README. ([@existentialism](https://github.com/existentialism)) +* `babel-plugin-syntax-class-constructor-call` + * [#5130](https://github.com/babel/babel/pull/5130) update syntax-class-constructor-call documentation. ([@xtuc](https://github.com/xtuc)) +* `babel-plugin-transform-es2015-duplicate-keys`, `babel-plugin-transform-es2015-parameters` + * [#5111](https://github.com/babel/babel/pull/5111) Fixes some inconsistent documentation. ([@xtuc](https://github.com/xtuc)) +* `babel-plugin-transform-es2015-computed-properties`, `babel-plugin-transform-es2015-for-of` + * [#5096](https://github.com/babel/babel/pull/5096) Add examples to computed-props and for-of READMEs [skip ci]. ([@existentialism](https://github.com/existentialism)) +* `babel-plugin-transform-class-properties` + * [#5077](https://github.com/babel/babel/pull/5077) Static function call result comment does not match variable content [skip ci]. ([@kasn](https://github.com/kasn)) +* Other + * [#5070](https://github.com/babel/babel/pull/5070) Fix typo in README.md. ([@nomicos](https://github.com/nomicos)) + * [#5031](https://github.com/babel/babel/pull/5031) remove plugin links, just use the website [skip ci]. ([@hzoo](https://github.com/hzoo)) + * [#5011](https://github.com/babel/babel/pull/5011) Add Team section [skip ci]. ([@hzoo](https://github.com/hzoo)) +* `babel-plugin-transform-es2015-classes`, `babel-plugin-transform-function-bind` + * [#5061](https://github.com/babel/babel/pull/5061) Fix some doc lint issues. ([@existentialism](https://github.com/existentialism)) +* `babel-helpers` + * [#5059](https://github.com/babel/babel/pull/5059) Fix incorrect snippet language in babel-helpers. ([@xtuc](https://github.com/xtuc)) +* `babel-preset-react` + * [#5051](https://github.com/babel/babel/pull/5051) Adding more info to the Install section. ([@gitanupam](https://github.com/gitanupam)) +* `babel-plugin-check-es2015-constants`, `babel-plugin-transform-es2015-modules-umd`, `babel-plugin-transform-es2015-typeof-symbol`, `babel-register` + * [#5045](https://github.com/babel/babel/pull/5045) Fix some README links. ([@existentialism](https://github.com/existentialism)) +* `babel-core` + * [#5014](https://github.com/babel/babel/pull/5014) Update babel-core's README. ([@xtuc](https://github.com/xtuc)) + +#### :house: Internal +* `babel-*` + * [#5129](https://github.com/babel/babel/pull/5129) Bump eslint-config-babel and fix lint. ([@existentialism](https://github.com/existentialism)) + * [#5138](https://github.com/babel/babel/pull/5138) Refactor packages to use ES modules instead of CJS. ([@chicoxyzzy](https://github.com/chicoxyzzy)) + * [#5113](https://github.com/babel/babel/pull/5113) Kaicataldo enable prefer const. ([@hzoo](https://github.com/hzoo)) +* `babel-helper-transform-fixture-test-runner` + * [#5135](https://github.com/babel/babel/pull/5135) Run Babel's unittests in a custom sandbox.. ([@loganfsmyth](https://github.com/loganfsmyth)) +* `babel-cli`, `babel-core`, `babel-generator`, `babel-helper-define-map`, `babel-register`, `babel-runtime`, `babel-types` + * [#5043](https://github.com/babel/babel/pull/5043) Replace "lodash/is*" and "lodash/each" with native equivalents. ([@zertosh](https://github.com/zertosh)) +* `babel-cli`, `babel-generator`, `babel-helper-fixtures`, `babel-helper-transform-fixture-test-runner`, `babel-preset-es2015`, `babel-runtime`, `babel-traverse` + * [#5042](https://github.com/babel/babel/pull/5042) Use native or lodash util module where full "lodash" is required. ([@zertosh](https://github.com/zertosh)) +* `babel-code-frame` + * [#5094](https://github.com/babel/babel/pull/5094) babel-code-frame: Upgrade to js-tokens@3. ([@lydell](https://github.com/lydell)) +* `babel-plugin-transform-react-jsx` + * [#5100](https://github.com/babel/babel/pull/5100) Fix broken repository url. ([@batista](https://github.com/batista)) +* `babel-plugin-transform-decorators` + * [#5038](https://github.com/babel/babel/pull/5038) Remove unused dependency. ([@zertosh](https://github.com/zertosh)) +* `babel-plugin-transform-es2015-computed-properties` + * [#5053](https://github.com/babel/babel/pull/5053) Remove unused define-map helper from computed-properties. ([@existentialism](https://github.com/existentialism)) +* `babel-cli` + * [#5027](https://github.com/babel/babel/pull/5027) Dependencies: Upgrade glob to v7. ([@ysangkok](https://github.com/ysangkok)) + +#### Committers: 23, First PRs: 10 +- Andres Suarez ([zertosh](https://github.com/zertosh)) +- Andrii Bida ([nomicos](https://github.com/nomicos)) First PR! +- Anthony Zotti ([amZotti](https://github.com/amZotti)) First PR! +- Anupam ([gitanupam](https://github.com/gitanupam)) First PR! +- Artem Yavorsky ([yavorsky](https://github.com/yavorsky)) First PR! +- Brian Ng ([existentialism](https://github.com/existentialism)) +- Christophe Hurpeau ([christophehurpeau](https://github.com/christophehurpeau)) +- Daniel Tschinder ([danez](https://github.com/danez)) +- Diogo Franco ([Kovensky](https://github.com/Kovensky)) +- Erik Desjardins ([erikdesjardins](https://github.com/erikdesjardins)) +- Henry Zhu ([hzoo](https://github.com/hzoo)) +- Howard Yeh ([hayeah](https://github.com/hayeah)) First PR! +- Janus Troelsen ([ysangkok](https://github.com/ysangkok)) First PR! +- Jeff Morrison ([jeffmo](https://github.com/jeffmo)) +- Karsten Gohm ([kasn](https://github.com/kasn)) First PR! +- Logan Smyth ([loganfsmyth](https://github.com/loganfsmyth)) +- Mark Wubben ([novemberborn](https://github.com/novemberborn)) First PR! +- Peter Mikula ([peterm0x](https://github.com/peterm0x)) +- Ryan Tsao ([rtsao](https://github.com/rtsao)) First PR! +- Sergey Rubanov ([chicoxyzzy](https://github.com/chicoxyzzy)) +- Simon Lydell ([lydell](https://github.com/lydell)) +- Sven SAULEAU ([xtuc](https://github.com/xtuc)) +- Sérgio Batista ([batista](https://github.com/batista)) First PR! +- [rmacklin](https://github.com/rmacklin) + +## 6.21.1 (2016-12-17) + +#### :bug: Bug Fix +* `babel-helper-builder-react-jsx`, `babel-plugin-transform-react-jsx` + * [#5015](https://github.com/babel/babel/pull/5015) Revert the introduction of a new error message that ended up introducing its own error ([@loganfsmyth](https://github.com/loganfsmyth)) + ## 6.21.0 (2016-12-16) #### :rocket: New Feature diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 80c27d86d3..fa6650e420 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,13 +2,15 @@ ---- -

+

Setup | Running linting/tests | Writing tests | + Debugging code + | Internals

@@ -25,7 +27,7 @@ Contributions are always welcome, no matter how large or small. - If you aren't just making a documentation change, you'll probably want to learn a bit about a few topics. - [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babylon/blob/master/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babylon#output). - - This repository's [`/doc`](/doc) directory for notes on Babel's internals + - This repository's [`/doc`](https://github.com/babel/babel/tree/master/doc) directory for notes on Babel's internals - Check out [the Babel Plugin Handbook](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-plugin-handbook) - core plugins are written the same way as any other plugin! - Check out [AST Explorer](http://astexplorer.net/#/scUfOmVOG5) to learn more about ASTs or make your own plugin in the browser - When you feel ready to finally jump into the babel source code a good start is to look out for issues which are labeled with [help-wanted](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and/or [beginner-friendly](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22beginner-friendly%22). @@ -38,11 +40,14 @@ Feel free to check out the `#discussion`/`#development` channels on our [slack]( **Note:** Versions `< 5.1.10` can't be built. -Babel is built for node 0.10 and up but we develop using node 6. Make sure you are on npm 3. +Babel is built for node 4 and up but we develop using node 6. Make sure you are on npm 3. You can check this with `node -v` and `npm -v`. -#### Setup +In addition, make sure that Yarn is installed. +Installation instructions can be found here: https://yarnpkg.com/en/docs/install. + +### Setup ```sh $ git clone https://github.com/babel/babel @@ -72,7 +77,7 @@ If you wish to build a copy of Babel for distribution, then run: $ make build-dist ``` -#### Running linting/tests +### Running linting/tests You can run lint via: @@ -103,7 +108,7 @@ $ make test-only Most likely you'll want to focus in on a specific issue. -To run tests for a specific package in [packages](/packages), you can use the `TEST_ONLY` environment variable: +To run tests for a specific package in [packages](https://github.com/babel/babel/tree/master/packages), you can use the `TEST_ONLY` environment variable: ```sh $ TEST_ONLY=babel-cli make test @@ -124,30 +129,31 @@ $ TEST_DEBUG=true make test To test the code coverage, use: ```sh -$ make test-cov +$ BABEL_ENV=cov make build +$ ./scripts/test-cov.sh ``` -#### Writing tests +### Writing tests -Most packages in [`/packages`](/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](/packages/babel-core/test/fixtures). +Most packages in [`/packages`](https://github.com/babel/babel/tree/master/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](https://github.com/babel/babel/tree/master/packages/babel-core/test/fixtures). -##### `babel-plugin-x` +#### `babel-plugin-x` All the Babel plugins (and other packages) that have a `/test/fixtures` are written in a similar way. -For example, in [`babel-plugin-transform-exponentiation-operator/test`](/packages/babel-plugin-transform-exponentiation-operator/test): +For example, in [`babel-plugin-transform-exponentiation-operator/test`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test): -- There is an `index.js` file. It imports our [test helper](/packages/babel-helper-plugin-test-runner). (You don't have to worry about this). -- There can be multiple folders under [`/fixtures`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures) - - There is an [`options.json`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests. +- There is an `index.js` file. It imports our [test helper](https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner). (You don't have to worry about this). +- There can be multiple folders under [`/fixtures`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures) + - There is an [`options.json`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests. - For this test, we only need the relevant plugin, so it's just `{ "plugins": ["transform-exponentiation-operator"] }`. - If necessary, you can have an `options.json` with different options in each subfolder. - In each subfolder, you can organize your directory structure by categories of tests. (Example: these folders can be named after the feature you are testing or can reference the issue number they fix) - Generally, there are two kinds of tests for plugins - - The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file. + - The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file. - If you need to expect an error, you can ignore creating the `expected.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created. - - The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file. + - The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file. In an actual/expected test, you simply write out the code you want transformed in `actual.js`. @@ -180,7 +186,7 @@ If you need to check for an error that is thrown you can add to the `options.jso } ``` -##### Bootstrapping expected output +#### Bootstrapping expected output For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js`/`expected.json` automatically by just providing `actual.js` and running the tests as you usually would. @@ -196,9 +202,46 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js - expected.json (will be generated if not created) ``` -#### Internals +### Debugging code + +A common approach to debugging JavaScript code is to walk through the code using the [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/) debugger. +For illustration purposes, we are going to assume that we need to get a better understanding of [`Generator.generate()`](https://github.com/babel/babel/blob/b5246994b57f06af871be6a63dcc4c6fd41d94d6/packages/babel-generator/src/index.js#L32), which is responsible for generating code for a given AST. +To get a better understanding of what is actually going on for this particular piece of code, we are going to make use of breakpoints. + +```diff +generate() { ++ debugger; // breakpoint + return super.generate(this.ast); +} +``` + +To include the changes, we have to make sure to build Babel: + +```bash +$ make build +``` + +Next, we need to execute `Generator.generate()`, which can be achieved by running a test case in the `babel-generator` package. +For example, we can run the test case that tests the generation of class declarations: + +```bash +$ TEST_DEBUG=true TEST_GREP=ClassDeclaration make test-only + +./scripts/test.sh +Debugger listening on port 9229. +Warning: This is an experimental feature and could change at any time. +To start debugging, open the following URL in Chrome: + chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/3cdaebd2-be88-4e7b-a94b-432950ab72d0 +``` + +To start the debugging in Chrome DevTools, open the given URL. +The debugger starts at the first executed line of code, which is Mocha's first line by default. +Click _Resume script execution_ Resume script execution button. to jump to the set breakpoint. +Note that the code shown in Chrome DevTools is compiled code and therefore differs. + +## Internals - AST spec ([babylon/ast/spec.md](https://github.com/babel/babylon/blob/master/ast/spec.md)) -- Versionning ([doc/design/versioning.md](./doc/design/versioning.md)) -- Monorepo ([doc/design/monorepo.md](./doc/design/monorepo.md)) -- Compiler environment support ([doc/design/compiler-environment-support.md](./doc/design/compiler-environment-support.md)) -- Compiler assumptions ([doc/design/compiler-assumptions.md](./doc/design/compiler-assumptions.md)) +- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.md) +- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/master/doc/design/monorepo.md)) +- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/master/doc/design/compiler-environment-support.md)) +- Compiler assumptions ([doc/design/compiler-assumptions.md](https://github.com/babel/babel/blob/master/doc/design/compiler-assumptions.md)) diff --git a/LICENSE b/LICENSE index 6a5e2b14bd..d6b2e00435 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2016 Sebastian McKenzie +Copyright (c) 2014-2017 Sebastian McKenzie 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 561846cef5..3f68e4cb04 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MAKEFLAGS = -j1 export NODE_ENV = test -.PHONY: build build-dist watch lint fix clean test-clean test-only test test-cov test-ci publish bootstrap +.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap build: clean ./node_modules/.bin/gulp build @@ -16,7 +16,7 @@ build-dist: build watch: clean rm -rf packages/*/lib - BABEL_ENV=development ./node_modules/.bin/gulp watch + ./node_modules/.bin/gulp watch lint: ./node_modules/.bin/eslint packages/ --format=codeframe @@ -42,22 +42,19 @@ clean-all: rm -rf packages/*/node_modules make clean -# without lint test-only: ./scripts/test.sh make test-clean test: lint test-only -test-cov: clean - # rebuild with test - rm -rf packages/*/lib - BABEL_ENV=test ./node_modules/.bin/gulp build - ./scripts/test-cov.sh - test-ci: - NODE_ENV=test make bootstrap - make test-cov + make bootstrap + make test-only + +test-ci-coverage: + BABEL_ENV=cov make bootstrap + ./scripts/test-cov.sh ./node_modules/.bin/codecov -f coverage/coverage-final.json publish: @@ -66,15 +63,14 @@ publish: BABEL_ENV=production make build-dist make test # not using lerna independent mode atm, so only update packages that have changed since we use ^ - ./node_modules/.bin/lerna publish --only-explicit-updates + # --only-explicit-updates + ./node_modules/.bin/lerna publish --npm-tag=next --exact --skip-temp-tag make clean - #./scripts/build-website.sh bootstrap: make clean-all - npm install + yarn ./node_modules/.bin/lerna bootstrap make build cd packages/babel-runtime; \ - npm install; \ node scripts/build-dist.js diff --git a/README.md b/README.md index 04057583fe..367565bba1 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,12 @@

- Travis Status - CircleCI Status - Coverage Status + Business Strategy Status + Travis Status + CircleCI Status + Coverage Status Slack Status - NPM Downloads + NPM Downloads

Babel is a community-driven tool that helps you write the latest version of JavaScript. @@ -24,13 +25,13 @@ When your supported environments don't support certain features natively, it wil ```js // ES2015 arrow function -[1,2,3].map(n => n + 1); +[1, 2, 3].map((n) => n + 1); ``` **Out** ```js -[1,2,3].map(function(n) { +[1, 2, 3].map(function(n) { return n + 1; }); ``` @@ -46,6 +47,7 @@ Try it out at our [REPL](https://babeljs.io/repl/#?babili=false&evaluate=true&li - [Transform Plugins](#transform-plugins) - [Syntax Plugins](#syntax-plugins) - [Misc Packages](#misc-packages) +- [Team](#team) - [License](#license) # FAQ @@ -70,7 +72,7 @@ https://phabricator.babeljs.io/T2168 mostly corresponds to https://github.com/ba ## Want to report an issue with [babeljs.io](https://babeljs.io) (the website)? -For documentation and website issues please visit the [babel/babel.github.io](https://github.com/babel/babel.github.io)repo. +For documentation and website issues please visit the [babel/babel.github.io](https://github.com/babel/babel.github.io) repo. ## Want to contribute to Babel? @@ -123,8 +125,8 @@ Check out the [`babel-handbook`](https://github.com/thejameskyle/babel-handbook/ - [`babel-cli`](/packages/babel-cli) is the CLI tool that runs `babel-core` and helps with outputting to a directory, a file, stdout and more (also includes `babel-node`). Check out the [docs](https://babeljs.io/docs/usage/cli/). - [`babel-types`](/packages/babel-types) is used to validate, build, change AST nodes. - [`babel-polyfill`](/packages/babel-polyfill) is [literally a wrapper](https://github.com/babel/babel/blob/master/packages/babel-polyfill/src/index.js) around [`core-js`](https://github.com/zloirock/core-js) and [regenerator-runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime). Check out the [docs](https://babeljs.io/docs/usage/polyfill/). -- [`babel-runtime`](/packages/babel-runtime) is similar to the polyfill except that it doesn't modify the global scope and is to be used with [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) (usually in library/plugin code). Check out the [docs](https://babeljs.io/docs/plugins/transform-runtime/) -- [`babel-register`](/packages/babel-register) is a way to automatically compile files with babel on the fly by binding to node's require. Check out the [docs](http://babeljs.io/docs/usage/require/) +- [`babel-runtime`](/packages/babel-runtime) is similar to the polyfill except that it doesn't modify the global scope and is to be used with [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) (usually in library/plugin code). Check out the [docs](https://babeljs.io/docs/plugins/transform-runtime/). +- [`babel-register`](/packages/babel-register) is a way to automatically compile files with babel on the fly by binding to node's require. Check out the [docs](http://babeljs.io/docs/usage/require/). - [`babel-template`](/packages/babel-template) is a helper function to make AST nodes. Instead you can pass a string representing the code you want to create rather than tediously building them using `babel-types`. - [`babel-helpers`](/packages/babel-helpers) is a set of premade `babel-template` functions that are used in some babel plugins. - [`babel-code-frame`](/packages/babel-code-frame) is a standalone package used to generate errors that prints the source code and points to error locations. @@ -135,25 +137,9 @@ After Babel 6, the default transforms were removed; if you don't specify any plu The transformer[s] used in Babel are the independent pieces of code that transform specific things. For example: the [`es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) transform specifically changes arrow functions into a regular function. Presets are just simply an array of plugins that make it easier to run a whole a set of transforms without specifying each one manually. -There are a few presets that we maintain officially. - -| Package | Version | Dependencies | -|--------|-------|------------| -| [`babel-preset-es2015`](/packages/babel-preset-es2015) | [![npm](https://img.shields.io/npm/v/babel-preset-es2015.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2015) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2015)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2015) | -| [`babel-preset-es2016`](/packages/babel-preset-es2016) | [![npm](https://img.shields.io/npm/v/babel-preset-es2016.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2016) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2016)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2016) | -| [`babel-preset-es2017`](/packages/babel-preset-es2017) | [![npm](https://img.shields.io/npm/v/babel-preset-es2017.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2017) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2017)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2017) | -| [`babel-preset-latest`](/packages/babel-preset-latest) | [![npm](https://img.shields.io/npm/v/babel-preset-latest.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-latest) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-latest)](https://david-dm.org/babel/babel?path=packages/babel-preset-latest) | -| [`babel-preset-stage-0`](/packages/babel-preset-stage-0) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-0.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-0) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-0)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-0) | -| [`babel-preset-stage-1`](/packages/babel-preset-stage-1) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-1.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-1) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-1)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-1) | -| [`babel-preset-stage-2`](/packages/babel-preset-stage-2) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-2.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-2) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-2)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-2) | -| [`babel-preset-stage-3`](/packages/babel-preset-stage-3) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-3.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-3) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-3)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-3) | -| [`babel-preset-react`](/packages/babel-preset-react) | [![npm](https://img.shields.io/npm/v/babel-preset-react.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-react) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-react)](https://david-dm.org/babel/babel?path=packages/babel-preset-react) | - -We maintain: - -- a preset for each yearly release of ECMAScript (Javascript) starting from ES6/ES2015 -- a preset for react (JSX/Flow) -- a preset for each [stage (0-3)](http://babeljs.io/docs/plugins/#stage-x-experimental-presets) of the [TC-39 Process](https://tc39.github.io/process-document/) for ECMAScript proposals. +| Package | Version | Dependencies | Description | +|--------|-------|------------|---| +| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [![npm](https://img.shields.io/npm/v/babel-preset-env.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-env) | [![Dependency Status](https://david-dm.org/babel/babel-preset-env.svg)](https://david-dm.org/babel/babel-preset-env) | automatically determines plugins and polyfills you need based on your supported environments | > You can find community maintained presets on [npm](https://www.npmjs.com/search?q=babel-preset) @@ -165,79 +151,57 @@ Plugins are the heart of Babel and what make it work. #### Transform Plugins -There are many kinds of plugins: ones that convert ES6/ES2015 to ES5, transform to ES3, minification, JSX, flow, experimental features, and more. - -| Package | Version | External Deps | -|--------|-------|------------| -| [`babel-plugin-check-es2015-constants`](/packages/babel-plugin-check-es2015-constants) | [![npm](https://img.shields.io/npm/v/babel-plugin-check-es2015-constants.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-check-es2015-constants) | | -| [`babel-plugin-transform-async-functions`](/packages/babel-plugin-transform-async-functions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-async-functions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-async-functions) | | -| [`babel-plugin-transform-async-generator-functions`](/packages/babel-plugin-transform-async-generator-functions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-async-generator-functions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-async-generator-functions) | -| [`babel-plugin-transform-async-to-generator`](/packages/babel-plugin-transform-async-to-generator) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-async-to-generator.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-async-to-generator) | | -| [`babel-plugin-transform-async-to-module-method`](/packages/babel-plugin-transform-async-to-module-method) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-async-to-module-method.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-async-to-module-method) | | -| [`babel-plugin-transform-class-properties`](/packages/babel-plugin-transform-class-properties) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-class-properties.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-class-properties) | | -| [`babel-plugin-transform-decorators`](/packages/babel-plugin-transform-decorators) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-decorators.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-decorators) | | -| [`babel-plugin-transform-do-expressions`](/packages/babel-plugin-transform-do-expressions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-do-expressions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-do-expressions) | | -| [`babel-plugin-transform-es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-arrow-functions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-arrow-functions) | | -| [`babel-plugin-transform-es2015-block-scoped-functions`](/packages/babel-plugin-transform-es2015-block-scoped-functions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-block-scoped-functions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-block-scoped-functions) | | -| [`babel-plugin-transform-es2015-block-scoping`](/packages/babel-plugin-transform-es2015-block-scoping) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-block-scoping.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-block-scoping) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-plugin-transform-es2015-block-scoping)](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-es2015-block-scoping) | -| [`babel-plugin-transform-es2015-classes`](/packages/babel-plugin-transform-es2015-classes) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-classes.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-classes) | | -| [`babel-plugin-transform-es2015-computed-properties`](/packages/babel-plugin-transform-es2015-computed-properties) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-computed-properties.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-computed-properties) | | -| [`babel-plugin-transform-es2015-destructuring`](/packages/babel-plugin-transform-es2015-destructuring) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-destructuring.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-destructuring) | | -| [`babel-plugin-transform-es2015-duplicate-keys`](/packages/babel-plugin-transform-es2015-duplicate-keys) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-duplicate-keys.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-duplicate-keys) | | -| [`babel-plugin-transform-es2015-for-of`](/packages/babel-plugin-transform-es2015-for-of) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-for-of.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-for-of) | | -| [`babel-plugin-transform-es2015-function-name`](/packages/babel-plugin-transform-es2015-function-name) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-function-name.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-function-name) | | -| [`babel-plugin-transform-es2015-instanceof`](/packages/babel-plugin-transform-es2015-instanceof) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-instanceof.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-instanceof) | | -| [`babel-plugin-transform-es2015-literals`](/packages/babel-plugin-transform-es2015-literals) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-literals.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-literals) | | -| [`babel-plugin-transform-es2015-modules-amd`](/packages/babel-plugin-transform-es2015-modules-amd) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-modules-amd.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-amd) | | -| [`babel-plugin-transform-es2015-modules-commonjs`](/packages/babel-plugin-transform-es2015-modules-commonjs) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-modules-commonjs.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs) | | -| [`babel-plugin-transform-es2015-modules-systemjs`](/packages/babel-plugin-transform-es2015-modules-systemjs) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-modules-systemjs.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-systemjs) | | -| [`babel-plugin-transform-es2015-modules-umd`](/packages/babel-plugin-transform-es2015-modules-umd) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-modules-umd.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-umd) | | -| [`babel-plugin-transform-es2015-object-super`](/packages/babel-plugin-transform-es2015-object-super) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-object-super.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-object-super) | | -| [`babel-plugin-transform-es2015-parameters`](/packages/babel-plugin-transform-es2015-parameters) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-parameters.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-parameters) | | -| [`babel-plugin-transform-es2015-shorthand-properties`](/packages/babel-plugin-transform-es2015-shorthand-properties) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-shorthand-properties.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-shorthand-properties) | | -| [`babel-plugin-transform-es2015-spread`](/packages/babel-plugin-transform-es2015-spread) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-spread.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-spread) | | -| [`babel-plugin-transform-es2015-sticky-regex`](/packages/babel-plugin-transform-es2015-sticky-regex) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-sticky-regex.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-sticky-regex) | | -| [`babel-plugin-transform-es2015-template-literals`](/packages/babel-plugin-transform-es2015-template-literals) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-template-literals.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-template-literals) | | -| [`babel-plugin-transform-es2015-typeof-symbol`](/packages/babel-plugin-transform-es2015-typeof-symbol) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-typeof-symbol.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-typeof-symbol) | | -| [`babel-plugin-transform-es2015-unicode-regex`](/packages/babel-plugin-transform-es2015-unicode-regex) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es2015-unicode-regex.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es2015-unicode-regex) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-plugin-transform-es2015-unicode-regex)](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-es2015-unicode-regex) | -| [`babel-plugin-transform-es3-member-expression-literals`](/packages/babel-plugin-transform-es3-member-expression-literals) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es3-member-expression-literals.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es3-member-expression-literals) | | -| [`babel-plugin-transform-es3-property-literals`](/packages/babel-plugin-transform-es3-property-literals) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es3-property-literals.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es3-property-literals) | | -| [`babel-plugin-transform-es5-property-mutators`](/packages/babel-plugin-transform-es5-property-mutators) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-es5-property-mutators.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-es5-property-mutators) | | -| [`babel-plugin-transform-eval`](/packages/babel-plugin-transform-eval) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-eval.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-eval) | | -| [`babel-plugin-transform-exponentiation-operator`](/packages/babel-plugin-transform-exponentiation-operator) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-exponentiation-operator.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-exponentiation-operator) | | -| [`babel-plugin-transform-export-extensions`](/packages/babel-plugin-transform-export-extensions) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-export-extensions.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-export-extensions) | | -| [`babel-plugin-transform-flow-comments`](/packages/babel-plugin-transform-flow-comments) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-flow-comments.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-flow-comments) | | -| [`babel-plugin-transform-flow-strip-types`](/packages/babel-plugin-transform-flow-strip-types) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-flow-strip-types.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-flow-strip-types) | | -| [`babel-plugin-transform-function-bind`](/packages/babel-plugin-transform-function-bind) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-function-bind.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-function-bind) | | -| [`babel-plugin-transform-jscript`](/packages/babel-plugin-transform-jscript) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-jscript.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-jscript) | | -| [`babel-plugin-transform-object-assign`](/packages/babel-plugin-transform-object-assign) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-object-assign.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-object-assign) | | -| [`babel-plugin-transform-object-rest-spread`](/packages/babel-plugin-transform-object-rest-spread) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-object-rest-spread.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-object-rest-spread) | | -| [`babel-plugin-transform-object-set-prototype-of-to-assign`](/packages/babel-plugin-transform-object-set-prototype-of-to-assign) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-object-set-prototype-of-to-assign.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-object-set-prototype-of-to-assign) | | -| [`babel-plugin-transform-proto-to-assign`](/packages/babel-plugin-transform-proto-to-assign) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-proto-to-assign.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-proto-to-assign) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-plugin-transform-proto-to-assign)](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-proto-to-assign) | -| [`babel-plugin-transform-react-constant-elements`](/packages/babel-plugin-transform-react-constant-elements) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-constant-elements.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-constant-elements) | | -| [`babel-plugin-transform-react-display-name`](/packages/babel-plugin-transform-react-display-name) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-display-name.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-display-name) | | -| [`babel-plugin-transform-react-inline-elements`](/packages/babel-plugin-transform-react-inline-elements) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-inline-elements.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-inline-elements) | | -| [`babel-plugin-transform-react-jsx`](/packages/babel-plugin-transform-react-jsx) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-jsx.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-jsx) | | -| [`babel-plugin-transform-react-jsx-compat`](/packages/babel-plugin-transform-react-jsx-compat) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-jsx-compat.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-compat) | | -| [`babel-plugin-transform-react-jsx-self`](/packages/babel-plugin-transform-react-jsx-self) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-jsx-self.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-self) | | -| [`babel-plugin-transform-react-jsx-source`](/packages/babel-plugin-transform-react-jsx-source) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-react-jsx-source.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) | | -| [`babel-plugin-transform-regenerator`](/packages/babel-plugin-transform-regenerator) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-regenerator.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-regenerator) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-plugin-transform-regenerator)](https://david-dm.org/babel/babel?path=packages/babel-plugin-transform-regenerator) | -| [`babel-plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-runtime.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-runtime) | | -| [`babel-plugin-transform-strict-mode`](/packages/babel-plugin-transform-strict-mode) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-strict-mode.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-transform-strict-mode) | | +There are many kinds of plugins: ones that convert ES6/ES2015 to ES5, transform to ES3, minification, JSX, flow, experimental features, and more. Check out our [website for more](http://babeljs.io/docs/plugins/#transform-plugins). #### Syntax Plugins -These just enable the transform plugins to be able to parse certain features (the transform plugins already include the syntax plugins so you don't need both): `babel-plugin-syntax-x`. +These just enable the transform plugins to be able to parse certain features (the transform plugins already include the syntax plugins so you don't need both): `babel-plugin-syntax-x`. Check out our [website for more](http://babeljs.io/docs/plugins/#syntax-plugins). ### Helpers These are mostly for internal use in various plugins: `babel-helper-x`. -### Misc Packages +## Team -- [`babel`](/packages/babel) the deprecated `babel` package on npm that was used in Babel 5. -- [`babel-messages`](/packages/babel-messages) a package to keep error messages, etc (not always used) +### Core members + +[![Babel](https://avatars.githubusercontent.com/u/9637642?s=64)](https://github.com/babel) | [![Daniel Tschinder](https://avatars.githubusercontent.com/u/231804?s=64)](https://github.com/danez) | [![Logan Smyth](https://avatars.githubusercontent.com/u/132260?s=64)](https://github.com/loganfsmyth) | [![Henry Zhu](https://avatars.githubusercontent.com/u/588473?s=64)](https://github.com/hzoo) | +|---|---|---|---|---| +Babel | Daniel Tschinder | Logan Smyth | Henry Zhu | +:octocat: [@babel](https://github.com/babel) | [@danez](https://github.com/danez) | [@loganfsmyth](https://github.com/loganfsmyth) | [@hzoo](https://github.com/hzoo) | +:bird: [@babeljs](https://twitter.com/babeljs) | [@TschinderDaniel](https://twitter.com/TschinderDaniel) | [@loganfsmyth](https://twitter.com/loganfsmyth) | [@left_pad](https://twitter.com/left_pad) | + +### Members + +[![Andrew Levine](https://avatars.githubusercontent.com/u/5233399?s=64)](https://github.com/drewml) | [![Boopathi Rajaa](https://avatars.githubusercontent.com/u/294474?s=64)](https://github.com/boopathi) | [![Brian Ng](https://avatars.githubusercontent.com/u/56288?s=64)](https://github.com/existentialism) | [![Dan Harper](https://avatars.githubusercontent.com/u/510740?s=64)](https://github.com/danharper) | [![diogo franco](https://avatars.githubusercontent.com/u/73085?s=64)](https://github.com/kovensky) | [![Aaron Ang](https://avatars1.githubusercontent.com/u/7579804?s=64)](https://github.com/aaronang) | [![Artem Yavorsky](https://avatars2.githubusercontent.com/u/1521229?s=64)](https://github.com/yavorsky) | +|---|---|---|---|---|---|---|---|---|---|---| +| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco | Aaron Ang | Artem Yavorsky | +| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) | [@aaronang](https://github.com/aaronang) | [@yavorsky](https://github.com/yavorsky) | +| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) | [@_aaronang](https://twitter.com/_aaronang) | [@yavorsky_](https://twitter.com/yavorsky_) | + +[![Juriy Zaytsev](https://avatars.githubusercontent.com/u/383?s=64)](https://github.com/kangax) | [![Kai Cataldo](https://avatars.githubusercontent.com/u/7041728?s=64)](https://github.com/kaicataldo) | [![Moti Zilberman](https://avatars.githubusercontent.com/u/2246565?s=64)](https://github.com/motiz88) | [![Sven Sauleau](https://avatars3.githubusercontent.com/u/1493671?s=64)](https://github.com/xtuc) | [![Samuel Reed](https://avatars3.githubusercontent.com/u/1197375?s=64)](https://github.com/STRML) | [![Sergey Rubanov](https://avatars1.githubusercontent.com/u/1507086?s=64)](https://github.com/chicoxyzzy) | +|---|---|---|---|---|---|---|---|---|---|---| +| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau | Samuel Reed | Sergey Rubanov | +| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | [@STRML](https://github.com/STRML) | [@chicoxyzzy](https://github.com/chicoxyzzy) | +| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) | [@STRML_](https://twitter.com/STRML_) | [@chicoxyzzy](https://twitter.com/chicoxyzzy) | + +### Non-Human Members + +[](https://github.com/babel-bot) | +|---| +| Babel Bot | +| [@babel-bot](https://github.com/babel-bot) | +| [@babeljs](https://twitter.com/babeljs) | + +### Inactive members + +[![Amjad Masad](https://avatars.githubusercontent.com/u/587518?s=64)](https://github.com/amasad) | [![James Kyle](https://avatars.githubusercontent.com/u/952783?s=64)](https://github.com/thejameskyle) | [![Jesse McCarthy](https://avatars.githubusercontent.com/u/129203?s=64)](https://github.com/jmm) | [![Sebastian McKenzie](https://avatars.githubusercontent.com/u/853712?s=64)](https://github.com/kittens) (Creator) | +|---|---|---|---| +Amjad Masad | James Kyle | Jesse McCarthy | Sebastian McKenzie | +[@amasad](https://github.com/amasad) | [@thejameskyle](https://github.com/thejameskyle) | [@jmm](https://github.com/jmm) | [@sebmck](https://twitter.com/sebmck) | +| [@amasad](https://twitter.com/amasad) | [@thejameskyle](https://twitter.com/thejameskyle) | [@mccjm](https://twitter.com/mccjm) | [@kittens](https://github.com/kittens) ## License [MIT](https://github.com/babel/babel/blob/master/LICENSE) + diff --git a/babel.sublime-project b/babel.sublime-project new file mode 100644 index 0000000000..1f18a8cc50 --- /dev/null +++ b/babel.sublime-project @@ -0,0 +1,25 @@ +{ + "settings": { + "rulers": [ + 110 + ], + + // Set to false to disable detection of tabs vs. spaces on load + "detect_indentation": false, + + "translate_tabs_to_spaces": true, + + "tab_size": 2 + }, + + "folders": [{ + "path": ".", + "folder_exclude_patterns": [ + "packages/*/lib", + "node_modules" + ], + "file_exclude_patterns": [ + + ] + }] +} diff --git a/circle.yml b/circle.yml index 8aa7e6da90..df9b1c49ec 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,15 @@ machine: node: version: - 0.10.46 + 6 + +dependencies: + pre: + - curl -o- -L https://yarnpkg.com/install.sh | bash + cache_directories: + - ~/.yarn-cache + override: + - yarn test: override: diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..3e31ee1814 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,4 @@ +coverage: + parsers: + javascript: + enable_partials: yes diff --git a/doc/design/compiler-environment-support.md b/doc/design/compiler-environment-support.md index 77c01b0878..1d5a867205 100644 --- a/doc/design/compiler-environment-support.md +++ b/doc/design/compiler-environment-support.md @@ -2,12 +2,12 @@ **NOTE:** Compiler support does not dictate the runtime requirements of compiled code. -## Supported environments +## Officially supported environments The Babel compiler is **only** supported in these environments: - Modern browsers such as Chrome, Firefox, Safari, Edge etc. - - Node 0.10+ + - Node.js 4 and upper versions ## Unsupported environments @@ -17,7 +17,6 @@ to: - Rhino - Nashorn - Internet Explorer - - ... **NOTE:** If Babel works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk. diff --git a/lerna.json b/lerna.json index d2ff6578fb..91036a0b36 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { - "lerna": "2.0.0-beta.23", - "version": "6.21.0", + "lerna": "2.0.0-beta.38", + "version": "7.0.0-alpha.2", "changelog": { "repo": "babel/babel", "labels": { @@ -13,13 +13,13 @@ "tag: internal": ":house: Internal" } }, - "bootstrapConfig": { - "ignore": "babel-runtime" - }, - "publishConfig": { - "ignore": [ - "*.md", - "test/**" - ] + "cacheDir": ".changelog", + "commands": { + "publish": { + "ignore": [ + "*.md", + "test/**" + ] + } } } diff --git a/lib/types.js b/lib/types.js index e42a516b4a..869cd587f8 100644 --- a/lib/types.js +++ b/lib/types.js @@ -581,8 +581,8 @@ declare class BabelNodeDeclareVariable extends BabelNode { id: any; } -declare class BabelNodeExistentialTypeParam extends BabelNode { - type: "ExistentialTypeParam"; +declare class BabelNodeExistsTypeAnnotation extends BabelNode { + type: "ExistsTypeAnnotation"; } declare class BabelNodeFunctionTypeAnnotation extends BabelNode { @@ -632,8 +632,8 @@ declare class BabelNodeNullableTypeAnnotation extends BabelNode { typeAnnotation: any; } -declare class BabelNodeNumericLiteralTypeAnnotation extends BabelNode { - type: "NumericLiteralTypeAnnotation"; +declare class BabelNodeNumberLiteralTypeAnnotation extends BabelNode { + type: "NumberLiteralTypeAnnotation"; } declare class BabelNodeNumberTypeAnnotation extends BabelNode { @@ -873,7 +873,7 @@ type BabelNodeClass = BabelNodeClassDeclaration | BabelNodeClassExpression; type BabelNodeModuleDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration | BabelNodeImportDeclaration; type BabelNodeExportDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration; type BabelNodeModuleSpecifier = BabelNodeExportSpecifier | BabelNodeImportDefaultSpecifier | BabelNodeImportNamespaceSpecifier | BabelNodeImportSpecifier | BabelNodeExportDefaultSpecifier | BabelNodeExportNamespaceSpecifier; -type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistentialTypeParam | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumericLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation; +type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistsTypeAnnotation | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumberLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation; type BabelNodeFlowBaseAnnotation = BabelNodeAnyTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeVoidTypeAnnotation; type BabelNodeFlowDeclaration = BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeInterfaceDeclaration | BabelNodeTypeAlias; type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText; @@ -965,7 +965,7 @@ declare module "babel-types" { declare function declareModuleExports(typeAnnotation: any): BabelNodeDeclareModuleExports; declare function declareTypeAlias(id: any, typeParameters: any, right: any): BabelNodeDeclareTypeAlias; declare function declareVariable(id: any): BabelNodeDeclareVariable; - declare function existentialTypeParam(): BabelNodeExistentialTypeParam; + declare function existsTypeAnnotation(): BabelNodeExistsTypeAnnotation; declare function functionTypeAnnotation(typeParameters: any, params: any, rest: any, returnType: any): BabelNodeFunctionTypeAnnotation; declare function functionTypeParam(name: any, typeAnnotation: any): BabelNodeFunctionTypeParam; declare function genericTypeAnnotation(id: any, typeParameters: any): BabelNodeGenericTypeAnnotation; @@ -974,7 +974,7 @@ declare module "babel-types" { declare function intersectionTypeAnnotation(types: any): BabelNodeIntersectionTypeAnnotation; declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation; declare function nullableTypeAnnotation(typeAnnotation: any): BabelNodeNullableTypeAnnotation; - declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation; + declare function numberLiteralTypeAnnotation(): BabelNodeNumberLiteralTypeAnnotation; declare function numberTypeAnnotation(): BabelNodeNumberTypeAnnotation; declare function stringLiteralTypeAnnotation(): BabelNodeStringLiteralTypeAnnotation; declare function stringTypeAnnotation(): BabelNodeStringTypeAnnotation; @@ -1101,7 +1101,7 @@ declare module "babel-types" { declare function isDeclareModuleExports(node: Object, opts?: Object): boolean; declare function isDeclareTypeAlias(node: Object, opts?: Object): boolean; declare function isDeclareVariable(node: Object, opts?: Object): boolean; - declare function isExistentialTypeParam(node: Object, opts?: Object): boolean; + declare function isExistsTypeAnnotation(node: Object, opts?: Object): boolean; declare function isFunctionTypeAnnotation(node: Object, opts?: Object): boolean; declare function isFunctionTypeParam(node: Object, opts?: Object): boolean; declare function isGenericTypeAnnotation(node: Object, opts?: Object): boolean; @@ -1110,7 +1110,7 @@ declare module "babel-types" { declare function isIntersectionTypeAnnotation(node: Object, opts?: Object): boolean; declare function isMixedTypeAnnotation(node: Object, opts?: Object): boolean; declare function isNullableTypeAnnotation(node: Object, opts?: Object): boolean; - declare function isNumericLiteralTypeAnnotation(node: Object, opts?: Object): boolean; + declare function isNumberLiteralTypeAnnotation(node: Object, opts?: Object): boolean; declare function isNumberTypeAnnotation(node: Object, opts?: Object): boolean; declare function isStringLiteralTypeAnnotation(node: Object, opts?: Object): boolean; declare function isStringTypeAnnotation(node: Object, opts?: Object): boolean; diff --git a/package.json b/package.json index e62332ff19..b4ebcee5a0 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "name": "babel", "private": true, "license": "MIT", "scripts": { @@ -14,11 +15,9 @@ "babel-plugin-istanbul": "^2.0.1", "babel-plugin-transform-class-properties": "^6.6.0", "babel-plugin-transform-flow-strip-types": "^6.3.13", - "babel-plugin-transform-runtime": "^6.3.13", "babel-preset-es2015": "^6.13.2", "babel-preset-stage-0": "^6.0.0", "babel-register": "^6.14.0", - "babel-runtime": "^6.0.0", "browserify": "^13.1.1", "bundle-collapser": "^1.2.1", "chai": "^3.5.0", @@ -26,8 +25,7 @@ "codecov": "^1.0.1", "derequire": "^2.0.2", "eslint": "^3.9.0", - "eslint-config-babel": "^2.0.1", - "eslint-plugin-babel": "^3.3.0", + "eslint-config-babel": "^6.0.0", "eslint-plugin-flowtype": "^2.20.0", "flow-bin": "^0.34.0", "gulp": "^3.9.0", @@ -36,7 +34,7 @@ "gulp-plumber": "^1.0.1", "gulp-util": "^3.0.7", "gulp-watch": "^4.3.5", - "lerna": "2.0.0-beta.23", + "lerna": "^2.0.0-beta.38", "lerna-changelog": "^0.2.0", "lodash": "^4.2.0", "mocha": "^3.0.0", @@ -47,6 +45,10 @@ "through2": "^2.0.0", "uglify-js": "^2.4.16" }, + "devEngines": { + "node": ">= 0.10 <= 7.x", + "npm": "2.x || 3.x || 4.x" + }, "babel": { "comments": false, "presets": [ @@ -59,13 +61,11 @@ "stage-0" ], "plugins": [ - "./scripts/add-module-exports", - "transform-runtime", "transform-class-properties", "transform-flow-strip-types" ], "env": { - "test": { + "cov": { "auxiliaryCommentBefore": "istanbul ignore next", "plugins": [ "istanbul" diff --git a/packages/babel-cli/package.json b/packages/babel-cli/package.json index 9dfdd70124..81ca73d32b 100644 --- a/packages/babel-cli/package.json +++ b/packages/babel-cli/package.json @@ -1,32 +1,39 @@ { "name": "babel-cli", - "version": "6.18.0", + "version": "7.0.0-alpha.2", "description": "Babel command line.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-cli", + "keywords": [ + "6to5", + "babel", + "es6", + "transpile", + "transpiler", + "babel-cli", + "compiler" + ], "dependencies": { - "babel-core": "^6.18.0", - "babel-register": "^6.18.0", - "babel-polyfill": "^6.16.0", - "babel-runtime": "^6.9.0", + "babel-core": "7.0.0-alpha.2", + "babel-register": "7.0.0-alpha.2", + "babel-polyfill": "7.0.0-alpha.1", "commander": "^2.8.1", "convert-source-map": "^1.1.0", "fs-readdir-recursive": "^1.0.0", - "glob": "^5.0.5", + "glob": "^7.0.0", "lodash": "^4.2.0", "output-file-sync": "^1.1.0", - "path-is-absolute": "^1.0.0", "slash": "^1.0.0", "source-map": "^0.5.0", "v8flags": "^2.0.10" }, "optionalDependencies": { - "chokidar": "^1.0.0" + "chokidar": "^1.6.1" }, "devDependencies": { - "babel-helper-fixtures": "^6.18.0" + "babel-helper-fixtures": "7.0.0-alpha.1" }, "bin": { "babel-doctor": "./bin/babel-doctor.js", diff --git a/packages/babel-cli/src/_babel-node.js b/packages/babel-cli/src/_babel-node.js index 3c7c40ed4d..ee6e340c31 100644 --- a/packages/babel-cli/src/_babel-node.js +++ b/packages/babel-cli/src/_babel-node.js @@ -1,4 +1,3 @@ -import pathIsAbsolute from "path-is-absolute"; import commander from "commander"; import Module from "module"; import { inspect } from "util"; @@ -7,11 +6,12 @@ import repl from "repl"; import { util } from "babel-core"; import * as babel from "babel-core"; import vm from "vm"; -import _ from "lodash"; import "babel-polyfill"; import register from "babel-register"; -let program = new commander.Command("babel-node"); +import pkg from "../package.json"; + +const program = new commander.Command("babel-node"); program.option("-e, --eval [script]", "Evaluate script"); program.option("-p, --print [code]", "Evaluate script and print result"); @@ -21,7 +21,6 @@ program.option("-x, --extensions [extensions]", "List of extensions to hook into program.option("-w, --plugins [string]", "", util.list); program.option("-b, --presets [string]", "", util.list); -let pkg = require("../package.json"); program.version(pkg.version); program.usage("[options] [ -e script | script.js ] [arguments]"); program.parse(process.argv); @@ -30,15 +29,15 @@ program.parse(process.argv); register({ extensions: program.extensions, - ignore: program.ignore, - only: program.only, - plugins: program.plugins, - presets: program.presets, + ignore: program.ignore, + only: program.only, + plugins: program.plugins, + presets: program.presets, }); // -let replPlugin = ({ types: t }) => ({ +const replPlugin = ({ types: t }) => ({ visitor: { ModuleDeclaration(path) { throw path.buildCodeFrameError("Modules aren't supported in the REPL"); @@ -56,24 +55,24 @@ let replPlugin = ({ types: t }) => ({ // If the executed code doesn't evaluate to a value, // prevent implicit strict mode from printing 'use strict'. path.pushContainer("body", t.expressionStatement(t.identifier("undefined"))); - } - } + }, + }, }); // -let _eval = function (code, filename) { +const _eval = function (code, filename) { code = code.trim(); if (!code) return undefined; code = babel.transform(code, { filename: filename, presets: program.presets, - plugins: (program.plugins || []).concat([replPlugin]) + plugins: (program.plugins || []).concat([replPlugin]), }).code; return vm.runInThisContext(code, { - filename: filename + filename: filename, }); }; @@ -84,17 +83,17 @@ if (program.eval || program.print) { global.__filename = "[eval]"; global.__dirname = process.cwd(); - let module = new Module(global.__filename); + const module = new Module(global.__filename); module.filename = global.__filename; - module.paths = Module._nodeModulePaths(global.__dirname); + module.paths = Module._nodeModulePaths(global.__dirname); global.exports = module.exports; - global.module = module; + global.module = module; global.require = module.require.bind(module); - let result = _eval(code, global.__filename); + const result = _eval(code, global.__filename); if (program.print) { - let output = _.isString(result) ? result : inspect(result); + const output = typeof result === "string" ? result : inspect(result); process.stdout.write(output + "\n"); } } else { @@ -104,27 +103,27 @@ if (program.eval || program.print) { let i = 0; let ignoreNext = false; - _.each(args, function (arg, i2) { + args.some(function (arg, i2) { if (ignoreNext) { ignoreNext = false; return; } if (arg[0] === "-") { - let parsedArg = program[arg.slice(2)]; + const parsedArg = program[arg.slice(2)]; if (parsedArg && parsedArg !== true) { ignoreNext = true; } } else { i = i2; - return false; + return true; } }); args = args.slice(i); // make the filename absolute - let filename = args[0]; - if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename); + const filename = args[0]; + if (!path.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename); // add back on node and concat the sliced args process.argv = ["node"].concat(args); @@ -142,7 +141,7 @@ function replStart() { input: process.stdin, output: process.stdout, eval: replEval, - useGlobal: true + useGlobal: true, }); } diff --git a/packages/babel-cli/src/babel-node.js b/packages/babel-cli/src/babel-node.js index 0830a2313d..3da22997f7 100755 --- a/packages/babel-cli/src/babel-node.js +++ b/packages/babel-cli/src/babel-node.js @@ -1,12 +1,10 @@ -/* eslint indent: 0 */ - /** * This tiny wrapper file checks for known node flags and appends them * when found, before invoking the "real" _babel-node(1) executable. */ -let getV8Flags = require("v8flags"); -let path = require("path"); +import getV8Flags from "v8flags"; +import path from "path"; let args = [path.join(__dirname, "_babel-node")]; @@ -14,9 +12,9 @@ let babelArgs = process.argv.slice(2); let userArgs; // separate node arguments from script arguments -let argSeparator = babelArgs.indexOf("--"); +const argSeparator = babelArgs.indexOf("--"); if (argSeparator > -1) { - userArgs = babelArgs.slice(argSeparator); // including the -- + userArgs = babelArgs.slice(argSeparator); // including the -- babelArgs = babelArgs.slice(0, argSeparator); } @@ -75,13 +73,13 @@ getV8Flags(function (err, v8Flags) { } try { - let kexec = require("kexec"); + const kexec = require("kexec"); kexec(process.argv[0], args); } catch (err) { if (err.code !== "MODULE_NOT_FOUND") throw err; - let child_process = require("child_process"); - let proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" }); + const child_process = require("child_process"); + const proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" }); proc.on("exit", function (code, signal) { process.on("exit", function () { if (signal) { diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 78be975c88..0316062590 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -1,26 +1,26 @@ -let outputFileSync = require("output-file-sync"); -let slash = require("slash"); -let path = require("path"); -let util = require("./util"); -let fs = require("fs"); -let _ = require("lodash"); +import outputFileSync from "output-file-sync"; +import slash from "slash"; +import path from "path"; +import fs from "fs"; -module.exports = function (commander, filenames) { +import * as util from "./util"; + +export default function (commander, filenames) { function write(src, relative) { // remove extension and then append back on .js relative = relative.replace(/\.(\w*?)$/, "") + ".js"; - let dest = path.join(commander.outDir, relative); + const dest = path.join(commander.outDir, relative); - let data = util.compile(src, { + const data = util.compile(src, { sourceFileName: slash(path.relative(dest + "/..", src)), - sourceMapTarget: path.basename(relative) + sourceMapTarget: path.basename(relative), }); if (!commander.copyFiles && data.ignored) return; // we've requested explicit sourcemaps to be written to disk if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") { - let mapLoc = dest + ".map"; + const mapLoc = dest + ".map"; data.code = util.addSourceMappingUrl(data.code, mapLoc); outputFileSync(mapLoc, JSON.stringify(data.map)); } @@ -37,7 +37,7 @@ module.exports = function (commander, filenames) { if (util.canCompile(filename, commander.extensions)) { write(src, filename); } else if (commander.copyFiles) { - let dest = path.join(commander.outDir, filename); + const dest = path.join(commander.outDir, filename); outputFileSync(dest, fs.readFileSync(src)); util.chmod(src, dest); } @@ -46,13 +46,13 @@ module.exports = function (commander, filenames) { function handle(filename) { if (!fs.existsSync(filename)) return; - let stat = fs.statSync(filename); + const stat = fs.statSync(filename); if (stat.isDirectory(filename)) { - let dirname = filename; + const dirname = filename; - _.each(util.readdir(dirname), function (filename) { - let src = path.join(dirname, filename); + util.readdir(dirname).forEach(function (filename) { + const src = path.join(dirname, filename); handleFile(src, filename); }); } else { @@ -61,21 +61,25 @@ module.exports = function (commander, filenames) { } if (!commander.skipInitialBuild) { - _.each(filenames, handle); + filenames.forEach(handle); } if (commander.watch) { - let chokidar = util.requireChokidar(); + const chokidar = util.requireChokidar(); - _.each(filenames, function (dirname) { - let watcher = chokidar.watch(dirname, { + filenames.forEach(function (dirname) { + const watcher = chokidar.watch(dirname, { persistent: true, - ignoreInitial: true + ignoreInitial: true, + awaitWriteFinish: { + stabilityThreshold: 50, + pollInterval: 10, + }, }); - _.each(["add", "change"], function (type) { + ["add", "change"].forEach(function (type) { watcher.on(type, function (filename) { - let relative = path.relative(dirname, filename) || filename; + const relative = path.relative(dirname, filename) || filename; try { handleFile(filename, relative); } catch (err) { @@ -85,4 +89,4 @@ module.exports = function (commander, filenames) { }); }); } -}; +} diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js index 1feb8d2aad..fb4b1f9a0c 100644 --- a/packages/babel-cli/src/babel/file.js +++ b/packages/babel-cli/src/babel/file.js @@ -1,33 +1,33 @@ -let convertSourceMap = require("convert-source-map"); -let sourceMap = require("source-map"); -let slash = require("slash"); -let path = require("path"); -let util = require("./util"); -let fs = require("fs"); -let _ = require("lodash"); +import convertSourceMap from "convert-source-map"; +import sourceMap from "source-map"; +import slash from "slash"; +import path from "path"; +import fs from "fs"; -module.exports = function (commander, filenames, opts) { +import * as util from "./util"; + +export default function (commander, filenames, opts) { if (commander.sourceMaps === "inline") { opts.sourceMaps = true; } let results = []; - let buildResult = function () { - let map = new sourceMap.SourceMapGenerator({ + const buildResult = function () { + const map = new sourceMap.SourceMapGenerator({ file: path.basename(commander.outFile || "") || "stdout", - sourceRoot: opts.sourceRoot + sourceRoot: opts.sourceRoot, }); let code = ""; let offset = 0; - _.each(results, function (result) { + results.forEach(function (result) { code += result.code + "\n"; if (result.map) { - let consumer = new sourceMap.SourceMapConsumer(result.map); - let sources = new Set(); + const consumer = new sourceMap.SourceMapConsumer(result.map); + const sources = new Set(); consumer.eachMapping(function (mapping) { if (mapping.source != null) sources.add(mapping.source); @@ -46,13 +46,13 @@ module.exports = function (commander, filenames, opts) { }); sources.forEach((source) => { - let content = consumer.sourceContentFor(source, true); + const content = consumer.sourceContentFor(source, true); if (content !== null) { map.setSourceContent(source, content); } }); - offset = code.split("\n").length; + offset = code.split("\n").length - 1; } }); @@ -64,17 +64,17 @@ module.exports = function (commander, filenames, opts) { return { map: map, - code: code + code: code, }; }; - let output = function () { - let result = buildResult(); + const output = function () { + const result = buildResult(); if (commander.outFile) { // we've requested for a sourcemap to be written to disk if (commander.sourceMaps && commander.sourceMaps !== "inline") { - let mapLoc = commander.outFile + ".map"; + const mapLoc = commander.outFile + ".map"; result.code = util.addSourceMappingUrl(result.code, mapLoc); fs.writeFileSync(mapLoc, JSON.stringify(result.map)); } @@ -85,13 +85,13 @@ module.exports = function (commander, filenames, opts) { } }; - let stdin = function () { + const stdin = function () { let code = ""; process.stdin.setEncoding("utf8"); process.stdin.on("readable", function () { - let chunk = process.stdin.read(); + const chunk = process.stdin.read(); if (chunk !== null) code += chunk; }); @@ -103,18 +103,18 @@ module.exports = function (commander, filenames, opts) { }); }; - let walk = function () { - let _filenames = []; + const walk = function () { + const _filenames = []; results = []; - _.each(filenames, function (filename) { + filenames.forEach(function (filename) { if (!fs.existsSync(filename)) return; - let stat = fs.statSync(filename); + const stat = fs.statSync(filename); if (stat.isDirectory()) { - let dirname = filename; + const dirname = filename; - _.each(util.readdirFilter(filename), function (filename) { + util.readdirFilter(filename).forEach(function (filename) { _filenames.push(path.join(dirname, filename)); }); } else { @@ -122,7 +122,7 @@ module.exports = function (commander, filenames, opts) { } }); - _.each(_filenames, function (filename) { + _filenames.forEach(function (filename) { if (util.shouldIgnore(filename)) return; let sourceFilename = filename; @@ -131,7 +131,7 @@ module.exports = function (commander, filenames, opts) { } sourceFilename = slash(sourceFilename); - let data = util.compile(filename, { + const data = util.compile(filename, { sourceFileName: sourceFilename, }); @@ -142,17 +142,21 @@ module.exports = function (commander, filenames, opts) { output(); }; - let files = function () { + const files = function () { if (!commander.skipInitialBuild) { walk(); } if (commander.watch) { - let chokidar = util.requireChokidar(); + const chokidar = util.requireChokidar(); chokidar.watch(filenames, { persistent: true, - ignoreInitial: true + ignoreInitial: true, + awaitWriteFinish: { + stabilityThreshold: 50, + pollInterval: 10, + }, }).on("all", function (type, filename) { if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return; @@ -173,4 +177,4 @@ module.exports = function (commander, filenames, opts) { } else { stdin(); } -}; +} diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js index 236c2df72a..a96056b3dc 100755 --- a/packages/babel-cli/src/babel/index.js +++ b/packages/babel-cli/src/babel/index.js @@ -1,18 +1,19 @@ #!/usr/bin/env node -/* eslint max-len: 0 */ -require("babel-core"); +import fs from "fs"; +import commander from "commander"; +import kebabCase from "lodash/kebabCase"; +import { options, util, version } from "babel-core"; +import uniq from "lodash/uniq"; +import glob from "glob"; -let fs = require("fs"); -let commander = require("commander"); -let kebabCase = require("lodash/kebabCase"); -let options = require("babel-core").options; -let util = require("babel-core").util; -let uniq = require("lodash/uniq"); -let each = require("lodash/each"); -let glob = require("glob"); +import dirCommand from "./dir"; +import fileCommand from "./file"; -each(options, function (option, key) { +import pkg from "../../package.json"; + +Object.keys(options).forEach(function (key) { + const option = options[key]; if (option.hidden) return; let arg = kebabCase(key); @@ -31,13 +32,14 @@ each(options, function (option, key) { arg = "-" + option.shorthand + ", " + arg; } - let desc = []; + const desc = []; if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated); if (option.description) desc.push(option.description); commander.option(arg, desc.join(" ")); }); +/* eslint-disable max-len */ commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]"); commander.option("-w, --watch", "Recompile files on changes"); commander.option("--skip-initial-build", "Do not compile files before watching"); @@ -45,9 +47,9 @@ commander.option("-o, --out-file [out]", "Compile all input files into a single commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory"); commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files"); commander.option("-q, --quiet", "Don't log anything"); +/* eslint-enable max-len */ -let pkg = require("../../package.json"); -commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")"); +commander.version(pkg.version + " (babel-core " + version + ")"); commander.usage("[options] "); commander.parse(process.argv); @@ -59,7 +61,7 @@ if (commander.extensions) { // -let errors = []; +const errors = []; let filenames = commander.args.reduce(function (globbed, input) { let files = glob.sync(input); @@ -69,7 +71,7 @@ let filenames = commander.args.reduce(function (globbed, input) { filenames = uniq(filenames); -each(filenames, function (filename) { +filenames.forEach(function (filename) { if (!fs.existsSync(filename)) { errors.push(filename + " doesn't exist"); } @@ -104,9 +106,10 @@ if (errors.length) { // -let opts = exports.opts = {}; +export const opts = {}; -each(options, function (opt, key) { +Object.keys(options).forEach(function (key) { + const opt = options[key]; if (commander[key] !== undefined && commander[key] !== opt.default) { opts[key] = commander[key]; } @@ -118,12 +121,5 @@ if (opts.only) { opts.only = util.arrayify(opts.only, util.regexify); } -let fn; - -if (commander.outDir) { - fn = require("./dir"); -} else { - fn = require("./file"); -} - -fn(commander, filenames, exports.opts); +const fn = commander.outDir ? dirCommand : fileCommand; +fn(commander, filenames, opts); diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js index fd06aa6ce7..e92b09c671 100644 --- a/packages/babel-cli/src/babel/util.js +++ b/packages/babel-cli/src/babel/util.js @@ -1,11 +1,11 @@ -let commander = require("commander"); -let readdir = require("fs-readdir-recursive"); -let index = require("./index"); -let babel = require("babel-core"); -let util = require("babel-core").util; -let path = require("path"); -let fs = require("fs"); -let _ = require("lodash"); +import commander from "commander"; +import defaults from "lodash/defaults"; +import readdir from "fs-readdir-recursive"; +import * as babel from "babel-core"; +import path from "path"; +import fs from "fs"; + +import * as index from "./index"; export function chmod(src, dest) { fs.chmodSync(dest, fs.statSync(src).mode); @@ -13,16 +13,16 @@ export function chmod(src, dest) { export function readdirFilter(filename) { return readdir(filename).filter(function (filename) { - return util.canCompile(filename); + return babel.util.canCompile(filename); }); } export { readdir }; -export let canCompile = util.canCompile; +export const canCompile = babel.util.canCompile; export function shouldIgnore(loc) { - return util.shouldIgnore(loc, index.opts.ignore, index.opts.only); + return babel.util.shouldIgnore(loc, index.opts.ignore, index.opts.only); } export function addSourceMappingUrl(code, loc) { @@ -34,10 +34,10 @@ export function log(msg) { } export function transform(filename, code, opts) { - opts = _.defaults(opts || {}, index.opts); + opts = defaults(opts || {}, index.opts); opts.filename = filename; - let result = babel.transform(code, opts); + const result = babel.transform(code, opts); result.filename = filename; result.actual = code; return result; @@ -45,7 +45,7 @@ export function transform(filename, code, opts) { export function compile(filename, opts) { try { - let code = fs.readFileSync(filename, "utf8"); + const code = fs.readFileSync(filename, "utf8"); return transform(filename, code, opts); } catch (err) { if (commander.watch) { diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js new file mode 100644 index 0000000000..13257ec5e8 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js @@ -0,0 +1 @@ +console.log(process.argv[2]); diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/options.json b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json new file mode 100644 index 0000000000..5aa934d555 --- /dev/null +++ b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json @@ -0,0 +1,4 @@ +{ + "args": ["bar", "foo"], + "stdout": "foo" +} diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js index cd0326f68f..5ab4d85cee 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps inline/out-files/script3.js @@ -11,4 +11,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7OztBQ0FOLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map index 6dc6dd4027..cd5df70d02 100644 --- a/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map +++ b/packages/babel-cli/test/fixtures/babel/filenames --out-file --source-maps/out-files/script3.js.map @@ -1 +1 @@ -{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,I;;;;;;ACAN,IAAI,GAAJ,CAAQ;AAAA,SAAK,IAAI,UAAT;AAAA,CAAR","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,I;;;;;ACAN,IAAI,GAAJ,CAAQ;AAAA,SAAK,IAAI,UAAT;AAAA,CAAR","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]} diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index 61cb19aed9..c2bda15c4c 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -1,50 +1,53 @@ -let readdir = require("fs-readdir-recursive"); -let helper = require("babel-helper-fixtures"); -let assert = require("assert"); -let rimraf = require("rimraf"); -let outputFileSync = require("output-file-sync"); -let child = require("child_process"); -let path = require("path"); -let chai = require("chai"); -let fs = require("fs"); -let _ = require("lodash"); +const includes = require("lodash/includes"); +const readdir = require("fs-readdir-recursive"); +const helper = require("babel-helper-fixtures"); +const assert = require("assert"); +const rimraf = require("rimraf"); +const outputFileSync = require("output-file-sync"); +const child = require("child_process"); +const merge = require("lodash/merge"); +const path = require("path"); +const chai = require("chai"); +const fs = require("fs"); -let fixtureLoc = path.join(__dirname, "fixtures"); -let tmpLoc = path.join(__dirname, "tmp"); +const fixtureLoc = path.join(__dirname, "fixtures"); +const tmpLoc = path.join(__dirname, "tmp"); -let presetLocs = [ +const presetLocs = [ path.join(__dirname, "../../babel-preset-es2015"), - path.join(__dirname, "../../babel-preset-react") + path.join(__dirname, "../../babel-preset-react"), ].join(","); -let pluginLocs = [ +const pluginLocs = [ path.join(__dirname, "/../../babel-plugin-transform-strict-mode"), path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"), ].join(","); -let readDir = function (loc) { - let files = {}; +const readDir = function (loc) { + const files = {}; if (fs.existsSync(loc)) { - _.each(readdir(loc), function (filename) { + readdir(loc).forEach(function (filename) { files[filename] = helper.readFile(path.join(loc, filename)); }); } return files; }; -let saveInFiles = function (files) { - _.each(files, function (content, filename) { +const saveInFiles = function (files) { + Object.keys(files).forEach(function (filename) { + const content = files[filename]; outputFileSync(filename, content); }); }; -let assertTest = function (stdout, stderr, opts) { - let expectStderr = opts.stderr.trim(); +const assertTest = function (stdout, stderr, opts) { + const expectStderr = opts.stderr.trim(); stderr = stderr.trim(); if (opts.stderr) { if (opts.stderrContains) { - assert.ok(_.includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr)); + assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + + " didn't contain " + JSON.stringify(expectStderr)); } else { chai.expect(stderr).to.equal(expectStderr, "stderr didn't match"); } @@ -52,13 +55,14 @@ let assertTest = function (stdout, stderr, opts) { throw new Error("stderr:\n" + stderr); } - let expectStdout = opts.stdout.trim(); + const expectStdout = opts.stdout.trim(); stdout = stdout.trim(); stdout = stdout.replace(/\\/g, "/"); if (opts.stdout) { if (opts.stdoutContains) { - assert.ok(_.includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout)); + assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + + " didn't contain " + JSON.stringify(expectStdout)); } else { chai.expect(stdout).to.equal(expectStdout, "stdout didn't match"); } @@ -66,14 +70,15 @@ let assertTest = function (stdout, stderr, opts) { throw new Error("stdout:\n" + stdout); } - _.each(opts.outFiles, function (expect, filename) { - let actual = helper.readFile(filename); + Object.keys(opts.outFiles, function (filename) { + const expect = opts.outFiles[filename]; + const actual = helper.readFile(filename); chai.expect(actual).to.equal(expect, "out-file " + filename); }); }; -let buildTest = function (binName, testName, opts) { - let binLoc = path.join(__dirname, "../lib", binName); +const buildTest = function (binName, testName, opts) { + const binLoc = path.join(__dirname, "../lib", binName); return function (callback) { clear(); @@ -91,7 +96,7 @@ let buildTest = function (binName, testName, opts) { args = args.concat(opts.args); - let spawn = child.spawn(process.execPath, args); + const spawn = child.spawn(process.execPath, args); let stderr = ""; let stdout = ""; @@ -127,32 +132,32 @@ let buildTest = function (binName, testName, opts) { }; }; -let clear = function () { +const clear = function () { process.chdir(__dirname); if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc); fs.mkdirSync(tmpLoc); process.chdir(tmpLoc); }; -_.each(fs.readdirSync(fixtureLoc), function (binName) { +fs.readdirSync(fixtureLoc).forEach(function (binName) { if (binName[0] === ".") return; - let suiteLoc = path.join(fixtureLoc, binName); + const suiteLoc = path.join(fixtureLoc, binName); describe("bin/" + binName, function () { - _.each(fs.readdirSync(suiteLoc), function (testName) { + fs.readdirSync(suiteLoc).forEach(function (testName) { if (testName[0] === ".") return; - let testLoc = path.join(suiteLoc, testName); + const testLoc = path.join(suiteLoc, testName); - let opts = { - args: [] + const opts = { + args: [], }; - let optionsLoc = path.join(testLoc, "options.json"); - if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc)); + const optionsLoc = path.join(testLoc, "options.json"); + if (fs.existsSync(optionsLoc)) merge(opts, require(optionsLoc)); - _.each(["stdout", "stdin", "stderr"], function (key) { - let loc = path.join(testLoc, key + ".txt"); + ["stdout", "stdin", "stderr"].forEach(function (key) { + const loc = path.join(testLoc, key + ".txt"); if (fs.existsSync(loc)) { opts[key] = helper.readFile(loc); } else { @@ -161,9 +166,9 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) { }); opts.outFiles = readDir(path.join(testLoc, "out-files")); - opts.inFiles = readDir(path.join(testLoc, "in-files")); + opts.inFiles = readDir(path.join(testLoc, "in-files")); - let babelrcLoc = path.join(testLoc, ".babelrc"); + const babelrcLoc = path.join(testLoc, ".babelrc"); if (fs.existsSync(babelrcLoc)) { // copy .babelrc file to tmp directory opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc); diff --git a/packages/babel-code-frame/README.md b/packages/babel-code-frame/README.md index 0257a2da1f..7ef5368d31 100644 --- a/packages/babel-code-frame/README.md +++ b/packages/babel-code-frame/README.md @@ -35,9 +35,26 @@ If the column number is not known, you may pass `null` instead. ## Options -name | type | default | description ------------------------|----------|-----------------|------------------------------------------------------ -highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals -linesAbove | number | 2 | The number of lines to show above the error -linesBelow | number | 3 | The number of lines to show below the error -forceColor | boolean | `false` | Forcibly syntax highlight the code as JavaScript (for non-terminals); overrides highlightCode +### `highlightCode` + +`boolean`, defaults to `false`. + +Toggles syntax highlighting the code as JavaScript for terminals. + +### `linesAbove` + +`number`, defaults to `2`. + +Adjust the number of lines to show above the error. + +### `linesBelow` + +`number`, defaults to `3`. + +Adjust the number of lines to show below the error. + +### `forceColor` + +`boolean`, defaults to `false`. + +Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`. diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json index f480727283..d8ac4d99f0 100644 --- a/packages/babel-code-frame/package.json +++ b/packages/babel-code-frame/package.json @@ -1,6 +1,6 @@ { "name": "babel-code-frame", - "version": "6.20.0", + "version": "7.0.0-alpha.1", "description": "Generate errors that contain a code frame that point to source locations.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -10,6 +10,6 @@ "dependencies": { "chalk": "^1.1.0", "esutils": "^2.0.2", - "js-tokens": "^2.0.0" + "js-tokens": "^3.0.0" } } diff --git a/packages/babel-code-frame/src/index.js b/packages/babel-code-frame/src/index.js index 05637e9e40..5dbf1b8ada 100644 --- a/packages/babel-code-frame/src/index.js +++ b/packages/babel-code-frame/src/index.js @@ -1,4 +1,4 @@ -import jsTokens from "js-tokens"; +import jsTokens, { matchToToken } from "js-tokens"; import esutils from "esutils"; import Chalk from "chalk"; @@ -8,18 +8,18 @@ import Chalk from "chalk"; function getDefs(chalk) { return { - keyword: chalk.cyan, + keyword: chalk.cyan, capitalized: chalk.yellow, - jsx_tag: chalk.yellow, - punctuator: chalk.yellow, + jsx_tag: chalk.yellow, + punctuator: chalk.yellow, // bracket: intentionally omitted. - number: chalk.magenta, - string: chalk.green, - regex: chalk.magenta, - comment: chalk.grey, - invalid: chalk.white.bgRed.bold, - gutter: chalk.grey, - marker: chalk.red.bold, + number: chalk.magenta, + string: chalk.green, + regex: chalk.magenta, + comment: chalk.grey, + invalid: chalk.white.bgRed.bold, + gutter: chalk.grey, + marker: chalk.red.bold, }; } @@ -46,8 +46,8 @@ const BRACKET = /^[()\[\]{}]$/; */ function getTokenType(match) { - let [offset, text] = match.slice(-2); - let token = jsTokens.matchToToken(match); + const [offset, text] = match.slice(-2); + const token = matchToToken(match); if (token.type === "name") { if (esutils.keyword.isReservedWordES6(token.value)) { @@ -79,8 +79,8 @@ function getTokenType(match) { function highlight(defs: Object, text: string) { return text.replace(jsTokens, function (...args) { - let type = getTokenType(args); - let colorize = defs[type]; + const type = getTokenType(args); + const colorize = defs[type]; if (colorize) { return args[0].split(NEWLINE).map((str) => colorize(str)).join("\n"); } else { @@ -101,51 +101,51 @@ export default function ( ): string { colNumber = Math.max(colNumber, 0); - let highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor; + const highlighted = (opts.highlightCode && Chalk.supportsColor) || opts.forceColor; let chalk = Chalk; if (opts.forceColor) { chalk = new Chalk.constructor({ enabled: true }); } - let maybeHighlight = (chalkFn, string) => { + const maybeHighlight = (chalkFn, string) => { return highlighted ? chalkFn(string) : string; }; - let defs = getDefs(chalk); + const defs = getDefs(chalk); if (highlighted) rawLines = highlight(defs, rawLines); - let linesAbove = opts.linesAbove || 2; - let linesBelow = opts.linesBelow || 3; + const linesAbove = opts.linesAbove || 2; + const linesBelow = opts.linesBelow || 3; - let lines = rawLines.split(NEWLINE); + const lines = rawLines.split(NEWLINE); let start = Math.max(lineNumber - (linesAbove + 1), 0); - let end = Math.min(lines.length, lineNumber + linesBelow); + let end = Math.min(lines.length, lineNumber + linesBelow); if (!lineNumber && !colNumber) { start = 0; end = lines.length; } - let numberMaxWidth = String(end).length; + const numberMaxWidth = String(end).length; - let frame = lines.slice(start, end).map((line, index) => { - let number = start + 1 + index; - let paddedNumber = ` ${number}`.slice(-numberMaxWidth); - let gutter = ` ${paddedNumber} | `; + const frame = lines.slice(start, end).map((line, index) => { + const number = start + 1 + index; + const paddedNumber = ` ${number}`.slice(-numberMaxWidth); + const gutter = ` ${paddedNumber} | `; if (number === lineNumber) { let markerLine = ""; if (colNumber) { - let markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " "); + const markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " "); markerLine = [ "\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, - maybeHighlight(defs.marker, "^") + maybeHighlight(defs.marker, "^"), ].join(""); } return [ maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, - markerLine + markerLine, ].join(""); } else { return ` ${maybeHighlight(defs.gutter, gutter)}${line}`; diff --git a/packages/babel-code-frame/test/index.js b/packages/babel-code-frame/test/index.js index c85d59ddec..fa1455c496 100644 --- a/packages/babel-code-frame/test/index.js +++ b/packages/babel-code-frame/test/index.js @@ -1,6 +1,6 @@ -let assert = require("assert"); -let chalk = require("chalk"); -let codeFrame = require(".."); +import assert from "assert"; +import chalk from "chalk"; +import codeFrame from ".."; describe("babel-code-frame", function () { it("basic usage", function () { @@ -55,7 +55,7 @@ describe("babel-code-frame", function () { "", "function sum(a, b) {", " return a + b", - "}" + "}", ].join("\n"); assert.equal(codeFrame(rawLines, 7, 2), [ " 5 | * @param b Number", @@ -80,7 +80,7 @@ describe("babel-code-frame", function () { "", "function sum(a, b) {", " return a + b", - "}" + "}", ].join("\n"); assert.equal(codeFrame(rawLines, 6, 2), [ " 4 | * @param a Number", @@ -109,7 +109,7 @@ describe("babel-code-frame", function () { it("opts.highlightCode", function () { const rawLines = "console.log('babel')"; - const result = codeFrame(rawLines, 1, 9, {highlightCode: true}); + const result = codeFrame(rawLines, 1, 9, { highlightCode: true }); const stripped = chalk.stripColor(result); assert.ok(result.length > stripped.length); assert.equal(stripped, [ @@ -119,7 +119,7 @@ describe("babel-code-frame", function () { }); it("opts.linesAbove", function () { - let rawLines = [ + const rawLines = [ "/**", " * Sums two numbers.", " *", @@ -130,7 +130,7 @@ describe("babel-code-frame", function () { "", "function sum(a, b) {", " return a + b", - "}" + "}", ].join("\n"); assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1 }), [ " 6 | * @returns Number", @@ -143,7 +143,7 @@ describe("babel-code-frame", function () { }); it("opts.linesBelow", function () { - let rawLines = [ + const rawLines = [ "/**", " * Sums two numbers.", " *", @@ -154,19 +154,19 @@ describe("babel-code-frame", function () { "", "function sum(a, b) {", " return a + b", - "}" + "}", ].join("\n"); assert.equal(codeFrame(rawLines, 7, 2, { linesBelow: 1 }), [ " 5 | * @param b Number", " 6 | * @returns Number", "> 7 | */", " | ^", - " 8 | " + " 8 | ", ].join("\n")); }); it("opts.linesAbove and opts.linesBelow", function () { - let rawLines = [ + const rawLines = [ "/**", " * Sums two numbers.", " *", @@ -177,30 +177,32 @@ describe("babel-code-frame", function () { "", "function sum(a, b) {", " return a + b", - "}" + "}", ].join("\n"); assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1, linesBelow: 1 }), [ " 6 | * @returns Number", "> 7 | */", " | ^", - " 8 | " + " 8 | ", ].join("\n")); }); it("opts.forceColor", function() { - let marker = chalk.red.bold; - let gutter = chalk.grey; + const marker = chalk.red.bold; + const gutter = chalk.grey; - let rawLines = [ + const rawLines = [ + "", "", "", "", - "" ].join("\n"); - assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }), chalk.reset([ - " " + gutter(" 2 | "), - marker(">") + gutter(" 3 | "), - " " + gutter(" 4 | ") - ].join("\n"))); + assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }), + chalk.reset([ + " " + gutter(" 2 | "), + marker(">") + gutter(" 3 | "), + " " + gutter(" 4 | "), + ].join("\n")) + ); }); }); diff --git a/packages/babel-core/README.md b/packages/babel-core/README.md index 3db09945ec..5b2f4d53d1 100644 --- a/packages/babel-core/README.md +++ b/packages/babel-core/README.md @@ -9,7 +9,9 @@ import { transform } from 'babel-core'; import * as babel from 'babel-core'; ``` -## babel.transform(code: string, [options?](/docs/usage/api/#options): Object) +All transformations will use your local configuration files (.babelrc or in package.json). See [options](#options) to disable it. + +## babel.transform(code: string, [options?](#options): Object) Transforms the passed in `code`. Returning an object with the generated code, source map, and AST. @@ -27,7 +29,7 @@ result.map; result.ast; ``` -## babel.transformFile(filename: string, [options?](/docs/usage/api/#options): Object, callback: Function) +## babel.transformFile(filename: string, [options?](#options): Object, callback: Function) Asynchronously transforms the entire contents of a file. @@ -43,7 +45,7 @@ babel.transformFile("filename.js", options, function (err, result) { }); ``` -## babel.transformFileSync(filename: string, [options?](/docs/usage/api/#options): Object) +## babel.transformFileSync(filename: string, [options?](#options): Object) Synchronous version of `babel.transformFile`. Returns the transformed contents of the `filename`. @@ -58,7 +60,7 @@ babel.transformFileSync(filename, options) // => { code, map, ast } babel.transformFileSync("filename.js", options).code; ``` -## babel.transformFromAst(ast: Object, code?: string, [options?](/docs/usage/api/#options): Object) +## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object) Given, an [AST](https://astexplorer.net/), transform it. @@ -84,34 +86,36 @@ Following is a table of the options you can use: | Option | Default | Description | | ------------------------ | -------------------- | ------------------------------- | +| `ast` | `true` | Include the AST in the returned object | +| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code. | +| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code. | +| `babelrc` | `true` | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/usage/cli/#babel-ignoring-babelrc). | +| `code` | `true` | Enable code generation | +| `comments` | `true` | Output comments in generated output. | +| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB. | +| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the environment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` | +| `extends` | `null` | A path to an `.babelrc` file to extend | | `filename` | `"unknown"` | Filename for use in errors etc. | | `filenameRelative` | `(filename)` | Filename relative to `sourceRoot`. | -| `presets` | `[]` | List of [presets](/docs/plugins/#presets) (a set of plugins) to load and use. | -| `plugins` | `[]` | List of [plugins](/docs/plugins/) to load and use. | -| `parserOpts` | `{}` | An object containing the options to be passed down to the babel parser, babylon | | `generatorOpts` | `{}` | An object containing the options to be passed down to the babel code generator, babel-generator | -| `highlightCode` | `true` | ANSI highlight syntax error code frames | -| `only` | `null` | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim. | -| `ignore` | `null` | Opposite to the `only` option. `ignore` is disregarded if `only` is specified. | -| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code. | -| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code. | -| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. | -| `inputSourceMap` | `null` | A source map object that the output source map will be based on. | -| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map. | -| `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map. | -| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative. | -| `moduleRoot` | `(sourceRoot)` | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. | -| `moduleIds` | `false` | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) | -| `moduleId` | `null` | Specify a custom name for module ids. | | `getModuleId` | `null` | Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used. | -| `resolveModuleSource` | `null` | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)`. | -| `code` | `true` | Enable code generation | -| `no-babelrc` | [CLI flag](http://babeljs.io/docs/usage/cli/#ignoring-babelrc) | Specify whether or not to use .babelrc and .babelignore files. Only available when using the CLI. | -| `ast` | `true` | Include the AST in the returned object | -| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB. | +| `highlightCode` | `true` | ANSI highlight syntax error code frames | +| `ignore` | `null` | Opposite to the `only` option. `ignore` is disregarded if `only` is specified. | +| `inputSourceMap` | `null` | A source map object that the output source map will be based on. | | `minified` | `false` | Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe) | -| `comments` | `true` | Output comments in generated output. | -| `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used. | -| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the enviroment variable `BABEL_ENV` is set to `"production"`. If `BABEL_ENV` isn't set then `NODE_ENV` will be used, if it's not set then it defaults to `"development"` | +| `moduleId` | `null` | Specify a custom name for module ids. | +| `moduleIds` | `false` | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) | +| `moduleRoot` | `(sourceRoot)` | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions. | +| `only` | `null` | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim. | +| `parserOpts` | `{}` | An object containing the options to be passed down to the babel parser, babylon | +| `plugins` | `[]` | List of [plugins](/docs/plugins/) to load and use. | +| `presets` | `[]` | List of [presets](/docs/plugins/#presets) (a set of plugins) to load and use. | | `retainLines` | `false` | Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE:** This will not retain the columns) | -| `extends` | `null` | A path to an `.babelrc` file to extend | +| `resolveModuleSource` | `null` | Resolve a module source ie. `import "SOURCE";` to a custom value. Called as `resolveModuleSource(source, filename)`. | +| `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used. | +| `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map. | +| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. | +| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map. | +| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative. | +| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be either "script" or "module". | +| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`. diff --git a/packages/babel-core/index.js b/packages/babel-core/index.js index e8f04775a2..07edf9757c 100644 --- a/packages/babel-core/index.js +++ b/packages/babel-core/index.js @@ -1 +1 @@ -module.exports = require("./lib/api/node.js"); +module.exports = require("./lib/index.js"); diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index cff80e6a2d..0c99b59385 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -1,6 +1,6 @@ { "name": "babel-core", - "version": "6.21.0", + "version": "7.0.0-alpha.2", "description": "Babel compiler core.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -18,36 +18,36 @@ "transpile", "transpiler", "var", - "babel-core" + "babel-core", + "compiler" ], "scripts": { "bench": "make bench", "test": "make test" }, "dependencies": { - "babel-code-frame": "^6.20.0", - "babel-generator": "^6.21.0", - "babel-helpers": "^6.16.0", - "babel-messages": "^6.8.0", - "babel-template": "^6.16.0", - "babel-runtime": "^6.20.0", - "babel-register": "^6.18.0", - "babel-traverse": "^6.21.0", - "babel-types": "^6.21.0", - "babylon": "^6.11.0", + "babel-code-frame": "7.0.0-alpha.1", + "babel-generator": "7.0.0-alpha.1", + "babel-helpers": "7.0.0-alpha.1", + "babel-messages": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "babel-register": "7.0.0-alpha.2", + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babylon": "7.0.0-beta.4", "convert-source-map": "^1.1.0", "debug": "^2.1.1", "json5": "^0.5.0", "lodash": "^4.2.0", "minimatch": "^3.0.2", - "path-is-absolute": "^1.0.0", "private": "^0.1.6", + "resolve": "^1.3.2", "slash": "^1.0.0", "source-map": "^0.5.0" }, "devDependencies": { - "babel-helper-fixtures": "^6.20.0", - "babel-helper-transform-fixture-test-runner": "^6.21.0", - "babel-polyfill": "^6.20.0" + "babel-helper-fixtures": "7.0.0-alpha.1", + "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.2", + "babel-polyfill": "7.0.0-alpha.1" } } diff --git a/packages/babel-core/register.js b/packages/babel-core/register.js index 97d35f276e..2f32d9baaf 100644 --- a/packages/babel-core/register.js +++ b/packages/babel-core/register.js @@ -1,3 +1 @@ -/* eslint max-len: 0 */ -// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`"); -module.exports = require("babel-register"); +throw new Error("`babel-core/register` has been moved to `babel-register`."); diff --git a/packages/babel-core/src/api/browser.js b/packages/babel-core/src/api/browser.js deleted file mode 100644 index 1c53951acf..0000000000 --- a/packages/babel-core/src/api/browser.js +++ /dev/null @@ -1,112 +0,0 @@ -/* eslint max-len: 0 */ -/* eslint no-new-func: 0 */ - -import { transform } from "./node"; -export { - File, - options, - buildExternalHelpers, - template, - version, - util, - messages, - types, - traverse, - OptionManager, - Plugin, - Pipeline, - analyse, - transform, - transformFromAst, - transformFile, - transformFileSync -} from "./node"; - -export function run(code: string, opts: Object = {}): any { - return new Function(transform(code, opts).code)(); -} - -export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) { - opts.filename = opts.filename || url; - - let xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest(); - xhr.open("GET", url, true); - if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain"); - - xhr.onreadystatechange = function () { - if (xhr.readyState !== 4) return; - - let status = xhr.status; - if (status === 0 || status === 200) { - let param = [xhr.responseText, opts]; - if (!hold) run(param); - if (callback) callback(param); - } else { - throw new Error(`Could not load ${url}`); - } - }; - - xhr.send(null); -} - -function runScripts() { - let scripts: Array | Object> = []; - let types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"]; - let index = 0; - - /** - * Transform and execute script. Ensures correct load order. - */ - - function exec() { - let param = scripts[index]; - if (param instanceof Array) { - run(param, index); - index++; - exec(); - } - } - - /** - * Load, transform, and execute all scripts. - */ - - function run(script: Object, i: number) { - let opts = {}; - - if (script.src) { - load(script.src, function (param) { - scripts[i] = param; - exec(); - }, opts, true); - } else { - opts.filename = "embedded"; - scripts[i] = [script.innerHTML, opts]; - } - } - - // Collect scripts with Babel `types`. - - let _scripts = global.document.getElementsByTagName("script"); - - for (let i = 0; i < _scripts.length; ++i) { - let _script = _scripts[i]; - if (types.indexOf(_script.type) >= 0) scripts.push(_script); - } - - for (let i = 0; i < scripts.length; i++) { - run(scripts[i], i); - } - - exec(); -} - -/** - * Register load event to transform and execute scripts. - */ - -if (global.addEventListener) { - global.addEventListener("DOMContentLoaded", runScripts, false); -} else if (global.attachEvent) { - global.attachEvent("onload", runScripts); -} diff --git a/packages/babel-core/src/helpers/get-possible-plugin-names.js b/packages/babel-core/src/helpers/get-possible-plugin-names.js new file mode 100644 index 0000000000..9aa95920a8 --- /dev/null +++ b/packages/babel-core/src/helpers/get-possible-plugin-names.js @@ -0,0 +1,3 @@ +export default function getPossiblePluginNames(pluginName: string): Array { + return [`babel-plugin-${pluginName}`, pluginName]; +} diff --git a/packages/babel-core/src/helpers/get-possible-preset-names.js b/packages/babel-core/src/helpers/get-possible-preset-names.js new file mode 100644 index 0000000000..a2140b9887 --- /dev/null +++ b/packages/babel-core/src/helpers/get-possible-preset-names.js @@ -0,0 +1,13 @@ +export default function getPossiblePresetNames(presetName: string): Array { + const possibleNames = [`babel-preset-${presetName}`, presetName]; + + // trying to resolve @organization shortcat + // @foo/es2015 -> @foo/babel-preset-es2015 + const matches = presetName.match(/^(@[^/]+)\/(.+)$/); + if (matches) { + const [, orgName, presetPath] = matches; + possibleNames.push(`${orgName}/babel-preset-${presetPath}`); + } + + return possibleNames; +} diff --git a/packages/babel-core/src/helpers/merge.js b/packages/babel-core/src/helpers/merge.js index 5a695f6afa..1a01e22889 100644 --- a/packages/babel-core/src/helpers/merge.js +++ b/packages/babel-core/src/helpers/merge.js @@ -5,9 +5,9 @@ export default function (dest?: Object, src?: Object): ?Object { return mergeWith(dest, src, function (a, b) { if (b && Array.isArray(a)) { - let newArray = b.slice(0); + const newArray = b.slice(0); - for (let item of a) { + for (const item of a) { if (newArray.indexOf(item) < 0) { newArray.push(item); } diff --git a/packages/babel-core/src/helpers/resolve-from-possible-names.js b/packages/babel-core/src/helpers/resolve-from-possible-names.js new file mode 100644 index 0000000000..e7a34adf01 --- /dev/null +++ b/packages/babel-core/src/helpers/resolve-from-possible-names.js @@ -0,0 +1,5 @@ +import resolve from "./resolve"; + +export default function resolveFromPossibleNames(possibleNames: Array, dirname: string): ?string { + return possibleNames.reduce((accum, curr) => accum || resolve(curr, dirname), null); +} diff --git a/packages/babel-core/src/helpers/resolve-plugin.js b/packages/babel-core/src/helpers/resolve-plugin.js new file mode 100644 index 0000000000..65aba0138b --- /dev/null +++ b/packages/babel-core/src/helpers/resolve-plugin.js @@ -0,0 +1,6 @@ +import resolveFromPossibleNames from "./resolve-from-possible-names"; +import getPossiblePluginNames from "./get-possible-plugin-names"; + +export default function resolvePlugin(pluginName: string, dirname: string = process.cwd()): ?string { + return resolveFromPossibleNames(getPossiblePluginNames(pluginName), dirname); +} diff --git a/packages/babel-core/src/helpers/resolve-preset.js b/packages/babel-core/src/helpers/resolve-preset.js new file mode 100644 index 0000000000..417aaf9a01 --- /dev/null +++ b/packages/babel-core/src/helpers/resolve-preset.js @@ -0,0 +1,6 @@ +import resolveFromPossibleNames from "./resolve-from-possible-names"; +import getPossiblePresetNames from "./get-possible-preset-names"; + +export default function resolvePreset(presetName: string, dirname: string = process.cwd()): ?string { + return resolveFromPossibleNames(getPossiblePresetNames(presetName), dirname); +} diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/helpers/resolve.js index 623a910cbf..f0c6b27f81 100644 --- a/packages/babel-core/src/helpers/resolve.js +++ b/packages/babel-core/src/helpers/resolve.js @@ -1,33 +1,8 @@ -import Module from "module"; -import path from "path"; - -let relativeModules = {}; +import resolve from "resolve"; export default function (loc: string, relative: string = process.cwd()): ?string { - // we're in the browser, probably - if (typeof Module === "object") return null; - - let relativeMod = relativeModules[relative]; - - if (!relativeMod) { - relativeMod = new Module; - - // We need to define an id and filename on our "fake" relative` module so that - // Node knows what "." means in the case of us trying to resolve a plugin - // such as "./myPlugins/somePlugin.js". If we don't specify id and filename here, - // Node presumes "." is process.cwd(), not our relative path. - // Since this fake module is never "loaded", we don't have to worry about mutating - // any global Node module cache state here. - let filename = path.join(relative, ".babelrc"); - relativeMod.id = filename; - relativeMod.filename = filename; - - relativeMod.paths = Module._nodeModulePaths(relative); - relativeModules[relative] = relativeMod; - } - try { - return Module._resolveFilename(loc, relativeMod); + return resolve.sync(loc, { basedir: relative }); } catch (err) { return null; } diff --git a/packages/babel-core/src/api/node.js b/packages/babel-core/src/index.js similarity index 58% rename from packages/babel-core/src/api/node.js rename to packages/babel-core/src/index.js index 72492e95a5..1efc832d1f 100644 --- a/packages/babel-core/src/api/node.js +++ b/packages/babel-core/src/index.js @@ -1,13 +1,14 @@ -import isFunction from "lodash/isFunction"; import fs from "fs"; -export { default as File } from "../transformation/file"; -export { default as options } from "../transformation/file/options/config"; -export { default as buildExternalHelpers } from "../tools/build-external-helpers"; +export { default as File } from "./transformation/file"; +export { default as options } from "./transformation/file/options/config"; +export { default as buildExternalHelpers } from "./tools/build-external-helpers"; export { default as template } from "babel-template"; -export { version } from "../../package"; +export { default as resolvePlugin } from "./helpers/resolve-plugin"; +export { default as resolvePreset } from "./helpers/resolve-preset"; +export { version } from "../package"; -import * as util from "../util"; +import * as util from "./util"; export { util }; import * as messages from "babel-messages"; @@ -19,23 +20,18 @@ export { t as types }; import traverse from "babel-traverse"; export { traverse }; -import OptionManager from "../transformation/file/options/option-manager"; +import OptionManager from "./transformation/file/options/option-manager"; export { OptionManager }; export function Plugin(alias) { throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`); } -import Pipeline from "../transformation/pipeline"; -export { Pipeline }; - -let pipeline = new Pipeline; -export let analyse = pipeline.analyse.bind(pipeline); -export let transform = pipeline.transform.bind(pipeline); -export let transformFromAst = pipeline.transformFromAst.bind(pipeline); +import { transform, analyse, transformFromAst } from "./transformation/pipeline"; +export { transform, analyse, transformFromAst }; export function transformFile(filename: string, opts?: Object, callback: Function) { - if (isFunction(opts)) { + if (typeof opts === "function") { callback = opts; opts = {}; } diff --git a/packages/babel-core/src/store.js b/packages/babel-core/src/store.js index fab3d10f34..7f2f4db6e2 100644 --- a/packages/babel-core/src/store.js +++ b/packages/babel-core/src/store.js @@ -1,22 +1,24 @@ -export default class Store extends Map { +export default class Store { constructor() { - super(); - this.dynamicData = {}; + this._map = new Map(); + this._map.dynamicData = {}; } - dynamicData: Object; - setDynamic(key, fn) { - this.dynamicData[key] = fn; + this._map.dynamicData[key] = fn; + } + + set(key: string, val) { + this._map.set(key, val); } get(key: string): any { - if (this.has(key)) { - return super.get(key); + if (this._map.has(key)) { + return this._map.get(key); } else { - if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) { - let val = this.dynamicData[key](); - this.set(key, val); + if (Object.prototype.hasOwnProperty.call(this._map.dynamicData, key)) { + const val = this._map.dynamicData[key](); + this._map.set(key, val); return val; } } diff --git a/packages/babel-core/src/tools/build-external-helpers.js b/packages/babel-core/src/tools/build-external-helpers.js index a26febd34b..75a00f0fff 100644 --- a/packages/babel-core/src/tools/build-external-helpers.js +++ b/packages/babel-core/src/tools/build-external-helpers.js @@ -1,13 +1,10 @@ -/* eslint max-len: 0 */ - import * as helpers from "babel-helpers"; import generator from "babel-generator"; import * as messages from "babel-messages"; import template from "babel-template"; -import each from "lodash/each"; import * as t from "babel-types"; -let buildUmdWrapper = template(` +const buildUmdWrapper = template(` (function (root, factory) { if (typeof define === "function" && define.amd) { define(AMD_ARGUMENTS, factory); @@ -22,15 +19,17 @@ let buildUmdWrapper = template(` `); function buildGlobal(namespace, builder) { - let body = []; - let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); - let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]); + const body = []; + const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); + const tree = t.program([ + t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]); body.push(t.variableDeclaration("var", [ t.variableDeclarator( namespace, - t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])) - ) + t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), + t.objectExpression([])) + ), ])); builder(body); @@ -39,9 +38,9 @@ function buildGlobal(namespace, builder) { } function buildUmd(namespace, builder) { - let body = []; + const body = []; body.push(t.variableDeclaration("var", [ - t.variableDeclarator(namespace, t.identifier("global")) + t.variableDeclarator(namespace, t.identifier("global")), ])); builder(body); @@ -49,23 +48,23 @@ function buildUmd(namespace, builder) { return t.program([ buildUmdWrapper({ FACTORY_PARAMETERS: t.identifier("global"), - BROWSER_ARGUMENTS: t.assignmentExpression( + BROWSER_ARGUMENTS: t.assignmentExpression( "=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression([]) ), - COMMON_ARGUMENTS: t.identifier("exports"), - AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]), - FACTORY_BODY: body, - UMD_ROOT: t.identifier("this") - }) + COMMON_ARGUMENTS: t.identifier("exports"), + AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]), + FACTORY_BODY: body, + UMD_ROOT: t.identifier("this"), + }), ]); } function buildVar(namespace, builder) { - let body = []; + const body = []; body.push(t.variableDeclaration("var", [ - t.variableDeclarator(namespace, t.objectExpression([])) + t.variableDeclarator(namespace, t.objectExpression([])), ])); builder(body); body.push(t.expressionStatement(namespace)); @@ -73,10 +72,10 @@ function buildVar(namespace, builder) { } function buildHelpers(body, namespace, whitelist) { - each(helpers.list, function (name) { + helpers.list.forEach(function (name) { if (whitelist && whitelist.indexOf(name) < 0) return; - let key = t.identifier(name); + const key = t.identifier(name); body.push(t.expressionStatement( t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name)) )); @@ -86,18 +85,18 @@ export default function ( whitelist?: Array, outputType: "global" | "umd" | "var" = "global", ) { - let namespace = t.identifier("babelHelpers"); + const namespace = t.identifier("babelHelpers"); - let builder = function (body) { + const builder = function (body) { return buildHelpers(body, namespace, whitelist); }; let tree; - let build = { + const build = { global: buildGlobal, - umd: buildUmd, - var: buildVar, + umd: buildUmd, + var: buildVar, }[outputType]; if (build) { diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 01d5b7efc9..f11e750303 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -1,11 +1,9 @@ /* global BabelFileResult, BabelParserOptions, BabelFileMetadata */ -/* eslint max-len: 0 */ import getHelper from "babel-helpers"; import * as metadataVisitor from "./metadata"; import convertSourceMap from "convert-source-map"; import OptionManager from "./options/option-manager"; -import type Pipeline from "../pipeline"; import PluginPass from "../plugin-pass"; import { NodePath, Hub, Scope } from "babel-traverse"; import sourceMap from "source-map"; @@ -16,7 +14,7 @@ import traverse from "babel-traverse"; import Logger from "./logger"; import Store from "../../store"; import { parse } from "babylon"; -import * as util from "../../util"; +import * as util from "../../util"; import path from "path"; import * as t from "babel-types"; @@ -29,50 +27,48 @@ const shebangRegex = /^#!.*/; const INTERNAL_PLUGINS = [ [blockHoistPlugin], - [shadowFunctionsPlugin] + [shadowFunctionsPlugin], ]; -let errorVisitor = { +const errorVisitor = { enter(path, state) { - let loc = path.node.loc; + const loc = path.node.loc; if (loc) { state.loc = loc; path.stop(); } - } + }, }; export default class File extends Store { - constructor(opts: Object = {}, pipeline: Pipeline) { + constructor(opts: Object = {}) { super(); - this.pipeline = pipeline; + this.log = new Logger(this, opts.filename || "unknown"); - this.log = new Logger(this, opts.filename || "unknown"); - this.opts = this.initOptions(opts); + opts = this.initOptions(opts); + + let passes = []; + if (opts.plugins) passes.push(opts.plugins); + + // With "passPerPreset" enabled there may still be presets in the options. + if (opts.presets) passes = passes.concat(opts.presets.map((preset) => preset.plugins).filter(Boolean)); + + this.pluginPasses = passes; + this.opts = opts; this.parserOpts = { - sourceType: this.opts.sourceType, + sourceType: this.opts.sourceType, sourceFileName: this.opts.filename, - plugins: [] + plugins: [], }; - this.pluginVisitors = []; - this.pluginPasses = []; - - // Plugins for top-level options. - this.buildPluginsForOptions(this.opts); - - // If we are in the "pass per preset" mode, build - // also plugins for each preset. - if (this.opts.passPerPreset) { - // All the "per preset" options are inherited from the main options. - this.perPresetOpts = []; - this.opts.presets.forEach((presetOpts) => { - let perPresetOpts = Object.assign(Object.create(this.opts), presetOpts); - this.perPresetOpts.push(perPresetOpts); - this.buildPluginsForOptions(perPresetOpts); - }); + for (const pluginPairs of passes) { + for (const [ plugin ] of pluginPairs) { + if (plugin.manipulateOptions) { + plugin.manipulateOptions(opts, this.parserOpts, this); + } + } } this.metadata = { @@ -82,21 +78,21 @@ export default class File extends Store { imports: [], exports: { exported: [], - specifiers: [] - } - } + specifiers: [], + }, + }, }; this.dynamicImportTypes = {}; - this.dynamicImportIds = {}; - this.dynamicImports = []; - this.declarations = {}; - this.usedHelpers = {}; + this.dynamicImportIds = {}; + this.dynamicImports = []; + this.declarations = {}; + this.usedHelpers = {}; this.path = null; - this.ast = {}; + this.ast = {}; - this.code = ""; + this.code = ""; this.shebang = ""; this.hub = new Hub(this); @@ -104,9 +100,7 @@ export default class File extends Store { static helpers: Array; - pluginVisitors: Array; - pluginPasses: Array; - pipeline: Pipeline; + pluginPasses: Array>; parserOpts: BabelParserOptions; log: Logger; opts: Object; @@ -125,7 +119,7 @@ export default class File extends Store { getMetadata() { let has = false; - for (let node of (this.ast.program.body: Array)) { + for (const node of (this.ast.program.body: Array)) { if (t.isModuleDeclaration(node)) { has = true; break; @@ -137,7 +131,7 @@ export default class File extends Store { } initOptions(opts) { - opts = new OptionManager(this.log, this.pipeline).init(opts); + opts = this.log.wrap(() => new OptionManager().init(opts)); if (opts.inputSourceMap) { opts.sourceMaps = true; @@ -154,54 +148,29 @@ export default class File extends Store { if (opts.only) opts.only = util.arrayify(opts.only, util.regexify); defaults(opts, { - moduleRoot: opts.sourceRoot + moduleRoot: opts.sourceRoot, }); defaults(opts, { - sourceRoot: opts.moduleRoot + sourceRoot: opts.moduleRoot, }); defaults(opts, { - filenameRelative: opts.filename + filenameRelative: opts.filename, }); - let basenameRelative = path.basename(opts.filenameRelative); + const basenameRelative = path.basename(opts.filenameRelative); defaults(opts, { - sourceFileName: basenameRelative, - sourceMapTarget: basenameRelative + sourceFileName: basenameRelative, + sourceMapTarget: basenameRelative, }); return opts; } - buildPluginsForOptions(opts) { - if (!Array.isArray(opts.plugins)) { - return; - } - - let plugins: Array<[PluginPass, Object]> = opts.plugins.concat(INTERNAL_PLUGINS); - let currentPluginVisitors = []; - let currentPluginPasses = []; - - // init plugins! - for (let ref of plugins) { - let [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug - - currentPluginVisitors.push(plugin.visitor); - currentPluginPasses.push(new PluginPass(this, plugin, pluginOpts)); - - if (plugin.manipulateOptions) { - plugin.manipulateOptions(opts, this.parserOpts, this); - } - } - - this.pluginVisitors.push(currentPluginVisitors); - this.pluginPasses.push(currentPluginPasses); - } - getModuleName(): ?string { - let opts = this.opts; + const opts = this.opts; if (!opts.moduleIds) { return null; } @@ -224,7 +193,7 @@ export default class File extends Store { if (opts.sourceRoot != null) { // remove sourceRoot from filename - let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); + const sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); } @@ -245,20 +214,20 @@ export default class File extends Store { } resolveModuleSource(source: string): string { - let resolveModuleSource = this.opts.resolveModuleSource; + const resolveModuleSource = this.opts.resolveModuleSource; if (resolveModuleSource) source = resolveModuleSource(source, this.opts.filename); return source; } addImport(source: string, imported: string, name?: string = imported): Object { - let alias = `${source}:${imported}`; + const alias = `${source}:${imported}`; let id = this.dynamicImportIds[alias]; if (!id) { source = this.resolveModuleSource(source); id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name); - let specifiers = []; + const specifiers = []; if (imported === "*") { specifiers.push(t.importNamespaceSpecifier(id)); @@ -268,7 +237,7 @@ export default class File extends Store { specifiers.push(t.importSpecifier(id, t.identifier(imported))); } - let declar = t.importDeclaration(specifiers, t.stringLiteral(source)); + const declar = t.importDeclaration(specifiers, t.stringLiteral(source)); declar._blockHoist = 3; this.path.unshiftContainer("body", declar); @@ -278,7 +247,7 @@ export default class File extends Store { } addHelper(name: string): Object { - let declar = this.declarations[name]; + const declar = this.declarations[name]; if (declar) return declar; if (!this.usedHelpers[name]) { @@ -286,17 +255,17 @@ export default class File extends Store { this.usedHelpers[name] = true; } - let generator = this.get("helperGenerator"); - let runtime = this.get("helpersNamespace"); + const generator = this.get("helperGenerator"); + const runtime = this.get("helpersNamespace"); if (generator) { - let res = generator(name); + const res = generator(name); if (res) return res; } else if (runtime) { return t.memberExpression(runtime, t.identifier(name)); } - let ref = getHelper(name); - let uid = this.declarations[name] = this.scope.generateUidIdentifier(name); + const ref = getHelper(name); + const uid = this.declarations[name] = this.scope.generateUidIdentifier(name); if (t.isFunctionExpression(ref) && !ref.id) { ref.body._compact = true; @@ -309,7 +278,7 @@ export default class File extends Store { this.scope.push({ id: uid, init: ref, - unique: true + unique: true, }); } @@ -323,31 +292,31 @@ export default class File extends Store { ): Object { // Generate a unique name based on the string literals so we dedupe // identical strings used in the program. - let stringIds = raw.elements.map(function(string) { + const stringIds = raw.elements.map(function(string) { return string.value; }); - let name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`; + const name = `${helperName}_${raw.elements.length}_${stringIds.join(",")}`; - let declar = this.declarations[name]; + const declar = this.declarations[name]; if (declar) return declar; - let uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject"); + const uid = this.declarations[name] = this.scope.generateUidIdentifier("templateObject"); - let helperId = this.addHelper(helperName); - let init = t.callExpression(helperId, [strings, raw]); + const helperId = this.addHelper(helperName); + const init = t.callExpression(helperId, [strings, raw]); init._compact = true; this.scope.push({ id: uid, init: init, - _blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers + _blockHoist: 1.9, // This ensures that we don't fail if not using function expression helpers }); return uid; } buildCodeFrameError(node: Object, msg: string, Error: typeof Error = SyntaxError): Error { - let loc = node && (node.loc || node._loc); + const loc = node && (node.loc || node._loc); - let err = new Error(msg); + const err = new Error(msg); if (loc) { err.loc = loc.start; @@ -367,26 +336,26 @@ export default class File extends Store { } mergeSourceMap(map: Object) { - let inputMap = this.opts.inputSourceMap; + const inputMap = this.opts.inputSourceMap; if (inputMap) { - let inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap); - let outputMapConsumer = new sourceMap.SourceMapConsumer(map); + const inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap); + const outputMapConsumer = new sourceMap.SourceMapConsumer(map); - let mergedGenerator = new sourceMap.SourceMapGenerator({ + const mergedGenerator = new sourceMap.SourceMapGenerator({ file: inputMapConsumer.file, - sourceRoot: inputMapConsumer.sourceRoot + sourceRoot: inputMapConsumer.sourceRoot, }); - // This assumes the output map always has a single source, since Babel always compiles a single source file to a - // single output file. + // This assumes the output map always has a single source, since Babel always compiles a + // single source file to a single output file. const source = outputMapConsumer.sources[0]; inputMapConsumer.eachMapping(function (mapping) { const generatedPosition = outputMapConsumer.generatedPositionFor({ line: mapping.generatedLine, column: mapping.generatedColumn, - source: source + source: source, }); if (generatedPosition.column != null) { mergedGenerator.addMapping({ @@ -394,15 +363,15 @@ export default class File extends Store { original: mapping.source == null ? null : { line: mapping.originalLine, - column: mapping.originalColumn + column: mapping.originalColumn, }, - generated: generatedPosition + generated: generatedPosition, }); } }); - let mergedMap = mergedGenerator.toJSON(); + const mergedMap = mergedGenerator.toJSON(); inputMap.mappings = mergedMap.mappings; return inputMap; } else { @@ -419,12 +388,13 @@ export default class File extends Store { if (parserOpts.parser) { if (typeof parserOpts.parser === "string") { - let dirname = path.dirname(this.opts.filename) || process.cwd(); - let parser = resolve(parserOpts.parser, dirname); + const dirname = path.dirname(this.opts.filename) || process.cwd(); + const parser = resolve(parserOpts.parser, dirname); if (parser) { parseCode = require(parser).parse; } else { - throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method relative to directory ${dirname}`); + throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method ` + + `relative to directory ${dirname}`); } } else { parseCode = parserOpts.parser; @@ -433,13 +403,13 @@ export default class File extends Store { parserOpts.parser = { parse(source) { return parse(source, parserOpts); - } + }, }; } } this.log.debug("Parse start"); - let ast = parseCode(code, parserOpts || this.parserOpts); + const ast = parseCode(code, parserOpts || this.parserOpts); this.log.debug("Parse stop"); return ast; } @@ -450,10 +420,10 @@ export default class File extends Store { parentPath: null, parent: ast, container: ast, - key: "program" + key: "program", }).setContext(); this.scope = this.path.scope; - this.ast = ast; + this.ast = ast; this.getMetadata(); } @@ -464,19 +434,25 @@ export default class File extends Store { } transform(): BabelFileResult { - // In the "pass per preset" mode, we have grouped passes. - // Otherwise, there is only one plain pluginPasses array. - for (let i = 0; i < this.pluginPasses.length; i++) { - const pluginPasses = this.pluginPasses[i]; - this.call("pre", pluginPasses); + for (const pluginPairs of this.pluginPasses) { + const passes = []; + const visitors = []; + + for (const [ plugin, pluginOpts ] of pluginPairs.concat(INTERNAL_PLUGINS)) { + const pass = new PluginPass(this, plugin, pluginOpts); + passes.push(pass); + visitors.push(plugin.visitor); + } + + this.call("pre", passes); this.log.debug("Start transform traverse"); // merge all plugin visitors into a single visitor - let visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod); + const visitor = traverse.visitors.merge(visitors, passes, this.opts.wrapPluginVisitorMethod); traverse(this.ast, visitor, this.scope); this.log.debug("End transform traverse"); - this.call("post", pluginPasses); + this.call("post", passes); } return this.generate(); @@ -500,7 +476,7 @@ export default class File extends Store { let message = err.message = `${this.opts.filename}: ${err.message}`; - let loc = err.loc; + const loc = err.loc; if (loc) { err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts); message += "\n" + err.codeFrame; @@ -513,7 +489,7 @@ export default class File extends Store { } if (err.stack) { - let newStack = err.stack.replace(err.message, message); + const newStack = err.stack.replace(err.message, message); err.stack = newStack; } @@ -529,28 +505,28 @@ export default class File extends Store { parseCode() { this.parseShebang(); - let ast = this.parse(this.code); + const ast = this.parse(this.code); this.addAst(ast); } shouldIgnore() { - let opts = this.opts; + const opts = this.opts; return util.shouldIgnore(opts.filename, opts.ignore, opts.only); } call(key: "pre" | "post", pluginPasses: Array) { - for (let pass of pluginPasses) { - let plugin = pass.plugin; - let fn = plugin[key]; + for (const pass of pluginPasses) { + const plugin = pass.plugin; + const fn = plugin[key]; if (fn) fn.call(pass, this); } } parseInputSourceMap(code: string): string { - let opts = this.opts; + const opts = this.opts; if (opts.inputSourceMap !== false) { - let inputMap = convertSourceMap.fromSource(code); + const inputMap = convertSourceMap.fromSource(code); if (inputMap) { opts.inputSourceMap = inputMap.toObject(); code = convertSourceMap.removeComments(code); @@ -561,7 +537,7 @@ export default class File extends Store { } parseShebang() { - let shebangMatch = shebangRegex.exec(this.code); + const shebangMatch = shebangRegex.exec(this.code); if (shebangMatch) { this.shebang = shebangMatch[0]; this.code = this.code.replace(shebangRegex, ""); @@ -569,13 +545,13 @@ export default class File extends Store { } makeResult({ code, map, ast, ignored }: BabelFileResult): BabelFileResult { - let result = { + const result = { metadata: null, - options: this.opts, - ignored: !!ignored, - code: null, - ast: null, - map: map || null + options: this.opts, + ignored: !!ignored, + code: null, + ast: null, + map: map || null, }; if (this.opts.code) { @@ -594,10 +570,10 @@ export default class File extends Store { } generate(): BabelFileResult { - let opts = this.opts; - let ast = this.ast; + const opts = this.opts; + const ast = this.ast; - let result: BabelFileResult = { ast }; + const result: BabelFileResult = { ast }; if (!opts.code) return this.makeResult(result); let gen = generate; @@ -605,21 +581,23 @@ export default class File extends Store { gen = opts.generatorOpts.generator; if (typeof gen === "string") { - let dirname = path.dirname(this.opts.filename) || process.cwd(); - let generator = resolve(gen, dirname); + const dirname = path.dirname(this.opts.filename) || process.cwd(); + const generator = resolve(gen, dirname); if (generator) { gen = require(generator).print; } else { - throw new Error(`Couldn't find generator ${gen} with "print" method relative to directory ${dirname}`); + throw new Error(`Couldn't find generator ${gen} with "print" method relative ` + + `to directory ${dirname}`); } } } this.log.debug("Generation start"); - let _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code); + const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, + this.code); result.code = _result.code; - result.map = _result.map; + result.map = _result.map; this.log.debug("Generation end"); diff --git a/packages/babel-core/src/transformation/file/logger.js b/packages/babel-core/src/transformation/file/logger.js index 54aecf60a1..6a9503396a 100644 --- a/packages/babel-core/src/transformation/file/logger.js +++ b/packages/babel-core/src/transformation/file/logger.js @@ -1,15 +1,15 @@ import type File from "./index"; import buildDebug from "debug"; -let verboseDebug = buildDebug("babel:verbose"); -let generalDebug = buildDebug("babel"); +const verboseDebug = buildDebug("babel:verbose"); +const generalDebug = buildDebug("babel"); -let seenDeprecatedMessages = []; +const seenDeprecatedMessages = []; export default class Logger { constructor(file: File, filename: string) { this.filename = filename; - this.file = file; + this.file = file; } filename: string; @@ -21,6 +21,15 @@ export default class Logger { return parts; } + wrap(callback: () => T): T { + try { + return callback(); + } catch (e) { + e.message = this._buildMessage(e.message); + throw e; + } + } + warn(msg: string) { console.warn(this._buildMessage(msg)); } diff --git a/packages/babel-core/src/transformation/file/metadata.js b/packages/babel-core/src/transformation/file/metadata.js index 0183006ffb..5fcb0efa79 100644 --- a/packages/babel-core/src/transformation/file/metadata.js +++ b/packages/babel-core/src/transformation/file/metadata.js @@ -1,45 +1,45 @@ import * as t from "babel-types"; -export let ModuleDeclaration = { +export const ModuleDeclaration = { enter(path, file) { - let { node } = path; + const { node } = path; if (node.source) { node.source.value = file.resolveModuleSource(node.source.value); } - } + }, }; -export let ImportDeclaration = { +export const ImportDeclaration = { exit(path, file) { - let { node } = path; + const { node } = path; - let specifiers = []; - let imported = []; + const specifiers = []; + const imported = []; file.metadata.modules.imports.push({ source: node.source.value, imported, - specifiers + specifiers, }); - for (let specifier of (path.get("specifiers"): Array)) { - let local = specifier.node.local.name; + for (const specifier of (path.get("specifiers"): Array)) { + const local = specifier.node.local.name; if (specifier.isImportDefaultSpecifier()) { imported.push("default"); specifiers.push({ kind: "named", imported: "default", - local + local, }); } if (specifier.isImportSpecifier()) { - let importedName = specifier.node.imported.name; + const importedName = specifier.node.imported.name; imported.push(importedName); specifiers.push({ kind: "named", imported: importedName, - local + local, }); } @@ -47,38 +47,38 @@ export let ImportDeclaration = { imported.push("*"); specifiers.push({ kind: "namespace", - local + local, }); } } - } + }, }; export function ExportDeclaration(path, file) { - let { node } = path; + const { node } = path; - let source = node.source ? node.source.value : null; - let exports = file.metadata.modules.exports; + const source = node.source ? node.source.value : null; + const exports = file.metadata.modules.exports; // export function foo() {} // export let foo = "bar"; - let declar = path.get("declaration"); + const declar = path.get("declaration"); if (declar.isStatement()) { - let bindings = declar.getBindingIdentifiers(); + const bindings = declar.getBindingIdentifiers(); - for (let name in bindings) { + for (const name in bindings) { exports.exported.push(name); exports.specifiers.push({ kind: "local", local: name, - exported: path.isExportDefaultDeclaration() ? "default" : name + exported: path.isExportDefaultDeclaration() ? "default" : name, }); } } if (path.isExportNamedDeclaration() && node.specifiers) { - for (let specifier of (node.specifiers: Array)) { - let exported = specifier.exported.name; + for (const specifier of (node.specifiers: Array)) { + const exported = specifier.exported.name; exports.exported.push(exported); // export foo from "bar"; @@ -87,7 +87,7 @@ export function ExportDeclaration(path, file) { kind: "external", local: exported, exported, - source + source, }); } @@ -96,11 +96,11 @@ export function ExportDeclaration(path, file) { exports.specifiers.push({ kind: "external-namespace", exported, - source + source, }); } - let local = specifier.local; + const local = specifier.local; if (!local) continue; // export { foo } from "bar"; @@ -110,7 +110,7 @@ export function ExportDeclaration(path, file) { kind: "external", local: local.name, exported, - source + source, }); } @@ -120,7 +120,7 @@ export function ExportDeclaration(path, file) { exports.specifiers.push({ kind: "local", local: local.name, - exported + exported, }); } } @@ -130,7 +130,7 @@ export function ExportDeclaration(path, file) { if (path.isExportAllDeclaration()) { exports.specifiers.push({ kind: "external-all", - source + source, }); } } diff --git a/packages/babel-core/src/transformation/file/options/build-config-chain.js b/packages/babel-core/src/transformation/file/options/build-config-chain.js index 02ce737641..a5af4e82ba 100644 --- a/packages/babel-core/src/transformation/file/options/build-config-chain.js +++ b/packages/babel-core/src/transformation/file/options/build-config-chain.js @@ -1,20 +1,18 @@ - -import type Logger from "../logger"; import resolve from "../../../helpers/resolve"; import json5 from "json5"; -import isAbsolute from "path-is-absolute"; import path from "path"; import fs from "fs"; -let existsCache = {}; -let jsonCache = {}; +const existsCache = {}; +const jsonCache = {}; +const BABELRC_FILENAME = ".babelrc"; +const BABELRC_JS_FILENAME = ".babelrc.js"; +const PACKAGE_FILENAME = "package.json"; const BABELIGNORE_FILENAME = ".babelignore"; -const BABELRC_FILENAME = ".babelrc"; -const PACKAGE_FILENAME = "package.json"; function exists(filename) { - let cached = existsCache[filename]; + const cached = existsCache[filename]; if (cached == null) { return existsCache[filename] = fs.existsSync(filename); } else { @@ -22,9 +20,9 @@ function exists(filename) { } } -export default function buildConfigChain(opts: Object = {}, log?: Logger) { - let filename = opts.filename; - let builder = new ConfigChainBuilder(log); +export default function buildConfigChain(opts: Object = {}) { + const filename = opts.filename; + const builder = new ConfigChainBuilder(); // resolve all .babelrc files if (opts.babelrc !== false) { @@ -34,23 +32,27 @@ export default function buildConfigChain(opts: Object = {}, log?: Logger) { builder.mergeConfig({ options: opts, alias: "base", - dirname: filename && path.dirname(filename) + dirname: filename && path.dirname(filename), }); return builder.configs; } class ConfigChainBuilder { - constructor(log?: Logger) { + constructor() { this.resolvedConfigs = []; this.configs = []; - this.log = log; } - findConfigs(loc) { + errorMultipleConfigs(loc1: string, loc2: string) { + throw new Error(`Multiple configuration files found. Please remove one:\n- ${ + loc1}\n- ${loc2}`); + } + + findConfigs(loc: string) { if (!loc) return; - if (!isAbsolute(loc)) { + if (!path.isAbsolute(loc)) { loc = path.join(process.cwd(), loc); } @@ -59,20 +61,31 @@ class ConfigChainBuilder { while (loc !== (loc = path.dirname(loc))) { if (!foundConfig) { - let configLoc = path.join(loc, BABELRC_FILENAME); - if (exists(configLoc)) { - this.addConfig(configLoc); - foundConfig = true; - } + const configLoc = path.join(loc, BABELRC_FILENAME); + const configJSLoc = path.join(loc, BABELRC_JS_FILENAME); + const pkgLoc = path.join(loc, PACKAGE_FILENAME); + const configLocs = [configLoc, configJSLoc, pkgLoc]; + const foundConfigs = configLocs.reduce((arr, config) => { + if (exists(config)) { + const configAdded = config === pkgLoc + ? this.addConfig(config, "babel", JSON) + : this.addConfig(config); - let pkgLoc = path.join(loc, PACKAGE_FILENAME); - if (!foundConfig && exists(pkgLoc)) { - foundConfig = this.addConfig(pkgLoc, "babel", JSON); - } + if (configAdded && arr.length) { + this.errorMultipleConfigs(arr.pop(), config); + } + + arr.push(config); + } + + return arr; + }, []); + + foundConfig = !!foundConfigs.length; } if (!foundIgnore) { - let ignoreLoc = path.join(loc, BABELIGNORE_FILENAME); + const ignoreLoc = path.join(loc, BABELIGNORE_FILENAME); if (exists(ignoreLoc)) { this.addIgnoreConfig(ignoreLoc); foundIgnore = true; @@ -83,8 +96,8 @@ class ConfigChainBuilder { } } - addIgnoreConfig(loc) { - let file = fs.readFileSync(loc, "utf8"); + addIgnoreConfig(loc: string) { + const file = fs.readFileSync(loc, "utf8"); let lines = file.split("\n"); lines = lines @@ -95,7 +108,7 @@ class ConfigChainBuilder { this.mergeConfig({ options: { ignore: lines }, alias: loc, - dirname: path.dirname(loc) + dirname: path.dirname(loc), }); } } @@ -107,21 +120,41 @@ class ConfigChainBuilder { this.resolvedConfigs.push(loc); - let content = fs.readFileSync(loc, "utf8"); let options; + if (path.extname(loc) === ".js") { + try { + const configModule = require(loc); + options = configModule && configModule.__esModule ? configModule.default : configModule; + } catch (err) { + err.message = `${loc}: Error while loading config - ${err.message}`; + throw err; + } - try { - options = jsonCache[content] = jsonCache[content] || json.parse(content); - if (key) options = options[key]; - } catch (err) { - err.message = `${loc}: Error while parsing JSON - ${err.message}`; - throw err; + if (!options || typeof options !== "object") { + throw new Error("Configuration should be an exported JavaScript object."); + } + } else { + const content = fs.readFileSync(loc, "utf8"); + try { + options = jsonCache[content] = jsonCache[content] || json.parse(content); + } catch (err) { + err.message = `${loc}: Error while parsing JSON - ${err.message}`; + throw err; + } + } + + if (key) { + if (!options[key]) { + return false; + } + + options = options[key]; } this.mergeConfig({ options, alias: loc, - dirname: path.dirname(loc) + dirname: path.dirname(loc), }); return !!options; @@ -131,7 +164,7 @@ class ConfigChainBuilder { options, alias, loc, - dirname + dirname, }) { if (!options) { return false; @@ -144,11 +177,11 @@ class ConfigChainBuilder { // add extends clause if (options.extends) { - let extendsLoc = resolve(options.extends, dirname); + const extendsLoc = resolve(options.extends, dirname); if (extendsLoc) { this.addConfig(extendsLoc); } else { - if (this.log) this.log.error(`Couldn't resolve extends clause of ${options.extends} in ${alias}`); + throw new Error(`Couldn't resolve extends clause of ${options.extends} in ${alias}`); } delete options.extends; } @@ -157,12 +190,12 @@ class ConfigChainBuilder { options, alias, loc, - dirname + dirname, }); // env let envOpts; - let envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development"; + const envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development"; if (options.env) { envOpts = options.env[envKey]; delete options.env; @@ -171,7 +204,7 @@ class ConfigChainBuilder { this.mergeConfig({ options: envOpts, alias: `${alias}.env.${envKey}`, - dirname: dirname + dirname: dirname, }); } } diff --git a/packages/babel-core/src/transformation/file/options/config.js b/packages/babel-core/src/transformation/file/options/config.js index 7b11963f38..8c8df2c0c9 100644 --- a/packages/babel-core/src/transformation/file/options/config.js +++ b/packages/babel-core/src/transformation/file/options/config.js @@ -1,195 +1,195 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ -module.exports = { +export default { filename: { type: "filename", description: "filename to use when reading from stdin - this will be used in source-maps, errors etc", default: "unknown", - shorthand: "f" + shorthand: "f", }, filenameRelative: { hidden: true, - type: "string" + type: "string", }, inputSourceMap: { - hidden: true + hidden: true, }, env: { hidden: true, - default: {} + default: {}, }, mode: { description: "", - hidden: true + hidden: true, }, retainLines: { type: "boolean", default: false, - description: "retain line numbers - will result in really ugly code" + description: "retain line numbers - will result in really ugly code", }, highlightCode: { description: "enable/disable ANSI syntax highlighting of code frames (on by default)", type: "boolean", - default: true + default: true, }, suppressDeprecationMessages: { type: "boolean", default: false, - hidden: true + hidden: true, }, presets: { type: "list", description: "", - default: [] + default: [], }, plugins: { type: "list", default: [], - description: "" + description: "", }, ignore: { type: "list", description: "list of glob paths to **not** compile", - default: [] + default: [], }, only: { type: "list", - description: "list of glob paths to **only** compile" + description: "list of glob paths to **only** compile", }, code: { hidden: true, default: true, - type: "boolean" + type: "boolean", }, metadata: { hidden: true, default: true, - type: "boolean" + type: "boolean", }, ast: { hidden: true, default: true, - type: "boolean" + type: "boolean", }, extends: { type: "string", - hidden: true + hidden: true, }, comments: { type: "boolean", default: true, - description: "write comments to generated output (true by default)" + description: "write comments to generated output (true by default)", }, shouldPrintComment: { hidden: true, - description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored" + description: "optional callback to control whether a comment should be inserted, when this is used the comments option is ignored", }, wrapPluginVisitorMethod: { hidden: true, - description: "optional callback to wrap all visitor methods" + description: "optional callback to wrap all visitor methods", }, compact: { type: "booleanString", default: "auto", - description: "do not include superfluous whitespace characters and line terminators [true|false|auto]" + description: "do not include superfluous whitespace characters and line terminators [true|false|auto]", }, minified: { type: "boolean", default: false, - description: "save as much bytes when printing [true|false]" + description: "save as much bytes when printing [true|false]", }, sourceMap: { alias: "sourceMaps", - hidden: true + hidden: true, }, sourceMaps: { type: "booleanString", description: "[true|false|inline]", default: false, - shorthand: "s" + shorthand: "s", }, sourceMapTarget: { type: "string", - description: "set `file` on returned source map" + description: "set `file` on returned source map", }, sourceFileName: { type: "string", - description: "set `sources[0]` on returned source map" + description: "set `sources[0]` on returned source map", }, sourceRoot: { type: "filename", - description: "the root from which all sources are relative" + description: "the root from which all sources are relative", }, babelrc: { description: "Whether or not to look up .babelrc and .babelignore files", type: "boolean", - default: true + default: true, }, sourceType: { description: "", - default: "module" + default: "module", }, auxiliaryCommentBefore: { type: "string", - description: "print a comment before any injected non-user code" + description: "print a comment before any injected non-user code", }, auxiliaryCommentAfter: { type: "string", - description: "print a comment after any injected non-user code" + description: "print a comment after any injected non-user code", }, resolveModuleSource: { - hidden: true + hidden: true, }, getModuleId: { - hidden: true + hidden: true, }, moduleRoot: { type: "filename", - description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions" + description: "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions", }, moduleIds: { type: "boolean", default: false, shorthand: "M", - description: "insert an explicit id for modules" + description: "insert an explicit id for modules", }, moduleId: { description: "specify a custom name for module ids", - type: "string" + type: "string", }, passPerPreset: { @@ -202,12 +202,12 @@ module.exports = { // Deprecate top level parserOpts parserOpts: { description: "Options to pass into the parser, or to change parsers (parserOpts.parser)", - default: false + default: false, }, // Deprecate top level generatorOpts generatorOpts: { description: "Options to pass into the generator, or to change generators (generatorOpts.generator)", - default: false - } + default: false, + }, }; diff --git a/packages/babel-core/src/transformation/file/options/index.js b/packages/babel-core/src/transformation/file/options/index.js index 69792cc65e..c5f8a73c51 100644 --- a/packages/babel-core/src/transformation/file/options/index.js +++ b/packages/babel-core/src/transformation/file/options/index.js @@ -4,7 +4,7 @@ import config from "./config"; export { config }; export function normaliseOptions(options: Object = {}): Object { - for (let key in options) { + for (const key in options) { let val = options[key]; if (val == null) continue; @@ -12,7 +12,7 @@ export function normaliseOptions(options: Object = {}): Object { if (opt && opt.alias) opt = config[opt.alias]; if (!opt) continue; - let parser = parsers[opt.type]; + const parser = parsers[opt.type]; if (parser) val = parser(val); options[key] = val; diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index 1ab1a5badb..762a643784 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -1,11 +1,9 @@ -/* eslint max-len: 0 */ - -import * as context from "../../../api/node"; -import type Logger from "../logger"; +import * as context from "../../../index"; import Plugin from "../../plugin"; import * as messages from "babel-messages"; import { normaliseOptions } from "./index"; -import resolve from "../../../helpers/resolve"; +import resolvePlugin from "../../../helpers/resolve-plugin"; +import resolvePreset from "../../../helpers/resolve-preset"; import cloneDeepWith from "lodash/cloneDeepWith"; import clone from "lodash/clone"; import merge from "../../../helpers/merge"; @@ -36,15 +34,13 @@ type MergeOptions = { }; export default class OptionManager { - constructor(log?: Logger) { + constructor() { this.resolvedConfigs = []; this.options = OptionManager.createBareOptions(); - this.log = log; } resolvedConfigs: Array; options: Object; - log: ?Logger; static memoisedPlugins: Array<{ container: Function; @@ -52,7 +48,7 @@ export default class OptionManager { }>; static memoisePluginContainer(fn, loc, i, alias) { - for (let cache of (OptionManager.memoisedPlugins: Array)) { + for (const cache of (OptionManager.memoisedPlugins: Array)) { if (cache.container === fn) return cache.plugin; } @@ -65,10 +61,10 @@ export default class OptionManager { } if (typeof obj === "object") { - let plugin = new Plugin(obj, alias); + const plugin = new Plugin(obj, alias); OptionManager.memoisedPlugins.push({ container: fn, - plugin: plugin + plugin: plugin, }); return plugin; } else { @@ -77,10 +73,10 @@ export default class OptionManager { } static createBareOptions() { - let opts = {}; + const opts = {}; - for (let key in config) { - let opt = config[key]; + for (const key in config) { + const opt = config[key]; opts[key] = clone(opt.default); } @@ -119,11 +115,11 @@ export default class OptionManager { plugin = val; } - let alias = typeof plugin === "string" ? plugin : `${loc}$${i}`; + const alias = typeof plugin === "string" ? plugin : `${loc}$${i}`; // allow plugins to be specified as strings if (typeof plugin === "string") { - let pluginLoc = resolve(`babel-plugin-${plugin}`, dirname) || resolve(plugin, dirname); + const pluginLoc = resolvePlugin(plugin, dirname); if (pluginLoc) { plugin = require(pluginLoc); } else { @@ -152,18 +148,18 @@ export default class OptionManager { extending: extendingOpts, alias, loc, - dirname + dirname, }: MergeOptions) { alias = alias || "foreign"; if (!rawOpts) return; // if (typeof rawOpts !== "object" || Array.isArray(rawOpts)) { - this.log.error(`Invalid options type for ${alias}`, TypeError); + throw new TypeError(`Invalid options type for ${alias}`); } // - let opts = cloneDeepWith(rawOpts, (val) => { + const opts = cloneDeepWith(rawOpts, (val) => { if (val instanceof Plugin) { return val; } @@ -173,18 +169,18 @@ export default class OptionManager { dirname = dirname || process.cwd(); loc = loc || alias; - for (let key in opts) { - let option = config[key]; + for (const key in opts) { + const option = config[key]; // check for an unknown option - if (!option && this.log) { + if (!option) { if (removed[key]) { - this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError); + throw new ReferenceError(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`); } else { - let unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; - let presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options."; + // eslint-disable-next-line max-len + const unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`; - this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError); + throw new ReferenceError(unknownOptErr); } } } @@ -208,7 +204,7 @@ export default class OptionManager { extending: preset, alias: presetLoc, loc: presetLoc, - dirname: dirname + dirname: dirname, }); }); } else { @@ -238,7 +234,7 @@ export default class OptionManager { options: presetOpts, alias: presetLoc, loc: presetLoc, - dirname: path.dirname(presetLoc || "") + dirname: path.dirname(presetLoc || ""), }); }); } @@ -248,89 +244,77 @@ export default class OptionManager { * or a module name to require. */ resolvePresets(presets: Array, dirname: string, onResolve?) { - return presets.map((val) => { + return presets.map((preset) => { let options; - if (Array.isArray(val)) { - if (val.length > 2) { - throw new Error(`Unexpected extra options ${JSON.stringify(val.slice(2))} passed to preset.`); + if (Array.isArray(preset)) { + if (preset.length > 2) { + throw new Error(`Unexpected extra options ${JSON.stringify(preset.slice(2))} passed to preset.`); } - [val, options] = val; + [preset, options] = preset; } let presetLoc; try { - if (typeof val === "string") { - presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname); - - // trying to resolve @organization shortcat - // @foo/es2015 -> @foo/babel-preset-es2015 - if (!presetLoc) { - let matches = val.match(/^(@[^/]+)\/(.+)$/); - if (matches) { - let [, orgName, presetPath] = matches; - val = `${orgName}/babel-preset-${presetPath}`; - presetLoc = resolve(val, dirname); - } - } + if (typeof preset === "string") { + presetLoc = resolvePreset(preset, dirname); if (!presetLoc) { - throw new Error(`Couldn't find preset ${JSON.stringify(val)} relative to directory ` + + throw new Error(`Couldn't find preset ${JSON.stringify(preset)} relative to directory ` + JSON.stringify(dirname)); } - - val = require(presetLoc); } + const resolvedPreset = this.loadPreset(presetLoc || preset, options, { dirname }); - // If the imported preset is a transpiled ES2015 module - if (typeof val === "object" && val.__esModule) { - // Try to grab the default export. - if (val.default) { - val = val.default; - } else { - // If there is no default export we treat all named exports as options - // and just remove the __esModule. This is to support presets that have been - // exporting named exports in the past, although we definitely want presets to - // only use the default export (with either an object or a function) - const { __esModule, ...rest } = val; // eslint-disable-line no-unused-vars - val = rest; - } - } + if (onResolve) onResolve(resolvedPreset, presetLoc); - // For compatibility with babel-core < 6.13.x, allow presets to export an object with a - // a 'buildPreset' function that will return the preset itself, while still exporting a - // simple object (rather than a function), for supporting old Babel versions. - if (typeof val === "object" && val.buildPreset) val = val.buildPreset; - - - if (typeof val !== "function" && options !== undefined) { - throw new Error(`Options ${JSON.stringify(options)} passed to ` + - (presetLoc || "a preset") + " which does not accept options."); - } - - if (typeof val === "function") val = val(context, options); - - if (typeof val !== "object") { - throw new Error(`Unsupported preset format: ${val}.`); - } - - onResolve && onResolve(val, presetLoc); + return resolvedPreset; } catch (e) { if (presetLoc) { e.message += ` (While processing preset: ${JSON.stringify(presetLoc)})`; } throw e; } - return val; }); } - normaliseOptions() { - let opts = this.options; + /** + * Tries to load one preset. The input is either the module name of the preset, + * a function, or an object + */ + loadPreset(preset, options, meta) { + let presetFactory = preset; + if (typeof presetFactory === "string") { + presetFactory = require(presetFactory); + } - for (let key in config) { - let option = config[key]; - let val = opts[key]; + if (typeof presetFactory === "object" && presetFactory.__esModule) { + if (presetFactory.default) { + presetFactory = presetFactory.default; + } else { + throw new Error("Preset must export a default export when using ES6 modules."); + } + } + + // Allow simple object exports + if (typeof presetFactory === "object") { + return presetFactory; + } + + if (typeof presetFactory !== "function") { + // eslint-disable-next-line max-len + throw new Error(`Unsupported preset format: ${typeof presetFactory}. Expected preset to return a function.`); + } + + return presetFactory(context, options, meta); + } + + normaliseOptions() { + const opts = this.options; + + for (const key in config) { + const option = config[key]; + const val = opts[key]; // optional if (!val && option.optional) continue; @@ -345,7 +329,7 @@ export default class OptionManager { } init(opts: Object = {}): Object { - for (let config of buildConfigChain(opts, this.log)) { + for (const config of buildConfigChain(opts)) { this.mergeOptions(config); } diff --git a/packages/babel-core/src/transformation/file/options/parsers.js b/packages/babel-core/src/transformation/file/options/parsers.js index fa8dbae260..2dcf5b7a71 100644 --- a/packages/babel-core/src/transformation/file/options/parsers.js +++ b/packages/babel-core/src/transformation/file/options/parsers.js @@ -1,7 +1,7 @@ import slash from "slash"; import * as util from "../../../util"; -export let filename = slash; +export const filename = slash; export function boolean(val: any): boolean { return !!val; diff --git a/packages/babel-core/src/transformation/file/options/removed.js b/packages/babel-core/src/transformation/file/options/removed.js index 00a24ea61e..c9ccd740a1 100644 --- a/packages/babel-core/src/transformation/file/options/removed.js +++ b/packages/babel-core/src/transformation/file/options/removed.js @@ -1,35 +1,35 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ -module.exports = { +export default { "auxiliaryComment": { - "message": "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`" + "message": "Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`", }, "blacklist": { - "message": "Put the specific transforms you want in the `plugins` option" + "message": "Put the specific transforms you want in the `plugins` option", }, "breakConfig": { - "message": "This is not a necessary option in Babel 6" + "message": "This is not a necessary option in Babel 6", }, "experimental": { - "message": "Put the specific transforms you want in the `plugins` option" + "message": "Put the specific transforms you want in the `plugins` option", }, "externalHelpers": { - "message": "Use the `external-helpers` plugin instead. Check out http://babeljs.io/docs/plugins/external-helpers/" + "message": "Use the `external-helpers` plugin instead. Check out http://babeljs.io/docs/plugins/external-helpers/", }, "extra": { - "message": "" + "message": "", }, "jsxPragma": { - "message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/" + "message": "use the `pragma` option in the `react-jsx` plugin . Check out http://babeljs.io/docs/plugins/transform-react-jsx/", }, // "keepModuleIdExtensions": { // "message": "" // }, "loose": { - "message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option." + "message": "Specify the `loose` option for the relevant plugin you are using or use a preset that sets the option.", }, "metadataUsedHelpers": { - "message": "Not required anymore as this is enabled by default" + "message": "Not required anymore as this is enabled by default", }, "modules": { "message": "Use the corresponding module transform plugin in the `plugins` option. Check out http://babeljs.io/docs/plugins/#modules", @@ -38,15 +38,15 @@ module.exports = { "message": "Use the `react-jsx` and `flow-strip-types` plugins to support JSX and Flow. Also check out the react preset http://babeljs.io/docs/plugins/preset-react/", }, "optional": { - "message": "Put the specific transforms you want in the `plugins` option" + "message": "Put the specific transforms you want in the `plugins` option", }, "sourceMapName": { - "message": "Use the `sourceMapTarget` option" + "message": "Use the `sourceMapTarget` option", }, "stage": { - "message": "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets" + "message": "Check out the corresponding stage-x presets http://babeljs.io/docs/plugins/#presets", }, "whitelist": { - "message": "Put the specific transforms you want in the `plugins` option" - } + "message": "Put the specific transforms you want in the `plugins` option", + }, }; diff --git a/packages/babel-core/src/transformation/internal-plugins/block-hoist.js b/packages/babel-core/src/transformation/internal-plugins/block-hoist.js index de8bedf5bb..35dee65312 100644 --- a/packages/babel-core/src/transformation/internal-plugins/block-hoist.js +++ b/packages/babel-core/src/transformation/internal-plugins/block-hoist.js @@ -20,7 +20,7 @@ export default new Plugin({ exit({ node }) { let hasChange = false; for (let i = 0; i < node.body.length; i++) { - let bodyNode = node.body[i]; + const bodyNode = node.body[i]; if (bodyNode && bodyNode._blockHoist != null) { hasChange = true; break; @@ -36,7 +36,7 @@ export default new Plugin({ // Higher priorities should move toward the top. return -1 * priority; }); - } - } - } + }, + }, + }, }); diff --git a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js index 572b9bb379..ce50d21c01 100644 --- a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js +++ b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js @@ -7,12 +7,12 @@ const superVisitor = { CallExpression(path) { if (!path.get("callee").isSuper()) return; - const {node} = path; + const { node } = path; if (node[SUPER_THIS_BOUND]) return; node[SUPER_THIS_BOUND] = true; path.replaceWith(t.assignmentExpression("=", this.id, node)); - } + }, }; export default new Plugin({ @@ -27,8 +27,8 @@ export default new Plugin({ if (path.node.name === "arguments") { remap(path, "arguments"); } - } - } + }, + }, }); function shouldShadow(path, shadowPath) { @@ -41,10 +41,10 @@ function shouldShadow(path, shadowPath) { function remap(path, key) { // ensure that we're shadowed - let shadowPath = path.inShadow(key); + const shadowPath = path.inShadow(key); if (!shouldShadow(path, shadowPath)) return; - let shadowFunction = path.node._shadowedFunctionLiteral; + const shadowFunction = path.node._shadowedFunctionLiteral; let currentFunction; let passedShadowFunction = false; @@ -91,17 +91,17 @@ function remap(path, key) { // binding since arrow function syntax already does that. if (!passedShadowFunction) return; - let cached = fnPath.getData(key); + const cached = fnPath.getData(key); if (cached) return path.replaceWith(cached); - let id = path.scope.generateUidIdentifier(key); + const id = path.scope.generateUidIdentifier(key); fnPath.setData(key, id); - let classPath = fnPath.findParent((p) => p.isClass()); - let hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass); + const classPath = fnPath.findParent((p) => p.isClass()); + const hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass); - if (key === "this" && fnPath.isMethod({kind: "constructor"}) && hasSuperClass) { + if (key === "this" && fnPath.isMethod({ kind: "constructor" }) && hasSuperClass) { fnPath.scope.push({ id }); fnPath.traverse(superVisitor, { id }); diff --git a/packages/babel-core/src/transformation/pipeline.js b/packages/babel-core/src/transformation/pipeline.js index 12b1edbba3..c38edd7312 100644 --- a/packages/babel-core/src/transformation/pipeline.js +++ b/packages/babel-core/src/transformation/pipeline.js @@ -3,48 +3,31 @@ import normalizeAst from "../helpers/normalize-ast"; import Plugin from "./plugin"; import File from "./file"; -export default class Pipeline { - lint(code: string, opts?: Object = {}): BabelFileResult { - opts.code = false; - opts.mode = "lint"; - return this.transform(code, opts); - } - - pretransform(code: string, opts?: Object): BabelFileResult { - let file = new File(opts, this); - return file.wrap(code, function () { - file.addCode(code); - file.parseCode(code); - return file; - }); - } - - transform(code: string, opts?: Object): BabelFileResult { - let file = new File(opts, this); - return file.wrap(code, function () { - file.addCode(code); - file.parseCode(code); - return file.transform(); - }); - } - - analyse(code: string, opts: Object = {}, visitor?: Object): ?BabelFileMetadata { - opts.code = false; - if (visitor) { - opts.plugins = opts.plugins || []; - opts.plugins.push(new Plugin({ visitor })); - } - return this.transform(code, opts).metadata; - } - - transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult { - ast = normalizeAst(ast); - - let file = new File(opts, this); - return file.wrap(code, function () { - file.addCode(code); - file.addAst(ast); - return file.transform(); - }); +export function analyse(code: string, opts: Object = {}, visitor?: Object): ?BabelFileMetadata { + opts.code = false; + if (visitor) { + opts.plugins = opts.plugins || []; + opts.plugins.push(new Plugin({ visitor })); } + return transform(code, opts).metadata; +} + +export function transform(code: string, opts?: Object): BabelFileResult { + const file = new File(opts); + return file.wrap(code, function () { + file.addCode(code); + file.parseCode(code); + return file.transform(); + }); +} + +export function transformFromAst(ast: Object, code: string, opts: Object): BabelFileResult { + ast = normalizeAst(ast); + + const file = new File(opts); + return file.wrap(code, function () { + file.addCode(code); + file.addAst(ast); + return file.transform(); + }); } diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 1d1d60b01b..5e7ddb205d 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -6,9 +6,9 @@ export default class PluginPass extends Store { constructor(file: File, plugin: Plugin, options: Object = {}) { super(); this.plugin = plugin; - this.key = plugin.key; - this.file = file; - this.opts = options; + this.key = plugin.key; + this.file = file; + this.opts = options; } key: string; diff --git a/packages/babel-core/src/transformation/plugin.js b/packages/babel-core/src/transformation/plugin.js index afca4c882b..75665c1552 100644 --- a/packages/babel-core/src/transformation/plugin.js +++ b/packages/babel-core/src/transformation/plugin.js @@ -1,10 +1,7 @@ -/* eslint max-len: 0 */ - import OptionManager from "./file/options/option-manager"; import * as messages from "babel-messages"; import Store from "../store"; import traverse from "babel-traverse"; -import assign from "lodash/assign"; import clone from "lodash/clone"; const GLOBAL_VISITOR_PROPS = ["enter", "exit"]; @@ -14,13 +11,13 @@ export default class Plugin extends Store { super(); this.initialized = false; - this.raw = assign({}, plugin); - this.key = this.take("name") || key; + this.raw = Object.assign({}, plugin); + this.key = this.take("name") || key; this.manipulateOptions = this.take("manipulateOptions"); - this.post = this.take("post"); - this.pre = this.take("pre"); - this.visitor = this.normaliseVisitor(clone(this.take("visitor")) || {}); + this.post = this.take("post"); + this.pre = this.take("pre"); + this.visitor = this.normaliseVisitor(clone(this.take("visitor")) || {}); } initialized: boolean; @@ -31,7 +28,7 @@ export default class Plugin extends Store { visitor: Object; take(key) { - let val = this.raw[key]; + const val = this.raw[key]; delete this.raw[key]; return val; } @@ -40,13 +37,13 @@ export default class Plugin extends Store { if (!target[key]) return this[key]; if (!this[key]) return target[key]; - let fns: Array = [target[key], this[key]]; + const fns: Array = [target[key], this[key]]; return function (...args) { let val; - for (let fn of fns) { + for (const fn of fns) { if (fn) { - let ret = fn.apply(this, args); + const ret = fn.apply(this, args); if (ret != null) val = ret; } } @@ -77,15 +74,16 @@ export default class Plugin extends Store { this.maybeInherit(loc); - for (let key in this.raw) { + for (const key in this.raw) { throw new Error(messages.get("pluginInvalidProperty", loc, i, key)); } } normaliseVisitor(visitor: Object): Object { - for (let key of GLOBAL_VISITOR_PROPS) { + for (const key of GLOBAL_VISITOR_PROPS) { if (visitor[key]) { - throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. Please target individual nodes."); + throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. " + + "Please target individual nodes."); } } diff --git a/packages/babel-core/src/util.js b/packages/babel-core/src/util.js index 4da7503e8c..8d3ba4142e 100644 --- a/packages/babel-core/src/util.js +++ b/packages/babel-core/src/util.js @@ -1,9 +1,7 @@ import escapeRegExp from "lodash/escapeRegExp"; import startsWith from "lodash/startsWith"; -import isBoolean from "lodash/isBoolean"; import minimatch from "minimatch"; import includes from "lodash/includes"; -import isString from "lodash/isString"; import isRegExp from "lodash/isRegExp"; import path from "path"; import slash from "slash"; @@ -15,8 +13,8 @@ export { inherits, inspect } from "util"; */ export function canCompile(filename: string, altExts?: Array): boolean { - let exts = altExts || canCompile.EXTENSIONS; - let ext = path.extname(filename); + const exts = altExts || canCompile.EXTENSIONS; + const ext = path.extname(filename); return includes(exts, ext); } @@ -63,7 +61,7 @@ export function regexify(val: any): RegExp { if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2); if (startsWith(val, "**/")) val = val.slice(3); - let regex = minimatch.makeRe(val, { nocase: true }); + const regex = minimatch.makeRe(val, { nocase: true }); return new RegExp(regex.source.slice(1, -1), "i"); } @@ -80,8 +78,8 @@ export function regexify(val: any): RegExp { export function arrayify(val: any, mapFn?: Function): Array { if (!val) return []; - if (isBoolean(val)) return arrayify([val], mapFn); - if (isString(val)) return arrayify(list(val), mapFn); + if (typeof val === "boolean") return arrayify([val], mapFn); + if (typeof val === "string") return arrayify(list(val), mapFn); if (Array.isArray(val)) { if (mapFn) val = val.map(mapFn); @@ -119,12 +117,12 @@ export function shouldIgnore( filename = filename.replace(/\\/g, "/"); if (only) { - for (let pattern of only) { + for (const pattern of only) { if (_shouldIgnore(pattern, filename)) return false; } return true; } else if (ignore.length) { - for (let pattern of ignore) { + for (const pattern of ignore) { if (_shouldIgnore(pattern, filename)) return true; } } diff --git a/packages/babel-core/test/_browser.js b/packages/babel-core/test/_browser.js deleted file mode 100644 index 53e16f6e6c..0000000000 --- a/packages/babel-core/test/_browser.js +++ /dev/null @@ -1,7 +0,0 @@ -if (process.browser) { - require("../lib/api/browser"); - require("./generation"); - require("./transformation"); - require("./traverse"); - require("./util"); -} diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 1122e497e8..097b515b1a 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -1,9 +1,9 @@ -let babel = require("../lib/api/node"); -let buildExternalHelpers = require("../lib/tools/build-external-helpers"); -let sourceMap = require("source-map"); -let assert = require("assert"); -let Plugin = require("../lib/transformation/plugin"); -let generator = require("babel-generator").default; +import * as babel from "../lib/index"; +import buildExternalHelpers from "../lib/tools/build-external-helpers"; +import sourceMap from "source-map"; +import assert from "assert"; +import Plugin from "../lib/transformation/plugin"; +import generator from "babel-generator"; function assertIgnored(result) { assert.ok(result.ignored); @@ -18,18 +18,18 @@ function transformAsync(code, opts) { return { then: function (resolve) { resolve(babel.transform(code, opts)); - } + }, }; } describe("parser and generator options", function() { - let recast = { + const recast = { parse: function(code, opts) { return opts.parser.parse(code); }, print: function(ast) { return generator(ast); - } + }, }; function newTransform(string) { @@ -37,27 +37,27 @@ describe("parser and generator options", function() { parserOpts: { parser: recast.parse, plugins: ["flow"], - allowImportExportEverywhere: true + allowImportExportEverywhere: true, }, generatorOpts: { - generator: recast.print - } + generator: recast.print, + }, }); } it("options", function() { - let string = "original;"; + const string = "original;"; assert.deepEqual(newTransform(string).ast, babel.transform(string).ast); assert.equal(newTransform(string).code, string); }); it("experimental syntax", function() { - let experimental = "var a: number = 1;"; + const experimental = "var a: number = 1;"; assert.deepEqual(newTransform(experimental).ast, babel.transform(experimental, { parserOpts: { - plugins: ["flow"] - } + plugins: ["flow"], + }, }).ast); assert.equal(newTransform(experimental).code, experimental); @@ -65,29 +65,29 @@ describe("parser and generator options", function() { return babel.transform(string, { plugins: [__dirname + "/../../babel-plugin-syntax-flow"], parserOpts: { - parser: recast.parse + parser: recast.parse, }, generatorOpts: { - generator: recast.print - } + generator: recast.print, + }, }); } assert.deepEqual(newTransformWithPlugins(experimental).ast, babel.transform(experimental, { parserOpts: { - plugins: ["flow"] - } + plugins: ["flow"], + }, }).ast); assert.equal(newTransformWithPlugins(experimental).code, experimental); }); it("other options", function() { - let experimental = "if (true) {\n import a from 'a';\n}"; + const experimental = "if (true) {\n import a from 'a';\n}"; assert.notEqual(newTransform(experimental).ast, babel.transform(experimental, { parserOpts: { - allowImportExportEverywhere: true - } + allowImportExportEverywhere: true, + }, }).ast); assert.equal(newTransform(experimental).code, experimental); }); @@ -102,18 +102,26 @@ describe("api", function () { visitor: { Program: function (path) { path.mark("category", "foobar"); - } - } - })] + }, + }, + })], }).marked[0].message, "foobar"); assert.equal(babel.analyse("foobar;", {}, { Program: function (path) { path.mark("category", "foobar"); - } + }, }).marked[0].message, "foobar"); }); + it("exposes the resolvePlugin method", function() { + assert.equal(babel.resolvePlugin("nonexistent-plugin"), null); + }); + + it("exposes the resolvePreset method", function() { + assert.equal(babel.resolvePreset("nonexistent-preset"), null); + }); + it("transformFile", function (done) { babel.transformFile(__dirname + "/fixtures/api/file.js", {}, function (err, res) { if (err) return done(err); @@ -130,17 +138,17 @@ describe("api", function () { return assert.throws( function () { babel.transform("", { - plugins: [__dirname + "/../../babel-plugin-syntax-jsx", false] + plugins: [__dirname + "/../../babel-plugin-syntax-jsx", false], }); }, - /TypeError: Falsy value found in plugins/ + /TypeError: \[BABEL\] unknown: Falsy value found in plugins/ ); }); it("options merge backwards", function () { return transformAsync("", { presets: [__dirname + "/../../babel-preset-es2015"], - plugins: [__dirname + "/../../babel-plugin-syntax-jsx"] + plugins: [__dirname + "/../../babel-plugin-syntax-jsx"], }).then(function (result) { assert.ok(result.options.plugins[0][0].manipulateOptions.toString().indexOf("jsx") >= 0); }); @@ -169,9 +177,9 @@ describe("api", function () { visitor: { "Program|Identifier": function () { calledRaw++; - } - } - })] + }, + }, + })], }); assert.equal(calledRaw, 4); @@ -186,39 +194,43 @@ describe("api", function () { passPerPreset: passPerPreset, presets: [ // First preset with our plugin, "before" - { - plugins: [ - new Plugin({ - visitor: { - Function: function(path) { - let alias = path.scope.getProgramParent().path.get("body")[0].node; - if (!babel.types.isTypeAlias(alias)) return; + function () { + return { + plugins: [ + new Plugin({ + visitor: { + Function: function (path) { + const alias = path.scope.getProgramParent().path.get("body")[0].node; + if (!babel.types.isTypeAlias(alias)) return; - // In case of `passPerPreset` being `false`, the - // alias node is already removed by Flow plugin. - if (!alias) { - return; - } + // In case of `passPerPreset` being `false`, the + // alias node is already removed by Flow plugin. + if (!alias) { + return; + } - // In case of `passPerPreset` being `true`, the - // alias node should still exist. - aliasBaseType = alias.right.type; // NumberTypeAnnotation - } - } - }) - ] + // In case of `passPerPreset` being `true`, the + // alias node should still exist. + aliasBaseType = alias.right.type; // NumberTypeAnnotation + }, + }, + }), + ], + }; }, // ES2015 preset require(__dirname + "/../../babel-preset-es2015"), // Third preset for Flow. - { - plugins: [ - require(__dirname + "/../../babel-plugin-syntax-flow"), - require(__dirname + "/../../babel-plugin-transform-flow-strip-types"), - ] - } + function () { + return { + plugins: [ + require(__dirname + "/../../babel-plugin-syntax-flow"), + require(__dirname + "/../../babel-plugin-transform-flow-strip-types"), + ], + }; + }, ], }); } @@ -234,7 +246,7 @@ describe("api", function () { "", "var x = function x(y) {", " return y;", - "};" + "};", ].join("\n"), result.code); // 2. passPerPreset: false @@ -250,44 +262,24 @@ describe("api", function () { "", "var x = function x(y) {", " return y;", - "};" + "};", ].join("\n"), result.code); }); - it("handles preset shortcuts (adds babel-preset-)", function () { - return assert.throws( - function () { - babel.transform("", { - presets: ["@babel/es2015"] - }); - }, - /Couldn\'t find preset \"\@babel\/babel\-preset\-es2015\" relative to directory/ - ); - }); - - it("handles preset shortcuts 2 (adds babel-preset-)", function () { - return assert.throws( - function () { - babel.transform("", { - presets: ["@babel/react/optimizations"] - }); - }, - /Couldn\'t find preset \"\@babel\/babel\-preset\-react\/optimizations\" relative to directory/ - ); - }); - it("source map merging", function () { - let result = babel.transform([ + const result = babel.transform([ + /* eslint-disable max-len */ "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }", "", "let Foo = function Foo() {", " _classCallCheck(this, Foo);", "};", "", - "//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0=" + "//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0=", + /* eslint-enable max-len */ ].join("\n"), { - sourceMap: true + sourceMap: true, }); assert.deepEqual([ @@ -299,19 +291,19 @@ describe("api", function () { "", "let Foo = function Foo() {", " _classCallCheck(this, Foo);", - "};" + "};", ].join("\n"), result.code); - let consumer = new sourceMap.SourceMapConsumer(result.map); + const consumer = new sourceMap.SourceMapConsumer(result.map); assert.deepEqual(consumer.originalPositionFor({ line: 7, - column: 4 + column: 4, }), { name: null, source: "stdout", line: 1, - column: 6 + column: 6, }); }); @@ -332,23 +324,25 @@ describe("api", function () { auxiliaryCommentBefore: "before", auxiliaryCommentAfter: "after", plugins: [function (babel) { - let t = babel.types; + const t = babel.types; return { visitor: { Program: function (path) { path.unshiftContainer("body", t.expressionStatement(t.identifier("start"))); path.pushContainer("body", t.expressionStatement(t.identifier("end"))); - } - } + }, + }, }; - }] + }], }).then(function (result) { - assert.equal(result.code, "/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/"); + assert.equal(result.code, + "/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/"); }); }); it("modules metadata", function () { return Promise.all([ + // eslint-disable-next-line max-len transformAsync("import { externalName as localName } from \"external\";").then(function (result) { assert.deepEqual(result.metadata.modules.imports[0], { source: "external", @@ -356,8 +350,8 @@ describe("api", function () { specifiers: [{ kind: "named", imported: "externalName", - local: "localName" - }] + local: "localName", + }], }); }), @@ -367,8 +361,8 @@ describe("api", function () { imported: ["*"], specifiers: [{ kind: "namespace", - local: "localName2" - }] + local: "localName2", + }], }); }), @@ -379,15 +373,15 @@ describe("api", function () { specifiers: [{ kind: "named", imported: "default", - local: "localName3" - }] + local: "localName3", + }], }); }), transformAsync("import localName from \"./array\";", { resolveModuleSource: function() { return "override-source"; - } + }, }).then(function (result) { assert.deepEqual(result.metadata.modules.imports, [ { @@ -397,15 +391,15 @@ describe("api", function () { { "kind": "named", "imported": "default", - "local": "localName" - } - ] - } + "local": "localName", + }, + ], + }, ]); }), transformAsync("export * as externalName1 from \"external\";", { - plugins: [require("../../babel-plugin-syntax-export-extensions")] + plugins: [require("../../babel-plugin-syntax-export-extensions")], }).then(function (result) { assert.deepEqual(result.metadata.modules.exports, { exported: ["externalName1"], @@ -413,12 +407,12 @@ describe("api", function () { kind: "external-namespace", exported: "externalName1", source: "external", - }] + }], }); }), transformAsync("export externalName2 from \"external\";", { - plugins: [require("../../babel-plugin-syntax-export-extensions")] + plugins: [require("../../babel-plugin-syntax-export-extensions")], }).then(function (result) { assert.deepEqual(result.metadata.modules.exports, { exported: ["externalName2"], @@ -426,8 +420,8 @@ describe("api", function () { kind: "external", local: "externalName2", exported: "externalName2", - source: "external" - }] + source: "external", + }], }); }), @@ -437,8 +431,8 @@ describe("api", function () { specifiers: [{ kind: "local", local: "namedFunction", - exported: "namedFunction" - }] + exported: "namedFunction", + }], }); }), @@ -448,8 +442,8 @@ describe("api", function () { specifiers: [{ kind: "local", local: "foo", - exported: "foo" - }] + exported: "foo", + }], }); }), @@ -459,8 +453,8 @@ describe("api", function () { specifiers: [{ kind: "local", local: "localName", - exported: "externalName3" - }] + exported: "externalName3", + }], }); }), @@ -471,8 +465,8 @@ describe("api", function () { kind: "external", local: "externalName4", exported: "externalName4", - source: "external" - }] + source: "external", + }], }); }), @@ -481,8 +475,8 @@ describe("api", function () { exported: [], specifiers: [{ kind: "external-all", - source: "external" - }] + source: "external", + }], }); }), @@ -492,10 +486,10 @@ describe("api", function () { specifiers: [{ kind: "local", local: "defaultFunction", - exported: "default" - }] + exported: "default", + }], }); - }) + }), ]); }); @@ -503,18 +497,18 @@ describe("api", function () { return Promise.all([ transformAsync("", { ignore: "node_modules", - filename: "/foo/node_modules/bar" + filename: "/foo/node_modules/bar", }).then(assertIgnored), transformAsync("", { ignore: "foo/node_modules", - filename: "/foo/node_modules/bar" + filename: "/foo/node_modules/bar", }).then(assertIgnored), transformAsync("", { ignore: "foo/node_modules/*.bar", - filename: "/foo/node_modules/foo.bar" - }).then(assertIgnored) + filename: "/foo/node_modules/foo.bar", + }).then(assertIgnored), ]); }); @@ -522,39 +516,39 @@ describe("api", function () { return Promise.all([ transformAsync("", { only: "node_modules", - filename: "/foo/node_modules/bar" + filename: "/foo/node_modules/bar", }).then(assertNotIgnored), transformAsync("", { only: "foo/node_modules", - filename: "/foo/node_modules/bar" + filename: "/foo/node_modules/bar", }).then(assertNotIgnored), transformAsync("", { only: "foo/node_modules/*.bar", - filename: "/foo/node_modules/foo.bar" + filename: "/foo/node_modules/foo.bar", }).then(assertNotIgnored), transformAsync("", { only: "node_modules", - filename: "/foo/node_module/bar" + filename: "/foo/node_module/bar", }).then(assertIgnored), transformAsync("", { only: "foo/node_modules", - filename: "/bar/node_modules/foo" + filename: "/bar/node_modules/foo", }).then(assertIgnored), transformAsync("", { only: "foo/node_modules/*.bar", - filename: "/foo/node_modules/bar.foo" - }).then(assertIgnored) + filename: "/foo/node_modules/bar.foo", + }).then(assertIgnored), ]); }); describe("env option", function () { - let oldBabelEnv = process.env.BABEL_ENV; - let oldNodeEnv = process.env.NODE_ENV; + const oldBabelEnv = process.env.BABEL_ENV; + const oldNodeEnv = process.env.NODE_ENV; setup(function () { // Tests need to run with the default and specific values for these. They @@ -569,10 +563,10 @@ describe("api", function () { }); it("default", function () { - let result = babel.transform("foo;", { + const result = babel.transform("foo;", { env: { - development: { code: false } - } + development: { code: false }, + }, }); assert.equal(result.code, undefined); @@ -580,33 +574,35 @@ describe("api", function () { it("BABEL_ENV", function () { process.env.BABEL_ENV = "foo"; - let result = babel.transform("foo;", { + const result = babel.transform("foo;", { env: { - foo: { code: false } - } + foo: { code: false }, + }, }); assert.equal(result.code, undefined); }); it("NODE_ENV", function () { process.env.NODE_ENV = "foo"; - let result = babel.transform("foo;", { + const result = babel.transform("foo;", { env: { - foo: { code: false } - } + foo: { code: false }, + }, }); assert.equal(result.code, undefined); }); }); it("resolveModuleSource option", function () { - let actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";"; - let expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";"; + /* eslint-disable max-len */ + const actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";"; + const expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";"; + /* eslint-enable max-len */ return transformAsync(actual, { resolveModuleSource: function (originalSource) { return "resolved/" + originalSource; - } + }, }).then(function (result) { assert.equal(result.code.trim(), expected); }); @@ -614,25 +610,25 @@ describe("api", function () { describe("buildExternalHelpers", function () { it("all", function () { - let script = buildExternalHelpers(); + const script = buildExternalHelpers(); assert.ok(script.indexOf("classCallCheck") >= -1); assert.ok(script.indexOf("inherits") >= 0); }); it("whitelist", function () { - let script = buildExternalHelpers(["inherits"]); + const script = buildExternalHelpers(["inherits"]); assert.ok(script.indexOf("classCallCheck") === -1); assert.ok(script.indexOf("inherits") >= 0); }); it("empty whitelist", function () { - let script = buildExternalHelpers([]); + const script = buildExternalHelpers([]); assert.ok(script.indexOf("classCallCheck") === -1); assert.ok(script.indexOf("inherits") === -1); }); it("underscored", function () { - let script = buildExternalHelpers(["typeof"]); + const script = buildExternalHelpers(["typeof"]); assert.ok(script.indexOf("typeof") >= 0); }); }); diff --git a/packages/babel-core/test/browserify.js b/packages/babel-core/test/browserify.js index 9923f6c52e..e8e8f27c82 100644 --- a/packages/babel-core/test/browserify.js +++ b/packages/babel-core/test/browserify.js @@ -1,11 +1,11 @@ -let browserify = require("browserify"); -let assert = require("assert"); -let path = require("path"); -let vm = require("vm"); +import browserify from "browserify"; +import assert from "assert"; +import path from "path"; +import vm from "vm"; describe("browserify", function() { it("babel/register may be used without breaking browserify", function(done) { - let bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js")); + const bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js")); bundler.bundle(function(err, bundle) { if (err) return done(err); diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 0a0b952d51..f317eca7d8 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -1,9 +1,9 @@ -let assert = require("assert"); -let path = require("path"); -let buildConfigChain = require("../lib/transformation/file/options/build-config-chain"); +import assert from "assert"; +import path from "path"; +import buildConfigChain from "../lib/transformation/file/options/build-config-chain"; function fixture() { - let args = [__dirname, "fixtures", "config"]; + const args = [__dirname, "fixtures", "config"]; for (let i = 0; i < arguments.length; i ++) { args.push(arguments[i]); } @@ -28,127 +28,127 @@ describe("buildConfigChain", function () { }); it("dir1", function () { - let chain = buildConfigChain({ - filename: fixture("dir1", "src.js") + const chain = buildConfigChain({ + filename: fixture("dir1", "src.js"), }); - let expected = [ + const expected = [ { options: { plugins: [ - "extended" - ] + "extended", + ], }, alias: fixture("extended.babelrc.json"), loc: fixture("extended.babelrc.json"), - dirname: fixture() + dirname: fixture(), }, { options: { plugins: [ - "root" - ] + "root", + ], }, alias: fixture(".babelrc"), loc: fixture(".babelrc"), - dirname: fixture() + dirname: fixture(), }, { options: { ignore: [ - "root-ignore" - ] + "root-ignore", + ], }, alias: fixture(".babelignore"), loc: fixture(".babelignore"), - dirname: fixture() + dirname: fixture(), }, { options: { - filename: fixture("dir1", "src.js") + filename: fixture("dir1", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("dir1") - } + dirname: fixture("dir1"), + }, ]; assert.deepEqual(chain, expected); }); it("dir2", function () { - let chain = buildConfigChain({ - filename: fixture("dir2", "src.js") + const chain = buildConfigChain({ + filename: fixture("dir2", "src.js"), }); - let expected = [ + const expected = [ { options: { plugins: [ - "dir2" - ] + "dir2", + ], }, alias: fixture("dir2", ".babelrc"), loc: fixture("dir2", ".babelrc"), - dirname: fixture("dir2") + dirname: fixture("dir2"), }, { options: { ignore: [ - "root-ignore" - ] + "root-ignore", + ], }, alias: fixture(".babelignore"), loc: fixture(".babelignore"), - dirname: fixture() + dirname: fixture(), }, { options: { - filename: fixture("dir2", "src.js") + filename: fixture("dir2", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("dir2") - } + dirname: fixture("dir2"), + }, ]; assert.deepEqual(chain, expected); }); it("env - base", function () { - let chain = buildConfigChain({ - filename: fixture("env", "src.js") + const chain = buildConfigChain({ + filename: fixture("env", "src.js"), }); - let expected = [ + const expected = [ { options: { plugins: [ - "env-base" - ] + "env-base", + ], }, alias: fixture("env", ".babelrc"), loc: fixture("env", ".babelrc"), - dirname: fixture("env") + dirname: fixture("env"), }, { options: { ignore: [ - "root-ignore" - ] + "root-ignore", + ], }, alias: fixture(".babelignore"), loc: fixture(".babelignore"), - dirname: fixture() + dirname: fixture(), }, { options: { - filename: fixture("env", "src.js") + filename: fixture("env", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("env") - } + dirname: fixture("env"), + }, ]; assert.deepEqual(chain, expected); @@ -157,49 +157,49 @@ describe("buildConfigChain", function () { it("env - foo", function () { process.env.NODE_ENV = "foo"; - let chain = buildConfigChain({ - filename: fixture("env", "src.js") + const chain = buildConfigChain({ + filename: fixture("env", "src.js"), }); - let expected = [ + const expected = [ { options: { plugins: [ - "env-base" - ] + "env-base", + ], }, alias: fixture("env", ".babelrc"), loc: fixture("env", ".babelrc"), - dirname: fixture("env") + dirname: fixture("env"), }, { options: { plugins: [ - "env-foo" - ] + "env-foo", + ], }, alias: fixture("env", ".babelrc.env.foo"), loc: fixture("env", ".babelrc.env.foo"), - dirname: fixture("env") + dirname: fixture("env"), }, { options: { ignore: [ - "root-ignore" - ] + "root-ignore", + ], }, alias: fixture(".babelignore"), loc: fixture(".babelignore"), - dirname: fixture() + dirname: fixture(), }, { options: { - filename: fixture("env", "src.js") + filename: fixture("env", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("env") - } + dirname: fixture("env"), + }, ]; assert.deepEqual(chain, expected); @@ -209,49 +209,49 @@ describe("buildConfigChain", function () { process.env.NODE_ENV = "foo"; // overridden process.env.NODE_ENV = "bar"; - let chain = buildConfigChain({ - filename: fixture("env", "src.js") + const chain = buildConfigChain({ + filename: fixture("env", "src.js"), }); - let expected = [ + const expected = [ { options: { plugins: [ - "env-base" - ] + "env-base", + ], }, alias: fixture("env", ".babelrc"), loc: fixture("env", ".babelrc"), - dirname: fixture("env") + dirname: fixture("env"), }, { options: { plugins: [ - "env-bar" - ] + "env-bar", + ], }, alias: fixture("env", ".babelrc.env.bar"), loc: fixture("env", ".babelrc.env.bar"), - dirname: fixture("env") + dirname: fixture("env"), }, { options: { ignore: [ - "root-ignore" - ] + "root-ignore", + ], }, alias: fixture(".babelignore"), loc: fixture(".babelignore"), - dirname: fixture() + dirname: fixture(), }, { options: { - filename: fixture("env", "src.js") + filename: fixture("env", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("env") - } + dirname: fixture("env"), + }, ]; assert.deepEqual(chain, expected); @@ -261,37 +261,286 @@ describe("buildConfigChain", function () { it("env - foo", function () { process.env.NODE_ENV = "foo"; - let chain = buildConfigChain({ - filename: fixture("pkg", "src.js") + const chain = buildConfigChain({ + filename: fixture("pkg", "src.js"), }); - let expected = [ + const expected = [ { options: { - plugins: ["pkg-plugin"] + plugins: ["pkg-plugin"], }, alias: fixture("pkg", "package.json"), loc: fixture("pkg", "package.json"), - dirname: fixture("pkg") + dirname: fixture("pkg"), }, { options: { - ignore: ["pkg-ignore"] + ignore: ["pkg-ignore"], }, alias: fixture("pkg", ".babelignore"), loc: fixture("pkg", ".babelignore"), - dirname: fixture("pkg") + dirname: fixture("pkg"), }, { options: { - filename: fixture("pkg", "src.js") + filename: fixture("pkg", "src.js"), }, alias: "base", loc: "base", - dirname: fixture("pkg") - } + dirname: fixture("pkg"), + }, ]; assert.deepEqual(chain, expected); }); + + it("js-config", function () { + const chain = buildConfigChain({ + filename: fixture("js-config", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config", ".babelrc.js"), + loc: fixture("js-config", ".babelrc.js"), + dirname: fixture("js-config"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("js-config-default - should read transpiled export default", function () { + const chain = buildConfigChain({ + filename: fixture("js-config-default", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config-default", ".babelrc.js"), + loc: fixture("js-config-default", ".babelrc.js"), + dirname: fixture("js-config-default"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config-default", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config-default"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + it("js-config-extended", function () { + const chain = buildConfigChain({ + filename: fixture("js-config-extended", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "extended", + ], + }, + alias: fixture("extended.babelrc.json"), + loc: fixture("extended.babelrc.json"), + dirname: fixture(), + }, + { + options: { + plugins: [ + "foo", + "bar", + ], + }, + alias: fixture("js-config-extended", ".babelrc.js"), + loc: fixture("js-config-extended", ".babelrc.js"), + dirname: fixture("js-config-extended"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("js-config-extended", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("js-config-extended"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("json-pkg-config-no-babel - should not throw if" + + " package.json doesn't contain a `babel` field", function () { + const chain = buildConfigChain({ + filename: fixture("json-pkg-config-no-babel", "src.js"), + }); + + const expected = [ + { + options: { + plugins: [ + "json", + ], + }, + alias: fixture("json-pkg-config-no-babel", ".babelrc"), + loc: fixture("json-pkg-config-no-babel", ".babelrc"), + dirname: fixture("json-pkg-config-no-babel"), + }, + { + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + options: { + filename: fixture("json-pkg-config-no-babel", "src.js"), + }, + alias: "base", + loc: "base", + dirname: fixture("json-pkg-config-no-babel"), + }, + ]; + + assert.deepEqual(chain, expected); + }); + + it("js-json-config - should throw an error if both a .babelrc" + + " and a .babelrc.js are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-json-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*\.babelrc\.js/ + ); + }); + + it("js-pkg-config - should throw an error if both a .babelrc.js" + + " and a package.json with a babel field are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-pkg-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc\.js(.|\n)*package\.json/ + ); + }); + + it("json-pkg-config - should throw an error if both a .babelrc" + + " and a package.json with a babel field are present", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("json-pkg-config", "src.js"), + }); + }, + /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*package\.json/ + ); + }); + + it("js-config-error", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error", "src.js"), + }); + }, + /Error while loading config/ + ); + }); + + it("js-config-error2", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error2", "src.js"), + }); + }, + /Configuration should be an exported JavaScript object/ + ); + }); + + it("js-config-error3", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("js-config-error3", "src.js"), + }); + }, + /Configuration should be an exported JavaScript object/ + ); + }); + + it("json-config-error", function () { + assert.throws( + function () { + buildConfigChain({ + filename: fixture("json-config-error", "src.js"), + }); + }, + /Error while parsing JSON/ + ); + }); }); diff --git a/packages/babel-core/test/evaluation.js b/packages/babel-core/test/evaluation.js index 1af3bc7399..ca86f51839 100644 --- a/packages/babel-core/test/evaluation.js +++ b/packages/babel-core/test/evaluation.js @@ -1,20 +1,20 @@ -let traverse = require("babel-traverse").default; -let assert = require("assert"); -let parse = require("babylon").parse; +import traverse from "babel-traverse"; +import assert from "assert"; +import { parse } from "babylon"; describe("evaluation", function () { function addTest(code, type, value, notConfident) { it(type + ": " + code, function () { - let visitor = {}; + const visitor = {}; visitor[type] = function (path) { - let evaluate = path.evaluate(); + const evaluate = path.evaluate(); assert.equal(evaluate.confident, !notConfident); assert.deepEqual(evaluate.value, value); }; traverse(parse(code, { - plugins: ["*"] + plugins: ["*"], }), visitor); }); } @@ -64,6 +64,6 @@ describe("evaluation", function () { addTest("'abc' === 'xyz' || (1 === 1 && 'four' === 'four')", "LogicalExpression", true); addTest("'abc' === 'abc' && (1 === 1 && 'four' === 'four')", "LogicalExpression", true); addTest("({})", "ObjectExpression", {}); - addTest("({a: '1'})", "ObjectExpression", {a: "1"}); - addTest("({['a' + 'b']: 10 * 20, 'z': [1, 2, 3]})", "ObjectExpression", {ab: 200, z: [1, 2, 3]}); + addTest("({a: '1'})", "ObjectExpression", { a: "1" }); + addTest("({['a' + 'b']: 10 * 20, 'z': [1, 2, 3]})", "ObjectExpression", { ab: 200, z: [1, 2, 3] }); }); diff --git a/packages/babel-core/test/fixtures/browserify/register.js b/packages/babel-core/test/fixtures/browserify/register.js index e1100b136b..d8f99e94a6 100644 --- a/packages/babel-core/test/fixtures/browserify/register.js +++ b/packages/babel-core/test/fixtures/browserify/register.js @@ -1,3 +1,3 @@ -require("../../../register")({ +require("babel-register").default({ ignore: false }); diff --git a/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js new file mode 100644 index 0000000000..de5f1c0244 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js @@ -0,0 +1,10 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var plugins = ["foo", "bar"]; + +exports.default = { + plugins: plugins +}; diff --git a/packages/babel-core/test/fixtures/config/js-config-default/src.js b/packages/babel-core/test/fixtures/config/js-config-default/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-default/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js new file mode 100644 index 0000000000..d14a2b71a8 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js @@ -0,0 +1,2 @@ +throw new Error("Something bad happened!"); +module.exports = {} diff --git a/packages/babel-core/test/fixtures/config/js-config-error/src.js b/packages/babel-core/test/fixtures/config/js-config-error/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js new file mode 100644 index 0000000000..9dc5fc1e4a --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js @@ -0,0 +1 @@ +module.exports = ''; diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/src.js b/packages/babel-core/test/fixtures/config/js-config-error2/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error2/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js new file mode 100644 index 0000000000..b894a23a24 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js @@ -0,0 +1 @@ +module.exports = null; diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/src.js b/packages/babel-core/test/fixtures/config/js-config-error3/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-error3/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js new file mode 100644 index 0000000000..05741c6ef8 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js @@ -0,0 +1,6 @@ +var plugins = ["foo", "bar"]; + +module.exports = { + extends: "../extended.babelrc.json", + plugins: plugins +} diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/src.js b/packages/babel-core/test/fixtures/config/js-config-extended/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config-extended/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config/.babelrc.js new file mode 100644 index 0000000000..e6fa0742df --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config/.babelrc.js @@ -0,0 +1,5 @@ +var plugins = ["foo", "bar"]; + +module.exports = { + plugins: plugins +} diff --git a/packages/babel-core/test/fixtures/config/js-config/src.js b/packages/babel-core/test/fixtures/config/js-config/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc new file mode 100644 index 0000000000..c80e833d70 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js new file mode 100644 index 0000000000..71bb3e5762 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + "js" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/src.js b/packages/babel-core/test/fixtures/config/js-json-config/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-json-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js new file mode 100644 index 0000000000..71bb3e5762 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + "js" + ] +} diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/package.json b/packages/babel-core/test/fixtures/config/js-pkg-config/package.json new file mode 100644 index 0000000000..e25be3ecd2 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/package.json @@ -0,0 +1,3 @@ +{ + "babel": {} +} diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/src.js b/packages/babel-core/test/fixtures/config/js-pkg-config/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/js-pkg-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-config-error/.babelrc b/packages/babel-core/test/fixtures/config/json-config-error/.babelrc new file mode 100644 index 0000000000..a07fde17a3 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-config-error/.babelrc @@ -0,0 +1,3 @@ +{ + "bad: "json" +} diff --git a/packages/babel-core/test/fixtures/config/json-config-error/src.js b/packages/babel-core/test/fixtures/config/json-config-error/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-config-error/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc new file mode 100644 index 0000000000..c80e833d70 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc new file mode 100644 index 0000000000..c80e833d70 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "json" + ] +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/package.json b/packages/babel-core/test/fixtures/config/json-pkg-config/package.json new file mode 100644 index 0000000000..e25be3ecd2 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/package.json @@ -0,0 +1,3 @@ +{ + "babel": {} +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/json-pkg-config/src.js @@ -0,0 +1 @@ +// empty diff --git a/packages/babel-core/test/fixtures/option-manager/not-a-preset.js b/packages/babel-core/test/fixtures/option-manager/not-a-preset.js index 7059dfdbe3..67e7ffccf5 100644 --- a/packages/babel-core/test/fixtures/option-manager/not-a-preset.js +++ b/packages/babel-core/test/fixtures/option-manager/not-a-preset.js @@ -1,3 +1,3 @@ module.exports = function () { throw new Error('Not a real preset'); -} +}; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es2015_default.js b/packages/babel-core/test/fixtures/option-manager/presets/es2015_default_object.js similarity index 100% rename from packages/babel-core/test/fixtures/option-manager/presets/es2015_default.js rename to packages/babel-core/test/fixtures/option-manager/presets/es2015_default_object.js diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es2015_default_object_function.js b/packages/babel-core/test/fixtures/option-manager/presets/es2015_default_object_function.js deleted file mode 100644 index b5f1eef249..0000000000 --- a/packages/babel-core/test/fixtures/option-manager/presets/es2015_default_object_function.js +++ /dev/null @@ -1,18 +0,0 @@ -// from code: -// export default { -// buildPreset: function() { -// return { -// plugins: [require('../../../../../babel-plugin-syntax-decorators'),] -// }; -// } -// } -'use strict'; - -exports.__esModule = true; -exports.default = { - buildPreset: function buildPreset() { - return { - plugins: [require('../../../../../babel-plugin-syntax-decorators')] - }; - } -}; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es2015_function.js b/packages/babel-core/test/fixtures/option-manager/presets/es2015_function.js deleted file mode 100644 index eddcf7e294..0000000000 --- a/packages/babel-core/test/fixtures/option-manager/presets/es2015_function.js +++ /dev/null @@ -1,17 +0,0 @@ -// from code: -// export const buildPreset = function() { -// return { -// plugins: [require('../../../../../babel-plugin-syntax-decorators'),] -// }; -// } -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var buildPreset = exports.buildPreset = function buildPreset() { - return { - plugins: [require('../../../../../babel-plugin-syntax-decorators')] - }; -}; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es2015_function_fallback.js b/packages/babel-core/test/fixtures/option-manager/presets/es2015_function_fallback.js deleted file mode 100644 index d0c11d0258..0000000000 --- a/packages/babel-core/test/fixtures/option-manager/presets/es2015_function_fallback.js +++ /dev/null @@ -1,50 +0,0 @@ -// from code: -// function preset() { -// return { -// plugins: [ -// require('../../../../../babel-plugin-syntax-decorators'), -// ] -// }; -// } -// -// const oldConfig = preset(); -// -// export default oldConfig; -// -// // However, for backward compatibility with babel-core < v6.13.x, we use the 'buildPreset' -// // property of the preset object for the preset creation function with the enumerability -// // caveat mentioned below. -// Object.defineProperty(oldConfig, "buildPreset", { -// configurable: true, -// writable: true, -// // We make this non-enumerable so old versions of babel-core won't see it as an unknown property, -// // while allowing new versions to see it as a preset builder function. -// enumerable: false, -// value: preset, -// }); -// - -"use strict"; - -exports.__esModule = true; -function preset() { - return { - plugins: [require('../../../../../babel-plugin-syntax-decorators')] - }; -} - -var oldConfig = preset(); - -exports.default = oldConfig; - -// However, for backward compatibility with babel-core < v6.13.x, we use the 'buildPreset' -// property of the preset object for the preset creation function with the enumerability -// caveat mentioned below. -Object.defineProperty(oldConfig, "buildPreset", { - configurable: true, - writable: true, - // We make this non-enumerable so old versions of babel-core won't see it as an unknown property, - // while allowing new versions to see it as a preset builder function. - enumerable: false, - value: preset -}); diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es2015_invalid.js b/packages/babel-core/test/fixtures/option-manager/presets/es2015_invalid.js new file mode 100644 index 0000000000..88437e1088 --- /dev/null +++ b/packages/babel-core/test/fixtures/option-manager/presets/es2015_invalid.js @@ -0,0 +1,6 @@ +// from code: +// export default "string"; +'use strict'; + +exports.__esModule = true; +exports.default = "string"; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es5_function.js b/packages/babel-core/test/fixtures/option-manager/presets/es5_function.js index 31648d0600..71c789f9df 100644 --- a/packages/babel-core/test/fixtures/option-manager/presets/es5_function.js +++ b/packages/babel-core/test/fixtures/option-manager/presets/es5_function.js @@ -1,9 +1,7 @@ -module.exports = { - buildPreset: function () { - return { - plugins: [ - require('../../../../../babel-plugin-syntax-decorators'), - ] - }; - } +module.exports = function () { + return { + plugins: [ + require('../../../../../babel-plugin-syntax-decorators'), + ] + }; }; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es5_invalid.js b/packages/babel-core/test/fixtures/option-manager/presets/es5_invalid.js new file mode 100644 index 0000000000..258dbaf2cc --- /dev/null +++ b/packages/babel-core/test/fixtures/option-manager/presets/es5_invalid.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = "invalid"; diff --git a/packages/babel-core/test/fixtures/option-manager/presets/es5.js b/packages/babel-core/test/fixtures/option-manager/presets/es5_object.js similarity index 100% rename from packages/babel-core/test/fixtures/option-manager/presets/es5.js rename to packages/babel-core/test/fixtures/option-manager/presets/es5_object.js diff --git a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js index a1af16e41f..1f313cfaa1 100644 --- a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js +++ b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js @@ -1,5 +1,10 @@ -module.exports = { - plugins: [plugin], +module.exports = function (context, options, fileContext) { + if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) { + return { + plugins: [plugin], + }; + } + return {}; }; function plugin () { diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-2364/actual.js b/packages/babel-core/test/fixtures/transformation/misc/regression-2364/actual.js index e995e0d234..c2ae386b34 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-2364/actual.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-2364/actual.js @@ -1,6 +1,6 @@ function wrapper(fn) { return (...args) => { - if (someCondition) { + while (someCondition) { const val = fn(...args); return val.test(() => { console.log(val); diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-2364/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-2364/expected.js index ae32dbb4d3..c1079c01cb 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-2364/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-2364/expected.js @@ -2,17 +2,19 @@ function wrapper(fn) { return function () { var _arguments = arguments; - if (someCondition) { - var _ret = function () { - var val = fn(..._arguments); - return { - v: val.test(function () { - console.log(val); - }) - }; - }(); + var _loop = function () { + var val = fn(..._arguments); + return { + v: val.test(function () { + console.log(val); + }) + }; + }; + + while (someCondition) { + var _ret = _loop(); if (typeof _ret === "object") return _ret.v; } }; -} \ No newline at end of file +} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js index 00ae47b875..991056b8bf 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCJdLCJtYXBwaW5ncyI6IkFBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlBLENBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCJdLCJtYXBwaW5ncyI6IkFBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlBLENBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 diff --git a/packages/babel-core/test/get-possible-plugin-names.js b/packages/babel-core/test/get-possible-plugin-names.js new file mode 100644 index 0000000000..7ce8644769 --- /dev/null +++ b/packages/babel-core/test/get-possible-plugin-names.js @@ -0,0 +1,8 @@ +import assert from "assert"; +import getPossiblePluginNames from "../lib/helpers/get-possible-plugin-names"; + +describe("getPossiblePluginNames", function () { + it("adds the babel-plugin prefix", function() { + assert.deepEqual(getPossiblePluginNames("foobar"), ["babel-plugin-foobar", "foobar"]); + }); +}); diff --git a/packages/babel-core/test/get-possible-preset-names.js b/packages/babel-core/test/get-possible-preset-names.js new file mode 100644 index 0000000000..40052fdfbb --- /dev/null +++ b/packages/babel-core/test/get-possible-preset-names.js @@ -0,0 +1,22 @@ +import assert from "assert"; +import getPossiblePresetNames from "../lib/helpers/get-possible-preset-names"; + +describe("getPossiblePresetNames", function () { + it("adds the babel-preset prefix", function() { + assert.deepEqual(getPossiblePresetNames("foobar"), ["babel-preset-foobar", "foobar"]); + }); + + it("inserts babel-preset after @org/", function() { + assert.deepEqual(getPossiblePresetNames("@babel/es2015"), [ + "babel-preset-@babel/es2015", + "@babel/es2015", + "@babel/babel-preset-es2015", + ]); + + assert.deepEqual(getPossiblePresetNames("@babel/react/optimizations"), [ + "babel-preset-@babel/react/optimizations", + "@babel/react/optimizations", + "@babel/babel-preset-react/optimizations", + ]); + }); +}); diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js index 592c431d54..126ed83c27 100644 --- a/packages/babel-core/test/option-manager.js +++ b/packages/babel-core/test/option-manager.js @@ -1,6 +1,5 @@ import assert from "assert"; import OptionManager from "../lib/transformation/file/options/option-manager"; -import Logger from "../lib/transformation/file/logger"; import path from "path"; describe("option-manager", () => { @@ -17,9 +16,9 @@ describe("option-manager", () => { it("throws for removed babel 5 options", () => { return assert.throws( () => { - let opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ - "randomOption": true + "randomOption": true, }); }, /Unknown option: base.randomOption/ @@ -29,12 +28,13 @@ describe("option-manager", () => { it("throws for removed babel 5 options", () => { return assert.throws( () => { - let opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ "auxiliaryComment": true, - "blacklist": true + "blacklist": true, }); }, + // eslint-disable-next-line max-len /Using removed Babel 5 option: base.auxiliaryComment - Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`/ ); }); @@ -42,34 +42,22 @@ describe("option-manager", () => { it("throws for resolved but erroring preset", () => { return assert.throws( () => { - let opt = new OptionManager(new Logger(null, "unknown")); + const opt = new OptionManager(); opt.init({ - "presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")] + "presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")], }); }, /While processing preset: .*option-manager(?:\/|\\\\)not-a-preset\.js/ ); }); - - it("throws for invalid preset configuration", function() { - return assert.throws( - function () { - let opt = new OptionManager(new Logger(null, "unknown")); - opt.init({ - "presets": [{ option: "value" }] - }); - }, - /Unknown option: foreign.option\.(?:.|\n)+A common cause of this error is the presence of a configuration options object without the corresponding preset name/ - ); - }); }); describe("presets", function () { function presetTest(name) { it(name, function () { - let opt = new OptionManager(new Logger(null, "unknown")); - let options = opt.init({ - "presets": [path.join(__dirname, "fixtures/option-manager/presets", name)] + const opt = new OptionManager(); + const options = opt.init({ + "presets": [path.join(__dirname, "fixtures/option-manager/presets", name)], }); assert.equal(true, Array.isArray(options.plugins)); @@ -77,14 +65,22 @@ describe("option-manager", () => { }); } - presetTest("es5"); - presetTest("es5_function"); - presetTest("es2015_default"); - presetTest("es2015_default_function"); - presetTest("es2015_default_object_function"); - presetTest("es2015_function"); - presetTest("es2015_function_fallback"); - presetTest("es2015_named"); + function presetThrowsTest(name, msg) { + it(name, function () { + const opt = new OptionManager(); + assert.throws(() => opt.init({ + "presets": [path.join(__dirname, "fixtures/option-manager/presets", name)], + }), msg); + }); + } + presetTest("es5_function"); + presetTest("es5_object"); + presetTest("es2015_default_function"); + presetTest("es2015_default_object"); + + presetThrowsTest("es2015_named", /Preset must export a default export when using ES6 modules/); + presetThrowsTest("es2015_invalid", /Unsupported preset format: string/); + presetThrowsTest("es5_invalid", /Unsupported preset format: string/); }); }); diff --git a/packages/babel-core/test/path.js b/packages/babel-core/test/path.js index c76fc31e59..f84d7eef8e 100644 --- a/packages/babel-core/test/path.js +++ b/packages/babel-core/test/path.js @@ -1,28 +1,28 @@ -let transform = require("../lib/api/node").transform; -let Plugin = require("../lib/transformation/plugin"); -let chai = require("chai"); +import { transform } from "../lib/index"; +import Plugin from "../lib/transformation/plugin"; +import chai from "chai"; describe("traversal path", function () { it("replaceWithSourceString", function () { - let expectCode = "function foo() {}"; + const expectCode = "function foo() {}"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { FunctionDeclaration: function (path) { path.replaceWithSourceString("console.whatever()"); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("console.whatever();"); }); it("replaceWith (arrow expression body to block statement body)", function () { - let expectCode = "var fn = () => true;"; + const expectCode = "var fn = () => true;"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ArrowFunctionExpression: function (path) { @@ -32,41 +32,41 @@ describe("traversal path", function () { type: "ReturnStatement", argument: { type: "BooleanLiteral", - value: true - } - }] + value: true, + }, + }], }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("var fn = () => {\n return true;\n};"); }); it("replaceWith (arrow block statement body to expression body)", function () { - let expectCode = "var fn = () => { return true; }"; + const expectCode = "var fn = () => { return true; }"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ArrowFunctionExpression: function (path) { path.get("body").replaceWith({ type: "BooleanLiteral", - value: true + value: true, }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("var fn = () => true;"); }); it("replaceWith (for-in left expression to variable declaration)", function () { - let expectCode = "for (KEY in right);"; + const expectCode = "for (KEY in right);"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ForInStatement: function (path) { @@ -77,41 +77,41 @@ describe("traversal path", function () { type: "VariableDeclarator", id: { type: "Identifier", - name: "KEY" - } - }] + name: "KEY", + }, + }], }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("for (var KEY in right);"); }); it("replaceWith (for-in left variable declaration to expression)", function () { - let expectCode = "for (var KEY in right);"; + const expectCode = "for (var KEY in right);"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ForInStatement: function (path) { path.get("left").replaceWith({ type: "Identifier", - name: "KEY" + name: "KEY", }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("for (KEY in right);"); }); it("replaceWith (for-loop left expression to variable declaration)", function () { - let expectCode = "for (KEY;;);"; + const expectCode = "for (KEY;;);"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ForStatement: function (path) { @@ -122,32 +122,32 @@ describe("traversal path", function () { type: "VariableDeclarator", id: { type: "Identifier", - name: "KEY" - } - }] + name: "KEY", + }, + }], }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("for (var KEY;;);"); }); it("replaceWith (for-loop left variable declaration to expression)", function () { - let expectCode = "for (var KEY;;);"; + const expectCode = "for (var KEY;;);"; - let actualCode = transform(expectCode, { + const actualCode = transform(expectCode, { plugins: [new Plugin({ visitor: { ForStatement: function (path) { path.get("init").replaceWith({ type: "Identifier", - name: "KEY" + name: "KEY", }); - } - } - })] + }, + }, + })], }).code; chai.expect(actualCode).to.be.equal("for (KEY;;);"); diff --git a/packages/babel-core/test/plugins.js b/packages/babel-core/test/plugins.js index 1ca0caf9ca..0f1e3245ad 100644 --- a/packages/babel-core/test/plugins.js +++ b/packages/babel-core/test/plugins.js @@ -1 +1,3 @@ -require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/plugins", "plugins"); +import runner from "babel-helper-transform-fixture-test-runner"; + +runner(`${__dirname}/fixtures/plugins`, "plugins"); diff --git a/packages/babel-core/test/resolution.js b/packages/babel-core/test/resolution.js index bdffce466d..d65c7e9028 100644 --- a/packages/babel-core/test/resolution.js +++ b/packages/babel-core/test/resolution.js @@ -1,14 +1,14 @@ -let assert = require("assert"); -let async = require("async"); -let babel = require("../lib/api/node"); -let fs = require("fs"); -let path = require("path"); +import assert from "assert"; +import async from "async"; +import * as babel from "../lib/index"; +import fs from "fs"; +import path from "path"; // Test that plugins & presets are resolved relative to `filename`. describe("addon resolution", function () { it("addon resolution", function (done) { - let fixtures = {}; - let paths = {}; + const fixtures = {}; + const paths = {}; paths.fixtures = path.join( __dirname, @@ -33,7 +33,7 @@ describe("addon resolution", function () { function fixturesReady (err) { if (err) return done(err); - let actual = babel.transform(fixtures.actual, { + const actual = babel.transform(fixtures.actual, { filename: paths.actual, plugins: ["addons/plugin"], presets: ["addons/preset"], diff --git a/packages/babel-core/test/transformation.js b/packages/babel-core/test/transformation.js index 1bacd85623..6b663895d6 100644 --- a/packages/babel-core/test/transformation.js +++ b/packages/babel-core/test/transformation.js @@ -1 +1,3 @@ -require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/transformation", "transformation"); +import runner from "babel-helper-transform-fixture-test-runner"; + +runner(`${__dirname}/fixtures/transformation`, "transformation"); diff --git a/packages/babel-core/test/util.js b/packages/babel-core/test/util.js index ae1e83e913..5d84ad41f6 100644 --- a/packages/babel-core/test/util.js +++ b/packages/babel-core/test/util.js @@ -1,6 +1,6 @@ -let assert = require("assert"); -let util = require("../lib/util"); -let t = require("babel-types"); +import assert from "assert"; +import * as util from "../lib/util"; +import * as t from "babel-types"; describe("util", function () { it("canCompile", function () { @@ -36,7 +36,7 @@ describe("util", function () { assert.deepEqual(util.list(["foo", "bar"]), ["foo", "bar"]); assert.deepEqual(util.list(/foo/), [/foo/]); - let date = new Date; + const date = new Date; assert.deepEqual(util.list(date), [date]); }); @@ -84,8 +84,8 @@ describe("util", function () { }); it("shouldIgnore", function () { - let reIgnore = /\-reIgnore\.js/; - let fnIgnore = function (src) { + const reIgnore = /\-reIgnore\.js/; + const fnIgnore = function (src) { if (src.indexOf("fnIgnore") > 0) { return true; } diff --git a/packages/babel-generator/README.md b/packages/babel-generator/README.md index 46a4c051b3..b71ee3c14f 100644 --- a/packages/babel-generator/README.md +++ b/packages/babel-generator/README.md @@ -35,9 +35,7 @@ comments | boolean | `true` | Should comments be include compact | boolean or `'auto'` | `opts.minified` | Set to `true` to avoid adding whitespace for formatting minified | boolean | `false` | Should the output be minified concise | boolean | `false` | Set to `true` to reduce whitespace (but not as much as `opts.compact`) -quotes | `'single'` or `'double'` | autodetect based on `ast.tokens` | The type of quote to use in the output filename | string | | Used in warning messages -flowCommaSeparator | boolean | `false` | Set to `true` to use commas instead of semicolons as Flow property separators jsonCompatibleStrings | boolean | `false` | Set to true to run `jsesc` with "json": true to print "\u00A9" vs. "©"; Options for source maps: diff --git a/packages/babel-generator/package.json b/packages/babel-generator/package.json index 3a1dc1ab2a..eb9900f150 100644 --- a/packages/babel-generator/package.json +++ b/packages/babel-generator/package.json @@ -1,6 +1,6 @@ { "name": "babel-generator", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Turns an AST into code.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -11,16 +11,16 @@ "lib" ], "dependencies": { - "babel-messages": "^6.8.0", - "babel-runtime": "^6.20.0", - "babel-types": "^6.21.0", + "babel-messages": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", "detect-indent": "^4.0.0", "jsesc": "^1.3.0", "lodash": "^4.2.0", - "source-map": "^0.5.0" + "source-map": "^0.5.0", + "trim-right": "^1.0.1" }, "devDependencies": { - "babel-helper-fixtures": "^6.20.0", - "babylon": "^6.11.0" + "babel-helper-fixtures": "7.0.0-alpha.1", + "babylon": "7.0.0-beta.4" } } diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js index 69c61db864..3c53ef666d 100644 --- a/packages/babel-generator/src/buffer.js +++ b/packages/babel-generator/src/buffer.js @@ -1,5 +1,5 @@ import type SourceMap from "./source-map"; -import trimEnd from "lodash/trimEnd"; +import trimRight from "trim-right"; const SPACES_RE = /^[ \t]+$/; @@ -40,7 +40,9 @@ export default class Buffer { const map = this._map; const result = { - code: trimEnd(this._buf.join("")), + // Whatever trim is used here should not execute a regex against the + // source string since it may be arbitrarily large after all transformations + code: trimRight(this._buf.join("")), map: null, rawMappings: map && map.getRawMappings(), }; @@ -55,7 +57,7 @@ export default class Buffer { return this.map = map.get(); }, set(value) { - Object.defineProperty(this, "map", {value, writable: true}); + Object.defineProperty(this, "map", { value, writable: true }); }, }); } @@ -153,7 +155,7 @@ export default class Buffer { source(prop: string, loc: Location): void { if (prop && !loc) return; - let pos = loc ? loc[prop] : null; + const pos = loc ? loc[prop] : null; this._sourcePosition.identifierName = loc && loc.identifierName || null; this._sourcePosition.line = pos ? pos.line : null; @@ -169,10 +171,10 @@ export default class Buffer { if (!this._map) return cb(); // Use the call stack to manage a stack of "source location" data. - let originalLine = this._sourcePosition.line; - let originalColumn = this._sourcePosition.column; - let originalFilename = this._sourcePosition.filename; - let originalIdentifierName = this._sourcePosition.identifierName; + const originalLine = this._sourcePosition.line; + const originalColumn = this._sourcePosition.column; + const originalFilename = this._sourcePosition.filename; + const originalIdentifierName = this._sourcePosition.identifierName; this.source(prop, loc); diff --git a/packages/babel-generator/src/generators/base.js b/packages/babel-generator/src/generators/base.js index dec9fe11bf..ec2dd76364 100644 --- a/packages/babel-generator/src/generators/base.js +++ b/packages/babel-generator/src/generators/base.js @@ -15,7 +15,7 @@ export function BlockStatement(node: Object) { this.token("{"); this.printInnerComments(node); - let hasDirectives = node.directives && node.directives.length; + const hasDirectives = node.directives && node.directives.length; if (node.body.length || hasDirectives) { this.newline(); diff --git a/packages/babel-generator/src/generators/classes.js b/packages/babel-generator/src/generators/classes.js index 67c3aed42b..64066a04cd 100644 --- a/packages/babel-generator/src/generators/classes.js +++ b/packages/babel-generator/src/generators/classes.js @@ -81,10 +81,5 @@ export function ClassMethod(node: Object) { this.space(); } - if (node.kind === "constructorCall") { - this.word("call"); - this.space(); - } - this._method(node); } diff --git a/packages/babel-generator/src/generators/expressions.js b/packages/babel-generator/src/generators/expressions.js index b38cebed54..a3600f83b5 100644 --- a/packages/babel-generator/src/generators/expressions.js +++ b/packages/babel-generator/src/generators/expressions.js @@ -1,6 +1,3 @@ -/* eslint max-len: 0 */ - -import isNumber from "lodash/isNumber"; import * as t from "babel-types"; import * as n from "../node"; @@ -94,7 +91,7 @@ export function CallExpression(node: Object) { this.token("("); - let isPrettyCall = node._prettyCall; + const isPrettyCall = node._prettyCall; let separator; if (isPrettyCall) { @@ -127,15 +124,15 @@ function buildYieldAwait(keyword: string) { if (node.argument) { this.space(); - let terminatorState = this.startTerminatorless(); + const terminatorState = this.startTerminatorless(); this.print(node.argument, node); this.endTerminatorless(terminatorState); } }; } -export let YieldExpression = buildYieldAwait("yield"); -export let AwaitExpression = buildYieldAwait("await"); +export const YieldExpression = buildYieldAwait("yield"); +export const AwaitExpression = buildYieldAwait("await"); export function EmptyStatement() { this.semicolon(true /* force */); @@ -159,7 +156,7 @@ export function AssignmentPattern(node: Object) { export function AssignmentExpression(node: Object, parent: Object) { // Somewhere inside a for statement `init` node but doesn't usually // needs a paren except for `in` expressions: `for (a in b ? a : b;;)` - let parens = this.inForStatementInitCounter && node.operator === "in" && + const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); if (parens) { @@ -191,7 +188,7 @@ export function BindExpression(node: Object) { export { AssignmentExpression as BinaryExpression, - AssignmentExpression as LogicalExpression + AssignmentExpression as LogicalExpression, }; export function MemberExpression(node: Object) { @@ -202,7 +199,7 @@ export function MemberExpression(node: Object) { } let computed = node.computed; - if (t.isLiteral(node.property) && isNumber(node.property.value)) { + if (t.isLiteral(node.property) && typeof node.property.value === "number") { computed = true; } diff --git a/packages/babel-generator/src/generators/flow.js b/packages/babel-generator/src/generators/flow.js index 9ef56bdde4..279502b928 100644 --- a/packages/babel-generator/src/generators/flow.js +++ b/packages/babel-generator/src/generators/flow.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - export function AnyTypeAnnotation() { this.word("any"); } @@ -81,7 +79,7 @@ export function DeclareVariable(node: Object) { this.semicolon(); } -export function ExistentialTypeParam() { +export function ExistsTypeAnnotation() { this.token("*"); } @@ -148,10 +146,12 @@ export function _interfaceish(node: Object) { } export function _variance(node) { - if (node.variance === "plus") { - this.token("+"); - } else if (node.variance === "minus") { - this.token("-"); + if (node.variance) { + if (node.variance.kind === "plus") { + this.token("+"); + } else if (node.variance.kind === "minus") { + this.token("-"); + } } } @@ -185,7 +185,7 @@ export function NullableTypeAnnotation(node: Object) { } export { - NumericLiteral as NumericLiteralTypeAnnotation, + NumericLiteral as NumberLiteralTypeAnnotation, StringLiteral as StringLiteralTypeAnnotation, } from "./types"; @@ -264,7 +264,7 @@ export function ObjectTypeAnnotation(node: Object) { this.token("{"); } - let props = node.properties.concat(node.callProperties, node.indexers); + const props = node.properties.concat(node.callProperties, node.indexers); if (props.length) { this.space(); @@ -277,14 +277,10 @@ export function ObjectTypeAnnotation(node: Object) { statement: true, iterator: () => { if (props.length !== 1) { - if (this.format.flowCommaSeparator) { - this.token(","); - } else { - this.semicolon(); - } + this.token(","); this.space(); } - } + }, }); this.space(); diff --git a/packages/babel-generator/src/generators/index.js b/packages/babel-generator/src/generators/index.js new file mode 100644 index 0000000000..61db3d68ec --- /dev/null +++ b/packages/babel-generator/src/generators/index.js @@ -0,0 +1,10 @@ +export * from "./template-literals"; +export * from "./expressions"; +export * from "./statements"; +export * from "./classes"; +export * from "./methods"; +export * from "./modules"; +export * from "./types"; +export * from "./flow"; +export * from "./base"; +export * from "./jsx"; diff --git a/packages/babel-generator/src/generators/jsx.js b/packages/babel-generator/src/generators/jsx.js index 7da237ff6a..521b479ae0 100644 --- a/packages/babel-generator/src/generators/jsx.js +++ b/packages/babel-generator/src/generators/jsx.js @@ -47,12 +47,12 @@ export function JSXText(node: Object) { } export function JSXElement(node: Object) { - let open = node.openingElement; + const open = node.openingElement; this.print(open, node); if (open.selfClosing) return; this.indent(); - for (let child of (node.children: Array)) { + for (const child of (node.children: Array)) { this.print(child, node); } this.dedent(); diff --git a/packages/babel-generator/src/generators/methods.js b/packages/babel-generator/src/generators/methods.js index 720aa0c87b..4dcc71a251 100644 --- a/packages/babel-generator/src/generators/methods.js +++ b/packages/babel-generator/src/generators/methods.js @@ -7,7 +7,7 @@ export function _params(node: Object) { iterator: (node) => { if (node.optional) this.token("?"); this.print(node.typeAnnotation, node); - } + }, }); this.token(")"); @@ -17,8 +17,8 @@ export function _params(node: Object) { } export function _method(node: Object) { - let kind = node.kind; - let key = node.key; + const kind = node.kind; + const key = node.key; if (kind === "method" || kind === "init") { if (node.generator) { @@ -93,5 +93,6 @@ export function ArrowFunctionExpression(node: Object) { } function hasTypes(node, param) { - return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments; + return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || + param.trailingComments; } diff --git a/packages/babel-generator/src/generators/modules.js b/packages/babel-generator/src/generators/modules.js index 6a87a02512..3d6fbae1e2 100644 --- a/packages/babel-generator/src/generators/modules.js +++ b/packages/babel-generator/src/generators/modules.js @@ -1,6 +1,11 @@ import * as t from "babel-types"; export function ImportSpecifier(node: Object) { + if (node.importKind === "type" || node.importKind === "typeof") { + this.word(node.importKind); + this.space(); + } + this.print(node.imported, node); if (node.local && node.local.name !== node.imported.name) { this.space(); @@ -40,12 +45,6 @@ export function ExportAllDeclaration(node: Object) { this.word("export"); this.space(); this.token("*"); - if (node.exported) { - this.space(); - this.word("as"); - this.space(); - this.print(node.exported, node); - } this.space(); this.word("from"); this.space(); @@ -69,7 +68,7 @@ export function ExportDefaultDeclaration() { function ExportDeclaration(node: Object) { if (node.declaration) { - let declar = node.declaration; + const declar = node.declaration; this.print(declar, node); if (!t.isStatement(declar)) this.semicolon(); } else { @@ -78,12 +77,12 @@ function ExportDeclaration(node: Object) { this.space(); } - let specifiers = node.specifiers.slice(0); + const specifiers = node.specifiers.slice(0); // print "special" specifiers first let hasSpecial = false; while (true) { - let first = specifiers[0]; + const first = specifiers[0]; if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { hasSpecial = true; this.print(specifiers.shift(), node); @@ -126,11 +125,11 @@ export function ImportDeclaration(node: Object) { this.space(); } - let specifiers = node.specifiers.slice(0); + const specifiers = node.specifiers.slice(0); if (specifiers && specifiers.length) { // print "special" specifiers first while (true) { - let first = specifiers[0]; + const first = specifiers[0]; if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { this.print(specifiers.shift(), node); if (specifiers.length) { diff --git a/packages/babel-generator/src/generators/statements.js b/packages/babel-generator/src/generators/statements.js index a5ec481882..8aee284a6d 100644 --- a/packages/babel-generator/src/generators/statements.js +++ b/packages/babel-generator/src/generators/statements.js @@ -17,7 +17,7 @@ export function IfStatement(node: Object) { this.token(")"); this.space(); - let needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); + const needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); if (needsBlock) { this.token("{"); this.newline(); @@ -80,17 +80,15 @@ export function WhileStatement(node: Object) { this.printBlock(node); } -let buildForXStatement = function (op) { +const buildForXStatement = function (op) { return function (node: Object) { this.word("for"); this.space(); - if (op === "await") { + if (op === "of" && node.await) { this.word("await"); this.space(); - op = "of"; } this.token("("); - this.print(node.left, node); this.space(); this.word(op); @@ -101,9 +99,8 @@ let buildForXStatement = function (op) { }; }; -export let ForInStatement = buildForXStatement("in"); -export let ForOfStatement = buildForXStatement("of"); -export let ForAwaitStatement = buildForXStatement("await"); +export const ForInStatement = buildForXStatement("in"); +export const ForOfStatement = buildForXStatement("of"); export function DoWhileStatement(node: Object) { this.word("do"); @@ -122,11 +119,11 @@ function buildLabelStatement(prefix, key = "label") { return function (node: Object) { this.word(prefix); - let label = node[key]; + const label = node[key]; if (label) { this.space(); - let terminatorState = this.startTerminatorless(); + const terminatorState = this.startTerminatorless(); this.print(label, node); this.endTerminatorless(terminatorState); } @@ -135,10 +132,10 @@ function buildLabelStatement(prefix, key = "label") { }; } -export let ContinueStatement = buildLabelStatement("continue"); -export let ReturnStatement = buildLabelStatement("return", "argument"); -export let BreakStatement = buildLabelStatement("break"); -export let ThrowStatement = buildLabelStatement("throw", "argument"); +export const ContinueStatement = buildLabelStatement("continue"); +export const ReturnStatement = buildLabelStatement("return", "argument"); +export const BreakStatement = buildLabelStatement("break"); +export const ThrowStatement = buildLabelStatement("throw", "argument"); export function LabeledStatement(node: Object) { this.print(node.label, node); @@ -193,7 +190,7 @@ export function SwitchStatement(node: Object) { indent: true, addNewlines(leading, cas) { if (!leading && node.cases[node.cases.length - 1] === cas) return -1; - } + }, }); this.token("}"); @@ -221,14 +218,14 @@ export function DebuggerStatement() { this.semicolon(); } -function variableDeclarationIdent() { +function variableDeclarationIndent() { // "let " or "var " indentation. this.token(","); this.newline(); if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true); } -function constDeclarationIdent() { +function constDeclarationIndent() { // "const " indentation. this.token(","); this.newline(); @@ -242,7 +239,7 @@ export function VariableDeclaration(node: Object, parent: Object) { let hasInits = false; // don't add whitespace to loop heads if (!t.isFor(parent)) { - for (let declar of (node.declarations: Array)) { + for (const declar of (node.declarations: Array)) { if (declar.init) { // has an init so let's split it up over multiple lines hasInits = true; @@ -264,7 +261,7 @@ export function VariableDeclaration(node: Object, parent: Object) { let separator; if (hasInits) { - separator = node.kind === "const" ? constDeclarationIdent : variableDeclarationIdent; + separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent; } // diff --git a/packages/babel-generator/src/generators/template-literals.js b/packages/babel-generator/src/generators/template-literals.js index a8234a00a8..a49b8615ed 100644 --- a/packages/babel-generator/src/generators/template-literals.js +++ b/packages/babel-generator/src/generators/template-literals.js @@ -7,15 +7,13 @@ export function TemplateElement(node: Object, parent: Object) { const isFirst = parent.quasis[0] === node; const isLast = parent.quasis[parent.quasis.length - 1] === node; - let value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); + const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); - if (!isFirst) this.space(); this.token(value); - if (!isLast) this.space(); } export function TemplateLiteral(node: Object) { - let quasis = node.quasis; + const quasis = node.quasis; for (let i = 0; i < quasis.length; i++) { this.print(quasis[i], node); diff --git a/packages/babel-generator/src/generators/types.js b/packages/babel-generator/src/generators/types.js index 3f803c8e11..9895324062 100644 --- a/packages/babel-generator/src/generators/types.js +++ b/packages/babel-generator/src/generators/types.js @@ -1,22 +1,7 @@ -/* eslint max-len: 0 */ -/* eslint quotes: 0 */ - import * as t from "babel-types"; import jsesc from "jsesc"; export function Identifier(node: Object) { - // FIXME: We hang variance off Identifer to support Flow's def-site variance. - // This is a terrible hack, but changing type annotations to use a new, - // dedicated node would be a breaking change. This should be cleaned up in - // the next major. - if (node.variance) { - if (node.variance === "plus") { - this.token("+"); - } else if (node.variance === "minus") { - this.token("-"); - } - } - this.word(node.name); } @@ -27,12 +12,10 @@ export function RestElement(node: Object) { export { RestElement as SpreadElement, - RestElement as SpreadProperty, - RestElement as RestProperty, }; export function ObjectExpression(node: Object) { - let props = node.properties; + const props = node.properties; this.token("{"); this.printInnerComments(node); @@ -62,7 +45,8 @@ export function ObjectProperty(node: Object) { this.token("]"); } else { // print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});` - if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) { + if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && + node.key.name === node.value.left.name) { this.print(node.value, node); return; } @@ -84,14 +68,14 @@ export function ObjectProperty(node: Object) { } export function ArrayExpression(node: Object) { - let elems = node.elements; - let len = elems.length; + const elems = node.elements; + const len = elems.length; this.token("["); this.printInnerComments(node); for (let i = 0; i < elems.length; i++) { - let elem = elems[i]; + const elem = elems[i]; if (elem) { if (i > 0) this.space(); this.print(elem, node); @@ -136,7 +120,7 @@ export function NumericLiteral(node: Object) { } export function StringLiteral(node: Object, parent: Object) { - let raw = this.getPossibleRaw(node); + const raw = this.getPossibleRaw(node); if (!this.format.minified && raw != null) { this.token(raw); return; @@ -145,12 +129,12 @@ export function StringLiteral(node: Object, parent: Object) { // ensure the output is ASCII-safe const opts = { quotes: t.isJSX(parent) ? "double" : this.format.quotes, - wrap: true + wrap: true, }; if (this.format.jsonCompatibleStrings) { opts.json = true; } - let val = jsesc(node.value, opts); + const val = jsesc(node.value, opts); return this.token(val); } diff --git a/packages/babel-generator/src/index.js b/packages/babel-generator/src/index.js index c212cbdf7c..5be44e2d02 100644 --- a/packages/babel-generator/src/index.js +++ b/packages/babel-generator/src/index.js @@ -2,7 +2,7 @@ import detectIndent from "detect-indent"; import SourceMap from "./source-map"; import * as messages from "babel-messages"; import Printer from "./printer"; -import type {Format} from "./printer"; +import type { Format } from "./printer"; /** * Babel's code generator, turns an ast into code, maintaining sourcemaps, @@ -10,12 +10,10 @@ import type {Format} from "./printer"; */ class Generator extends Printer { - constructor(ast, opts, code) { - opts = opts || {}; - + constructor(ast, opts = {}, code) { const tokens = ast.tokens || []; - let format = normalizeOptions(code, opts, tokens); - let map = opts.sourceMaps ? new SourceMap(opts, code) : null; + const format = normalizeOptions(code, opts, tokens); + const map = opts.sourceMaps ? new SourceMap(opts, code) : null; super(format, map, tokens); this.ast = ast; @@ -44,11 +42,11 @@ class Generator extends Printer { function normalizeOptions(code, opts, tokens): Format { let style = " "; if (code && typeof code === "string") { - let indent = detectIndent(code).indent; + const indent = detectIndent(code).indent; if (indent && indent !== " ") style = indent; } - let format = { + const format = { auxiliaryCommentBefore: opts.auxiliaryCommentBefore, auxiliaryCommentAfter: opts.auxiliaryCommentAfter, shouldPrintComment: opts.shouldPrintComment, @@ -58,14 +56,13 @@ function normalizeOptions(code, opts, tokens): Format { compact: opts.compact, minified: opts.minified, concise: opts.concise, - quotes: opts.quotes || findCommonStringDelimiter(code, tokens), + quotes: findCommonStringDelimiter(code, tokens), jsonCompatibleStrings: opts.jsonCompatibleStrings, indent: { adjustMultilineComment: true, style: style, - base: 0 + base: 0, }, - flowCommaSeparator: opts.flowCommaSeparator, }; if (format.minified) { @@ -101,18 +98,18 @@ function findCommonStringDelimiter(code, tokens) { return DEFAULT_STRING_DELIMITER; } - let occurences = { + const occurences = { single: 0, - double: 0 + double: 0, }; let checked = 0; for (let i = 0; i < tokens.length; i++) { - let token = tokens[i]; + const token = tokens[i]; if (token.type.label !== "string") continue; - let raw = code.slice(token.start, token.end); + const raw = code.slice(token.start, token.end); if (raw[0] === "'") { occurences.single++; } else { @@ -145,6 +142,6 @@ export class CodeGenerator { } export default function (ast: Object, opts: Object, code: string): Object { - let gen = new Generator(ast, opts, code); + const gen = new Generator(ast, opts, code); return gen.generate(); } diff --git a/packages/babel-generator/src/node/index.js b/packages/babel-generator/src/node/index.js index 971f478a3d..c3a17cea6c 100644 --- a/packages/babel-generator/src/node/index.js +++ b/packages/babel-generator/src/node/index.js @@ -1,24 +1,24 @@ -import whitespace from "./whitespace"; +import * as whitespace from "./whitespace"; import * as parens from "./parentheses"; import * as t from "babel-types"; function expandAliases(obj) { - let newObj = {}; + const newObj = {}; function add(type, func) { - let fn = newObj[type]; + const fn = newObj[type]; newObj[type] = fn ? function(node, parent, stack) { - let result = fn(node, parent, stack); + const result = fn(node, parent, stack); return result == null ? func(node, parent, stack) : result; } : func; } - for (let type of Object.keys(obj)) { + for (const type of Object.keys(obj)) { - let aliases = t.FLIPPED_ALIAS_KEYS[type]; + const aliases = t.FLIPPED_ALIAS_KEYS[type]; if (aliases) { - for (let alias of aliases) { + for (const alias of aliases) { add(alias, obj[type]); } } else { @@ -31,12 +31,12 @@ function expandAliases(obj) { // Rather than using `t.is` on each object property, we pre-expand any type aliases // into concrete types so that the 'find' call below can be as fast as possible. -let expandedParens = expandAliases(parens); -let expandedWhitespaceNodes = expandAliases(whitespace.nodes); -let expandedWhitespaceList = expandAliases(whitespace.list); +const expandedParens = expandAliases(parens); +const expandedWhitespaceNodes = expandAliases(whitespace.nodes); +const expandedWhitespaceList = expandAliases(whitespace.list); function find(obj, node, parent, printStack) { - let fn = obj[node.type]; + const fn = obj[node.type]; return fn ? fn(node, parent, printStack) : null; } @@ -63,7 +63,7 @@ export function needsWhitespace(node, parent, type) { let linesInfo = find(expandedWhitespaceNodes, node, parent); if (!linesInfo) { - let items = find(expandedWhitespaceList, node, parent); + const items = find(expandedWhitespaceList, node, parent); if (items) { for (let i = 0; i < items.length; i++) { linesInfo = needsWhitespace(items[i], node, type); diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index 199252d96e..79ef9b448c 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -24,7 +24,7 @@ const PRECEDENCE = { "*": 9, "/": 9, "%": 9, - "**": 10 + "**": 10, }; export function NullableTypeAnnotation(node: Object, parent: Object): boolean { @@ -34,44 +34,40 @@ export function NullableTypeAnnotation(node: Object, parent: Object): boolean { export { NullableTypeAnnotation as FunctionTypeAnnotation }; export function UpdateExpression(node: Object, parent: Object): boolean { - if (t.isMemberExpression(parent) && parent.object === node) { - // (foo++).test() - return true; - } - - return false; + // (foo++).test() + return t.isMemberExpression(parent) && parent.object === node; } export function ObjectExpression(node: Object, parent: Object, printStack: Array): boolean { - return isFirstInStatement(printStack, {considerArrow: true}); + return isFirstInStatement(printStack, { considerArrow: true }); +} + +export function DoExpression(node: Object, parent: Object, printStack: Array): boolean { + return isFirstInStatement(printStack); } export function Binary(node: Object, parent: Object): boolean { - if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) { - return true; - } - - if (t.isUnaryLike(parent)) { - return true; - } - - if (t.isMemberExpression(parent) && parent.object === node) { + if ( + ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) || + t.isUnaryLike(parent) || + (t.isMemberExpression(parent) && parent.object === node) || + t.isAwaitExpression(parent) + ) { return true; } if (t.isBinary(parent)) { - let parentOp = parent.operator; - let parentPos = PRECEDENCE[parentOp]; + const parentOp = parent.operator; + const parentPos = PRECEDENCE[parentOp]; - let nodeOp = node.operator; - let nodePos = PRECEDENCE[nodeOp]; + const nodeOp = node.operator; + const nodePos = PRECEDENCE[nodeOp]; - if (parentPos > nodePos) { - return true; - } - - // Logical expressions with the same precedence don't need parens. - if (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent)) { + if ( + // Logical expressions with the same precedence don't need parens. + (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent)) || + parentPos > nodePos + ) { return true; } } @@ -80,55 +76,27 @@ export function Binary(node: Object, parent: Object): boolean { } export function BinaryExpression(node: Object, parent: Object): boolean { - if (node.operator === "in") { - // let i = (1 in []); - if (t.isVariableDeclarator(parent)) { - return true; - } - - // for ((1 in []);;); - if (t.isFor(parent)) { - return true; - } - } - - return false; + // let i = (1 in []); + // for ((1 in []);;); + return node.operator === "in" && (t.isVariableDeclarator(parent) || t.isFor(parent)); } export function SequenceExpression(node: Object, parent: Object): boolean { - if (t.isForStatement(parent)) { + + if ( // Although parentheses wouldn"t hurt around sequence // expressions in the head of for loops, traditional style // dictates that e.g. i++, j++ should not be wrapped with // parentheses. - return false; - } - - if (t.isExpressionStatement(parent) && parent.expression === node) { - return false; - } - - if (t.isReturnStatement(parent)) { - return false; - } - - if (t.isThrowStatement(parent)) { - return false; - } - - if (t.isSwitchStatement(parent) && parent.discriminant === node) { - return false; - } - - if (t.isWhileStatement(parent) && parent.test === node) { - return false; - } - - if (t.isIfStatement(parent) && parent.test === node) { - return false; - } - - if (t.isForInStatement(parent) && parent.right === node) { + t.isForStatement(parent) || + t.isThrowStatement(parent) || + t.isReturnStatement(parent) || + (t.isIfStatement(parent) && parent.test === node) || + (t.isWhileStatement(parent) && parent.test === node) || + (t.isForInStatement(parent) && parent.right === node) || + (t.isSwitchStatement(parent) && parent.discriminant === node) || + (t.isExpressionStatement(parent) && parent.expression === node) + ) { return false; } @@ -150,36 +118,28 @@ export function YieldExpression(node: Object, parent: Object): boolean { export { YieldExpression as AwaitExpression }; export function ClassExpression(node: Object, parent: Object, printStack: Array): boolean { - return isFirstInStatement(printStack, {considerDefaultExports: true}); + return isFirstInStatement(printStack, { considerDefaultExports: true }); } export function UnaryLike(node: Object, parent: Object): boolean { - if (t.isMemberExpression(parent, { object: node })) { - return true; - } - - if (t.isCallExpression(parent, { callee: node }) || t.isNewExpression(parent, { callee: node })) { - return true; - } - - return false; + return t.isMemberExpression(parent, { object: node }) || + t.isCallExpression(parent, { callee: node }) || + t.isNewExpression(parent, { callee: node }); } export function FunctionExpression(node: Object, parent: Object, printStack: Array): boolean { - return isFirstInStatement(printStack, {considerDefaultExports: true}); + return isFirstInStatement(printStack, { considerDefaultExports: true }); } export function ArrowFunctionExpression(node: Object, parent: Object): boolean { - // export default (function () {}); - if (t.isExportDeclaration(parent)) { - return true; - } - - if (t.isBinaryExpression(parent) || t.isLogicalExpression(parent)) { - return true; - } - - if (t.isUnaryExpression(parent)) { + if ( + // export default (function () {}); + t.isExportDeclaration(parent) || + t.isBinaryExpression(parent) || + t.isLogicalExpression(parent) || + t.isUnaryExpression(parent) || + t.isTaggedTemplateExpression(parent) + ) { return true; } @@ -187,15 +147,12 @@ export function ArrowFunctionExpression(node: Object, parent: Object): boolean { } export function ConditionalExpression(node: Object, parent: Object): boolean { - if (t.isUnaryLike(parent)) { - return true; - } - - if (t.isBinary(parent)) { - return true; - } - - if (t.isConditionalExpression(parent, { test: node })) { + if ( + t.isUnaryLike(parent) || + t.isBinary(parent) || + t.isConditionalExpression(parent, { test: node }) || + t.isAwaitExpression(parent) + ) { return true; } @@ -214,31 +171,30 @@ export function AssignmentExpression(node: Object): boolean { // in statement. function isFirstInStatement(printStack: Array, { considerArrow = false, - considerDefaultExports = false + considerDefaultExports = false, } = {}): boolean { let i = printStack.length - 1; let node = printStack[i]; i--; let parent = printStack[i]; while (i > 0) { - if (t.isExpressionStatement(parent, { expression: node })) { + if ( + t.isExpressionStatement(parent, { expression: node }) || + t.isTaggedTemplateExpression(parent) || + considerDefaultExports && t.isExportDefaultDeclaration(parent, { declaration: node }) || + considerArrow && t.isArrowFunctionExpression(parent, { body: node }) + ) { return true; } - if (considerDefaultExports && t.isExportDefaultDeclaration(parent, { declaration: node })) { - return true; - } - - if (considerArrow && t.isArrowFunctionExpression(parent, { body: node })) { - return true; - } - - if ((t.isCallExpression(parent, { callee: node })) || - (t.isSequenceExpression(parent) && parent.expressions[0] === node) || - (t.isMemberExpression(parent, { object: node })) || - (t.isConditional(parent, { test: node })) || - (t.isBinary(parent, { left: node })) || - (t.isAssignmentExpression(parent, { left: node }))) { + if ( + t.isCallExpression(parent, { callee: node }) || + (t.isSequenceExpression(parent) && parent.expressions[0] === node) || + t.isMemberExpression(parent, { object: node }) || + t.isConditional(parent, { test: node }) || + t.isBinary(parent, { left: node }) || + t.isAssignmentExpression(parent, { left: node }) + ) { node = parent; i--; parent = printStack[i]; diff --git a/packages/babel-generator/src/node/whitespace.js b/packages/babel-generator/src/node/whitespace.js index 6ba8522e08..11dce425e6 100644 --- a/packages/babel-generator/src/node/whitespace.js +++ b/packages/babel-generator/src/node/whitespace.js @@ -1,5 +1,3 @@ -import isBoolean from "lodash/isBoolean"; -import each from "lodash/each"; import map from "lodash/map"; import * as t from "babel-types"; @@ -62,18 +60,18 @@ function isType(node) { * Tests for node types that need whitespace. */ -exports.nodes = { +export const nodes = { /** * Test if AssignmentExpression needs whitespace. */ AssignmentExpression(node: Object): ?WhitespaceObject { - let state = crawl(node.right); + const state = crawl(node.right); if ((state.hasCall && state.hasHelper) || state.hasFunction) { return { before: state.hasFunction, - after: true + after: true, }; } }, @@ -84,7 +82,7 @@ exports.nodes = { SwitchCase(node: Object, parent: Object): ?WhitespaceObject { return { - before: node.consequent.length || parent.cases[0] === node + before: node.consequent.length || parent.cases[0] === node, }; }, @@ -95,7 +93,7 @@ exports.nodes = { LogicalExpression(node: Object): ?WhitespaceObject { if (t.isFunction(node.left) || t.isFunction(node.right)) { return { - after: true + after: true, }; } }, @@ -107,7 +105,7 @@ exports.nodes = { Literal(node: Object): ?WhitespaceObject { if (node.value === "use strict") { return { - after: true + after: true, }; } }, @@ -120,7 +118,7 @@ exports.nodes = { if (t.isFunction(node.callee) || isHelper(node)) { return { before: true, - after: true + after: true, }; } }, @@ -131,18 +129,18 @@ exports.nodes = { VariableDeclaration(node: Object): ?WhitespaceObject { for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; + const declar = node.declarations[i]; let enabled = isHelper(declar.id) && !isType(declar.init); if (!enabled) { - let state = crawl(declar.init); + const state = crawl(declar.init); enabled = (isHelper(declar.init) && state.hasCall) || state.hasFunction; } if (enabled) { return { before: true, - after: true + after: true, }; } } @@ -156,23 +154,22 @@ exports.nodes = { if (t.isBlockStatement(node.consequent)) { return { before: true, - after: true + after: true, }; } - } + }, }; /** - * Test if Property or SpreadProperty needs whitespace. + * Test if Property needs whitespace. */ -exports.nodes.ObjectProperty = -exports.nodes.ObjectTypeProperty = -exports.nodes.ObjectMethod = -exports.nodes.SpreadProperty = function (node: Object, parent): ?WhitespaceObject { +nodes.ObjectProperty = +nodes.ObjectTypeProperty = +nodes.ObjectMethod = function (node: Object, parent): ?WhitespaceObject { if (parent.properties[0] === node) { return { - before: true + before: true, }; } }; @@ -181,7 +178,7 @@ exports.nodes.SpreadProperty = function (node: Object, parent): ?WhitespaceObjec * Returns lists from node types that need whitespace. */ -exports.list = { +export const list = { /** * Return VariableDeclaration declarations init properties. @@ -205,27 +202,26 @@ exports.list = { ObjectExpression(node: Object): Array { return node.properties; - } + }, }; /** * Add whitespace tests for nodes and their aliases. */ -each({ - Function: true, - Class: true, - Loop: true, - LabeledStatement: true, - SwitchStatement: true, - TryStatement: true -}, function (amounts, type) { - if (isBoolean(amounts)) { +[ + ["Function", true], + ["Class", true], + ["Loop", true], + ["LabeledStatement", true], + ["SwitchStatement", true], + ["TryStatement", true], +].forEach(function ([type, amounts]) { + if (typeof amounts === "boolean") { amounts = { after: amounts, before: amounts }; } - - each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) { - exports.nodes[type] = function () { + [type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { + nodes[type] = function () { return amounts; }; }); diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index a9af009429..1941b94ace 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import find from "lodash/find"; import findLast from "lodash/findLast"; import isInteger from "lodash/isInteger"; @@ -9,6 +7,8 @@ import * as n from "./node"; import Whitespace from "./whitespace"; import * as t from "babel-types"; +import * as generatorFunctions from "./generators"; + const SCIENTIFIC_NOTATION = /e/i; const ZERO_DECIMAL_INTEGER = /\.0+$/; const NON_DECIMAL_LITERAL = /^0[box]/; @@ -238,7 +238,7 @@ export default class Printer { _maybeAddParen(str: string): void { // see startTerminatorless() instance method - let parenPushNewlineState = this._parenPushNewlineState; + const parenPushNewlineState = this._parenPushNewlineState; if (!parenPushNewlineState) return; this._parenPushNewlineState = null; @@ -295,7 +295,7 @@ export default class Printer { startTerminatorless(): Object { return this._parenPushNewlineState = { - printed: false + printed: false, }; } @@ -314,33 +314,36 @@ export default class Printer { print(node, parent) { if (!node) return; - let oldConcise = this.format.concise; + const oldConcise = this.format.concise; if (node._compact) { this.format.concise = true; } - let printMethod = this[node.type]; + const printMethod = this[node.type]; if (!printMethod) { + // eslint-disable-next-line max-len throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`); } this._printStack.push(node); - let oldInAux = this._insideAux; + const oldInAux = this._insideAux; this._insideAux = !node.loc; this._maybeAddAuxComment(this._insideAux && !oldInAux); let needsParens = n.needsParens(node, parent, this._printStack); - if (this.format.retainFunctionParens && - node.type === "FunctionExpression" && - node.extra && node.extra.parenthesized) { + if ( + this.format.retainFunctionParens && + node.type === "FunctionExpression" && + node.extra && node.extra.parenthesized + ) { needsParens = true; } if (needsParens) this.token("("); this._printLeadingComments(node, parent); - let loc = (t.isProgram(node) || t.isFile(node)) ? null : node.loc; + const loc = (t.isProgram(node) || t.isFile(node)) ? null : node.loc; this.withSource("start", loc, () => { this[node.type](node, parent); }); @@ -369,7 +372,7 @@ export default class Printer { if (comment) { this._printComment({ type: "CommentBlock", - value: comment + value: comment, }); } } @@ -382,13 +385,13 @@ export default class Printer { if (comment) { this._printComment({ type: "CommentBlock", - value: comment + value: comment, }); } } getPossibleRaw(node) { - let extra = node.extra; + const extra = node.extra; if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { return extra.raw; } @@ -426,14 +429,14 @@ export default class Printer { } printAndIndentOnComments(node, parent) { - let indent = !!node.leadingComments; + const indent = !!node.leadingComments; if (indent) this.indent(); this.print(node, parent); if (indent) this.dedent(); } printBlock(parent) { - let node = parent.body; + const node = parent.body; if (!t.isEmptyStatement(node)) { this.space(); @@ -544,13 +547,13 @@ export default class Printer { // if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) { - let offset = comment.loc && comment.loc.start.column; + const offset = comment.loc && comment.loc.start.column; if (offset) { - let newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); + const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); val = val.replace(newlineRegex, "\n"); } - let indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn()); + const indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn()); val = val.replace(/\n(?!$)/g, `\n${repeat(" ", indentSize)}`); } @@ -567,28 +570,16 @@ export default class Printer { _printComments(comments?: Array) { if (!comments || !comments.length) return; - for (let comment of comments) { + for (const comment of comments) { this._printComment(comment); } } } +// Expose the node type functions and helpers on the prototype for easy usage. +Object.assign(Printer.prototype, generatorFunctions); + function commaSeparator() { this.token(","); this.space(); } - -for (let generator of [ - require("./generators/template-literals"), - require("./generators/expressions"), - require("./generators/statements"), - require("./generators/classes"), - require("./generators/methods"), - require("./generators/modules"), - require("./generators/types"), - require("./generators/flow"), - require("./generators/base"), - require("./generators/jsx") -]) { - Object.assign(Printer.prototype, generator); -} diff --git a/packages/babel-generator/src/whitespace.js b/packages/babel-generator/src/whitespace.js index 2eb4f9b308..aabe0d123a 100644 --- a/packages/babel-generator/src/whitespace.js +++ b/packages/babel-generator/src/whitespace.js @@ -5,7 +5,7 @@ export default class Whitespace { constructor(tokens) { this.tokens = tokens; - this.used = {}; + this.used = {}; } /** @@ -15,7 +15,7 @@ export default class Whitespace { getNewlinesBefore(node) { let startToken; let endToken; - let tokens = this.tokens; + const tokens = this.tokens; let index = this._findToken((token) => token.start - node.start, 0, tokens.length); if (index >= 0) { @@ -34,7 +34,7 @@ export default class Whitespace { getNewlinesAfter(node) { let startToken; let endToken; - let tokens = this.tokens; + const tokens = this.tokens; let index = this._findToken((token) => token.end - node.end, 0, tokens.length); if (index >= 0) { @@ -58,8 +58,8 @@ export default class Whitespace { _getNewlinesBetween(startToken, endToken) { if (!endToken || !endToken.loc) return 0; - let start = startToken ? startToken.loc.end.line : 1; - let end = endToken.loc.start.line; + const start = startToken ? startToken.loc.end.line : 1; + const end = endToken.loc.start.line; let lines = 0; for (let line = start; line < end; line++) { diff --git a/packages/babel-generator/test/fixtures/flow/call-properties/expected.js b/packages/babel-generator/test/fixtures/flow/call-properties/expected.js index 11d4f2a107..f0b5dabbe3 100644 --- a/packages/babel-generator/test/fixtures/flow/call-properties/expected.js +++ b/packages/babel-generator/test/fixtures/flow/call-properties/expected.js @@ -1,5 +1,5 @@ var a: { (): number }; var a: { (): number }; -var a: { y: string; (): number; (x: string): string; }; +var a: { y: string, (): number, (x: string): string, }; var a: { (x: T): number }; interface A { (): number }; diff --git a/packages/babel-generator/test/fixtures/flow/declare-statements/expected.js b/packages/babel-generator/test/fixtures/flow/declare-statements/expected.js index 8f667c0137..7498e25025 100644 --- a/packages/babel-generator/test/fixtures/flow/declare-statements/expected.js +++ b/packages/babel-generator/test/fixtures/flow/declare-statements/expected.js @@ -6,7 +6,7 @@ declare function foo(): void; declare function foo(x: number, y: string): void; declare class A {} declare class A extends B { x: number } -declare class A { static foo: () => number; static x: string; } +declare class A { static foo: () => number, static x: string, } declare class A { static [indexer: number]: string } declare class A { static (): number } declare class A mixins B, C {} diff --git a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/expected.js b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/expected.js index ee084a80b7..89aa627760 100644 --- a/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/expected.js +++ b/packages/babel-generator/test/fixtures/flow/interfaces-module-and-script/expected.js @@ -2,7 +2,7 @@ interface A {}; interface A extends B {}; interface A extends B, C {}; interface A { foo: () => number }; -interface Dictionary { length: number; [index: string]: string; }; +interface Dictionary { length: number, [index: string]: string, }; class Foo implements Bar {} class Foo extends Bar implements Bat, Man {} class Foo extends class Bar implements Bat {} {} diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/actual.js b/packages/babel-generator/test/fixtures/flow/type-annotations/actual.js index 2690152d34..d252ef635a 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/actual.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/actual.js @@ -97,6 +97,10 @@ import type { foo as bar } from "baz"; import type from "foo"; import type, { foo } from "bar"; import type * 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 }; export type { bar } from "bar"; export interface baz { p: number }; diff --git a/packages/babel-generator/test/fixtures/flow/type-annotations/expected.js b/packages/babel-generator/test/fixtures/flow/type-annotations/expected.js index 7a9406eaa3..e90a7bcfc4 100644 --- a/packages/babel-generator/test/fixtures/flow/type-annotations/expected.js +++ b/packages/babel-generator/test/fixtures/flow/type-annotations/expected.js @@ -38,14 +38,14 @@ var numVal: number; var numVal: number = otherNumVal; var a: { numVal: number }; var a: { numVal: number }; -var a: { numVal: number; [indexer: string]: number; }; +var a: { numVal: number, [indexer: string]: number, }; var a: ?{ numVal: number }; -var a: { numVal: number; strVal: string; }; +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: { 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 }; @@ -101,6 +101,10 @@ import type { foo as bar } from "baz"; import type from "foo"; import type, { foo } from "bar"; import type * 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 }; export type { bar } from "bar"; export interface baz { p: number }; @@ -108,14 +112,14 @@ 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, [indexer: string]: number, |}; var a: ?{| numVal: number |}; -var a: {| numVal: number; strVal: string; |}; +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: {| 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 |}; diff --git a/packages/babel-generator/test/fixtures/flow/typecasts/expected.js b/packages/babel-generator/test/fixtures/flow/typecasts/expected.js index 69c9dc4b93..61771958e6 100644 --- a/packages/babel-generator/test/fixtures/flow/typecasts/expected.js +++ b/packages/babel-generator/test/fixtures/flow/typecasts/expected.js @@ -1,4 +1,4 @@ (xxx: number); -({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string; }); +({ xxx: 0, yyy: "hey" }: { xxx: number, yyy: string, }); (xxx => xxx + 1: (xxx: number) => number); (xxx: number), (yyy: string); diff --git a/packages/babel-generator/test/fixtures/flowUsesCommas/options.json b/packages/babel-generator/test/fixtures/flowUsesCommas/options.json deleted file mode 100644 index f50690ec13..0000000000 --- a/packages/babel-generator/test/fixtures/flowUsesCommas/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "flowCommaSeparator": true -} diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/templates-indentation/expected.js b/packages/babel-generator/test/fixtures/harmony-edgecase/templates-indentation/expected.js index 1f664f0ae2..50f361c162 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/templates-indentation/expected.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/templates-indentation/expected.js @@ -1,15 +1,15 @@ function multilineTemplate() { return `I'm done reconfoobling -${ 'the energy motron' } - ${ '...or whatever' }`; +${'the energy motron'} + ${'...or whatever'}`; } { const foo = `spam and eggs!`; - const bar = `${ 4 + 2 }`; + const bar = `${4 + 2}`; const hello = `Hello -${ 'world' }`; +${'world'}`; } diff --git a/packages/babel-generator/test/fixtures/harmony-edgecase/templates/expected.js b/packages/babel-generator/test/fixtures/harmony-edgecase/templates/expected.js index 93ff1e3ebb..476203f277 100644 --- a/packages/babel-generator/test/fixtures/harmony-edgecase/templates/expected.js +++ b/packages/babel-generator/test/fixtures/harmony-edgecase/templates/expected.js @@ -15,17 +15,17 @@ Is the order a rabbit? `; var middles = ` -Is the order ${ order }? +Is the order ${order}? `; var middles = ` -Is the order ${ order }? +Is the order ${order}? `; var middles = ` -1. ${ cocoa } -2. ${ chino } -3. ${ rize } -4. ${ syaro } -5. ${ chiya } +1. ${cocoa} +2. ${chino} +3. ${rize} +4. ${syaro} +5. ${chiya} `; diff --git a/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js index 6ac1480c55..8289263007 100644 --- a/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js +++ b/packages/babel-generator/test/fixtures/parentheses/await-expression/actual.js @@ -3,7 +3,9 @@ async function asdf() { (await b)(); new (await b)(); true ? (await 1) : (await 2); + await (1 ? 2 : 3); await (await 1); + await (a || b); } async function a(b) { diff --git a/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js index a5ec177acd..271a15791e 100644 --- a/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js +++ b/packages/babel-generator/test/fixtures/parentheses/await-expression/expected.js @@ -3,7 +3,9 @@ async function asdf() { (await b)(); new (await b)(); true ? await 1 : await 2; + await (1 ? 2 : 3); await await 1; + await (a || b); } async function a(b) { diff --git a/packages/babel-generator/test/fixtures/parentheses/do-expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/do-expression/actual.js new file mode 100644 index 0000000000..21177fdcef --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/do-expression/actual.js @@ -0,0 +1,3 @@ +(do { + foo; +}); diff --git a/packages/babel-generator/test/fixtures/parentheses/do-expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/do-expression/expected.js new file mode 100644 index 0000000000..21177fdcef --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/do-expression/expected.js @@ -0,0 +1,3 @@ +(do { + foo; +}); diff --git a/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/actual.js new file mode 100644 index 0000000000..8a19f04a89 --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/actual.js @@ -0,0 +1,2 @@ +(() => {})``; +(function(){}``); diff --git a/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/expected.js new file mode 100644 index 0000000000..f47cd2e9af --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/tagged-template-expression/expected.js @@ -0,0 +1,2 @@ +(() => {})``; +(function () {})``; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/parentheses/yield-expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/yield-expression/actual.js index 97ef823d3c..b000b972b5 100644 --- a/packages/babel-generator/test/fixtures/parentheses/yield-expression/actual.js +++ b/packages/babel-generator/test/fixtures/parentheses/yield-expression/actual.js @@ -3,6 +3,7 @@ function* asdf() { (yield b)(); new (yield b)(); (yield 1) ? (yield 2) : (yield 3); + yield (1 ? 2 : 3); yield (yield 1); } diff --git a/packages/babel-generator/test/fixtures/parentheses/yield-expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/yield-expression/expected.js index cbc86c5c5c..68c2e6b123 100644 --- a/packages/babel-generator/test/fixtures/parentheses/yield-expression/expected.js +++ b/packages/babel-generator/test/fixtures/parentheses/yield-expression/expected.js @@ -3,6 +3,7 @@ function* asdf() { (yield b)(); new (yield b)(); (yield 1) ? yield 2 : yield 3; + yield 1 ? 2 : 3; yield yield 1; } diff --git a/packages/babel-generator/test/fixtures/types/DoExpression/actual.js b/packages/babel-generator/test/fixtures/types/DoExpression/actual.js new file mode 100644 index 0000000000..944d0559dd --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/DoExpression/actual.js @@ -0,0 +1,9 @@ +(do {}); + +let a = do { + if (x > 10) { + 'big'; + } else { + 'small'; + } +}; diff --git a/packages/babel-generator/test/fixtures/types/DoExpression/expected.js b/packages/babel-generator/test/fixtures/types/DoExpression/expected.js new file mode 100644 index 0000000000..944d0559dd --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/DoExpression/expected.js @@ -0,0 +1,9 @@ +(do {}); + +let a = do { + if (x > 10) { + 'big'; + } else { + 'small'; + } +}; diff --git a/packages/babel-generator/test/fixtures/types/LogicalExpression/actual.js b/packages/babel-generator/test/fixtures/types/LogicalExpression/actual.js new file mode 100644 index 0000000000..5df2b0728d --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/LogicalExpression/actual.js @@ -0,0 +1,2 @@ +foo ||bar; +(x => x)|| bar; diff --git a/packages/babel-generator/test/fixtures/types/LogicalExpression/expected.js b/packages/babel-generator/test/fixtures/types/LogicalExpression/expected.js new file mode 100644 index 0000000000..91f0b20ce2 --- /dev/null +++ b/packages/babel-generator/test/fixtures/types/LogicalExpression/expected.js @@ -0,0 +1,2 @@ +foo || bar; +(x => x) || bar; diff --git a/packages/babel-generator/test/fixtures/types/TemplateLiteral-TaggedTemplateExpression-TemplateElement/expected.js b/packages/babel-generator/test/fixtures/types/TemplateLiteral-TaggedTemplateExpression-TemplateElement/expected.js index 455ed642b5..b1cd86e7e2 100644 --- a/packages/babel-generator/test/fixtures/types/TemplateLiteral-TaggedTemplateExpression-TemplateElement/expected.js +++ b/packages/babel-generator/test/fixtures/types/TemplateLiteral-TaggedTemplateExpression-TemplateElement/expected.js @@ -3,7 +3,7 @@ html``; `multi lines`; -`test ${ interpolation } test`; +`test ${interpolation} test`; `foob diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index 40d8402d34..c0e0ec4584 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -1,46 +1,46 @@ -let Whitespace = require("../lib/whitespace"); -let Printer = require("../lib/printer"); -let generate = require("../lib"); -let assert = require("assert"); -let parse = require("babylon").parse; -let chai = require("chai"); -let t = require("babel-types"); -let _ = require("lodash"); -let fs = require("fs"); -let path = require("path"); +import Whitespace from "../lib/whitespace"; +import Printer from "../lib/printer"; +import generate from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; +import chai from "chai"; +import * as t from "babel-types"; +import fs from "fs"; +import path from "path"; +import fixtures from "babel-helper-fixtures"; describe("generation", function () { it("completeness", function () { - _.each(t.VISITOR_KEYS, function (keys, type) { + Object.keys(t.VISITOR_KEYS).forEach(function (type) { assert.ok(!!Printer.prototype[type], type + " should exist"); }); - _.each(Printer.prototype, function (fn, type) { + Object.keys(Printer.prototype).forEach(function (type) { if (!/[A-Z]/.test(type[0])) return; assert.ok(t.VISITOR_KEYS[type], type + " should not exist"); }); }); it("multiple sources", function () { - let sources = { + const sources = { "a.js": "function hi (msg) { console.log(msg); }\n", - "b.js": "hi('hello');\n" + "b.js": "hi('hello');\n", }; - let parsed = _.keys(sources).reduce(function (_parsed, filename) { + const parsed = Object.keys(sources).reduce(function (_parsed, filename) { _parsed[filename] = parse(sources[filename], { sourceFilename: filename }); return _parsed; }, {}); - let combinedAst = { + const combinedAst = { "type": "File", "program": { "type": "Program", "sourceType": "module", - "body": [].concat(parsed["a.js"].program.body, parsed["b.js"].program.body) - } + "body": [].concat(parsed["a.js"].program.body, parsed["b.js"].program.body), + }, }; - let generated = generate.default(combinedAst, { sourceMaps: true }, sources); + const generated = generate(combinedAst, { sourceMaps: true }, sources); chai.expect(generated.map).to.deep.equal({ version: 3, @@ -54,8 +54,8 @@ describe("generation", function () { ], sourcesContent: [ "function hi (msg) { console.log(msg); }\n", - "hi('hello');\n" - ] + "hi('hello');\n", + ], }, "sourcemap was incorrectly generated"); chai.expect(generated.rawMappings).to.deep.equal([ @@ -128,23 +128,23 @@ describe("generation", function () { }); it("identifierName", function () { - let code = "function foo() { bar; }\n"; + const code = "function foo() { bar; }\n"; - let ast = parse(code, { filename: "inline" }).program; - let fn = ast.body[0]; + const ast = parse(code, { filename: "inline" }).program; + const fn = ast.body[0]; - let id = fn.id; + const id = fn.id; id.name += "2"; id.loc.identifierName = "foo"; - let id2 = fn.body.body[0].expression; + const id2 = fn.body.body[0].expression; id2.name += "2"; id2.loc.identiferName = "bar"; - let generated = generate.default(ast, { + const generated = generate(ast, { filename: "inline", sourceFileName: "inline", - sourceMaps: true + sourceMaps: true, }, code); chai.expect(generated.map).to.deep.equal({ @@ -152,7 +152,7 @@ describe("generation", function () { sources: ["inline"], names: ["foo", "bar" ], mappings: "AAAA,SAASA,IAAT,GAAe;AAAEC;AAAM", - sourcesContent: [ "function foo() { bar; }\n" ] + sourcesContent: [ "function foo() { bar; }\n" ], }, "sourcemap was incorrectly generated"); chai.expect(generated.rawMappings).to.deep.equal([ @@ -189,10 +189,10 @@ describe("generation", function () { }); it("lazy source map generation", function() { - let code = "function hi (msg) { console.log(msg); }\n"; + const code = "function hi (msg) { console.log(msg); }\n"; - let ast = parse(code, { filename: "a.js" }).program; - let generated = generate.default(ast, { + const ast = parse(code, { filename: "a.js" }).program; + const generated = generate(ast, { sourceFileName: "a.js", sourceMaps: true, }); @@ -209,12 +209,12 @@ describe("generation", function () { describe("programmatic generation", function() { it("numeric member expression", function() { // Should not generate `0.foo` - let mem = t.memberExpression(t.numericLiteral(60702), t.identifier("foo")); - new Function(generate.default(mem).code); + const mem = t.memberExpression(t.numericLiteral(60702), t.identifier("foo")); + new Function(generate(mem).code); }); it("nested if statements needs block", function() { - let ifStatement = t.ifStatement( + const ifStatement = t.ifStatement( t.stringLiteral("top cond"), t.whileStatement( t.stringLiteral("while cond"), @@ -226,26 +226,26 @@ describe("programmatic generation", function() { t.expressionStatement(t.stringLiteral("alt")) ); - let ast = parse(generate.default(ifStatement).code); + const ast = parse(generate(ifStatement).code); assert.equal(ast.program.body[0].consequent.type, "BlockStatement"); }); it("prints directives in block with empty body", function() { - let blockStatement = t.blockStatement( + const blockStatement = t.blockStatement( [], [t.directive(t.directiveLiteral("use strict"))] ); - let output = generate.default(blockStatement).code; + const output = generate(blockStatement).code; assert.equal(output, [ "{", " \"use strict\";", - "}" + "}", ].join("\n")); }); it("flow object indentation", function() { - let objectStatement = t.objectTypeAnnotation( + const objectStatement = t.objectTypeAnnotation( [ t.objectTypeProperty( t.identifier("bar"), @@ -256,16 +256,16 @@ describe("programmatic generation", function() { null ); - let output = generate.default(objectStatement).code; + const output = generate(objectStatement).code; assert.equal(output, [ "{", - " bar: string;", + " bar: string,", "}", ].join("\n")); }); it("flow object indentation with empty leading ObjectTypeProperty", function() { - let objectStatement = t.objectTypeAnnotation( + const objectStatement = t.objectTypeAnnotation( [], [ t.objectTypeIndexer( @@ -276,11 +276,11 @@ describe("programmatic generation", function() { ] ); - let output = generate.default(objectStatement).code; + const output = generate(objectStatement).code; assert.equal(output, [ "{", - " [key: any]: Test;", + " [key: any]: Test,", "}", ].join("\n")); }); @@ -288,31 +288,46 @@ describe("programmatic generation", function() { describe("whitespace", function () { it("empty token list", function () { - let w = new Whitespace([]); + const w = new Whitespace([]); assert.equal(w.getNewlinesBefore(t.stringLiteral("1")), 0); }); }); -let suites = require("babel-helper-fixtures").default(__dirname + "/fixtures"); +const suites = fixtures(`${__dirname}/fixtures`); suites.forEach(function (testSuite) { describe("generation/" + testSuite.title, function () { - _.each(testSuite.tests, function (task) { + testSuite.tests.forEach(function (task) { it(task.title, !task.disabled && function () { - let expect = task.expect; - let actual = task.actual; - let actualCode = actual.code; + const expect = task.expect; + const actual = task.actual; + const actualCode = actual.code; if (actualCode) { - let actualAst = parse(actualCode, { + const actualAst = parse(actualCode, { filename: actual.loc, - plugins: ["*"], + plugins: [ + "asyncGenerators", + "classProperties", + "decorators", + "doExpressions", + "dynamicImport", + "exportExtensions", + "flow", + "functionBind", + "functionSent", + "jsx", + "objectRestSpread", + ], strictMode: false, sourceType: "module", }); - let result = generate.default(actualAst, task.options, actualCode); + const result = generate(actualAst, task.options, actualCode); - if (!expect.code && result.code && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) { + if ( + !expect.code && result.code && fs.statSync(path.dirname(expect.loc)).isDirectory() && + !process.env.CI + ) { console.log(`New test file created: ${expect.loc}`); fs.writeFileSync(expect.loc, result.code); } else { diff --git a/packages/babel-helper-bindify-decorators/package.json b/packages/babel-helper-bindify-decorators/package.json index 65d88770a2..db00bb72cd 100644 --- a/packages/babel-helper-bindify-decorators/package.json +++ b/packages/babel-helper-bindify-decorators/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-bindify-decorators", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to bindify decorators", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-bindify-decorators", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-traverse": "^6.18.0", - "babel-types": "^6.18.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-bindify-decorators/src/index.js b/packages/babel-helper-bindify-decorators/src/index.js index 750c00f56f..debc145a4f 100644 --- a/packages/babel-helper-bindify-decorators/src/index.js +++ b/packages/babel-helper-bindify-decorators/src/index.js @@ -2,15 +2,15 @@ import type { NodePath } from "babel-traverse"; import * as t from "babel-types"; export default function bindifyDecorators(decorators: Array): Array { - for (let decoratorPath of decorators) { - let decorator = decoratorPath.node; - let expression = decorator.expression; + for (const decoratorPath of decorators) { + const decorator = decoratorPath.node; + const expression = decorator.expression; if (!t.isMemberExpression(expression)) continue; - let temp = decoratorPath.scope.maybeGenerateMemoised(expression.object); + const temp = decoratorPath.scope.maybeGenerateMemoised(expression.object); let ref; - let nodes = []; + const nodes = []; if (temp) { ref = temp; diff --git a/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json b/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json index 3dabe28676..94ebb53e66 100644 --- a/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json +++ b/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-builder-binary-assignment-operator-visitor", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to build binary assignment operator visitors", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-binary-assignment-operator-visitor", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-helper-explode-assignable-expression": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-helper-explode-assignable-expression": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js b/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js index 0c07eecf9f..1b03a6681a 100644 --- a/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js +++ b/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js @@ -5,7 +5,7 @@ export default function (opts: { build: Function; operator: string; }): Object { - let visitor = {}; + const visitor = {}; function isAssignment(node) { return node && node.operator === opts.operator + "="; @@ -19,11 +19,11 @@ export default function (opts: { // hit the `AssignmentExpression` one below if (path.isCompletionRecord()) return; - let expr = path.node.expression; + const expr = path.node.expression; if (!isAssignment(expr)) return; - let nodes = []; - let exploded = explode(expr.left, nodes, file, path.scope, true); + const nodes = []; + const exploded = explode(expr.left, nodes, file, path.scope, true); nodes.push(t.expressionStatement( buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right)) @@ -33,17 +33,17 @@ export default function (opts: { }; visitor.AssignmentExpression = function (path, file) { - let { node, scope } = path; + const { node, scope } = path; if (!isAssignment(node)) return; - let nodes = []; - let exploded = explode(node.left, nodes, file, scope); + const nodes = []; + const exploded = explode(node.left, nodes, file, scope); nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right))); path.replaceWithMultiple(nodes); }; visitor.BinaryExpression = function (path) { - let { node } = path; + const { node } = path; if (node.operator === opts.operator) { path.replaceWith(opts.build(node.left, node.right)); } diff --git a/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json b/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json index 5ef4606b9e..5fea995e98 100644 --- a/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json +++ b/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-builder-conditional-assignment-operator-visitor", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to build conditional assignment operator visitors", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-conditional-assignment-operator-visitor", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-helper-explode-assignable-expression": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-helper-explode-assignable-expression": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js b/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js index bf8f9d48b9..ae5c1772cb 100644 --- a/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js +++ b/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js @@ -8,7 +8,7 @@ export default function ( is: Function; }, ) { - let buildAssignment = function (left, right) { + const buildAssignment = function (left, right) { return t.assignmentExpression("=", left, right); }; @@ -16,12 +16,12 @@ export default function ( // hit the `AssignmentExpression` one below if (path.isCompletionRecord()) return; - let expr = path.node.expression; + const expr = path.node.expression; if (!opts.is(expr, file)) return; - let nodes = []; + const nodes = []; - let exploded = explode(expr.left, nodes, file, path.scope); + const exploded = explode(expr.left, nodes, file, path.scope); nodes.push(t.ifStatement( opts.build(exploded.uid, file), @@ -32,11 +32,11 @@ export default function ( }; exports.AssignmentExpression = function (path, file) { - let node = path.node; + const node = path.node; if (!opts.is(node, file)) return; - let nodes = []; - let exploded = explode(node.left, nodes, file, path.scope); + const nodes = []; + const exploded = explode(node.left, nodes, file, path.scope); nodes.push(t.logicalExpression( "&&", diff --git a/packages/babel-helper-builder-react-jsx/package.json b/packages/babel-helper-builder-react-jsx/package.json index 908e3a2c34..312b5a63b1 100644 --- a/packages/babel-helper-builder-react-jsx/package.json +++ b/packages/babel-helper-builder-react-jsx/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-builder-react-jsx", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Helper function to build react jsx", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.9.0", - "babel-types": "^6.21.0", + "babel-types": "7.0.0-alpha.1", "esutils": "^2.0.0", "lodash": "^4.2.0" } diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js index 22f963e342..13d205fd4b 100644 --- a/packages/babel-helper-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -11,19 +11,15 @@ type ElementState = { }; export default function (opts) { - let visitor = {}; + const visitor = {}; visitor.JSXNamespacedName = function (path) { throw path.buildCodeFrameError("Namespace tags are not supported. ReactJSX is not XML."); }; - visitor.JSXSpreadChild = function(path) { - throw path.buildCodeFrameError("Spread children are not supported."); - }; - visitor.JSXElement = { exit(path, file) { - let callExpr = buildElementCall(path.get("openingElement"), file); + const callExpr = buildElementCall(path.get("openingElement"), file); callExpr.arguments = callExpr.arguments.concat(path.node.children); @@ -32,7 +28,7 @@ export default function (opts) { } path.replaceWith(t.inherits(callExpr, path.node)); - } + }, }; return visitor; @@ -65,7 +61,7 @@ export default function (opts) { } function convertAttribute(node) { - let value = convertAttributeValue(node.value || t.booleanLiteral(true)); + const value = convertAttributeValue(node.value || t.booleanLiteral(true)); if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(node.value)) { value.value = value.value.replace(/\n\s+/g, " "); @@ -83,8 +79,8 @@ export default function (opts) { function buildElementCall(path, file) { path.parent.children = t.react.buildChildren(path.parent); - let tagExpr = convertJSXIdentifier(path.node.name, path.node); - let args = []; + const tagExpr = convertJSXIdentifier(path.node.name, path.node); + const args = []; let tagName; if (t.isIdentifier(tagExpr)) { @@ -93,10 +89,10 @@ export default function (opts) { tagName = tagExpr.value; } - let state: ElementState = { + const state: ElementState = { tagExpr: tagExpr, tagName: tagName, - args: args + args: args, }; if (opts.pre) { @@ -128,11 +124,12 @@ export default function (opts) { function buildOpeningElementAttributes(attribs, file) { let _props = []; - let objs = []; + const objs = []; - let useBuiltIns = file.opts.useBuiltIns || false; + const useBuiltIns = file.opts.useBuiltIns || false; if (typeof useBuiltIns !== "boolean") { - throw new Error("transform-react-jsx currently only accepts a boolean option for useBuiltIns (defaults to false)"); + throw new Error("transform-react-jsx currently only accepts a boolean option for " + + "useBuiltIns (defaults to false)"); } function pushProps() { @@ -143,7 +140,7 @@ export default function (opts) { } while (attribs.length) { - let prop = attribs.shift(); + const prop = attribs.shift(); if (t.isJSXSpreadAttribute(prop)) { pushProps(); objs.push(prop.argument); diff --git a/packages/babel-helper-call-delegate/package.json b/packages/babel-helper-call-delegate/package.json index d0f5ae0986..4438a7cb84 100644 --- a/packages/babel-helper-call-delegate/package.json +++ b/packages/babel-helper-call-delegate/package.json @@ -1,14 +1,13 @@ { "name": "babel-helper-call-delegate", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to call delegate", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-call-delegate", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-traverse": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0", - "babel-helper-hoist-variables": "^6.18.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babel-helper-hoist-variables": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-call-delegate/src/index.js b/packages/babel-helper-call-delegate/src/index.js index 1319a662fc..fdf05257ce 100644 --- a/packages/babel-helper-call-delegate/src/index.js +++ b/packages/babel-helper-call-delegate/src/index.js @@ -2,7 +2,7 @@ import hoistVariables from "babel-helper-hoist-variables"; import type { NodePath } from "babel-traverse"; import * as t from "babel-types"; -let visitor = { +const visitor = { enter(path, state) { if (path.isThisExpression()) { state.foundThis = true; @@ -15,22 +15,22 @@ let visitor = { Function(path) { path.skip(); - } + }, }; export default function (path: NodePath, scope = path.scope) { - let { node } = path; - let container = t.functionExpression(null, [], node.body, node.generator, node.async); + const { node } = path; + const container = t.functionExpression(null, [], node.body, node.generator, node.async); let callee = container; - let args = []; + let args = []; // todo: only hoist if necessary hoistVariables(path, (id) => scope.push({ id })); - let state = { + const state = { foundThis: false, - foundArguments: false + foundArguments: false, }; path.traverse(visitor, state); diff --git a/packages/babel-helper-define-map/package.json b/packages/babel-helper-define-map/package.json index a417778656..6f1399418f 100644 --- a/packages/babel-helper-define-map/package.json +++ b/packages/babel-helper-define-map/package.json @@ -1,14 +1,13 @@ { "name": "babel-helper-define-map", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to define a map", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-define-map", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.9.0", "lodash": "^4.2.0", - "babel-types": "^6.18.0", - "babel-helper-function-name": "^6.18.0" + "babel-types": "7.0.0-alpha.1", + "babel-helper-function-name": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-define-map/src/index.js b/packages/babel-helper-define-map/src/index.js index 6536747555..b0c45ab7e1 100644 --- a/packages/babel-helper-define-map/src/index.js +++ b/packages/babel-helper-define-map/src/index.js @@ -1,7 +1,4 @@ -/* eslint max-len: 0 */ - import nameFunction from "babel-helper-function-name"; -import each from "lodash/each"; import has from "lodash/has"; import * as t from "babel-types"; @@ -16,7 +13,7 @@ function toKind(node: Object) { } export function push(mutatorMap: Object, node: Object, kind: string, file, scope?): Object { - let alias = t.toKeyAlias(node); + const alias = t.toKeyAlias(node); // @@ -36,8 +33,9 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope } if (node.decorators) { - let decorators = map.decorators = map.decorators || t.arrayExpression([]); - decorators.elements = decorators.elements.concat(node.decorators.map((dec) => dec.expression).reverse()); + const decorators = map.decorators = map.decorators || t.arrayExpression([]); + decorators.elements = decorators.elements.concat( + node.decorators.map((dec) => dec.expression).reverse()); } if (map.value || map.initializer) { @@ -58,13 +56,14 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope value.returnType = node.returnType; } - let inheritedKind = toKind(node); + const inheritedKind = toKind(node); if (!kind || inheritedKind !== "value") { kind = inheritedKind; } // infer function name - if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && t.isFunctionExpression(value)) { + if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && + t.isFunctionExpression(value)) { value = nameFunction({ id: key, node: value, scope }); } @@ -77,7 +76,7 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope } export function hasComputed(mutatorMap: Object): boolean { - for (let key in mutatorMap) { + for (const key in mutatorMap) { if (mutatorMap[key]._computed) { return true; } @@ -86,11 +85,11 @@ export function hasComputed(mutatorMap: Object): boolean { } export function toComputedObjectFromClass(obj: Object): Object { - let objExpr = t.arrayExpression([]); + const objExpr = t.arrayExpression([]); for (let i = 0; i < obj.properties.length; i++) { - let prop = obj.properties[i]; - let val = prop.value; + const prop = obj.properties[i]; + const val = prop.value; val.properties.unshift(t.objectProperty(t.identifier("key"), t.toComputedKey(prop))); objExpr.elements.push(val); } @@ -99,20 +98,22 @@ export function toComputedObjectFromClass(obj: Object): Object { } export function toClassObject(mutatorMap: Object): Object { - let objExpr = t.objectExpression([]); + const objExpr = t.objectExpression([]); - each(mutatorMap, function (map) { - let mapNode = t.objectExpression([]); + Object.keys(mutatorMap).forEach(function (mutatorMapKey) { + const map = mutatorMap[mutatorMapKey]; + const mapNode = t.objectExpression([]); - let propNode = t.objectProperty(map._key, mapNode, map._computed); + const propNode = t.objectProperty(map._key, mapNode, map._computed); - each(map, function (node, key) { + Object.keys(map).forEach(function (key) { + let node = map[key]; if (key[0] === "_") return; - let inheritNode = node; + const inheritNode = node; if (t.isClassMethod(node) || t.isClassProperty(node)) node = node.value; - let prop = t.objectProperty(t.identifier(key), node); + const prop = t.objectProperty(t.identifier(key), node); t.inheritsComments(prop, inheritNode); t.removeComments(inheritNode); @@ -126,7 +127,8 @@ export function toClassObject(mutatorMap: Object): Object { } export function toDefineObject(mutatorMap: Object): Object { - each(mutatorMap, function (map) { + Object.keys(mutatorMap).forEach(function (key) { + const map = mutatorMap[key]; if (map.value) map.writable = t.booleanLiteral(true); map.configurable = t.booleanLiteral(true); map.enumerable = t.booleanLiteral(true); diff --git a/packages/babel-helper-explode-assignable-expression/package.json b/packages/babel-helper-explode-assignable-expression/package.json index 61accc3d91..3127951b84 100644 --- a/packages/babel-helper-explode-assignable-expression/package.json +++ b/packages/babel-helper-explode-assignable-expression/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-explode-assignable-expression", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to explode an assignable expression", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-assignable-expression", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-traverse": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-explode-assignable-expression/src/index.js b/packages/babel-helper-explode-assignable-expression/src/index.js index 8ffdd95fa2..60f4940bb8 100644 --- a/packages/babel-helper-explode-assignable-expression/src/index.js +++ b/packages/babel-helper-explode-assignable-expression/src/index.js @@ -31,21 +31,21 @@ function getObjRef(node, nodes, file, scope) { throw new Error(`We can't explode this node type ${node.type}`); } - let temp = scope.generateUidIdentifierBasedOnNode(ref); + const temp = scope.generateUidIdentifierBasedOnNode(ref); nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(temp, ref) + t.variableDeclarator(temp, ref), ])); return temp; } function getPropRef(node, nodes, file, scope) { - let prop = node.property; - let key = t.toComputedKey(node, prop); + const prop = node.property; + const key = t.toComputedKey(node, prop); if (t.isLiteral(key) && t.isPureish(key)) return key; - let temp = scope.generateUidIdentifierBasedOnNode(prop); + const temp = scope.generateUidIdentifierBasedOnNode(prop); nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(temp, prop) + t.variableDeclarator(temp, prop), ])); return temp; } @@ -73,13 +73,13 @@ export default function ( ref = node; uid = obj; } else { - let prop = getPropRef(node, nodes, file, scope); - let computed = node.computed || t.isLiteral(prop); + const prop = getPropRef(node, nodes, file, scope); + const computed = node.computed || t.isLiteral(prop); uid = ref = t.memberExpression(obj, prop, computed); } return { uid: uid, - ref: ref + ref: ref, }; } diff --git a/packages/babel-helper-explode-class/package.json b/packages/babel-helper-explode-class/package.json index b1c339f57a..8bdeb3707f 100644 --- a/packages/babel-helper-explode-class/package.json +++ b/packages/babel-helper-explode-class/package.json @@ -1,14 +1,13 @@ { "name": "babel-helper-explode-class", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to explode class", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-class", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-traverse": "^6.18.0", - "babel-types": "^6.18.0", - "babel-helper-bindify-decorators": "^6.18.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babel-helper-bindify-decorators": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-explode-class/src/index.js b/packages/babel-helper-explode-class/src/index.js index 1091e1ba06..2ced5be5b1 100644 --- a/packages/babel-helper-explode-class/src/index.js +++ b/packages/babel-helper-explode-class/src/index.js @@ -5,12 +5,12 @@ import * as t from "babel-types"; export default function (classPath) { classPath.assertClass(); - let memoisedExpressions = []; + const memoisedExpressions = []; function maybeMemoise(path) { if (!path.node || path.isPure()) return; - let uid = classPath.scope.generateDeclaredUidIdentifier(); + const uid = classPath.scope.generateDeclaredUidIdentifier(); memoisedExpressions.push(t.assignmentExpression("=", uid, path.node)); path.replaceWith(uid); } @@ -24,7 +24,7 @@ export default function (classPath) { // bind decorators if they're member expressions bindifyDecorators(paths); - for (let path of paths) { + for (const path of paths) { maybeMemoise(path); } } @@ -32,8 +32,8 @@ export default function (classPath) { maybeMemoise(classPath.get("superClass")); memoiseDecorators(classPath.get("decorators"), true); - let methods: Array = classPath.get("body.body"); - for (let methodPath of methods) { + const methods: Array = classPath.get("body.body"); + for (const methodPath of methods) { if (methodPath.is("computed")) { maybeMemoise(methodPath.get("key")); } diff --git a/packages/babel-helper-fixtures/package.json b/packages/babel-helper-fixtures/package.json index 974ea43217..79fa866a78 100644 --- a/packages/babel-helper-fixtures/package.json +++ b/packages/babel-helper-fixtures/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-fixtures", - "version": "6.20.0", + "version": "7.0.0-alpha.1", "description": "Helper function to support fixtures", "author": "Sebastian McKenzie ", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-fixtures", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.20.0", "lodash": "^4.2.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 40faaf1530..4b905cc7cd 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.js @@ -1,7 +1,10 @@ +import cloneDeep from "lodash/cloneDeep"; +import trimEnd from "lodash/trimEnd"; import resolve from "try-resolve"; +import clone from "lodash/clone"; +import merge from "lodash/merge"; import path from "path"; import fs from "fs"; -import _ from "lodash"; function humanize(val, noext) { if (noext) val = path.basename(val, path.extname(val)); @@ -41,50 +44,50 @@ function shouldIgnore(name, blacklist?: Array) { return true; } - let ext = path.extname(name); - let base = path.basename(name, ext); + const ext = path.extname(name); + const base = path.basename(name, ext); return name[0] === "." || ext === ".md" || base === "LICENSE" || base === "options"; } export default function get(entryLoc): Array { - let suites = []; + const suites = []; let rootOpts = {}; - let rootOptsLoc = resolve(entryLoc + "/options"); + const rootOptsLoc = resolve(entryLoc + "/options"); if (rootOptsLoc) rootOpts = require(rootOptsLoc); - for (let suiteName of fs.readdirSync(entryLoc)) { + for (const suiteName of fs.readdirSync(entryLoc)) { if (shouldIgnore(suiteName)) continue; - let suite = { - options: _.clone(rootOpts), + const suite = { + options: clone(rootOpts), tests: [], title: humanize(suiteName), - filename: entryLoc + "/" + suiteName + filename: entryLoc + "/" + suiteName, }; assertDirectory(suite.filename); suites.push(suite); - let suiteOptsLoc = resolve(suite.filename + "/options"); + const suiteOptsLoc = resolve(suite.filename + "/options"); if (suiteOptsLoc) suite.options = require(suiteOptsLoc); - for (let taskName of fs.readdirSync(suite.filename)) { + for (const taskName of fs.readdirSync(suite.filename)) { push(taskName, suite.filename + "/" + taskName); } function push(taskName, taskDir) { - let actualLocAlias = suiteName + "/" + taskName + "/actual.js"; + const actualLocAlias = suiteName + "/" + taskName + "/actual.js"; let expectLocAlias = suiteName + "/" + taskName + "/expected.js"; - let execLocAlias = suiteName + "/" + taskName + "/exec.js"; + const execLocAlias = suiteName + "/" + taskName + "/exec.js"; - let actualLoc = taskDir + "/actual.js"; + const actualLoc = taskDir + "/actual.js"; let expectLoc = taskDir + "/expected.js"; - let execLoc = taskDir + "/exec.js"; + let execLoc = taskDir + "/exec.js"; if (fs.statSync(taskDir).isFile()) { - let ext = path.extname(taskDir); + const ext = path.extname(taskDir); if (ext !== ".js" && ext !== ".module.js") return; execLoc = taskDir; @@ -95,12 +98,12 @@ export default function get(entryLoc): Array { expectLocAlias += "on"; } - let taskOpts = _.cloneDeep(suite.options); + const taskOpts = cloneDeep(suite.options); - let taskOptsLoc = resolve(taskDir + "/options"); - if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc)); + const taskOptsLoc = resolve(taskDir + "/options"); + if (taskOptsLoc) merge(taskOpts, require(taskOptsLoc)); - let test = { + const test = { optionsDir: taskOptsLoc ? path.dirname(taskOptsLoc) : null, title: humanize(taskName, true), disabled: taskName[0] === ".", @@ -118,8 +121,8 @@ export default function get(entryLoc): Array { expect: { loc: expectLoc, code: readFile(expectLoc), - filename: expectLocAlias - } + filename: expectLocAlias, + }, }; // traceur checks @@ -130,12 +133,12 @@ export default function get(entryLoc): Array { suite.tests.push(test); - let sourceMappingsLoc = taskDir + "/source-mappings.json"; + const sourceMappingsLoc = taskDir + "/source-mappings.json"; if (fs.existsSync(sourceMappingsLoc)) { test.sourceMappings = JSON.parse(readFile(sourceMappingsLoc)); } - let sourceMapLoc = taskDir + "/source-map.json"; + const sourceMapLoc = taskDir + "/source-map.json"; if (fs.existsSync(sourceMapLoc)) { test.sourceMap = JSON.parse(readFile(sourceMapLoc)); } @@ -146,12 +149,12 @@ export default function get(entryLoc): Array { } export function multiple(entryLoc, ignore?: Array) { - let categories = {}; + const categories = {}; - for (let name of fs.readdirSync(entryLoc)) { + for (const name of fs.readdirSync(entryLoc)) { if (shouldIgnore(name, ignore)) continue; - let loc = path.join(entryLoc, name); + const loc = path.join(entryLoc, name); assertDirectory(loc); categories[name] = get(loc); @@ -162,7 +165,7 @@ export function multiple(entryLoc, ignore?: Array) { export function readFile(filename) { if (fs.existsSync(filename)) { - let file = _.trimEnd(fs.readFileSync(filename, "utf8")); + let file = trimEnd(fs.readFileSync(filename, "utf8")); file = file.replace(/\r\n/g, "\n"); return file; } else { diff --git a/packages/babel-helper-function-name/package.json b/packages/babel-helper-function-name/package.json index af03cdcd9d..b9557a60c4 100644 --- a/packages/babel-helper-function-name/package.json +++ b/packages/babel-helper-function-name/package.json @@ -1,15 +1,14 @@ { "name": "babel-helper-function-name", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to change the property 'name' of every function", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-function-name", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0", - "babel-traverse": "^6.18.0", - "babel-helper-get-function-arity": "^6.18.0", - "babel-template": "^6.8.0" + "babel-types": "7.0.0-alpha.1", + "babel-traverse": "7.0.0-alpha.1", + "babel-helper-get-function-arity": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-function-name/src/index.js b/packages/babel-helper-function-name/src/index.js index 1e6d8add9d..9783c6fc1a 100644 --- a/packages/babel-helper-function-name/src/index.js +++ b/packages/babel-helper-function-name/src/index.js @@ -1,10 +1,8 @@ -/* eslint max-len: 0 */ - import getFunctionArity from "babel-helper-get-function-arity"; import template from "babel-template"; import * as t from "babel-types"; -let buildPropertyMethodAssignmentWrapper = template(` +const buildPropertyMethodAssignmentWrapper = template(` (function (FUNCTION_KEY) { function FUNCTION_ID() { return FUNCTION_KEY.apply(this, arguments); @@ -18,7 +16,7 @@ let buildPropertyMethodAssignmentWrapper = template(` })(FUNCTION) `); -let buildGeneratorPropertyMethodAssignmentWrapper = template(` +const buildGeneratorPropertyMethodAssignmentWrapper = template(` (function (FUNCTION_KEY) { function* FUNCTION_ID() { return yield* FUNCTION_KEY.apply(this, arguments); @@ -32,19 +30,19 @@ let buildGeneratorPropertyMethodAssignmentWrapper = template(` })(FUNCTION) `); -let visitor = { +const visitor = { "ReferencedIdentifier|BindingIdentifier"(path, state) { // check if this node matches our function id if (path.node.name !== state.name) return; // check that we don't have a local variable declared as that removes the need // for the wrapper - let localDeclar = path.scope.getBindingIdentifier(state.name); + const localDeclar = path.scope.getBindingIdentifier(state.name); if (localDeclar !== state.outerDeclar) return; state.selfReference = true; path.stop(); - } + }, }; function wrap(state, method, id, scope) { @@ -59,16 +57,16 @@ function wrap(state, method, id, scope) { // need to add a wrapper since we can't change the references let build = buildPropertyMethodAssignmentWrapper; if (method.generator) build = buildGeneratorPropertyMethodAssignmentWrapper; - let template = build({ + const template = build({ FUNCTION: method, FUNCTION_ID: id, - FUNCTION_KEY: scope.generateUidIdentifier(id.name) + FUNCTION_KEY: scope.generateUidIdentifier(id.name), }).expression; template.callee._skipModulesRemap = true; // shim in dummy params to retain function arity, if you try to read the // source then you'll get the original since it's proxied so it's all good - let params = template.callee.body.body[0].params; + const params = template.callee.body.body[0].params; for (let i = 0, len = getFunctionArity(method); i < len; i++) { params.push(scope.generateUidIdentifier("x")); } @@ -82,18 +80,18 @@ function wrap(state, method, id, scope) { } function visit(node, name, scope) { - let state = { + const state = { selfAssignment: false, - selfReference: false, - outerDeclar: scope.getBindingIdentifier(name), - references: [], - name: name + selfReference: false, + outerDeclar: scope.getBindingIdentifier(name), + references: [], + name: name, }; // check to see if we have a local binding of the id we're setting inside of // the function, this is important as there are caveats associated - let binding = scope.getOwnBinding(name); + const binding = scope.getOwnBinding(name); if (binding) { if (binding.kind === "param") { @@ -131,7 +129,8 @@ export default function ({ node, parent, scope, id }) { // has an `id` so we don't need to infer one if (node.id) return; - if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) && (!parent.computed || t.isLiteral(parent.key))) { + if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) && + (!parent.computed || t.isLiteral(parent.key))) { // { foo() {} }; id = parent.key; } else if (t.isVariableDeclarator(parent)) { @@ -139,7 +138,7 @@ export default function ({ node, parent, scope, id }) { id = parent.id; if (t.isIdentifier(id)) { - let binding = scope.parent.getBinding(id.name); + const binding = scope.parent.getBinding(id.name); if (binding && binding.constant && scope.getBinding(id.name) === binding) { // always going to reference this method node.id = id; @@ -171,6 +170,6 @@ export default function ({ node, parent, scope, id }) { // a local binding. id[t.NOT_LOCAL_BINDING] = true; - let state = visit(node, name, scope); + const state = visit(node, name, scope); return wrap(state, node, id, scope) || node; } diff --git a/packages/babel-helper-get-function-arity/package.json b/packages/babel-helper-get-function-arity/package.json index 29f7cb4734..89c0a5c8cb 100644 --- a/packages/babel-helper-get-function-arity/package.json +++ b/packages/babel-helper-get-function-arity/package.json @@ -1,12 +1,11 @@ { "name": "babel-helper-get-function-arity", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to get function arity", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-get-function-arity", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-get-function-arity/src/index.js b/packages/babel-helper-get-function-arity/src/index.js index a3c60a5a61..c54613f6fe 100644 --- a/packages/babel-helper-get-function-arity/src/index.js +++ b/packages/babel-helper-get-function-arity/src/index.js @@ -1,9 +1,9 @@ import * as t from "babel-types"; export default function (node): number { - let params: Array = node.params; + const params: Array = node.params; for (let i = 0; i < params.length; i++) { - let param = params[i]; + const param = params[i]; if (t.isAssignmentPattern(param) || t.isRestElement(param)) { return i; } diff --git a/packages/babel-helper-hoist-variables/package.json b/packages/babel-helper-hoist-variables/package.json index 1fdc14f062..0928124fd6 100644 --- a/packages/babel-helper-hoist-variables/package.json +++ b/packages/babel-helper-hoist-variables/package.json @@ -1,12 +1,11 @@ { "name": "babel-helper-hoist-variables", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to hoist variables", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-hoist-variables", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-hoist-variables/src/index.js b/packages/babel-helper-hoist-variables/src/index.js index de36a3f591..ca5e640600 100644 --- a/packages/babel-helper-hoist-variables/src/index.js +++ b/packages/babel-helper-hoist-variables/src/index.js @@ -1,6 +1,6 @@ import * as t from "babel-types"; -let visitor = { +const visitor = { Scope(path, state) { if (state.kind === "let") path.skip(); }, @@ -12,12 +12,12 @@ let visitor = { VariableDeclaration(path, state) { if (state.kind && path.node.kind !== state.kind) return; - let nodes = []; + const nodes = []; - let declarations: Array = path.get("declarations"); + const declarations: Array = path.get("declarations"); let firstId; - for (let declar of declarations) { + for (const declar of declarations) { firstId = declar.node.id; if (declar.node.init) { @@ -26,7 +26,7 @@ let visitor = { )); } - for (let name in declar.getBindingIdentifiers()) { + for (const name in declar.getBindingIdentifiers()) { state.emit(t.identifier(name), name); } } @@ -37,7 +37,7 @@ let visitor = { } else { path.replaceWithMultiple(nodes); } - } + }, }; export default function (path, emit: Function, kind: "var" | "let" = "var") { diff --git a/packages/babel-helper-optimise-call-expression/package.json b/packages/babel-helper-optimise-call-expression/package.json index 9e2f16c49e..fb880ab319 100644 --- a/packages/babel-helper-optimise-call-expression/package.json +++ b/packages/babel-helper-optimise-call-expression/package.json @@ -1,12 +1,11 @@ { "name": "babel-helper-optimise-call-expression", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to optimise call expression", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-optimise-call-expression", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-optimise-call-expression/src/index.js b/packages/babel-helper-optimise-call-expression/src/index.js index d96f2e64c6..485f986321 100644 --- a/packages/babel-helper-optimise-call-expression/src/index.js +++ b/packages/babel-helper-optimise-call-expression/src/index.js @@ -1,9 +1,8 @@ -/* eslint max-len: 0 */ - import * as t from "babel-types"; export default function (callee, thisNode, args) { - if (args.length === 1 && t.isSpreadElement(args[0]) && t.isIdentifier(args[0].argument, { name: "arguments" })) { + if (args.length === 1 && t.isSpreadElement(args[0]) && + t.isIdentifier(args[0].argument, { name: "arguments" })) { // eg. super(...arguments); return t.callExpression( t.memberExpression(callee, t.identifier("apply")), diff --git a/packages/babel-helper-plugin-test-runner/package.json b/packages/babel-helper-plugin-test-runner/package.json index 2d8ff34519..ad893637a1 100644 --- a/packages/babel-helper-plugin-test-runner/package.json +++ b/packages/babel-helper-plugin-test-runner/package.json @@ -1,12 +1,11 @@ { "name": "babel-helper-plugin-test-runner", - "version": "6.18.0", + "version": "7.0.0-alpha.2", "description": "Helper function to support test runner", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-helper-transform-fixture-test-runner": "^6.18.0" + "babel-helper-transform-fixture-test-runner": "7.0.0-alpha.2" } } diff --git a/packages/babel-helper-plugin-test-runner/src/index.js b/packages/babel-helper-plugin-test-runner/src/index.js index 749f964aa3..37bcc4360c 100644 --- a/packages/babel-helper-plugin-test-runner/src/index.js +++ b/packages/babel-helper-plugin-test-runner/src/index.js @@ -2,6 +2,6 @@ import testRunner from "babel-helper-transform-fixture-test-runner"; import path from "path"; export default function (loc) { - let name = path.basename(path.dirname(loc)); + const name = path.basename(path.dirname(loc)); testRunner(loc + "/fixtures", name); } diff --git a/packages/babel-helper-regex/package.json b/packages/babel-helper-regex/package.json index 787533a89e..0de910c904 100644 --- a/packages/babel-helper-regex/package.json +++ b/packages/babel-helper-regex/package.json @@ -1,13 +1,12 @@ { "name": "babel-helper-regex", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to check for literal RegEx", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-regex", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.9.0", "lodash": "^4.2.0", - "babel-types": "^6.18.0" + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-regex/src/index.js b/packages/babel-helper-regex/src/index.js index b59a30f7d5..998bbe4716 100644 --- a/packages/babel-helper-regex/src/index.js +++ b/packages/babel-helper-regex/src/index.js @@ -6,7 +6,7 @@ export function is(node: Object, flag: string): boolean { } export function pullFlag(node: Object, flag: string) { - let flags = node.flags.split(""); + const flags = node.flags.split(""); if (node.flags.indexOf(flag) < 0) return; pull(flags, flag); node.flags = flags.join(""); diff --git a/packages/babel-helper-remap-async-to-generator/package.json b/packages/babel-helper-remap-async-to-generator/package.json index 0e633745d6..a173b2228e 100644 --- a/packages/babel-helper-remap-async-to-generator/package.json +++ b/packages/babel-helper-remap-async-to-generator/package.json @@ -1,15 +1,14 @@ { "name": "babel-helper-remap-async-to-generator", - "version": "6.20.3", + "version": "7.0.0-alpha.1", "description": "Helper function to remap async functions to generators", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-remap-async-to-generator", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.20.0", - "babel-template": "^6.16.0", - "babel-types": "^6.20.0", - "babel-traverse": "^6.20.0", - "babel-helper-function-name": "^6.18.0" + "babel-template": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babel-traverse": "7.0.0-alpha.1", + "babel-helper-function-name": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-remap-async-to-generator/src/for-await.js b/packages/babel-helper-remap-async-to-generator/src/for-await.js index 5e3fe1f0bc..c9b638283b 100644 --- a/packages/babel-helper-remap-async-to-generator/src/for-await.js +++ b/packages/babel-helper-remap-async-to-generator/src/for-await.js @@ -2,7 +2,7 @@ import * as t from "babel-types"; import template from "babel-template"; import traverse from "babel-traverse"; -let buildForAwait = template(` +const buildForAwait = template(` function* wrapper() { var ITERATOR_COMPLETION = true; var ITERATOR_HAD_ERROR_KEY = false; @@ -35,7 +35,7 @@ let buildForAwait = template(` } `); -let forAwaitVisitor = { +const forAwaitVisitor = { noScope: true, Identifier(path, replacements) { @@ -45,21 +45,21 @@ let forAwaitVisitor = { }, CallExpression(path, replacements) { - let callee = path.node.callee; + const callee = path.node.callee; // if no await wrapping is being applied, unwrap the call expression if (t.isIdentifier(callee) && callee.name === "AWAIT" && !replacements.AWAIT) { path.replaceWith(path.node.arguments[0]); } - } + }, }; export default function (path, helpers) { - let { node, scope, parent } = path; + const { node, scope, parent } = path; - let stepKey = scope.generateUidIdentifier("step"); - let stepValue = scope.generateUidIdentifier("value"); - let left = node.left; + const stepKey = scope.generateUidIdentifier("step"); + const stepValue = scope.generateUidIdentifier("value"); + const left = node.left; let declar; if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { @@ -68,7 +68,7 @@ export default function (path, helpers) { } else if (t.isVariableDeclaration(left)) { // for await (let i of test) declar = t.variableDeclaration(left.kind, [ - t.variableDeclarator(left.declarations[0].id, stepValue) + t.variableDeclarator(left.declarations[0].id, stepValue), ]); } @@ -83,15 +83,15 @@ export default function (path, helpers) { OBJECT: node.right, STEP_VALUE: stepValue, STEP_KEY: stepKey, - AWAIT: helpers.wrapAwait + AWAIT: helpers.wrapAwait, }); // remove generator function wrapper template = template.body.body; - let isLabeledParent = t.isLabeledStatement(parent); - let tryBody = template[3].block.body; - let loop = tryBody[0]; + const isLabeledParent = t.isLabeledStatement(parent); + const tryBody = template[3].block.body; + const loop = tryBody[0]; if (isLabeledParent) { tryBody[0] = t.labeledStatement(parent.label, loop); @@ -101,6 +101,6 @@ export default function (path, helpers) { replaceParent: isLabeledParent, node: template, declar, - loop + loop, }; } diff --git a/packages/babel-helper-remap-async-to-generator/src/index.js b/packages/babel-helper-remap-async-to-generator/src/index.js index 840a195d8a..612fe18fbf 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -6,7 +6,7 @@ import template from "babel-template"; import * as t from "babel-types"; import rewriteForAwait from "./for-await"; -let buildWrapper = template(` +const buildWrapper = template(` (() => { var REF = FUNCTION; return function NAME(PARAMS) { @@ -15,7 +15,7 @@ let buildWrapper = template(` }) `); -let namedBuildWrapper = template(` +const namedBuildWrapper = template(` (() => { var REF = FUNCTION; function NAME(PARAMS) { @@ -25,7 +25,7 @@ let namedBuildWrapper = template(` }) `); -let awaitVisitor = { +const awaitVisitor = { Function(path) { if (path.isArrowFunctionExpression() && !path.node.async) { path.arrowFunctionToShadowed(); @@ -41,16 +41,17 @@ let awaitVisitor = { } }, - ForAwaitStatement(path, { file, wrapAwait }) { - let { node } = path; + ForOfStatement(path, { file, wrapAwait }) { + const { node } = path; + if (!node.await) return; - let build = rewriteForAwait(path, { + const build = rewriteForAwait(path, { getAsyncIterator: file.addHelper("asyncIterator"), - wrapAwait + wrapAwait, }); - let { declar, loop } = build; - let block = loop.body; + const { declar, loop } = build; + const block = loop.body; // ensure that it's a block so we can take all its statements path.ensureBlock(); @@ -72,23 +73,23 @@ let awaitVisitor = { } else { path.replaceWithMultiple(build.node); } - } + }, }; function classOrObjectMethod(path: NodePath, callId: Object) { - let node = path.node; - let body = node.body; + const node = path.node; + const body = node.body; node.async = false; - let container = t.functionExpression(null, [], t.blockStatement(body.body), true); + const container = t.functionExpression(null, [], t.blockStatement(body.body), true); container.shadow = true; body.body = [ t.returnStatement(t.callExpression( t.callExpression(callId, [container]), [] - )) + )), ]; // Regardless of whether or not the wrapped function is a an async method @@ -97,9 +98,9 @@ function classOrObjectMethod(path: NodePath, callId: Object) { } function plainFunction(path: NodePath, callId: Object) { - let node = path.node; - let isDeclaration = path.isFunctionDeclaration(); - let asyncFnId = node.id; + const node = path.node; + const isDeclaration = path.isFunctionDeclaration(); + const asyncFnId = node.id; let wrapper = buildWrapper; if (path.isArrowFunctionExpression()) { @@ -117,8 +118,8 @@ function plainFunction(path: NodePath, callId: Object) { node.type = "FunctionExpression"; } - let built = t.callExpression(callId, [node]); - let container = wrapper({ + const built = t.callExpression(callId, [node]); + const container = wrapper({ NAME: asyncFnId, REF: path.scope.generateUidIdentifier("ref"), FUNCTION: built, @@ -137,22 +138,39 @@ function plainFunction(path: NodePath, callId: Object) { }).expression; if (isDeclaration) { - let declar = t.variableDeclaration("let", [ + const declar = t.variableDeclaration("let", [ t.variableDeclarator( t.identifier(asyncFnId.name), t.callExpression(container, []) - ) + ), ]); declar._blockHoist = true; + if (path.parentPath.isExportDefaultDeclaration()) { + // change the path type so that replaceWith() does not wrap + // the identifier into an expressionStatement + path.parentPath.insertBefore(declar); + path.parentPath.replaceWith( + t.exportNamedDeclaration(null, + [ + t.exportSpecifier( + t.identifier(asyncFnId.name), + t.identifier("default") + ), + ] + ) + ); + return; + } + path.replaceWith(declar); } else { - let retFunction = container.body.body[1].argument; + const retFunction = container.body.body[1].argument; if (!asyncFnId) { nameFunction({ node: retFunction, parent: path.parent, - scope: path.scope + scope: path.scope, }); } @@ -174,7 +192,7 @@ export default function (path: NodePath, file: Object, helpers: Object) { } path.traverse(awaitVisitor, { file, - wrapAwait: helpers.wrapAwait + wrapAwait: helpers.wrapAwait, }); if (path.isClassMethod() || path.isObjectMethod()) { diff --git a/packages/babel-helper-replace-supers/package.json b/packages/babel-helper-replace-supers/package.json index a9da5aa291..798f1299f8 100644 --- a/packages/babel-helper-replace-supers/package.json +++ b/packages/babel-helper-replace-supers/package.json @@ -1,16 +1,15 @@ { "name": "babel-helper-replace-supers", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Helper function to replace supers", "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-helper-optimise-call-expression": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-traverse": "^6.18.0", - "babel-messages": "^6.8.0", - "babel-template": "^6.16.0", - "babel-types": "^6.18.0" + "babel-helper-optimise-call-expression": "7.0.0-alpha.1", + "babel-traverse": "7.0.0-alpha.1", + "babel-messages": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" } } diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index 8465df1936..2a88d5e296 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -1,12 +1,10 @@ -/* eslint max-len: 0 */ - import type { NodePath, Scope } from "babel-traverse"; import optimiseCall from "babel-helper-optimise-call-expression"; import * as messages from "babel-messages"; import * as t from "babel-types"; // ✌️ -let HARDCORE_THIS_REF = Symbol(); +const HARDCORE_THIS_REF = Symbol(); function isIllegalBareSuper(node, parent) { if (!t.isSuper(node)) return false; @@ -40,13 +38,13 @@ function getPrototypeOfExpression(objectRef, isStatic) { t.callExpression( t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [ - targetRef + targetRef, ] ), ); } -let visitor = { +const visitor = { Function(path) { if (!path.inShadow("this")) { path.skip(); @@ -69,9 +67,9 @@ let visitor = { let callback = state.specHandle; if (state.isLoose) callback = state.looseHandle; - let isBareSuper = path.isCallExpression() && path.get("callee").isSuper(); + const isBareSuper = path.isCallExpression() && path.get("callee").isSuper(); - let result = callback.call(state, path); + const result = callback.call(state, path); if (result) { state.hasSuper = true; @@ -92,26 +90,26 @@ let visitor = { path.replaceWith(result); } } - } + }, }; export default class ReplaceSupers { constructor(opts: Object, inClass?: boolean = false) { this.forceSuperMemoisation = opts.forceSuperMemoisation; - this.methodPath = opts.methodPath; - this.methodNode = opts.methodNode; - this.superRef = opts.superRef; - this.isStatic = opts.isStatic; - this.hasSuper = false; - this.inClass = inClass; - this.isLoose = opts.isLoose; - this.scope = this.methodPath.scope; - this.file = opts.file; - this.opts = opts; + this.methodPath = opts.methodPath; + this.methodNode = opts.methodNode; + this.superRef = opts.superRef; + this.isStatic = opts.isStatic; + this.hasSuper = false; + this.inClass = inClass; + this.isLoose = opts.isLoose; + this.scope = this.methodPath.scope; + this.file = opts.file; + this.opts = opts; this.bareSupers = []; - this.returns = []; - this.thises = []; + this.returns = []; + this.thises = []; } forceSuperMemoisation: boolean; @@ -144,7 +142,8 @@ export default class ReplaceSupers { * * @example * - * _set(CLASS.prototype.__proto__ || Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this) + * _set(CLASS.prototype.__proto__ || Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", + * this) * */ @@ -155,7 +154,7 @@ export default class ReplaceSupers { getPrototypeOfExpression(this.getObjectRef(), this.isStatic), isComputed ? property : t.stringLiteral(property.name), value, - t.thisExpression() + t.thisExpression(), ] ); } @@ -175,7 +174,7 @@ export default class ReplaceSupers { [ getPrototypeOfExpression(this.getObjectRef(), this.isStatic), isComputed ? property : t.stringLiteral(property.name), - t.thisExpression() + t.thisExpression(), ] ); } @@ -185,8 +184,8 @@ export default class ReplaceSupers { } getLooseSuperProperty(id: Object, parent: Object) { - let methodNode = this.methodNode; - let superRef = this.superRef || t.identifier("Function"); + const methodNode = this.methodNode; + const superRef = this.superRef || t.identifier("Function"); if (parent.property === id) { return; @@ -201,11 +200,11 @@ export default class ReplaceSupers { } looseHandle(path: NodePath) { - let node = path.node; + const node = path.node; if (path.isSuper()) { return this.getLooseSuperProperty(node, path.parent); } else if (path.isCallExpression()) { - let callee = node.callee; + const callee = node.callee; if (!t.isMemberExpression(callee)) return; if (!t.isSuper(callee.object)) return; @@ -225,11 +224,10 @@ export default class ReplaceSupers { ref = ref || path.scope.generateUidIdentifier("ref"); return [ t.variableDeclaration("var", [ - t.variableDeclarator(ref, node.left) + t.variableDeclarator(ref, node.left), ]), - t.expressionStatement( - t.assignmentExpression("=", node.left, t.binaryExpression(node.operator[0], ref, node.right)) - ) + t.expressionStatement(t.assignmentExpression("=", node.left, + t.binaryExpression(node.operator[0], ref, node.right))), ]; } } @@ -239,35 +237,43 @@ export default class ReplaceSupers { let computed; let args; - let parent = path.parent; - let node = path.node; + const parent = path.parent; + const node = path.node; if (isIllegalBareSuper(node, parent)) { throw path.buildCodeFrameError(messages.get("classesIllegalBareSuper")); } if (t.isCallExpression(node)) { - let callee = node.callee; + const callee = node.callee; if (t.isSuper(callee)) { return; } else if (isMemberExpressionSuper(callee)) { - // super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this); + // super.test(); + // to + // _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this); property = callee.property; computed = callee.computed; args = node.arguments; } } else if (t.isMemberExpression(node) && t.isSuper(node.object)) { - // super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this); + // super.name; + // to + // _get(Object.getPrototypeOf(objectRef.prototype), "name", this); property = node.property; computed = node.computed; } else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) { - let binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1)); + const binary = t.binaryExpression(node.operator[0], node.argument, t.numericLiteral(1)); if (node.prefix) { - // ++super.foo; -> super.foo += 1; + // ++super.foo; + // to + // super.foo += 1; return this.specHandleAssignmentExpression(null, path, binary); } else { - // super.foo++; -> let _ref = super.foo; super.foo = _ref + 1; - let ref = path.scope.generateUidIdentifier("ref"); + // super.foo++; + // to + // let _ref = super.foo; super.foo = _ref + 1; + const ref = path.scope.generateUidIdentifier("ref"); return this.specHandleAssignmentExpression(ref, path, binary).concat(t.expressionStatement(ref)); } } else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) { @@ -276,7 +282,7 @@ export default class ReplaceSupers { if (!property) return; - let superProperty = this.getSuperProperty(property, computed); + const superProperty = this.getSuperProperty(property, computed); if (args) { return this.optimiseCall(superProperty, args); @@ -286,7 +292,7 @@ export default class ReplaceSupers { } optimiseCall(callee, args) { - let thisNode = t.thisExpression(); + const thisNode = t.thisExpression(); thisNode[HARDCORE_THIS_REF] = true; return optimiseCall(callee, thisNode, args); } diff --git a/packages/babel-helper-transform-fixture-test-runner/package.json b/packages/babel-helper-transform-fixture-test-runner/package.json index b95f3b57d4..01f5ab0d4c 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": "6.21.0", + "version": "7.0.0-alpha.2", "description": "Transform test runner for babel-helper-fixtures module", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,13 +8,13 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.20.0", - "babel-core": "^6.21.0", - "babel-polyfill": "^6.20.0", - "babel-helper-fixtures": "^6.20.0", - "source-map": "^0.5.0", - "babel-code-frame": "^6.20.0", + "babel-code-frame": "7.0.0-alpha.1", + "babel-core": "7.0.0-alpha.2", + "babel-polyfill": "7.0.0-alpha.1", + "babel-helper-fixtures": "7.0.0-alpha.1", "chai": "^3.0.0", - "lodash": "^4.2.0" + "lodash": "^4.2.0", + "resolve": "^1.3.2", + "source-map": "^0.5.0" } } diff --git a/packages/babel-helper-transform-fixture-test-runner/src/helpers.js b/packages/babel-helper-transform-fixture-test-runner/src/helpers.js index bd4a61d3b9..f289042638 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/helpers.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/helpers.js @@ -16,4 +16,4 @@ export function multiline(arr) { return arr.join("\n"); } -export let assertArrayEquals = assert.deepEqual; +export const assertArrayEquals = assert.deepEqual; 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 9fced3069f..6afb777bd3 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.js @@ -3,15 +3,88 @@ import { buildExternalHelpers } from "babel-core"; import getFixtures from "babel-helper-fixtures"; import sourceMap from "source-map"; import codeFrame from "babel-code-frame"; +import defaults from "lodash/defaults"; +import includes from "lodash/includes"; import * as helpers from "./helpers"; +import extend from "lodash/extend"; +import merge from "lodash/merge"; +import resolve from "resolve"; import assert from "assert"; import chai from "chai"; -import _ from "lodash"; -import "babel-polyfill"; import fs from "fs"; import path from "path"; +import vm from "vm"; -let babelHelpers = eval(buildExternalHelpers(null, "var")); +const moduleCache = {}; +const testContext = vm.createContext({ + ...helpers, + assert: chai.assert, + transform: babel.transform, +}); +testContext.global = testContext; + +// Initialize the test context with the polyfill, and then freeze the global to prevent implicit +// global creation in tests, which could cause things to bleed between tests. +runModuleInTestContext("babel-polyfill", __filename); + +// Populate the "babelHelpers" global with Babel's helper utilities. +runCodeInTestContext(buildExternalHelpers()); + +/** + * A basic implementation of CommonJS so we can execute `babel-polyfill` inside our test context. + * This allows us to run our unittests + */ +function runModuleInTestContext(id: string, relativeFilename: string) { + const filename = resolve.sync(id, { basedir: path.dirname(relativeFilename) }); + + // Expose Node-internal modules if the tests want them. Note, this will not execute inside + // the context's global scope. + if (filename === id) return require(id); + + if (moduleCache[filename]) return moduleCache[filename].exports; + + const module = moduleCache[filename] = { + id: filename, + exports: {}, + }; + const dirname = path.dirname(filename); + const req = (id) => runModuleInTestContext(id, filename); + + const src = fs.readFileSync(filename, "utf8"); + const code = `(function (exports, require, module, __filename, __dirname) {${src}\n});`; + + vm.runInContext(code, testContext, { + filename, + displayErrors: true, + }).call(module.exports, module.exports, req, module, filename, dirname); + + return module.exports; +} + +/** + * Run the given snippet of code inside a CommonJS module. + * + * Exposed for unit tests, not for use as an API. + */ +export function runCodeInTestContext(code: string, opts: {filename?: string} = {}) { + const filename = opts.filename || null; + const dirname = filename ? path.dirname(filename) : null; + const req = filename ? ((id) => runModuleInTestContext(id, filename)) : null; + + const module = { + id: filename, + exports: {}, + }; + + // Expose the test options as "opts", but otherwise run the test in a CommonJS-like environment. + // Note: This isn't doing .call(module.exports, ...) because some of our tests currently + // rely on 'this === global'. + const src = `(function(exports, require, module, __filename, __dirname, opts) {${code}\n});`; + return vm.runInContext(src, testContext, { + filename, + displayErrors: true, + })(module.exports, req, module, filename, dirname, opts); +} function wrapPackagesArray(type, names, optionsDir) { return (names || []).map(function (val) { @@ -21,7 +94,8 @@ function wrapPackagesArray(type, names, optionsDir) { if (val[0][0] === ".") { if (!optionsDir) { - throw new Error("Please provide an options.json in test dir when using a relative plugin path."); + throw new Error("Please provide an options.json in test dir when using a " + + "relative plugin path."); } val[0] = path.resolve(optionsDir, val[0]); @@ -36,21 +110,22 @@ function wrapPackagesArray(type, names, optionsDir) { } function run(task) { - let actual = task.actual; - let expect = task.expect; - let exec = task.exec; - let opts = task.options; - let optionsDir = task.optionsDir; + const actual = task.actual; + const expect = task.expect; + const exec = task.exec; + const opts = task.options; + const optionsDir = task.optionsDir; function getOpts(self) { - let newOpts = _.merge({ + const newOpts = merge({ filename: self.loc, }, opts); newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins, optionsDir); newOpts.presets = wrapPackagesArray("preset", newOpts.presets, optionsDir).map(function (val) { if (val.length > 2) { - throw new Error(`Unexpected extra options ${JSON.stringify(val.slice(2))} passed to preset.`); + throw new Error("Unexpected extra options " + JSON.stringify(val.slice(2)) + + " passed to preset."); } return val; @@ -64,13 +139,12 @@ function run(task) { let resultExec; if (execCode) { - let execOpts = getOpts(exec); - let execDirName = path.dirname(exec.loc); + const execOpts = getOpts(exec); result = babel.transform(execCode, execOpts); execCode = result.code; try { - resultExec = runExec(execOpts, execCode, execDirName); + resultExec = runCodeInTestContext(execCode, execOpts); } catch (err) { err.message = exec.loc + ": " + err.message; err.message += codeFrame(execCode); @@ -79,10 +153,13 @@ function run(task) { } let actualCode = actual.code; - let expectCode = expect.code; + const expectCode = expect.code; if (!execCode || actualCode) { result = babel.transform(actualCode, getOpts(actual)); - if (!expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) { + if ( + !expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() && + !process.env.CI + ) { console.log(`New test file created: ${expect.loc}`); fs.writeFileSync(expect.loc, result.code); } else { @@ -96,12 +173,12 @@ function run(task) { } if (task.sourceMappings) { - let consumer = new sourceMap.SourceMapConsumer(result.map); + const consumer = new sourceMap.SourceMapConsumer(result.map); - _.each(task.sourceMappings, function (mapping) { - let actual = mapping.original; + task.sourceMappings.forEach(function (mapping) { + const actual = mapping.original; - let expect = consumer.originalPositionFor(mapping.generated); + const expect = consumer.originalPositionFor(mapping.generated); chai.expect({ line: expect.line, column: expect.column }).to.deep.equal(actual); }); } @@ -111,23 +188,6 @@ function run(task) { } } -function runExec(opts, execCode, execDirname) { - let sandbox = { - ...helpers, - babelHelpers, - assert: chai.assert, - transform: babel.transform, - opts, - exports: {}, - require(id) { - return require(id[0] === "." ? path.resolve(execDirname, id) : id); - } - }; - - let fn = new Function(...Object.keys(sandbox), execCode); - return fn.apply(null, Object.values(sandbox)); -} - export default function ( fixturesLoc: string, name: string, @@ -135,35 +195,35 @@ export default function ( taskOpts = {}, dynamicOpts?: Function, ) { - let suites = getFixtures(fixturesLoc); + const suites = getFixtures(fixturesLoc); - for (let testSuite of suites) { - if (_.includes(suiteOpts.ignoreSuites, testSuite.title)) continue; + for (const testSuite of suites) { + if (includes(suiteOpts.ignoreSuites, testSuite.title)) continue; describe(name + "/" + testSuite.title, function () { - for (let task of testSuite.tests) { - if (_.includes(suiteOpts.ignoreTasks, task.title) || - _.includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) continue; + for (const task of testSuite.tests) { + if (includes(suiteOpts.ignoreTasks, task.title) || + includes(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) continue; it(task.title, !task.disabled && function () { function runTask() { run(task); } - _.defaults(task.options, { + defaults(task.options, { filenameRelative: task.expect.filename, - sourceFileName: task.actual.filename, - sourceMapTarget: task.expect.filename, + sourceFileName: task.actual.filename, + sourceMapTarget: task.expect.filename, suppressDeprecationMessages: true, babelrc: false, sourceMap: !!(task.sourceMappings || task.sourceMap), }); - _.extend(task.options, taskOpts); + extend(task.options, taskOpts); if (dynamicOpts) dynamicOpts(task.options, task); - let throwMsg = task.options.throws; + const throwMsg = task.options.throws; if (throwMsg) { // internal api doesn't have this option but it's best not to pollute // the options object with useless options @@ -174,7 +234,7 @@ export default function ( }); } else { if (task.exec.code) { - let result = run(task); + const result = run(task); if (result && typeof result.then === "function") { return result; } diff --git a/packages/babel-helper-transform-fixture-test-runner/test/index.js b/packages/babel-helper-transform-fixture-test-runner/test/index.js new file mode 100644 index 0000000000..f6c1baefd4 --- /dev/null +++ b/packages/babel-helper-transform-fixture-test-runner/test/index.js @@ -0,0 +1,24 @@ +import assert from "assert"; +import { runCodeInTestContext } from ".."; + +describe("helper-transform-fixture-test-runner", function() { + it("should not execute code in Node's global context", function() { + try { + global.foo = "outer"; + runCodeInTestContext(` + assert.equal(global.foo, undefined); + global.foo = "inner"; + `); + + assert.equal(global.foo, "outer"); + runCodeInTestContext(` + assert.equal(global.foo, "inner"); + `); + } finally { + delete global.foo; + runCodeInTestContext(` + delete global.foo; + `); + } + }); +}); diff --git a/packages/babel-helpers/README.md b/packages/babel-helpers/README.md index 5a57c5d46a..2614f1160e 100644 --- a/packages/babel-helpers/README.md +++ b/packages/babel-helpers/README.md @@ -4,7 +4,7 @@ ## Install -```js +```sh npm install --save-dev babel-helpers ``` diff --git a/packages/babel-helpers/package.json b/packages/babel-helpers/package.json index 645ca47f51..a2039ecdbd 100644 --- a/packages/babel-helpers/package.json +++ b/packages/babel-helpers/package.json @@ -1,6 +1,6 @@ { "name": "babel-helpers", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Collection of helper functions used by Babel transforms.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,7 +8,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.0.0", - "babel-template": "^6.16.0" + "babel-template": "7.0.0-alpha.1" } } diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 87a58c3dc9..d7d20aedfd 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1,8 +1,8 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ import template from "babel-template"; -let helpers = {}; +const helpers = {}; export default helpers; helpers.typeof = template(` diff --git a/packages/babel-helpers/src/index.js b/packages/babel-helpers/src/index.js index e742f224a3..c25dce9c14 100644 --- a/packages/babel-helpers/src/index.js +++ b/packages/babel-helpers/src/index.js @@ -1,16 +1,14 @@ -/* eslint no-confusing-arrow: 0 */ - import helpers from "./helpers"; export function get(name) { - let fn = helpers[name]; + const fn = helpers[name]; if (!fn) throw new ReferenceError(`Unknown helper ${name}`); return fn().expression; } -export let list = Object.keys(helpers) - .map((name) => name[0] === "_" ? name.slice(1) : name) +export const list = Object.keys(helpers) + .map((name) => name.replace(/^_/, "")) .filter((name) => name !== "__esModule"); export default get; diff --git a/packages/babel-messages/package.json b/packages/babel-messages/package.json index 5f621dc458..a769e68278 100644 --- a/packages/babel-messages/package.json +++ b/packages/babel-messages/package.json @@ -1,13 +1,10 @@ { "name": "babel-messages", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Collection of debug messages used by Babel.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-messages", - "main": "lib/index.js", - "dependencies": { - "babel-runtime": "^6.0.0" - } + "main": "lib/index.js" } diff --git a/packages/babel-messages/src/index.js b/packages/babel-messages/src/index.js index 3fce2e2cf2..aefd7d46a0 100644 --- a/packages/babel-messages/src/index.js +++ b/packages/babel-messages/src/index.js @@ -1,4 +1,4 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ import * as util from "util"; @@ -40,7 +40,7 @@ export const MESSAGES = { pluginNotObject: "Plugin $2 specified in $1 was expected to return an object when invoked but returned $3", pluginNotFunction: "Plugin $2 specified in $1 was expected to return a function but returned $3", pluginUnknown: "Unknown plugin $1 specified in $2 at $3, attempted to resolve relative to $4", - pluginInvalidProperty: "Plugin $2 specified in $1 provided an invalid property of $3" + pluginInvalidProperty: "Plugin $2 specified in $1 provided an invalid property of $3", }; /** @@ -48,7 +48,7 @@ export const MESSAGES = { */ export function get(key: string, ...args: Array): string { - let msg = MESSAGES[key]; + const msg = MESSAGES[key]; if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`); // stringify args diff --git a/packages/babel-plugin-check-es2015-constants/README.md b/packages/babel-plugin-check-es2015-constants/README.md index ee85b823e7..1ee65e3f07 100644 --- a/packages/babel-plugin-check-es2015-constants/README.md +++ b/packages/babel-plugin-check-es2015-constants/README.md @@ -20,7 +20,6 @@ repl: "a" is read-only | ^ ``` -[Try in REPL](http://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015&experimental=false&loose=false&spec=false&code=const%20a%20%3D%201%3B%0Aa%20%3D%202%3B&playground=true) ## Installation @@ -56,4 +55,4 @@ require("babel-core").transform("code", { ## Note -This check will only validate consts. If you need it to compile down to `var` then you must also install and enable [`transform-es2015-block-scoping`](../babel-plugin-transform-es2015-block-scoping). +This check will only validate consts. If you need it to compile down to `var` then you must also install and enable [`transform-es2015-block-scoping`](http://babeljs.io/docs/plugins/transform-es2015-block-scoping/). diff --git a/packages/babel-plugin-check-es2015-constants/package.json b/packages/babel-plugin-check-es2015-constants/package.json index 7c9a0ac58b..c54d9bb856 100644 --- a/packages/babel-plugin-check-es2015-constants/package.json +++ b/packages/babel-plugin-check-es2015-constants/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-check-es2015-constants", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 constants to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-check-es2015-constants", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-check-es2015-constants/src/index.js b/packages/babel-plugin-check-es2015-constants/src/index.js index 4269b0385c..ccc79b1b16 100644 --- a/packages/babel-plugin-check-es2015-constants/src/index.js +++ b/packages/babel-plugin-check-es2015-constants/src/index.js @@ -2,15 +2,15 @@ export default function ({ messages }) { return { visitor: { Scope({ scope }) { - for (let name in scope.bindings) { - let binding = scope.bindings[name]; + for (const name in scope.bindings) { + const binding = scope.bindings[name]; if (binding.kind !== "const" && binding.kind !== "module") continue; - for (let violation of (binding.constantViolations: Array)) { + for (const violation of (binding.constantViolations: Array)) { throw violation.buildCodeFrameError(messages.get("readOnly", name)); } } }, - } + }, }; } diff --git a/packages/babel-plugin-check-es2015-constants/test/index.js b/packages/babel-plugin-check-es2015-constants/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-check-es2015-constants/test/index.js +++ b/packages/babel-plugin-check-es2015-constants/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-external-helpers/package.json b/packages/babel-plugin-external-helpers/package.json index c03298e29a..2820e253c3 100644 --- a/packages/babel-plugin-external-helpers/package.json +++ b/packages/babel-plugin-external-helpers/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-external-helpers", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin contains helper functions that’ll be placed at the top of the generated code", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-external-helpers", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-external-helpers/src/index.js b/packages/babel-plugin-external-helpers/src/index.js index 2103ae9131..5bc3235f86 100644 --- a/packages/babel-plugin-external-helpers/src/index.js +++ b/packages/babel-plugin-external-helpers/src/index.js @@ -2,6 +2,6 @@ export default function ({ types: t }) { return { pre(file) { file.set("helpersNamespace", t.identifier("babelHelpers")); - } + }, }; } diff --git a/packages/babel-plugin-syntax-async-functions/package.json b/packages/babel-plugin-syntax-async-functions/package.json index ef46b578c5..fd2f81d061 100644 --- a/packages/babel-plugin-syntax-async-functions/package.json +++ b/packages/babel-plugin-syntax-async-functions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-async-functions", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of async functions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-functions", "license": "MIT", diff --git a/packages/babel-plugin-syntax-async-functions/src/index.js b/packages/babel-plugin-syntax-async-functions/src/index.js index a95134d839..11939db7dd 100644 --- a/packages/babel-plugin-syntax-async-functions/src/index.js +++ b/packages/babel-plugin-syntax-async-functions/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("asyncFunctions"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-async-generators/package.json b/packages/babel-plugin-syntax-async-generators/package.json index a17544f1ea..de3f839b7a 100644 --- a/packages/babel-plugin-syntax-async-generators/package.json +++ b/packages/babel-plugin-syntax-async-generators/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-async-generators", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of async generator functions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-generators", "license": "MIT", diff --git a/packages/babel-plugin-syntax-async-generators/src/index.js b/packages/babel-plugin-syntax-async-generators/src/index.js index 4064178ff1..9bccbfa57a 100644 --- a/packages/babel-plugin-syntax-async-generators/src/index.js +++ b/packages/babel-plugin-syntax-async-generators/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("asyncGenerators"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-class-constructor-call/.npmignore b/packages/babel-plugin-syntax-class-constructor-call/.npmignore deleted file mode 100644 index cace0d6ddc..0000000000 --- a/packages/babel-plugin-syntax-class-constructor-call/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -*.log -src diff --git a/packages/babel-plugin-syntax-class-constructor-call/README.md b/packages/babel-plugin-syntax-class-constructor-call/README.md deleted file mode 100644 index 6b3a3e804e..0000000000 --- a/packages/babel-plugin-syntax-class-constructor-call/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# babel-plugin-syntax-class-constructor-call (deprecated) - -> Proposal Withdrawn: can be solved with decorators. - -Allow parsing of call constructors. - -## Installation - -```sh -npm install --save-dev babel-plugin-syntax-class-constructor-call -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["syntax-class-constructor-call"] -} -``` - -### Via CLI - -```sh -babel --plugins syntax-class-constructor-call script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["syntax-class-constructor-call"] -}); -``` - -## References - -* [Inactive Proposals](https://github.com/tc39/proposals/blob/master/inactive-proposals.md) -* [Proposal: Call Constructor](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md) -* [Blog post: ECMAScript proposal: function-callable classes](http://www.2ality.com/2015/10/call-constructor-esprop.html) diff --git a/packages/babel-plugin-syntax-class-constructor-call/package.json b/packages/babel-plugin-syntax-class-constructor-call/package.json deleted file mode 100644 index 2be301b342..0000000000 --- a/packages/babel-plugin-syntax-class-constructor-call/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "babel-plugin-syntax-class-constructor-call", - "version": "6.18.0", - "description": "Allow parsing of class constructor calls (deprecated)", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-class-constructor-call", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": {}, - "devDependencies": {} -} diff --git a/packages/babel-plugin-syntax-class-constructor-call/src/index.js b/packages/babel-plugin-syntax-class-constructor-call/src/index.js deleted file mode 100644 index d3839a279c..0000000000 --- a/packages/babel-plugin-syntax-class-constructor-call/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function () { - return { - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("classConstructorCall"); - } - }; -} diff --git a/packages/babel-plugin-syntax-class-properties/package.json b/packages/babel-plugin-syntax-class-properties/package.json index 5882a28eab..d8949ccd7a 100644 --- a/packages/babel-plugin-syntax-class-properties/package.json +++ b/packages/babel-plugin-syntax-class-properties/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-class-properties", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of class properties", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-class-properties", "license": "MIT", diff --git a/packages/babel-plugin-syntax-class-properties/src/index.js b/packages/babel-plugin-syntax-class-properties/src/index.js index d9ba5cf12f..481b7be1e8 100644 --- a/packages/babel-plugin-syntax-class-properties/src/index.js +++ b/packages/babel-plugin-syntax-class-properties/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("classProperties"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-decorators/package.json b/packages/babel-plugin-syntax-decorators/package.json index aeb4e0b2d7..0278b74a8c 100644 --- a/packages/babel-plugin-syntax-decorators/package.json +++ b/packages/babel-plugin-syntax-decorators/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-decorators", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of decorators", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-decorators", "license": "MIT", diff --git a/packages/babel-plugin-syntax-decorators/src/index.js b/packages/babel-plugin-syntax-decorators/src/index.js index db7392f158..8bd18d37b7 100644 --- a/packages/babel-plugin-syntax-decorators/src/index.js +++ b/packages/babel-plugin-syntax-decorators/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("decorators"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-do-expressions/package.json b/packages/babel-plugin-syntax-do-expressions/package.json index 027e697816..cb886b7cae 100644 --- a/packages/babel-plugin-syntax-do-expressions/package.json +++ b/packages/babel-plugin-syntax-do-expressions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-do-expressions", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of do expressions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-do-expressions", "license": "MIT", diff --git a/packages/babel-plugin-syntax-do-expressions/src/index.js b/packages/babel-plugin-syntax-do-expressions/src/index.js index 469b32173e..bb09f4c9f5 100644 --- a/packages/babel-plugin-syntax-do-expressions/src/index.js +++ b/packages/babel-plugin-syntax-do-expressions/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("doExpressions"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-dynamic-import/package.json b/packages/babel-plugin-syntax-dynamic-import/package.json index 4ef935f7f7..f1b52f3a52 100644 --- a/packages/babel-plugin-syntax-dynamic-import/package.json +++ b/packages/babel-plugin-syntax-dynamic-import/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-dynamic-import", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of import()", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import", "license": "MIT", diff --git a/packages/babel-plugin-syntax-dynamic-import/src/index.js b/packages/babel-plugin-syntax-dynamic-import/src/index.js index 729c741629..ebcaaa4a19 100644 --- a/packages/babel-plugin-syntax-dynamic-import/src/index.js +++ b/packages/babel-plugin-syntax-dynamic-import/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("dynamicImport"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-exponentiation-operator/package.json b/packages/babel-plugin-syntax-exponentiation-operator/package.json index 94c1d041e9..1c83d8f509 100644 --- a/packages/babel-plugin-syntax-exponentiation-operator/package.json +++ b/packages/babel-plugin-syntax-exponentiation-operator/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-exponentiation-operator", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of the exponentiation operator", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-exponentation-operator", "license": "MIT", diff --git a/packages/babel-plugin-syntax-exponentiation-operator/src/index.js b/packages/babel-plugin-syntax-exponentiation-operator/src/index.js index 943542f771..a8001e291c 100644 --- a/packages/babel-plugin-syntax-exponentiation-operator/src/index.js +++ b/packages/babel-plugin-syntax-exponentiation-operator/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("exponentiationOperator"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-export-extensions/package.json b/packages/babel-plugin-syntax-export-extensions/package.json index 9a86e90236..83f9afeeb4 100644 --- a/packages/babel-plugin-syntax-export-extensions/package.json +++ b/packages/babel-plugin-syntax-export-extensions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-export-extensions", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of export extensions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-export-extensions", "license": "MIT", diff --git a/packages/babel-plugin-syntax-export-extensions/src/index.js b/packages/babel-plugin-syntax-export-extensions/src/index.js index 8bc33ab44d..b2a6727fce 100644 --- a/packages/babel-plugin-syntax-export-extensions/src/index.js +++ b/packages/babel-plugin-syntax-export-extensions/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("exportExtensions"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-flow/package.json b/packages/babel-plugin-syntax-flow/package.json index 2a701dd854..a0f4e85651 100644 --- a/packages/babel-plugin-syntax-flow/package.json +++ b/packages/babel-plugin-syntax-flow/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-flow", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of the flow syntax", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-flow", "license": "MIT", diff --git a/packages/babel-plugin-syntax-flow/src/index.js b/packages/babel-plugin-syntax-flow/src/index.js index ac230f4a25..01890b3618 100644 --- a/packages/babel-plugin-syntax-flow/src/index.js +++ b/packages/babel-plugin-syntax-flow/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("flow"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-function-bind/package.json b/packages/babel-plugin-syntax-function-bind/package.json index 8a2de38ac4..5d9a90768c 100644 --- a/packages/babel-plugin-syntax-function-bind/package.json +++ b/packages/babel-plugin-syntax-function-bind/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-function-bind", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of function bind", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-function-bind", "license": "MIT", diff --git a/packages/babel-plugin-syntax-function-bind/src/index.js b/packages/babel-plugin-syntax-function-bind/src/index.js index 2fdf90ffb0..3f05d86ff4 100644 --- a/packages/babel-plugin-syntax-function-bind/src/index.js +++ b/packages/babel-plugin-syntax-function-bind/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("functionBind"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-function-sent/package.json b/packages/babel-plugin-syntax-function-sent/package.json index bd68fcfaa1..54b6a5b906 100644 --- a/packages/babel-plugin-syntax-function-sent/package.json +++ b/packages/babel-plugin-syntax-function-sent/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-function-sent", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of the function.sent meta property", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-function-sent", "license": "MIT", diff --git a/packages/babel-plugin-syntax-function-sent/src/index.js b/packages/babel-plugin-syntax-function-sent/src/index.js index b79f1e04fc..f336b24077 100644 --- a/packages/babel-plugin-syntax-function-sent/src/index.js +++ b/packages/babel-plugin-syntax-function-sent/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("functionSent"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-jsx/package.json b/packages/babel-plugin-syntax-jsx/package.json index d9a604d01e..bc8a740dfc 100644 --- a/packages/babel-plugin-syntax-jsx/package.json +++ b/packages/babel-plugin-syntax-jsx/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-jsx", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of jsx", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-jsx", "license": "MIT", diff --git a/packages/babel-plugin-syntax-jsx/src/index.js b/packages/babel-plugin-syntax-jsx/src/index.js index 44e80e966a..e7d1697f3d 100644 --- a/packages/babel-plugin-syntax-jsx/src/index.js +++ b/packages/babel-plugin-syntax-jsx/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("jsx"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-object-rest-spread/package.json b/packages/babel-plugin-syntax-object-rest-spread/package.json index 15554cd3be..fbf44e4280 100644 --- a/packages/babel-plugin-syntax-object-rest-spread/package.json +++ b/packages/babel-plugin-syntax-object-rest-spread/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-object-rest-spread", - "version": "6.13.0", + "version": "7.0.0-alpha.1", "description": "Allow parsing of object rest/spread", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-object-rest-spread", "license": "MIT", diff --git a/packages/babel-plugin-syntax-object-rest-spread/src/index.js b/packages/babel-plugin-syntax-object-rest-spread/src/index.js index 7792d54dd6..5353e63eed 100644 --- a/packages/babel-plugin-syntax-object-rest-spread/src/index.js +++ b/packages/babel-plugin-syntax-object-rest-spread/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("objectRestSpread"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-trailing-function-commas/README.md b/packages/babel-plugin-syntax-trailing-function-commas/README.md index fd7022b23f..61622bfe69 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/README.md +++ b/packages/babel-plugin-syntax-trailing-function-commas/README.md @@ -14,7 +14,6 @@ clownPuppiesEverywhere( 'bar', ); ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=function%20clownPuppiesEverywhere(%0A%20%20param1%2C%0A%20%20param2%2C%0A)%20%7B%20%2F*%20...%20*%2F%20%7D%0A%0AclownPuppiesEverywhere(%0A%20%20'foo'%2C%0A%20%20'bar'%2C%0A)%3B) ## Example diff --git a/packages/babel-plugin-syntax-trailing-function-commas/package.json b/packages/babel-plugin-syntax-trailing-function-commas/package.json index 74d448be81..fab5f329cd 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/package.json +++ b/packages/babel-plugin-syntax-trailing-function-commas/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-syntax-trailing-function-commas", - "version": "6.20.0", + "version": "7.0.0-alpha.1", "description": "Compile trailing function commas to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-trailing-function-commas", "license": "MIT", @@ -10,6 +10,6 @@ ], "dependencies": {}, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-syntax-trailing-function-commas/src/index.js b/packages/babel-plugin-syntax-trailing-function-commas/src/index.js index d50ddd959c..29d5031933 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/src/index.js +++ b/packages/babel-plugin-syntax-trailing-function-commas/src/index.js @@ -2,6 +2,6 @@ export default function () { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("trailingFunctionCommas"); - } + }, }; } diff --git a/packages/babel-plugin-syntax-trailing-function-commas/test/index.js b/packages/babel-plugin-syntax-trailing-function-commas/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/test/index.js +++ b/packages/babel-plugin-syntax-trailing-function-commas/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-async-functions/package.json b/packages/babel-plugin-transform-async-functions/package.json index 779c3bcf2e..a6d512ecfd 100644 --- a/packages/babel-plugin-transform-async-functions/package.json +++ b/packages/babel-plugin-transform-async-functions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-async-functions", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile async functions to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-functions", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-async-functions": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-async-functions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-functions/src/index.js b/packages/babel-plugin-transform-async-functions/src/index.js index abe7b8a0f7..20eb9f453b 100644 --- a/packages/babel-plugin-transform-async-functions/src/index.js +++ b/packages/babel-plugin-transform-async-functions/src/index.js @@ -1,5 +1,7 @@ +import asyncSyntaxPlugin from "babel-plugin-syntax-async-functions"; + export default function () { return { - inherits: require("babel-plugin-syntax-async-functions") + inherits: asyncSyntaxPlugin, }; } diff --git a/packages/babel-plugin-transform-async-generator-functions/package.json b/packages/babel-plugin-transform-async-generator-functions/package.json index ecd3a8d0d9..84e7abcb7d 100644 --- a/packages/babel-plugin-transform-async-generator-functions/package.json +++ b/packages/babel-plugin-transform-async-generator-functions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-async-generator-functions", - "version": "6.17.0", + "version": "7.0.0-alpha.1", "description": "Turn async generator functions into ES2015 generators", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-generator-functions", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-helper-remap-async-to-generator": "^6.16.2", - "babel-plugin-syntax-async-generators": "^6.5.0", - "babel-runtime": "^6.0.0" + "babel-helper-remap-async-to-generator": "7.0.0-alpha.1", + "babel-plugin-syntax-async-generators": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.3.13" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-generator-functions/src/index.js b/packages/babel-plugin-transform-async-generator-functions/src/index.js index 409b14f364..ebd5903e1d 100644 --- a/packages/babel-plugin-transform-async-generator-functions/src/index.js +++ b/packages/babel-plugin-transform-async-generator-functions/src/index.js @@ -1,23 +1,24 @@ import remapAsyncToGenerator from "babel-helper-remap-async-to-generator"; +import syntaxAsyncGenerators from "babel-plugin-syntax-async-generators"; export default function ({ types: t }) { - let yieldStarVisitor = { + const yieldStarVisitor = { Function(path) { path.skip(); }, YieldExpression({ node }, state) { if (!node.delegate) return; - let callee = state.addHelper("asyncGeneratorDelegate"); + const callee = state.addHelper("asyncGeneratorDelegate"); node.argument = t.callExpression(callee, [ t.callExpression(state.addHelper("asyncIterator"), [node.argument]), - t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("await")) + t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("await")), ]); - } + }, }; return { - inherits: require("babel-plugin-syntax-async-generators"), + inherits: syntaxAsyncGenerators, visitor: { Function(path, state) { if (!path.node.async || !path.node.generator) return; @@ -28,9 +29,9 @@ export default function ({ types: t }) { wrapAsync: t.memberExpression( state.addHelper("asyncGenerator"), t.identifier("wrap")), wrapAwait: t.memberExpression( - state.addHelper("asyncGenerator"), t.identifier("await")) + state.addHelper("asyncGenerator"), t.identifier("await")), }); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-async-generator-functions/test/index.js b/packages/babel-plugin-transform-async-generator-functions/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-async-generator-functions/test/index.js +++ b/packages/babel-plugin-transform-async-generator-functions/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-async-to-generator/package.json b/packages/babel-plugin-transform-async-to-generator/package.json index caadd159e7..ab6c8a89dd 100644 --- a/packages/babel-plugin-transform-async-to-generator/package.json +++ b/packages/babel-plugin-transform-async-to-generator/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-async-to-generator", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Turn async functions into ES2015 generators", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-generator", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-helper-remap-async-to-generator": "^6.16.0", - "babel-plugin-syntax-async-functions": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-helper-remap-async-to-generator": "7.0.0-alpha.1", + "babel-plugin-syntax-async-functions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-to-generator/src/index.js b/packages/babel-plugin-transform-async-to-generator/src/index.js index beabecb253..73caf1bebe 100644 --- a/packages/babel-plugin-transform-async-to-generator/src/index.js +++ b/packages/babel-plugin-transform-async-to-generator/src/index.js @@ -1,17 +1,18 @@ import remapAsyncToGenerator from "babel-helper-remap-async-to-generator"; +import syntaxAsyncFunctions from "babel-plugin-syntax-async-functions"; export default function () { return { - inherits: require("babel-plugin-syntax-async-functions"), + inherits: syntaxAsyncFunctions, visitor: { Function(path, state) { if (!path.node.async || path.node.generator) return; remapAsyncToGenerator(path, state.file, { - wrapAsync: state.addHelper("asyncToGenerator") + wrapAsync: state.addHelper("asyncToGenerator"), }); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/actual.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/actual.js new file mode 100644 index 0000000000..22ad33dc07 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/actual.js @@ -0,0 +1 @@ +export default async () => { return await foo(); } diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/expected.js new file mode 100644 index 0000000000..130cbb5e7f --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-arrow-export/expected.js @@ -0,0 +1,8 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = babelHelpers.asyncToGenerator(function* () { + return yield foo(); +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/actual.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/actual.js new file mode 100644 index 0000000000..9c82a22d00 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/actual.js @@ -0,0 +1 @@ +export default async function myFunc() {} diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/expected.js new file mode 100644 index 0000000000..84d8c21afc --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/default-export/expected.js @@ -0,0 +1,15 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +let myFunc = (() => { + var _ref = babelHelpers.asyncToGenerator(function* () {}); + + return function myFunc() { + return _ref.apply(this, arguments); + }; +})(); + +exports.default = myFunc; \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-to-generator/test/index.js b/packages/babel-plugin-transform-async-to-generator/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/index.js +++ b/packages/babel-plugin-transform-async-to-generator/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-async-to-module-method/README.md b/packages/babel-plugin-transform-async-to-module-method/README.md index 268271a163..116da364f5 100644 --- a/packages/babel-plugin-transform-async-to-module-method/README.md +++ b/packages/babel-plugin-transform-async-to-module-method/README.md @@ -34,13 +34,17 @@ npm install --save-dev babel-plugin-transform-async-to-module-method **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-async-to-module-method"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-async-to-module-method", { diff --git a/packages/babel-plugin-transform-async-to-module-method/package.json b/packages/babel-plugin-transform-async-to-module-method/package.json index d867a68fb4..ed52d24946 100644 --- a/packages/babel-plugin-transform-async-to-module-method/package.json +++ b/packages/babel-plugin-transform-async-to-module-method/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-async-to-module-method", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Turn async functions into a module method", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-module-method", "license": "MIT", @@ -9,12 +9,11 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-async-functions": "^6.8.0", - "babel-helper-remap-async-to-generator": "^6.16.0", - "babel-types": "^6.16.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-async-functions": "7.0.0-alpha.1", + "babel-helper-remap-async-to-generator": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-async-to-module-method/src/index.js b/packages/babel-plugin-transform-async-to-module-method/src/index.js index f9a7706ed1..51a0ab4089 100644 --- a/packages/babel-plugin-transform-async-to-module-method/src/index.js +++ b/packages/babel-plugin-transform-async-to-module-method/src/index.js @@ -1,17 +1,18 @@ import remapAsyncToGenerator from "babel-helper-remap-async-to-generator"; +import syntaxAsyncFunctions from "babel-plugin-syntax-async-functions"; export default function () { return { - inherits: require("babel-plugin-syntax-async-functions"), + inherits: syntaxAsyncFunctions, visitor: { Function(path, state) { if (!path.node.async || path.node.generator) return; remapAsyncToGenerator(path, state.file, { - wrapAsync: state.addImport(state.opts.module, state.opts.method) + wrapAsync: state.addImport(state.opts.module, state.opts.method), }); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-async-to-module-method/test/index.js b/packages/babel-plugin-transform-async-to-module-method/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-async-to-module-method/test/index.js +++ b/packages/babel-plugin-transform-async-to-module-method/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-class-constructor-call/.npmignore b/packages/babel-plugin-transform-class-constructor-call/.npmignore deleted file mode 100644 index 31852902b1..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -*.log -src -test diff --git a/packages/babel-plugin-transform-class-constructor-call/README.md b/packages/babel-plugin-transform-class-constructor-call/README.md deleted file mode 100644 index badb23aef9..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/README.md +++ /dev/null @@ -1,101 +0,0 @@ -# babel-plugin-transform-class-constructor-call (deprecated) - -> Proposal Withdrawn: can be solved with decorators. - -This plugin allows Babel to transform class constructors. - -It basically allows to use the [new.target](http://mdn.io/new.target) feature on ES2015 classes: - -```js -class Point { - - constructor(x, y) { - this.x = x; - this.y = y; - } - - call constructor(x, y) { - return new Point(x, y); - } - -} - -let p1 = new Point(1, 2); // OK -let p2 = Point(3, 4); // OK -``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=class%20Point%20%7B%0A%0A%20%20constructor(x%2C%20y)%20%7B%0A%20%20%20%20this.x%20%3D%20x%3B%0A%20%20%20%20this.y%20%3D%20y%3B%0A%20%20%7D%0A%0A%20%20call%20constructor(x%2C%20y)%20%7B%0A%20%20%20%20return%20new%20Point(x%2C%20y)%3B%0A%20%20%7D%0A%0A%7D%0A%0Alet%20p1%20%3D%20new%20Point(1%2C%202)%3B%20%2F%2F%20OK%0Alet%20p2%20%3D%20Point(3%2C%204)%3B%20%2F%2F%20OK) - -## Example - -### Date example -The javascript [Date](http://mdn.io/date) works this way: - -```js -// You can get a Date instance using the new keyword -let now = new Date(); -console.log(now.getMonth()); // Prints '3' -console.log(now.toString()); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)' - -// You can get a string of the current date using Date as a function: -let nowStr = Date(); -console.log(nowStr); // Prints 'Mon Apr 11 2016 13:26:07 GMT+0100 (BST)' -``` - -It is currently possible to implement something like that using [new.target](http://mdn.io/new.target) (see [example in proposal](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md#motivating-example)) and this new feature makes it available for ES2015 classes. - -A date implementation could be: - -```js -class Date { - constructor() { - // ... - } - - call constructor() { - let date = new Date(); - return date.toString(); - } -} - -let now = new Date(); // Get a Date instance -let nowStr = Date(); // Use the 'call constructor()' part to get a string value of the current date -``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=class%20Date%20%7B%0A%20%20constructor()%20%7B%0A%20%20%20%20%2F%2F%20...%0A%20%20%7D%0A%0A%20%20call%20constructor()%20%7B%0A%20%20%20%20let%20date%20%3D%20new%20Date()%3B%0A%20%20%20%20return%20date.toString()%3B%0A%20%20%7D%0A%7D%0A%0Alet%20now%20%3D%20new%20Date()%3B%20%2F%2F%20Get%20a%20Date%20instance%0Alet%20nowStr%20%3D%20Date()%3B%20%2F%2F%20Use%20the%20'call%20constructor()'%20part%20to%20get%20a%20string%20value%20of%20the%20current%20date) - -## Installation - -```sh -npm install --save-dev babel-plugin-transform-class-constructor-call -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-class-constructor-call"] -} -``` - -### Via CLI - -```sh -babel --plugins transform-class-constructor-call script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-class-constructor-call"] -}); -``` - -## References - -* [Inactive Proposals](https://github.com/tc39/proposals/blob/master/inactive-proposals.md) -* [Proposal: Call Constructor](https://github.com/tc39/ecma262/blob/master/workingdocs/callconstructor.md) -* [Blog post: ECMAScript proposal: function-callable classes](http://www.2ality.com/2015/10/call-constructor-esprop.html) diff --git a/packages/babel-plugin-transform-class-constructor-call/package.json b/packages/babel-plugin-transform-class-constructor-call/package.json deleted file mode 100644 index ccf696c3da..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "babel-plugin-transform-class-constructor-call", - "version": "6.18.0", - "description": "This plugin allows Babel to transform class constructors (deprecated)", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-constructor-call", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "babel-template": "^6.8.0", - "babel-plugin-syntax-class-constructor-call": "^6.18.0", - "babel-runtime": "^6.0.0" - }, - "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" - } -} diff --git a/packages/babel-plugin-transform-class-constructor-call/src/index.js b/packages/babel-plugin-transform-class-constructor-call/src/index.js deleted file mode 100644 index 5d2e80f90f..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/src/index.js +++ /dev/null @@ -1,70 +0,0 @@ -import template from "babel-template"; - -let buildWrapper = template(` - let CLASS_REF = CLASS; - var CALL_REF = CALL; - var WRAPPER_REF = function (...args) { - if (this instanceof WRAPPER_REF) { - return Reflect.construct(CLASS_REF, args); - } else { - return CALL_REF.apply(this, args); - } - }; - WRAPPER_REF.__proto__ = CLASS_REF; - WRAPPER_REF; -`); - -export default function ({ types: t }) { - let ALREADY_VISITED = Symbol(); - - function findConstructorCall(path): ?Object { - let methods: Array = path.get("body.body"); - - for (let method of methods) { - if (method.node.kind === "constructorCall") { - return method; - } - } - - return null; - } - - function handleClassWithCall(constructorCall, classPath) { - let { node } = classPath; - let ref = node.id || classPath.scope.generateUidIdentifier("class"); - - if (classPath.parentPath.isExportDefaultDeclaration()) { - classPath = classPath.parentPath; - classPath.insertAfter(t.exportDefaultDeclaration(ref)); - } - - classPath.replaceWithMultiple(buildWrapper({ - CLASS_REF: classPath.scope.generateUidIdentifier(ref.name), - CALL_REF: classPath.scope.generateUidIdentifier(`${ref.name}Call`), - CALL: t.functionExpression(null, constructorCall.node.params, constructorCall.node.body), - CLASS: t.toExpression(node), - WRAPPER_REF: ref - })); - - constructorCall.remove(); - } - - return { - inherits: require("babel-plugin-syntax-class-constructor-call"), - - visitor: { - Class(path) { - if (path.node[ALREADY_VISITED]) return; - path.node[ALREADY_VISITED] = true; - - let constructorCall = findConstructorCall(path); - - if (constructorCall) { - handleClassWithCall(constructorCall, path); - } else { - return; - } - } - } - }; -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/exec.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/exec.js deleted file mode 100644 index 6141a3f65e..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -class Foo { - constructor() { - this.num = 1; - } - - call constructor() { - return { num: 2 }; - } -} - -assert.equal(new Foo().num, 1); -assert.equal(Foo().num, 2); diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/options.json b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/options.json deleted file mode 100644 index 37e52d209d..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration-exec/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["transform-class-constructor-call", "transform-es2015-classes", "transform-es2015-block-scoping", "transform-es2015-parameters"] -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/actual.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/actual.js deleted file mode 100644 index 1f8b64ef4a..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Foo { - call constructor() { - foo(); - } -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/expected.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/expected.js deleted file mode 100644 index 32e55b668f..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/declaration/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -let _Foo = class Foo {}; - -var _FooCall = function () { - foo(); -}; - -var Foo = function (...args) { - if (this instanceof Foo) { - return Reflect.construct(_Foo, args); - } else { - return _FooCall.apply(this, args); - } -}; - -Foo.__proto__ = _Foo; -Foo; diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/actual.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/actual.js deleted file mode 100644 index aad0d96b1d..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -export default class Foo { - call constructor() { - - } -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/expected.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/expected.js deleted file mode 100644 index 2131254c57..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/export-default/expected.js +++ /dev/null @@ -1,14 +0,0 @@ -let _Foo = class Foo {}; - -var _FooCall = function () {}; - -var Foo = function (...args) { - if (this instanceof Foo) { - return Reflect.construct(_Foo, args); - } else { - return _FooCall.apply(this, args); - } -}; - -Foo.__proto__ = _Foo; -export default Foo; diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/actual.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/actual.js deleted file mode 100644 index 0663cd8a88..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -(class { - call constructor() { - foo(); - } -}); diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/expected.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/expected.js deleted file mode 100644 index 5bedc84e65..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-completion-record/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -let _class2 = class {}; - -var _classCall = function () { - foo(); -}; - -var _class = function (...args) { - if (this instanceof _class) { - return Reflect.construct(_class2, args); - } else { - return _classCall.apply(this, args); - } -}; - -_class.__proto__ = _class2; -_class; diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/exec.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/exec.js deleted file mode 100644 index c276e23ab3..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/exec.js +++ /dev/null @@ -1,12 +0,0 @@ -let Foo = class { - constructor() { - this.num = 1; - } - - call constructor() { - return { num: 2 }; - } -}; - -assert.equal(new Foo().num, 1); -assert.equal(Foo().num, 2); diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/options.json b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/options.json deleted file mode 100644 index 37e52d209d..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression-exec/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["transform-class-constructor-call", "transform-es2015-classes", "transform-es2015-block-scoping", "transform-es2015-parameters"] -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/actual.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/actual.js deleted file mode 100644 index 0da72faf45..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -let Foo = class { - call constructor() { - foo(); - } -}; diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/expected.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/expected.js deleted file mode 100644 index 47ccf7e759..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/expression/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -let Foo = function () { - let _class2 = class {}; - - var _classCall = function () { - foo(); - }; - - var _class = function (...args) { - if (this instanceof _class) { - return Reflect.construct(_class2, args); - } else { - return _classCall.apply(this, args); - } - }; - - _class.__proto__ = _class2; - return _class; -}(); diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/actual.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/actual.js deleted file mode 100644 index 4e6a6de653..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/actual.js +++ /dev/null @@ -1 +0,0 @@ -class Foo {} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/expected.js b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/expected.js deleted file mode 100644 index 4e6a6de653..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/none/expected.js +++ /dev/null @@ -1 +0,0 @@ -class Foo {} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/options.json b/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/options.json deleted file mode 100644 index 98dd15ca98..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/fixtures/class-constructor-call/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["transform-class-constructor-call"] -} diff --git a/packages/babel-plugin-transform-class-constructor-call/test/index.js b/packages/babel-plugin-transform-class-constructor-call/test/index.js deleted file mode 100644 index 1f6634aabd..0000000000 --- a/packages/babel-plugin-transform-class-constructor-call/test/index.js +++ /dev/null @@ -1 +0,0 @@ -require("babel-helper-plugin-test-runner")(__dirname); diff --git a/packages/babel-plugin-transform-class-properties/README.md b/packages/babel-plugin-transform-class-properties/README.md index a4c7ea02c0..49f48223e4 100644 --- a/packages/babel-plugin-transform-class-properties/README.md +++ b/packages/babel-plugin-transform-class-properties/README.md @@ -15,7 +15,7 @@ Below is a class with four class properties which will be transformed. } //Static class properties - static staticProperty = "babeliscool"; + static staticProperty = "babelIsCool"; static staticFunction = function() { return Bork.staticProperty; } @@ -33,7 +33,6 @@ Below is a class with four class properties which will be transformed. console.log(Bork.staticFunction()); // > "babelIsCool" ``` -[Try in REPL](http://babeljs.io/repl/#?babili=false&evaluate=false&lineWrap=false&presets=es2016%2Clatest%2Cstage-2&code=%20%20class%20Bork%20%7B%0A%20%20%20%20%2F%2FProperty%20initilizer%20syntax%0A%20%20%20%20instanceProperty%20%3D%20%22bork%22%3B%0A%20%20%20%20boundFunction%20%3D%20()%20%3D%3E%20%7B%0A%20%20%20%20%20%20return%20this.instanceProperty%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20%2F%2FStatic%20class%20properties%0A%20%20%20%20static%20staticProperty%20%3D%20%22babeliscool%22%3B%0A%20%20%20%20static%20staticFunction%20%3D%20function()%20%7B%0A%20%20%20%20%20%20return%20Bork.staticProperty%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20let%20myBork%20%3D%20new%20Bork%3B%0A%0A%20%20%2F%2FProperty%20initializers%20are%20not%20on%20the%20prototype.%0A%20%20console.log(Bork.prototype.boundFunction)%3B%20%2F%2F%20%3E%20undefined%0A%0A%20%20%2F%2FBound%20functions%20are%20bound%20to%20the%20class%20instance.%0A%20%20console.log(myBork.boundFunction.call(undefined))%3B%20%2F%2F%20%3E%20%22bork%22%0A%0A%20%20%2F%2FStatic%20function%20exists%20on%20the%20class.%0A%20%20console.log(Bork.staticFunction())%3B%20%2F%2F%20%3E%20%22babelIsCool%22) ## Installation @@ -77,7 +76,11 @@ require("babel-core").transform("code", { ## Options -* `spec` - Class properties are compiled to use `Object.defineProperty. Static fields are now defined even if they are not initialized +### `spec` + +`boolean`, defaults to `false`. + +Class properties are compiled to use `Object.defineProperty`. Static fields are now defined even if they are not initialized. ## References diff --git a/packages/babel-plugin-transform-class-properties/package.json b/packages/babel-plugin-transform-class-properties/package.json index 63288d330a..c8462d6102 100644 --- a/packages/babel-plugin-transform-class-properties/package.json +++ b/packages/babel-plugin-transform-class-properties/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-class-properties", - "version": "6.19.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms static class properties as well as properties declared with the property initializer syntax", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-properties", "license": "MIT", @@ -9,12 +9,11 @@ "babel-plugin" ], "dependencies": { - "babel-helper-function-name": "^6.18.0", - "babel-plugin-syntax-class-properties": "^6.8.0", - "babel-runtime": "^6.9.1", - "babel-template": "^6.15.0" + "babel-helper-function-name": "7.0.0-alpha.1", + "babel-plugin-syntax-class-properties": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-class-properties/src/index.js b/packages/babel-plugin-transform-class-properties/src/index.js index 10451b3779..5d58f767e6 100644 --- a/packages/babel-plugin-transform-class-properties/src/index.js +++ b/packages/babel-plugin-transform-class-properties/src/index.js @@ -1,23 +1,23 @@ -/* eslint max-len: 0 */ import nameFunction from "babel-helper-function-name"; import template from "babel-template"; +import syntaxClassProperties from "babel-plugin-syntax-class-properties"; export default function ({ types: t }) { - let findBareSupers = { + const findBareSupers = { Super(path) { if (path.parentPath.isCallExpression({ callee: path.node })) { this.push(path.parentPath); } - } + }, }; - let referenceVisitor = { + const referenceVisitor = { ReferencedIdentifier(path) { if (this.scope.hasOwnBinding(path.node.name)) { this.collision = true; path.skip(); } - } + }, }; const buildObjectDefineProperty = template(` @@ -29,28 +29,29 @@ export default function ({ types: t }) { }); `); - const buildClassPropertySpec = (ref, {key, value, computed}) => buildObjectDefineProperty({ + const buildClassPropertySpec = (ref, { key, value, computed }) => buildObjectDefineProperty({ REF: ref, KEY: (t.isIdentifier(key) && !computed) ? t.stringLiteral(key.name) : key, - VALUE: value ? value : t.identifier("undefined") + VALUE: value ? value : t.identifier("undefined"), }); - const buildClassPropertyNonSpec = (ref, {key, value, computed}) => t.expressionStatement( + const buildClassPropertyNonSpec = (ref, { key, value, computed }) => t.expressionStatement( t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value) ); return { - inherits: require("babel-plugin-syntax-class-properties"), + inherits: syntaxClassProperties, visitor: { Class(path, state) { - const buildClassProperty = state.opts.spec ? buildClassPropertySpec : buildClassPropertyNonSpec; - let isDerived = !!path.node.superClass; + const buildClassProperty = state.opts.spec ? buildClassPropertySpec : + buildClassPropertyNonSpec; + const isDerived = !!path.node.superClass; let constructor; - let props = []; - let body = path.get("body"); + const props = []; + const body = path.get("body"); - for (let path of body.get("body")) { + for (const path of body.get("body")) { if (path.isClassProperty()) { props.push(path); } else if (path.isClassMethod({ kind: "constructor" })) { @@ -60,7 +61,7 @@ export default function ({ types: t }) { if (!props.length) return; - let nodes = []; + const nodes = []; let ref; if (path.isClassExpression() || !path.node.id) { @@ -72,15 +73,15 @@ export default function ({ types: t }) { let instanceBody = []; - for (let prop of props) { - let propNode = prop.node; + for (const prop of props) { + const propNode = prop.node; if (propNode.decorators && propNode.decorators.length > 0) continue; // In non-spec mode, all properties without values are ignored. // In spec mode, *static* properties without values are still defined (see below). if (!state.opts.spec && !propNode.value) continue; - let isStatic = propNode.static; + const isStatic = propNode.static; if (isStatic) { nodes.push(buildClassProperty(ref, propNode)); @@ -92,7 +93,8 @@ export default function ({ types: t }) { if (instanceBody.length) { if (!constructor) { - let newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([])); + const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], + t.blockStatement([])); if (isDerived) { newConstructor.params = [t.restElement(t.identifier("args"))]; newConstructor.body.body.push( @@ -107,39 +109,40 @@ export default function ({ types: t }) { [constructor] = body.unshiftContainer("body", newConstructor); } - let collisionState = { + const collisionState = { collision: false, - scope: constructor.scope + scope: constructor.scope, }; - for (let prop of props) { + for (const prop of props) { prop.traverse(referenceVisitor, collisionState); if (collisionState.collision) break; } if (collisionState.collision) { - let initialisePropsRef = path.scope.generateUidIdentifier("initialiseProps"); + const initialisePropsRef = path.scope.generateUidIdentifier("initialiseProps"); nodes.push(t.variableDeclaration("var", [ t.variableDeclarator( initialisePropsRef, t.functionExpression(null, [], t.blockStatement(instanceBody)) - ) + ), ])); instanceBody = [ t.expressionStatement( - t.callExpression(t.memberExpression(initialisePropsRef, t.identifier("call")), [t.thisExpression()]) - ) + t.callExpression(t.memberExpression(initialisePropsRef, t.identifier("call")), [ + t.thisExpression()]) + ), ]; } // if (isDerived) { - let bareSupers = []; + const bareSupers = []; constructor.traverse(findBareSupers, bareSupers); - for (let bareSuper of bareSupers) { + for (const bareSuper of bareSupers) { bareSuper.insertAfter(instanceBody); } } else { @@ -147,7 +150,7 @@ export default function ({ types: t }) { } } - for (let prop of props) { + for (const prop of props) { prop.remove(); } @@ -169,15 +172,15 @@ export default function ({ types: t }) { path.insertAfter(nodes); }, ArrowFunctionExpression(path) { - let classExp = path.get("body"); + const classExp = path.get("body"); if (!classExp.isClassExpression()) return; - let body = classExp.get("body"); - let members = body.get("body"); + const body = classExp.get("body"); + const members = body.get("body"); if (members.some((member) => member.isClassProperty())) { path.ensureBlock(); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-class-properties/test/index.js b/packages/babel-plugin-transform-class-properties/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-class-properties/test/index.js +++ b/packages/babel-plugin-transform-class-properties/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-decorators/README.md b/packages/babel-plugin-transform-decorators/README.md index 71fee789b4..a19335dfdc 100644 --- a/packages/babel-plugin-transform-decorators/README.md +++ b/packages/babel-plugin-transform-decorators/README.md @@ -54,9 +54,7 @@ npm install --save-dev babel-plugin-transform-decorators ## Usage -### Via `.babelrc` (Recommended) - -**.babelrc** +Add the following line to your .babelrc file: ```json { @@ -64,6 +62,32 @@ npm install --save-dev babel-plugin-transform-decorators } ``` +#### NOTE: Order of Plugins Matters! + +If you are including your plugins manually and using `transform-class-properties`, make sure that `transform-decorators` comes *before* `transform-class-properties`. + +Wrong: + +```json +{ + "plugins": [ + "transform-class-properties", + "transform-decorators" + ] +} +``` + +Right: + +```json +{ + "plugins": [ + "transform-decorators", + "transform-class-properties" + ] +} +``` + ### Via CLI ```sh diff --git a/packages/babel-plugin-transform-decorators/package.json b/packages/babel-plugin-transform-decorators/package.json index 05b2e6e480..0d41ef971e 100644 --- a/packages/babel-plugin-transform-decorators/package.json +++ b/packages/babel-plugin-transform-decorators/package.json @@ -1,22 +1,22 @@ { "name": "babel-plugin-transform-decorators", - "version": "6.13.0", + "version": "7.0.0-alpha.1", + "author": "Logan Smyth ", + "license": "MIT", "description": "Compile class and object decorators to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-decorators", - "license": "MIT", "main": "lib/index.js", "keywords": [ - "babel-plugin" + "babel", + "babel-plugin", + "decorators" ], "dependencies": { - "babel-types": "^6.13.0", - "babel-helper-define-map": "^6.8.0", - "babel-plugin-syntax-decorators": "^6.13.0", - "babel-helper-explode-class": "^6.8.0", - "babel-template": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-decorators": "7.0.0-alpha.1", + "babel-runtime": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-decorators/src/index.js b/packages/babel-plugin-transform-decorators/src/index.js index 1b3fbed6f8..700bc50259 100644 --- a/packages/babel-plugin-transform-decorators/src/index.js +++ b/packages/babel-plugin-transform-decorators/src/index.js @@ -1,132 +1,342 @@ -import template from "babel-template"; -import explodeClass from "babel-helper-explode-class"; +// Fork of https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy -let buildClassDecorator = template(` - CLASS_REF = DECORATOR(CLASS_REF) || CLASS_REF; +import template from "babel-template"; +import syntaxDecorators from "babel-plugin-syntax-decorators"; + +const buildClassDecorator = template(` + DECORATOR(CLASS_REF = INNER) || CLASS_REF; `); -export default function ({ types: t }) { - function cleanDecorators(decorators) { - return decorators.reverse().map((dec) => dec.expression); - } +const buildClassPrototype = template(` + CLASS_REF.prototype; +`); - function transformClass(path, ref, state) { - let nodes = []; +const buildGetDescriptor = template(` + Object.getOwnPropertyDescriptor(TARGET, PROPERTY); +`); - state; - let classDecorators = path.node.decorators; - if (classDecorators) { - path.node.decorators = null; - classDecorators = cleanDecorators(classDecorators); - - for (let decorator of classDecorators) { - nodes.push(buildClassDecorator({ - CLASS_REF: ref, - DECORATOR: decorator - })); - } - } - - let map = Object.create(null); - - for (let method of path.get("body.body")) { - let decorators = method.node.decorators; - if (!decorators) continue; - - let alias = t.toKeyAlias(method.node); - map[alias] = map[alias] || []; - map[alias].push(method.node); - - method.remove(); - } - - for (let alias in map) { - let items = map[alias]; - - items; - } - - return nodes; - } - - function hasDecorators(path) { - if (path.isClass()) { - if (path.node.decorators) return true; - - for (let method of (path.node.body.body: Array)) { - if (method.decorators) { - return true; +const buildGetObjectInitializer = template(` + (TEMP = Object.getOwnPropertyDescriptor(TARGET, PROPERTY), (TEMP = TEMP ? TEMP.value : undefined), { + enumerable: true, + configurable: true, + writable: true, + initializer: function(){ + return TEMP; } - } - } else if (path.isObjectExpression()) { - for (let prop of (path.node.properties: Array)) { - if (prop.decorators) { - return true; + }) +`); + +const buildInitializerWarningHelper = template(` + function NAME(descriptor, context){ + throw new Error( + 'Decorating class property failed. Please ensure that ' + + 'transform-class-properties is enabled.' + ); + } +`); + +const buildInitializerDefineProperty = template(` + function NAME(target, property, descriptor, context){ + if (!descriptor) return; + + Object.defineProperty(target, property, { + enumerable: descriptor.enumerable, + configurable: descriptor.configurable, + writable: descriptor.writable, + value: descriptor.initializer ? descriptor.initializer.call(context) : void 0, + }); + } +`); + +const buildApplyDecoratedDescriptor = template(` + function NAME(target, property, decorators, descriptor, context){ + var desc = {}; + Object['ke' + 'ys'](descriptor).forEach(function(key){ + desc[key] = descriptor[key]; + }); + desc.enumerable = !!desc.enumerable; + desc.configurable = !!desc.configurable; + if ('value' in desc || desc.initializer){ + desc.writable = true; } - } + + desc = decorators.slice().reverse().reduce(function(desc, decorator){ + return decorator(target, property, desc) || desc; + }, desc); + + if (context && desc.initializer !== void 0){ + desc.value = desc.initializer ? desc.initializer.call(context) : void 0; + desc.initializer = undefined; + } + + 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); + desc = null; + } + + return desc; + } +`); + +export default function({ types: t }) { + /** + * Add a helper to take an initial descriptor, apply some decorators to it, and optionally + * define the property. + */ + function ensureApplyDecoratedDescriptorHelper(path, state) { + if (!state.applyDecoratedDescriptor) { + state.applyDecoratedDescriptor = path.scope.generateUidIdentifier("applyDecoratedDescriptor"); + const helper = buildApplyDecoratedDescriptor({ + NAME: state.applyDecoratedDescriptor, + }); + path.scope.getProgramParent().path.unshiftContainer("body", helper); } - return false; + return state.applyDecoratedDescriptor; } - function doError(path) { - throw path.buildCodeFrameError( -`Decorators are not officially supported yet in 6.x pending a proposal update. -However, if you need to use them you can install the legacy decorators transform with: + /** + * Add a helper to call as a replacement for class property definition. + */ + function ensureInitializerDefineProp(path, state) { + if (!state.initializerDefineProp) { + state.initializerDefineProp = path.scope.generateUidIdentifier("initDefineProp"); + const helper = buildInitializerDefineProperty({ + NAME: state.initializerDefineProp, + }); + path.scope.getProgramParent().path.unshiftContainer("body", helper); + } -npm install babel-plugin-transform-decorators-legacy --save-dev + return state.initializerDefineProp; + } -and add the following line to your .babelrc file: + /** + * Add a helper that will throw a useful error if the transform fails to detect the class + * property assignment, so users know something failed. + */ + function ensureInitializerWarning(path, state) { + if (!state.initializerWarningHelper) { + state.initializerWarningHelper = path.scope.generateUidIdentifier("initializerWarningHelper"); + const helper = buildInitializerWarningHelper({ + NAME: state.initializerWarningHelper, + }); + path.scope.getProgramParent().path.unshiftContainer("body", helper); + } -{ - "plugins": ["transform-decorators-legacy"] -} + return state.initializerWarningHelper; + } -The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy. - `); + /** + * If the decorator expressions are non-identifiers, hoist them to before the class so we can be sure + * that they are evaluated in order. + */ + function applyEnsureOrdering(path) { + // TODO: This should probably also hoist computed properties. + const decorators = ( + path.isClass() + ? [path].concat(path.get("body.body")) + : path.get("properties") + ).reduce((acc, prop) => acc.concat(prop.node.decorators || []), []); + + const identDecorators = decorators.filter((decorator) => !t.isIdentifier(decorator.expression)); + if (identDecorators.length === 0) return; + + return t.sequenceExpression(identDecorators.map((decorator) => { + const expression = decorator.expression; + const id = decorator.expression = path.scope.generateDeclaredUidIdentifier("dec"); + return t.assignmentExpression("=", id, expression); + }).concat([path.node])); + } + + /** + * Given a class expression with class-level decorators, create a new expression + * with the proper decorated behavior. + */ + function applyClassDecorators(classPath) { + const decorators = classPath.node.decorators || []; + classPath.node.decorators = null; + + if (decorators.length === 0) return; + + const name = classPath.scope.generateDeclaredUidIdentifier("class"); + + return decorators + .map((dec) => dec.expression) + .reverse() + .reduce(function(acc, decorator) { + return buildClassDecorator({ + CLASS_REF: name, + DECORATOR: decorator, + INNER: acc, + }).expression; + }, classPath.node); + } + + /** + * Given a class expression with method-level decorators, create a new expression + * with the proper decorated behavior. + */ + function applyMethodDecorators(path, state) { + const hasMethodDecorators = path.node.body.body.some(function(node) { + return (node.decorators || []).length > 0; + }); + + if (!hasMethodDecorators) return; + + return applyTargetDecorators(path, state, path.node.body.body); + } + + /** + * Given an object expression with property decorators, create a new expression + * with the proper decorated behavior. + */ + function applyObjectDecorators(path, state) { + const hasMethodDecorators = path.node.properties.some(function(node) { + return (node.decorators || []).length > 0; + }); + + if (!hasMethodDecorators) return; + + return applyTargetDecorators(path, state, path.node.properties); + } + + /** + * A helper to pull out property decorators into a sequence expression. + */ + function applyTargetDecorators(path, state, decoratedProps) { + const name = path.scope.generateDeclaredUidIdentifier(path.isClass() ? "class" : "obj"); + + const exprs = decoratedProps.reduce(function(acc, node) { + const decorators = node.decorators || []; + node.decorators = null; + + if (decorators.length === 0) return acc; + + if (node.computed) { + throw path.buildCodeFrameError("Computed method/property decorators are not yet supported."); + } + + const property = t.isLiteral(node.key) ? node.key : t.stringLiteral(node.key.name); + + const target = (path.isClass() && !node.static) ? buildClassPrototype({ + CLASS_REF: name, + }).expression : name; + + if (t.isClassProperty(node, { static: false })) { + const descriptor = path.scope.generateDeclaredUidIdentifier("descriptor"); + + const initializer = node.value ? + t.functionExpression(null, [], t.blockStatement([t.returnStatement(node.value)])) : + t.nullLiteral(); + node.value = t.callExpression( + ensureInitializerWarning(path, state), [descriptor, t.thisExpression()] + ); + + acc = acc.concat([ + t.assignmentExpression( + "=", descriptor, t.callExpression(ensureApplyDecoratedDescriptorHelper(path, state), [ + target, + property, + t.arrayExpression(decorators.map((dec) => dec.expression)), + t.objectExpression([ + t.objectProperty(t.identifier("enumerable"), t.booleanLiteral(true)), + t.objectProperty(t.identifier("initializer"), initializer), + ]), + ]) + ), + ]); + } else { + acc = acc.concat( + t.callExpression(ensureApplyDecoratedDescriptorHelper(path, state), [ + target, + property, + t.arrayExpression(decorators.map((dec) => dec.expression)), + ( + t.isObjectProperty(node) || + t.isClassProperty(node, { static: true })) ? + buildGetObjectInitializer({ + TEMP: path.scope.generateDeclaredUidIdentifier("init"), + TARGET: target, + PROPERTY: property, + }).expression : buildGetDescriptor({ + TARGET: target, + PROPERTY: property, + } + ).expression, + target, + ]) + ); + } + + return acc; + }, []); + + return t.sequenceExpression([ + t.assignmentExpression("=", name, path.node), + t.sequenceExpression(exprs), + name, + ]); } return { - inherits: require("babel-plugin-syntax-decorators"), + inherits: syntaxDecorators, visitor: { - ClassExpression(path) { - if (!hasDecorators(path)) return; - doError(path); + ExportDefaultDeclaration(path) { + if (!path.get("declaration").isClassDeclaration()) return; - explodeClass(path); + const { node } = path; + const ref = node.declaration.id || path.scope.generateUidIdentifier("default"); + node.declaration.id = ref; - let ref = path.scope.generateDeclaredUidIdentifier("ref"); - let nodes = []; - - nodes.push(t.assignmentExpression("=", ref, path.node)); - - nodes = nodes.concat(transformClass(path, ref, this)); - - nodes.push(ref); - - path.replaceWith(t.sequenceExpression(nodes)); + // Split the class declaration and the export into two separate statements. + path.replaceWith(node.declaration); + path.insertAfter(t.exportNamedDeclaration(null, [t.exportSpecifier(ref, t.identifier("default"))])); }, - ClassDeclaration(path) { - if (!hasDecorators(path)) return; - doError(path); - explodeClass(path); + const { node } = path; - let ref = path.node.id; - let nodes = []; + const ref = node.id || path.scope.generateUidIdentifier("class"); - nodes = nodes.concat(transformClass(path, ref, this).map((expr) => t.expressionStatement(expr))); - nodes.push(t.expressionStatement(ref)); + path.replaceWith(t.variableDeclaration("let", [ + t.variableDeclarator(ref, t.toExpression(node)), + ])); + }, + ClassExpression(path, state) { + // Create a replacement for the class node if there is one. We do one pass to replace classes with + // class decorators, and a second pass to process method decorators. + const decoratedClass = ( + applyEnsureOrdering(path) || + applyClassDecorators(path, state) || + applyMethodDecorators(path, state) + ); - path.insertAfter(nodes); + if (decoratedClass) path.replaceWith(decoratedClass); + }, + ObjectExpression(path, state) { + const decoratedObject = applyEnsureOrdering(path) || applyObjectDecorators(path, state); + + if (decoratedObject) path.replaceWith(decoratedObject); }, - ObjectExpression(path) { - if (!hasDecorators(path)) return; - doError(path); - } - } + AssignmentExpression(path, state) { + if (!state.initializerWarningHelper) return; + + if (!path.get("left").isMemberExpression()) return; + if (!path.get("left.property").isIdentifier()) return; + if (!path.get("right").isCallExpression()) return; + if (!path.get("right.callee").isIdentifier({ name: state.initializerWarningHelper.name })) return; + + path.replaceWith(t.callExpression(ensureInitializerDefineProp(path, state), [ + path.get("left.object").node, + t.stringLiteral(path.get("left.property").node.name), + path.get("right.arguments")[0].node, + path.get("right.arguments")[1].node, + ])); + }, + }, }; } diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/mutate-existing-constructor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/mutate-existing-constructor/exec.js new file mode 100644 index 0000000000..22fc0fdfc6 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/mutate-existing-constructor/exec.js @@ -0,0 +1,10 @@ +function dec(cls){ + cls.staticProp = "prop"; +} + +@dec +class Parent { + parent() {}; +} + +assert.equal(Parent.staticProp, "prop"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/return-new-constructor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/return-new-constructor/exec.js new file mode 100644 index 0000000000..e0471eb47f --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-constructors/return-new-constructor/exec.js @@ -0,0 +1,13 @@ +function dec(cls){ + return class Child extends cls { + child(){} + }; +} + +@dec +class Parent { + parent(){} +} + +assert.equal(typeof Parent.prototype.parent, "function") +assert.equal(typeof Parent.prototype.child, "function") diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/order/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/order/exec.js new file mode 100644 index 0000000000..c31dd400aa --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/order/exec.js @@ -0,0 +1,28 @@ +const calls = []; + +function dec(id){ + calls.push(id); + return function() {}; +} + +@dec(1) +@dec(2) +class Example { + @dec(3) + @dec(4) + method1() {}; + + @dec(5) + @dec(6) + prop1 = 1; + + @dec(7) + @dec(8) + method2() {}; + + @dec(9) + @dec(10) + prop2 = 2; +} + +assert.deepEqual(calls, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/reverse-order/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/reverse-order/exec.js new file mode 100644 index 0000000000..0edd5a76e5 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-ordering/reverse-order/exec.js @@ -0,0 +1,29 @@ +const calls = []; + +function dec(id){ + return function(){ + calls.push(id); + }; +} + +@dec(10) +@dec(9) +class Example2 { + @dec(2) + @dec(1) + method1() {}; + + @dec(4) + @dec(3) + prop1 = 1; + + @dec(6) + @dec(5) + method2() {}; + + @dec(8) + @dec(7) + prop2 = 2; +} + +assert.deepEqual(calls, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/mutate-descriptor/exec.js new file mode 100644 index 0000000000..16b5ee6f52 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/mutate-descriptor/exec.js @@ -0,0 +1,115 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + Object.assign(descriptor, { + enumerable: name.indexOf("enum") !== -1, + configurable: name.indexOf("conf") !== -1, + writable: name.indexOf("write") !== -1, + value: function(...args) { + return "__" + value.apply(this, args) + "__"; + }, + }); +} + +class Example { + @dec + enumconfwrite(){ + return 1; + } + + @dec + enumconf(){ + return 2; + } + + @dec + enumwrite(){ + return 3; + } + + @dec + enum(){ + return 4; + } + + @dec + confwrite(){ + return 5; + } + + @dec + conf(){ + return 6; + } + + @dec + write(){ + return 7; + } + + @dec + _(){ + return 8; + } +} + +assert(Example.prototype.hasOwnProperty('decoratedProps')); +assert.deepEqual(Example.prototype.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const inst = new Example(); + +const descs = Object.getOwnPropertyDescriptors(Example.prototype); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/numeric-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/numeric-props/exec.js new file mode 100644 index 0000000000..1955a25ee8 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/numeric-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(name, 4); + assert.equal(typeof descriptor, "object"); +} + +class Example { + @dec + 4() {}; +} diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/return-descriptor/exec.js new file mode 100644 index 0000000000..7d614d16a3 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/return-descriptor/exec.js @@ -0,0 +1,117 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + value: function(...args){ + return '__' + value.apply(this, args) + '__'; + }, + }; +} + +class Example { + @dec + enumconfwrite() { + return 1; + } + + @dec + enumconf() { + return 2; + } + + @dec + enumwrite() { + return 3; + } + + @dec + enum() { + return 4; + } + + @dec + confwrite() { + return 5; + } + + @dec + conf() { + return 6; + } + + @dec + write() { + return 7; + } + + @dec + _() { + return 8; + } +} + + +assert(Example.prototype.hasOwnProperty('decoratedProps')); +assert.deepEqual(Example.prototype.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + + +const inst = new Example(); + +const descs = Object.getOwnPropertyDescriptors(Example.prototype); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/string-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/string-props/exec.js new file mode 100644 index 0000000000..46d76bd73a --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-methods/string-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(name, "str"); + assert.equal(typeof descriptor, "object"); +} + +class Example { + @dec + "str"() {}; +} diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/child-classes-properties/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/child-classes-properties/exec.js new file mode 100644 index 0000000000..7d843bdc9f --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/child-classes-properties/exec.js @@ -0,0 +1,27 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + descriptor.initializer = function(...args){ + return "__" + initializer.apply(this, args) + "__"; + }; +} + +class Base { + @dec + prop2 = 4; +} + +class Example extends Base { + @dec + prop = 3; +} + +let inst = new Example(); + +assert.equal(inst.prop, "__3__"); +assert.equal(inst.prop2, "__4__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-descriptor/exec.js new file mode 100644 index 0000000000..e0baa17081 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-descriptor/exec.js @@ -0,0 +1,99 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + Object.assign(descriptor, { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }); +} + +class Example { + @dec + enumconfwrite = 1; + + @dec + enumconf = 2; + + @dec + enumwrite = 3; + + @dec + enum = 4; + + @dec + confwrite = 5; + + @dec + conf = 6; + + @dec + write = 7; + + @dec + _ = 8; +} + +const inst = new Example(); + +assert(Example.prototype.hasOwnProperty("decoratedProps")); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-initialzer/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-initialzer/exec.js new file mode 100644 index 0000000000..e5bd2bf933 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/mutate-initialzer/exec.js @@ -0,0 +1,27 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, "prop"); + assert.equal(typeof descriptor, "object"); + + let {initializer} = descriptor; + delete descriptor.initializer; + delete descriptor.writable; + + let value; + descriptor.get = function(){ + if (initializer){ + value = '__' + initializer.call(this) + '__'; + initializer = null; + } + return value; + }; +} + +class Example { + @dec + prop = 3; +} + +let inst = new Example(); + +assert.equal(inst.prop, "__3__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/properties-without-initializer/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/properties-without-initializer/exec.js new file mode 100644 index 0000000000..3031f7b3cd --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/properties-without-initializer/exec.js @@ -0,0 +1,11 @@ +function dec(target, name, descriptor) { + +} + +class Example { + @dec prop; +} + +let inst = new Example(); +assert(inst.hasOwnProperty("prop")); +assert.equal(inst.prop, undefined); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/return-descriptor/exec.js new file mode 100644 index 0000000000..b98c219651 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-prototype-properties/return-descriptor/exec.js @@ -0,0 +1,99 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }; +} + +class Example { + @dec + enumconfwrite = 1; + + @dec + enumconf = 2; + + @dec + enumwrite = 3; + + @dec + enum = 4; + + @dec + confwrite = 5; + + @dec + conf = 6; + + @dec + write = 7; + + @dec + _ = 8; +} + +const inst = new Example(); + +assert(Example.prototype.hasOwnProperty("decoratedProps")); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/mutate-descriptor/exec.js new file mode 100644 index 0000000000..63c53284bc --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/mutate-descriptor/exec.js @@ -0,0 +1,113 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + Object.assign(descriptor, { + enumerable: name.indexOf("enum") !== -1, + configurable: name.indexOf("conf") !== -1, + writable: name.indexOf("write") !== -1, + value: function(...args) { + return "__" + value.apply(this, args) + "__"; + }, + }); +} + +class Example { + @dec + static enumconfwrite(){ + return 1; + } + + @dec + static enumconf(){ + return 2; + } + + @dec + static enumwrite(){ + return 3; + } + + @dec + static enum(){ + return 4; + } + + @dec + static confwrite(){ + return 5; + } + + @dec + static conf(){ + return 6; + } + + @dec + static write(){ + return 7; + } + + @dec + static _(){ + return 8; + } +} + +assert(Example.hasOwnProperty("decoratedProps")); +assert.deepEqual(Example.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(Example); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(Example.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(Example.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(Example.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(Example.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(Example.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(Example.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(Example.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(Example._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/numeric-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/numeric-props/exec.js new file mode 100644 index 0000000000..61c7b3fc18 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/numeric-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, 4); + assert.equal(typeof descriptor, "object"); +} + +class Example { + @dec + static 4() {} +} diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/return-descriptor/exec.js new file mode 100644 index 0000000000..fc117a5166 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/return-descriptor/exec.js @@ -0,0 +1,114 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + value: function(...args){ + return '__' + value.apply(this, args) + '__'; + }, + }; +} + +class Example { + @dec + static enumconfwrite() { + return 1; + } + + @dec + static enumconf() { + return 2; + } + + @dec + static enumwrite() { + return 3; + } + + @dec + static enum() { + return 4; + } + + @dec + static confwrite() { + return 5; + } + + @dec + static conf() { + return 6; + } + + @dec + static write() { + return 7; + } + + @dec + static _() { + return 8; + } +} + + +assert(Example.hasOwnProperty("decoratedProps")); +assert.deepEqual(Example.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(Example); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(Example.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(Example.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(Example.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(Example.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(Example.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(Example.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(Example.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(Example._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/string-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/string-props/exec.js new file mode 100644 index 0000000000..2e20b5dbce --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-methods/string-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(name, "str"); + assert.equal(typeof descriptor, "object"); +} + +class Example { + @dec + static "str"() {}; +} diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-descriptor/exec.js new file mode 100644 index 0000000000..e936af3d7d --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-descriptor/exec.js @@ -0,0 +1,99 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + Object.assign(descriptor, { + enumerable: name.indexOf("enum") !== -1, + configurable: name.indexOf("conf") !== -1, + writable: name.indexOf("write") !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }); +} + +class Example { + @dec + static enumconfwrite = 1; + + @dec + static enumconf = 2; + + @dec + static enumwrite = 3; + + @dec + static enum = 4; + + @dec + static confwrite = 5; + + @dec + static conf = 6; + + @dec + static write = 7; + + @dec + static _ = 8; +} + +const inst = new Example(); + +assert(Example.hasOwnProperty("decoratedProps")); +assert.deepEqual(Example.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(Example); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(Example.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(Example.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(Example.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(Example.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(Example.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(Example.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(Example.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(Example._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-initialzer/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-initialzer/exec.js new file mode 100644 index 0000000000..e9d60ef728 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/mutate-initialzer/exec.js @@ -0,0 +1,25 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, "prop"); + assert.equal(typeof descriptor, "object"); + + let {initializer} = descriptor; + delete descriptor.initializer; + delete descriptor.writable; + + let value; + descriptor.get = function(){ + if (initializer){ + value = '__' + initializer.call(this) + '__'; + initializer = null; + } + return value; + }; +} + +class Example { + @dec + static prop = 3; +} + +assert.equal(Example.prop, "__3__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/properties-without-initializer/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/properties-without-initializer/exec.js new file mode 100644 index 0000000000..94b5a6ce32 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/properties-without-initializer/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor) { + +} + +class Example { + @dec static prop; +} + +assert(Example.hasOwnProperty("prop")); +assert.equal(Example.prop, undefined); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/return-descriptor/exec.js new file mode 100644 index 0000000000..8aa17ef0bd --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/class-static-properties/return-descriptor/exec.js @@ -0,0 +1,99 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }; +} + +class Example { + @dec + static enumconfwrite = 1; + + @dec + static enumconf = 2; + + @dec + static enumwrite = 3; + + @dec + static enum = 4; + + @dec + static confwrite = 5; + + @dec + static conf = 6; + + @dec + static write = 7; + + @dec + static _ = 8; +} + +const inst = new Example(); + +assert(Example.hasOwnProperty("decoratedProps")); +assert.deepEqual(Example.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(Example); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(Example.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(Example.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(Example.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(Example.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(Example.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(Example.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(Example.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(Example._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/exec/options.json b/packages/babel-plugin-transform-decorators/test/fixtures/exec/options.json deleted file mode 100644 index 0c91a1a362..0000000000 --- a/packages/babel-plugin-transform-decorators/test/fixtures/exec/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["external-helpers", "transform-es2015-destructuring", "transform-es2015-block-scoping", "transform-decorators", "transform-es2015-classes", "transform-class-properties"] -} diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/mutate-descriptor/exec.js new file mode 100644 index 0000000000..f6392e0aea --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/mutate-descriptor/exec.js @@ -0,0 +1,113 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + Object.assign(descriptor, { + enumerable: name.indexOf("enum") !== -1, + configurable: name.indexOf("conf") !== -1, + writable: name.indexOf("write") !== -1, + value: function(...args) { + return "__" + value.apply(this, args) + "__"; + }, + }); +} + +const inst = { + @dec + enumconfwrite(){ + return 1; + }, + + @dec + enumconf(){ + return 2; + }, + + @dec + enumwrite(){ + return 3; + }, + + @dec + enum(){ + return 4; + }, + + @dec + confwrite(){ + return 5; + }, + + @dec + conf(){ + return 6; + }, + + @dec + write(){ + return 7; + }, + + @dec + _(){ + return 8; + }, +} + +assert(inst.hasOwnProperty('decoratedProps')); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/numeric-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/numeric-props/exec.js new file mode 100644 index 0000000000..5474eb7dec --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/numeric-props/exec.js @@ -0,0 +1,11 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, 4); + assert.equal(typeof descriptor, "object"); +} + +const inst = { + @dec + 4(){ + } +}; diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/return-descriptor/exec.js new file mode 100644 index 0000000000..a1ed774df0 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/return-descriptor/exec.js @@ -0,0 +1,113 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let value = descriptor.value; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + value: function(...args){ + return '__' + value.apply(this, args) + '__'; + }, + }; +} + +const inst = { + @dec + enumconfwrite(){ + return 1; + }, + + @dec + enumconf(){ + return 2; + }, + + @dec + enumwrite(){ + return 3; + }, + + @dec + enum(){ + return 4; + }, + + @dec + confwrite(){ + return 5; + }, + + @dec + conf(){ + return 6; + }, + + @dec + write(){ + return 7; + }, + + @dec + _(){ + return 8; + }, +} + +assert(inst.hasOwnProperty('decoratedProps')); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite(), "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf(), "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite(), "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum(), "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite(), "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf(), "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write(), "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._(), "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/string-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/string-props/exec.js new file mode 100644 index 0000000000..d20b0c8096 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-methods/string-props/exec.js @@ -0,0 +1,12 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, "str"); + assert.equal(typeof descriptor, "object"); +} + +const inst = { + @dec + "str"(){ + + } +}; diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/order/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/order/exec.js new file mode 100644 index 0000000000..129a19ef6a --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/order/exec.js @@ -0,0 +1,25 @@ +const calls = []; +function dec(id){ + calls.push(id); + return function(){}; +} + +const obj = { + @dec(1) + @dec(2) + method1(){}, + + @dec(3) + @dec(4) + prop1: 1, + + @dec(5) + @dec(6) + method2(){}, + + @dec(7) + @dec(8) + prop2: 2, +} + +assert.deepEqual(calls, [1, 2, 3, 4, 5, 6, 7, 8]); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/reverse-order/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/reverse-order/exec.js new file mode 100644 index 0000000000..fc6066b196 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-ordering/reverse-order/exec.js @@ -0,0 +1,26 @@ +const calls = []; +function dec(id){ + return function(){ + calls.push(id); + }; +} + +const obj = { + @dec(2) + @dec(1) + method1(){}, + + @dec(4) + @dec(3) + prop1: 1, + + @dec(6) + @dec(5) + method2(){}, + + @dec(8) + @dec(7) + prop2: 2, +} + +assert.deepEqual(calls, [1, 2, 3, 4, 5, 6, 7, 8]); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-descriptor/exec.js new file mode 100644 index 0000000000..4ff3fc269b --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-descriptor/exec.js @@ -0,0 +1,98 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + Object.assign(descriptor, { + enumerable: name.indexOf("enum") !== -1, + configurable: name.indexOf("conf") !== -1, + writable: name.indexOf("write") !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }); +} + +const inst = { + @dec + enumconfwrite: 1, + + @dec + enumconf: 2, + + @dec + enumwrite: 3, + + @dec + enum: 4, + + @dec + confwrite: 5, + + @dec + conf: 6, + + @dec + write: 7, + + @dec + _: 8, +}; + + +assert(inst.hasOwnProperty("decoratedProps")); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-initialzer/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-initialzer/exec.js new file mode 100644 index 0000000000..1c046d4a7d --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/mutate-initialzer/exec.js @@ -0,0 +1,25 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, "prop"); + assert.equal(typeof descriptor, "object"); + + let {initializer} = descriptor; + delete descriptor.initializer; + delete descriptor.writable; + + let value; + descriptor.get = function(){ + if (initializer){ + value = '__' + initializer.call(this) + '__'; + initializer = null; + } + return value; + }; +} + +let inst = { + @dec + prop: 3 +}; + +assert.equal(inst.prop, "__3__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/numeric-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/numeric-props/exec.js new file mode 100644 index 0000000000..fd0c328a29 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/numeric-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, 4); + assert.equal(typeof descriptor, "object"); +} + +const inst = { + @dec + 4: 1 +}; diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/return-descriptor/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/return-descriptor/exec.js new file mode 100644 index 0000000000..3b79d92dcf --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/return-descriptor/exec.js @@ -0,0 +1,97 @@ +function dec(target, name, descriptor) { + assert(target); + assert.equal(typeof name, "string"); + assert.equal(typeof descriptor, "object"); + + target.decoratedProps = (target.decoratedProps || []).concat([name]); + + let initializer = descriptor.initializer; + return { + enumerable: name.indexOf('enum') !== -1, + configurable: name.indexOf('conf') !== -1, + writable: name.indexOf('write') !== -1, + initializer: function(...args){ + return '__' + initializer.apply(this, args) + '__'; + }, + }; +} + +const inst = { + @dec + enumconfwrite: 1, + + @dec + enumconf: 2, + + @dec + enumwrite: 3, + + @dec + enum: 4, + + @dec + confwrite: 5, + + @dec + conf: 6, + + @dec + write: 7, + + @dec + _: 8, +}; + +assert(inst.hasOwnProperty("decoratedProps")); +assert.deepEqual(inst.decoratedProps, [ + "enumconfwrite", + "enumconf", + "enumwrite", + "enum", + "confwrite", + "conf", + "write", + "_", +]); + +const descs = Object.getOwnPropertyDescriptors(inst); + +assert(descs.enumconfwrite.enumerable); +assert(descs.enumconfwrite.writable); +assert(descs.enumconfwrite.configurable); +assert.equal(inst.enumconfwrite, "__1__"); + +assert(descs.enumconf.enumerable); +assert.equal(descs.enumconf.writable, false); +assert(descs.enumconf.configurable); +assert.equal(inst.enumconf, "__2__"); + +assert(descs.enumwrite.enumerable); +assert(descs.enumwrite.writable); +assert.equal(descs.enumwrite.configurable, false); +assert.equal(inst.enumwrite, "__3__"); + +assert(descs.enum.enumerable); +assert.equal(descs.enum.writable, false); +assert.equal(descs.enum.configurable, false); +assert.equal(inst.enum, "__4__"); + +assert.equal(descs.confwrite.enumerable, false); +assert(descs.confwrite.writable); +assert(descs.confwrite.configurable); +assert.equal(inst.confwrite, "__5__"); + +assert.equal(descs.conf.enumerable, false); +assert.equal(descs.conf.writable, false); +assert(descs.conf.configurable); +assert.equal(inst.conf, "__6__"); + +assert.equal(descs.write.enumerable, false); +assert(descs.write.writable); +assert.equal(descs.write.configurable, false); +assert.equal(inst.write, "__7__"); + +assert.equal(descs._.enumerable, false); +assert.equal(descs._.writable, false); +assert.equal(descs._.configurable, false); +assert.equal(inst._, "__8__"); diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/string-props/exec.js b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/string-props/exec.js new file mode 100644 index 0000000000..8dec1d5e54 --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/object-properties/string-props/exec.js @@ -0,0 +1,10 @@ +function dec(target, name, descriptor){ + assert(target); + assert.equal(name, "str"); + assert.equal(typeof descriptor, "object"); +} + +const inst = { + @dec + "str": 1 +}; diff --git a/packages/babel-plugin-transform-decorators/test/fixtures/options.json b/packages/babel-plugin-transform-decorators/test/fixtures/options.json new file mode 100644 index 0000000000..f2aac002ac --- /dev/null +++ b/packages/babel-plugin-transform-decorators/test/fixtures/options.json @@ -0,0 +1,4 @@ +{ + "presets": ["es2015"], + "plugins": ["transform-decorators", "transform-class-properties"] +} diff --git a/packages/babel-plugin-transform-decorators/test/index.js b/packages/babel-plugin-transform-decorators/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-decorators/test/index.js +++ b/packages/babel-plugin-transform-decorators/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-do-expressions/README.md b/packages/babel-plugin-transform-do-expressions/README.md index 44e252e17d..3408d8d894 100644 --- a/packages/babel-plugin-transform-do-expressions/README.md +++ b/packages/babel-plugin-transform-do-expressions/README.md @@ -22,7 +22,6 @@ let a = do { let a = x > 10 ? 'big' : 'small'; ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=%0Alet%20x%20%3D%20100%3B%0A%0Alet%20a%20%3D%20do%20%7B%0A%20%20if(x%20%3E%2010)%20%7B%0A%20%20%20%20'big'%3B%0A%20%20%7D%20else%20%7B%0A%20%20%20%20'small'%3B%0A%20%20%7D%0A%7D%3B%0A%0Aconsole.log(a)%3B) This example is not the best usage because it is too simple and using a ternary operator is a better option but you can have a much more complex condition in the `do { ... }` expression with several `if ... else` chains: @@ -47,8 +46,6 @@ let a = do { }; ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=let%20x%20%3D%20100%3B%0Alet%20y%20%3D%2020%3B%0A%0Alet%20a%20%3D%20do%20%7B%0A%20%20if(x%20%3E%2010)%20%7B%0A%20%20%20%20if(y%20%3E%2020)%20%7B%0A%20%20%20%20%20%20'big%20x%2C%20big%20y'%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20'big%20x%2C%20small%20y'%3B%0A%20%20%20%20%7D%0A%20%20%7D%20else%20%7B%0A%20%20%20%20if(y%20%3E%2010)%20%7B%0A%20%20%20%20%20%20'small%20x%2C%20big%20y'%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20'small%20x%2C%20small%20y'%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%3B%0A%0Aconsole.log(a)%3B) - ## Example ### In JSX @@ -75,14 +72,13 @@ const Component = props =>
{do { if(color === 'blue') { ; } - if(color === 'red') { ; } - if(color === 'green') { ; } + else if(color === 'red') { ; } + else if(color === 'green') { ; } }}
; ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Creact%2Cstage-0&code=const%20Component%20%3D%20props%20%3D%3E%0A%20%20%3Cdiv%20className%3D'myComponent'%3E%0A%20%20%20%20%7Bdo%20%7B%0A%20%20%20%20%20%20if(color%20%3D%3D%3D%20'blue')%20%7B%20%3CBlueComponent%2F%3E%3B%20%7D%0A%20%20%20%20%20%20if(color%20%3D%3D%3D%20'red')%20%7B%20%3CRedComponent%2F%3E%3B%20%7D%0A%20%20%20%20%20%20if(color%20%3D%3D%3D%20'green')%20%7B%20%3CGreenComponent%2F%3E%3B%20%7D%0A%20%20%20%20%7D%7D%0A%20%20%3C%2Fdiv%3E%0A%3B) ## Installation diff --git a/packages/babel-plugin-transform-do-expressions/package.json b/packages/babel-plugin-transform-do-expressions/package.json index 401176ed10..eea756892c 100644 --- a/packages/babel-plugin-transform-do-expressions/package.json +++ b/packages/babel-plugin-transform-do-expressions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-do-expressions", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile do expressions to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-do-expressions", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-do-expressions": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-do-expressions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-do-expressions/src/index.js b/packages/babel-plugin-transform-do-expressions/src/index.js index 8bfe9c0dc5..2692b98bf4 100644 --- a/packages/babel-plugin-transform-do-expressions/src/index.js +++ b/packages/babel-plugin-transform-do-expressions/src/index.js @@ -1,16 +1,18 @@ +import syntaxDoExpressions from "babel-plugin-syntax-do-expressions"; + export default function () { return { - inherits: require("babel-plugin-syntax-do-expressions"), + inherits: syntaxDoExpressions, visitor: { DoExpression(path) { - let body = path.node.body.body; + const body = path.node.body.body; if (body.length) { path.replaceWithMultiple(body); } else { path.replaceWith(path.scope.buildUndefinedNode()); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/actual.js b/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/actual.js new file mode 100644 index 0000000000..d3706c14b3 --- /dev/null +++ b/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/actual.js @@ -0,0 +1,10 @@ +let p +let a = do { + while (p = p.parentPath) { + if (a) { + 'a' + } else { + 'b' + } + } +}; diff --git a/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/expected.js b/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/expected.js new file mode 100644 index 0000000000..5c0298f045 --- /dev/null +++ b/packages/babel-plugin-transform-do-expressions/test/fixtures/do-expressions/while-if/expected.js @@ -0,0 +1,13 @@ +let p; +let a = function () { + var _ret; + + while (p = p.parentPath) { + if (a) { + _ret = 'a'; + } else { + _ret = 'b'; + } + } + return _ret; +}(); diff --git a/packages/babel-plugin-transform-do-expressions/test/index.js b/packages/babel-plugin-transform-do-expressions/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-do-expressions/test/index.js +++ b/packages/babel-plugin-transform-do-expressions/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/README.md b/packages/babel-plugin-transform-es2015-arrow-functions/README.md index 6e1b8f353e..658f413f6c 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/README.md +++ b/packages/babel-plugin-transform-es2015-arrow-functions/README.md @@ -51,8 +51,6 @@ var bob = { console.log(bob.printFriends()); ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&lineWrap=true&presets=es2015%2Ces2015-loose&experimental=false&loose=false&spec=false&code=var%20a%20%3D%20()%20%3D%3E%20%7B%7D%3B%0Avar%20a%20%3D%20(b)%20%3D%3E%20b%3B%0A%0Aconst%20double%20%3D%20%5B1%2C2%2C3%5D.map((num)%20%3D%3E%20num%20*%202)%3B%0Aconsole.log(double)%3B%20%2F%2F%20%5B2%2C4%2C6%5D%0A%0Avar%20bob%20%3D%20%7B%0A%20%20_name%3A%20%22Bob%22%2C%0A%20%20_friends%3A%20%5B%22Sally%22%2C%20%22Tom%22%5D%2C%0A%20%20printFriends()%20%7B%0A%20%20%20%20this._friends.forEach(f%20%3D%3E%0A%20%20%20%20%20%20console.log(this._name%20%2B%20%22%20knows%20%22%20%2B%20f))%3B%0A%20%20%7D%0A%7D%3B%0Aconsole.log(bob.printFriends())%3B&playground=true) - ## Installation ```sh @@ -65,13 +63,17 @@ npm install --save-dev babel-plugin-transform-es2015-arrow-functions **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-es2015-arrow-functions"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-arrow-functions", { "spec": true }] @@ -95,4 +97,8 @@ require("babel-core").transform("code", { ## Options -* `spec` - This option wraps the generated function in `.bind(this)` and keeps uses of `this` inside the function as-is, instead of using a renamed `this`. It also adds a runtime check to ensure the functions are not instantiated. +### `spec` + +`boolean`, defaults to `false`. + +This option wraps the generated function in `.bind(this)` and keeps uses of `this` inside the function as-is, instead of using a renamed `this`. It also adds a runtime check to ensure the functions are not instantiated. diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/package.json b/packages/babel-plugin-transform-es2015-arrow-functions/package.json index 766e4b851b..769a11ac31 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/package.json +++ b/packages/babel-plugin-transform-es2015-arrow-functions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-arrow-functions", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 arrow functions to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-arrow-functions", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js b/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js index 1d4c91fee7..31c1193482 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js +++ b/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js @@ -3,13 +3,13 @@ export default function ({ types: t }) { visitor: { ArrowFunctionExpression(path, state) { if (state.opts.spec) { - let { node } = path; + const { node } = path; if (node.shadow) return; node.shadow = { this: false }; node.type = "FunctionExpression"; - let boundThis = t.thisExpression(); + const boundThis = t.thisExpression(); boundThis._forceShadow = path; // make sure that arrow function won't be instantiated @@ -18,7 +18,7 @@ export default function ({ types: t }) { "body", t.expressionStatement(t.callExpression(state.addHelper("newArrowCheck"), [ t.thisExpression(), - boundThis + boundThis, ])) ); @@ -29,7 +29,7 @@ export default function ({ types: t }) { } else { path.arrowFunctionToShadowed(); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/test/index.js b/packages/babel-plugin-transform-es2015-arrow-functions/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/test/index.js +++ b/packages/babel-plugin-transform-es2015-arrow-functions/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json index db3b0a0318..9dfc7356b8 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-block-scoped-functions", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Babel plugin to ensure function declarations at the block level are block scoped", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-block-scoped-functions", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js index a1aac15dc3..dad07b0db7 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js @@ -1,13 +1,13 @@ export default function ({ types: t }) { function statementList(key, path) { - let paths: Array = path.get(key); + const paths: Array = path.get(key); - for (let path of paths) { - let func = path.node; + for (const path of paths) { + const func = path.node; if (!path.isFunctionDeclaration()) continue; - let declar = t.variableDeclaration("let", [ - t.variableDeclarator(func.id, t.toExpression(func)) + const declar = t.variableDeclaration("let", [ + t.variableDeclarator(func.id, t.toExpression(func)), ]); // hoist it up above everything else @@ -23,8 +23,8 @@ export default function ({ types: t }) { return { visitor: { BlockStatement(path) { - let { node, parent } = path; - if (t.isFunction(parent, { body: node }) || t.isExportDeclaration(parent)) { + const { node, parent } = path; + if (t.isFunction(parent, { body: node }) || t.isExportDeclaration(parent)) { return; } @@ -33,7 +33,7 @@ export default function ({ types: t }) { SwitchCase(path) { statementList("consequent", path); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/README.md b/packages/babel-plugin-transform-es2015-block-scoping/README.md index ee1d426600..2890f38d09 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/README.md +++ b/packages/babel-plugin-transform-es2015-block-scoping/README.md @@ -14,12 +14,26 @@ npm install --save-dev babel-plugin-transform-es2015-block-scoping **.babelrc** +Without options: + ```json { "plugins": ["transform-es2015-block-scoping"] } ``` +With options: + +```json +{ + "plugins": [ + ["transform-es2015-block-scoping", { + "throwIfClosureRequired": true + }] + ] +} +``` + ### Via CLI ```sh @@ -33,3 +47,15 @@ require("babel-core").transform("code", { plugins: ["transform-es2015-block-scoping"] }); ``` + +## Options `throwIfClosureRequired` + +In cases such as the following it's impossible to rewrite let/const without adding an additional function and closure while transforming: + +```javascript +for (let i = 0; i < 5; i++) { + setTimeout(() => console.log(i), 1); +} +``` + +In extremely performance-sensitive code, this can be undesirable. If `"throwIfClosureRequired": true` is set, Babel throws when transforming these patterns instead of automatically adding an additional function. diff --git a/packages/babel-plugin-transform-es2015-block-scoping/package.json b/packages/babel-plugin-transform-es2015-block-scoping/package.json index d8dd65f9a5..839997ebe0 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoping/package.json @@ -1,21 +1,20 @@ { "name": "babel-plugin-transform-es2015-block-scoping", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 block scoping (const and let) to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-block-scoping", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-traverse": "^6.21.0", - "babel-types": "^6.21.0", - "babel-template": "^6.15.0", - "lodash": "^4.2.0", - "babel-runtime": "^6.20.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "lodash": "^4.2.0" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js index 95b63d36b3..1942cb8846 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import type NodePath from "babel-traverse"; import type Scope from "babel-traverse"; import type File from "../../../file"; @@ -14,17 +12,17 @@ export default function () { return { visitor: { VariableDeclaration(path, file) { - let { node, parent, scope } = path; + const { node, parent, scope } = path; if (!isBlockScoped(node)) return; convertBlockScopedToVar(path, null, parent, scope, true); if (node._tdzThis) { - let nodes = [node]; + const nodes = [node]; for (let i = 0; i < node.declarations.length; i++) { - let decl = node.declarations[i]; + const decl = node.declarations[i]; if (decl.init) { - let assign = t.assignmentExpression("=", decl.id, decl.init); + const assign = t.assignmentExpression("=", decl.id, decl.init); assign._ignoreBlockScopingTDZ = true; nodes.push(t.expressionStatement(assign)); } @@ -44,26 +42,26 @@ export default function () { }, Loop(path, file) { - let { node, parent, scope } = path; + const { node, parent, scope } = path; t.ensureBlock(node); - let blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file); - let replace = blockScoping.run(); + const blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file); + const replace = blockScoping.run(); if (replace) path.replaceWith(replace); }, CatchClause(path, file) { - let { parent, scope } = path; - let blockScoping = new BlockScoping(null, path.get("body"), parent, scope, file); + const { parent, scope } = path; + const blockScoping = new BlockScoping(null, path.get("body"), parent, scope, file); blockScoping.run(); }, "BlockStatement|SwitchStatement|Program"(path, file) { if (!ignoreBlock(path)) { - let blockScoping = new BlockScoping(null, path, path.parent, path.scope, file); + const blockScoping = new BlockScoping(null, path, path.parent, path.scope, file); blockScoping.run(); } - } - } + }, + }, }; } @@ -71,7 +69,7 @@ function ignoreBlock(path) { return t.isLoop(path.parent) || t.isCatchClause(path.parent); } -let buildRetCheck = template(` +const buildRetCheck = template(` if (typeof RETURN === "object") return RETURN.v; `); @@ -89,7 +87,7 @@ function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent // https://github.com/babel/babel/issues/255 if (!t.isFor(parent)) { for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; + const declar = node.declarations[i]; declar.init = declar.init || scope.buildUndefinedNode(); } } @@ -101,8 +99,8 @@ function convertBlockScopedToVar(path, node, parent, scope, moveBindingsToParent if (moveBindingsToParent) { const parentScope = scope.getFunctionParent(); const ids = path.getBindingIdentifiers(); - for (let name in ids) { - let binding = scope.getOwnBinding(name); + for (const name in ids) { + const binding = scope.getOwnBinding(name); if (binding) binding.kind = "var"; scope.moveBindingTo(name, parentScope); } @@ -113,36 +111,49 @@ function isVar(node) { return t.isVariableDeclaration(node, { kind: "var" }) && !isBlockScoped(node); } -let letReferenceBlockVisitor = traverse.visitors.merge([{ +const letReferenceBlockVisitor = traverse.visitors.merge([{ + Loop: { + enter(path, state) { + state.loopDepth++; + }, + exit(path, state) { + state.loopDepth--; + }, + }, Function(path, state) { - path.traverse(letReferenceFunctionVisitor, state); + // References to block-scoped variables only require added closures if it's + // possible for the code to run more than once -- otherwise it is safe to + // simply rename the variables. + if (state.loopDepth > 0) { + path.traverse(letReferenceFunctionVisitor, state); + } return path.skip(); - } + }, }, tdzVisitor]); -let letReferenceFunctionVisitor = traverse.visitors.merge([{ +const letReferenceFunctionVisitor = traverse.visitors.merge([{ ReferencedIdentifier(path, state) { - let ref = state.letReferences[path.node.name]; + const ref = state.letReferences[path.node.name]; // not a part of our scope if (!ref) return; // this scope has a variable with the same name so it couldn't belong // to our let scope - let localBinding = path.scope.getBindingIdentifier(path.node.name); + const localBinding = path.scope.getBindingIdentifier(path.node.name); if (localBinding && localBinding !== ref) return; state.closurify = true; - } + }, }, tdzVisitor]); -let hoistVarDeclarationsVisitor = { +const hoistVarDeclarationsVisitor = { enter(path, self) { - let { node, parent } = path; + const { node, parent } = path; if (path.isForStatement()) { if (isVar(node.init, node)) { - let nodes = self.pushDeclar(node.init); + const nodes = self.pushDeclar(node.init); if (nodes.length === 1) { node.init = nodes[0]; } else { @@ -159,25 +170,25 @@ let hoistVarDeclarationsVisitor = { } else if (path.isFunction()) { return path.skip(); } - } + }, }; -let loopLabelVisitor = { +const loopLabelVisitor = { LabeledStatement({ node }, state) { state.innerLabels.push(node.label.name); - } + }, }; -let continuationVisitor = { +const continuationVisitor = { enter(path, state) { if (path.isAssignmentExpression() || path.isUpdateExpression()) { - let bindings = path.getBindingIdentifiers(); - for (let name in bindings) { + const bindings = path.getBindingIdentifiers(); + for (const name in bindings) { if (state.outsideReferences[name] !== path.scope.getBindingIdentifier(name)) continue; state.reassignments[name] = true; } } - } + }, }; function loopNodeTo(node) { @@ -188,9 +199,9 @@ function loopNodeTo(node) { } } -let loopVisitor = { +const loopVisitor = { Loop(path, state) { - let oldIgnoreLabeless = state.ignoreLabeless; + const oldIgnoreLabeless = state.ignoreLabeless; state.ignoreLabeless = true; path.traverse(loopVisitor, state); state.ignoreLabeless = oldIgnoreLabeless; @@ -202,7 +213,7 @@ let loopVisitor = { }, SwitchCase(path, state) { - let oldInSwitchCase = state.inSwitchCase; + const oldInSwitchCase = state.inSwitchCase; state.inSwitchCase = true; path.traverse(loopVisitor, state); state.inSwitchCase = oldInSwitchCase; @@ -210,7 +221,7 @@ let loopVisitor = { }, "BreakStatement|ContinueStatement|ReturnStatement"(path, state) { - let { node, parent, scope } = path; + const { node, parent, scope } = path; if (node[this.LOOP_IGNORE]) return; let replace; @@ -244,7 +255,7 @@ let loopVisitor = { if (path.isReturnStatement()) { state.hasReturn = true; replace = t.objectExpression([ - t.objectProperty(t.identifier("v"), node.argument || scope.buildUndefinedNode()) + t.objectProperty(t.identifier("v"), node.argument || scope.buildUndefinedNode()), ]); } @@ -254,28 +265,28 @@ let loopVisitor = { path.skip(); path.replaceWith(t.inherits(replace, node)); } - } + }, }; class BlockScoping { constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) { this.parent = parent; - this.scope = scope; - this.file = file; + this.scope = scope; + this.file = file; this.blockPath = blockPath; - this.block = blockPath.node; + this.block = blockPath.node; this.outsideLetReferences = Object.create(null); - this.hasLetReferences = false; - this.letReferences = Object.create(null); - this.body = []; + this.hasLetReferences = false; + this.letReferences = Object.create(null); + this.body = []; if (loopPath) { this.loopParent = loopPath.parent; - this.loopLabel = t.isLabeledStatement(this.loopParent) && this.loopParent.label; - this.loopPath = loopPath; - this.loop = loopPath.node; + this.loopLabel = t.isLabeledStatement(this.loopParent) && this.loopParent.label; + this.loopPath = loopPath; + this.loop = loopPath.node; } } @@ -284,11 +295,11 @@ class BlockScoping { */ run() { - let block = this.block; + const block = this.block; if (block._letDone) return; block._letDone = true; - let needsClosure = this.getLetReferences(); + const needsClosure = this.getLetReferences(); // this is a block within a `Function/Program` so we can safely leave it be if (t.isFunction(this.parent) || t.isProgram(this.block)) { @@ -313,12 +324,12 @@ class BlockScoping { } updateScopeInfo(wrappedInClosure) { - let scope = this.scope; - let parentScope = scope.getFunctionParent(); - let letRefs = this.letReferences; + const scope = this.scope; + const parentScope = scope.getFunctionParent(); + const letRefs = this.letReferences; - for (let key in letRefs) { - let ref = letRefs[key]; + for (const key in letRefs) { + const ref = letRefs[key]; const binding = scope.getBinding(ref.name); if (!binding) continue; if (binding.kind === "let" || binding.kind === "const") { @@ -334,18 +345,18 @@ class BlockScoping { } remap() { - let letRefs = this.letReferences; - let scope = this.scope; + const letRefs = this.letReferences; + const scope = this.scope; // alright, so since we aren't wrapping this block in a closure // we have to check if any of our let variables collide with // those in upper scopes and then if they do, generate a uid // for them and replace all references with it - for (let key in letRefs) { + for (const key in letRefs) { // just an Identifier node we collected in `getLetReferences` // this is the defining identifier of a declaration - let ref = letRefs[key]; + const ref = letRefs[key]; // todo: could skip this if the colliding binding is in another function if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { @@ -353,23 +364,29 @@ class BlockScoping { // the enclosing scope (e.g. loop or catch statement), so we should handle both // individually if (scope.hasOwnBinding(key)) - scope.rename(ref.name); + {scope.rename(ref.name);} if (this.blockPath.scope.hasOwnBinding(key)) - this.blockPath.scope.rename(ref.name); + {this.blockPath.scope.rename(ref.name);} } } } wrapClosure() { - let block = this.block; + if (this.file.opts.throwIfClosureRequired) { + throw this.blockPath.buildCodeFrameError( + "Compiling let/const in this block would add a closure " + + "(throwIfClosureRequired)." + ); + } + const block = this.block; - let outsideRefs = this.outsideLetReferences; + const outsideRefs = this.outsideLetReferences; // remap loop heads with colliding variables if (this.loop) { - for (let name in outsideRefs) { - let id = outsideRefs[name]; + for (const name in outsideRefs) { + const id = outsideRefs[name]; if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { delete outsideRefs[id.name]; @@ -391,13 +408,14 @@ class BlockScoping { this.hoistVarDeclarations(); // turn outsideLetReferences into an array - let params = values(outsideRefs); - let args = values(outsideRefs); + const params = values(outsideRefs); + const args = values(outsideRefs); const isSwitch = this.blockPath.isSwitchStatement(); // build the closure that we're going to wrap the block with, possible wrapping switch(){} - let fn = t.functionExpression(null, params, t.blockStatement(isSwitch ? [block] : block.body)); + const fn = t.functionExpression(null, params, + t.blockStatement(isSwitch ? [block] : block.body)); fn.shadow = true; // continuation @@ -408,23 +426,23 @@ class BlockScoping { if (this.loop) { ref = this.scope.generateUidIdentifier("loop"); this.loopPath.insertBefore(t.variableDeclaration("var", [ - t.variableDeclarator(ref, fn) + t.variableDeclarator(ref, fn), ])); } // build a call and a unique id that we can assign the return value to let call = t.callExpression(ref, args); - let ret = this.scope.generateUidIdentifier("ret"); + const ret = this.scope.generateUidIdentifier("ret"); // handle generators - let hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES); + const hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES); if (hasYield) { fn.generator = true; call = t.yieldExpression(call, true); } // handlers async functions - let hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES); + const hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES); if (hasAsync) { fn.async = true; call = t.awaitExpression(call); @@ -442,7 +460,7 @@ class BlockScoping { */ buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { - let has = this.has; + const has = this.has; if (has.hasReturn || has.hasBreakContinue) { this.buildHas(ret, call); } else { @@ -459,18 +477,18 @@ class BlockScoping { */ addContinuations(fn) { - let state = { + const state = { reassignments: {}, - outsideReferences: this.outsideLetReferences + outsideReferences: this.outsideLetReferences, }; this.scope.traverse(fn, continuationVisitor, state); for (let i = 0; i < fn.params.length; i++) { - let param = fn.params[i]; + const param = fn.params[i]; if (!state.reassignments[param.name]) continue; - let newParam = this.scope.generateUidIdentifier(param.name); + const newParam = this.scope.generateUidIdentifier(param.name); fn.params[i] = newParam; this.scope.rename(param.name, newParam.name, fn); @@ -481,12 +499,12 @@ class BlockScoping { } getLetReferences() { - let block = this.block; + const block = this.block; let declarators = []; if (this.loop) { - let init = this.loop.left || this.loop.init; + const init = this.loop.left || this.loop.init; if (isBlockScoped(init)) { declarators.push(init); extend(this.outsideLetReferences, t.getBindingIdentifiers(init)); @@ -509,18 +527,18 @@ class BlockScoping { // if (block.body) { for (let i = 0; i < block.body.length; i++) { - let declarPath = this.blockPath.get("body")[i]; + const declarPath = this.blockPath.get("body")[i]; addDeclarationsFromChild(declarPath); } } if (block.cases) { for (let i = 0; i < block.cases.length; i++) { - let consequents = block.cases[i].consequent; + const consequents = block.cases[i].consequent; for (let j = 0; j < consequents.length; j++) { - let declarPath = this.blockPath.get("cases")[i]; - let declar = consequents[j]; + const declarPath = this.blockPath.get("cases")[i]; + const declar = consequents[j]; addDeclarationsFromChild(declarPath, declar); } } @@ -528,12 +546,12 @@ class BlockScoping { // for (let i = 0; i < declarators.length; i++) { - let declar = declarators[i]; + const declar = declarators[i]; // Passing true as the third argument causes t.getBindingIdentifiers // to return only the *outer* binding identifiers of this // declaration, rather than (for example) mistakenly including the // parameters of a function declaration. Fixes #4880. - let keys = t.getBindingIdentifiers(declar, false, true); + const keys = t.getBindingIdentifiers(declar, false, true); extend(this.letReferences, keys); this.hasLetReferences = true; } @@ -541,12 +559,22 @@ class BlockScoping { // no let references so we can just quit if (!this.hasLetReferences) return; - let state = { + const state = { letReferences: this.letReferences, - closurify: false, - file: this.file + closurify: false, + file: this.file, + loopDepth: 0, }; + const loopOrFunctionParent = this.blockPath.find( + (path) => path.isLoop() || path.isFunction() + ); + if (loopOrFunctionParent && loopOrFunctionParent.isLoop()) { + // There is a loop ancestor closer than the closest function, so we + // consider ourselves to be in a loop. + state.loopDepth++; + } + // traverse through this block, stopping on functions and checking if they // contain any local let references this.blockPath.traverse(letReferenceBlockVisitor, state); @@ -562,15 +590,15 @@ class BlockScoping { */ checkLoop(): Object { - let state = { + const state = { hasBreakContinue: false, - ignoreLabeless: false, - inSwitchCase: false, - innerLabels: [], - hasReturn: false, - isLoop: !!this.loop, - map: {}, - LOOP_IGNORE: Symbol() + ignoreLabeless: false, + inSwitchCase: false, + innerLabels: [], + hasReturn: false, + isLoop: !!this.loop, + map: {}, + LOOP_IGNORE: Symbol(), }; this.blockPath.traverse(loopLabelVisitor, state); @@ -594,21 +622,21 @@ class BlockScoping { */ pushDeclar(node: { type: "VariableDeclaration" }): Array { - let declars = []; - let names = t.getBindingIdentifiers(node); - for (let name in names) { + const declars = []; + const names = t.getBindingIdentifiers(node); + for (const name in names) { declars.push(t.variableDeclarator(names[name])); } this.body.push(t.variableDeclaration(node.kind, declars)); - let replace = []; + const replace = []; for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; + const declar = node.declarations[i]; if (!declar.init) continue; - let expr = t.assignmentExpression("=", declar.id, declar.init); + const expr = t.assignmentExpression("=", declar.id, declar.init); replace.push(t.inherits(expr, declar)); } @@ -616,25 +644,25 @@ class BlockScoping { } buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { - let body = this.body; + const body = this.body; body.push(t.variableDeclaration("var", [ - t.variableDeclarator(ret, call) + t.variableDeclarator(ret, call), ])); let retCheck; - let has = this.has; - let cases = []; + const has = this.has; + const cases = []; if (has.hasReturn) { // typeof ret === "object" retCheck = buildRetCheck({ - RETURN: ret + RETURN: ret, }); } if (has.hasBreakContinue) { - for (let key in has.map) { + for (const key in has.map) { cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]])); } @@ -643,7 +671,7 @@ class BlockScoping { } if (cases.length === 1) { - let single = cases[0]; + const single = cases[0]; body.push(t.ifStatement( t.binaryExpression("===", ret, single.test), single.consequent[0] @@ -652,9 +680,10 @@ class BlockScoping { if (this.loop) { // https://github.com/babel/babel/issues/998 for (let i = 0; i < cases.length; i++) { - let caseConsequent = cases[i].consequent[0]; + const caseConsequent = cases[i].consequent[0]; if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) { - caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop"); + caseConsequent.label = this.loopLabel = this.loopLabel || + this.scope.generateUidIdentifier("loop"); } } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js b/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js index 10d68c174d..5b8d55796a 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js @@ -1,7 +1,7 @@ import * as t from "babel-types"; function getTDZStatus(refPath, bindingPath) { - let executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath); + const executionStatus = bindingPath._guessExecutionStatusRelativeTo(refPath); if (executionStatus === "before") { return "inside"; @@ -20,29 +20,29 @@ function buildTDZAssert(node, file) { } function isReference(node, scope, state) { - let declared = state.letReferences[node.name]; + const declared = state.letReferences[node.name]; if (!declared) return false; // declared node is different in this scope return scope.getBindingIdentifier(node.name) === declared; } -export let visitor = { +export const visitor = { ReferencedIdentifier(path, state) { if (!this.file.opts.tdz) return; - let { node, parent, scope } = path; + const { node, parent, scope } = path; if (path.parentPath.isFor({ left: node })) return; if (!isReference(node, scope, state)) return; - let bindingPath = scope.getBinding(node.name).path; + const bindingPath = scope.getBinding(node.name).path; - let status = getTDZStatus(path, bindingPath); + const status = getTDZStatus(path, bindingPath); if (status === "inside") return; if (status === "maybe") { - let assert = buildTDZAssert(node, state.file); + const assert = buildTDZAssert(node, state.file); // add tdzThis to parent variable declarator so it's exploded bindingPath.parent._tdzThis = true; @@ -58,7 +58,7 @@ export let visitor = { } else if (status === "outside") { path.replaceWith(t.throwStatement(t.inherits( t.newExpression(t.identifier("ReferenceError"), [ - t.stringLiteral(`${node.name} is not defined - temporal dead zone`) + t.stringLiteral(`${node.name} is not defined - temporal dead zone`), ]), node ))); @@ -69,14 +69,14 @@ export let visitor = { exit(path, state) { if (!this.file.opts.tdz) return; - let { node } = path; + const { node } = path; if (node._ignoreBlockScopingTDZ) return; - let nodes = []; - let ids = path.getBindingIdentifiers(); + const nodes = []; + const ids = path.getBindingIdentifiers(); - for (let name in ids) { - let id = ids[name]; + for (const name in ids) { + const id = ids[name]; if (isReference(id, path.scope, state)) { nodes.push(buildTDZAssert(id, state.file)); @@ -88,6 +88,6 @@ export let visitor = { nodes.push(node); path.replaceWithMultiple(nodes.map(t.expressionStatement)); } - } - } + }, + }, }; diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-2174/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-2174/expected.js index 1dce9c4c17..9efbc1091f 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-2174/expected.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-2174/expected.js @@ -1,11 +1,9 @@ if (true) { - var x; + var foo = function () {}; - (function () { - function foo() {} - function bar() { - return foo; - } - for (x in {}) {} - })(); + var bar = function () { + return foo; + }; + + for (var x in {}) {} } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/actual.js new file mode 100644 index 0000000000..f030ac811d --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/actual.js @@ -0,0 +1,34 @@ +function foo() { + const x = 5; + console.log(x); + + { + const x = 7; + setTimeout(() => x, 0); + } +} + +function bar() { + const x = 5; + console.log(x); + + for (let i = 0; i < 7; i++) { + { + const x = i; + setTimeout(() => x, 0); + } + } +} + +function baz() { + const x = 5; + console.log(x); + + for (let i = 0; i < 7; i++) { + var qux = function qux(y) { + const x = y; + setTimeout(() => x, 0); + }; + qux(i); + } +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/expected.js new file mode 100644 index 0000000000..a86a2e4811 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/loops-and-no-loops/expected.js @@ -0,0 +1,42 @@ +function foo() { + var x = 5; + console.log(x); + + { + var _x = 7; + setTimeout(function () { + return _x; + }, 0); + } +} + +function bar() { + var x = 5; + console.log(x); + + for (var i = 0; i < 7; i++) { + { + (function () { + var x = i; + setTimeout(function () { + return x; + }, 0); + })(); + } + } +} + +function baz() { + var x = 5; + console.log(x); + + for (var i = 0; i < 7; i++) { + var qux = function qux(y) { + var x = y; + setTimeout(function () { + return x; + }, 0); + }; + qux(i); + } +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/actual.js new file mode 100644 index 0000000000..e3020dada7 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/actual.js @@ -0,0 +1,11 @@ +var f1, f2; +{ + let z = 'z1 value'; + f1 = function() { return z; }; +} +{ + let z = 'z2 value'; + f2 = function() { return z; }; +} +f1(); +f2(); diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/expected.js new file mode 100644 index 0000000000..8bbdfc7ddf --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/sibling-scopes/expected.js @@ -0,0 +1,15 @@ +var f1, f2; +{ + var z = 'z1 value'; + f1 = function () { + return z; + }; +} +{ + var _z = 'z2 value'; + f2 = function () { + return _z; + }; +} +f1(); +f2(); \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js index 857b8641f4..5dedf9a592 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js @@ -1,16 +1,18 @@ function foo() { - switch (2) { - case 0: { - if (true) { - return; - } + while (true) { + switch (2) { + case 0: { + if (true) { + return; + } - const stuff = new Map(); - const data = 0; - stuff.forEach(() => { - const d = data; - }); - break; + const stuff = new Map(); + const data = 0; + stuff.forEach(() => { + const d = data; + }); + break; + } } } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/expected.js index 05d7afe3d9..80b21eba9c 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/expected.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/expected.js @@ -1,29 +1,31 @@ function foo() { - switch (2) { - case 0: - { - var _ret = function () { - if (true) { - return { - v: void 0 - }; + while (true) { + switch (2) { + case 0: + { + var _ret = function () { + if (true) { + return { + v: void 0 + }; + } + + var stuff = new Map(); + var data = 0; + stuff.forEach(function () { + var d = data; + }); + return "break"; + }(); + + switch (_ret) { + case "break": + break; + + default: + if (typeof _ret === "object") return _ret.v; } - - var stuff = new Map(); - var data = 0; - stuff.forEach(function () { - var d = data; - }); - return "break"; - }(); - - switch (_ret) { - case "break": - break; - - default: - if (typeof _ret === "object") return _ret.v; } - } + } } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/actual.js index c57bdc6e51..99f8726f05 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/actual.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/actual.js @@ -1,10 +1,12 @@ function fn() { - switch (true) { - default: - let foo = 4; - if (true) { - let bar = () => foo; - console.log(bar()); + while (true) { + switch (true) { + default: + let foo = 4; + if (true) { + let bar = () => foo; + console.log(bar()); + } } } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/expected.js index 2efd145af3..40f23daea6 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/expected.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-callbacks/expected.js @@ -1,14 +1,16 @@ function fn() { - (function () { - switch (true) { - default: - var foo = 4; - if (true) { - var bar = function () { - return foo; - }; - console.log(bar()); - } - } - })(); + while (true) { + (function () { + switch (true) { + default: + var foo = 4; + if (true) { + var bar = function () { + return foo; + }; + console.log(bar()); + } + } + })(); + } } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/actual.js new file mode 100644 index 0000000000..55dbb21d37 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/actual.js @@ -0,0 +1,6 @@ +for (let i = 0; i < 5; i++) { + const l = i; + setTimeout(function() { + console.log(l); + }, 1); +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/expected.js new file mode 100644 index 0000000000..c28cb3bf74 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/expected.js @@ -0,0 +1,6 @@ +for (var i = 0; i < 5; i++) { + var l = i; + setTimeout(function () { + console.log(l); + }, 1); +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/options.json b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/options.json new file mode 100644 index 0000000000..d210fdebfc --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Compiling let/const in this block would add a closure (throwIfClosureRequired)." +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/actual.js new file mode 100644 index 0000000000..2b9635ec33 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/actual.js @@ -0,0 +1,3 @@ +function test() { + let foo = "bar"; +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/expected.js new file mode 100644 index 0000000000..bb4b09c9c5 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/expected.js @@ -0,0 +1,3 @@ +function test() { + var foo = "bar"; +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/options.json b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/options.json new file mode 100644 index 0000000000..3228559d0b --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["transform-es2015-block-scoping", { "throwIfClosureRequired": true }], "syntax-jsx", "transform-react-jsx", "transform-es2015-block-scoped-functions", "transform-es2015-arrow-functions"] +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/index.js b/packages/babel-plugin-transform-es2015-block-scoping/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-classes/README.md b/packages/babel-plugin-transform-es2015-classes/README.md index aa68fde1ca..c189adf3f5 100644 --- a/packages/babel-plugin-transform-es2015-classes/README.md +++ b/packages/babel-plugin-transform-es2015-classes/README.md @@ -50,7 +50,11 @@ require("babel-core").transform("code", { }); ``` -## Options `loose` +## Options + +### `loose` + +`boolean`, defaults to `false`. #### Method enumerability @@ -79,25 +83,3 @@ class Bar extends Foo { When `Bar.prototype.foo` is defined it triggers the setter on `Foo`. This is a case that is very unlikely to appear in production code however it's something to keep in mind. - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```js -// without options -{ - "plugins": ["transform-es2015-classes"] -} - -// with options -{ - "plugins": [ - ["transform-es2015-classes", { - "loose": true - }] - ] -} -``` diff --git a/packages/babel-plugin-transform-es2015-classes/package.json b/packages/babel-plugin-transform-es2015-classes/package.json index 43e0d24ef8..37e45942a7 100644 --- a/packages/babel-plugin-transform-es2015-classes/package.json +++ b/packages/babel-plugin-transform-es2015-classes/package.json @@ -1,25 +1,24 @@ { "name": "babel-plugin-transform-es2015-classes", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 classes to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-classes", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-helper-optimise-call-expression": "^6.18.0", - "babel-helper-function-name": "^6.18.0", - "babel-helper-replace-supers": "^6.18.0", - "babel-template": "^6.14.0", - "babel-traverse": "^6.18.0", - "babel-helper-define-map": "^6.18.0", - "babel-messages": "^6.8.0", - "babel-runtime": "^6.9.0", - "babel-types": "^6.18.0" + "babel-helper-optimise-call-expression": "7.0.0-alpha.1", + "babel-helper-function-name": "7.0.0-alpha.1", + "babel-helper-replace-supers": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "babel-traverse": "7.0.0-alpha.1", + "babel-helper-define-map": "7.0.0-alpha.1", + "babel-messages": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-classes/src/index.js b/packages/babel-plugin-transform-es2015-classes/src/index.js index 9b4d371e5c..52e06fa3af 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/index.js +++ b/packages/babel-plugin-transform-es2015-classes/src/index.js @@ -4,15 +4,15 @@ import nameFunction from "babel-helper-function-name"; export default function ({ types: t }) { // todo: investigate traversal requeueing - let VISITED = Symbol(); + const VISITED = Symbol(); return { visitor: { ExportDefaultDeclaration(path) { if (!path.get("declaration").isClassDeclaration()) return; - let { node } = path; - let ref = node.declaration.id || path.scope.generateUidIdentifier("class"); + const { node } = path; + const ref = node.declaration.id || path.scope.generateUidIdentifier("class"); node.declaration.id = ref; // Split the class declaration and the export into two separate statements. @@ -21,20 +21,20 @@ export default function ({ types: t }) { }, ClassDeclaration(path) { - let { node } = path; + const { node } = path; - let ref = node.id || path.scope.generateUidIdentifier("class"); + const ref = node.id || path.scope.generateUidIdentifier("class"); path.replaceWith(t.variableDeclaration("let", [ - t.variableDeclarator(ref, t.toExpression(node)) + t.variableDeclarator(ref, t.toExpression(node)), ])); }, ClassExpression(path, state) { - let { node } = path; + const { node } = path; if (node[VISITED]) return; - let inferred = nameFunction(path); + const inferred = nameFunction(path); if (inferred && inferred !== node) return path.replaceWith(inferred); node[VISITED] = true; @@ -43,7 +43,7 @@ export default function ({ types: t }) { if (state.opts.loose) Constructor = LooseTransformer; path.replaceWith(new Constructor(path, state.file).run()); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js b/packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js index 2948528182..6583d081dc 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js +++ b/packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js @@ -2,14 +2,14 @@ import type { Scope } from "babel-traverse"; import * as t from "babel-types"; export default function (decorators: Array, scope: Scope): Array { - for (let decorator of decorators) { - let expression = decorator.expression; + for (const decorator of decorators) { + const expression = decorator.expression; if (!t.isMemberExpression(expression)) continue; - let temp = scope.maybeGenerateMemoised(expression.object); + const temp = scope.maybeGenerateMemoised(expression.object); let ref; - let nodes = []; + const nodes = []; if (temp) { ref = temp; diff --git a/packages/babel-plugin-transform-es2015-classes/src/loose.js b/packages/babel-plugin-transform-es2015-classes/src/loose.js index 5c9122bacc..57f7abbbec 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/loose.js +++ b/packages/babel-plugin-transform-es2015-classes/src/loose.js @@ -14,20 +14,20 @@ export default class LooseClassTransformer extends VanillaTransformer { let classRef = this.classRef; if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype")); - let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key)); + const methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key)); let func = t.functionExpression(null, node.params, node.body, node.generator, node.async); func.returnType = node.returnType; - let key = t.toComputedKey(node, node.key); + const key = t.toComputedKey(node, node.key); if (t.isStringLiteral(key)) { func = nameFunction({ node: func, id: key, - scope + scope, }); } - let expr = t.expressionStatement(t.assignmentExpression("=", methodName, func)); + const expr = t.expressionStatement(t.assignmentExpression("=", methodName, func)); t.inheritsComments(expr, node); this.body.push(expr); return true; diff --git a/packages/babel-plugin-transform-es2015-classes/src/vanilla.js b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js index 34109568af..cdf20beb75 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/vanilla.js +++ b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import type { NodePath } from "babel-traverse"; import { visitors } from "babel-traverse"; import ReplaceSupers from "babel-helper-replace-supers"; @@ -8,13 +6,13 @@ import * as defineMap from "babel-helper-define-map"; import template from "babel-template"; import * as t from "babel-types"; -let buildDerivedConstructor = template(` +const buildDerivedConstructor = template(` (function () { super(...arguments); }) `); -let noMethodVisitor = { +const noMethodVisitor = { "FunctionExpression|FunctionDeclaration"(path) { if (!path.is("shadow")) { path.skip(); @@ -23,12 +21,15 @@ let noMethodVisitor = { Method(path) { path.skip(); - } + }, }; -let verifyConstructorVisitor = visitors.merge([noMethodVisitor, { +const verifyConstructorVisitor = visitors.merge([noMethodVisitor, { Super(path) { - if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) { + if ( + this.isDerived && !this.hasBareSuper && + !path.parentPath.isCallExpression({ callee: path.node }) + ) { throw path.buildCodeFrameError("'super.*' is not allowed before super()"); } }, @@ -42,7 +43,7 @@ let verifyConstructorVisitor = visitors.merge([noMethodVisitor, { throw path.buildCodeFrameError("super() is only allowed in a derived constructor"); } } - } + }, }, ThisExpression(path) { @@ -51,36 +52,36 @@ let verifyConstructorVisitor = visitors.merge([noMethodVisitor, { throw path.buildCodeFrameError("'this' is not allowed before super()"); } } - } + }, }]); -let findThisesVisitor = visitors.merge([noMethodVisitor, { +const findThisesVisitor = visitors.merge([noMethodVisitor, { ThisExpression(path) { this.superThises.push(path); - } + }, }]); export default class ClassTransformer { constructor(path: NodePath, file) { this.parent = path.parent; - this.scope = path.scope; - this.node = path.node; - this.path = path; - this.file = file; + this.scope = path.scope; + this.node = path.node; + this.path = path; + this.file = file; this.clearDescriptors(); this.instancePropBody = []; this.instancePropRefs = {}; - this.staticPropBody = []; - this.body = []; + this.staticPropBody = []; + this.body = []; - this.bareSuperAfter = []; - this.bareSupers = []; + this.bareSuperAfter = []; + this.bareSupers = []; this.pushedConstructor = false; - this.pushedInherits = false; - this.isLoose = false; + this.pushedInherits = false; + this.isLoose = false; this.superThises = []; @@ -88,7 +89,8 @@ export default class ClassTransformer { this.classId = this.node.id; // this is the name of the binding that will **always** reference the class we've constructed - this.classRef = this.node.id ? t.identifier(this.node.id.name) : this.scope.generateUidIdentifier("class"); + this.classRef = this.node.id ? t.identifier(this.node.id.name) : + this.scope.generateUidIdentifier("class"); this.superName = this.node.superClass || t.identifier("Function"); this.isDerived = !!this.node.superClass; @@ -96,18 +98,18 @@ export default class ClassTransformer { run() { let superName = this.superName; - let file = this.file; - let body = this.body; + const file = this.file; + let body = this.body; // - let constructorBody = this.constructorBody = t.blockStatement([]); - this.constructor = this.buildConstructor(); + const constructorBody = this.constructorBody = t.blockStatement([]); + this.constructor = this.buildConstructor(); // - let closureParams = []; - let closureArgs = []; + const closureParams = []; + const closureArgs = []; // if (this.isDerived) { @@ -123,10 +125,12 @@ export default class ClassTransformer { this.buildBody(); // make sure this class isn't directly called - constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("classCallCheck"), [ - t.thisExpression(), - this.classRef - ]))); + constructorBody.body.unshift(t.expressionStatement(t.callExpression( + file.addHelper("classCallCheck"), [ + t.thisExpression(), + this.classRef, + ] + ))); body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef))); @@ -138,13 +142,13 @@ export default class ClassTransformer { // body.push(t.returnStatement(this.classRef)); - let container = t.functionExpression(null, closureParams, t.blockStatement(body)); + const container = t.functionExpression(null, closureParams, t.blockStatement(body)); container.shadow = true; return t.callExpression(container, closureArgs); } buildConstructor() { - let func = t.functionDeclaration(this.classRef, [], this.constructorBody); + const func = t.functionDeclaration(this.classRef, [], this.constructorBody); t.inherits(func, this.node); return func; } @@ -159,7 +163,7 @@ export default class ClassTransformer { mutatorMap = this.instanceMutatorMap; } - let map = defineMap.push(mutatorMap, node, kind, this.file, scope); + const map = defineMap.push(mutatorMap, node, kind, this.file, scope); if (enumerable) { map.enumerable = t.booleanLiteral(true); @@ -175,8 +179,8 @@ export default class ClassTransformer { constructorMeMaybe() { let hasConstructor = false; - let paths = this.path.get("body.body"); - for (let path of (paths: Array)) { + const paths = this.path.get("body.body"); + for (const path of (paths: Array)) { hasConstructor = path.equals("kind", "constructor"); if (hasConstructor) break; } @@ -185,7 +189,7 @@ export default class ClassTransformer { let params, body; if (this.isDerived) { - let constructor = buildDerivedConstructor().expression; + const constructor = buildDerivedConstructor().expression; params = constructor.params; body = constructor.body; } else { @@ -207,7 +211,7 @@ export default class ClassTransformer { this.verifyConstructor(); if (this.userConstructor) { - let constructorBody = this.constructorBody; + const constructorBody = this.constructorBody; constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body); t.inherits(this.constructor, this.userConstructor); t.inherits(constructorBody, this.userConstructor.body); @@ -217,21 +221,22 @@ export default class ClassTransformer { } pushBody() { - let classBodyPaths: Array = this.path.get("body.body"); + const classBodyPaths: Array = this.path.get("body.body"); - for (let path of classBodyPaths) { - let node = path.node; + for (const path of classBodyPaths) { + const node = path.node; if (path.isClassProperty()) { throw path.buildCodeFrameError("Missing class properties transform."); } if (node.decorators) { - throw path.buildCodeFrameError("Method has decorators, put the decorator plugin before the classes one."); + throw path.buildCodeFrameError( + "Method has decorators, put the decorator plugin before the classes one."); } if (t.isClassMethod(node)) { - let isConstructor = node.kind === "constructor"; + const isConstructor = node.kind === "constructor"; if (isConstructor) { path.traverse(verifyConstructorVisitor, this); @@ -241,16 +246,16 @@ export default class ClassTransformer { } } - let replaceSupers = new ReplaceSupers({ + const replaceSupers = new ReplaceSupers({ forceSuperMemoisation: isConstructor, - methodPath: path, - methodNode: node, - objectRef: this.classRef, - superRef: this.superName, - isStatic: node.static, - isLoose: this.isLoose, - scope: this.scope, - file: this.file + methodPath: path, + methodNode: node, + objectRef: this.classRef, + superRef: this.superName, + isStatic: node.static, + isLoose: this.isLoose, + scope: this.scope, + file: this.file, }, true); replaceSupers.replace(); @@ -266,16 +271,16 @@ export default class ClassTransformer { clearDescriptors() { this.hasInstanceDescriptors = false; - this.hasStaticDescriptors = false; + this.hasStaticDescriptors = false; this.instanceMutatorMap = {}; - this.staticMutatorMap = {}; + this.staticMutatorMap = {}; } pushDescriptors() { this.pushInherits(); - let body = this.body; + const body = this.body; let instanceProps; let staticProps; @@ -292,10 +297,15 @@ export default class ClassTransformer { if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps); if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps); - let nullNode = t.nullLiteral(); + const nullNode = t.nullLiteral(); - // (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers) - let args = [this.classRef, nullNode, nullNode, nullNode, nullNode]; + let args = [ + this.classRef, // Constructor + nullNode, // instanceDescriptors + nullNode, // staticDescriptors + nullNode, // instanceInitializers + nullNode, // staticInitializers + ]; if (instanceProps) args[1] = instanceProps; if (staticProps) args[2] = staticProps; @@ -327,7 +337,7 @@ export default class ClassTransformer { buildObjectAssignment(id) { return t.variableDeclaration("var", [ - t.variableDeclarator(id, t.objectExpression([])) + t.variableDeclarator(id, t.objectExpression([])), ]); } @@ -336,7 +346,11 @@ export default class ClassTransformer { if (this.isLoose) { bareSuperNode.arguments.unshift(t.thisExpression()); - if (bareSuperNode.arguments.length === 2 && t.isSpreadElement(bareSuperNode.arguments[1]) && t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" })) { + if ( + bareSuperNode.arguments.length === 2 && + t.isSpreadElement(bareSuperNode.arguments[1]) && + t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" }) + ) { // special case single arguments spread bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument; bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply")); @@ -363,9 +377,13 @@ export default class ClassTransformer { [t.thisExpression(), bareSuperNode] ); - let bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef)); + const bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef)); - if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) { + if ( + bareSuper.parentPath.isExpressionStatement() && + bareSuper.parentPath.container === body.node.body && + body.node.body.length - 1 === bareSuper.parentPath.key + ) { // this super call is the last statement in the body so we can just straight up // turn it into a return @@ -382,10 +400,10 @@ export default class ClassTransformer { } else { bareSuper.replaceWithMultiple([ t.variableDeclaration("var", [ - t.variableDeclarator(thisRef, call) + t.variableDeclarator(thisRef, call), ]), ...bareSuperAfter, - t.expressionStatement(thisRef) + t.expressionStatement(thisRef), ]); } @@ -394,17 +412,17 @@ export default class ClassTransformer { verifyConstructor() { if (!this.isDerived) return; - let path = this.userConstructorPath; - let body = path.get("body"); + const path = this.userConstructorPath; + const body = path.get("body"); path.traverse(findThisesVisitor, this); let guaranteedSuperBeforeFinish = !!this.bareSupers.length; - let superRef = this.superName || t.identifier("Function"); - let thisRef = path.scope.generateUidIdentifier("this"); + const superRef = this.superName || t.identifier("Function"); + const thisRef = path.scope.generateUidIdentifier("this"); - for (let bareSuper of this.bareSupers) { + for (const bareSuper of this.bareSupers) { this.wrapSuperCall(bareSuper, superRef, thisRef, body); if (guaranteedSuperBeforeFinish) { @@ -422,28 +440,29 @@ export default class ClassTransformer { } } - for (let thisPath of this.superThises) { + for (const thisPath of this.superThises) { thisPath.replaceWith(thisRef); } - let wrapReturn = (returnArg) => t.callExpression( + const wrapReturn = (returnArg) => t.callExpression( this.file.addHelper("possibleConstructorReturn"), [thisRef].concat(returnArg || []) ); // if we have a return as the last node in the body then we've already caught that // return - let bodyPaths = body.get("body"); + const bodyPaths = body.get("body"); if (bodyPaths.length && !bodyPaths.pop().isReturnStatement()) { - body.pushContainer("body", t.returnStatement(guaranteedSuperBeforeFinish ? thisRef : wrapReturn())); + body.pushContainer("body", t.returnStatement( + guaranteedSuperBeforeFinish ? thisRef : wrapReturn())); } - for (let returnPath of this.superReturns) { + for (const returnPath of this.superReturns) { if (returnPath.node.argument) { - let ref = returnPath.scope.generateDeclaredUidIdentifier("ret"); + const ref = returnPath.scope.generateDeclaredUidIdentifier("ret"); returnPath.get("argument").replaceWithMultiple([ t.assignmentExpression("=", ref, returnPath.node.argument), - wrapReturn(ref) + wrapReturn(ref), ]); } else { returnPath.get("argument").replaceWith(wrapReturn()); @@ -456,7 +475,7 @@ export default class ClassTransformer { */ pushMethod(node: { type: "ClassMethod" }, path?: NodePath) { - let scope = path ? path.scope : this.scope; + const scope = path ? path.scope : this.scope; if (node.kind === "method") { if (this._processMethod(node, scope)) return; @@ -482,16 +501,16 @@ export default class ClassTransformer { path.scope.rename(this.classRef.name); } - let construct = this.constructor; + const construct = this.constructor; this.userConstructorPath = path; - this.userConstructor = method; - this.hasConstructor = true; + this.userConstructor = method; + this.hasConstructor = true; t.inheritsComments(construct, method); construct._ignoreUserWhitespace = true; - construct.params = method.params; + construct.params = method.params; t.inherits(construct.body, method.body); construct.body.directives = method.body.directives; diff --git a/packages/babel-plugin-transform-es2015-classes/test/index.js b/packages/babel-plugin-transform-es2015-classes/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-classes/test/index.js +++ b/packages/babel-plugin-transform-es2015-classes/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-computed-properties/README.md b/packages/babel-plugin-transform-es2015-computed-properties/README.md index db0e270a38..4a7c74d026 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/README.md +++ b/packages/babel-plugin-transform-es2015-computed-properties/README.md @@ -2,6 +2,49 @@ > Compile ES2015 computed properties to ES5 +## Example + +**In** + +```js +var obj = { + ["x" + foo]: "heh", + ["y" + bar]: "noo", + foo: "foo", + bar: "bar" +}; +``` + +**Out** + +```js +var _obj; + +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; +} + +var obj = ( + _obj = {}, + _defineProperty(_obj, "x" + foo, "heh"), + _defineProperty(_obj, "y" + bar, "noo"), + _defineProperty(_obj, "foo", "foo"), + _defineProperty(_obj, "bar", "bar"), + _obj +); +``` + ## Installation ```sh @@ -14,13 +57,17 @@ npm install --save-dev babel-plugin-transform-es2015-computed-properties **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-es2015-computed-properties"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-computed-properties", { @@ -46,6 +93,38 @@ require("babel-core").transform("code", { ## Options -* `loose` - Just like method assignment in classes, in loose mode, computed property names +### `loose` + +`boolean`, defaults to `false` + +Just like method assignment in classes, in loose mode, computed property names use simple assignments instead of being defined. This is unlikely to be an issue in production code. + +#### Example + +***In*** + +```js +var obj = { + ["x" + foo]: "heh", + ["y" + bar]: "noo", + foo: "foo", + bar: "bar" +}; +``` + +***Out*** + +```js +var _obj; + +var obj = ( + _obj = {}, + _obj["x" + foo] = "heh", + _obj["y" + bar] = "noo", + _obj.foo = "foo", + _obj.bar = "bar", + _obj +); +``` diff --git a/packages/babel-plugin-transform-es2015-computed-properties/package.json b/packages/babel-plugin-transform-es2015-computed-properties/package.json index e86661c43c..31b3130408 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/package.json +++ b/packages/babel-plugin-transform-es2015-computed-properties/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-computed-properties", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 computed properties to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-computed-properties", "license": "MIT", @@ -9,11 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-helper-define-map": "^6.8.0", - "babel-template": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-template": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js index 6bf843aaab..87f2de6a33 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js @@ -1,5 +1,5 @@ export default function ({ types: t, template }) { - let buildMutatorMapAssign = template(` + const buildMutatorMapAssign = template(` MUTATOR_MAP_REF[KEY] = MUTATOR_MAP_REF[KEY] || {}; MUTATOR_MAP_REF[KEY].KIND = VALUE; `); @@ -29,7 +29,7 @@ export default function ({ types: t, template }) { function pushMutatorDefine({ objId, body, getMutatorId, scope }, prop) { let key = !prop.computed && t.isIdentifier(prop.key) ? t.stringLiteral(prop.key.name) : prop.key; - let maybeMemoise = scope.maybeGenerateMemoised(key); + const maybeMemoise = scope.maybeGenerateMemoised(key); if (maybeMemoise) { body.push(t.expressionStatement(t.assignmentExpression("=", maybeMemoise, key))); key = maybeMemoise; @@ -39,12 +39,12 @@ export default function ({ types: t, template }) { MUTATOR_MAP_REF: getMutatorId(), KEY: key, VALUE: getValue(prop), - KIND: t.identifier(prop.kind) + KIND: t.identifier(prop.kind), })); } function loose(info) { - for (let prop of info.computedProps) { + for (const prop of info.computedProps) { if (prop.kind === "get" || prop.kind === "set") { pushMutatorDefine(info, prop); } else { @@ -54,10 +54,10 @@ export default function ({ types: t, template }) { } function spec(info) { - let { objId, body, computedProps, state } = info; + const { objId, body, computedProps, state } = info; - for (let prop of computedProps) { - let key = t.toComputedKey(prop); + for (const prop of computedProps) { + const key = t.toComputedKey(prop); if (prop.kind === "get" || prop.kind === "set") { pushMutatorDefine(info, prop); @@ -68,14 +68,14 @@ export default function ({ types: t, template }) { return t.callExpression(state.addHelper("defineProperty"), [ info.initPropExpression, key, - getValue(prop) + getValue(prop), ]); } else { body.push(t.expressionStatement( t.callExpression(state.addHelper("defineProperty"), [ objId, key, - getValue(prop) + getValue(prop), ]) )); } @@ -87,9 +87,9 @@ export default function ({ types: t, template }) { visitor: { ObjectExpression: { exit(path, state) { - let { node, parent, scope } = path; + const { node, parent, scope } = path; let hasComputed = false; - for (let prop of (node.properties: Array)) { + for (const prop of (node.properties: Array)) { hasComputed = prop.computed === true; if (hasComputed) break; } @@ -98,11 +98,11 @@ export default function ({ types: t, template }) { // put all getters/setters into the first object expression as well as all initialisers up // to the first computed property - let initProps = []; - let computedProps = []; + const initProps = []; + const computedProps = []; let foundComputed = false; - for (let prop of node.properties) { + for (const prop of node.properties) { if (prop.computed) { foundComputed = true; } @@ -114,12 +114,12 @@ export default function ({ types: t, template }) { } } - let objId = scope.generateUidIdentifierBasedOnNode(parent); - let initPropExpression = t.objectExpression(initProps); - let body = []; + const objId = scope.generateUidIdentifierBasedOnNode(parent); + const initPropExpression = t.objectExpression(initProps); + const body = []; body.push(t.variableDeclaration("var", [ - t.variableDeclarator(objId, initPropExpression) + t.variableDeclarator(objId, initPropExpression), ])); let callback = spec; @@ -127,19 +127,19 @@ export default function ({ types: t, template }) { let mutatorRef; - let getMutatorId = function () { + const getMutatorId = function () { if (!mutatorRef) { mutatorRef = scope.generateUidIdentifier("mutatorMap"); body.push(t.variableDeclaration("var", [ - t.variableDeclarator(mutatorRef, t.objectExpression([])) + t.variableDeclarator(mutatorRef, t.objectExpression([])), ])); } return mutatorRef; }; - let single = callback({ + const single = callback({ scope, objId, body, @@ -162,8 +162,8 @@ export default function ({ types: t, template }) { body.push(t.expressionStatement(objId)); path.replaceWithMultiple(body); } - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-computed-properties/test/index.js b/packages/babel-plugin-transform-es2015-computed-properties/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/test/index.js +++ b/packages/babel-plugin-transform-es2015-computed-properties/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-destructuring/package.json b/packages/babel-plugin-transform-es2015-destructuring/package.json index 2d8f9fc233..e3eef565a1 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/package.json +++ b/packages/babel-plugin-transform-es2015-destructuring/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-destructuring", - "version": "6.19.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 destructuring to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-destructuring", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.9.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-destructuring/src/index.js b/packages/babel-plugin-transform-es2015-destructuring/src/index.js index 3fe8c9fd3b..ea6ffe5ab8 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/src/index.js +++ b/packages/babel-plugin-transform-es2015-destructuring/src/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - export default function ({ types: t }) { /** @@ -7,7 +5,7 @@ export default function ({ types: t }) { */ function variableDeclarationHasPattern(node) { - for (let declar of (node.declarations: Array)) { + for (const declar of (node.declarations: Array)) { if (t.isPattern(declar.id)) { return true; } @@ -20,7 +18,7 @@ export default function ({ types: t }) { */ function hasRest(pattern) { - for (let elem of (pattern.elements: Array)) { + for (const elem of (pattern.elements: Array)) { if (t.isRestElement(elem)) { return true; } @@ -28,24 +26,24 @@ export default function ({ types: t }) { return false; } - let arrayUnpackVisitor = { + const arrayUnpackVisitor = { ReferencedIdentifier(path, state) { if (state.bindings[path.node.name]) { state.deopt = true; path.stop(); } - } + }, }; class DestructuringTransformer { constructor(opts) { this.blockHoist = opts.blockHoist; - this.operator = opts.operator; - this.arrays = {}; - this.nodes = opts.nodes || []; - this.scope = opts.scope; - this.file = opts.file; - this.kind = opts.kind; + this.operator = opts.operator; + this.arrays = {}; + this.nodes = opts.nodes || []; + this.scope = opts.scope; + this.file = opts.file; + this.kind = opts.kind; } buildVariableAssignment(id, init) { @@ -58,7 +56,7 @@ export default function ({ types: t }) { node = t.expressionStatement(t.assignmentExpression(op, id, init)); } else { node = t.variableDeclaration(this.kind, [ - t.variableDeclarator(id, init) + t.variableDeclarator(id, init), ]); } @@ -68,8 +66,8 @@ export default function ({ types: t }) { } buildVariableDeclaration(id, init) { - let declar = t.variableDeclaration("var", [ - t.variableDeclarator(id, init) + const declar = t.variableDeclaration("var", [ + t.variableDeclarator(id, init), ]); declar._blockHoist = this.blockHoist; return declar; @@ -99,25 +97,25 @@ export default function ({ types: t }) { // we need to assign the current value of the assignment to avoid evaluating // it more than once - let tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef); + const tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef); - let declar = t.variableDeclaration("var", [ - t.variableDeclarator(tempValueRef, valueRef) + const declar = t.variableDeclaration("var", [ + t.variableDeclarator(tempValueRef, valueRef), ]); declar._blockHoist = this.blockHoist; this.nodes.push(declar); // - let tempConditional = t.conditionalExpression( + const tempConditional = t.conditionalExpression( t.binaryExpression("===", tempValueRef, t.identifier("undefined")), pattern.right, tempValueRef ); - let left = pattern.left; + const left = pattern.left; if (t.isPattern(left)) { - let tempValueDefault = t.expressionStatement( + const tempValueDefault = t.expressionStatement( t.assignmentExpression("=", tempValueRef, tempConditional) ); tempValueDefault._blockHoist = this.blockHoist; @@ -135,14 +133,14 @@ export default function ({ types: t }) { let keys = []; for (let i = 0; i < pattern.properties.length; i++) { - let prop = pattern.properties[i]; + const prop = pattern.properties[i]; // we've exceeded the index of the spread property to all properties to the // right need to be ignored if (i >= spreadPropIndex) break; // ignore other spread properties - if (t.isRestProperty(prop)) continue; + if (t.isRestElement(prop)) continue; let key = prop.key; if (t.isIdentifier(key) && !prop.computed) key = t.stringLiteral(prop.key.name); @@ -153,15 +151,16 @@ export default function ({ types: t }) { // - let value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]); + const value = t.callExpression( + this.file.addHelper("objectWithoutProperties"), [objRef, keys]); this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value)); } pushObjectProperty(prop, propRef) { if (t.isLiteral(prop.key)) prop.computed = true; - let pattern = prop.value; - let objRef = t.memberExpression(propRef, prop.key, prop.computed); + const pattern = prop.value; + const objRef = t.memberExpression(propRef, prop.key, prop.computed); if (t.isPattern(pattern)) { this.push(pattern, objRef); @@ -184,7 +183,7 @@ export default function ({ types: t }) { // only evaluated once if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) { - let temp = this.scope.generateUidIdentifierBasedOnNode(objRef); + const temp = this.scope.generateUidIdentifierBasedOnNode(objRef); this.nodes.push(this.buildVariableDeclaration(temp, objRef)); objRef = temp; } @@ -192,8 +191,8 @@ export default function ({ types: t }) { // for (let i = 0; i < pattern.properties.length; i++) { - let prop = pattern.properties[i]; - if (t.isRestProperty(prop)) { + const prop = pattern.properties[i]; + if (t.isRestElement(prop)) { this.pushObjectRest(pattern, objRef, prop, i); } else { this.pushObjectProperty(prop, objRef); @@ -210,7 +209,7 @@ export default function ({ types: t }) { if (pattern.elements.length > arr.elements.length) return; if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false; - for (let elem of (pattern.elements: Array)) { + for (const elem of (pattern.elements: Array)) { // deopt on holes if (!elem) return false; @@ -218,7 +217,7 @@ export default function ({ types: t }) { if (t.isMemberExpression(elem)) return false; } - for (let elem of (arr.elements: Array)) { + for (const elem of (arr.elements: Array)) { // deopt on spread elements if (t.isSpreadElement(elem)) return false; @@ -230,15 +229,15 @@ export default function ({ types: t }) { } // deopt on reference to left side identifiers - let bindings = t.getBindingIdentifiers(pattern); - let state = { deopt: false, bindings }; + const bindings = t.getBindingIdentifiers(pattern); + const state = { deopt: false, bindings }; this.scope.traverse(arr, arrayUnpackVisitor, state); return !state.deopt; } pushUnpackedArrayPattern(pattern, arr) { for (let i = 0; i < pattern.elements.length; i++) { - let elem = pattern.elements[i]; + const elem = pattern.elements[i]; if (t.isRestElement(elem)) { this.push(elem.argument, t.arrayExpression(arr.elements.slice(i))); } else { @@ -264,13 +263,13 @@ export default function ({ types: t }) { // if we have a rest then we need all the elements so don't tell // `scope.toArray` to only get a certain amount - let count = !hasRest(pattern) && pattern.elements.length; + const count = !hasRest(pattern) && pattern.elements.length; // so we need to ensure that the `arrayRef` is an array, `scope.toArray` will // return a locally bound identifier if it's been inferred to be an array, // otherwise it'll be a call to a helper that will ensure it's one - let toArray = this.toArray(arrayRef, count); + const toArray = this.toArray(arrayRef, count); if (t.isIdentifier(toArray)) { // we've been given an identifier so it must have been inferred to be an @@ -294,10 +293,8 @@ export default function ({ types: t }) { if (t.isRestElement(elem)) { elemRef = this.toArray(arrayRef); - - if (i > 0) { - elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.numericLiteral(i)]); - } + elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), + [t.numericLiteral(i)]); // set the element to the rest element argument since we've dealt with it // being a rest already @@ -315,7 +312,7 @@ export default function ({ types: t }) { // need to save it to a variable if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) { - let memo = this.scope.maybeGenerateMemoised(ref, true); + const memo = this.scope.maybeGenerateMemoised(ref, true); if (memo) { this.nodes.push(this.buildVariableDeclaration(memo, ref)); ref = memo; @@ -334,14 +331,14 @@ export default function ({ types: t }) { return { visitor: { ExportNamedDeclaration(path) { - let declaration = path.get("declaration"); + const declaration = path.get("declaration"); if (!declaration.isVariableDeclaration()) return; if (!variableDeclarationHasPattern(declaration.node)) return; - let specifiers = []; + const specifiers = []; - for (let name in path.getOuterBindingIdentifiers(path)) { - let id = t.identifier(name); + for (const name in path.getOuterBindingIdentifiers(path)) { + const id = t.identifier(name); specifiers.push(t.exportSpecifier(id, id)); } @@ -353,22 +350,22 @@ export default function ({ types: t }) { }, ForXStatement(path, file) { - let { node, scope } = path; - let left = node.left; + const { node, scope } = path; + const left = node.left; if (t.isPattern(left)) { // for ({ length: k } in { abc: 3 }); - let temp = scope.generateUidIdentifier("ref"); + const temp = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration("var", [ - t.variableDeclarator(temp) + t.variableDeclarator(temp), ]); path.ensureBlock(); node.body.body.unshift(t.variableDeclaration("var", [ - t.variableDeclarator(left, temp) + t.variableDeclarator(left, temp), ])); return; @@ -376,45 +373,45 @@ export default function ({ types: t }) { if (!t.isVariableDeclaration(left)) return; - let pattern = left.declarations[0].id; + const pattern = left.declarations[0].id; if (!t.isPattern(pattern)) return; - let key = scope.generateUidIdentifier("ref"); + const key = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration(left.kind, [ - t.variableDeclarator(key, null) + t.variableDeclarator(key, null), ]); - let nodes = []; + const nodes = []; - let destructuring = new DestructuringTransformer({ + const destructuring = new DestructuringTransformer({ kind: left.kind, file: file, scope: scope, - nodes: nodes + nodes: nodes, }); destructuring.init(pattern, key); path.ensureBlock(); - let block = node.body; + const block = node.body; block.body = nodes.concat(block.body); }, CatchClause({ node, scope }, file) { - let pattern = node.param; + const pattern = node.param; if (!t.isPattern(pattern)) return; - let ref = scope.generateUidIdentifier("ref"); + const ref = scope.generateUidIdentifier("ref"); node.param = ref; - let nodes = []; + const nodes = []; - let destructuring = new DestructuringTransformer({ + const destructuring = new DestructuringTransformer({ kind: "let", file: file, scope: scope, - nodes: nodes + nodes: nodes, }); destructuring.init(pattern, ref); @@ -422,16 +419,16 @@ export default function ({ types: t }) { }, AssignmentExpression(path, file) { - let { node, scope } = path; + const { node, scope } = path; if (!t.isPattern(node.left)) return; - let nodes = []; + const nodes = []; - let destructuring = new DestructuringTransformer({ + const destructuring = new DestructuringTransformer({ operator: node.operator, file: file, scope: scope, - nodes: nodes + nodes: nodes, }); let ref; @@ -439,7 +436,7 @@ export default function ({ types: t }) { ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref"); nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(ref, node.right) + t.variableDeclarator(ref, node.right), ])); if (t.isArrayExpression(node.right)) { @@ -457,26 +454,26 @@ export default function ({ types: t }) { }, VariableDeclaration(path, file) { - let { node, scope, parent } = path; + const { node, scope, parent } = path; if (t.isForXStatement(parent)) return; if (!parent || !path.container) return; // i don't know why this is necessary - TODO if (!variableDeclarationHasPattern(node)) return; - let nodes = []; + const nodes = []; let declar; for (let i = 0; i < node.declarations.length; i++) { declar = node.declarations[i]; - let patternId = declar.init; - let pattern = declar.id; + const patternId = declar.init; + const pattern = declar.id; - let destructuring = new DestructuringTransformer({ + const destructuring = new DestructuringTransformer({ blockHoist: node._blockHoist, - nodes: nodes, - scope: scope, - kind: node.kind, - file: file + nodes: nodes, + scope: scope, + kind: node.kind, + file: file, }); if (t.isPattern(pattern)) { @@ -488,14 +485,18 @@ export default function ({ types: t }) { t.inherits(nodes[nodes.length - 1], declar); } } else { - nodes.push(t.inherits(destructuring.buildVariableAssignment(declar.id, declar.init), declar)); + nodes.push(t.inherits( + destructuring.buildVariableAssignment(declar.id, declar.init), declar)); } } const nodesOut = []; for (const node of nodes) { const tail = nodesOut[nodesOut.length - 1]; - if (tail && t.isVariableDeclaration(tail) && t.isVariableDeclaration(node) && tail.kind === node.kind) { + if ( + tail && t.isVariableDeclaration(tail) && t.isVariableDeclaration(node) && + tail.kind === node.kind + ) { // Create a single compound let/var rather than many. tail.declarations.push(...node.declarations); } else { @@ -509,7 +510,7 @@ export default function ({ types: t }) { for (const nodeOut of nodesOut) { if (!nodeOut.declarations) continue; for (const declaration of nodeOut.declarations) { - const {name} = declaration.id; + const { name } = declaration.id; if (scope.bindings[name]) { scope.bindings[name].kind = nodeOut.kind; } @@ -521,7 +522,7 @@ export default function ({ types: t }) { } else { path.replaceWithMultiple(nodesOut); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js b/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js new file mode 100644 index 0000000000..b7727da604 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js @@ -0,0 +1,9 @@ +const assign = function([...arr], index, value) { + arr[index] = value; + return arr; +} + +const arr = [1, 2, 3]; +assign(arr, 1, 42); + +assert.deepEqual(arr, [1, 2, 3]); diff --git a/packages/babel-plugin-transform-es2015-destructuring/test/index.js b/packages/babel-plugin-transform-es2015-destructuring/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/test/index.js +++ b/packages/babel-plugin-transform-es2015-destructuring/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-duplicate-keys/README.md b/packages/babel-plugin-transform-es2015-duplicate-keys/README.md index bfcb7c4257..aa502cce50 100644 --- a/packages/babel-plugin-transform-es2015-duplicate-keys/README.md +++ b/packages/babel-plugin-transform-es2015-duplicate-keys/README.md @@ -1,6 +1,8 @@ # babel-plugin-transform-es2015-duplicate-keys -> Compile objects with duplicate keys to valid strict ES5. This plugin actually converts duplicate keys in objects to be computed properties, which then must be handled by the [transform-es2015-computed-properties](http://babeljs.io/docs/plugins/transform-es2015-computed-properties) plugin. The final result won't contain any object literals with duplicate keys. +> Compile objects with duplicate keys to valid strict ES5. + +This plugin actually converts duplicate keys in objects to be computed properties, which then must be handled by the [transform-es2015-computed-properties](http://babeljs.io/docs/plugins/transform-es2015-computed-properties) plugin. The final result won't contain any object literals with duplicate keys. ## Example diff --git a/packages/babel-plugin-transform-es2015-duplicate-keys/package.json b/packages/babel-plugin-transform-es2015-duplicate-keys/package.json index 80f4a294b5..fd327fb34d 100644 --- a/packages/babel-plugin-transform-es2015-duplicate-keys/package.json +++ b/packages/babel-plugin-transform-es2015-duplicate-keys/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-duplicate-keys", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile objects with duplicate keys to valid strict ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-duplicate-keys", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.8.0" + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-duplicate-keys/src/index.js b/packages/babel-plugin-transform-es2015-duplicate-keys/src/index.js index 551e27a4ec..268af6e513 100644 --- a/packages/babel-plugin-transform-es2015-duplicate-keys/src/index.js +++ b/packages/babel-plugin-transform-es2015-duplicate-keys/src/index.js @@ -12,7 +12,7 @@ export default function() { visitor: { ObjectExpression(path) { const { node } = path; - const plainProps = node.properties.filter((prop) => !t.isSpreadProperty(prop) && !prop.computed); + const plainProps = node.properties.filter((prop) => !t.isSpreadElement(prop) && !prop.computed); // A property is a duplicate key if: // * the property is a data property, and is preceeded by a data, @@ -26,27 +26,27 @@ export default function() { const alreadySeenGetters = Object.create(null); const alreadySeenSetters = Object.create(null); - for (let prop of plainProps) { + for (const prop of plainProps) { const name = getName(prop.key); let isDuplicate = false; switch (prop.kind) { - case "get": - if (alreadySeenData[name] || alreadySeenGetters[name]) { - isDuplicate = true; - } - alreadySeenGetters[name] = true; - break; - case "set": - if (alreadySeenData[name] || alreadySeenSetters[name]) { - isDuplicate = true; - } - alreadySeenSetters[name] = true; - break; - default: - if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) { - isDuplicate = true; - } - alreadySeenData[name] = true; + case "get": + if (alreadySeenData[name] || alreadySeenGetters[name]) { + isDuplicate = true; + } + alreadySeenGetters[name] = true; + break; + case "set": + if (alreadySeenData[name] || alreadySeenSetters[name]) { + isDuplicate = true; + } + alreadySeenSetters[name] = true; + break; + default: + if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) { + isDuplicate = true; + } + alreadySeenData[name] = true; } if (isDuplicate) { @@ -56,7 +56,7 @@ export default function() { prop.key = t.stringLiteral(name); } } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-duplicate-keys/test/index.js b/packages/babel-plugin-transform-es2015-duplicate-keys/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-duplicate-keys/test/index.js +++ b/packages/babel-plugin-transform-es2015-duplicate-keys/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-for-of/README.md b/packages/babel-plugin-transform-es2015-for-of/README.md index 22aae1b1a0..3e9efe20d9 100644 --- a/packages/babel-plugin-transform-es2015-for-of/README.md +++ b/packages/babel-plugin-transform-es2015-for-of/README.md @@ -2,6 +2,41 @@ > Compile ES2015 for...of to ES5 +## Example + +**In** + +```js +for (var i of foo) {} +``` + +**Out** + +```js +var _iteratorNormalCompletion = true; +var _didIteratorError = false; +var _iteratorError = undefined; + +try { + for (var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var i = _step.value; + } +} catch (err) { + _didIteratorError = true; + _iteratorError = err; +} finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } +} +``` + ## Installation ```sh @@ -14,13 +49,17 @@ npm install --save-dev babel-plugin-transform-es2015-for-of **.babelrc** +Without options: + ```js -// without options { "plugins": ["transform-es2015-for-of"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-for-of", { @@ -44,52 +83,48 @@ require("babel-core").transform("code", { }); ``` -## Options `loose` +## Options -#### Abrupt completions +### `loose` -In loose mode an iterators `return` method will not be called on abrupt completions caused by thrown errors. +`boolean`, defaults to `false` -Please 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. +In loose mode, arrays are put in a fast path, thus heavily increasing performance. +All other iterables will continue to work fine. -#### Arrays +#### Example -Under loose mode the `forOf` transformer will output more verbose iteration code. +**In** -For example the following: - -```javascript +```js for (var i of foo) {} ``` -is normally output as: +**Out** -```javascript -for (var _iterator = foo[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { - var i = _step.value; -} -``` - -Under loose mode however it's output as: - -```javascript +```js for (var _iterator = foo, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var i; + var _ref; + if (_isArray) { if (_i >= _iterator.length) break; - i = _iterator[_i++]; + _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; - i = _i.value; + _ref = _i.value; } + + var i = _ref; } ``` -The result is that arrays are put in a fast path, heavily increasing performance. -All other iterables will continue to work fine but array iteration will be -significantly faster. +#### Abrupt completions + +In loose mode an iterator's `return` method will not be called on abrupt completions caused by thrown errors. + +Please 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. ### Optimization diff --git a/packages/babel-plugin-transform-es2015-for-of/package.json b/packages/babel-plugin-transform-es2015-for-of/package.json index 37d0d82808..24c437586b 100644 --- a/packages/babel-plugin-transform-es2015-for-of/package.json +++ b/packages/babel-plugin-transform-es2015-for-of/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-for-of", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 for...of to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-for-of", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-for-of/src/index.js b/packages/babel-plugin-transform-es2015-for-of/src/index.js index ca5ab6c090..9b7c0ed813 100644 --- a/packages/babel-plugin-transform-es2015-for-of/src/index.js +++ b/packages/babel-plugin-transform-es2015-for-of/src/index.js @@ -1,11 +1,9 @@ -/* eslint max-len: 0 */ - export default function ({ messages, template, types: t }) { - let buildForOfArray = template(` + const buildForOfArray = template(` for (var KEY = 0; KEY < ARR.length; KEY++) BODY; `); - let buildForOfLoose = template(` + const buildForOfLoose = template(` for (var LOOP_OBJECT = OBJECT, IS_ARRAY = Array.isArray(LOOP_OBJECT), INDEX = 0, @@ -22,7 +20,8 @@ export default function ({ messages, template, types: t }) { } `); - let buildForOf = template(` + /* eslint-disable max-len */ + const buildForOf = template(` var ITERATOR_COMPLETION = true; var ITERATOR_HAD_ERROR_KEY = false; var ITERATOR_ERROR_KEY = undefined; @@ -44,39 +43,41 @@ export default function ({ messages, template, types: t }) { } } `); + /* eslint-enable max-len */ function _ForOfStatementArray(path) { - let { node, scope } = path; - let nodes = []; + const { node, scope } = path; + const nodes = []; let right = node.right; if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) { - let uid = scope.generateUidIdentifier("arr"); + const uid = scope.generateUidIdentifier("arr"); nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(uid, right) + t.variableDeclarator(uid, right), ])); right = uid; } - let iterationKey = scope.generateUidIdentifier("i"); + const iterationKey = scope.generateUidIdentifier("i"); let loop = buildForOfArray({ BODY: node.body, - KEY: iterationKey, - ARR: right + KEY: iterationKey, + ARR: right, }); t.inherits(loop, node); t.ensureBlock(loop); - let iterationValue = t.memberExpression(right, iterationKey, true); + const iterationValue = t.memberExpression(right, iterationKey, true); - let left = node.left; + const left = node.left; if (t.isVariableDeclaration(left)) { left.declarations[0].init = iterationValue; loop.body.body.unshift(left); } else { - loop.body.body.unshift(t.expressionStatement(t.assignmentExpression("=", left, iterationValue))); + loop.body.body.unshift(t.expressionStatement( + t.assignmentExpression("=", left, iterationValue))); } if (path.parentPath.isLabeledStatement()) { @@ -103,11 +104,11 @@ export default function ({ messages, template, types: t }) { let callback = spec; if (state.opts.loose) callback = loose; - let { node } = path; - let build = callback(path, state); - let declar = build.declar; - let loop = build.loop; - let block = loop.body; + const { node } = path; + const build = callback(path, state); + const declar = build.declar; + const loop = build.loop; + const block = loop.body; // ensure that it's a block so we can take all its statements path.ensureBlock(); @@ -129,14 +130,13 @@ export default function ({ messages, template, types: t }) { } else { path.replaceWithMultiple(build.node); } - } - } + }, + }, }; function loose(path, file) { - let { node, scope } = path; - - let left = node.left; + const { node, scope, parent } = path; + const { left } = node; let declar, id; if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { @@ -146,21 +146,21 @@ export default function ({ messages, template, types: t }) { // for (let i of test) id = scope.generateUidIdentifier("ref"); declar = t.variableDeclaration(left.kind, [ - t.variableDeclarator(left.declarations[0].id, id) + t.variableDeclarator(left.declarations[0].id, id), ]); } else { throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type)); } - let iteratorKey = scope.generateUidIdentifier("iterator"); - let isArrayKey = scope.generateUidIdentifier("isArray"); + const iteratorKey = scope.generateUidIdentifier("iterator"); + const isArrayKey = scope.generateUidIdentifier("isArray"); - let loop = buildForOfLoose({ - LOOP_OBJECT: iteratorKey, - IS_ARRAY: isArrayKey, - OBJECT: node.right, - INDEX: scope.generateUidIdentifier("i"), - ID: id + const loop = buildForOfLoose({ + LOOP_OBJECT: iteratorKey, + IS_ARRAY: isArrayKey, + OBJECT: node.right, + INDEX: scope.generateUidIdentifier("i"), + ID: id, }); if (!declar) { @@ -170,21 +170,28 @@ export default function ({ messages, template, types: t }) { } // + const isLabeledParent = t.isLabeledStatement(parent); + let labeled; + + if (isLabeledParent) { + labeled = t.labeledStatement(parent.label, loop); + } return { + replaceParent: isLabeledParent, declar: declar, - node: loop, - loop: loop + node: labeled || loop, + loop: loop, }; } function spec(path, file) { - let { node, scope, parent } = path; - let left = node.left; + const { node, scope, parent } = path; + const left = node.left; let declar; - let stepKey = scope.generateUidIdentifier("step"); - let stepValue = t.memberExpression(stepKey, t.identifier("value")); + const stepKey = scope.generateUidIdentifier("step"); + const stepValue = t.memberExpression(stepKey, t.identifier("value")); if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { // for (i of test), for ({ i } of test) @@ -192,7 +199,7 @@ export default function ({ messages, template, types: t }) { } else if (t.isVariableDeclaration(left)) { // for (let i of test) declar = t.variableDeclaration(left.kind, [ - t.variableDeclarator(left.declarations[0].id, stepValue) + t.variableDeclarator(left.declarations[0].id, stepValue), ]); } else { throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type)); @@ -200,22 +207,22 @@ export default function ({ messages, template, types: t }) { // - let iteratorKey = scope.generateUidIdentifier("iterator"); + const iteratorKey = scope.generateUidIdentifier("iterator"); - let template = buildForOf({ + const template = buildForOf({ ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"), - ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"), - ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"), - ITERATOR_KEY: iteratorKey, - STEP_KEY: stepKey, - OBJECT: node.right, - BODY: null + ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"), + ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"), + ITERATOR_KEY: iteratorKey, + STEP_KEY: stepKey, + OBJECT: node.right, + BODY: null, }); - let isLabeledParent = t.isLabeledStatement(parent); + const isLabeledParent = t.isLabeledStatement(parent); - let tryBody = template[3].block.body; - let loop = tryBody[0]; + const tryBody = template[3].block.body; + const loop = tryBody[0]; if (isLabeledParent) { tryBody[0] = t.labeledStatement(parent.label, loop); @@ -225,9 +232,9 @@ export default function ({ messages, template, types: t }) { return { replaceParent: isLabeledParent, - declar: declar, - loop: loop, - node: template + declar: declar, + loop: loop, + node: template, }; } } diff --git a/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/actual.js b/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/actual.js new file mode 100644 index 0000000000..73c8203449 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/actual.js @@ -0,0 +1,5 @@ +b: for (let c of d()) { + for (let e of f()) { + continue b; + } +} diff --git a/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/expected.js b/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/expected.js new file mode 100644 index 0000000000..e3e9396649 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-for-of/test/fixtures/loose/nested-label-for-of/expected.js @@ -0,0 +1,31 @@ +b: for (var _iterator = d(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + let c = _ref; + + for (var _iterator2 = f(), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + let e = _ref2; + + continue b; + } +} diff --git a/packages/babel-plugin-transform-es2015-for-of/test/index.js b/packages/babel-plugin-transform-es2015-for-of/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-for-of/test/index.js +++ b/packages/babel-plugin-transform-es2015-for-of/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-function-name/package.json b/packages/babel-plugin-transform-es2015-function-name/package.json index 291bd84c7b..d2458bf881 100644 --- a/packages/babel-plugin-transform-es2015-function-name/package.json +++ b/packages/babel-plugin-transform-es2015-function-name/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-function-name", - "version": "6.9.0", + "version": "7.0.0-alpha.1", "description": "Apply ES2015 function.name semantics to all functions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-function-name", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-helper-function-name": "^6.8.0", - "babel-types": "^6.9.0", - "babel-runtime": "^6.9.0" + "babel-helper-function-name": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-function-name/src/index.js b/packages/babel-plugin-transform-es2015-function-name/src/index.js index ab403e6ec5..737144c05a 100644 --- a/packages/babel-plugin-transform-es2015-function-name/src/index.js +++ b/packages/babel-plugin-transform-es2015-function-name/src/index.js @@ -3,22 +3,22 @@ import nameFunction from "babel-helper-function-name"; export default function () { return { visitor: { - "ArrowFunctionExpression|FunctionExpression": { + FunctionExpression: { exit(path) { if (path.key !== "value" && !path.parentPath.isObjectProperty()) { - let replacement = nameFunction(path); + const replacement = nameFunction(path); if (replacement) path.replaceWith(replacement); } - } + }, }, ObjectProperty(path) { - let value = path.get("value"); + const value = path.get("value"); if (value.isFunction()) { - let newNode = nameFunction(value); + const newNode = nameFunction(value); if (newNode) value.replaceWith(newNode); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js new file mode 100644 index 0000000000..f56af5c601 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js @@ -0,0 +1,5 @@ +// I don't know if this is a bug with arrow-functions spec: true +// or with function-name, but the functions are missing their names. +const x = () => x; +const y = x => x(); +const z = { z: () => y(x) }.z; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js new file mode 100644 index 0000000000..b842455dae --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js @@ -0,0 +1,16 @@ +var _this = this; + +// I don't know if this is a bug with arrow-functions spec: true +// or with function-name, but the functions are missing their names. +const x = function () { + babelHelpers.newArrowCheck(this, _this); + return x; +}.bind(this); +const y = function (x) { + babelHelpers.newArrowCheck(this, _this); + return x(); +}.bind(this); +const z = { z: function z() { + babelHelpers.newArrowCheck(this, _this); + return y(x); + }.bind(this) }.z; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json new file mode 100644 index 0000000000..d66c99f262 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", [ "transform-es2015-arrow-functions", { "spec": true } ]] +} diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js new file mode 100644 index 0000000000..c1e980a79f --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js @@ -0,0 +1,3 @@ +const x = () => x; +const y = x => x(); +const z = { z: () => y(x) }.z; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js new file mode 100644 index 0000000000..096e218d2d --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js @@ -0,0 +1,9 @@ +const x = function x() { + return x; +}; +const y = function y(x) { + return x(); +}; +const z = { z: function z() { + return y(x); + } }.z; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json new file mode 100644 index 0000000000..32ac45253f --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-arrow-functions"] +} diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js new file mode 100644 index 0000000000..c8b74de50e --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js @@ -0,0 +1,2 @@ +export const x = ({x}) => x; +export const y = function () {}; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js new file mode 100644 index 0000000000..e7a7ae72b4 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js @@ -0,0 +1,2 @@ +export const x = ({ x }) => x; +export const y = function y() {}; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json new file mode 100644 index 0000000000..f2178b7ef6 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name"] +} diff --git a/packages/babel-plugin-transform-es2015-function-name/test/index.js b/packages/babel-plugin-transform-es2015-function-name/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-function-name/test/index.js +++ b/packages/babel-plugin-transform-es2015-function-name/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-instanceof/package.json b/packages/babel-plugin-transform-es2015-instanceof/package.json index f597d17ec3..d997b4c467 100644 --- a/packages/babel-plugin-transform-es2015-instanceof/package.json +++ b/packages/babel-plugin-transform-es2015-instanceof/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-instanceof", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms all the ES2015 'instanceof' methods", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-instanceof", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-instanceof/src/index.js b/packages/babel-plugin-transform-es2015-instanceof/src/index.js index d12f4c6fc9..50e10c06c4 100644 --- a/packages/babel-plugin-transform-es2015-instanceof/src/index.js +++ b/packages/babel-plugin-transform-es2015-instanceof/src/index.js @@ -2,11 +2,11 @@ export default function ({ types: t }) { return { visitor: { BinaryExpression(path) { - let { node } = path; + const { node } = path; if (node.operator === "instanceof") { path.replaceWith(t.callExpression(this.addHelper("instanceof"), [node.left, node.right])); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-instanceof/test/index.js b/packages/babel-plugin-transform-es2015-instanceof/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-instanceof/test/index.js +++ b/packages/babel-plugin-transform-es2015-instanceof/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-literals/package.json b/packages/babel-plugin-transform-es2015-literals/package.json index 0d3047c0e0..bc81940b1d 100644 --- a/packages/babel-plugin-transform-es2015-literals/package.json +++ b/packages/babel-plugin-transform-es2015-literals/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-literals", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 unicode string and number literals to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-literals", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-literals/src/index.js b/packages/babel-plugin-transform-es2015-literals/src/index.js index 3f6d33c4ce..4e9dd463d2 100644 --- a/packages/babel-plugin-transform-es2015-literals/src/index.js +++ b/packages/babel-plugin-transform-es2015-literals/src/index.js @@ -13,7 +13,7 @@ export default function () { if (node.extra && /\\[u]/gi.test(node.extra.raw)) { node.extra = undefined; } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/README.md b/packages/babel-plugin-transform-es2015-modules-amd/README.md index 04455655ac..bf54c82a75 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/README.md +++ b/packages/babel-plugin-transform-es2015-modules-amd/README.md @@ -55,3 +55,7 @@ require("babel-core").transform("code", { plugins: ["transform-es2015-modules-amd"] }); ``` + +### Options + +See options for `babel-plugin-transform-es2015-commonjs`. diff --git a/packages/babel-plugin-transform-es2015-modules-amd/package.json b/packages/babel-plugin-transform-es2015-modules-amd/package.json index d17ea42bb0..36969f3150 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/package.json +++ b/packages/babel-plugin-transform-es2015-modules-amd/package.json @@ -1,19 +1,18 @@ { "name": "babel-plugin-transform-es2015-modules-amd", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms ES2015 modules to AMD", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-modules-amd", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", - "babel-template": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-transform-es2015-modules-commonjs": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/src/index.js b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js index 3c5f9243bc..12cf89b0d8 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js @@ -1,10 +1,11 @@ import template from "babel-template"; +import transformCommonjs from "babel-plugin-transform-es2015-modules-commonjs"; -let buildDefine = template(` +const buildDefine = template(` define(MODULE_NAME, [SOURCES], FACTORY); `); -let buildFactory = template(` +const buildFactory = template(` (function (PARAMS) { BODY; }) @@ -16,16 +17,16 @@ export default function ({ types: t }) { if (!path.get("callee").isIdentifier({ name: "require" })) return false; if (path.scope.getBinding("require")) return false; - let args = path.get("arguments"); + const args = path.get("arguments"); if (args.length !== 1) return false; - let arg = args[0]; + const arg = args[0]; if (!arg.isStringLiteral()) return false; return true; } - let amdVisitor = { + const amdVisitor = { ReferencedIdentifier({ node, scope }) { if (node.name === "exports" && !scope.getBinding("exports")) { this.hasExports = true; @@ -43,22 +44,22 @@ export default function ({ types: t }) { }, VariableDeclarator(path) { - let id = path.get("id"); + const id = path.get("id"); if (!id.isIdentifier()) return; - let init = path.get("init"); + const init = path.get("init"); if (!isValidRequireCall(init)) return; - let source = init.node.arguments[0]; + const source = init.node.arguments[0]; this.sourceNames[source.value] = true; this.sources.push([id.node, source]); path.remove(); - } + }, }; return { - inherits: require("babel-plugin-transform-es2015-modules-commonjs"), + inherits: transformCommonjs, pre() { // source strings @@ -80,7 +81,7 @@ export default function ({ types: t }) { path.traverse(amdVisitor, this); - let params = this.sources.map((source) => source[0]); + const params = this.sources.map((source) => source[0]); let sources = this.sources.map((source) => source[1]); sources = sources.concat(this.bareSources.filter((str) => { @@ -100,10 +101,10 @@ export default function ({ types: t }) { params.unshift(t.identifier("module")); } - let { node } = path; - let factory = buildFactory({ + const { node } = path; + const factory = buildFactory({ PARAMS: params, - BODY: node.body + BODY: node.body, }); factory.expression.body.directives = node.directives; node.directives = []; @@ -111,10 +112,10 @@ export default function ({ types: t }) { node.body = [buildDefine({ MODULE_NAME: moduleName, SOURCES: sources, - FACTORY: factory + FACTORY: factory, })]; - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js new file mode 100644 index 0000000000..7d2c9b022e --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/actual.js @@ -0,0 +1 @@ +export { default } from 'foo'; diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js new file mode 100644 index 0000000000..cd5f804ab6 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/expected.js @@ -0,0 +1,13 @@ +define(['exports', 'foo'], function (exports, _foo) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, 'default', { + enumerable: true, + get: function () { + return _foo.default; + } + }); +}); diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json new file mode 100644 index 0000000000..096d2b9404 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-export-from/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-amd", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js new file mode 100644 index 0000000000..44567cb185 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/actual.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +foo; diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js new file mode 100644 index 0000000000..acdfb3b580 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/expected.js @@ -0,0 +1,5 @@ +define(["foo"], function (_foo) { + "use strict"; + + _foo.default; +}); diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json new file mode 100644 index 0000000000..096d2b9404 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/fixtures/amd/noInterop-import-default-only/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-amd", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-amd/test/index.js b/packages/babel-plugin-transform-es2015-modules-amd/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-modules-amd/test/index.js +++ b/packages/babel-plugin-transform-es2015-modules-amd/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md index 0693b91f07..33088cc868 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md @@ -62,7 +62,11 @@ require("babel-core").transform("code", { }); ``` -## Options `loose` +## Options + +### `loose` + +`boolean`, defaults to `false`. As per the spec, `import` and `export` are only allowed to be used at the top level. When in loose mode these are allowed to be used anywhere. @@ -78,10 +82,53 @@ Object.defineProperty(exports, "__esModule", { }); ``` -In environments that don't support this you can enable loose mode on `es6.modules` +In environments that don't support this you can enable loose mode on `babel-plugin-transform-es20150-modules-commonjs` and instead of using `Object.defineProperty` an assignment will be used instead. ```javascript var foo = exports.foo = 5; exports.__esModule = true; ``` + +### `strict` + +`boolean`, defaults to `false` + +By default, when using exports with babel a non-enumerable `__esModule` property +is exported. In some cases this property is used to determine if the import _is_ the +default export or if it _contains_ the default export. + +```javascript +var foo = exports.foo = 5; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +``` + +In order to prevent the `__esModule` property from being exported, you can set +the `strict` option to `true`. + +### `noInterop` + +`boolean`, defaults to `false` + +By default, when using exports with babel a non-enumerable `__esModule` property +is exported. This property is then used to determine if the import _is_ the default +export or if it _contains_ the default export. + +```javascript +"use strict"; + +var _foo = require("foo"); + +var _foo2 = _interopRequireDefault(_foo); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +``` + +In cases where the auto-unwrapping of `default` is not needed, you can set the +`noInterop` option to `true` to avoid the usage of the `interopRequireDefault` +helper (shown in inline form above). diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/package.json b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json index bc8f84282f..fe000208af 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/package.json +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json @@ -1,20 +1,19 @@ { "name": "babel-plugin-transform-es2015-modules-commonjs", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms ES2015 modules to CommonJS", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-modules-commonjs", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-types": "^6.18.0", - "babel-runtime": "^6.0.0", - "babel-template": "^6.16.0", - "babel-plugin-transform-strict-mode": "^6.18.0" + "babel-types": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "babel-plugin-transform-strict-mode": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index 8d3351bfa9..a9178da61e 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -1,20 +1,19 @@ -/* eslint max-len: 0 */ - import { basename, extname } from "path"; import template from "babel-template"; import * as t from "babel-types"; +import transformStrictMode from "babel-plugin-transform-strict-mode"; -let buildRequire = template(` +const buildRequire = template(` require($0); `); -let buildExportsModuleDeclaration = template(` +const buildExportsModuleDeclaration = template(` Object.defineProperty(exports, "__esModule", { value: true }); `); -let buildExportsFrom = template(` +const buildExportsFrom = template(` Object.defineProperty(exports, $0, { enumerable: true, get: function () { @@ -23,15 +22,15 @@ let buildExportsFrom = template(` }); `); -let buildLooseExportsModuleDeclaration = template(` +const buildLooseExportsModuleDeclaration = template(` exports.__esModule = true; `); -let buildExportsAssignment = template(` +const buildExportsAssignment = template(` exports.$0 = $1; `); -let buildExportAll = template(` +const buildExportAll = template(` Object.keys(OBJECT).forEach(function (key) { if (key === "default" || key === "__esModule") return; Object.defineProperty(exports, key, { @@ -43,15 +42,16 @@ let buildExportAll = template(` }); `); -const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", "ClassMethod", "ObjectMethod"]; +const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", + "ClassMethod", "ObjectMethod"]; export default function () { - let REASSIGN_REMAP_SKIP = Symbol(); + const REASSIGN_REMAP_SKIP = Symbol(); - let reassignmentVisitor = { + const reassignmentVisitor = { ReferencedIdentifier(path) { - let name = path.node.name; - let remap = this.remaps[name]; + const name = path.node.name; + const remap = this.remaps[name]; if (!remap) return; // redeclared in this scope @@ -61,7 +61,8 @@ export default function () { path.replaceWith(t.sequenceExpression([t.numericLiteral(0), remap])); } else if (path.isJSXIdentifier() && t.isMemberExpression(remap)) { const { object, property } = remap; - path.replaceWith(t.JSXMemberExpression(t.JSXIdentifier(object.name), t.JSXIdentifier(property.name))); + path.replaceWith(t.JSXMemberExpression(t.JSXIdentifier(object.name), + t.JSXIdentifier(property.name))); } else { path.replaceWith(remap); } @@ -72,11 +73,11 @@ export default function () { let node = path.node; if (node[REASSIGN_REMAP_SKIP]) return; - let left = path.get("left"); + const left = path.get("left"); if (!left.isIdentifier()) return; - let name = left.node.name; - let exports = this.exports[name]; + const name = left.node.name; + const exports = this.exports[name]; if (!exports) return; // redeclared in this scope @@ -84,7 +85,7 @@ export default function () { node[REASSIGN_REMAP_SKIP] = true; - for (let reid of exports) { + for (const reid of exports) { node = buildExportsAssignment(reid, node).expression; } @@ -93,17 +94,17 @@ export default function () { }, UpdateExpression(path) { - let arg = path.get("argument"); + const arg = path.get("argument"); if (!arg.isIdentifier()) return; - let name = arg.node.name; - let exports = this.exports[name]; + const name = arg.node.name; + const exports = this.exports[name]; if (!exports) return; // redeclared in this scope if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; - let node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numericLiteral(1)); + const node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numericLiteral(1)); if ((path.parentPath.isExpressionStatement() && !path.isCompletionRecord()) || path.node.prefix) { path.replaceWith(node); @@ -111,7 +112,7 @@ export default function () { return; } - let nodes = []; + const nodes = []; nodes.push(node); let operator; @@ -123,11 +124,11 @@ export default function () { nodes.push(t.binaryExpression(operator, arg.node, t.numericLiteral(1))); path.replaceWithMultiple(t.sequenceExpression(nodes)); - } + }, }; return { - inherits: require("babel-plugin-transform-strict-mode"), + inherits: transformStrictMode, visitor: { ThisExpression(path, state) { @@ -149,9 +150,10 @@ export default function () { exit(path) { this.ranCommonJS = true; - let strict = !!this.opts.strict; + const strict = !!this.opts.strict; + const noInterop = !!this.opts.noInterop; - let { scope } = path; + const { scope } = path; // rename these commonjs variables if they're declared in the file scope.rename("module"); @@ -161,27 +163,27 @@ export default function () { let hasExports = false; let hasImports = false; - let body: Array = path.get("body"); - let imports = Object.create(null); - let exports = Object.create(null); + const body: Array = path.get("body"); + const imports = Object.create(null); + const exports = Object.create(null); - let nonHoistedExportNames = Object.create(null); + const nonHoistedExportNames = Object.create(null); - let topNodes = []; - let remaps = Object.create(null); + const topNodes = []; + const remaps = Object.create(null); - let requires = Object.create(null); + const requires = Object.create(null); function addRequire(source, blockHoist) { - let cached = requires[source]; + const cached = requires[source]; if (cached) return cached; - let ref = path.scope.generateUidIdentifier(basename(source, extname(source))); + const ref = path.scope.generateUidIdentifier(basename(source, extname(source))); - let varDecl = t.variableDeclaration("var", [ + const varDecl = t.variableDeclaration("var", [ t.variableDeclarator(ref, buildRequire( t.stringLiteral(source) - ).expression) + ).expression), ]); // Copy location from the original import statement for sourcemap @@ -200,17 +202,17 @@ export default function () { } function addTo(obj, key, arr) { - let existing = obj[key] || []; + const existing = obj[key] || []; obj[key] = existing.concat(arr); } - for (let path of body) { + for (const path of body) { if (path.isExportDeclaration()) { hasExports = true; - let specifiers = [].concat(path.get("declaration"), path.get("specifiers")); - for (let specifier of specifiers) { - let ids = specifier.getBindingIdentifiers(); + const specifiers = [].concat(path.get("declaration"), path.get("specifiers")); + for (const specifier of specifiers) { + const ids = specifier.getBindingIdentifiers(); if (ids.__esModule) { throw specifier.buildCodeFrameError("Illegal export \"__esModule\""); } @@ -220,8 +222,8 @@ export default function () { if (path.isImportDeclaration()) { hasImports = true; - let key = path.node.source.value; - let importsEntry = imports[key] || { + const key = path.node.source.value; + const importsEntry = imports[key] || { specifiers: [], maxBlockHoist: 0, loc: path.node.loc, @@ -240,10 +242,10 @@ export default function () { path.remove(); } else if (path.isExportDefaultDeclaration()) { - let declaration = path.get("declaration"); + const declaration = path.get("declaration"); if (declaration.isFunctionDeclaration()) { - let id = declaration.node.id; - let defNode = t.identifier("default"); + const id = declaration.node.id; + const defNode = t.identifier("default"); if (id) { addTo(exports, id.name, defNode); topNodes.push(buildExportsAssignment(defNode, id)); @@ -253,13 +255,13 @@ export default function () { path.remove(); } } else if (declaration.isClassDeclaration()) { - let id = declaration.node.id; - let defNode = t.identifier("default"); + const id = declaration.node.id; + const defNode = t.identifier("default"); if (id) { addTo(exports, id.name, defNode); path.replaceWithMultiple([ declaration.node, - buildExportsAssignment(defNode, id) + buildExportsAssignment(defNode, id), ]); } else { path.replaceWith(buildExportsAssignment(defNode, t.toExpression(declaration.node))); @@ -278,27 +280,27 @@ export default function () { path.parentPath.requeue(path.get("expression.left")); } } else if (path.isExportNamedDeclaration()) { - let declaration = path.get("declaration"); + const declaration = path.get("declaration"); if (declaration.node) { if (declaration.isFunctionDeclaration()) { - let id = declaration.node.id; + const id = declaration.node.id; addTo(exports, id.name, id); topNodes.push(buildExportsAssignment(id, id)); path.replaceWith(declaration.node); } else if (declaration.isClassDeclaration()) { - let id = declaration.node.id; + const id = declaration.node.id; addTo(exports, id.name, id); path.replaceWithMultiple([ declaration.node, - buildExportsAssignment(id, id) + buildExportsAssignment(id, id), ]); nonHoistedExportNames[id.name] = true; } else if (declaration.isVariableDeclaration()) { - let declarators = declaration.get("declarations"); - for (let decl of declarators) { - let id = decl.get("id"); + const declarators = declaration.get("declarations"); + for (const decl of declarators) { + const id = decl.get("id"); - let init = decl.get("init"); + const init = decl.get("init"); if (!init.node) init.replaceWith(t.identifier("undefined")); if (id.isIdentifier()) { @@ -314,28 +316,34 @@ export default function () { continue; } - let specifiers = path.get("specifiers"); - let nodes = []; - let source = path.node.source; + const specifiers = path.get("specifiers"); + const nodes = []; + const source = path.node.source; if (source) { - let ref = addRequire(source.value, path.node._blockHoist); + const ref = addRequire(source.value, path.node._blockHoist); - for (let specifier of specifiers) { + for (const specifier of specifiers) { if (specifier.isExportNamespaceSpecifier()) { // todo } else if (specifier.isExportDefaultSpecifier()) { // todo } else if (specifier.isExportSpecifier()) { - if (specifier.node.local.name === "default") { - topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(t.callExpression(this.addHelper("interopRequireDefault"), [ref]), specifier.node.local))); + if (!noInterop && specifier.node.local.name === "default") { + topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), + t.memberExpression( + t.callExpression(this.addHelper("interopRequireDefault"), [ref]), + specifier.node.local + ) + )); } else { - topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(ref, specifier.node.local))); + topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), + t.memberExpression(ref, specifier.node.local))); } nonHoistedExportNames[specifier.node.exported.name] = true; } } } else { - for (let specifier of specifiers) { + for (const specifier of specifiers) { if (specifier.isExportSpecifier()) { addTo(exports, specifier.node.local.name, specifier.node.exported); nonHoistedExportNames[specifier.node.exported.name] = true; @@ -345,8 +353,8 @@ export default function () { } path.replaceWithMultiple(nodes); } else if (path.isExportAllDeclaration()) { - let exportNode = buildExportAll({ - OBJECT: addRequire(path.node.source.value, path.node._blockHoist) + const exportNode = buildExportAll({ + OBJECT: addRequire(path.node.source.value, path.node._blockHoist), }); exportNode.loc = path.node.loc; topNodes.push(exportNode); @@ -354,17 +362,17 @@ export default function () { } } - for (let source in imports) { - let {specifiers, maxBlockHoist} = imports[source]; + for (const source in imports) { + const { specifiers, maxBlockHoist } = imports[source]; if (specifiers.length) { - let uid = addRequire(source, maxBlockHoist); + const uid = addRequire(source, maxBlockHoist); let wildcard; for (let i = 0; i < specifiers.length; i++) { - let specifier = specifiers[i]; + const specifier = specifiers[i]; if (t.isImportNamespaceSpecifier(specifier)) { - if (strict) { + if (strict || noInterop) { remaps[specifier.local.name] = uid; } else { const varDecl = t.variableDeclaration("var", [ @@ -374,7 +382,7 @@ export default function () { this.addHelper("interopRequireWildcard"), [uid] ) - ) + ), ]); if (maxBlockHoist > 0) { @@ -389,13 +397,13 @@ export default function () { } } - for (let specifier of specifiers) { + for (const specifier of specifiers) { if (t.isImportSpecifier(specifier)) { let target = uid; if (specifier.imported.name === "default") { if (wildcard) { target = wildcard; - } else { + } else if (!noInterop) { target = wildcard = path.scope.generateUidIdentifier(uid.name); const varDecl = t.variableDeclaration("var", [ t.variableDeclarator( @@ -404,7 +412,7 @@ export default function () { this.addHelper("interopRequireDefault"), [uid] ) - ) + ), ]); if (maxBlockHoist > 0) { @@ -414,28 +422,45 @@ export default function () { topNodes.push(varDecl); } } - remaps[specifier.local.name] = t.memberExpression(target, t.cloneWithoutLoc(specifier.imported)); + remaps[specifier.local.name] = t.memberExpression(target, + t.cloneWithoutLoc(specifier.imported)); } } } else { // bare import - let requireNode = buildRequire(t.stringLiteral(source)); + const requireNode = buildRequire(t.stringLiteral(source)); requireNode.loc = imports[source].loc; topNodes.push(requireNode); } } if (hasImports && Object.keys(nonHoistedExportNames).length) { - let hoistedExportsNode = t.identifier("undefined"); - for (let name in nonHoistedExportNames) { - hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression; + // avoid creating too long of export assignment to prevent stack overflow + const maxHoistedExportsNodeAssignmentLength = 100; + const nonHoistedExportNamesArr = Object.keys(nonHoistedExportNames); + + for ( + let currentExportsNodeAssignmentLength = 0; + currentExportsNodeAssignmentLength < nonHoistedExportNamesArr.length; + currentExportsNodeAssignmentLength += maxHoistedExportsNodeAssignmentLength + ) { + const nonHoistedExportNamesChunk = nonHoistedExportNamesArr.slice( + currentExportsNodeAssignmentLength, + currentExportsNodeAssignmentLength + maxHoistedExportsNodeAssignmentLength); + + let hoistedExportsNode = t.identifier("undefined"); + + nonHoistedExportNamesChunk.forEach(function (name) { + hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode) + .expression; + }); + + const node = t.expressionStatement(hoistedExportsNode); + node._blockHoist = 3; + + topNodes.unshift(node); } - - const node = t.expressionStatement(hoistedExportsNode); - node._blockHoist = 3; - - topNodes.unshift(node); } // add __esModule declaration if this file has any exports @@ -456,8 +481,8 @@ export default function () { exports, requeueInParent: (newPath) => path.requeue(newPath), }); - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/esmodule-flag.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/esmodule-flag.js index beee1e9cd3..6315e0d83a 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/esmodule-flag.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/esmodule-flag.js @@ -1,16 +1,16 @@ -let assert = require("assert"); -let babel = require("babel-core"); -let vm = require("vm"); +const assert = require("assert"); +const babel = require("babel-core"); +const vm = require("vm"); test("Re-export doesn't overwrite __esModule flag", function () { let code = "export * from \"./dep\";"; - let depStub = { + const depStub = { __esModule: false, }; - let context = { + const context = { module: { - exports: {} + exports: {}, }, require: function (id) { if (id === "./dep") return depStub; @@ -21,7 +21,7 @@ test("Re-export doesn't overwrite __esModule flag", function () { code = babel.transform(code, { "plugins": [ - [require("../"), {loose: true}], + [require("../"), { loose: true }], ], "ast": false, }).code; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/actual.js new file mode 100644 index 0000000000..b42963fe70 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/actual.js @@ -0,0 +1,2 @@ +import { foo, foo1, foo2, foo3, foo4, foo5, foo6, foo7, foo8, foo9, foo10, foo11, foo12, foo13, foo14, foo15, foo16, foo17, foo18, foo19, foo20, foo21, foo22, foo23, foo24, foo25, foo26, foo27, foo28, foo29, foo30, foo31, foo32, foo33, foo34, foo35, foo36, foo37, foo38, foo39, foo40, foo41, foo42, foo43, foo44, foo45, foo46, foo47, foo48, foo49, foo50, foo51, foo52, foo53, foo54, foo55, foo56, foo57, foo58, foo59, foo60, foo61, foo62, foo63, foo64, foo65, foo66, foo67, foo68, foo69, foo70, foo71, foo72, foo73, foo74, foo75, foo76, foo77, foo78, foo79, foo80, foo81, foo82, foo83, foo84, foo85, foo86, foo87, foo88, foo89, foo90, foo91, foo92, foo93, foo94, foo95, foo96, foo97, foo98, foo99, foo100 } from "foo"; +export { foo, foo1, foo2, foo3, foo4, foo5, foo6, foo7, foo8, foo9, foo10, foo11, foo12, foo13, foo14, foo15, foo16, foo17, foo18, foo19, foo20, foo21, foo22, foo23, foo24, foo25, foo26, foo27, foo28, foo29, foo30, foo31, foo32, foo33, foo34, foo35, foo36, foo37, foo38, foo39, foo40, foo41, foo42, foo43, foo44, foo45, foo46, foo47, foo48, foo49, foo50, foo51, foo52, foo53, foo54, foo55, foo56, foo57, foo58, foo59, foo60, foo61, foo62, foo63, foo64, foo65, foo66, foo67, foo68, foo69, foo70, foo71, foo72, foo73, foo74, foo75, foo76, foo77, foo78, foo79, foo80, foo81, foo82, foo83, foo84, foo85, foo86, foo87, foo88, foo89, foo90, foo91, foo92, foo93, foo94, foo95, foo96, foo97, foo98, foo99, foo100 } \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/expected.js new file mode 100644 index 0000000000..5f034e9682 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/interop/export-from-8/expected.js @@ -0,0 +1,111 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.foo100 = undefined; +exports.foo99 = exports.foo98 = exports.foo97 = exports.foo96 = exports.foo95 = exports.foo94 = exports.foo93 = exports.foo92 = exports.foo91 = exports.foo90 = exports.foo89 = exports.foo88 = exports.foo87 = exports.foo86 = exports.foo85 = exports.foo84 = exports.foo83 = exports.foo82 = exports.foo81 = exports.foo80 = exports.foo79 = exports.foo78 = exports.foo77 = exports.foo76 = exports.foo75 = exports.foo74 = exports.foo73 = exports.foo72 = exports.foo71 = exports.foo70 = exports.foo69 = exports.foo68 = exports.foo67 = exports.foo66 = exports.foo65 = exports.foo64 = exports.foo63 = exports.foo62 = exports.foo61 = exports.foo60 = exports.foo59 = exports.foo58 = exports.foo57 = exports.foo56 = exports.foo55 = exports.foo54 = exports.foo53 = exports.foo52 = exports.foo51 = exports.foo50 = exports.foo49 = exports.foo48 = exports.foo47 = exports.foo46 = exports.foo45 = exports.foo44 = exports.foo43 = exports.foo42 = exports.foo41 = exports.foo40 = exports.foo39 = exports.foo38 = exports.foo37 = exports.foo36 = exports.foo35 = exports.foo34 = exports.foo33 = exports.foo32 = exports.foo31 = exports.foo30 = exports.foo29 = exports.foo28 = exports.foo27 = exports.foo26 = exports.foo25 = exports.foo24 = exports.foo23 = exports.foo22 = exports.foo21 = exports.foo20 = exports.foo19 = exports.foo18 = exports.foo17 = exports.foo16 = exports.foo15 = exports.foo14 = exports.foo13 = exports.foo12 = exports.foo11 = exports.foo10 = exports.foo9 = exports.foo8 = exports.foo7 = exports.foo6 = exports.foo5 = exports.foo4 = exports.foo3 = exports.foo2 = exports.foo1 = exports.foo = undefined; + +var _foo = require("foo"); + +exports.foo = _foo.foo; +exports.foo1 = _foo.foo1; +exports.foo2 = _foo.foo2; +exports.foo3 = _foo.foo3; +exports.foo4 = _foo.foo4; +exports.foo5 = _foo.foo5; +exports.foo6 = _foo.foo6; +exports.foo7 = _foo.foo7; +exports.foo8 = _foo.foo8; +exports.foo9 = _foo.foo9; +exports.foo10 = _foo.foo10; +exports.foo11 = _foo.foo11; +exports.foo12 = _foo.foo12; +exports.foo13 = _foo.foo13; +exports.foo14 = _foo.foo14; +exports.foo15 = _foo.foo15; +exports.foo16 = _foo.foo16; +exports.foo17 = _foo.foo17; +exports.foo18 = _foo.foo18; +exports.foo19 = _foo.foo19; +exports.foo20 = _foo.foo20; +exports.foo21 = _foo.foo21; +exports.foo22 = _foo.foo22; +exports.foo23 = _foo.foo23; +exports.foo24 = _foo.foo24; +exports.foo25 = _foo.foo25; +exports.foo26 = _foo.foo26; +exports.foo27 = _foo.foo27; +exports.foo28 = _foo.foo28; +exports.foo29 = _foo.foo29; +exports.foo30 = _foo.foo30; +exports.foo31 = _foo.foo31; +exports.foo32 = _foo.foo32; +exports.foo33 = _foo.foo33; +exports.foo34 = _foo.foo34; +exports.foo35 = _foo.foo35; +exports.foo36 = _foo.foo36; +exports.foo37 = _foo.foo37; +exports.foo38 = _foo.foo38; +exports.foo39 = _foo.foo39; +exports.foo40 = _foo.foo40; +exports.foo41 = _foo.foo41; +exports.foo42 = _foo.foo42; +exports.foo43 = _foo.foo43; +exports.foo44 = _foo.foo44; +exports.foo45 = _foo.foo45; +exports.foo46 = _foo.foo46; +exports.foo47 = _foo.foo47; +exports.foo48 = _foo.foo48; +exports.foo49 = _foo.foo49; +exports.foo50 = _foo.foo50; +exports.foo51 = _foo.foo51; +exports.foo52 = _foo.foo52; +exports.foo53 = _foo.foo53; +exports.foo54 = _foo.foo54; +exports.foo55 = _foo.foo55; +exports.foo56 = _foo.foo56; +exports.foo57 = _foo.foo57; +exports.foo58 = _foo.foo58; +exports.foo59 = _foo.foo59; +exports.foo60 = _foo.foo60; +exports.foo61 = _foo.foo61; +exports.foo62 = _foo.foo62; +exports.foo63 = _foo.foo63; +exports.foo64 = _foo.foo64; +exports.foo65 = _foo.foo65; +exports.foo66 = _foo.foo66; +exports.foo67 = _foo.foo67; +exports.foo68 = _foo.foo68; +exports.foo69 = _foo.foo69; +exports.foo70 = _foo.foo70; +exports.foo71 = _foo.foo71; +exports.foo72 = _foo.foo72; +exports.foo73 = _foo.foo73; +exports.foo74 = _foo.foo74; +exports.foo75 = _foo.foo75; +exports.foo76 = _foo.foo76; +exports.foo77 = _foo.foo77; +exports.foo78 = _foo.foo78; +exports.foo79 = _foo.foo79; +exports.foo80 = _foo.foo80; +exports.foo81 = _foo.foo81; +exports.foo82 = _foo.foo82; +exports.foo83 = _foo.foo83; +exports.foo84 = _foo.foo84; +exports.foo85 = _foo.foo85; +exports.foo86 = _foo.foo86; +exports.foo87 = _foo.foo87; +exports.foo88 = _foo.foo88; +exports.foo89 = _foo.foo89; +exports.foo90 = _foo.foo90; +exports.foo91 = _foo.foo91; +exports.foo92 = _foo.foo92; +exports.foo93 = _foo.foo93; +exports.foo94 = _foo.foo94; +exports.foo95 = _foo.foo95; +exports.foo96 = _foo.foo96; +exports.foo97 = _foo.foo97; +exports.foo98 = _foo.foo98; +exports.foo99 = _foo.foo99; +exports.foo100 = _foo.foo100; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js new file mode 100644 index 0000000000..7d2c9b022e --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/actual.js @@ -0,0 +1 @@ +export { default } from 'foo'; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js new file mode 100644 index 0000000000..c986dfedbb --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/export-from/expected.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _foo = require('foo'); + +Object.defineProperty(exports, 'default', { + enumerable: true, + get: function () { + return _foo.default; + } +}); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js new file mode 100644 index 0000000000..65b75b7293 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/actual.js @@ -0,0 +1,3 @@ +import foo from "foo"; + +foo(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js new file mode 100644 index 0000000000..1bc59ef949 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-default-only/expected.js @@ -0,0 +1,5 @@ +"use strict"; + +var _foo = require("foo"); + +(0, _foo.default)(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js new file mode 100644 index 0000000000..bf67ef46a2 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/actual.js @@ -0,0 +1,4 @@ +import * as foo from 'foo'; + +foo.bar(); +foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js new file mode 100644 index 0000000000..284db9decd --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/import-wildcard/expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var _foo = require('foo'); + +_foo.bar(); +_foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json new file mode 100644 index 0000000000..b2a35b9fc8 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/noInterop/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", ["transform-es2015-modules-commonjs", { "noInterop": true }]] +} diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js new file mode 100644 index 0000000000..bf67ef46a2 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/actual.js @@ -0,0 +1,4 @@ +import * as foo from 'foo'; + +foo.bar(); +foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js new file mode 100644 index 0000000000..284db9decd --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/strict/import-wildcard/expected.js @@ -0,0 +1,6 @@ +'use strict'; + +var _foo = require('foo'); + +_foo.bar(); +_foo.baz(); diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/test/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/README.md b/packages/babel-plugin-transform-es2015-modules-systemjs/README.md index ca205005d9..554421de63 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/README.md +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/README.md @@ -35,13 +35,17 @@ npm install --save-dev babel-plugin-transform-es2015-modules-systemjs **.babelrc** -```javascript -// without options +Without options: + +```json { "plugins": ["transform-es2015-modules-systemjs"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-modules-systemjs", { diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/package.json b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json index 7a9e82b159..864028998a 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/package.json +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json @@ -1,20 +1,19 @@ { "name": "babel-plugin-transform-es2015-modules-systemjs", - "version": "6.19.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms ES2015 modules to SystemJS", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-modules-systemjs", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-template": "^6.14.0", - "babel-helper-hoist-variables": "^6.18.0", - "babel-runtime": "^6.11.6" + "babel-template": "7.0.0-alpha.1", + "babel-helper-hoist-variables": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0", - "babel-plugin-syntax-dynamic-import": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1", + "babel-plugin-syntax-dynamic-import": "7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js index 93091bac29..10383b609a 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js @@ -1,9 +1,7 @@ -/* eslint max-len: 0 */ - import hoistVariables from "babel-helper-hoist-variables"; import template from "babel-template"; -let buildTemplate = template(` +const buildTemplate = template(` SYSTEM_REGISTER(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) { "use strict"; BEFORE_BODY; @@ -16,7 +14,7 @@ let buildTemplate = template(` }); `); -let buildExportAll = template(` +const buildExportAll = template(` for (var KEY in TARGET) { if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY]; } @@ -26,22 +24,22 @@ let buildExportAll = template(` const TYPE_IMPORT = "Import"; export default function ({ types: t }) { - let IGNORE_REASSIGNMENT_SYMBOL = Symbol(); + const IGNORE_REASSIGNMENT_SYMBOL = Symbol(); - let reassignmentVisitor = { + const reassignmentVisitor = { "AssignmentExpression|UpdateExpression"(path) { if (path.node[IGNORE_REASSIGNMENT_SYMBOL]) return; path.node[IGNORE_REASSIGNMENT_SYMBOL] = true; - let arg = path.get(path.isAssignmentExpression() ? "left" : "argument"); + const arg = path.get(path.isAssignmentExpression() ? "left" : "argument"); if (!arg.isIdentifier()) return; - let name = arg.node.name; + const name = arg.node.name; // redeclared in this scope if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; - let exportedNames = this.exports[name]; + const exportedNames = this.exports[name]; if (!exportedNames) return; let node = path.node; @@ -52,22 +50,22 @@ export default function ({ types: t }) { let isPostUpdateExpression = path.isUpdateExpression() && !node.prefix; if (isPostUpdateExpression) { if (node.operator === "++") - node = t.binaryExpression("+", node.argument, t.numericLiteral(1)); + {node = t.binaryExpression("+", node.argument, t.numericLiteral(1));} else if (node.operator === "--") - node = t.binaryExpression("-", node.argument, t.numericLiteral(1)); + {node = t.binaryExpression("-", node.argument, t.numericLiteral(1));} else - isPostUpdateExpression = false; + {isPostUpdateExpression = false;} } - for (let exportedName of exportedNames) { + for (const exportedName of exportedNames) { node = this.buildCall(exportedName, node).expression; } if (isPostUpdateExpression) - node = t.sequenceExpression([node, path.node]); + {node = t.sequenceExpression([node, path.node]);} path.replaceWith(node); - } + }, }; return { @@ -75,8 +73,9 @@ export default function ({ types: t }) { CallExpression(path, state) { if (path.node.callee.type === TYPE_IMPORT) { - let contextIdent = state.contextIdent; - path.replaceWith(t.callExpression(t.memberExpression(contextIdent, t.identifier("import")), path.node.arguments)); + const contextIdent = state.contextIdent; + path.replaceWith(t.callExpression(t.memberExpression(contextIdent, t.identifier("import")), + path.node.arguments)); } }, @@ -91,17 +90,17 @@ export default function ({ types: t }) { state.contextIdent = path.scope.generateUidIdentifier("context"); }, exit(path, state) { - let exportIdent = path.scope.generateUidIdentifier("export"); - let contextIdent = state.contextIdent; + const exportIdent = path.scope.generateUidIdentifier("export"); + const contextIdent = state.contextIdent; - let exportNames = Object.create(null); - let modules = []; + const exportNames = Object.create(null); + const modules = []; let beforeBody = []; - let setters = []; - let sources = []; - let variableIds = []; - let removedPaths = []; + const setters = []; + const sources = []; + const variableIds = []; + const removedPaths = []; function addExportName(key, val) { exportNames[key] = exportNames[key] || []; @@ -127,7 +126,7 @@ export default function ({ types: t }) { ); } - let body: Array = path.get("body"); + const body: Array = path.get("body"); let canHoist = true; for (let path of body) { @@ -138,14 +137,14 @@ export default function ({ types: t }) { } } - for (let path of body) { + for (const path of body) { if (canHoist && path.isFunctionDeclaration()) { beforeBody.push(path.node); removedPaths.push(path); } else if (path.isImportDeclaration()) { - let source = path.node.source.value; + const source = path.node.source.value; pushModule(source, "imports", path.node.specifiers); - for (let name in path.getBindingIdentifiers()) { + for (const name in path.getBindingIdentifiers()) { path.scope.removeBinding(name); variableIds.push(t.identifier(name)); } @@ -154,10 +153,10 @@ export default function ({ types: t }) { pushModule(path.node.source.value, "exports", path.node); path.remove(); } else if (path.isExportDefaultDeclaration()) { - let declar = path.get("declaration"); + const declar = path.get("declaration"); if (declar.isClassDeclaration() || declar.isFunctionDeclaration()) { - let id = declar.node.id; - let nodes = []; + const id = declar.node.id; + const nodes = []; if (id) { nodes.push(declar.node); @@ -177,16 +176,16 @@ export default function ({ types: t }) { path.replaceWith(buildExportCall("default", declar.node)); } } else if (path.isExportNamedDeclaration()) { - let declar = path.get("declaration"); + const declar = path.get("declaration"); if (declar.node) { path.replaceWith(declar); - let nodes = []; + const nodes = []; let bindingIdentifiers; if (path.isFunction()) { - let node = declar.node; - let name = node.id.name; + const node = declar.node; + const name = node.id.name; if (canHoist) { addExportName(name, name); beforeBody.push(node); @@ -198,21 +197,21 @@ export default function ({ types: t }) { } else { bindingIdentifiers = declar.getBindingIdentifiers(); } - for (let name in bindingIdentifiers) { + for (const name in bindingIdentifiers) { addExportName(name, name); nodes.push(buildExportCall(name, t.identifier(name))); } path.insertAfter(nodes); } else { - let specifiers = path.node.specifiers; + const specifiers = path.node.specifiers; if (specifiers && specifiers.length) { if (path.node.source) { pushModule(path.node.source.value, "exports", specifiers); path.remove(); } else { - let nodes = []; + const nodes = []; - for (let specifier of specifiers) { + for (const specifier of specifiers) { nodes.push(buildExportCall(specifier.exported.name, specifier.local)); addExportName(specifier.local.name, specifier.exported.name); } @@ -225,8 +224,8 @@ export default function ({ types: t }) { } modules.forEach(function (specifiers) { - let setterBody = []; - let target = path.scope.generateUidIdentifier(specifiers.key); + const setterBody = []; + const target = path.scope.generateUidIdentifier(specifiers.key); for (let specifier of specifiers.imports) { if (t.isImportNamespaceSpecifier(specifier)) { @@ -236,27 +235,29 @@ export default function ({ types: t }) { } if (t.isImportSpecifier(specifier)) { - setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, t.memberExpression(target, specifier.imported)))); + setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, + t.memberExpression(target, specifier.imported)))); } } if (specifiers.exports.length) { - let exportObjRef = path.scope.generateUidIdentifier("exportObj"); + const exportObjRef = path.scope.generateUidIdentifier("exportObj"); setterBody.push(t.variableDeclaration("var", [ - t.variableDeclarator(exportObjRef, t.objectExpression([])) + t.variableDeclarator(exportObjRef, t.objectExpression([])), ])); - for (let node of specifiers.exports) { + for (const node of specifiers.exports) { if (t.isExportAllDeclaration(node)) { setterBody.push(buildExportAll({ KEY: path.scope.generateUidIdentifier("key"), EXPORT_OBJ: exportObjRef, - TARGET: target + TARGET: target, })); } else if (t.isExportSpecifier(node)) { setterBody.push(t.expressionStatement( - t.assignmentExpression("=", t.memberExpression(exportObjRef, node.exported), t.memberExpression(target, node.local)) + t.assignmentExpression("=", t.memberExpression(exportObjRef, node.exported), + t.memberExpression(target, node.local)) )); } else { // todo @@ -279,33 +280,35 @@ export default function ({ types: t }) { } if (variableIds.length) { - beforeBody.unshift(t.variableDeclaration("var", variableIds.map((id) => t.variableDeclarator(id)))); + beforeBody.unshift(t.variableDeclaration("var", + variableIds.map((id) => t.variableDeclarator(id)))); } path.traverse(reassignmentVisitor, { exports: exportNames, buildCall: buildExportCall, - scope: path.scope + scope: path.scope, }); - for (let path of removedPaths) { + for (const path of removedPaths) { path.remove(); } path.node.body = [ buildTemplate({ - SYSTEM_REGISTER: t.memberExpression(t.identifier(state.opts.systemGlobal || "System"), t.identifier("register")), + SYSTEM_REGISTER: t.memberExpression( + t.identifier(state.opts.systemGlobal || "System"), t.identifier("register")), BEFORE_BODY: beforeBody, MODULE_NAME: moduleName, SETTERS: setters, SOURCES: sources, BODY: path.node.body, EXPORT_IDENTIFIER: exportIdent, - CONTEXT_IDENTIFIER: contextIdent - }) + CONTEXT_IDENTIFIER: contextIdent, + }), ]; - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/test/index.js b/packages/babel-plugin-transform-es2015-modules-systemjs/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-modules-systemjs/test/index.js +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-modules-umd/README.md b/packages/babel-plugin-transform-es2015-modules-umd/README.md index 31fc415480..fe32773781 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/README.md +++ b/packages/babel-plugin-transform-es2015-modules-umd/README.md @@ -110,7 +110,7 @@ factory(global.fooBAR, global.fooBAR); because again the transform is only using the basename of the import. _Second_, the specified override will still be passed to the `toIdentifier` -function in [babel-types/src/converters](../babel-types/src/converters.js). +function in [babel-types/src/converters](https://github.com/babel/babel/blob/master/packages/babel-types/src/converters.js). This means that if you specify an override as a member expression like: ```json diff --git a/packages/babel-plugin-transform-es2015-modules-umd/package.json b/packages/babel-plugin-transform-es2015-modules-umd/package.json index a41001b674..b48322db93 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/package.json +++ b/packages/babel-plugin-transform-es2015-modules-umd/package.json @@ -1,19 +1,18 @@ { "name": "babel-plugin-transform-es2015-modules-umd", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin transforms ES2015 modules to UMD", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-modules-umd", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-es2015-modules-amd": "^6.18.0", - "babel-template": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-transform-es2015-modules-amd": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-modules-umd/src/index.js b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js index 44b88ee55d..72fd6fe7a5 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js @@ -1,20 +1,19 @@ -/* eslint max-len: 0 */ - import { basename, extname } from "path"; import template from "babel-template"; +import transformAMD from "babel-plugin-transform-es2015-modules-amd"; -let buildPrerequisiteAssignment = template(` +const buildPrerequisiteAssignment = template(` GLOBAL_REFERENCE = GLOBAL_REFERENCE || {} `); -let buildGlobalExport = template(` +const buildGlobalExport = template(` var mod = { exports: {} }; factory(BROWSER_ARGUMENTS); PREREQUISITE_ASSIGNMENTS GLOBAL_TO_ASSIGN = mod.exports; `); -let buildWrapper = template(` +const buildWrapper = template(` (function (global, factory) { if (typeof define === "function" && define.amd) { define(MODULE_NAME, AMD_ARGUMENTS, factory); @@ -30,11 +29,11 @@ export default function ({ types: t }) { function isValidDefine(path) { if (!path.isExpressionStatement()) return; - let expr = path.get("expression"); + const expr = path.get("expression"); if (!expr.isCallExpression()) return false; if (!expr.get("callee").isIdentifier({ name: "define" })) return false; - let args = expr.get("arguments"); + const args = expr.get("arguments"); if (args.length === 3 && !args.shift().isStringLiteral()) return false; if (args.length !== 2) return false; if (!args.shift().isArrayExpression()) return false; @@ -44,23 +43,23 @@ export default function ({ types: t }) { } return { - inherits: require("babel-plugin-transform-es2015-modules-amd"), + inherits: transformAMD, visitor: { Program: { exit(path, state) { - let last = path.get("body").pop(); + const last = path.get("body").pop(); if (!isValidDefine(last)) return; - let call = last.node.expression; - let args = call.arguments; + const call = last.node.expression; + const args = call.arguments; - let moduleName = args.length === 3 ? args.shift() : null; - let amdArgs = call.arguments[0]; - let func = call.arguments[1]; - let browserGlobals = state.opts.globals || {}; + const moduleName = args.length === 3 ? args.shift() : null; + const amdArgs = call.arguments[0]; + const func = call.arguments[1]; + const browserGlobals = state.opts.globals || {}; - let commonArgs = amdArgs.elements.map((arg) => { + const commonArgs = amdArgs.elements.map((arg) => { if (arg.value === "module" || arg.value === "exports") { return t.identifier(arg.value); } else { @@ -68,7 +67,7 @@ export default function ({ types: t }) { } }); - let browserArgs = amdArgs.elements.map((arg) => { + const browserArgs = amdArgs.elements.map((arg) => { if (arg.value === "module") { return t.identifier("mod"); } else if (arg.value === "exports") { @@ -77,7 +76,7 @@ export default function ({ types: t }) { let memberExpression; if (state.opts.exactGlobals) { - let globalRef = browserGlobals[arg.value]; + const globalRef = browserGlobals[arg.value]; if (globalRef) { memberExpression = globalRef.split(".").reduce( (accum, curr) => t.memberExpression(accum, t.identifier(curr)), t.identifier("global") @@ -88,8 +87,8 @@ export default function ({ types: t }) { ); } } else { - let requireName = basename(arg.value, extname(arg.value)); - let globalName = browserGlobals[requireName] || requireName; + const requireName = basename(arg.value, extname(arg.value)); + const globalName = browserGlobals[requireName] || requireName; memberExpression = t.memberExpression( t.identifier("global"), t.identifier(t.toIdentifier(globalName)) ); @@ -99,19 +98,19 @@ export default function ({ types: t }) { } }); - let moduleNameOrBasename = moduleName ? moduleName.value : this.file.opts.basename; + const moduleNameOrBasename = moduleName ? moduleName.value : this.file.opts.basename; let globalToAssign = t.memberExpression( t.identifier("global"), t.identifier(t.toIdentifier(moduleNameOrBasename)) ); let prerequisiteAssignments = null; if (state.opts.exactGlobals) { - let globalName = browserGlobals[moduleNameOrBasename]; + const globalName = browserGlobals[moduleNameOrBasename]; if (globalName) { prerequisiteAssignments = []; - let members = globalName.split("."); + const members = globalName.split("."); globalToAssign = members.slice(1).reduce((accum, curr) => { prerequisiteAssignments.push(buildPrerequisiteAssignment({ GLOBAL_REFERENCE: accum })); return t.memberExpression(accum, t.identifier(curr)); @@ -119,10 +118,10 @@ export default function ({ types: t }) { } } - let globalExport = buildGlobalExport({ + const globalExport = buildGlobalExport({ BROWSER_ARGUMENTS: browserArgs, PREREQUISITE_ASSIGNMENTS: prerequisiteAssignments, - GLOBAL_TO_ASSIGN: globalToAssign + GLOBAL_TO_ASSIGN: globalToAssign, }); last.replaceWith(buildWrapper({ @@ -130,10 +129,10 @@ export default function ({ types: t }) { AMD_ARGUMENTS: amdArgs, COMMON_ARGUMENTS: commonArgs, GLOBAL_EXPORT: globalExport, - FUNC: func + FUNC: func, })); - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-modules-umd/test/index.js b/packages/babel-plugin-transform-es2015-modules-umd/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-modules-umd/test/index.js +++ b/packages/babel-plugin-transform-es2015-modules-umd/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-object-super/package.json b/packages/babel-plugin-transform-es2015-object-super/package.json index a9e61b0cb1..4de65e9bb5 100644 --- a/packages/babel-plugin-transform-es2015-object-super/package.json +++ b/packages/babel-plugin-transform-es2015-object-super/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-object-super", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 object super to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-object-super", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-helper-replace-supers": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-helper-replace-supers": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-object-super/src/index.js b/packages/babel-plugin-transform-es2015-object-super/src/index.js index 95098fda8a..dd47816a7d 100644 --- a/packages/babel-plugin-transform-es2015-object-super/src/index.js +++ b/packages/babel-plugin-transform-es2015-object-super/src/index.js @@ -2,24 +2,24 @@ import ReplaceSupers from "babel-helper-replace-supers"; export default function ({ types: t }) { function Property(path, node, scope, getObjectRef, file) { - let replaceSupers = new ReplaceSupers({ + const replaceSupers = new ReplaceSupers({ getObjectRef: getObjectRef, - methodNode: node, - methodPath: path, - isStatic: true, - scope: scope, - file: file + methodNode: node, + methodPath: path, + isStatic: true, + scope: scope, + file: file, }); replaceSupers.replace(); } - let CONTAINS_SUPER = Symbol(); + const CONTAINS_SUPER = Symbol(); return { visitor: { Super(path) { - let parentObj = path.findParent((path) => path.isObjectExpression()); + const parentObj = path.findParent((path) => path.isObjectExpression()); if (parentObj) parentObj.node[CONTAINS_SUPER] = true; }, @@ -28,9 +28,9 @@ export default function ({ types: t }) { if (!path.node[CONTAINS_SUPER]) return; let objectRef; - let getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj"); + const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj"); - let propPaths: Array = path.get("properties"); + const propPaths: Array = path.get("properties"); for (let propPath of propPaths) { if (propPath.isObjectProperty()) propPath = propPath.get("value"); Property(propPath, propPath.node, path.scope, getObjectRef, file); @@ -40,8 +40,8 @@ export default function ({ types: t }) { path.scope.push({ id: objectRef }); path.replaceWith(t.assignmentExpression("=", objectRef, path.node)); } - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-object-super/test/index.js b/packages/babel-plugin-transform-es2015-object-super/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-object-super/test/index.js +++ b/packages/babel-plugin-transform-es2015-object-super/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-parameters/README.md b/packages/babel-plugin-transform-es2015-parameters/README.md index bd55bbc350..5c52e0c0c8 100644 --- a/packages/babel-plugin-transform-es2015-parameters/README.md +++ b/packages/babel-plugin-transform-es2015-parameters/README.md @@ -2,6 +2,12 @@ > Compile ES2015 default and rest parameters to ES5 +This plugin transforms ES2015 parameters to ES5, this includes: + +- Destructuring parameters +- Default parameters +- Rest parameters + ## Installation ```sh diff --git a/packages/babel-plugin-transform-es2015-parameters/package.json b/packages/babel-plugin-transform-es2015-parameters/package.json index 9b3ede5825..6347fdbf67 100644 --- a/packages/babel-plugin-transform-es2015-parameters/package.json +++ b/packages/babel-plugin-transform-es2015-parameters/package.json @@ -1,22 +1,21 @@ { "name": "babel-plugin-transform-es2015-parameters", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 default and rest parameters to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-parameters", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-traverse": "^6.21.0", - "babel-helper-call-delegate": "^6.18.0", - "babel-helper-get-function-arity": "^6.18.0", - "babel-template": "^6.16.0", - "babel-types": "^6.21.0", - "babel-runtime": "^6.9.0" + "babel-traverse": "7.0.0-alpha.1", + "babel-helper-call-delegate": "7.0.0-alpha.1", + "babel-helper-get-function-arity": "7.0.0-alpha.1", + "babel-template": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" }, "keywords": [ "babel-plugin" ], "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-parameters/src/default.js b/packages/babel-plugin-transform-es2015-parameters/src/default.js index 445000fadb..6b0d728f5e 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/default.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/default.js @@ -1,11 +1,9 @@ -/* eslint max-len: 0 */ - import getFunctionArity from "babel-helper-get-function-arity"; import callDelegate from "babel-helper-call-delegate"; import template from "babel-template"; import * as t from "babel-types"; -let buildDefaultParam = template(` +const buildDefaultParam = template(` let VARIABLE_NAME = ARGUMENTS.length > ARGUMENT_KEY && ARGUMENTS[ARGUMENT_KEY] !== undefined ? ARGUMENTS[ARGUMENT_KEY] @@ -13,12 +11,12 @@ let buildDefaultParam = template(` DEFAULT_VALUE; `); -let buildCutOff = template(` +const buildCutOff = template(` let $0 = $1[$2]; `); function hasDefaults(node) { - for (let param of (node.params: Array)) { + for (const param of (node.params: Array)) { if (!t.isIdentifier(param)) return true; } return false; @@ -30,7 +28,7 @@ function isSafeBinding(scope, node) { return kind === "param" || kind === "local"; } -let iifeVisitor = { +const iifeVisitor = { ReferencedIdentifier(path, state) { const { scope, node } = path; if (node.name === "eval" || !isSafeBinding(scope, node)) { @@ -42,26 +40,26 @@ let iifeVisitor = { Scope(path) { // different bindings path.skip(); - } + }, }; -export let visitor = { +export const visitor = { Function(path) { - let { node, scope } = path; + const { node, scope } = path; if (!hasDefaults(node)) return; // ensure it's a block, useful for arrow functions path.ensureBlock(); - let state = { + const state = { iife: false, - scope: scope + scope: scope, }; - let body = []; + const body = []; // - let argsIdentifier = t.identifier("arguments"); + const argsIdentifier = t.identifier("arguments"); argsIdentifier._shadowedFunctionLiteral = path; // push a default parameter definition @@ -69,20 +67,20 @@ export let visitor = { const defNode = buildDefaultParam({ VARIABLE_NAME: left, DEFAULT_VALUE: right, - ARGUMENT_KEY: t.numericLiteral(i), - ARGUMENTS: argsIdentifier + ARGUMENT_KEY: t.numericLiteral(i), + ARGUMENTS: argsIdentifier, }); defNode._blockHoist = node.params.length - i; body.push(defNode); } // - let lastNonDefaultParam = getFunctionArity(node); + const lastNonDefaultParam = getFunctionArity(node); // - let params = path.get("params"); + const params = path.get("params"); for (let i = 0; i < params.length; i++) { - let param = params[i]; + const param = params[i]; if (!param.isAssignmentPattern()) { if (!state.iife && !param.isIdentifier()) { @@ -92,12 +90,12 @@ export let visitor = { continue; } - let left = param.get("left"); - let right = param.get("right"); + const left = param.get("left"); + const right = param.get("right"); // if (i >= lastNonDefaultParam || left.isPattern()) { - let placeholder = scope.generateUidIdentifier("x"); + const placeholder = scope.generateUidIdentifier("x"); placeholder._isDefaultPlaceholder = true; node.params[i] = placeholder; } else { @@ -119,10 +117,10 @@ export let visitor = { // add declarations for trailing parameters for (let i = lastNonDefaultParam + 1; i < node.params.length; i++) { - let param = node.params[i]; + const param = node.params[i]; if (param._isDefaultPlaceholder) continue; - let declar = buildCutOff(param, argsIdentifier, t.numericLiteral(i)); + const declar = buildCutOff(param, argsIdentifier, t.numericLiteral(i)); declar._blockHoist = node.params.length - i; body.push(declar); } @@ -136,5 +134,5 @@ export let visitor = { } else { path.get("body").unshiftContainer("body", body); } - } + }, }; diff --git a/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js index e3a7e10494..c40db2dac9 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js @@ -1,21 +1,21 @@ import * as t from "babel-types"; -export let visitor = { +export const visitor = { Function(path) { - let params: Array = path.get("params"); + const params: Array = path.get("params"); // If there's a rest param, no need to loop through it. Also, we need to // hoist one more level to get `declar` at the right spot. - let hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0; - let outputParamsLength = params.length - hoistTweak; + const hoistTweak = t.isRestElement(params[params.length - 1]) ? 1 : 0; + const outputParamsLength = params.length - hoistTweak; for (let i = 0; i < outputParamsLength; i++) { - let param = params[i]; + const param = params[i]; if (param.isArrayPattern() || param.isObjectPattern()) { - let uid = path.scope.generateUidIdentifier("ref"); + const uid = path.scope.generateUidIdentifier("ref"); - let declar = t.variableDeclaration("let", [ - t.variableDeclarator(param.node, uid) + const declar = t.variableDeclaration("let", [ + t.variableDeclarator(param.node, uid), ]); declar._blockHoist = outputParamsLength - i; @@ -25,5 +25,5 @@ export let visitor = { param.replaceWith(uid); } } - } + }, }; diff --git a/packages/babel-plugin-transform-es2015-parameters/src/index.js b/packages/babel-plugin-transform-es2015-parameters/src/index.js index 6279147062..c3321d35c3 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/index.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/index.js @@ -10,14 +10,14 @@ export default function () { visitor: visitors.merge([{ ArrowFunctionExpression(path) { // default/rest visitors require access to `arguments` - let params: Array = path.get("params"); - for (let param of params) { + const params: Array = path.get("params"); + for (const param of params) { if (param.isRestElement() || param.isAssignmentPattern()) { path.arrowFunctionToShadowed(); break; } } - } - }, destructuring.visitor, rest.visitor, def.visitor]) + }, + }, destructuring.visitor, rest.visitor, def.visitor]), }; } diff --git a/packages/babel-plugin-transform-es2015-parameters/src/rest.js b/packages/babel-plugin-transform-es2015-parameters/src/rest.js index bda77d8c11..f0171ed443 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/rest.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/rest.js @@ -1,9 +1,7 @@ -/* eslint indent: 0 */ - import template from "babel-template"; import * as t from "babel-types"; -let buildRest = template(` +const buildRest = template(` for (var LEN = ARGUMENTS.length, ARRAY = Array(ARRAY_LEN), KEY = START; @@ -13,19 +11,19 @@ let buildRest = template(` } `); -let restIndex = template(` +const restIndex = template(` ARGUMENTS.length <= INDEX ? undefined : ARGUMENTS[INDEX] `); -let restIndexImpure = template(` +const restIndexImpure = template(` REF = INDEX, ARGUMENTS.length <= REF ? undefined : ARGUMENTS[REF] `); -let restLength = template(` +const restLength = template(` ARGUMENTS.length <= OFFSET ? 0 : ARGUMENTS.length - OFFSET `); -let memberExpressionOptimisationVisitor = { +const memberExpressionOptimisationVisitor = { Scope(path, state) { // check if this scope has a local binding that will shadow the rest parameter if (!path.scope.bindingIdentifierEquals(state.name, state.outerBinding)) { @@ -43,7 +41,7 @@ let memberExpressionOptimisationVisitor = { "Function|ClassProperty": function (path, state) { // Detect whether any reference to rest is contained in nested functions to // determine if deopt is necessary. - let oldNoOptimise = state.noOptimise; + const oldNoOptimise = state.noOptimise; state.noOptimise = true; path.traverse(memberExpressionOptimisationVisitor, state); state.noOptimise = oldNoOptimise; @@ -54,7 +52,7 @@ let memberExpressionOptimisationVisitor = { }, ReferencedIdentifier(path, state) { - let { node } = path; + const { node } = path; // we can't guarantee the purity of arguments if (node.name === "arguments") { @@ -67,7 +65,7 @@ let memberExpressionOptimisationVisitor = { if (state.noOptimise) { state.deopted = true; } else { - let {parentPath} = path; + const { parentPath } = path; // Is this identifier the right hand side of a default parameter? if (parentPath.listKey === "params" && parentPath.key < state.offset) { @@ -77,9 +75,9 @@ let memberExpressionOptimisationVisitor = { // ex: `args[0]` // ex: `args.whatever` if (parentPath.isMemberExpression({ object: node })) { - let grandparentPath = parentPath.parentPath; + const grandparentPath = parentPath.parentPath; - let argsOptEligible = !state.deopted && !( + const argsOptEligible = !state.deopted && !( // ex: `args[0] = "whatever"` ( grandparentPath.isAssignmentExpression() && @@ -117,13 +115,13 @@ let memberExpressionOptimisationVisitor = { // if we know that this member expression is referencing a number then // we can safely optimise it if (parentPath.get("property").isBaseType("number")) { - state.candidates.push({cause: "indexGetter", path}); + state.candidates.push({ cause: "indexGetter", path }); return; } } // args.length else if (parentPath.node.property.name === "length") { - state.candidates.push({cause: "lengthGetter", path}); + state.candidates.push({ cause: "lengthGetter", path }); return; } } @@ -134,9 +132,9 @@ let memberExpressionOptimisationVisitor = { // optimise single spread args in calls // ex: fn(...args) if (state.offset === 0 && parentPath.isSpreadElement()) { - let call = parentPath.parentPath; + const call = parentPath.parentPath; if (call.isCallExpression() && call.node.arguments.length === 1) { - state.candidates.push({cause: "argSpread", path}); + state.candidates.push({ cause: "argSpread", path }); return; } } @@ -155,7 +153,7 @@ let memberExpressionOptimisationVisitor = { if (node.name === state.name) { state.deopted = true; } - } + }, }; function hasRest(node) { return t.isRestElement(node.params[node.params.length - 1]); @@ -175,12 +173,12 @@ function optimiseIndexGetter(path, argsId, offset) { const { scope } = path; if (!scope.isPure(index)) { - let temp = scope.generateUidIdentifierBasedOnNode(index); - scope.push({id: temp, kind: "var"}); + const temp = scope.generateUidIdentifierBasedOnNode(index); + scope.push({ id: temp, kind: "var" }); path.parentPath.replaceWith(restIndexImpure({ ARGUMENTS: argsId, INDEX: index, - REF: temp + REF: temp, })); } else { path.parentPath.replaceWith(restIndex({ @@ -201,25 +199,25 @@ function optimiseLengthGetter(path, argsId, offset) { } } -export let visitor = { +export const visitor = { Function(path) { - let { node, scope } = path; + const { node, scope } = path; if (!hasRest(node)) return; - let rest = node.params.pop().argument; + const rest = node.params.pop().argument; - let argsId = t.identifier("arguments"); + const argsId = t.identifier("arguments"); // otherwise `arguments` will be remapped in arrow functions argsId._shadowedFunctionLiteral = path; // check and optimise for extremely common cases - let state = { + const state = { references: [], - offset: node.params.length, + offset: node.params.length, argumentsNode: argsId, - outerBinding: scope.getBindingIdentifier(rest.name), + outerBinding: scope.getBindingIdentifier(rest.name), // candidate member expressions we could optimise if there are no other references candidates: [], @@ -246,7 +244,7 @@ export let visitor = { // There are only "shorthand" references if (!state.deopted && !state.references.length) { - for (let {path, cause} of (state.candidates: Array)) { + for (const { path, cause } of (state.candidates: Array)) { switch (cause) { case "indexGetter": optimiseIndexGetter(path, argsId, state.offset); @@ -268,9 +266,9 @@ export let visitor = { // deopt shadowed functions as transforms like regenerator may try touch the allocation loop state.deopted = state.deopted || !!node.shadow; - let start = t.numericLiteral(node.params.length); - let key = scope.generateUidIdentifier("key"); - let len = scope.generateUidIdentifier("len"); + const start = t.numericLiteral(node.params.length); + const key = scope.generateUidIdentifier("key"); + const len = scope.generateUidIdentifier("len"); let arrKey = key; let arrLen = len; @@ -293,14 +291,14 @@ export let visitor = { ); } - let loop = buildRest({ + const loop = buildRest({ ARGUMENTS: argsId, ARRAY_KEY: arrKey, ARRAY_LEN: arrLen, - START: start, - ARRAY: rest, - KEY: key, - LEN: len, + START: start, + ARRAY: rest, + KEY: key, + LEN: len, }); if (state.deopted) { @@ -324,5 +322,5 @@ export let visitor = { target.insertBefore(loop); } - } + }, }; diff --git a/packages/babel-plugin-transform-es2015-parameters/test/index.js b/packages/babel-plugin-transform-es2015-parameters/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-parameters/test/index.js +++ b/packages/babel-plugin-transform-es2015-parameters/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/README.md b/packages/babel-plugin-transform-es2015-shorthand-properties/README.md index 171aa1ead7..95c87e2fa3 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/README.md +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/README.md @@ -13,7 +13,7 @@ var o = { a, b, c }; **Out** ```js -var o = { a: a, b: b, c:c }; +var o = { a: a, b: b, c: c }; ``` **In** diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json index 34d8b72f7e..d7e7ada681 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-shorthand-properties", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 shorthand properties to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-shorthand-properties", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-types": "^6.18.0", - "babel-runtime": "^6.0.0" + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js index c3aa80e4f5..fdf4c17fda 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js @@ -4,7 +4,7 @@ export default function () { return { visitor: { ObjectMethod(path) { - let { node } = path; + const { node } = path; if (node.kind === "method") { const func = t.functionExpression(null, node.params, node.body, node.generator, node.async); func.returnType = node.returnType; @@ -21,7 +21,7 @@ export default function () { if (node.shorthand) { node.shorthand = false; } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/test/index.js b/packages/babel-plugin-transform-es2015-shorthand-properties/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/test/index.js +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-spread/README.md b/packages/babel-plugin-transform-es2015-spread/README.md index 9d0e16629d..e33a1db7cf 100644 --- a/packages/babel-plugin-transform-es2015-spread/README.md +++ b/packages/babel-plugin-transform-es2015-spread/README.md @@ -2,6 +2,40 @@ > Compile ES2015 spread to ES5 +## Example + +**In** + +```js +var a = ['a', 'b', 'c']; +var b = [...a, 'foo']; + +var c = { foo: 'bar', baz: 42 }; +var d = {...c, a: 2}; +``` + +**Out** + +```js +var _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; +} + +var a = [ 'a', 'b', 'c' ]; +var b = [].concat(a, [ 'foo' ]); + +var c = { foo: 'bar', baz: 42 }; +var d = _extends({}, c, { a: 2 }); +``` + ## Installation ```sh @@ -14,13 +48,17 @@ npm install --save-dev babel-plugin-transform-es2015-spread **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-es2015-spread"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-spread", { @@ -46,4 +84,8 @@ require("babel-core").transform("code", { ## Options -* `loose` - All iterables are assumed to be arrays. +### `loose` + +`boolean`, defaults to `false`. + +In loose mode, **all** iterables are assumed to be arrays. diff --git a/packages/babel-plugin-transform-es2015-spread/package.json b/packages/babel-plugin-transform-es2015-spread/package.json index f2809d2374..9855e702f5 100644 --- a/packages/babel-plugin-transform-es2015-spread/package.json +++ b/packages/babel-plugin-transform-es2015-spread/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-spread", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 spread to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-spread", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-spread/src/index.js b/packages/babel-plugin-transform-es2015-spread/src/index.js index d7768cb161..d533d484b5 100644 --- a/packages/babel-plugin-transform-es2015-spread/src/index.js +++ b/packages/babel-plugin-transform-es2015-spread/src/index.js @@ -17,7 +17,7 @@ export default function ({ types: t }) { } function build(props: Array, scope, state) { - let nodes = []; + const nodes = []; let _props = []; @@ -27,7 +27,7 @@ export default function ({ types: t }) { _props = []; } - for (let prop of props) { + for (const prop of props) { if (t.isSpreadElement(prop)) { push(); nodes.push(getSpreadLiteral(prop, scope, state)); @@ -44,11 +44,11 @@ export default function ({ types: t }) { return { visitor: { ArrayExpression(path, state) { - let { node, scope } = path; - let elements = node.elements; + const { node, scope } = path; + const elements = node.elements; if (!hasSpread(elements)) return; - let nodes = build(elements, scope, state); + const nodes = build(elements, scope, state); let first = nodes.shift(); if (!t.isArrayExpression(first)) { @@ -60,12 +60,12 @@ export default function ({ types: t }) { }, CallExpression(path, state) { - let { node, scope } = path; + const { node, scope } = path; - let args = node.arguments; + const args = node.arguments; if (!hasSpread(args)) return; - let calleePath = path.get("callee"); + const calleePath = path.get("callee"); if (calleePath.isSuper()) return; let contextLiteral = t.identifier("undefined"); @@ -79,17 +79,17 @@ export default function ({ types: t }) { nodes = build(args, scope, state); } - let first = nodes.shift(); + const first = nodes.shift(); if (nodes.length) { node.arguments.push(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes)); } else { node.arguments.push(first); } - let callee = node.callee; + const callee = node.callee; if (calleePath.isMemberExpression()) { - let temp = scope.maybeGenerateMemoised(callee.object); + const temp = scope.maybeGenerateMemoised(callee.object); if (temp) { callee.object = t.assignmentExpression("=", temp, callee.object); contextLiteral = temp; @@ -109,13 +109,13 @@ export default function ({ types: t }) { }, NewExpression(path, state) { - let { node, scope } = path; + const { node, scope } = path; let args = node.arguments; if (!hasSpread(args)) return; - let nodes = build(args, scope, state); + const nodes = build(args, scope, state); - let context = t.arrayExpression([t.nullLiteral()]); + const context = t.arrayExpression([t.nullLiteral()]); args = t.callExpression(t.memberExpression(context, t.identifier("concat")), nodes); @@ -136,7 +136,7 @@ export default function ({ types: t }) { ), [] )); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-spread/test/index.js b/packages/babel-plugin-transform-es2015-spread/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-spread/test/index.js +++ b/packages/babel-plugin-transform-es2015-spread/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/package.json b/packages/babel-plugin-transform-es2015-sticky-regex/package.json index 2903d76e48..b8a0342172 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/package.json +++ b/packages/babel-plugin-transform-es2015-sticky-regex/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-sticky-regex", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 sticky regex to an ES5 RegExp constructor", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-sticky-regex", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-helper-regex": "^6.8.0", - "babel-types": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-helper-regex": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js b/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js index 8b703e85c8..0798fa002b 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js +++ b/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js @@ -5,14 +5,14 @@ export default function () { return { visitor: { RegExpLiteral(path) { - let { node } = path; + const { node } = path; if (!regex.is(node, "y")) return; path.replaceWith(t.newExpression(t.identifier("RegExp"), [ t.stringLiteral(node.pattern), - t.stringLiteral(node.flags) + t.stringLiteral(node.flags), ])); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/test/index.js b/packages/babel-plugin-transform-es2015-sticky-regex/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/test/index.js +++ b/packages/babel-plugin-transform-es2015-sticky-regex/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-template-literals/README.md b/packages/babel-plugin-transform-es2015-template-literals/README.md index 854bc74be6..477b11cce6 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/README.md +++ b/packages/babel-plugin-transform-es2015-template-literals/README.md @@ -28,13 +28,17 @@ npm install --save-dev babel-plugin-transform-es2015-template-literals **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-es2015-template-literals"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-es2015-template-literals", { @@ -62,10 +66,15 @@ require("babel-core").transform("code", { ## Options ### `loose` + +`boolean`, defaults to `false`. + In loose mode, tagged template literal objects aren't frozen. - ### `spec` + +`boolean`, defaults to `false`. + This option wraps all template literal expressions with `String`. See [babel/babel#1065](https://github.com/babel/babel/issues/1065) for more info. **In** diff --git a/packages/babel-plugin-transform-es2015-template-literals/package.json b/packages/babel-plugin-transform-es2015-template-literals/package.json index 5791baed70..39072ab9ce 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/package.json +++ b/packages/babel-plugin-transform-es2015-template-literals/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-template-literals", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 template literals to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-template-literals", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-template-literals/src/index.js b/packages/babel-plugin-transform-es2015-template-literals/src/index.js index 7359598f99..8743c990da 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/src/index.js +++ b/packages/babel-plugin-transform-es2015-template-literals/src/index.js @@ -10,14 +10,14 @@ export default function ({ types: t }) { return { visitor: { TaggedTemplateExpression(path, state) { - let { node } = path; - let quasi = node.quasi; - let args = []; + const { node } = path; + const quasi = node.quasi; + let args = []; let strings = []; - let raw = []; + let raw = []; - for (let elem of (quasi.quasis: Array)) { + for (const elem of (quasi.quasis: Array)) { strings.push(t.stringLiteral(elem.value.cooked)); raw.push(t.stringLiteral(elem.value.raw)); } @@ -28,7 +28,7 @@ export default function ({ types: t }) { let templateName = "taggedTemplateLiteral"; if (state.opts.loose) templateName += "Loose"; - let templateObject = state.file.addTemplateObject(templateName, strings, raw); + const templateObject = state.file.addTemplateObject(templateName, strings, raw); args.push(templateObject); args = args.concat(quasi.expressions); @@ -39,14 +39,14 @@ export default function ({ types: t }) { TemplateLiteral(path, state) { let nodes: Array = []; - let expressions = path.get("expressions"); + const expressions = path.get("expressions"); - for (let elem of (path.node.quasis: Array)) { + for (const elem of (path.node.quasis: Array)) { nodes.push(t.stringLiteral(elem.value.cooked)); - let expr = expressions.shift(); + const expr = expressions.shift(); if (expr) { - if (state.opts.spec && !expr.isBaseType("string") && !expr.isBaseType("number")) { + if (state.opts.spec && !expr.isBaseType("string") && !expr.isBaseType("number")) { nodes.push(t.callExpression(t.identifier("String"), [expr.node])); } else { nodes.push(expr.node); @@ -66,7 +66,7 @@ export default function ({ types: t }) { if (nodes.length > 1) { let root = buildBinaryExpression(nodes.shift(), nodes.shift()); - for (let node of nodes) { + for (const node of nodes) { root = buildBinaryExpression(root, node); } @@ -74,7 +74,7 @@ export default function ({ types: t }) { } else { path.replaceWith(nodes[0]); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-template-literals/test/index.js b/packages/babel-plugin-transform-es2015-template-literals/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/test/index.js +++ b/packages/babel-plugin-transform-es2015-template-literals/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/README.md b/packages/babel-plugin-transform-es2015-typeof-symbol/README.md index 53b9236ab3..92a7d2d61c 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/README.md +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/README.md @@ -1,6 +1,6 @@ # babel-plugin-transform-es2015-typeof-symbol -> ES6 introduces a new native type called [symbols](http://babeljs.io/docs/learn-es6#symbols). This transformer wraps all `typeof` expressions with a method that replicates native behaviour. (ie. returning "symbol" for symbols) +> ES6 introduces a new native type called [symbols](https://babeljs.io/learn-es2015/#ecmascript-2015-features-symbols). This transformer wraps all `typeof` expressions with a method that replicates native behaviour. (ie. returning "symbol" for symbols) ## Example diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/package.json b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json index ba886f993f..99caefcdb5 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/package.json +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-typeof-symbol", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This transformer wraps all typeof expressions with a method that replicates native behaviour. (ie. returning “symbol” for symbols)", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-typeof-symbol", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js index b2291af302..d5d7ae067d 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js @@ -1,7 +1,5 @@ -/* eslint max-len: 0 */ - export default function ({ types: t }) { - let IGNORE = Symbol(); + const IGNORE = Symbol(); return { visitor: { @@ -14,23 +12,30 @@ export default function ({ types: t }) { }, UnaryExpression(path) { - let { node, parent } = path; + const { node, parent } = path; if (node[IGNORE]) return; if (path.find((path) => path.node && !!path.node._generated)) return; - if (path.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) { - // optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols - let opposite = path.getOpposite(); - if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") { + if ( + path.parentPath.isBinaryExpression() && + t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0 + ) { + // optimise `typeof foo === "string"` since we can determine that they'll never + // need to handle symbols + const opposite = path.getOpposite(); + if ( + opposite.isLiteral() && opposite.node.value !== "symbol" && + opposite.node.value !== "object" + ) { return; } } if (node.operator === "typeof") { - let call = t.callExpression(this.addHelper("typeof"), [node.argument]); + const call = t.callExpression(this.addHelper("typeof"), [node.argument]); if (path.get("argument").isIdentifier()) { - let undefLiteral = t.stringLiteral("undefined"); - let unary = t.unaryExpression("typeof", node.argument); + const undefLiteral = t.stringLiteral("undefined"); + const unary = t.unaryExpression("typeof", node.argument); unary[IGNORE] = true; path.replaceWith(t.conditionalExpression( t.binaryExpression("===", unary, undefLiteral), @@ -41,7 +46,7 @@ export default function ({ types: t }) { path.replaceWith(call); } } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/test/index.js b/packages/babel-plugin-transform-es2015-typeof-symbol/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-typeof-symbol/test/index.js +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/package.json b/packages/babel-plugin-transform-es2015-unicode-regex/package.json index 4872b046a5..502acb965e 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/package.json +++ b/packages/babel-plugin-transform-es2015-unicode-regex/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es2015-unicode-regex", - "version": "6.11.0", + "version": "7.0.0-alpha.1", "description": "Compile ES2015 Unicode regex to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-unicode-regex", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-helper-regex": "^6.8.0", - "babel-runtime": "^6.0.0", - "regexpu-core": "^2.0.0" + "babel-helper-regex": "7.0.0-alpha.1", + "regexpu-core": "^4.0.2" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js b/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js index e659945dfa..0e537eeb5b 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js +++ b/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js @@ -8,7 +8,7 @@ export default function () { if (!regex.is(node, "u")) return; node.pattern = rewritePattern(node.pattern, node.flags); regex.pullFlag(node, "u"); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/test/index.js b/packages/babel-plugin-transform-es2015-unicode-regex/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/test/index.js +++ b/packages/babel-plugin-transform-es2015-unicode-regex/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/package.json b/packages/babel-plugin-transform-es3-member-expression-literals/package.json index 3f25880c4e..2738735d1e 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/package.json +++ b/packages/babel-plugin-transform-es3-member-expression-literals/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es3-member-expression-literals", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Ensure that reserved words are quoted in property accesses", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es3-member-expression-literals", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js b/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js index fa78563a23..ddcea660c1 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js +++ b/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js @@ -3,14 +3,14 @@ export default function ({ types: t }) { visitor: { MemberExpression: { exit({ node }) { - let prop = node.property; + const prop = node.property; if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) { // foo.default -> foo["default"] node.property = t.stringLiteral(prop.name); node.computed = true; } - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/test/index.js b/packages/babel-plugin-transform-es3-member-expression-literals/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/test/index.js +++ b/packages/babel-plugin-transform-es3-member-expression-literals/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es3-property-literals/package.json b/packages/babel-plugin-transform-es3-property-literals/package.json index 43ec94a753..66887c68fa 100644 --- a/packages/babel-plugin-transform-es3-property-literals/package.json +++ b/packages/babel-plugin-transform-es3-property-literals/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es3-property-literals", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Ensure that reserved words are quoted in object property keys", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es3-property-literals", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es3-property-literals/src/index.js b/packages/babel-plugin-transform-es3-property-literals/src/index.js index b8f6f412c2..b85cfc84a4 100644 --- a/packages/babel-plugin-transform-es3-property-literals/src/index.js +++ b/packages/babel-plugin-transform-es3-property-literals/src/index.js @@ -2,14 +2,14 @@ export default function ({ types: t }) { return { visitor: { ObjectProperty: { - exit({node}) { - let key = node.key; + exit({ node }) { + const key = node.key; if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) { // default: "bar" -> "default": "bar" node.key = t.stringLiteral(key.name); } - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-es3-property-literals/test/index.js b/packages/babel-plugin-transform-es3-property-literals/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es3-property-literals/test/index.js +++ b/packages/babel-plugin-transform-es3-property-literals/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-es5-property-mutators/package.json b/packages/babel-plugin-transform-es5-property-mutators/package.json index 9e411e0d98..2b52a92d8a 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/package.json +++ b/packages/babel-plugin-transform-es5-property-mutators/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-es5-property-mutators", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile ES5 property mutator shorthand syntax to Object.defineProperty", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es5-property-mutators", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-helper-define-map": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-helper-define-map": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-es5-property-mutators/src/index.js b/packages/babel-plugin-transform-es5-property-mutators/src/index.js index 46d810f6f5..243b690227 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/src/index.js +++ b/packages/babel-plugin-transform-es5-property-mutators/src/index.js @@ -4,9 +4,9 @@ export default function ({ types: t }) { return { visitor: { ObjectExpression(path, file) { - let { node } = path; + const { node } = path; let hasAny = false; - for (let prop of (node.properties: Array)) { + for (const prop of (node.properties: Array)) { if (prop.kind === "get" || prop.kind === "set") { hasAny = true; break; @@ -14,7 +14,7 @@ export default function ({ types: t }) { } if (!hasAny) return; - let mutatorMap = {}; + const mutatorMap = {}; node.properties = node.properties.filter(function (prop) { if (!prop.computed && (prop.kind === "get" || prop.kind === "set")) { @@ -29,7 +29,7 @@ export default function ({ types: t }) { t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), [node, defineMap.toDefineObject(mutatorMap)] )); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-es5-property-mutators/test/index.js b/packages/babel-plugin-transform-es5-property-mutators/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/test/index.js +++ b/packages/babel-plugin-transform-es5-property-mutators/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-eval/package.json b/packages/babel-plugin-transform-eval/package.json index 61a511bf0e..0420fd767c 100644 --- a/packages/babel-plugin-transform-eval/package.json +++ b/packages/babel-plugin-transform-eval/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-eval", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile eval calls with string literals", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-eval", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-eval/src/index.js b/packages/babel-plugin-transform-eval/src/index.js index 677401057a..14486299c0 100644 --- a/packages/babel-plugin-transform-eval/src/index.js +++ b/packages/babel-plugin-transform-eval/src/index.js @@ -3,17 +3,17 @@ export default function ({ parse, traverse }) { visitor: { CallExpression(path) { if (path.get("callee").isIdentifier({ name: "eval" }) && path.node.arguments.length === 1) { - let evaluate = path.get("arguments")[0].evaluate(); + const evaluate = path.get("arguments")[0].evaluate(); if (!evaluate.confident) return; - let code = evaluate.value; + const code = evaluate.value; if (typeof code !== "string") return; - let ast = parse(code); + const ast = parse(code); traverse.removeProperties(ast); return ast.program; } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-exponentiation-operator/README.md b/packages/babel-plugin-transform-exponentiation-operator/README.md index 82769d80a3..274dfe8416 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/README.md +++ b/packages/babel-plugin-transform-exponentiation-operator/README.md @@ -24,7 +24,6 @@ let b = 3; b **= 3; // same as: b = b * b * b; ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=%2F%2F%20x%20**%20y%0A%0Alet%20squared%20%3D%202%20**%202%3B%0A%2F%2F%20same%20as%3A%202%20*%202%0A%0Alet%20cubed%20%3D%202%20**%203%3B%0A%2F%2F%20same%20as%3A%202%20*%202%20*%202%0A%0A%0A%2F%2F%20x%20**%3D%20y%0A%0Alet%20a%20%3D%202%3B%0Aa%20**%3D%202%3B%0A%2F%2F%20same%20as%3A%20a%20%3D%20a%20*%20a%3B%0A%0Alet%20b%20%3D%203%3B%0Ab%20**%3D%203%3B%0A%2F%2F%20same%20as%3A%20b%20%3D%20b%20*%20b%20*%20b%3B) ## Installation diff --git a/packages/babel-plugin-transform-exponentiation-operator/package.json b/packages/babel-plugin-transform-exponentiation-operator/package.json index d50b5908d2..904ca600b1 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/package.json +++ b/packages/babel-plugin-transform-exponentiation-operator/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-exponentiation-operator", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile exponentiation operator to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator", "license": "MIT", @@ -9,11 +9,10 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-exponentiation-operator": "^6.8.0", - "babel-helper-builder-binary-assignment-operator-visitor": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-exponentiation-operator": "7.0.0-alpha.1", + "babel-helper-builder-binary-assignment-operator-visitor": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-exponentiation-operator/src/index.js b/packages/babel-plugin-transform-exponentiation-operator/src/index.js index 68d2ef8c69..8756cd81d0 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/src/index.js +++ b/packages/babel-plugin-transform-exponentiation-operator/src/index.js @@ -1,15 +1,16 @@ import build from "babel-helper-builder-binary-assignment-operator-visitor"; +import syntaxExponentiationOperator from "babel-plugin-syntax-exponentiation-operator"; export default function ({ types: t }) { return { - inherits: require("babel-plugin-syntax-exponentiation-operator"), + inherits: syntaxExponentiationOperator, visitor: build({ operator: "**", build(left, right) { return t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("pow")), [left, right]); - } - }) + }, + }), }; } diff --git a/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/regression/4403/expected.js b/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/regression/4403/expected.js index dbf2e9bdb1..32e1b04280 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/regression/4403/expected.js +++ b/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/regression/4403/expected.js @@ -1,3 +1,3 @@ var a, b; -var _ref = `${ b++ }`; +var _ref = `${b++}`; a[_ref] = Math.pow(a[_ref], 1) diff --git a/packages/babel-plugin-transform-exponentiation-operator/test/index.js b/packages/babel-plugin-transform-exponentiation-operator/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/test/index.js +++ b/packages/babel-plugin-transform-exponentiation-operator/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-export-extensions/README.md b/packages/babel-plugin-transform-export-extensions/README.md index 26f7d51278..6014dc4c53 100644 --- a/packages/babel-plugin-transform-export-extensions/README.md +++ b/packages/babel-plugin-transform-export-extensions/README.md @@ -8,7 +8,6 @@ export * as ns from 'mod'; export v from 'mod'; ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=export%20*%20as%20ns%20from%20'mod'%3B%0Aexport%20v%20from%20'mod'%3B) ## Installation diff --git a/packages/babel-plugin-transform-export-extensions/package.json b/packages/babel-plugin-transform-export-extensions/package.json index 88bb380f8e..83b20f22ff 100644 --- a/packages/babel-plugin-transform-export-extensions/package.json +++ b/packages/babel-plugin-transform-export-extensions/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-export-extensions", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile export extensions to ES2015", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-export-extensions", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-export-extensions": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-export-extensions": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-export-extensions/src/index.js b/packages/babel-plugin-transform-export-extensions/src/index.js index 6b0afad0ce..b79bfc8b8b 100644 --- a/packages/babel-plugin-transform-export-extensions/src/index.js +++ b/packages/babel-plugin-transform-export-extensions/src/index.js @@ -1,10 +1,12 @@ +import syntaxExportExtensions from "babel-plugin-syntax-export-extensions"; + export default function ({ types: t }) { function build(node, nodes, scope) { - let first = node.specifiers[0]; + const first = node.specifiers[0]; if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return; - let specifier = node.specifiers.shift(); - let uid = scope.generateUidIdentifier(specifier.exported.name); + const specifier = node.specifiers.shift(); + const uid = scope.generateUidIdentifier(specifier.exported.name); let newSpecifier; if (t.isExportNamespaceSpecifier(specifier)) { @@ -20,12 +22,12 @@ export default function ({ types: t }) { } return { - inherits: require("babel-plugin-syntax-export-extensions"), + inherits: syntaxExportExtensions, visitor: { ExportNamedDeclaration(path) { - let { node, scope } = path; - let nodes = []; + const { node, scope } = path; + const nodes = []; build(node, nodes, scope); if (!nodes.length) return; @@ -33,7 +35,7 @@ export default function ({ types: t }) { nodes.push(node); } path.replaceWithMultiple(nodes); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-export-extensions/test/index.js b/packages/babel-plugin-transform-export-extensions/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-export-extensions/test/index.js +++ b/packages/babel-plugin-transform-export-extensions/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-flow-comments/package.json b/packages/babel-plugin-transform-flow-comments/package.json index 39ab99a2f2..54aad70219 100644 --- a/packages/babel-plugin-transform-flow-comments/package.json +++ b/packages/babel-plugin-transform-flow-comments/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-flow-comments", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Turn flow type annotations into comments", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-flow-comments", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-plugin-syntax-flow": "^6.8.0" + "babel-plugin-syntax-flow": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-flow-comments/src/index.js b/packages/babel-plugin-transform-flow-comments/src/index.js index ece00a024a..05676fc825 100644 --- a/packages/babel-plugin-transform-flow-comments/src/index.js +++ b/packages/babel-plugin-transform-flow-comments/src/index.js @@ -1,3 +1,5 @@ +import syntaxFlow from "babel-plugin-syntax-flow"; + export default function ({ types: t }) { function wrapInFlowComment(path, parent) { path.addComment("trailing", generateComment(path, parent)); @@ -12,18 +14,18 @@ export default function ({ types: t }) { } return { - inherits: require("babel-plugin-syntax-flow"), + inherits: syntaxFlow, visitor: { TypeCastExpression(path) { - let { node } = path; + const { node } = path; path.get("expression").addComment("trailing", generateComment(path.get("typeAnnotation"))); path.replaceWith(t.parenthesizedExpression(node.expression)); }, // support function a(b?) {} Identifier(path) { - let { node } = path; + const { node } = path; if (!node.optional || node.typeAnnotation) { return; } @@ -33,25 +35,25 @@ export default function ({ types: t }) { AssignmentPattern: { exit({ node }) { node.left.optional = false; - } + }, }, // strip optional property from function params - facebook/fbjs#17 Function: { exit({ node }) { node.params.forEach((param) => param.optional = false); - } + }, }, // support for `class X { foo: string }` - #4622 ClassProperty(path) { - let { node, parent } = path; + const { node, parent } = path; if (!node.value) wrapInFlowComment(path, parent); }, // support `export type a = {}` - #8 Error: You passed path.replaceWith() a falsy node "ExportNamedDeclaration|Flow"(path) { - let { node, parent } = path; + const { node, parent } = path; if (t.isExportNamedDeclaration(node) && !t.isFlow(node.declaration)) { return; } @@ -60,12 +62,12 @@ export default function ({ types: t }) { // support `import type A` and `import typeof A` #10 ImportDeclaration(path) { - let { node, parent } = path; + const { node, parent } = path; if (t.isImportDeclaration(node) && node.importKind !== "type" && node.importKind !== "typeof") { return; } wrapInFlowComment(path, parent); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/actual.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/actual.js index 1c62d8ee90..7c28264794 100644 --- a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/actual.js +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/actual.js @@ -6,7 +6,7 @@ declare function foo(): void; declare function foo(x: number, y: string): void; declare class A {} declare class A extends B { x: number } -declare class A { static foo(): number; static x : string } +declare class A { static foo(): number, static x : string } declare class A { static [ indexer: number]: string } declare class A { static () : number } declare class A mixins B, C {} diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/expected.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/expected.js index 1e0c0a5b06..95116a0720 100644 --- a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/expected.js +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/declare-statements/expected.js @@ -6,7 +6,7 @@ /*:: declare function foo(x: number, y: string): void;*/ /*:: declare class A {}*/ /*:: declare class A extends B { x: number }*/ -/*:: declare class A { static foo(): number; static x : string }*/ +/*:: declare class A { static foo(): number, static x : string }*/ /*:: declare class A { static [ indexer: number]: string }*/ /*:: declare class A { static () : number }*/ /*:: declare class A mixins B, C {}*/ diff --git a/packages/babel-plugin-transform-flow-comments/test/index.js b/packages/babel-plugin-transform-flow-comments/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-flow-comments/test/index.js +++ b/packages/babel-plugin-transform-flow-comments/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-flow-strip-types/README.md b/packages/babel-plugin-transform-flow-strip-types/README.md index afde54949b..6e279dbfae 100644 --- a/packages/babel-plugin-transform-flow-strip-types/README.md +++ b/packages/babel-plugin-transform-flow-strip-types/README.md @@ -16,9 +16,6 @@ function foo(one: any, two: number, three?): string {} function foo(one, two, three) {} ``` -[Try in REPL](http://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=react&code=function%20foo(one%3A%20any%2C%20two%3A%20number%2C%20three%3F)%3A%20string%20%7B%7D&experimental=false&loose=false&spec=false&playground=false&stage=0 -) - ## Installation ```sh diff --git a/packages/babel-plugin-transform-flow-strip-types/package.json b/packages/babel-plugin-transform-flow-strip-types/package.json index 441d32c50a..345e6091f7 100644 --- a/packages/babel-plugin-transform-flow-strip-types/package.json +++ b/packages/babel-plugin-transform-flow-strip-types/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-flow-strip-types", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Strip flow type annotations from your output code.", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-flow-strip-types", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-plugin-syntax-flow": "^6.18.0" + "babel-plugin-syntax-flow": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index c64abb9a52..12f5f4bb8c 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -1,12 +1,14 @@ +import syntaxFlow from "babel-plugin-syntax-flow"; + export default function ({ types: t }) { const FLOW_DIRECTIVE = "@flow"; return { - inherits: require("babel-plugin-syntax-flow"), + inherits: syntaxFlow, visitor: { Program(path, { file: { ast: { comments } } }) { - for (let comment of (comments: Array)) { + for (const comment of (comments: Array)) { if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) { // remove flow directive comment.value = comment.value.replace(FLOW_DIRECTIVE, ""); @@ -46,7 +48,7 @@ export default function ({ types: t }) { Function({ node }) { for (let i = 0; i < node.params.length; i++) { - let param = node.params[i]; + const param = node.params[i]; param.optional = false; } }, @@ -57,7 +59,7 @@ export default function ({ types: t }) { node = node.expression; } while (t.isTypeCastExpression(node)); path.replaceWith(node); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js index 36cfd7f425..f602db2cbc 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/actual.js @@ -97,5 +97,9 @@ import type2, { foo3 } from "bar"; import type * as namespace from "bar"; export type { foo }; export type { foo2 } from "bar"; +import {type T} from "foo"; +import {type T2, V1} from "foo"; +import {typeof V2} from "foo"; +import {typeof V3, V4} from "foo"; export interface foo5 { p: number } export interface foo6 { p: T } diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js index 62bf507aae..a6c982a6a3 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-type-annotations/expected.js @@ -90,3 +90,8 @@ var identity; import type from "foo"; import type2, { foo3 } from "bar"; + +import "foo"; +import { V1 } from "foo"; +import "foo"; +import { V4 } from "foo"; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/index.js b/packages/babel-plugin-transform-flow-strip-types/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-flow-strip-types/test/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-function-bind/README.md b/packages/babel-plugin-transform-function-bind/README.md index 8e11aeae86..76505a17f4 100644 --- a/packages/babel-plugin-transform-function-bind/README.md +++ b/packages/babel-plugin-transform-function-bind/README.md @@ -18,7 +18,6 @@ func.call(obj, val) func.call(obj, val) ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=obj%3A%3Afunc%3B%0A%0Aobj%3A%3Afunc(val)%3B%0A%0A%3A%3Aobj.func(val)%3B) ## Example @@ -43,7 +42,6 @@ function add(val) { return this + val; } console.log(bigBox::getWeight()::add(5)); // prints '15' ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=const%20box%20%3D%20%7B%0A%20%20weight%3A%202%2C%0A%20%20getWeight()%20%7B%20return%20this.weight%3B%20%7D%2C%0A%7D%3B%0A%0Aconst%20%7B%20getWeight%20%7D%20%3D%20box%3B%0A%0Aconsole.log(box.getWeight())%3B%20%2F%2F%20prints%20'2'%0A%0Aconst%20bigBox%20%3D%20%7B%20weight%3A%2010%20%7D%3B%0Aconsole.log(bigBox%3A%3AgetWeight())%3B%20%2F%2F%20prints%20'10'%0A%2F%2F%20bigBox%3A%3AgetWeight()%20is%20equivalent%20to%20getWeight.call(bigBox)%0A%0A%2F%2F%20Can%20be%20chained%3A%0Afunction%20add(val)%20%7B%20return%20this%20%2B%20val%3B%20%7D%0A%0Aconsole.log(bigBox%3A%3AgetWeight()%3A%3Aadd(5))%3B%20%2F%2F%20prints%20'15') ### Using with `document.querySelectorAll` @@ -59,7 +57,6 @@ let sslUrls = document.querySelectorAll('a') console.log(sslUrls); ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=%0Aconst%20%7B%20map%2C%20filter%20%7D%20%3D%20Array.prototype%3B%0A%0Alet%20sslUrls%20%3D%20document.querySelectorAll('a')%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3A%3Amap(node%20%3D%3E%20node.href)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3A%3Afilter(href%20%3D%3E%20href.substring(0%2C%205)%20%3D%3D%3D%20'https')%3B%0A%0Aconsole.log(sslUrls)%3B%0A) `document.querySelectorAll` returns a `NodeList` element which is not a plain array, so you normally can't use the `map` function on it, and have to use it this way: `Array.prototype.map.call(document.querySelectorAll(...), node => { ... })`. The above code using the `::` will work because it is equivalent to: @@ -117,4 +114,4 @@ require("babel-core").transform("code", { ## References * [Proposal](https://github.com/zenparsing/es-function-bind) -* [Babel Blog: Function Bind Syntax](/blog/2015/05/14/function-bind) \ No newline at end of file +* [Babel Blog: Function Bind Syntax](/blog/2015/05/14/function-bind) diff --git a/packages/babel-plugin-transform-function-bind/package.json b/packages/babel-plugin-transform-function-bind/package.json index 872891dc4c..608bcde671 100644 --- a/packages/babel-plugin-transform-function-bind/package.json +++ b/packages/babel-plugin-transform-function-bind/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-function-bind", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Compile function bind operator to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-function-bind", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-function-bind": "^6.8.0", - "babel-runtime": "^6.0.0" + "babel-plugin-syntax-function-bind": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-function-bind/src/index.js b/packages/babel-plugin-transform-function-bind/src/index.js index 0d3099930f..c92e147397 100644 --- a/packages/babel-plugin-transform-function-bind/src/index.js +++ b/packages/babel-plugin-transform-function-bind/src/index.js @@ -1,3 +1,5 @@ +import syntaxFunctionBind from "babel-plugin-syntax-function-bind"; + export default function ({ types: t }) { function getTempId(scope) { let id = scope.path.getData("functionBind"); @@ -8,19 +10,19 @@ export default function ({ types: t }) { } function getStaticContext(bind, scope) { - let object = bind.object || bind.callee.object; + const object = bind.object || bind.callee.object; return scope.isStatic(object) && object; } function inferBindContext(bind, scope) { - let staticContext = getStaticContext(bind, scope); + const staticContext = getStaticContext(bind, scope); if (staticContext) return staticContext; - let tempId = getTempId(scope); + const tempId = getTempId(scope); if (bind.object) { bind.callee = t.sequenceExpression([ t.assignmentExpression("=", tempId, bind.object), - bind.callee + bind.callee, ]); } else { bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object); @@ -29,23 +31,23 @@ export default function ({ types: t }) { } return { - inherits: require("babel-plugin-syntax-function-bind"), + inherits: syntaxFunctionBind, visitor: { CallExpression({ node, scope }) { - let bind = node.callee; + const bind = node.callee; if (!t.isBindExpression(bind)) return; - let context = inferBindContext(bind, scope); + const context = inferBindContext(bind, scope); node.callee = t.memberExpression(bind.callee, t.identifier("call")); node.arguments.unshift(context); }, BindExpression(path) { - let { node, scope } = path; - let context = inferBindContext(node, scope); + const { node, scope } = path; + const context = inferBindContext(node, scope); path.replaceWith(t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context])); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-function-bind/test/index.js b/packages/babel-plugin-transform-function-bind/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-function-bind/test/index.js +++ b/packages/babel-plugin-transform-function-bind/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-jscript/package.json b/packages/babel-plugin-transform-jscript/package.json index 427c2645cb..a9e7124dd5 100644 --- a/packages/babel-plugin-transform-jscript/package.json +++ b/packages/babel-plugin-transform-jscript/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-jscript", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Babel plugin to fix buggy JScript named function expressions", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-jscript", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-jscript/src/index.js b/packages/babel-plugin-transform-jscript/src/index.js index 1361821acf..a34268656e 100644 --- a/packages/babel-plugin-transform-jscript/src/index.js +++ b/packages/babel-plugin-transform-jscript/src/index.js @@ -3,19 +3,19 @@ export default function ({ types: t }) { visitor: { FunctionExpression: { exit(path) { - let { node } = path; + const { node } = path; if (!node.id) return; node._ignoreUserWhitespace = true; path.replaceWith(t.callExpression( t.functionExpression(null, [], t.blockStatement([ t.toStatement(node), - t.returnStatement(node.id) + t.returnStatement(node.id), ])), [] )); - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-jscript/test/index.js b/packages/babel-plugin-transform-jscript/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-jscript/test/index.js +++ b/packages/babel-plugin-transform-jscript/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-object-assign/package.json b/packages/babel-plugin-transform-object-assign/package.json index f68603e5a6..eccbba7b59 100644 --- a/packages/babel-plugin-transform-object-assign/package.json +++ b/packages/babel-plugin-transform-object-assign/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-object-assign", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Replace Object.assign with an inline helper", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-assign", "author": "Jed Watson", @@ -9,10 +9,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-assign/src/index.js b/packages/babel-plugin-transform-object-assign/src/index.js index 4b985078df..067a793bdd 100644 --- a/packages/babel-plugin-transform-object-assign/src/index.js +++ b/packages/babel-plugin-transform-object-assign/src/index.js @@ -5,7 +5,7 @@ export default function () { if (path.get("callee").matchesPattern("Object.assign")) { path.node.callee = file.addHelper("extends"); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-object-rest-spread/README.md b/packages/babel-plugin-transform-object-rest-spread/README.md index 7fd2afe530..79f2432d03 100644 --- a/packages/babel-plugin-transform-object-rest-spread/README.md +++ b/packages/babel-plugin-transform-object-rest-spread/README.md @@ -4,20 +4,22 @@ ## Example +### Rest Properties + ```js -// Rest properties let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; console.log(x); // 1 console.log(y); // 2 console.log(z); // { a: 3, b: 4 } +``` -// Spread properties +### Spread Properties + +```js let n = { x, y, ...z }; console.log(n); // { x: 1, y: 2, a: 3, b: 4 } ``` -[Try in REPL](https://babeljs.io/repl/#?evaluate=true&presets=es2015%2Cstage-0&code=%2F%2F%20Rest%20properties%0Alet%20%7B%20x%2C%20y%2C%20...z%20%7D%20%3D%20%7B%20x%3A%201%2C%20y%3A%202%2C%20a%3A%203%2C%20b%3A%204%20%7D%3B%0Aconsole.log(x)%3B%20%2F%2F%201%0Aconsole.log(y)%3B%20%2F%2F%202%0Aconsole.log(z)%3B%20%2F%2F%20%7B%20a%3A%203%2C%20b%3A%204%20%7D%0A%0A%2F%2F%20Spread%20properties%0Alet%20n%20%3D%20%7B%20x%2C%20y%2C%20...z%20%7D%3B%0Aconsole.log(n)%3B%20%2F%2F%20%7B%20x%3A%201%2C%20y%3A%202%2C%20a%3A%203%2C%20b%3A%204%20%7D) - ## Installation ```sh @@ -36,25 +38,6 @@ npm install --save-dev babel-plugin-transform-object-rest-spread } ``` -## Options - -This plugin will use babel's `extends` helper, which will polyfill `Object.assign` by default. - -* `useBuiltIns` - Do not use Babel's helper's and just transform to use the built-in method (Disabled by default). - -```js -{ - "plugins": [ - ["transform-object-rest-spread", { "useBuiltIns": true }] - ] -} - -// source -z = { x, ...y }; -// compiled -z = Object.assign({ x }, y); -``` - ### Via CLI ```sh @@ -69,6 +52,36 @@ require("babel-core").transform("code", { }); ``` +## Options + +### `useBuiltIns` + +`boolean`, defaults to `false`. + +By default, this plugin uses Babel's `extends` helper which polyfills `Object.assign`. Enabling this option will use `Object.assign` directly. + +**.babelrc** + +```json +{ + "plugins": [ + ["transform-object-rest-spread", { "useBuiltIns": true }] + ] +} +``` + +**In** + +```js +z = { x, ...y }; +``` + +**Out** + +```js +z = Object.assign({ x }, y); +``` + ## References * [Proposal: Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread) diff --git a/packages/babel-plugin-transform-object-rest-spread/package.json b/packages/babel-plugin-transform-object-rest-spread/package.json index 572fc9c516..5e8e352239 100644 --- a/packages/babel-plugin-transform-object-rest-spread/package.json +++ b/packages/babel-plugin-transform-object-rest-spread/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-object-rest-spread", - "version": "6.20.2", + "version": "7.0.0-alpha.1", "description": "Compile object rest and spread to ES5", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-object-rest-spread": "^6.8.0", - "babel-runtime": "^6.20.0" + "babel-plugin-syntax-object-rest-spread": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-rest-spread/src/index.js b/packages/babel-plugin-transform-object-rest-spread/src/index.js index dbc357be07..34285cd093 100644 --- a/packages/babel-plugin-transform-object-rest-spread/src/index.js +++ b/packages/babel-plugin-transform-object-rest-spread/src/index.js @@ -1,18 +1,20 @@ +import syntaxObjectRestSpread from "babel-plugin-syntax-object-rest-spread"; + export default function ({ types: t }) { - function hasRestProperty(path) { - let foundRestProperty = false; + function hasRestElement(path) { + let foundRestElement = false; path.traverse({ - RestProperty() { - foundRestProperty = true; + RestElement() { + foundRestElement = true; path.stop(); - } + }, }); - return foundRestProperty; + return foundRestElement; } function hasSpread(node) { - for (let prop of (node.properties)) { - if (t.isSpreadProperty(prop)) { + for (const prop of (node.properties)) { + if (t.isSpreadElement(prop)) { return true; } } @@ -20,10 +22,10 @@ export default function ({ types: t }) { } function createObjectSpread(file, props, objRef) { - const restProperty = props.pop(); + const restElement = props.pop(); - let keys = []; - for (let prop of props) { + const keys = []; + for (const prop of props) { let key = prop.key; if (t.isIdentifier(key) && !prop.computed) { key = t.stringLiteral(prop.key.name); @@ -32,53 +34,80 @@ export default function ({ types: t }) { } return [ - restProperty.argument, + restElement.argument, t.callExpression( file.addHelper("objectWithoutProperties"), [ objRef, - t.arrayExpression(keys) + t.arrayExpression(keys), ] - ) + ), ]; } - function replaceRestProperty(paramsPath, i, numParams) { - if (paramsPath.isObjectPattern() && hasRestProperty(paramsPath)) { - let parentPath = paramsPath.parentPath; - let uid = parentPath.scope.generateUidIdentifier("ref"); + function replaceRestElement(parentPath, paramPath, i, numParams) { + if (paramPath.isAssignmentPattern()) { + replaceRestElement(parentPath, paramPath.get("left"), i, numParams); + return; + } - let declar = t.variableDeclaration("let", [ - t.variableDeclarator(paramsPath.node, uid) + if (paramPath.isObjectPattern() && hasRestElement(paramPath)) { + const uid = parentPath.scope.generateUidIdentifier("ref"); + + const declar = t.variableDeclaration("let", [ + t.variableDeclarator(paramPath.node, uid), ]); declar._blockHoist = i ? numParams - i : 1; parentPath.ensureBlock(); parentPath.get("body").unshiftContainer("body", declar); - paramsPath.replaceWith(uid); + paramPath.replaceWith(uid); } } return { - inherits: require("babel-plugin-syntax-object-rest-spread"), + inherits: syntaxObjectRestSpread, visitor: { // taken from transform-es2015-parameters/src/destructuring.js // function a({ b, ...c }) {} Function(path) { - let params = path.get("params"); + const params = path.get("params"); for (let i = 0; i < params.length; i++) { - replaceRestProperty(params[i], i, params.length); + replaceRestElement(params[i].parentPath, params[i], i, params.length); } }, // adapted from transform-es2015-destructuring/src/index.js#pushObjectRest // const { a, ...b } = c; VariableDeclarator(path, file) { if (!path.get("id").isObjectPattern()) { return; } - const kind = path.parentPath.node.kind; - let nodes = []; - path.traverse({ - RestProperty(path) { + let insertionPath = path; + + path.get("id").traverse({ + RestElement(path) { + if ( + // skip single-property case, e.g. + // const { ...x } = foo(); + // since the RHS will not be duplicated + this.originalPath.node.id.properties.length > 1 && + !t.isIdentifier(this.originalPath.node.init) + ) { + // const { a, ...b } = foo(); + // to avoid calling foo() twice, as a first step convert it to: + // const _foo = foo(), + // { a, ...b } = _foo; + const initRef = path.scope.generateUidIdentifierBasedOnNode( + this.originalPath.node.init, "ref"); + // insert _foo = foo() + this.originalPath.insertBefore(t.variableDeclarator(initRef, + this.originalPath.node.init)); + // replace foo() with _foo + this.originalPath.replaceWith(t.variableDeclarator( + this.originalPath.node.id, initRef)); + + return; + } + let ref = this.originalPath.node.init; path.findParent((path) => { @@ -89,47 +118,42 @@ export default function ({ types: t }) { } }); - let [ argument, callExpression ] = createObjectSpread( + const [ argument, callExpression ] = createObjectSpread( file, path.parentPath.node.properties, ref ); - nodes.push( + insertionPath.insertAfter( t.variableDeclarator( argument, callExpression ) ); + insertionPath = insertionPath.getSibling(insertionPath.key + 1); + if (path.parentPath.node.properties.length === 0) { path.findParent( - (path) => path.isObjectProperty() || path.isVariableDeclaration() + (path) => path.isObjectProperty() || path.isVariableDeclarator() ).remove(); } - } - },{ - originalPath: path + }, + }, { + originalPath: path, }); - - if (nodes.length > 0) { - path.parentPath.getSibling(path.parentPath.key + 1) - .insertBefore( - t.variableDeclaration(kind, nodes) - ); - } }, // taken from transform-es2015-destructuring/src/index.js#visitor // export var { a, ...b } = c; ExportNamedDeclaration(path) { - let declaration = path.get("declaration"); + const declaration = path.get("declaration"); if (!declaration.isVariableDeclaration()) return; - if (!hasRestProperty(declaration)) return; + if (!hasRestElement(declaration)) return; - let specifiers = []; + const specifiers = []; - for (let name in path.getOuterBindingIdentifiers(path)) { - let id = t.identifier(name); + for (const name in path.getOuterBindingIdentifiers(path)) { + const id = t.identifier(name); specifiers.push(t.exportSpecifier(id, id)); } @@ -141,30 +165,31 @@ export default function ({ types: t }) { }, // try {} catch ({a, ...b}) {} CatchClause(path) { - replaceRestProperty(path.get("param")); + const paramPath = path.get("param"); + replaceRestElement(paramPath.parentPath, paramPath); }, // ({a, ...b} = c); AssignmentExpression(path, file) { - let leftPath = path.get("left"); - if (leftPath.isObjectPattern() && hasRestProperty(leftPath)) { - let nodes = []; + const leftPath = path.get("left"); + if (leftPath.isObjectPattern() && hasRestElement(leftPath)) { + const nodes = []; let ref; if (path.isCompletionRecord() || path.parentPath.isExpressionStatement()) { ref = path.scope.generateUidIdentifierBasedOnNode(path.node.right, "ref"); nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(ref, path.node.right) + t.variableDeclarator(ref, path.node.right), ])); } - let [ argument, callExpression ] = createObjectSpread( + const [ argument, callExpression ] = createObjectSpread( file, path.node.left.properties, ref ); - let nodeWithoutSpread = t.clone(path.node); + const nodeWithoutSpread = t.clone(path.node); nodeWithoutSpread.right = ref; nodes.push(t.expressionStatement(nodeWithoutSpread)); nodes.push(t.toStatement(t.assignmentExpression( @@ -182,22 +207,22 @@ export default function ({ types: t }) { }, // taken from transform-es2015-destructuring/src/index.js#visitor ForXStatement(path) { - let { node, scope } = path; - let leftPath = path.get("left"); - let left = node.left; + const { node, scope } = path; + const leftPath = path.get("left"); + const left = node.left; // for ({a, ...b} of []) {} - if (t.isObjectPattern(left) && hasRestProperty(leftPath)) { - let temp = scope.generateUidIdentifier("ref"); + if (t.isObjectPattern(left) && hasRestElement(leftPath)) { + const temp = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration("var", [ - t.variableDeclarator(temp) + t.variableDeclarator(temp), ]); path.ensureBlock(); node.body.body.unshift(t.variableDeclaration("var", [ - t.variableDeclarator(left, temp) + t.variableDeclarator(left, temp), ])); return; @@ -205,19 +230,19 @@ export default function ({ types: t }) { if (!t.isVariableDeclaration(left)) return; - let pattern = left.declarations[0].id; + const pattern = left.declarations[0].id; if (!t.isObjectPattern(pattern)) return; - let key = scope.generateUidIdentifier("ref"); + const key = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration(left.kind, [ - t.variableDeclarator(key, null) + t.variableDeclarator(key, null), ]); path.ensureBlock(); node.body.body.unshift( t.variableDeclaration(node.left.kind, [ - t.variableDeclarator(pattern, key) + t.variableDeclarator(pattern, key), ]) ); }, @@ -225,12 +250,13 @@ export default function ({ types: t }) { ObjectExpression(path, file) { if (!hasSpread(path.node)) return; - let useBuiltIns = file.opts.useBuiltIns || false; + const useBuiltIns = file.opts.useBuiltIns || false; if (typeof useBuiltIns !== "boolean") { - throw new Error("transform-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)"); + throw new Error("transform-object-rest-spread currently only accepts a boolean " + + "option for useBuiltIns (defaults to false)"); } - let args = []; + const args = []; let props = []; function push() { @@ -239,8 +265,8 @@ export default function ({ types: t }) { props = []; } - for (let prop of (path.node.properties: Array)) { - if (t.isSpreadProperty(prop)) { + for (const prop of (path.node.properties: Array)) { + if (t.isSpreadElement(prop)) { push(); args.push(prop.argument); } else { @@ -259,7 +285,7 @@ export default function ({ types: t }) { file.addHelper("extends"); path.replaceWith(t.callExpression(helper, args)); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/catch-clause/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/catch-clause/expected.js index c1695cf2ed..a311c3e537 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/catch-clause/expected.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/catch-clause/expected.js @@ -2,16 +2,16 @@ try {} catch (_ref) { let a34 = babelHelpers.objectWithoutProperties(_ref, []); } try {} catch (_ref2) { - let { a1 } = _ref2; - let b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]); + let { a1 } = _ref2, + b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]); } try {} catch (_ref3) { - let { a2, b2 } = _ref3; - let c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]); + let { a2, b2 } = _ref3, + c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]); } try {} catch (_ref4) { - let { a2, b2, c2: { c3 } } = _ref4; - let c4 = babelHelpers.objectWithoutProperties(_ref4.c2, ["c3"]); + let { a2, b2, c2: { c3 } } = _ref4, + c4 = babelHelpers.objectWithoutProperties(_ref4.c2, ["c3"]); } // Unchanged diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/export/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/export/expected.js index d3d2967d6e..95af7b2702 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/export/expected.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/export/expected.js @@ -1,7 +1,7 @@ // ExportNamedDeclaration -var { b } = asdf2; +var { b } = asdf2, + c = babelHelpers.objectWithoutProperties(asdf2, ["b"]); // Skip -var c = babelHelpers.objectWithoutProperties(asdf2, ["b"]); export { b, c }; export var { bb, cc } = ads; -export var [dd, ee] = ads; \ No newline at end of file +export var [dd, ee] = ads; diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/for-x/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/for-x/expected.js index 59b38ec57f..0cffd92db6 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/for-x/expected.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/for-x/expected.js @@ -1,16 +1,16 @@ // ForXStatement for (var _ref of []) { - var { a } = _ref; - var b = babelHelpers.objectWithoutProperties(_ref, ["a"]); + var { a } = _ref, + b = babelHelpers.objectWithoutProperties(_ref, ["a"]); } for (var _ref2 of []) { - var { a } = _ref2; - var b = babelHelpers.objectWithoutProperties(_ref2, ["a"]); + var { a } = _ref2, + b = babelHelpers.objectWithoutProperties(_ref2, ["a"]); } async function a() { for await (var _ref3 of []) { - var { a } = _ref3; - var b = babelHelpers.objectWithoutProperties(_ref3, ["a"]); + var { a } = _ref3, + b = babelHelpers.objectWithoutProperties(_ref3, ["a"]); } } @@ -18,11 +18,11 @@ async function a() { for ({ a } in {}) {} for ({ a } of []) {} async function a() { - for ({ a } of []) {} + for await ({ a } of []) {} } for (a in {}) {} for (a of []) {} async function a() { - for (a of []) {} -} \ No newline at end of file + for await (a of []) {} +} diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/actual.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/actual.js index a3beccb8a4..553131f613 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/actual.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/actual.js @@ -4,6 +4,7 @@ function a3({a2, b2, ...c2}) {} function a4({a3, ...c3}, {a5, ...c5}) {} function a5({a3, b2: { ba1, ...ba2 }, ...c3}) {} function a6({a3, b2: { ba1, ...ba2 } }) {} +function a7({a1 = 1, ...b1} = {}) {} // Unchanged function b(a) {} function b2(a, ...b) {} diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/expected.js index a3ec9786f7..abaf34d76d 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/expected.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/parameters/expected.js @@ -2,27 +2,31 @@ function a(_ref) { let a34 = babelHelpers.objectWithoutProperties(_ref, []); } function a2(_ref2) { - let { a1 } = _ref2; - let b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]); + let { a1 } = _ref2, + b1 = babelHelpers.objectWithoutProperties(_ref2, ["a1"]); } function a3(_ref3) { - let { a2, b2 } = _ref3; - let c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]); + let { a2, b2 } = _ref3, + c2 = babelHelpers.objectWithoutProperties(_ref3, ["a2", "b2"]); } function a4(_ref4, _ref5) { - let { a5 } = _ref5; - let c5 = babelHelpers.objectWithoutProperties(_ref5, ["a5"]); - let { a3 } = _ref4; - let c3 = babelHelpers.objectWithoutProperties(_ref4, ["a3"]); + let { a5 } = _ref5, + c5 = babelHelpers.objectWithoutProperties(_ref5, ["a5"]); + let { a3 } = _ref4, + c3 = babelHelpers.objectWithoutProperties(_ref4, ["a3"]); } function a5(_ref6) { - let { a3, b2: { ba1 } } = _ref6; - let ba2 = babelHelpers.objectWithoutProperties(_ref6.b2, ["ba1"]), + let { a3, b2: { ba1 } } = _ref6, + ba2 = babelHelpers.objectWithoutProperties(_ref6.b2, ["ba1"]), c3 = babelHelpers.objectWithoutProperties(_ref6, ["a3", "b2"]); } function a6(_ref7) { - let { a3, b2: { ba1 } } = _ref7; - let ba2 = babelHelpers.objectWithoutProperties(_ref7.b2, ["ba1"]); + let { a3, b2: { ba1 } } = _ref7, + ba2 = babelHelpers.objectWithoutProperties(_ref7.b2, ["ba1"]); +} +function a7(_ref8 = {}) { + let { a1 = 1 } = _ref8, + b1 = babelHelpers.objectWithoutProperties(_ref8, ["a1"]); } // Unchanged function b(a) {} diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/variable-destructuring/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/variable-destructuring/expected.js index c7d81cdf99..b9b3cfe2d3 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/variable-destructuring/expected.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/variable-destructuring/expected.js @@ -3,25 +3,24 @@ var x = babelHelpers.objectWithoutProperties(z, []); var a = babelHelpers.objectWithoutProperties({ a: 1 }, []); var x = babelHelpers.objectWithoutProperties(a.b, []); var x = babelHelpers.objectWithoutProperties(a(), []); - -var { x1 } = z; -var y1 = babelHelpers.objectWithoutProperties(z, ["x1"]); +var { x1 } = z, + y1 = babelHelpers.objectWithoutProperties(z, ["x1"]); x1++; -var { [a]: b } = z; -var c = babelHelpers.objectWithoutProperties(z, [a]); -var { x1 } = z; -var y1 = babelHelpers.objectWithoutProperties(z, ["x1"]); -let { x2, y2 } = z; -let z2 = babelHelpers.objectWithoutProperties(z, ["x2", "y2"]); -const { w3, x3, y3 } = z; +var { [a]: b } = z, + c = babelHelpers.objectWithoutProperties(z, [a]); +var { x1 } = z, + y1 = babelHelpers.objectWithoutProperties(z, ["x1"]); +let { x2, y2 } = z, + z2 = babelHelpers.objectWithoutProperties(z, ["x2", "y2"]); +const { w3, x3, y3 } = z, + z4 = babelHelpers.objectWithoutProperties(z, ["w3", "x3", "y3"]); -const z4 = babelHelpers.objectWithoutProperties(z, ["w3", "x3", "y3"]); let { x: { a: xa, [d]: f } -} = complex; - -let asdf = babelHelpers.objectWithoutProperties(complex.x, ["a", d]), +} = complex, + asdf = babelHelpers.objectWithoutProperties(complex.x, ["a", d]), d = babelHelpers.objectWithoutProperties(complex.y, []), g = babelHelpers.objectWithoutProperties(complex, ["x"]); -let {} = z; -let y4 = babelHelpers.objectWithoutProperties(z.x4, []); + +let {} = z, + y4 = babelHelpers.objectWithoutProperties(z.x4, []); diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/actual.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/actual.js new file mode 100644 index 0000000000..261723058d --- /dev/null +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/actual.js @@ -0,0 +1,7 @@ +const { s, ...t } = foo(); + +const { s: { q1, ...q2 }, ...q3 } = bar(); + +const { a } = foo(({ b, ...c }) => { + console.log(b, c); +}); diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/expected.js new file mode 100644 index 0000000000..a07001af1b --- /dev/null +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-4904/expected.js @@ -0,0 +1,15 @@ +const _foo = foo(), + { s } = _foo, + t = babelHelpers.objectWithoutProperties(_foo, ["s"]); + +const _bar = bar(), + { s: { q1 } } = _bar, + q2 = babelHelpers.objectWithoutProperties(_bar.s, ["q1"]), + q3 = babelHelpers.objectWithoutProperties(_bar, ["s"]); + +const { a } = foo((_ref) => { + let { b } = _ref, + c = babelHelpers.objectWithoutProperties(_ref, ["b"]); + + console.log(b, c); +}); diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/actual.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/actual.js new file mode 100644 index 0000000000..a57f76549a --- /dev/null +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/actual.js @@ -0,0 +1,10 @@ +const { x, ...y } = a, + z = foo(y); + +const { ...s } = r, + t = foo(s); + +// ordering is preserved +var l = foo(), + { m: { n, ...o }, ...p } = bar(), + q = baz(); diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/expected.js b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/expected.js new file mode 100644 index 0000000000..ef6147befd --- /dev/null +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/gh-5151/expected.js @@ -0,0 +1,14 @@ +const { x } = a, + y = babelHelpers.objectWithoutProperties(a, ["x"]), + z = foo(y); + +const s = babelHelpers.objectWithoutProperties(r, []), + t = foo(s); + +// ordering is preserved +var l = foo(), + _bar = bar(), + { m: { n } } = _bar, + o = babelHelpers.objectWithoutProperties(_bar.m, ["n"]), + p = babelHelpers.objectWithoutProperties(_bar, ["m"]), + q = baz(); diff --git a/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/options.json b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/options.json new file mode 100644 index 0000000000..e155c0bd07 --- /dev/null +++ b/packages/babel-plugin-transform-object-rest-spread/test/fixtures/regression/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "transform-object-rest-spread", + "external-helpers" + ] +} diff --git a/packages/babel-plugin-transform-object-rest-spread/test/index.js b/packages/babel-plugin-transform-object-rest-spread/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-object-rest-spread/test/index.js +++ b/packages/babel-plugin-transform-object-rest-spread/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json index 62bdee5e52..599761b63b 100644 --- a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json +++ b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-object-set-prototype-of-to-assign", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Turn Object.setPrototypeOf to assignments", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-set-prototype-of-to-assign", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js index dc3575ab48..9f3d99c884 100644 --- a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js +++ b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/src/index.js @@ -5,7 +5,7 @@ export default function () { if (path.get("callee").matchesPattern("Object.setPrototypeOf")) { path.node.callee = file.addHelper("defaults"); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-proto-to-assign/package.json b/packages/babel-plugin-transform-proto-to-assign/package.json index 7613bff4b2..51b69cc3ad 100644 --- a/packages/babel-plugin-transform-proto-to-assign/package.json +++ b/packages/babel-plugin-transform-proto-to-assign/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-proto-to-assign", - "version": "6.9.0", + "version": "7.0.0-alpha.1", "description": "Babel plugin for turning __proto__ into a shallow property clone", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-proto-to-assign", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.9.0", "lodash": "^4.2.0" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-proto-to-assign/src/index.js b/packages/babel-plugin-transform-proto-to-assign/src/index.js index d17f857c18..83230a6ae4 100644 --- a/packages/babel-plugin-transform-proto-to-assign/src/index.js +++ b/packages/babel-plugin-transform-proto-to-assign/src/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import pull from "lodash/pull"; export default function ({ types: t }) { @@ -8,8 +6,9 @@ export default function ({ types: t }) { } function isProtoAssignmentExpression(node) { - let left = node.left; - return t.isMemberExpression(left) && t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" }); + const left = node.left; + return t.isMemberExpression(left) && + t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" }); } function buildDefaultsCallExpression(expr, ref, file) { @@ -21,9 +20,9 @@ export default function ({ types: t }) { AssignmentExpression(path, file) { if (!isProtoAssignmentExpression(path.node)) return; - let nodes = []; - let left = path.node.left.object; - let temp = path.scope.maybeGenerateMemoised(left); + const nodes = []; + const left = path.node.left.object; + const temp = path.scope.maybeGenerateMemoised(left); if (temp) nodes.push(t.expressionStatement(t.assignmentExpression("=", temp, left))); nodes.push(buildDefaultsCallExpression(path.node, temp || left, file)); @@ -33,7 +32,7 @@ export default function ({ types: t }) { }, ExpressionStatement(path, file) { - let expr = path.node.expression; + const expr = path.node.expression; if (!t.isAssignmentExpression(expr, { operator: "=" })) return; if (isProtoAssignmentExpression(expr)) { @@ -43,9 +42,9 @@ export default function ({ types: t }) { ObjectExpression(path, file) { let proto; - let { node } = path; + const { node } = path; - for (let prop of (node.properties: Array)) { + for (const prop of (node.properties: Array)) { if (isProtoKey(prop)) { proto = prop.value; pull(node.properties, prop); @@ -53,11 +52,11 @@ export default function ({ types: t }) { } if (proto) { - let args = [t.objectExpression([]), proto]; + const args = [t.objectExpression([]), proto]; if (node.properties.length) args.push(node); path.replaceWith(t.callExpression(file.addHelper("extends"), args)); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-proto-to-assign/test/index.js b/packages/babel-plugin-transform-proto-to-assign/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-proto-to-assign/test/index.js +++ b/packages/babel-plugin-transform-proto-to-assign/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-constant-elements/README.md b/packages/babel-plugin-transform-react-constant-elements/README.md index 6a75ab7a4a..4754c94534 100644 --- a/packages/babel-plugin-transform-react-constant-elements/README.md +++ b/packages/babel-plugin-transform-react-constant-elements/README.md @@ -6,7 +6,7 @@ **In** -```js +```jsx const Hr = () => { return
; }; @@ -14,7 +14,7 @@ const Hr = () => { **Out** -```js +```jsx const _ref =
; const Hr = () => { @@ -26,23 +26,17 @@ const Hr = () => { - **Spread Operator** - ```js + ```jsx
``` - **Refs** - ```js + ```jsx
this.node = node} /> ``` -- **Composite Components** - - ```js - const ComponentA = () =>
; - ``` - ## Installation ```sh diff --git a/packages/babel-plugin-transform-react-constant-elements/package.json b/packages/babel-plugin-transform-react-constant-elements/package.json index 144dc0f8a8..45b0d6bf05 100644 --- a/packages/babel-plugin-transform-react-constant-elements/package.json +++ b/packages/babel-plugin-transform-react-constant-elements/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-constant-elements", - "version": "6.9.1", + "version": "7.0.0-alpha.1", "description": "Treat React JSX elements as value types and hoist them to the highest scope", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-constant-elements", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.9.1" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-constant-elements/src/index.js b/packages/babel-plugin-transform-react-constant-elements/src/index.js index 9673af7c26..5b2b18fcc9 100644 --- a/packages/babel-plugin-transform-react-constant-elements/src/index.js +++ b/packages/babel-plugin-transform-react-constant-elements/src/index.js @@ -1,7 +1,7 @@ -export default function () { - let immutabilityVisitor = { +export default function ({ types: t }) { + const immutabilityVisitor = { enter(path, state) { - let stop = () => { + const stop = () => { state.isImmutable = false; path.stop(); }; @@ -11,16 +11,40 @@ export default function () { return; } + // Elements with refs are not safe to hoist. if (path.isJSXIdentifier({ name: "ref" }) && path.parentPath.isJSXAttribute({ name: path.node })) { return stop(); } + // Ignore identifiers & JSX expressions. if (path.isJSXIdentifier() || path.isIdentifier() || path.isJSXMemberExpression()) { return; } - if (!path.isImmutable()) stop(); - } + if (!path.isImmutable()) { + // If it's not immutable, it may still be a pure expression, such as string concatenation. + // It is still safe to hoist that, so long as its result is immutable. + // If not, it is not safe to replace as mutable values (like objects) could be mutated after render. + // https://github.com/facebook/react/issues/3226 + if (path.isPure()) { + const expressionResult = path.evaluate(); + if (expressionResult.confident) { + // We know the result; check its mutability. + const { value } = expressionResult; + const isMutable = (value && typeof value === "object") || (typeof value === "function"); + if (!isMutable) { + // It evaluated to an immutable value, so we can hoist it. + return; + } + } else if (t.isIdentifier(expressionResult.deopt)) { + // It's safe to hoist here if the deopt reason is an identifier (e.g. func param). + // The hoister will take care of how high up it can be hoisted. + return; + } + } + stop(); + } + }, }; return { @@ -28,7 +52,7 @@ export default function () { JSXElement(path) { if (path.node._hoisted) return; - let state = { isImmutable: true }; + const state = { isImmutable: true }; path.traverse(immutabilityVisitor, state); if (state.isImmutable) { @@ -36,7 +60,7 @@ export default function () { } else { path.node._hoisted = true; } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/expected.js index cceca3a5e8..46849febf6 100644 --- a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/expected.js +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope-3/expected.js @@ -1,18 +1,19 @@ -var _ref =

Parent

; - var _ref2 =
child
; +var _ref3 =

Parent

; + (function () { class App extends React.Component { render() { - return
- {_ref} - -
; + return _ref; } } const AppItem = () => { return _ref2; - }; -}); + }, + _ref =
+ {_ref3} + +
; +}); \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope/expected.js index 5fc8260845..fe04d4853f 100644 --- a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope/expected.js +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/append-to-end-when-declared-in-scope/expected.js @@ -1,16 +1,14 @@ -var _ref =

Parent

; - export default class App extends React.Component { render() { - return
- {_ref} - -
; + return _ref; } } -var _ref2 =
child
; - -const AppItem = () => { +const _ref2 =
child
, + AppItem = () => { return _ref2; -}; +}, + _ref =
+

Parent

+ +
; \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/actual.js new file mode 100644 index 0000000000..fbd1ed5555 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/actual.js @@ -0,0 +1,10 @@ +class AnchorLink extends Component { + render() { + const { isExternal, children } = this.props; + if (isExternal) { + return ({children}); + } + + return ({children}); + } +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/expected.js new file mode 100644 index 0000000000..4f730edf03 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/expected.js @@ -0,0 +1,13 @@ +class AnchorLink extends Component { + render() { + var _props = this.props; + const isExternal = _props.isExternal, + children = _props.children; + + if (isExternal) { + return {children}; + } + + return {children}; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/options.json b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/options.json new file mode 100644 index 0000000000..dc9272a969 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/destructure/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "syntax-jsx", + "transform-es2015-destructuring", + "transform-react-constant-elements" + ] +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/actual.js new file mode 100644 index 0000000000..0bcdd9ef7c --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/actual.js @@ -0,0 +1,15 @@ +import React from "react"; + +const Parent = ({}) => ( +
+ +
+); + +export default Parent; + +let Child = () => ( +
+ ChildTextContent +
+); diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/expected.js new file mode 100644 index 0000000000..6bcd6e0ffb --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-class/expected.js @@ -0,0 +1,13 @@ +import React from "react"; + +const Parent = ({}) => _ref; + +export default Parent; + +let _ref2 =
+ ChildTextContent +
, + Child = () => _ref2, + _ref =
+ +
; diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-declaration/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-declaration/expected.js index d85f9f3244..45b91bd296 100644 --- a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-declaration/expected.js +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-declaration/expected.js @@ -8,8 +8,9 @@ function render() { function render() { const bar = "bar", - renderFoo = () => , - baz = "baz"; + renderFoo = () => _ref2, + baz = "baz", + _ref2 = ; return renderFoo(); } \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/actual.js new file mode 100644 index 0000000000..21f7b2ed90 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/actual.js @@ -0,0 +1,18 @@ +import React from "react"; + +const HOC = component => component; + +const Parent = ({}) => ( +
+ +
+); + +export default Parent; + +let Child = () => ( +
+ ChildTextContent +
+); +Child = HOC(Child); diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/expected.js new file mode 100644 index 0000000000..8da0cc5ad1 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-before-hoc/expected.js @@ -0,0 +1,18 @@ +import React from "react"; + +const HOC = component => component; + +const Parent = ({}) => _ref; + +export default Parent; + +var _ref2 =
+ ChildTextContent +
; + +let Child = () => _ref2; +Child = HOC(Child); + +var _ref =
+ +
; \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-block-scoped-variables/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-block-scoped-variables/expected.js index 9618e6da02..ab6ad7d4c4 100644 --- a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-block-scoped-variables/expected.js +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/dont-hoist-block-scoped-variables/expected.js @@ -1,17 +1,11 @@ function render(flag) { if (flag) { - var _ret = function () { - var bar = "bar"; + var bar = "bar"; - [].map(() => bar); + [].map(() => bar); - return { - v: - }; - }(); - - if (typeof _ret === "object") return _ret.v; + return ; } return null; -} \ No newline at end of file +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/actual.js new file mode 100644 index 0000000000..a6c1f9b6ec --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/actual.js @@ -0,0 +1,4 @@ +function render() { + this.component = "div"; + return () => ; +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/expected.js new file mode 100644 index 0000000000..aa7a9994ba --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-constant/expected.js @@ -0,0 +1,7 @@ +function render() { + this.component = "div"; + + var _ref = ; + + return () => _ref; +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/actual.js new file mode 100644 index 0000000000..bdc61d684a --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/actual.js @@ -0,0 +1,5 @@ +class Component extends React.Component { + subComponent = () => Sub Component + + render = () => +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/expected.js new file mode 100644 index 0000000000..9ce3a08e74 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/expected.js @@ -0,0 +1,12 @@ +var _ref = Sub Component; + +class Component extends React.Component { + constructor(...args) { + var _temp; + + var _ref2 = ; + + return _temp = super(...args), this.subComponent = () => _ref, this.render = () => _ref2, _temp; + } + +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/options.json b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/options.json new file mode 100644 index 0000000000..d4789bbda3 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression-this/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"] +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/actual.js new file mode 100644 index 0000000000..2ab59df97b --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/actual.js @@ -0,0 +1,6 @@ +const els = { + subComponent: () => Sub Component +}; +class Component extends React.Component { + render = () => +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/expected.js new file mode 100644 index 0000000000..fe12eb988d --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/expected.js @@ -0,0 +1,16 @@ +var _ref = Sub Component; + +const els = { + subComponent: () => _ref +}; + +var _ref2 = ; + +class Component extends React.Component { + constructor(...args) { + var _temp; + + return _temp = super(...args), this.render = () => _ref2, _temp; + } + +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/options.json b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/options.json new file mode 100644 index 0000000000..d4789bbda3 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/member-expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"] +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/actual.js new file mode 100644 index 0000000000..4df51832c7 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/actual.js @@ -0,0 +1,5 @@ +// https://github.com/facebook/react/issues/3226 +// Not safe to reuse because it is mutable +function render() { + return
; +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/expected.js new file mode 100644 index 0000000000..4df51832c7 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-deopt/expected.js @@ -0,0 +1,5 @@ +// https://github.com/facebook/react/issues/3226 +// Not safe to reuse because it is mutable +function render() { + return
; +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/actual.js new file mode 100644 index 0000000000..0acb75cfaf --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/actual.js @@ -0,0 +1,5 @@ +function render(offset) { + return function () { + return
; + }; +} diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/expected.js new file mode 100644 index 0000000000..65df627806 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-2/expected.js @@ -0,0 +1,8 @@ +function render(offset) { + var _ref =
; + + return function () { + return _ref; + }; +} + diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/actual.js new file mode 100644 index 0000000000..c6b89c77fd --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/actual.js @@ -0,0 +1,10 @@ +const OFFSET = 3; + +var Foo = React.createClass({ + render: function () { + return ( +
+ ); + } +}); + diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/expected.js new file mode 100644 index 0000000000..e709176c48 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression-3/expected.js @@ -0,0 +1,10 @@ +const OFFSET = 3; + +var _ref =
; + +var Foo = React.createClass({ + render: function () { + return _ref; + } +}); + diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/actual.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/actual.js new file mode 100644 index 0000000000..5131c83989 --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/actual.js @@ -0,0 +1,11 @@ +var Foo = React.createClass({ + render: function () { + return ( +
+ ); + } +}); + diff --git a/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/expected.js b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/expected.js new file mode 100644 index 0000000000..a7afcb1d6e --- /dev/null +++ b/packages/babel-plugin-transform-react-constant-elements/test/fixtures/constant-elements/pure-expression/expected.js @@ -0,0 +1,8 @@ +var _ref =
; + +var Foo = React.createClass({ + render: function () { + return _ref; + } +}); + diff --git a/packages/babel-plugin-transform-react-constant-elements/test/index.js b/packages/babel-plugin-transform-react-constant-elements/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-constant-elements/test/index.js +++ b/packages/babel-plugin-transform-react-constant-elements/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-display-name/package.json b/packages/babel-plugin-transform-react-display-name/package.json index 03acc9556a..84747a6f53 100644 --- a/packages/babel-plugin-transform-react-display-name/package.json +++ b/packages/babel-plugin-transform-react-display-name/package.json @@ -1,17 +1,14 @@ { "name": "babel-plugin-transform-react-display-name", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Add displayName to React.createClass calls", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-display-name", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-display-name", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.0.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-display-name/src/index.js b/packages/babel-plugin-transform-react-display-name/src/index.js index 43206810e7..f80f67c8dd 100644 --- a/packages/babel-plugin-transform-react-display-name/src/index.js +++ b/packages/babel-plugin-transform-react-display-name/src/index.js @@ -2,12 +2,12 @@ import path from "path"; export default function ({ types: t }) { function addDisplayName(id, call) { - let props = call.arguments[0].properties; + const props = call.arguments[0].properties; let safe = true; for (let i = 0; i < props.length; i++) { - let prop = props[i]; - let key = t.toComputedKey(prop); + const prop = props[i]; + const key = t.toComputedKey(prop); if (t.isLiteral(key, { value: "displayName" })) { safe = false; break; @@ -19,7 +19,7 @@ export default function ({ types: t }) { } } - let isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass"); + const isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass"); function isCreateClass(node) { if (!node || !t.isCallExpression(node)) return false; @@ -28,11 +28,11 @@ export default function ({ types: t }) { if (!isCreateClassCallExpression(node.callee)) return false; // no call arguments - let args = node.arguments; + const args = node.arguments; if (args.length !== 1) return false; // first node arg is not an object - let first = args[0]; + const first = args[0]; if (!t.isObjectExpression(first)) return false; return true; @@ -54,7 +54,7 @@ export default function ({ types: t }) { }, CallExpression(path) { - let { node } = path; + const { node } = path; if (!isCreateClass(node)) return; let id; @@ -88,7 +88,7 @@ export default function ({ types: t }) { if (t.isIdentifier(id)) { addDisplayName(id.name, node); } - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-react-display-name/test/index.js b/packages/babel-plugin-transform-react-display-name/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-display-name/test/index.js +++ b/packages/babel-plugin-transform-react-display-name/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-inline-elements/package.json b/packages/babel-plugin-transform-react-inline-elements/package.json index 2d69aca9a4..f456210517 100644 --- a/packages/babel-plugin-transform-react-inline-elements/package.json +++ b/packages/babel-plugin-transform-react-inline-elements/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-inline-elements", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Turn JSX elements into exploded React objects", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-inline-elements", "license": "MIT", @@ -9,9 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0" + "babel-runtime": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-inline-elements/src/index.js b/packages/babel-plugin-transform-react-inline-elements/src/index.js index 5f394fc3f8..9af3146ec7 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -1,7 +1,7 @@ export default function ({ types: t }) { function hasRefOrSpread(attrs) { for (let i = 0; i < attrs.length; i++) { - let attr = attrs[i]; + const attr = attrs[i]; if (t.isJSXSpreadAttribute(attr)) return true; if (isJSXAttributeOfName(attr, "ref")) return true; } @@ -22,16 +22,16 @@ export default function ({ types: t }) { return { visitor: { JSXElement(path, file) { - let { node } = path; + const { node } = path; // filter - let open = node.openingElement; + const open = node.openingElement; if (hasRefOrSpread(open.attributes)) return; // init - let props = t.objectExpression([]); - let key = null; - let type = open.name; + const props = t.objectExpression([]); + let key = null; + let type = open.name; if (t.isJSXIdentifier(type) && t.react.isCompatTag(type.name)) { type = t.stringLiteral(type.name); @@ -42,28 +42,28 @@ export default function ({ types: t }) { } // props - for (let attr of (open.attributes: Array)) { + for (const attr of (open.attributes: Array)) { if (isJSXAttributeOfName(attr, "key")) { key = getAttributeValue(attr); } else { - let name = attr.name.name; - let propertyKey = t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name); + const name = attr.name.name; + const propertyKey = t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name); pushProp(props.properties, propertyKey, getAttributeValue(attr)); } } - let args = [type, props]; + const args = [type, props]; if (key || node.children.length) { - let children = t.react.buildChildren(node); + const children = t.react.buildChildren(node); args.push( key || t.unaryExpression("void", t.numericLiteral(0), true), ...children ); } - let el = t.callExpression(file.addHelper("jsx"), args); + const el = t.callExpression(file.addHelper("jsx"), args); path.replaceWith(el); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-react-inline-elements/test/index.js b/packages/babel-plugin-transform-react-inline-elements/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-inline-elements/test/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-jsx-compat/package.json b/packages/babel-plugin-transform-react-jsx-compat/package.json index fef317568b..4788f5e3f0 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/package.json +++ b/packages/babel-plugin-transform-react-jsx-compat/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-compat", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Turn JSX into React Pre-0.12 function calls", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-compat", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-helper-builder-react-jsx": "^6.8.0" + "babel-helper-builder-react-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-compat/src/index.js b/packages/babel-plugin-transform-react-jsx-compat/src/index.js index edb9ee5a45..7fa6b05edc 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-compat/src/index.js @@ -1,10 +1,12 @@ +import helper from "babel-helper-builder-react-jsx"; + export default function ({ types: t }) { return { manipulateOptions(opts, parserOpts) { parserOpts.plugins.push("jsx"); }, - visitor: require("babel-helper-builder-react-jsx")({ + visitor: helper({ pre(state) { state.callee = state.tagExpr; }, @@ -20,7 +22,7 @@ export default function ({ types: t }) { state.args ); } - } - }) + }, + }), }; } diff --git a/packages/babel-plugin-transform-react-jsx-compat/test/index.js b/packages/babel-plugin-transform-react-jsx-compat/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/test/index.js +++ b/packages/babel-plugin-transform-react-jsx-compat/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-jsx-self/package.json b/packages/babel-plugin-transform-react-jsx-self/package.json index 655bf9f9c2..de0fc545ab 100644 --- a/packages/babel-plugin-transform-react-jsx-self/package.json +++ b/packages/babel-plugin-transform-react-jsx-self/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-self", - "version": "6.11.0", + "version": "7.0.0-alpha.1", "description": "Add a __self prop to all JSX Elements", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-self", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.9.0", - "babel-plugin-syntax-jsx": "^6.8.0" + "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-self/src/index.js b/packages/babel-plugin-transform-react-jsx-self/src/index.js index 2fd02a77ed..089d1c1775 100644 --- a/packages/babel-plugin-transform-react-jsx-self/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-self/src/index.js @@ -15,16 +15,16 @@ const TRACE_ID = "__self"; export default function ({ types: t }) { - let visitor = { + const visitor = { JSXOpeningElement({ node }) { const id = t.jSXIdentifier(TRACE_ID); const trace = t.thisExpression(); node.attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace))); - } + }, }; return { - visitor + visitor, }; } diff --git a/packages/babel-plugin-transform-react-jsx-self/test/index.js b/packages/babel-plugin-transform-react-jsx-self/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-jsx-self/test/index.js +++ b/packages/babel-plugin-transform-react-jsx-self/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-jsx-source/package.json b/packages/babel-plugin-transform-react-jsx-source/package.json index fa5674b673..e9b1f0cc59 100644 --- a/packages/babel-plugin-transform-react-jsx-source/package.json +++ b/packages/babel-plugin-transform-react-jsx-source/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-source", - "version": "6.9.0", + "version": "7.0.0-alpha.1", "description": "Add a __source prop to all JSX Elements", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.9.0", - "babel-plugin-syntax-jsx": "^6.8.0" + "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx-source/src/index.js b/packages/babel-plugin-transform-react-jsx-source/src/index.js index cd296af979..1583598f22 100644 --- a/packages/babel-plugin-transform-react-jsx-source/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-source/src/index.js @@ -26,7 +26,7 @@ export default function ({ types: t }) { return t.objectExpression([fileNameProperty, lineNumberProperty]); } - let visitor = { + const visitor = { JSXOpeningElement(path, state) { const id = t.jSXIdentifier(TRACE_ID); const location = path.container.openingElement.loc; @@ -50,16 +50,16 @@ export default function ({ types: t }) { : null; const fileNameIdentifier = path.scope.generateUidIdentifier(FILE_NAME_VAR); - path.hub.file.scope.push({id: fileNameIdentifier, init: t.stringLiteral(fileName)}); + path.hub.file.scope.push({ id: fileNameIdentifier, init: t.stringLiteral(fileName) }); state.fileNameIdentifier = fileNameIdentifier; } const trace = makeTrace(state.fileNameIdentifier, location.start.line); attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace))); - } + }, }; return { - visitor + visitor, }; } diff --git a/packages/babel-plugin-transform-react-jsx-source/test/index.js b/packages/babel-plugin-transform-react-jsx-source/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-jsx-source/test/index.js +++ b/packages/babel-plugin-transform-react-jsx-source/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-react-jsx/README.md b/packages/babel-plugin-transform-react-jsx/README.md index 4a7c3ae0fb..128536db1e 100644 --- a/packages/babel-plugin-transform-react-jsx/README.md +++ b/packages/babel-plugin-transform-react-jsx/README.md @@ -64,12 +64,17 @@ npm install --save-dev babel-plugin-transform-react-jsx **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-react-jsx"] } -// with options +``` + +With options: + +```json { "plugins": [ ["transform-react-jsx", { @@ -95,6 +100,16 @@ require("babel-core").transform("code", { ## Options -* `pragma` - Replace the function used when compiling JSX expressions (Defaults to `React.createElement`). - - Note that the `@jsx React.DOM` pragma has been deprecated as of React v0.12 -* `useBuiltIns` - When spreading props, use Object.assign instead of Babel's extend helper (Disabled by default). +### `pragma` + +`string`, defaults to `React.createElement`. + +Replace the function used when compiling JSX expressions. + +Note that the `@jsx React.DOM` pragma has been deprecated as of React v0.12 + +### `useBuiltIns` + +`boolean`, defaults to `false`. + +When spreading props, use `Object.assign` directly instead of Babel's extend helper. diff --git a/packages/babel-plugin-transform-react-jsx/package.json b/packages/babel-plugin-transform-react-jsx/package.json index c80e86560f..954bf14360 100644 --- a/packages/babel-plugin-transform-react-jsx/package.json +++ b/packages/babel-plugin-transform-react-jsx/package.json @@ -1,19 +1,18 @@ { "name": "babel-plugin-transform-react-jsx", - "version": "6.8.0", + "version": "7.0.0-alpha.1", "description": "Turn JSX into React function calls", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-jsx", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-helper-builder-react-jsx": "^6.8.0", - "babel-plugin-syntax-jsx": "^6.8.0" + "babel-helper-builder-react-jsx": "7.0.0-alpha.1", + "babel-plugin-syntax-jsx": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 0a80ffac4b..0c3df28ebc 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -1,12 +1,13 @@ -/* eslint max-len: 0 */ +import jsx from "babel-plugin-syntax-jsx"; +import helper from "babel-helper-builder-react-jsx"; export default function ({ types: t }) { - let JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/; + const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/; - let visitor = require("babel-helper-builder-react-jsx")({ + const visitor = helper({ pre(state) { - let tagName = state.tagName; - let args = state.args; + const tagName = state.tagName; + const args = state.args; if (t.react.isCompatTag(tagName)) { args.push(t.stringLiteral(tagName)); } else { @@ -16,19 +17,20 @@ export default function ({ types: t }) { post(state, pass) { state.callee = pass.get("jsxIdentifier")(); - } + }, }); visitor.Program = function (path, state) { - let { file } = state; + const { file } = state; let id = state.opts.pragma || "React.createElement"; - for (let comment of (file.ast.comments: Array)) { - let matches = JSX_ANNOTATION_REGEX.exec(comment.value); + for (const comment of (file.ast.comments: Array)) { + const matches = JSX_ANNOTATION_REGEX.exec(comment.value); if (matches) { id = matches[1]; if (id === "React.DOM") { - throw file.buildCodeFrameError(comment, "The @jsx React.DOM pragma has been deprecated as of React 0.12"); + throw file.buildCodeFrameError(comment, + "The @jsx React.DOM pragma has been deprecated as of React 0.12"); } else { break; } @@ -44,7 +46,7 @@ export default function ({ types: t }) { }; return { - inherits: require("babel-plugin-syntax-jsx"), - visitor + inherits: jsx, + visitor, }; } diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/actual.js b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/actual.js deleted file mode 100644 index 6a05e108dc..0000000000 --- a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/actual.js +++ /dev/null @@ -1 +0,0 @@ -
{...children}
; diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json deleted file mode 100644 index ec71024507..0000000000 --- a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-spread-children/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Spread children are not supported." -} diff --git a/packages/babel-plugin-transform-react-jsx/test/index.js b/packages/babel-plugin-transform-react-jsx/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-react-jsx/test/index.js +++ b/packages/babel-plugin-transform-react-jsx/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-regenerator/README.md b/packages/babel-plugin-transform-regenerator/README.md index 18adfa4bca..e82f106380 100644 --- a/packages/babel-plugin-transform-regenerator/README.md +++ b/packages/babel-plugin-transform-regenerator/README.md @@ -34,8 +34,6 @@ function a() { } ``` -[Try in REPL](http://babeljs.io/repl/#?evaluate=true&lineWrap=true&presets=es2015%2Ces2015-loose%2Creact&experimental=false&loose=false&spec=false&code=function%20*range(max%2C%20step)%20%7B%0A%20%20var%20count%20%3D%200%3B%0A%20%20step%20%3D%20step%20%7C%7C%201%3B%0A%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20max%3B%20i%20%2B%3D%20step)%20%7B%0A%20%20%20%20count%2B%2B%3B%0A%20%20%20%20yield%20i%3B%0A%20%20%7D%0A%20%0A%20%20return%20count%3B%0A%7D%0A%20%0Avar%20gen%20%3D%20range(20%2C%203)%2C%20info%3B%0A%20%0Awhile%20(!(info%20%3D%20gen.next()).done)%20%7B%0A%20%20console.log(info.value)%3B%0A%7D%0A%20%0Aconsole.log(%22steps%20taken%3A%20%22%20%2B%20info.value)%3B&playground=true) - ## Installation ```sh @@ -46,20 +44,29 @@ npm install --save-dev babel-plugin-transform-regenerator ### Via `.babelrc` (Recommended) -**.babelrc** +Without options: -```js -// without options +```json { "plugins": ["transform-regenerator"] } -// with options +``` + +With options: + +|name|default value| +|---|---| +|asyncGenerators|true| +|generators|true| +|async|true| + +````json { "plugins": [ ["transform-regenerator", { - asyncGenerators: false, // true by default - generators: false, // true by default - async: false // true by default + asyncGenerators: false, + generators: false, + async: false }] ] } diff --git a/packages/babel-plugin-transform-regenerator/package.json b/packages/babel-plugin-transform-regenerator/package.json index a44902ca1d..56b1a5ad78 100644 --- a/packages/babel-plugin-transform-regenerator/package.json +++ b/packages/babel-plugin-transform-regenerator/package.json @@ -2,7 +2,7 @@ "name": "babel-plugin-transform-regenerator", "author": "Ben Newman ", "description": "Explode async and generator functions into a state machine.", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "homepage": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-regenerator", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-regenerator", "main": "lib/index.js", @@ -11,6 +11,6 @@ }, "license": "MIT", "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-regenerator/src/index.js b/packages/babel-plugin-transform-regenerator/src/index.js index e8207160e5..aaf6f168f5 100644 --- a/packages/babel-plugin-transform-regenerator/src/index.js +++ b/packages/babel-plugin-transform-regenerator/src/index.js @@ -1 +1 @@ -module.exports = require("regenerator-transform"); +export { default } from "regenerator-transform"; diff --git a/packages/babel-plugin-transform-regenerator/test/index.js b/packages/babel-plugin-transform-regenerator/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-regenerator/test/index.js +++ b/packages/babel-plugin-transform-regenerator/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-runtime/README.md b/packages/babel-plugin-transform-runtime/README.md index ff42d7e9af..fb82b38de5 100644 --- a/packages/babel-plugin-transform-runtime/README.md +++ b/packages/babel-plugin-transform-runtime/README.md @@ -40,13 +40,17 @@ The transformation plugin is typically used only in development, but the runtime Add the following line to your `.babelrc` file: -```js -// without options +Without options: + +```json { "plugins": ["transform-runtime"] } +``` -// with options +With options: + +```js { "plugins": [ ["transform-runtime", { diff --git a/packages/babel-plugin-transform-runtime/package.json b/packages/babel-plugin-transform-runtime/package.json index eb6ef08fbf..e731d2d8bd 100644 --- a/packages/babel-plugin-transform-runtime/package.json +++ b/packages/babel-plugin-transform-runtime/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-runtime", - "version": "6.15.0", + "version": "7.0.0-alpha.1", "description": "Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime", "license": "MIT", @@ -8,10 +8,7 @@ "keywords": [ "babel-plugin" ], - "dependencies": { - "babel-runtime": "^6.9.0" - }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-runtime/src/definitions.js b/packages/babel-plugin-transform-runtime/src/definitions.js index ce059f9634..159c4cde68 100644 --- a/packages/babel-plugin-transform-runtime/src/definitions.js +++ b/packages/babel-plugin-transform-runtime/src/definitions.js @@ -1,4 +1,4 @@ -module.exports = { +export default { builtins: { Symbol: "symbol", Promise: "promise", @@ -9,14 +9,13 @@ module.exports = { Observable: "observable", setImmediate: "set-immediate", clearImmediate: "clear-immediate", - asap: "asap" + asap: "asap", //parseFloat: "parse-float", // temporary disabled //parseInt: "parse-int" // temporary disabled }, methods: { Array: { - concat: "array/concat", // deprecated copyWithin: "array/copy-within", entries: "array/entries", every: "array/every", @@ -34,22 +33,16 @@ module.exports = { lastIndexOf: "array/last-index-of", map: "array/map", of: "array/of", - pop: "array/pop", // deprecated - push: "array/push", // deprecated reduceRight: "array/reduce-right", reduce: "array/reduce", - reverse: "array/reverse", // deprecated - shift: "array/shift", // deprecated - slice: "array/slice", // deprecated some: "array/some", sort: "array/sort", splice: "array/splice", - unshift: "array/unshift", // deprecated - values: "array/values" + values: "array/values", }, JSON: { - stringify: "json/stringify" + stringify: "json/stringify", }, Object: { @@ -72,11 +65,7 @@ module.exports = { preventExtensions: "object/prevent-extensions", seal: "object/seal", setPrototypeOf: "object/set-prototype-of", - values: "object/values" - }, - - RegExp: { - escape: "regexp/escape" // deprecated + values: "object/values", }, Math: { @@ -100,25 +89,23 @@ module.exports = { iaddh: "math/iaddh", isubh: "math/isubh", imulh: "math/imulh", - umulh: "math/umulh" + umulh: "math/umulh", }, Symbol: { - asyncIterator: "symbol/async-iterator", for: "symbol/for", hasInstance: "symbol/has-instance", isConcatSpreadable: "symbol/is-concat-spreadable", iterator: "symbol/iterator", keyFor: "symbol/key-for", match: "symbol/match", - observable: "symbol/observable", replace: "symbol/replace", search: "symbol/search", species: "symbol/species", split: "symbol/split", toPrimitive: "symbol/to-primitive", toStringTag: "symbol/to-string-tag", - unscopables: "symbol/unscopables" + unscopables: "symbol/unscopables", }, String: { @@ -128,8 +115,6 @@ module.exports = { fromCodePoint: "string/from-code-point", includes: "string/includes", matchAll: "string/match-all", - padLeft: "string/pad-left", // deprecated - padRight: "string/pad-right", // deprecated padStart: "string/pad-start", padEnd: "string/pad-end", raw: "string/raw", @@ -139,7 +124,7 @@ module.exports = { trimLeft: "string/trim-left", trimRight: "string/trim-right", trimStart: "string/trim-start", - trimEnd: "string/trim-end" + trimEnd: "string/trim-end", }, Number: { @@ -151,7 +136,7 @@ module.exports = { MAX_SAFE_INTEGER: "number/max-safe-integer", MIN_SAFE_INTEGER: "number/min-safe-integer", parseFloat: "number/parse-float", - parseInt: "number/parse-int" + parseInt: "number/parse-int", }, Reflect: { @@ -159,7 +144,6 @@ module.exports = { construct: "reflect/construct", defineProperty: "reflect/define-property", deleteProperty: "reflect/delete-property", - enumerate: "reflect/enumerate", // deprecated getOwnPropertyDescriptor: "reflect/get-own-property-descriptor", getPrototypeOf: "reflect/get-prototype-of", get: "reflect/get", @@ -177,15 +161,11 @@ module.exports = { getOwnMetadataKeys: "reflect/get-own-metadata-keys", hasMetadata: "reflect/has-metadata", hasOwnMetadata: "reflect/has-own-metadata", - metadata: "reflect/metadata" + metadata: "reflect/metadata", }, System: { - global: "system/global" - }, - - Error: { - isError: "error/is-error" // deprecated + global: "system/global", }, Date: { @@ -195,6 +175,6 @@ module.exports = { Function: { // Warning: /virtual/ method - prototype, not static, version //bind: "function/virtual/bind" // temporary disabled - } - } + }, + }, }; diff --git a/packages/babel-plugin-transform-runtime/src/index.js b/packages/babel-plugin-transform-runtime/src/index.js index 805df686ae..98976b52af 100644 --- a/packages/babel-plugin-transform-runtime/src/index.js +++ b/packages/babel-plugin-transform-runtime/src/index.js @@ -9,7 +9,7 @@ export default function ({ types: t }) { return Object.prototype.hasOwnProperty.call(obj, key); } - let HELPER_BLACKLIST = ["interopRequireWildcard", "interopRequireDefault"]; + const HELPER_BLACKLIST = ["interopRequireWildcard", "interopRequireDefault"]; return { pre(file) { @@ -30,7 +30,7 @@ export default function ({ types: t }) { visitor: { ReferencedIdentifier(path, state) { - let { node, parent, scope } = path; + const { node, parent, scope } = path; if (node.name === "regeneratorRuntime" && state.opts.regenerator !== false) { path.replaceWith(state.get("regeneratorIdentifier")); @@ -59,7 +59,7 @@ export default function ({ types: t }) { // we can't compile this if (path.node.arguments.length) return; - let callee = path.node.callee; + const callee = path.node.callee; if (!t.isMemberExpression(callee)) return; if (!callee.computed) return; if (!path.get("callee.property").matchesPattern("Symbol.iterator")) return; @@ -99,15 +99,15 @@ export default function ({ types: t }) { if (state.opts.polyfill === false) return; if (!path.isReferenced()) return; - let { node } = path; - let obj = node.object; - let prop = node.property; + const { node } = path; + const obj = node.object; + const prop = node.property; if (!t.isReferenced(obj, node)) return; if (node.computed) return; if (!has(definitions.methods, obj.name)) return; - let methods = definitions.methods[obj.name]; + const methods = definitions.methods[obj.name]; if (!has(methods, prop.name)) return; // doesn't reference the global @@ -115,7 +115,7 @@ export default function ({ types: t }) { // special case Object.defineProperty to not use core-js when using string keys if (obj.name === "Object" && prop.name === "defineProperty" && path.parentPath.isCallExpression()) { - let call = path.parentPath.node; + const call = path.parentPath.node; if (call.arguments.length === 3 && t.isLiteral(call.arguments[1])) return; } @@ -131,8 +131,8 @@ export default function ({ types: t }) { if (state.opts.polyfill === false) return; if (!path.isReferenced()) return; - let { node } = path; - let obj = node.object; + const { node } = path; + const obj = node.object; if (!has(definitions.builtins, obj.name)) return; if (path.scope.getBindingIdentifier(obj.name)) return; @@ -147,9 +147,9 @@ export default function ({ types: t }) { node.property, node.computed )); - } - } - } + }, + }, + }, }; } diff --git a/packages/babel-plugin-transform-runtime/test/index.js b/packages/babel-plugin-transform-runtime/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-runtime/test/index.js +++ b/packages/babel-plugin-transform-runtime/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-transform-strict-mode/README.md b/packages/babel-plugin-transform-strict-mode/README.md index d6c258d300..08c5afe405 100644 --- a/packages/babel-plugin-transform-strict-mode/README.md +++ b/packages/babel-plugin-transform-strict-mode/README.md @@ -34,13 +34,17 @@ npm install --save-dev babel-plugin-transform-strict-mode **.babelrc** -```js -// without options +Without options: + +```json { "plugins": ["transform-strict-mode"] } +``` -// with options +With options: + +```json { "plugins": [ ["transform-strict-mode", { diff --git a/packages/babel-plugin-transform-strict-mode/package.json b/packages/babel-plugin-transform-strict-mode/package.json index 679eaaee9a..62212a0f17 100644 --- a/packages/babel-plugin-transform-strict-mode/package.json +++ b/packages/babel-plugin-transform-strict-mode/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-strict-mode", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "This plugin places a 'use strict'; directive at the top of all files to enable strict mode", "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-strict-mode", "license": "MIT", @@ -9,10 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^6.0.0", - "babel-types": "^6.18.0" + "babel-types": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-plugin-transform-strict-mode/src/index.js b/packages/babel-plugin-transform-strict-mode/src/index.js index 8ed2d181fb..54b84fad98 100644 --- a/packages/babel-plugin-transform-strict-mode/src/index.js +++ b/packages/babel-plugin-transform-strict-mode/src/index.js @@ -6,14 +6,14 @@ export default function () { Program(path, state) { if (state.opts.strict === false || state.opts.strictMode === false) return; - let { node } = path; + const { node } = path; - for (let directive of (node.directives: Array)) { + for (const directive of (node.directives: Array)) { if (directive.value.value === "use strict") return; } path.unshiftContainer("directives", t.directive(t.directiveLiteral("use strict"))); - } - } + }, + }, }; } diff --git a/packages/babel-plugin-transform-strict-mode/test/index.js b/packages/babel-plugin-transform-strict-mode/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-plugin-transform-strict-mode/test/index.js +++ b/packages/babel-plugin-transform-strict-mode/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-plugin-undeclared-variables-check/.npmignore b/packages/babel-plugin-undeclared-variables-check/.npmignore deleted file mode 100644 index 31852902b1..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -*.log -src -test diff --git a/packages/babel-plugin-undeclared-variables-check/README.md b/packages/babel-plugin-undeclared-variables-check/README.md deleted file mode 100644 index 5bdf1b783a..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# babel-plugin-undeclared-variables-check - -> This plugin throws a compile-time error on references to undeclared variables. - -## Example - -**In** - -```javascript -function foo() {} -foo(); -bar(); -``` - -**Out** - -``` -ReferenceError: stdin: Line 3: Reference to undeclared variable "bar" - did you mean "foo"? - 1 | function foo() {} - 2 | foo(); -> 3 | bar(); - | ^ - 4 | -``` - -## Installation - -```sh -npm install --save-dev babel-plugin-undeclared-variables-check -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["undeclared-variables-check"] -} -``` - -### Via CLI - -```sh -babel --plugins undeclared-variables-check script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["undeclared-variables-check"] -}); -``` diff --git a/packages/babel-plugin-undeclared-variables-check/package.json b/packages/babel-plugin-undeclared-variables-check/package.json deleted file mode 100644 index 5ecc97376a..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "babel-plugin-undeclared-variables-check", - "version": "6.8.0", - "description": "Throw a compile-time error on references to undeclared variables", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-undeclared-variables-check", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "babel-runtime": "^6.0.0", - "leven": "^1.0.2" - }, - "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" - } -} diff --git a/packages/babel-plugin-undeclared-variables-check/src/index.js b/packages/babel-plugin-undeclared-variables-check/src/index.js deleted file mode 100644 index a6400dd8c7..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/src/index.js +++ /dev/null @@ -1,46 +0,0 @@ -import leven from "leven"; - -export default function ({ messages }) { - return { - visitor: { - ReferencedIdentifier(path) { - let { node, scope } = path; - - let binding = scope.getBinding(node.name); - if (binding && binding.kind === "type" && !path.parentPath.isFlow()) { - throw path.buildCodeFrameError(messages.get("undeclaredVariableType", node.name), ReferenceError); - } - - if (scope.hasBinding(node.name)) return; - - // get the closest declaration to offer as a suggestion - // the variable name may have just been mistyped - - let bindings = scope.getAllBindings(); - - let closest; - let shortest = -1; - - for (let name in bindings) { - let distance = leven(node.name, name); - if (distance <= 0 || distance > 3) continue; - if (distance <= shortest) continue; - - closest = name; - shortest = distance; - } - - let msg; - if (closest) { - msg = messages.get("undeclaredVariableSuggestion", node.name, closest); - } else { - msg = messages.get("undeclaredVariable", node.name); - } - - // - - throw path.buildCodeFrameError(msg, ReferenceError); - } - } - }; -} diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/declared/exec.js b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/declared/exec.js deleted file mode 100644 index e2721feb4a..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/declared/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -function foo() { - -} - -foo(); diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/options.json b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/options.json deleted file mode 100644 index 9aad0a18e2..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["undeclared-variables-check"] -} diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js deleted file mode 100644 index ee11821ed0..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js +++ /dev/null @@ -1 +0,0 @@ -({foo}) diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/options.json b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/options.json deleted file mode 100644 index a661ffc703..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared-shorthand-property/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Reference to undeclared variable" -} diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/exec.js b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/exec.js deleted file mode 100644 index a280f9a5cc..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/exec.js +++ /dev/null @@ -1 +0,0 @@ -foo(); diff --git a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/options.json b/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/options.json deleted file mode 100644 index a661ffc703..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/fixtures/validation.undeclared-variable-check/undeclared/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Reference to undeclared variable" -} diff --git a/packages/babel-plugin-undeclared-variables-check/test/index.js b/packages/babel-plugin-undeclared-variables-check/test/index.js deleted file mode 100644 index 1f6634aabd..0000000000 --- a/packages/babel-plugin-undeclared-variables-check/test/index.js +++ /dev/null @@ -1 +0,0 @@ -require("babel-helper-plugin-test-runner")(__dirname); diff --git a/packages/babel-polyfill/package.json b/packages/babel-polyfill/package.json index 15cd6f4379..04e23ce7ec 100644 --- a/packages/babel-polyfill/package.json +++ b/packages/babel-polyfill/package.json @@ -1,6 +1,6 @@ { "name": "babel-polyfill", - "version": "6.20.0", + "version": "7.0.0-alpha.1", "description": "Provides polyfills necessary for a full ES2015+ environment", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -9,7 +9,6 @@ "main": "lib/index.js", "dependencies": { "core-js": "^2.4.0", - "babel-runtime": "^6.20.0", "regenerator-runtime": "^0.10.0" } } diff --git a/packages/babel-polyfill/src/index.js b/packages/babel-polyfill/src/index.js index 0cb9b282d6..943e349060 100644 --- a/packages/babel-polyfill/src/index.js +++ b/packages/babel-polyfill/src/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - if (global._babelPolyfill) { throw new Error("only one instance of babel-polyfill is allowed"); } @@ -7,23 +5,3 @@ global._babelPolyfill = true; import "core-js/shim"; import "regenerator-runtime/runtime"; - -// Should be removed in the next major release: - -import "core-js/fn/regexp/escape"; - -let DEFINE_PROPERTY = "defineProperty"; -function define(O, key, value) { - O[key] || Object[DEFINE_PROPERTY](O, key, { - writable: true, - configurable: true, - value: value - }); -} - -define(String.prototype, "padLeft", "".padStart); -define(String.prototype, "padRight", "".padEnd); - -"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(key) { - [][key] && define(Array, key, Function.call.bind([][key])); -}); diff --git a/packages/babel-preset-es2015/README.md b/packages/babel-preset-es2015/README.md index dacd924c73..77340ab708 100644 --- a/packages/babel-preset-es2015/README.md +++ b/packages/babel-preset-es2015/README.md @@ -36,30 +36,22 @@ require("babel-core").transform("code", { ## Options -* `loose` - Enable "loose" transformations for any plugins in this preset that allow them (Disabled by default). -* `modules` - Enable transformation of ES6 module syntax to another module type (Enabled by default to `"commonjs"`). - * Can be `false` to not transform modules, or one of `["amd", "umd", "systemjs", "commonjs"]` -* `spec` - Enable "spec" transformations for any plugins in this preset that allow them (Disabled by default) +### `loose` -```js -{ - presets: [ - ["es2015", { "loose": true }] - ] -} -{ - presets: [ - ["es2015", { "modules": false }] - ] -} -{ - presets: [ - ["es2015", { "loose": true, "modules": false }] - ] -} -{ - presets: [ - ["es2015", { "spec": true }] - ] -} -``` +`boolean`, defaults to `false`. + +Enable "loose" transformations for any plugins in this preset that allow them. + +### `modules` + +`"amd" | "umd" | "systemjs" | "commonjs" | false`, defaults to `"commonjs"`. + +Enable transformation of ES6 module syntax to another module type. + +Setting this to `false` will not transform modules. + +### `spec` + +`boolean`, defaults to `false`. + +Enable "spec" transformations for any plugins in this preset that allow them. diff --git a/packages/babel-preset-es2015/package.json b/packages/babel-preset-es2015/package.json index 0c8384381e..60c1a389e2 100644 --- a/packages/babel-preset-es2015/package.json +++ b/packages/babel-preset-es2015/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-es2015", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for all es2015 plugins.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,33 +8,33 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-es2015", "main": "lib/index.js", "dependencies": { - "babel-plugin-check-es2015-constants": "^6.3.13", - "babel-plugin-transform-es2015-arrow-functions": "^6.3.13", - "babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13", - "babel-plugin-transform-es2015-block-scoping": "^6.18.0", - "babel-plugin-transform-es2015-classes": "^6.18.0", - "babel-plugin-transform-es2015-computed-properties": "^6.3.13", - "babel-plugin-transform-es2015-destructuring": "^6.18.0", - "babel-plugin-transform-es2015-duplicate-keys": "^6.6.0", - "babel-plugin-transform-es2015-for-of": "^6.18.0", - "babel-plugin-transform-es2015-function-name": "^6.9.0", - "babel-plugin-transform-es2015-literals": "^6.3.13", - "babel-plugin-transform-es2015-modules-amd": "^6.18.0", - "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0", - "babel-plugin-transform-es2015-modules-systemjs": "^6.18.0", - "babel-plugin-transform-es2015-modules-umd": "^6.18.0", - "babel-plugin-transform-es2015-object-super": "^6.3.13", - "babel-plugin-transform-es2015-parameters": "^6.18.0", - "babel-plugin-transform-es2015-shorthand-properties": "^6.18.0", - "babel-plugin-transform-es2015-spread": "^6.3.13", - "babel-plugin-transform-es2015-sticky-regex": "^6.3.13", - "babel-plugin-transform-es2015-template-literals": "^6.6.0", - "babel-plugin-transform-es2015-typeof-symbol": "^6.18.0", - "babel-plugin-transform-es2015-unicode-regex": "^6.3.13", - "babel-plugin-transform-regenerator": "^6.16.0" + "babel-plugin-check-es2015-constants": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-arrow-functions": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-block-scoped-functions": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-block-scoping": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-classes": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-computed-properties": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-destructuring": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-duplicate-keys": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-for-of": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-function-name": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-literals": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-modules-amd": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-modules-commonjs": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-modules-systemjs": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-modules-umd": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-object-super": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-parameters": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-shorthand-properties": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-spread": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-sticky-regex": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-template-literals": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-typeof-symbol": "7.0.0-alpha.1", + "babel-plugin-transform-es2015-unicode-regex": "7.0.0-alpha.1", + "babel-plugin-transform-regenerator": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-transform-fixture-test-runner": "^6.18.0", - "babel-helper-plugin-test-runner": "^6.18.0" + "babel-helper-transform-fixture-test-runner": "^7.0.0-alpha.1", + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-preset-es2015/src/index.js b/packages/babel-preset-es2015/src/index.js index 57d96082d1..162854e9c8 100644 --- a/packages/babel-preset-es2015/src/index.js +++ b/packages/babel-preset-es2015/src/index.js @@ -1,11 +1,3 @@ -/** - * This file is not the canonical way of writing a Babel preset since it strives for - * backward compatibility with babel-core < v6.13.x. If you're looking at it as a - * reference for how to write a preset, it's probably best to look at the other presets - * such as babel-preset-es2016 & babel-preset-latest noting that the former example - * exports via a default object and the latter via a default function. - */ - import transformES2015TemplateLiterals from "babel-plugin-transform-es2015-template-literals"; import transformES2015Literals from "babel-plugin-transform-es2015-literals"; import transformES2015FunctionName from "babel-plugin-transform-es2015-function-name"; @@ -31,7 +23,7 @@ import transformES2015ModulesAMD from "babel-plugin-transform-es2015-modules-amd import transformES2015ModulesUMD from "babel-plugin-transform-es2015-modules-umd"; import transformRegenerator from "babel-plugin-transform-regenerator"; -function preset(context, opts = {}) { +export default function (context, opts = {}) { const moduleTypes = ["commonjs", "amd", "umd", "systemjs"]; let loose = false; let modules = "commonjs"; @@ -78,28 +70,7 @@ function preset(context, opts = {}) { modules === "systemjs" && [transformES2015ModulesSystemJS, optsLoose], modules === "amd" && [transformES2015ModulesAMD, optsLoose], modules === "umd" && [transformES2015ModulesUMD, optsLoose], - [transformRegenerator, { async: false, asyncGenerators: false }] - ].filter(Boolean) // filter out falsy values + [transformRegenerator, { async: false, asyncGenerators: false }], + ].filter(Boolean), // filter out falsy values }; } - -/** - * This preset was originally an object, before function-based configurable presets were introduced. - * For backward-compatibility with anything that may have been loading this preset and expecting - * it to be a simple Babel config object, we export the old config here via default object. - */ -const oldConfig = preset({}); - -export default oldConfig; - -// However, for backward compatibility with babel-core < v6.13.x, we use the 'buildPreset' -// property of the preset object for the preset creation function with the enumerability -// caveat mentioned below. -Object.defineProperty(oldConfig, "buildPreset", { - configurable: true, - writable: true, - // We make this non-enumerable so old versions of babel-core won't see it as an unknown property, - // while allowing new versions to see it as a preset builder function. - enumerable: false, - value: preset, -}); diff --git a/packages/babel-preset-es2015/test/esnext.js b/packages/babel-preset-es2015/test/esnext.js index 95896efa51..97f8aaad47 100644 --- a/packages/babel-preset-es2015/test/esnext.js +++ b/packages/babel-preset-es2015/test/esnext.js @@ -1 +1,3 @@ -require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/esnext", "esnext"); +import runner from "babel-helper-transform-fixture-test-runner"; + +runner(`${__dirname}/fixtures/esnext`, "esnext"); diff --git a/packages/babel-preset-es2015/test/index.js b/packages/babel-preset-es2015/test/index.js index 7653dbb6f9..99ac458986 100644 --- a/packages/babel-preset-es2015/test/index.js +++ b/packages/babel-preset-es2015/test/index.js @@ -1,19 +1,11 @@ -let es2015 = require("../lib"); -let expect = require("chai").expect; +import es2015 from "../lib"; +import { expect } from "chai"; describe("es2015 preset", function () { - it("exposes an object", function () { - // Changing this will break compatibility with babel-core < 6.13.x. - expect(typeof es2015).to.equal("object"); - }); - - it("exposes a separate list of plugins", function () { - expect(Array.isArray(es2015.plugins)).to.equal(true); - }); it("doesn't throw with no options passed", function () { expect(function () { - es2015.buildPreset(null); + es2015(null); }).not.to.throw(); }); @@ -21,7 +13,7 @@ describe("es2015 preset", function () { describe("loose", function () { it("throws on non-boolean value", function () { expect(function () { - es2015.buildPreset(null, { loose: 1}); + es2015(null, { loose: 1 }); }).to.throw(/must be a boolean/); }); }); @@ -29,25 +21,25 @@ describe("es2015 preset", function () { describe("modules", function () { it("doesn't throw when passing one false", function () { expect(function () { - es2015.buildPreset(null, { modules: false }); + es2015(null, { modules: false }); }).not.to.throw(); }); it("doesn't throw when passing one of: 'commonjs', 'amd', 'umd', 'systemjs", function () { expect(function () { - es2015.buildPreset(null, { modules: "commonjs" }); + es2015(null, { modules: "commonjs" }); }).not.to.throw(); expect(function () { - es2015.buildPreset(null, { modules: "amd" }); + es2015(null, { modules: "amd" }); }).not.to.throw(); expect(function () { - es2015.buildPreset(null, { modules: "umd" }); + es2015(null, { modules: "umd" }); }).not.to.throw(); expect(function () { - es2015.buildPreset(null, { modules: "systemjs" }); + es2015(null, { modules: "systemjs" }); }).not.to.throw(); }); }); diff --git a/packages/babel-preset-es2015/test/preset-options.js b/packages/babel-preset-es2015/test/preset-options.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-preset-es2015/test/preset-options.js +++ b/packages/babel-preset-es2015/test/preset-options.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-preset-es2015/test/traceur.js b/packages/babel-preset-es2015/test/traceur.js index a4bfd87c3f..ce7577a5e5 100644 --- a/packages/babel-preset-es2015/test/traceur.js +++ b/packages/babel-preset-es2015/test/traceur.js @@ -1,6 +1,7 @@ -let _ = require("lodash"); +import includes from "lodash/includes"; +import runner from "babel-helper-transform-fixture-test-runner"; -require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/traceur", "traceur", { +runner(`${__dirname}/fixtures/traceur`, "traceur", { ignoreSuites: [ // weird environmental issue make these hard to test "Modules", @@ -75,11 +76,11 @@ require("babel-helper-transform-fixture-test-runner")(__dirname + "/fixtures/tra // TODO "Syntax/StrictKeywordsInPattern", - ] + ], }, { }, function (opts, task) { - if (_.includes(task.exec.loc, "module.js")) { + if (includes(task.exec.loc, "module.js")) { opts.plugins.push("transform-es2015-modules-commonjs"); } else { opts.sourceType = "script"; diff --git a/packages/babel-preset-es2016/package.json b/packages/babel-preset-es2016/package.json index a467e23cb5..ef113843ce 100644 --- a/packages/babel-preset-es2016/package.json +++ b/packages/babel-preset-es2016/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-es2016", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for all es2016 plugins.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,6 +8,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-es2016", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-exponentiation-operator": "^6.3.13" + "babel-plugin-transform-exponentiation-operator": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-es2016/src/index.js b/packages/babel-preset-es2016/src/index.js index 3ce3c75985..ae2a519918 100644 --- a/packages/babel-preset-es2016/src/index.js +++ b/packages/babel-preset-es2016/src/index.js @@ -1,7 +1,9 @@ import transformExponentiationOperator from "babel-plugin-transform-exponentiation-operator"; -export default { - plugins: [ - transformExponentiationOperator - ] -}; +export default function () { + return { + plugins: [ + transformExponentiationOperator, + ], + }; +} diff --git a/packages/babel-preset-es2017/package.json b/packages/babel-preset-es2017/package.json index cee5d6e8b2..c75189de11 100644 --- a/packages/babel-preset-es2017/package.json +++ b/packages/babel-preset-es2017/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-es2017", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for all es2017 plugins.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,7 +8,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-es2017", "main": "lib/index.js", "dependencies": { - "babel-plugin-syntax-trailing-function-commas": "^6.8.0", - "babel-plugin-transform-async-to-generator": "^6.16.0" + "babel-plugin-syntax-trailing-function-commas": "7.0.0-alpha.1", + "babel-plugin-transform-async-to-generator": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-es2017/src/index.js b/packages/babel-preset-es2017/src/index.js index 8c83b453c2..735e5aaf57 100644 --- a/packages/babel-preset-es2017/src/index.js +++ b/packages/babel-preset-es2017/src/index.js @@ -1,9 +1,11 @@ import syntaxTrailingFunctionCommas from "babel-plugin-syntax-trailing-function-commas"; import transformAsyncToGenerator from "babel-plugin-transform-async-to-generator"; -export default { - plugins: [ - syntaxTrailingFunctionCommas, - transformAsyncToGenerator - ] -}; +export default function () { + return { + plugins: [ + syntaxTrailingFunctionCommas, + transformAsyncToGenerator, + ], + }; +} diff --git a/packages/babel/.npmignore b/packages/babel-preset-flow/.npmignore similarity index 100% rename from packages/babel/.npmignore rename to packages/babel-preset-flow/.npmignore diff --git a/packages/babel-preset-flow/README.md b/packages/babel-preset-flow/README.md new file mode 100644 index 0000000000..26593bd878 --- /dev/null +++ b/packages/babel-preset-flow/README.md @@ -0,0 +1,53 @@ +# babel-preset-flow + +> Babel preset for all Flow plugins. + +This preset includes the following plugins: + +- [transform-flow-strip-types](https://babeljs.io/docs/plugins/transform-flow-strip-types/) + +## Example + +**In** + +```javascript +function foo(one: any, two: number, three?): string {} +``` + +**Out** + +```javascript +function foo(one, two, three) {} +``` + +## Installation + +```sh +npm install --save-dev babel-preset-flow +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "presets": ["flow"] +} +``` + +### Via CLI + +```sh +babel --presets flow script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + presets: ["flow"] +}); +``` diff --git a/packages/babel-preset-flow/package.json b/packages/babel-preset-flow/package.json new file mode 100644 index 0000000000..ecde4039d6 --- /dev/null +++ b/packages/babel-preset-flow/package.json @@ -0,0 +1,18 @@ +{ + "name": "babel-preset-flow", + "version": "7.0.0-alpha.1", + "description": "Babel preset for all Flow plugins.", + "author": "James Kyle ", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-flow", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-preset", + "flowtype", + "flow", + "types" + ], + "dependencies": { + "babel-plugin-transform-flow-strip-types": "7.0.0-alpha.1" + } +} diff --git a/packages/babel-preset-flow/src/index.js b/packages/babel-preset-flow/src/index.js new file mode 100644 index 0000000000..84a144a560 --- /dev/null +++ b/packages/babel-preset-flow/src/index.js @@ -0,0 +1,9 @@ +import transformFlowStripTypes from "babel-plugin-transform-flow-strip-types"; + +export default function () { + return { + plugins: [ + transformFlowStripTypes, + ], + }; +} diff --git a/packages/babel-preset-latest/README.md b/packages/babel-preset-latest/README.md index f46761d1aa..ec4e16769d 100644 --- a/packages/babel-preset-latest/README.md +++ b/packages/babel-preset-latest/README.md @@ -36,15 +36,17 @@ require("babel-core").transform("code", { ### Options -- `es2015`: Optionally not run any plugins from this preset (defaults to true) -- `es2016`: Optionally not run any plugins from this preset (defaults to true) -- `es2017`: Optionally not run any plugins from this preset (defaults to true) +### `es2015` -```js +`boolean`, defaults to `true`. + +Toggles including plugins from the [es2015 preset](https://babeljs.io/docs/plugins/preset-es2015/). + +```json { "presets": [ ["latest", { - "es2015": false // defaults to true + "es2015": false }] ] } @@ -52,14 +54,28 @@ require("babel-core").transform("code", { You can also pass options down to the `es2015` preset. -```js +```json { "presets": [ ["latest", { "es2015": { - "modules": false + "modules": false } }] ] } ``` + +**Note:** This also works for the other preset-year options below. + +### `es2016` + +`boolean`, defaults to `true`. + +Toggles including plugins from the [es2016 preset](https://babeljs.io/docs/plugins/preset-es2016/). + +### `es2017` + +`boolean`, defaults to `true`. + +Toggles including plugins from the [es2017 preset](https://babeljs.io/docs/plugins/preset-es2017/). diff --git a/packages/babel-preset-latest/package.json b/packages/babel-preset-latest/package.json index 743b60c59b..582557770a 100644 --- a/packages/babel-preset-latest/package.json +++ b/packages/babel-preset-latest/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-latest", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset including es2015+", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,11 +8,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-latest", "main": "lib/index.js", "dependencies": { - "babel-preset-es2015": "^6.16.0", - "babel-preset-es2016": "^6.16.0", - "babel-preset-es2017": "^6.16.0" + "babel-preset-es2015": "7.0.0-alpha.1", + "babel-preset-es2016": "7.0.0-alpha.1", + "babel-preset-es2017": "7.0.0-alpha.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "^6.8.0" + "babel-helper-plugin-test-runner": "^7.0.0-alpha.1" } } diff --git a/packages/babel-preset-latest/src/index.js b/packages/babel-preset-latest/src/index.js index 8571beea98..1ef36d8279 100644 --- a/packages/babel-preset-latest/src/index.js +++ b/packages/babel-preset-latest/src/index.js @@ -2,15 +2,12 @@ import presetES2015 from "babel-preset-es2015"; import presetES2016 from "babel-preset-es2016"; import presetES2017 from "babel-preset-es2017"; -// Rather than exporting a default object to represent the preset, we can -// also export a default function instead, as this preset demonstrates. -// This allows one to further configure a preset by way of specific options. export default function (context, opts = {}) { return { presets: [ - opts.es2015 !== false && [presetES2015.buildPreset, opts.es2015], + opts.es2015 !== false && [presetES2015, opts.es2015], opts.es2016 !== false && presetES2016, - opts.es2017 !== false && presetES2017 - ].filter(Boolean) // filter out falsy values + opts.es2017 !== false && presetES2017, + ].filter(Boolean), // filter out falsy values }; } diff --git a/packages/babel-preset-latest/test/index.js b/packages/babel-preset-latest/test/index.js index 1f6634aabd..09cfbc31f5 100644 --- a/packages/babel-preset-latest/test/index.js +++ b/packages/babel-preset-latest/test/index.js @@ -1 +1,3 @@ -require("babel-helper-plugin-test-runner")(__dirname); +import runner from "babel-helper-plugin-test-runner"; + +runner(__dirname); diff --git a/packages/babel-preset-react/README.md b/packages/babel-preset-react/README.md index 827160b246..591a59547b 100644 --- a/packages/babel-preset-react/README.md +++ b/packages/babel-preset-react/README.md @@ -2,10 +2,41 @@ > Babel preset for all React plugins. +This preset includes the following plugins/presets: + +- [preset-flow](https://babeljs.io/docs/plugins/preset-flow/) +- [syntax-jsx](https://babeljs.io/docs/plugins/syntax-jsx/) +- [transform-react-jsx](https://babeljs.io/docs/plugins/transform-react-jsx/) +- [transform-react-display-name](https://babeljs.io/docs/plugins/transform-react-display-name/) + ## Install +> You can also check out the React [Getting Started page](https://facebook.github.io/react/docs/hello-world.html) + +> For more info, check out the setup page on the [cli](/docs/setup/) and the [usage](/docs/usage/cli/) docs. + +Install the CLI and this preset + ```sh -npm install --save-dev babel-preset-react +npm install --save-dev babel-cli babel-preset-react +``` + +Make a .babelrc config file with the preset + +```sh +echo '{ "presets": ["react"] }' > .babelrc +``` + +Create a file to run on + +```sh +echo '

Hello, world!

' > index.js +``` + +View the output + +```sh +./node_modules/.bin/babel index.js ``` ## Usage diff --git a/packages/babel-preset-react/package.json b/packages/babel-preset-react/package.json index 984aca9053..91f21948af 100644 --- a/packages/babel-preset-react/package.json +++ b/packages/babel-preset-react/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-react", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for all React plugins.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,12 +8,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-react", "main": "lib/index.js", "dependencies": { - "babel-plugin-syntax-flow": "^6.3.13", - "babel-plugin-syntax-jsx": "^6.3.13", - "babel-plugin-transform-flow-strip-types": "^6.3.13", - "babel-plugin-transform-react-display-name": "^6.3.13", - "babel-plugin-transform-react-jsx": "^6.3.13", - "babel-plugin-transform-react-jsx-source": "^6.3.13", - "babel-plugin-transform-react-jsx-self": "^6.11.0" + "babel-preset-flow": "7.0.0-alpha.1", + "babel-plugin-syntax-jsx": "7.0.0-alpha.1", + "babel-plugin-transform-react-display-name": "7.0.0-alpha.1", + "babel-plugin-transform-react-jsx": "7.0.0-alpha.1", + "babel-plugin-transform-react-jsx-source": "7.0.0-alpha.1", + "babel-plugin-transform-react-jsx-self": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-react/src/index.js b/packages/babel-preset-react/src/index.js index 55dd6bbd8d..5b953685aa 100644 --- a/packages/babel-preset-react/src/index.js +++ b/packages/babel-preset-react/src/index.js @@ -1,6 +1,5 @@ +import presetFlow from "babel-preset-flow"; import transformReactJSX from "babel-plugin-transform-react-jsx"; -import transformFlowStripTypes from "babel-plugin-transform-flow-strip-types"; -import transformSyntaxFlow from "babel-plugin-syntax-flow"; import transformSyntaxJSX from "babel-plugin-syntax-jsx"; import transformReactDisplayName from "babel-plugin-transform-react-display-name"; @@ -8,20 +7,23 @@ import transformReactDisplayName from "babel-plugin-transform-react-display-name // import transformReactJSXSource from "babel-plugin-transform-react-jsx-source"; // import transformReactJSXSelf from "babel-plugin-transform-react-jsx-self"; -export default { - plugins: [ - transformReactJSX, - transformFlowStripTypes, - transformSyntaxFlow, - transformSyntaxJSX, - transformReactDisplayName - ], - env: { - development: { - plugins: [ - // transformReactJSXSource, - // transformReactJSXSelf - ] - } - } -}; +export default function () { + return { + presets: [ + presetFlow, + ], + plugins: [ + transformReactJSX, + transformSyntaxJSX, + transformReactDisplayName, + ], + env: { + development: { + plugins: [ + // transformReactJSXSource, + // transformReactJSXSelf + ], + }, + }, + }; +} diff --git a/packages/babel-preset-stage-0/package.json b/packages/babel-preset-stage-0/package.json index 8fececabc1..c3be6411de 100644 --- a/packages/babel-preset-stage-0/package.json +++ b/packages/babel-preset-stage-0/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-stage-0", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for stage 0 plugins", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,8 +8,8 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-0", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-do-expressions": "^6.3.13", - "babel-plugin-transform-function-bind": "^6.3.13", - "babel-preset-stage-1": "^6.16.0" + "babel-plugin-transform-do-expressions": "7.0.0-alpha.1", + "babel-plugin-transform-function-bind": "7.0.0-alpha.1", + "babel-preset-stage-1": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-stage-0/src/index.js b/packages/babel-preset-stage-0/src/index.js index b9b65f10a0..7ac934304b 100644 --- a/packages/babel-preset-stage-0/src/index.js +++ b/packages/babel-preset-stage-0/src/index.js @@ -3,12 +3,14 @@ import presetStage1 from "babel-preset-stage-1"; import transformDoExpressions from "babel-plugin-transform-do-expressions"; import transformFunctionBind from "babel-plugin-transform-function-bind"; -export default { - presets: [ - presetStage1 - ], - plugins: [ - transformDoExpressions, - transformFunctionBind - ] -}; +export default function () { + return { + presets: [ + presetStage1, + ], + plugins: [ + transformDoExpressions, + transformFunctionBind, + ], + }; +} diff --git a/packages/babel-preset-stage-1/README.md b/packages/babel-preset-stage-1/README.md index d0af0ffd58..19692c62a5 100644 --- a/packages/babel-preset-stage-1/README.md +++ b/packages/babel-preset-stage-1/README.md @@ -2,6 +2,16 @@ > Babel preset for stage 1 plugins. +The gist of Stage 1 is: + +> **Stage 1**: proposal +> +> **What is it?** A formal proposal for the feature. +> +> **What’s required?** A so-called champion must be identified who is responsible for the proposal. Either the champion or a co-champion must be a member of TC39 (source). The problem solved by the proposal must be described in prose. The solution must be described via examples, an API and a discussion of semantics and algorithms. Lastly, potential obstacles for the proposal must be identified, such as interactions with other features and implementation challenges. Implementation-wise, polyfills and demos are needed. +> +> **What’s next?** By accepting a proposal for stage 1, TC39 declares its willingness to examine, discuss and contribute to the proposal. Going forward, major changes to the proposal are expected + ## Install ```sh @@ -33,3 +43,7 @@ require("babel-core").transform("code", { presets: ["stage-1"] }); ``` + +## References + +- Chapter "[The TC39 process for ECMAScript features](http://exploringjs.com/es2016-es2017/ch_tc39-process.html)" in "Exploring ES2016 and ES2017" by Axel Rauschmayer diff --git a/packages/babel-preset-stage-1/package.json b/packages/babel-preset-stage-1/package.json index 63a34a5cf3..3d62562948 100644 --- a/packages/babel-preset-stage-1/package.json +++ b/packages/babel-preset-stage-1/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-stage-1", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for stage 1 plugins", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,8 +8,8 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-1", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-class-constructor-call": "^6.3.13", - "babel-plugin-transform-export-extensions": "^6.3.13", - "babel-preset-stage-2": "^6.16.0" + "babel-plugin-transform-decorators": "7.0.0-alpha.1", + "babel-plugin-transform-export-extensions": "7.0.0-alpha.1", + "babel-preset-stage-2": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-stage-1/src/index.js b/packages/babel-preset-stage-1/src/index.js index 47c5cea3bc..15000e690b 100644 --- a/packages/babel-preset-stage-1/src/index.js +++ b/packages/babel-preset-stage-1/src/index.js @@ -1,14 +1,16 @@ import presetStage2 from "babel-preset-stage-2"; -import transformClassConstructorCall from "babel-plugin-transform-class-constructor-call"; +import transformDecorators from "babel-plugin-transform-decorators"; import transformExportExtensions from "babel-plugin-transform-export-extensions"; -export default { - presets: [ - presetStage2 - ], - plugins: [ - transformClassConstructorCall, - transformExportExtensions - ] -}; +export default function () { + return { + presets: [ + presetStage2, + ], + plugins: [ + transformDecorators, + transformExportExtensions, + ], + }; +} diff --git a/packages/babel-preset-stage-2/README.md b/packages/babel-preset-stage-2/README.md index 1c6a5f900e..0007aa1a67 100644 --- a/packages/babel-preset-stage-2/README.md +++ b/packages/babel-preset-stage-2/README.md @@ -2,6 +2,18 @@ > Babel preset for stage 2 plugins. +The gist of Stage 2 is: + +> **Stage 2:** draft +> +> **What is it?** A first version of what will be in the specification. At this point, an eventual inclusion of the feature in the standard is likely. +> +> **What’s required?** The proposal must now additionally have a formal description of the syntax and semantics of the feature (using the formal language of the ECMAScript specification). The description should be as complete as possible, but can contain todos and placeholders. Two experimental implementations of the feature are needed, but one of them can be in a transpiler such as Babel. +> +> **What’s next?** Only incremental changes are expected from now on. + + + ## Install ```sh @@ -33,3 +45,6 @@ require("babel-core").transform("code", { presets: ["stage-2"] }); ``` +## References + +- Chapter "[The TC39 process for ECMAScript features](http://exploringjs.com/es2016-es2017/ch_tc39-process.html)" in "Exploring ES2016 and ES2017" by Axel Rauschmayer diff --git a/packages/babel-preset-stage-2/package.json b/packages/babel-preset-stage-2/package.json index bd93ad2a13..bdc0fe94aa 100644 --- a/packages/babel-preset-stage-2/package.json +++ b/packages/babel-preset-stage-2/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-stage-2", - "version": "6.18.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for stage 2 plugins", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,9 +8,9 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-2", "main": "lib/index.js", "dependencies": { - "babel-plugin-transform-class-properties": "^6.18.0", - "babel-plugin-transform-decorators": "^6.13.0", - "babel-plugin-syntax-dynamic-import": "^6.18.0", - "babel-preset-stage-3": "^6.17.0" + "babel-plugin-syntax-dynamic-import": "7.0.0-alpha.1", + "babel-plugin-transform-class-properties": "7.0.0-alpha.1", + "babel-plugin-transform-unicode-property-regex": "^2.0.0", + "babel-preset-stage-3": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-stage-2/src/index.js b/packages/babel-preset-stage-2/src/index.js index 7e9e8a2864..d927345d74 100644 --- a/packages/babel-preset-stage-2/src/index.js +++ b/packages/babel-preset-stage-2/src/index.js @@ -1,16 +1,18 @@ import presetStage3 from "babel-preset-stage-3"; -import transformClassProperties from "babel-plugin-transform-class-properties"; -import transformDecorators from "babel-plugin-transform-decorators"; import syntaxDynamicImport from "babel-plugin-syntax-dynamic-import"; +import transformClassProperties from "babel-plugin-transform-class-properties"; +import transformUnicodePropertyRegex from "babel-plugin-transform-unicode-property-regex"; -export default { - presets: [ - presetStage3 - ], - plugins: [ - syntaxDynamicImport, - transformClassProperties, - transformDecorators - ] -}; +export default function () { + return { + presets: [ + presetStage3, + ], + plugins: [ + syntaxDynamicImport, + transformClassProperties, + transformUnicodePropertyRegex, + ], + }; +} diff --git a/packages/babel-preset-stage-3/README.md b/packages/babel-preset-stage-3/README.md index fd29e4670e..656cd0d72c 100644 --- a/packages/babel-preset-stage-3/README.md +++ b/packages/babel-preset-stage-3/README.md @@ -2,6 +2,18 @@ > Babel preset for stage 3 plugins. +The gist of Stage 3 is: + +> **Stage 3**: candidate +> +> **What is it?** The proposal is mostly finished and now needs feedback from implementations and users to progress further. + +> **What’s required?** The spec text must be complete. Designated reviewers (appointed by TC39, not by the champion) and the ECMAScript spec editor must sign off on the spec text. There must be at least two spec-compliant implementations (which don’t have to be enabled by default). +> +> **What’s next?** Henceforth, changes should only be made in response to critical issues raised by the implementations and their use. + + + ## Install ```sh @@ -33,3 +45,7 @@ require("babel-core").transform("code", { presets: ["stage-3"] }); ``` + +## References + +- Chapter "[The TC39 process for ECMAScript features](http://exploringjs.com/es2016-es2017/ch_tc39-process.html)" in "Exploring ES2016 and ES2017" by Axel Rauschmayer diff --git a/packages/babel-preset-stage-3/package.json b/packages/babel-preset-stage-3/package.json index 9a39f1a46b..60ef2805a5 100644 --- a/packages/babel-preset-stage-3/package.json +++ b/packages/babel-preset-stage-3/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-stage-3", - "version": "6.17.0", + "version": "7.0.0-alpha.1", "description": "Babel preset for stage 3 plugins", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,10 +8,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-preset-stage-3", "main": "lib/index.js", "dependencies": { - "babel-plugin-syntax-trailing-function-commas": "^6.3.13", - "babel-plugin-transform-async-generator-functions": "^6.17.0", - "babel-plugin-transform-async-to-generator": "^6.16.0", - "babel-plugin-transform-exponentiation-operator": "^6.3.13", - "babel-plugin-transform-object-rest-spread": "^6.16.0" + "babel-plugin-transform-async-generator-functions": "7.0.0-alpha.1", + "babel-plugin-transform-object-rest-spread": "7.0.0-alpha.1" } } diff --git a/packages/babel-preset-stage-3/src/index.js b/packages/babel-preset-stage-3/src/index.js index 6d57f4af66..62b4854a52 100644 --- a/packages/babel-preset-stage-3/src/index.js +++ b/packages/babel-preset-stage-3/src/index.js @@ -1,15 +1,11 @@ -import syntaxTrailingFunctionCommas from "babel-plugin-syntax-trailing-function-commas"; -import transformAsyncToGenerator from "babel-plugin-transform-async-to-generator"; -import transformExponentiationOperator from "babel-plugin-transform-exponentiation-operator"; import transformObjectRestSpread from "babel-plugin-transform-object-rest-spread"; import transformAsyncGeneratorFunctions from "babel-plugin-transform-async-generator-functions"; -export default { - plugins: [ - syntaxTrailingFunctionCommas, // in ES2017 (remove as a breaking change) - transformAsyncToGenerator, // in ES2017 (remove as a breaking change) - transformExponentiationOperator, // in ES2016 (remove as a breaking change) - transformAsyncGeneratorFunctions, - transformObjectRestSpread - ] -}; +export default function () { + return { + plugins: [ + transformAsyncGeneratorFunctions, + transformObjectRestSpread, + ], + }; +} diff --git a/packages/babel-register/README.md b/packages/babel-register/README.md index 0abbe9b81f..6a4682b568 100644 --- a/packages/babel-register/README.md +++ b/packages/babel-register/README.md @@ -25,7 +25,8 @@ and `.js` will be transformed by Babel.

Polyfill not included

- You must include the polyfill separately when using features that require it, like generators. + You must include the polyfill separately + when using features that require it, like generators.

@@ -52,7 +53,7 @@ require("babel-register")({ // Ignore can also be specified as a function. ignore: function(filename) { - if (filename === '/path/to/es6-file.js') { + if (filename === "/path/to/es6-file.js") { return false; } else { return true; @@ -69,7 +70,9 @@ require("babel-register")({ }); ``` -You can pass in all other [options](/docs/usage/options/#options) as well, including `plugins` and `presets`. But note that the closest [`.babelrc`](/docs/usage/babelrc/) to each file still applies, and takes precedence over any options you pass in here. +You can pass in all other [options](https://babeljs.io/docs/usage/api/#options) as well, +including `plugins` and `presets`. But note that the closest [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) +to each file still applies, and takes precedence over any options you pass in here. ## Environment variables diff --git a/packages/babel-register/package.json b/packages/babel-register/package.json index b2b25e9cd9..f0ab4636f7 100644 --- a/packages/babel-register/package.json +++ b/packages/babel-register/package.json @@ -1,6 +1,6 @@ { "name": "babel-register", - "version": "6.18.0", + "version": "7.0.0-alpha.2", "description": "babel require hook", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-register", @@ -8,12 +8,14 @@ "main": "lib/node.js", "browser": "lib/browser.js", "dependencies": { - "babel-core": "^6.18.0", - "babel-runtime": "^6.11.6", + "babel-core": "7.0.0-alpha.2", "core-js": "^2.4.0", - "home-or-tmp": "^2.0.0", + "home-or-tmp": "^3.0.0", "lodash": "^4.2.0", "mkdirp": "^0.5.1", "source-map-support": "^0.4.2" + }, + "devDependencies": { + "decache": "^4.1.0" } } diff --git a/packages/babel-register/src/cache.js b/packages/babel-register/src/cache.js index 4b08e63ac7..204ac04019 100644 --- a/packages/babel-register/src/cache.js +++ b/packages/babel-register/src/cache.js @@ -3,18 +3,20 @@ import fs from "fs"; import { sync as mkdirpSync } from "mkdirp"; import homeOrTmp from "home-or-tmp"; -const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json"); -let data = {}; +const FILENAME: string = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json"); +let data: Object = {}; /** * Write stringified cache to disk. */ export function save() { - let serialised = {}; + let serialised: string = "{}"; + try { serialised = JSON.stringify(data, null, " "); } catch (err) { + if (err.message === "Invalid string length") { err.message = "Cache too large so it's been cleared."; console.error(err.stack); @@ -22,6 +24,7 @@ export function save() { throw err; } } + mkdirpSync(path.dirname(FILENAME)); fs.writeFileSync(FILENAME, serialised); } @@ -49,6 +52,6 @@ export function load() { * Retrieve data from cache. */ -export function get() { +export function get(): Object { return data; } diff --git a/packages/babel-register/src/node.js b/packages/babel-register/src/node.js index 91edc8c65b..a98d593bcc 100644 --- a/packages/babel-register/src/node.js +++ b/packages/babel-register/src/node.js @@ -3,39 +3,38 @@ import sourceMapSupport from "source-map-support"; import * as registerCache from "./cache"; import extend from "lodash/extend"; import * as babel from "babel-core"; -import each from "lodash/each"; import { util, OptionManager } from "babel-core"; import fs from "fs"; import path from "path"; sourceMapSupport.install({ handleUncaughtExceptions: false, - environment : "node", + environment: "node", retrieveSourceMap(source) { - let map = maps && maps[source]; + const map = maps && maps[source]; if (map) { return { url: null, - map: map + map: map, }; } else { return null; } - } + }, }); registerCache.load(); let cache = registerCache.get(); -let transformOpts = {}; +const transformOpts = {}; let ignore; let only; -let oldHandlers = {}; -let maps = {}; +let oldHandlers = {}; +const maps = {}; -let cwd = process.cwd(); +const cwd = process.cwd(); function getRelativePath(filename) { return path.relative(cwd, filename); @@ -49,7 +48,7 @@ function compile(filename) { let result; // merge in base options and resolve all the plugins and presets relative to this file - let opts = new OptionManager().init(extend( + const opts = new OptionManager().init(extend( { sourceRoot: path.dirname(filename) }, // sourceRoot can be overwritten deepClone(transformOpts), { filename } @@ -57,11 +56,11 @@ function compile(filename) { let cacheKey = `${JSON.stringify(opts)}:${babel.version}`; - let env = process.env.BABEL_ENV || process.env.NODE_ENV; + const env = process.env.BABEL_ENV || process.env.NODE_ENV; if (env) cacheKey += `:${env}`; if (cache) { - let cached = cache[cacheKey]; + const cached = cache[cacheKey]; if (cached && cached.mtime === mtime(filename)) { result = cached; } @@ -73,7 +72,7 @@ function compile(filename) { // calls above and would introduce duplicates. babelrc: false, sourceMaps: "both", - ast: false + ast: false, })); } @@ -100,7 +99,7 @@ function loader(m, filename) { } function registerExtension(ext) { - let old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"]; + const old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"]; require.extensions[ext] = function (m, filename) { if (shouldIgnore(filename)) { @@ -112,7 +111,8 @@ function registerExtension(ext) { } function hookExtensions(_exts) { - each(oldHandlers, function (old, ext) { + Object.keys(oldHandlers).forEach(function (ext) { + const old = oldHandlers[ext]; if (old === undefined) { delete require.extensions[ext]; } else { @@ -122,7 +122,7 @@ function hookExtensions(_exts) { oldHandlers = {}; - each(_exts, function (ext) { + _exts.forEach(function (ext) { oldHandlers[ext] = require.extensions[ext]; registerExtension(ext); }); diff --git a/packages/babel-register/test/index.js b/packages/babel-register/test/index.js new file mode 100644 index 0000000000..e736f3e484 --- /dev/null +++ b/packages/babel-register/test/index.js @@ -0,0 +1,84 @@ +import { expect } from "chai"; +import fs from "fs"; +import path from "path"; +import decache from "decache"; + +const testCacheFilename = path.join(__dirname, ".babel"); +const oldBabelDisableCacheValue = process.env.BABEL_DISABLE_CACHE; + +process.env.BABEL_CACHE_PATH = testCacheFilename; +delete process.env.BABEL_DISABLE_CACHE; + +function writeCache(data) { + if (typeof data === "object") { + data = JSON.stringify(data); + } + + fs.writeFileSync(testCacheFilename, data); +} + +function cleanCache() { + + try { + fs.unlinkSync(testCacheFilename); + } catch (e) { + // It is convenient to always try to clear + } +} + +function resetCache() { + process.env.BABEL_CACHE_PATH = null; + process.env.BABEL_DISABLE_CACHE = oldBabelDisableCacheValue; +} + +describe("babel register", () => { + + describe("cache", () => { + let load, get, save; + + beforeEach(() => { + // Since lib/cache is a singleton we need to fully reload it + decache("../lib/cache"); + const cache = require("../lib/cache"); + + load = cache.load; + get = cache.get; + save = cache.save; + }); + + afterEach(cleanCache); + after(resetCache); + + it("should load and get cached data", () => { + writeCache({ foo: "bar" }); + + load(); + + expect(get()).to.be.an("object"); + expect(get()).to.deep.equal({ foo: "bar" }); + }); + + it("should load and get an object with no cached data", () => { + load(); + + expect(get()).to.be.an("object"); + expect(get()).to.deep.equal({}); + }); + + it("should load and get an object with invalid cached data", () => { + writeCache("foobar"); + + load(); + + expect(get()).to.be.an("object"); + expect(get()).to.deep.equal({}); + }); + + it("should create the cache on save", () => { + save(); + + expect(fs.existsSync(testCacheFilename)).to.be.true; + expect(get()).to.deep.equal({}); + }); + }); +}); diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 73eb96ec15..92d0356d59 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -1,6 +1,6 @@ { "name": "babel-runtime", - "version": "6.20.0", + "version": "7.0.0-alpha.1", "description": "babel selfContained runtime", "license": "MIT", "repository": "https://github.com/babel/babel/tree/master/packages/babel-runtime", @@ -10,7 +10,7 @@ "regenerator-runtime": "^0.10.0" }, "devDependencies": { - "babel-helpers": "^6.6.0", - "babel-plugin-transform-runtime": "^6.9.0" + "babel-helpers": "7.0.0-alpha.1", + "babel-plugin-transform-runtime": "7.0.0-alpha.1" } } diff --git a/packages/babel-runtime/scripts/build-dist.js b/packages/babel-runtime/scripts/build-dist.js index 25799b68c6..050aa73b21 100644 --- a/packages/babel-runtime/scripts/build-dist.js +++ b/packages/babel-runtime/scripts/build-dist.js @@ -1,36 +1,28 @@ var outputFile = require("output-file-sync"); -var each = require("lodash/each"); +var kebabCase = require("lodash/kebabCase"); var fs = require("fs"); -var _ = require("lodash"); var coreDefinitions = require("babel-plugin-transform-runtime").definitions; var paths = ["is-iterable", "get-iterator"]; -each(coreDefinitions.builtins, function (path) { +Object.keys(coreDefinitions.builtins).forEach(function (key) { + const path = coreDefinitions.builtins[key]; paths.push(path); }); -each(coreDefinitions.methods, function (props) { - each(props, function (path) { +Object.keys(coreDefinitions.methods).forEach(function (key) { + const props = coreDefinitions.methods[key]; + Object.keys(props).forEach(function (key2) { + const path = props[key2]; paths.push(path); }); }); -each(paths, function (path) { +paths.forEach(function (path) { writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")')); }); -// Should be removed in the next major release: -var legacy = { - "string/pad-left": "string/pad-start", - "string/pad-right": "string/pad-end" -}; - -each(legacy, function (value, key) { - writeFile("core-js/" + key + ".js", defaultify('require("core-js/library/fn/' + value + '")')); -}); - var helpers = require("babel-helpers"); var babel = require("../../babel-core"); var util = require("../../babel-core/lib/util"); @@ -40,16 +32,6 @@ function relative(filename) { return __dirname + "/../" + filename; } -function readFile(filename, shouldDefaultify) { - var file = fs.readFileSync(require.resolve(filename), "utf8"); - - if (shouldDefaultify) { - file += "\n" + defaultify("module.exports") + "\n"; - } - - return file; -} - function defaultify(name) { return 'module.exports = { "default": ' + name + ', __esModule: true };'; } @@ -71,15 +53,15 @@ var transformOpts = { plugins: [ require("../../babel-plugin-transform-runtime"), - [require("../../babel-plugin-transform-es2015-modules-commonjs"), {loose: true, strict: false}] + [require("../../babel-plugin-transform-es2015-modules-commonjs"), { loose: true, strict: false }] ] }; function buildRuntimeRewritePlugin(relativePath, helperName) { return { - pre: function (file){ + pre: function (file) { var original = file.get("helperGenerator"); - file.set("helperGenerator", function(name){ + file.set("helperGenerator", function(name) { // make sure that helpers won't insert circular references to themselves if (name === helperName) return; @@ -100,13 +82,6 @@ function buildRuntimeRewritePlugin(relativePath, helperName) { }; } -function selfContainify(path, code) { - return babel.transform(code, { - presets: transformOpts.presets, - plugins: transformOpts.plugins.concat([buildRuntimeRewritePlugin(path, null)]) - }).code; -} - function buildHelper(helperName) { var tree = t.program([ t.exportDefaultDeclaration(helpers.get(helperName)) @@ -118,11 +93,11 @@ function buildHelper(helperName) { }).code; } -each(helpers.list, function (helperName) { +helpers.list.forEach(function (helperName) { writeFile("helpers/" + helperName + ".js", buildHelper(helperName)); // compat - var helperAlias = _.kebabCase(helperName); + var helperAlias = kebabCase(helperName); var content = "module.exports = require(\"./" + helperName + ".js\");"; writeFile("helpers/_" + helperAlias + ".js", content); if (helperAlias !== helperName) writeFile("helpers/" + helperAlias + ".js", content); diff --git a/packages/babel-template/README.md b/packages/babel-template/README.md index 9eeb0adf3f..c73507af59 100644 --- a/packages/babel-template/README.md +++ b/packages/babel-template/README.md @@ -13,24 +13,24 @@ npm install --save-dev babel-template ## Usage ```js -import template from 'babel-template'; -import generate from 'babel-generator'; -import * as t from 'babel-types'; +import template from "babel-template"; +import generate from "babel-generator"; +import * as t from "babel-types"; const buildRequire = template(` var IMPORT_NAME = require(SOURCE); `); const ast = buildRequire({ - IMPORT_NAME: t.identifier('myModule'), - SOURCE: t.stringLiteral('my-module') + IMPORT_NAME: t.identifier("myModule"), + SOURCE: t.stringLiteral("my-module") }); console.log(generate(ast).code); ``` ```js -var myModule = require('my-module'); +const myModule = require("my-module"); ``` ## API diff --git a/packages/babel-template/package.json b/packages/babel-template/package.json index 4446d9c5d0..8bb096ea95 100644 --- a/packages/babel-template/package.json +++ b/packages/babel-template/package.json @@ -1,6 +1,6 @@ { "name": "babel-template", - "version": "6.16.0", + "version": "7.0.0-alpha.1", "description": "Generate an AST from a string template.", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,10 +8,9 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-template", "main": "lib/index.js", "dependencies": { - "babylon": "^6.11.0", - "babel-traverse": "^6.16.0", - "babel-types": "^6.16.0", - "babel-runtime": "^6.9.0", + "babylon": "7.0.0-beta.4", + "babel-traverse": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", "lodash": "^4.2.0" } } diff --git a/packages/babel-template/src/index.js b/packages/babel-template/src/index.js index 5413e5d6ab..3b33f1247a 100644 --- a/packages/babel-template/src/index.js +++ b/packages/babel-template/src/index.js @@ -1,21 +1,19 @@ -/* eslint max-len: 0 */ - import cloneDeep from "lodash/cloneDeep"; -import assign from "lodash/assign"; import has from "lodash/has"; import traverse from "babel-traverse"; import * as babylon from "babylon"; import * as t from "babel-types"; -let FROM_TEMPLATE = "_fromTemplate"; //Symbol(); // todo: probably wont get copied over -let TEMPLATE_SKIP = Symbol(); +const FROM_TEMPLATE = "_fromTemplate"; //Symbol(); // todo: probably wont get copied over +const TEMPLATE_SKIP = Symbol(); export default function (code: string, opts?: Object): Function { // since we lazy parse the template, we get the current stack so we have the // original stack to append if it errors when parsing let stack; try { - // error stack gets populated in IE only on throw (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx) + // error stack gets populated in IE only on throw + // (https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx) throw new Error(); } catch (error) { if (error.stack) { @@ -24,7 +22,7 @@ export default function (code: string, opts?: Object): Function { } } - opts = assign({ + opts = Object.assign({ allowReturnOutsideFunction: true, allowSuperOutsideMethod: true, preserveComments: false, @@ -36,7 +34,7 @@ export default function (code: string, opts?: Object): Function { try { ast = babylon.parse(code, opts); - ast = traverse.removeProperties(ast, {preserveComments: opts.preserveComments}); + ast = traverse.removeProperties(ast, { preserveComments: opts.preserveComments }); traverse.cheap(ast, function (node) { node[FROM_TEMPLATE] = true; @@ -60,7 +58,7 @@ export default function (code: string, opts?: Object): Function { function useTemplate(ast, nodes?: Array) { ast = cloneDeep(ast); - let { program } = ast; + const { program } = ast; if (nodes.length) { traverse(ast, templateVisitor, null, nodes); @@ -73,7 +71,7 @@ function useTemplate(ast, nodes?: Array) { } } -let templateVisitor = { +const templateVisitor = { // 360 noScope: true, @@ -91,7 +89,7 @@ let templateVisitor = { if (has(args[0], node.name)) { replacement = args[0][node.name]; } else if (node.name[0] === "$") { - let i = +node.name.slice(1); + const i = +node.name.slice(1); if (args[i]) replacement = args[i]; } } @@ -108,6 +106,6 @@ let templateVisitor = { exit({ node }) { if (!node.loc) - traverse.clearNode(node); - } + {traverse.clearNode(node);} + }, }; diff --git a/packages/babel-template/test/index.js b/packages/babel-template/test/index.js index f64090e4a8..216d6a8939 100644 --- a/packages/babel-template/test/index.js +++ b/packages/babel-template/test/index.js @@ -1,8 +1,8 @@ -let generator = require("../../babel-generator").default; -let template = require("../lib"); -let chai = require("chai"); +import generator from "../../babel-generator"; +import template from "../lib"; +import chai from "chai"; -let comments = "// Sum two numbers\nconst add = (a, b) => a + b;"; +const comments = "// Sum two numbers\nconst add = (a, b) => a + b;"; describe("templating", function () { it("import statement will cause parser to throw by default", function () { @@ -13,18 +13,18 @@ describe("templating", function () { it("import statements are allowed with sourceType: module", function () { chai.expect(function () { - template("import foo from 'foo'", {sourceType: "module"})({}); + template("import foo from 'foo'", { sourceType: "module" })({}); }).not.to.throw(); }); it("should strip comments by default", function () { - let code = "const add = (a, b) => a + b;"; - let output = template(comments)(); + const code = "const add = (a, b) => a + b;"; + const output = template(comments)(); chai.expect(generator(output).code).to.be.equal(code); }); it("should preserve comments with a flag", function () { - let output = template(comments, {preserveComments: true})(); + const output = template(comments, { preserveComments: true })(); chai.expect(generator(output).code).to.be.equal(comments); }); }); diff --git a/packages/babel-traverse/package.json b/packages/babel-traverse/package.json index f88baac088..565159e53e 100644 --- a/packages/babel-traverse/package.json +++ b/packages/babel-traverse/package.json @@ -1,6 +1,6 @@ { "name": "babel-traverse", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,14 +8,16 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse", "main": "lib/index.js", "dependencies": { - "babel-code-frame": "^6.20.0", - "babel-messages": "^6.8.0", - "babel-runtime": "^6.20.0", - "babel-types": "^6.21.0", - "babylon": "^6.11.0", + "babel-code-frame": "7.0.0-alpha.1", + "babel-messages": "7.0.0-alpha.1", + "babel-types": "7.0.0-alpha.1", + "babylon": "7.0.0-beta.4", "debug": "^2.2.0", "globals": "^9.0.0", "invariant": "^2.2.0", "lodash": "^4.2.0" + }, + "devDependencies": { + "babel-generator": "7.0.0-alpha.1" } } diff --git a/packages/babel-traverse/src/context.js b/packages/babel-traverse/src/context.js index b73ff3f7bf..59ac4817c4 100644 --- a/packages/babel-traverse/src/context.js +++ b/packages/babel-traverse/src/context.js @@ -1,14 +1,14 @@ import NodePath from "./path"; import * as t from "babel-types"; -let testing = process.env.NODE_ENV === "test"; +const testing = process.env.NODE_ENV === "test"; export default class TraversalContext { constructor(scope, opts, state, parentPath) { this.parentPath = parentPath; - this.scope = scope; - this.state = state; - this.opts = opts; + this.scope = scope; + this.state = state; + this.opts = opts; } parentPath: NodePath; @@ -23,18 +23,18 @@ export default class TraversalContext { */ shouldVisit(node): boolean { - let opts = this.opts; + const opts = this.opts; if (opts.enter || opts.exit) return true; // check if we have a visitor for this node if (opts[node.type]) return true; // check if we're going to traverse into this node - let keys: ?Array = t.VISITOR_KEYS[node.type]; + const keys: ?Array = t.VISITOR_KEYS[node.type]; if (!keys || !keys.length) return false; // we need to traverse into this node so ensure that it has children to traverse into! - for (let key of keys) { + for (const key of keys) { if (node[key]) return true; } @@ -47,7 +47,7 @@ export default class TraversalContext { parent: node, container: obj, key: key, - listKey + listKey, }); } @@ -69,11 +69,11 @@ export default class TraversalContext { // nothing to traverse! if (container.length === 0) return false; - let queue = []; + const queue = []; // build up initial queue for (let key = 0; key < container.length; key++) { - let node = container[key]; + const node = container[key]; if (node && this.shouldVisit(node)) { queue.push(this.create(parent, container, key, listKey)); } @@ -85,7 +85,7 @@ export default class TraversalContext { visitSingle(node, key): boolean { if (this.shouldVisit(node[key])) { return this.visitQueue([ - this.create(node, node, key) + this.create(node, node, key), ]); } else { return false; @@ -97,11 +97,11 @@ export default class TraversalContext { this.queue = queue; this.priorityQueue = []; - let visited = []; + const visited = []; let stop = false; // visit the queue - for (let path of queue) { + for (const path of queue) { path.resync(); if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) { @@ -136,7 +136,7 @@ export default class TraversalContext { } // clear queue - for (let path of queue) { + for (const path of queue) { path.popContext(); } @@ -147,7 +147,7 @@ export default class TraversalContext { } visit(node, key) { - let nodes = node[key]; + const nodes = node[key]; if (!nodes) return false; if (Array.isArray(nodes)) { diff --git a/packages/babel-traverse/src/index.js b/packages/babel-traverse/src/index.js index 6a3d4660a4..1293dff45e 100644 --- a/packages/babel-traverse/src/index.js +++ b/packages/babel-traverse/src/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import TraversalContext from "./context"; import * as visitors from "./visitors"; import * as messages from "babel-messages"; @@ -38,19 +36,26 @@ traverse.verify = visitors.verify; traverse.explode = visitors.explode; traverse.NodePath = require("./path"); -traverse.Scope = require("./scope"); -traverse.Hub = require("./hub"); +traverse.Scope = require("./scope"); +traverse.Hub = require("./hub"); traverse.cheap = function (node, enter) { return t.traverseFast(node, enter); }; -traverse.node = function (node: Object, opts: Object, scope: Object, state: Object, parentPath: Object, skipKeys?) { - let keys: Array = t.VISITOR_KEYS[node.type]; +traverse.node = function ( + node: Object, + opts: Object, + scope: Object, + state: Object, + parentPath: Object, + skipKeys? +) { + const keys: Array = t.VISITOR_KEYS[node.type]; if (!keys) return; - let context = new TraversalContext(scope, opts, state, parentPath); - for (let key of keys) { + const context = new TraversalContext(scope, opts, state, parentPath); + for (const key of keys) { if (skipKeys && skipKeys[key]) continue; if (context.visit(node, key)) return; } @@ -74,21 +79,26 @@ function hasBlacklistedType(path, state) { } } -traverse.hasType = function (tree: Object, scope: Object, type: Object, blacklistTypes: Array): boolean { +traverse.hasType = function ( + tree: Object, + scope: Object, + type: Object, + blacklistTypes: Array +): boolean { // the node we're searching in is blacklisted if (includes(blacklistTypes, tree.type)) return false; // the type we're looking for is the same as the passed node if (tree.type === type) return true; - let state = { - has: false, - type: type + const state = { + has: false, + type: type, }; traverse(tree, { blacklist: blacklistTypes, - enter: hasBlacklistedType + enter: hasBlacklistedType, }, scope, state); return state.has; diff --git a/packages/babel-traverse/src/path/ancestry.js b/packages/babel-traverse/src/path/ancestry.js index 35fb7b3435..245910aa6a 100644 --- a/packages/babel-traverse/src/path/ancestry.js +++ b/packages/babel-traverse/src/path/ancestry.js @@ -60,10 +60,10 @@ export function getStatementParent() { export function getEarliestCommonAncestorFrom(paths: Array): NodePath { return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) { let earliest; - let keys = t.VISITOR_KEYS[deepest.type]; + const keys = t.VISITOR_KEYS[deepest.type]; - for (let ancestry of (ancestries: Array)) { - let path = ancestry[i + 1]; + for (const ancestry of (ancestries: Array)) { + const path = ancestry[i + 1]; // first path if (!earliest) { @@ -81,8 +81,8 @@ export function getEarliestCommonAncestorFrom(paths: Array): NodePath } // handle keys - let earliestKeyIndex = keys.indexOf(earliest.parentKey); - let currentKeyIndex = keys.indexOf(path.parentKey); + const earliestKeyIndex = keys.indexOf(earliest.parentKey); + const currentKeyIndex = keys.indexOf(path.parentKey); if (earliestKeyIndex > currentKeyIndex) { // key appears before so it's earlier earliest = path; @@ -115,8 +115,8 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu let lastCommonIndex, lastCommon; // get the ancestors of the path, breaking when the parent exceeds ourselves - let ancestries = paths.map((path) => { - let ancestry = []; + const ancestries = paths.map((path) => { + const ancestry = []; do { ancestry.unshift(path); @@ -131,13 +131,13 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu }); // get the first ancestry so we have a seed to assess all other ancestries with - let first = ancestries[0]; + const first = ancestries[0]; // check ancestor equality depthLoop: for (let i = 0; i < minDepth; i++) { - let shouldMatch = first[i]; + const shouldMatch = first[i]; - for (let ancestry of (ancestries: Array)) { + for (const ancestry of (ancestries: Array)) { if (ancestry[i] !== shouldMatch) { // we've hit a snag break depthLoop; @@ -168,7 +168,7 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu export function getAncestry() { let path = this; - let paths = []; + const paths = []; do { paths.push(path); } while (path = path.parentPath); @@ -192,7 +192,7 @@ export function isDescendant(maybeAncestor) { export function inType() { let path = this; while (path) { - for (let type of (arguments: Array)) { + for (const type of (arguments: Array)) { if (path.node.type === type) return true; } path = path.parentPath; @@ -235,11 +235,11 @@ export function inType() { */ export function inShadow(key?) { - let parentFn = this.isFunction() ? this : this.findParent((p) => p.isFunction()); + const parentFn = this.isFunction() ? this : this.findParent((p) => p.isFunction()); if (!parentFn) return; if (parentFn.isFunctionExpression() || parentFn.isFunctionDeclaration()) { - let shadow = parentFn.node.shadow; + const shadow = parentFn.node.shadow; // this is because sometimes we may have a `shadow` value of: // diff --git a/packages/babel-traverse/src/path/comments.js b/packages/babel-traverse/src/path/comments.js index b7f0ae1a07..ab2bda2cec 100644 --- a/packages/babel-traverse/src/path/comments.js +++ b/packages/babel-traverse/src/path/comments.js @@ -8,11 +8,11 @@ export function shareCommentsWithSiblings() { // NOTE: this assumes numbered keys if (typeof this.key === "string") return; - let node = this.node; + const node = this.node; if (!node) return; - let trailing = node.trailingComments; - let leading = node.leadingComments; + const trailing = node.trailingComments; + const leading = node.leadingComments; if (!trailing && !leading) return; let prev = this.getSibling(this.key - 1); @@ -28,7 +28,7 @@ export function shareCommentsWithSiblings() { export function addComment(type, content, line?) { this.addComments(type, [{ type: line ? "CommentLine" : "CommentBlock", - value: content + value: content, }]); } @@ -39,10 +39,10 @@ export function addComment(type, content, line?) { export function addComments(type: string, comments: Array) { if (!comments) return; - let node = this.node; + const node = this.node; if (!node) return; - let key = `${type}Comments`; + const key = `${type}Comments`; if (node[key]) { node[key] = node[key].concat(comments); diff --git a/packages/babel-traverse/src/path/context.js b/packages/babel-traverse/src/path/context.js index 6710171c57..3f393b6680 100644 --- a/packages/babel-traverse/src/path/context.js +++ b/packages/babel-traverse/src/path/context.js @@ -3,7 +3,7 @@ import traverse from "../index"; export function call(key): boolean { - let opts = this.opts; + const opts = this.opts; this.debug(() => key); @@ -21,13 +21,13 @@ export function call(key): boolean { export function _call(fns?: Array): boolean { if (!fns) return false; - for (let fn of fns) { + for (const fn of fns) { if (!fn) continue; - let node = this.node; + const node = this.node; if (!node) return true; - let ret = fn.call(this.state, this, this.state); + const ret = fn.call(this.state, this, this.state); if (ret) throw new Error(`Unexpected return value from visitor method ${fn}`); // node has been replaced, it will have been requeued @@ -40,7 +40,7 @@ export function _call(fns?: Array): boolean { } export function isBlacklisted(): boolean { - let blacklist = this.opts.blacklist; + const blacklist = this.opts.blacklist; return blacklist && blacklist.indexOf(this.node.type) > -1; } @@ -105,13 +105,13 @@ export function setScope() { export function setContext(context) { this.shouldSkip = false; this.shouldStop = false; - this.removed = false; - this.skipKeys = {}; + this.removed = false; + this.skipKeys = {}; if (context) { this.context = context; - this.state = context.state; - this.opts = context.opts; + this.state = context.state; + this.opts = context.opts; } this.setScope(); @@ -155,7 +155,7 @@ export function _resyncKey() { } } } else { - for (let key in this.container) { + for (const key in this.container) { if (this.container[key] === this.node) { return this.setKey(key); } @@ -169,7 +169,7 @@ export function _resyncKey() { export function _resyncList() { if (!this.parent || !this.inList) return; - let newContainer = this.parent[this.listKey]; + const newContainer = this.parent[this.listKey]; if (this.container === newContainer) return; // container is out of sync. this is likely the result of it being reassigned @@ -193,8 +193,8 @@ export function pushContext(context) { } export function setup(parentPath, container, listKey, key) { - this.inList = !!listKey; - this.listKey = listKey; + this.inList = !!listKey; + this.listKey = listKey; this.parentKey = listKey || key; this.container = container; @@ -203,7 +203,7 @@ export function setup(parentPath, container, listKey, key) { } export function setKey(key) { - this.key = key; + this.key = key; this.node = this.container[this.key]; this.type = this.node && this.node.type; } @@ -214,9 +214,9 @@ export function requeue(pathToQueue = this) { // TODO(loganfsmyth): This should be switched back to queue in parent contexts // automatically once #2892 and #4135 have been resolved. See #4140. // let contexts = this._getQueueContexts(); - let contexts = this.contexts; + const contexts = this.contexts; - for (let context of contexts) { + for (const context of contexts) { context.maybeQueue(pathToQueue); } } diff --git a/packages/babel-traverse/src/path/conversion.js b/packages/babel-traverse/src/path/conversion.js index 27079529d7..a9ff22fc64 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -3,7 +3,7 @@ import * as t from "babel-types"; export function toComputedKey(): Object { - let node = this.node; + const node = this.node; let key; if (this.isMemberExpression()) { @@ -31,7 +31,7 @@ export function arrowFunctionToShadowed() { this.ensureBlock(); - let { node } = this; + const { node } = this; node.expression = false; node.type = "FunctionExpression"; node.shadow = node.shadow || true; diff --git a/packages/babel-traverse/src/path/evaluation.js b/packages/babel-traverse/src/path/evaluation.js index 3b41b188c6..f28a1e148e 100644 --- a/packages/babel-traverse/src/path/evaluation.js +++ b/packages/babel-traverse/src/path/evaluation.js @@ -1,12 +1,7 @@ -/* eslint indent: 0 */ -/* eslint max-len: 0 */ - import type NodePath from "./index"; // This file contains Babels metainterpreter that can evaluate static code. -/* eslint eqeqeq: 0 */ - const VALID_CALLEES = ["String", "Number", "Math"]; const INVALID_METHODS = ["random"]; @@ -29,7 +24,7 @@ const INVALID_METHODS = ["random"]; */ export function evaluateTruthy(): boolean { - let res = this.evaluate(); + const res = this.evaluate(); if (res.confident) return !!res.value; } @@ -51,7 +46,7 @@ export function evaluateTruthy(): boolean { export function evaluate(): { confident: boolean; value: any } { let confident = true; let deoptPath: ?NodePath; - let seen = new Map; + const seen = new Map; function deopt(path) { if (!confident) return; @@ -63,8 +58,8 @@ export function evaluate(): { confident: boolean; value: any } { if (!confident) value = undefined; return { confident: confident, - deopt: deoptPath, - value: value + deopt: deoptPath, + value: value, }; // we wrap the _evaluate method so we can track `seen` nodes, we push an item @@ -75,10 +70,10 @@ export function evaluate(): { confident: boolean; value: any } { // a = g * this.foo // function evaluate(path) { - let { node } = path; + const { node } = path; if (seen.has(node)) { - let existing = seen.get(node); + const existing = seen.get(node); if (existing.resolved) { return existing.value; } else { @@ -86,10 +81,10 @@ export function evaluate(): { confident: boolean; value: any } { return; } } else { - let item = { resolved: false }; + const item = { resolved: false }; seen.set(node, item); - let val = _evaluate(path); + const val = _evaluate(path); if (confident) { item.resolved = true; item.value = val; @@ -101,10 +96,10 @@ export function evaluate(): { confident: boolean; value: any } { function _evaluate(path) { if (!confident) return; - let { node } = path; + const { node } = path; if (path.isSequenceExpression()) { - let exprs = path.get("expressions"); + const exprs = path.get("expressions"); return evaluate(exprs[exprs.length - 1]); } @@ -120,9 +115,9 @@ export function evaluate(): { confident: boolean; value: any } { let str = ""; let i = 0; - let exprs = path.get("expressions"); + const exprs = path.get("expressions"); - for (let elem of (node.quasis: Array)) { + for (const elem of (node.quasis: Array)) { // not confident, evaluated an expression we don't like if (!confident) break; @@ -130,7 +125,7 @@ export function evaluate(): { confident: boolean; value: any } { str += elem.value.cooked; // add on interpolated expression if it's present - let expr = exprs[i++]; + const expr = exprs[i++]; if (expr) str += String(evaluate(expr)); } @@ -139,7 +134,7 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isConditionalExpression()) { - let testResult = evaluate(path.get("test")); + const testResult = evaluate(path.get("test")); if (!confident) return; if (testResult) { return evaluate(path.get("consequent")); @@ -154,12 +149,12 @@ export function evaluate(): { confident: boolean; value: any } { // "foo".length if (path.isMemberExpression() && !path.parentPath.isCallExpression({ callee: node })) { - let property = path.get("property"); - let object = path.get("object"); + const property = path.get("property"); + const object = path.get("object"); if (object.isLiteral() && property.isIdentifier()) { - let value = object.node.value; - let type = typeof value; + const value = object.node.value; + const type = typeof value; if (type === "number" || type === "string") { return value[property.node.name]; } @@ -167,7 +162,7 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isReferencedIdentifier()) { - let binding = path.scope.getBinding(node.name); + const binding = path.scope.getBinding(node.name); if (binding && binding.constantViolations.length > 0) { return deopt(binding.path); @@ -181,14 +176,14 @@ export function evaluate(): { confident: boolean; value: any } { return binding.value; } else { if (node.name === "undefined") { - return undefined; + return binding ? deopt(binding.path) : undefined; } else if (node.name === "Infinity") { - return Infinity; + return binding ? deopt(binding.path) : Infinity; } else if (node.name === "NaN") { - return NaN; + return binding ? deopt(binding.path) : NaN; } - let resolved = path.resolve(); + const resolved = path.resolve(); if (resolved === path) { return deopt(path); } else { @@ -203,12 +198,12 @@ export function evaluate(): { confident: boolean; value: any } { return undefined; } - let argument = path.get("argument"); + const argument = path.get("argument"); if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { return "function"; } - let arg = evaluate(argument); + const arg = evaluate(argument); if (!confident) return; switch (node.operator) { case "!": return !arg; @@ -220,8 +215,8 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isArrayExpression()) { - let arr = []; - let elems: Array = path.get("elements"); + const arr = []; + const elems: Array = path.get("elements"); for (let elem of elems) { elem = elem.evaluate(); @@ -235,10 +230,10 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isObjectExpression()) { - let obj = {}; - let props: Array = path.get("properties"); - for (let prop of props) { - if (prop.isObjectMethod() || prop.isSpreadProperty()) { + const obj = {}; + const props: Array = path.get("properties"); + for (const prop of props) { + if (prop.isObjectMethod() || prop.isSpreadElement()) { return deopt(prop); } const keyPath = prop.get("key"); @@ -268,12 +263,12 @@ export function evaluate(): { confident: boolean; value: any } { if (path.isLogicalExpression()) { // If we are confident that one side of an && is false, or the left // side of an || is true, we can be confident about the entire expression - let wasConfident = confident; - let left = evaluate(path.get("left")); - let leftConfident = confident; + const wasConfident = confident; + const left = evaluate(path.get("left")); + const leftConfident = confident; confident = wasConfident; - let right = evaluate(path.get("right")); - let rightConfident = confident; + const right = evaluate(path.get("right")); + const rightConfident = confident; confident = leftConfident && rightConfident; switch (node.operator) { @@ -300,9 +295,9 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isBinaryExpression()) { - let left = evaluate(path.get("left")); + const left = evaluate(path.get("left")); if (!confident) return; - let right = evaluate(path.get("right")); + const right = evaluate(path.get("right")); if (!confident) return; switch (node.operator) { @@ -316,7 +311,7 @@ export function evaluate(): { confident: boolean; value: any } { case ">": return left > right; case "<=": return left <= right; case ">=": return left >= right; - case "==": return left == right; + case "==": return left == right; // eslint-disable-line eqeqeq case "!=": return left != right; case "===": return left === right; case "!==": return left !== right; @@ -330,28 +325,35 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isCallExpression()) { - let callee = path.get("callee"); + const callee = path.get("callee"); let context; let func; // Number(1); - if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { + if ( + callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && + VALID_CALLEES.indexOf(callee.node.name) >= 0 + ) { func = global[node.callee.name]; } if (callee.isMemberExpression()) { - let object = callee.get("object"); - let property = callee.get("property"); + const object = callee.get("object"); + const property = callee.get("property"); // Math.min(1, 2) - if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) { + if ( + object.isIdentifier() && property.isIdentifier() && + VALID_CALLEES.indexOf(object.node.name) >= 0 && + INVALID_METHODS.indexOf(property.node.name) < 0 + ) { context = global[object.node.name]; func = context[property.node.name]; } // "abc".charCodeAt(4) if (object.isLiteral() && property.isIdentifier()) { - let type = typeof object.node.value; + const type = typeof object.node.value; if (type === "string" || type === "number") { context = object.node.value; func = context[property.node.name]; @@ -360,7 +362,7 @@ export function evaluate(): { confident: boolean; value: any } { } if (func) { - let args = path.get("arguments").map(evaluate); + const args = path.get("arguments").map(evaluate); if (!confident) return; return func.apply(context, args); diff --git a/packages/babel-traverse/src/path/family.js b/packages/babel-traverse/src/path/family.js index f7a630d0a7..f1fe88dd54 100644 --- a/packages/babel-traverse/src/path/family.js +++ b/packages/babel-traverse/src/path/family.js @@ -33,7 +33,7 @@ export function getOpposite() { export function getCompletionRecords(): Array { let paths = []; - let add = function (path) { + const add = function (path) { if (path) paths = paths.concat(path.getCompletionRecords()); }; @@ -57,19 +57,49 @@ export function getCompletionRecords(): Array { return paths; } -export function getSibling(key) { +export function getSibling(key): NodePath { return NodePath.get({ parentPath: this.parentPath, parent: this.parent, container: this.container, listKey: this.listKey, - key: key + key: key, }); } +export function getPrevSibling(): NodePath { + return this.getSibling(this.key - 1); +} + +export function getNextSibling(): NodePath { + return this.getSibling(this.key + 1); +} + +export function getAllNextSiblings(): Array { + let _key = this.key; + let sibling:NodePath = this.getSibling(++_key); + const siblings:Array = []; + while (sibling.node) { + siblings.push(sibling); + sibling = this.getSibling(++_key); + } + return siblings; +} + +export function getAllPrevSiblings(): Array { + let _key = this.key; + let sibling:NodePath = this.getSibling(--_key); + const siblings:Array = []; + while (sibling.node) { + siblings.push(sibling); + sibling = this.getSibling(--_key); + } + return siblings; +} + export function get(key: string, context?: boolean | TraversalContext): NodePath { if (context === true) context = this.context; - let parts = key.split("."); + const parts = key.split("."); if (parts.length === 1) { // "foo" return this._getKey(key, context); } else { // "foo.bar" @@ -78,8 +108,8 @@ export function get(key: string, context?: boolean | TraversalContext): NodePath } export function _getKey(key, context?) { - let node = this.node; - let container = node[key]; + const node = this.node; + const container = node[key]; if (Array.isArray(container)) { // requested a container so give them all the paths @@ -89,7 +119,7 @@ export function _getKey(key, context?) { parentPath: this, parent: node, container: container, - key: i + key: i, }).setContext(context); }); } else { @@ -97,14 +127,14 @@ export function _getKey(key, context?) { parentPath: this, parent: node, container: node, - key: key + key: key, }).setContext(context); } } export function _getPattern(parts, context) { let path = this; - for (let part of (parts: Array)) { + for (const part of (parts: Array)) { if (part === ".") { path = path.parentPath; } else { @@ -130,20 +160,20 @@ export function getOuterBindingIdentifiers(duplicates?) { // path.getBindingIdentifiers returns nodes where the following re-implementation // returns paths export function getBindingIdentifierPaths(duplicates = false, outerOnly = false) { - let path = this; + const path = this; let search = [].concat(path); - let ids = Object.create(null); + const ids = Object.create(null); while (search.length) { - let id = search.shift(); + const id = search.shift(); if (!id) continue; if (!id.node) continue; - let keys = t.getBindingIdentifiers.keys[id.node.type]; + const keys = t.getBindingIdentifiers.keys[id.node.type]; if (id.isIdentifier()) { if (duplicates) { - let _ids = ids[id.node.name] = ids[id.node.name] || []; + const _ids = ids[id.node.name] = ids[id.node.name] || []; _ids.push(id); } else { ids[id.node.name] = id; @@ -171,8 +201,8 @@ export function getBindingIdentifierPaths(duplicates = false, outerOnly = false) if (keys) { for (let i = 0; i < keys.length; i++) { - let key = keys[i]; - let child = id.get(key); + const key = keys[i]; + const child = id.get(key); if (Array.isArray(child) || child.node) { search = search.concat(child); } diff --git a/packages/babel-traverse/src/path/index.js b/packages/babel-traverse/src/path/index.js index 1b5b589190..b5bdba44a4 100644 --- a/packages/babel-traverse/src/path/index.js +++ b/packages/babel-traverse/src/path/index.js @@ -1,17 +1,27 @@ -/* eslint max-len: 0 */ - import type Hub from "../hub"; import type TraversalContext from "../context"; import * as virtualTypes from "./lib/virtual-types"; import buildDebug from "debug"; import invariant from "invariant"; import traverse from "../index"; -import assign from "lodash/assign"; import Scope from "../scope"; import * as t from "babel-types"; import { path as pathCache } from "../cache"; -let debug = buildDebug("babel"); +// NodePath is split across many files. +import * as NodePath_ancestry from "./ancestry"; +import * as NodePath_inference from "./inference"; +import * as NodePath_replacement from "./replacement"; +import * as NodePath_evaluation from "./evaluation"; +import * as NodePath_conversion from "./conversion"; +import * as NodePath_introspection from "./introspection"; +import * as NodePath_context from "./context"; +import * as NodePath_removal from "./removal"; +import * as NodePath_modification from "./modification"; +import * as NodePath_family from "./family"; +import * as NodePath_comments from "./comments"; + +const debug = buildDebug("babel"); export default class NodePath { constructor(hub: Hub, parent: Object) { @@ -67,9 +77,9 @@ export default class NodePath { invariant(parent, "To get a node path the parent needs to exist"); - let targetNode = container[key]; + const targetNode = container[key]; - let paths = pathCache.get(parent) || []; + const paths = pathCache.get(parent) || []; if (!pathCache.has(parent)) { pathCache.set(parent, paths); } @@ -77,7 +87,7 @@ export default class NodePath { let path; for (let i = 0; i < paths.length; i++) { - let pathCheck = paths[i]; + const pathCheck = paths[i]; if (pathCheck.node === targetNode) { path = pathCheck; break; @@ -127,7 +137,7 @@ export default class NodePath { this.hub.file.metadata.marked.push({ type, message, - loc: this.node.loc + loc: this.node.loc, }); } @@ -137,7 +147,7 @@ export default class NodePath { } getPathLocation(): string { - let parts = []; + const parts = []; let path = this; do { let key = path.key; @@ -153,20 +163,21 @@ export default class NodePath { } } -assign(NodePath.prototype, require("./ancestry")); -assign(NodePath.prototype, require("./inference")); -assign(NodePath.prototype, require("./replacement")); -assign(NodePath.prototype, require("./evaluation")); -assign(NodePath.prototype, require("./conversion")); -assign(NodePath.prototype, require("./introspection")); -assign(NodePath.prototype, require("./context")); -assign(NodePath.prototype, require("./removal")); -assign(NodePath.prototype, require("./modification")); -assign(NodePath.prototype, require("./family")); -assign(NodePath.prototype, require("./comments")); +Object.assign(NodePath.prototype, + NodePath_ancestry, + NodePath_inference, + NodePath_replacement, + NodePath_evaluation, + NodePath_conversion, + NodePath_introspection, + NodePath_context, + NodePath_removal, + NodePath_modification, + NodePath_family, + NodePath_comments); -for (let type of (t.TYPES: Array)) { - let typeKey = `is${type}`; +for (const type of (t.TYPES: Array)) { + const typeKey = `is${type}`; NodePath.prototype[typeKey] = function (opts) { return t[typeKey](this.node, opts); }; @@ -178,11 +189,11 @@ for (let type of (t.TYPES: Array)) { }; } -for (let type in virtualTypes) { +for (const type in virtualTypes) { if (type[0] === "_") continue; if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type); - let virtualType = virtualTypes[type]; + const virtualType = virtualTypes[type]; NodePath.prototype[`is${type}`] = function (opts) { return virtualType.checkPath(this, opts); diff --git a/packages/babel-traverse/src/path/inference/index.js b/packages/babel-traverse/src/path/inference/index.js index 55a52911a6..c782b2779f 100644 --- a/packages/babel-traverse/src/path/inference/index.js +++ b/packages/babel-traverse/src/path/inference/index.js @@ -19,13 +19,13 @@ export function getTypeAnnotation(): Object { */ export function _getTypeAnnotation(): ?Object { - let node = this.node; + const node = this.node; if (!node) { // handle initializerless variables, add in checks for loop initializers too if (this.key === "init" && this.parentPath.isVariableDeclarator()) { - let declar = this.parentPath.parentPath; - let declarParent = declar.parentPath; + const declar = this.parentPath.parentPath; + const declarParent = declar.parentPath; // for (let NODE in bar) {} if (declar.key === "left" && declarParent.isForInStatement()) { @@ -87,11 +87,11 @@ function _isBaseType(baseName: string, type?, soft?): boolean { } export function couldBeBaseType(name: string): boolean { - let type = this.getTypeAnnotation(); + const type = this.getTypeAnnotation(); if (t.isAnyTypeAnnotation(type)) return true; if (t.isUnionTypeAnnotation(type)) { - for (let type2 of (type.types: Array)) { + for (const type2 of (type.types: Array)) { if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { return true; } @@ -103,7 +103,7 @@ export function couldBeBaseType(name: string): boolean { } export function baseTypeStrictlyMatches(right: NodePath) { - let left = this.getTypeAnnotation(); + const left = this.getTypeAnnotation(); right = right.getTypeAnnotation(); if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { @@ -112,6 +112,6 @@ export function baseTypeStrictlyMatches(right: NodePath) { } export function isGenericType(genericName: string): boolean { - let type = this.getTypeAnnotation(); + const type = this.getTypeAnnotation(); return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { name: genericName }); } diff --git a/packages/babel-traverse/src/path/inference/inferer-reference.js b/packages/babel-traverse/src/path/inference/inferer-reference.js index 4b1d8e58a9..9b95794a75 100644 --- a/packages/babel-traverse/src/path/inference/inferer-reference.js +++ b/packages/babel-traverse/src/path/inference/inferer-reference.js @@ -6,7 +6,7 @@ export default function (node: Object) { // check if a binding exists of this value and if so then return a union type of all // possible types that the binding could be - let binding = this.scope.getBinding(node.name); + const binding = this.scope.getBinding(node.name); if (binding) { if (binding.identifier.typeAnnotation) { return binding.identifier.typeAnnotation; @@ -26,17 +26,17 @@ export default function (node: Object) { } function getTypeAnnotationBindingConstantViolations(path, name) { - let binding = path.scope.getBinding(name); + const binding = path.scope.getBinding(name); - let types = []; + const types = []; path.typeAnnotation = t.unionTypeAnnotation(types); - let functionConstantViolations = []; + const functionConstantViolations = []; let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); - let testType = getConditionalAnnotation(path, name); + const testType = getConditionalAnnotation(path, name); if (testType) { - let testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); + const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); // remove constant violations observed before the IfStatement constantViolations = constantViolations.filter((path) => testConstantViolations.indexOf(path) < 0); @@ -76,7 +76,7 @@ function getTypeAnnotationBindingConstantViolations(path, name) { constantViolations = constantViolations.concat(functionConstantViolations); // push on inferred types of violated paths - for (let violation of (constantViolations: Array)) { + for (const violation of (constantViolations: Array)) { types.push(violation.getTypeAnnotation()); } } @@ -87,21 +87,21 @@ function getTypeAnnotationBindingConstantViolations(path, name) { } function getConstantViolationsBefore(binding, path, functions) { - let violations = binding.constantViolations.slice(); + const violations = binding.constantViolations.slice(); violations.unshift(binding.path); return violations.filter((violation) => { violation = violation.resolve(); - let status = violation._guessExecutionStatusRelativeTo(path); + const status = violation._guessExecutionStatusRelativeTo(path); if (functions && status === "function") functions.push(violation); return status === "before"; }); } function inferAnnotationFromBinaryExpression(name, path) { - let operator = path.node.operator; + const operator = path.node.operator; - let right = path.get("right").resolve(); - let left = path.get("left").resolve(); + const right = path.get("right").resolve(); + const left = path.get("left").resolve(); let target; if (left.isIdentifier({ name })) { @@ -138,7 +138,7 @@ function inferAnnotationFromBinaryExpression(name, path) { if (!typePath.isLiteral()) return; // and that it's a string so we can infer it - let typeValue = typePath.node.value; + const typeValue = typePath.node.value; if (typeof typeValue !== "string") return; // and that the argument of the typeof path references us! @@ -164,15 +164,15 @@ function getParentConditionalPath(path) { } function getConditionalAnnotation(path, name) { - let ifStatement = getParentConditionalPath(path); + const ifStatement = getParentConditionalPath(path); if (!ifStatement) return; - let test = ifStatement.get("test"); - let paths = [test]; - let types = []; + const test = ifStatement.get("test"); + const paths = [test]; + const types = []; do { - let path = paths.shift().resolve(); + const path = paths.shift().resolve(); if (path.isLogicalExpression()) { paths.push(path.get("left")); @@ -180,7 +180,7 @@ function getConditionalAnnotation(path, name) { } if (path.isBinaryExpression()) { - let type = inferAnnotationFromBinaryExpression(name, path); + const type = inferAnnotationFromBinaryExpression(name, path); if (type) types.push(type); } } while (paths.length); @@ -188,7 +188,7 @@ function getConditionalAnnotation(path, name) { if (types.length) { return { typeAnnotation: t.createUnionTypeAnnotation(types), - ifStatement + ifStatement, }; } else { return getConditionalAnnotation(ifStatement, name); diff --git a/packages/babel-traverse/src/path/inference/inferers.js b/packages/babel-traverse/src/path/inference/inferers.js index ec372f6825..da481e4894 100644 --- a/packages/babel-traverse/src/path/inference/inferers.js +++ b/packages/babel-traverse/src/path/inference/inferers.js @@ -3,7 +3,7 @@ import * as t from "babel-types"; export { default as Identifier } from "./inferer-reference"; export function VariableDeclarator() { - let id = this.get("id"); + const id = this.get("id"); if (id.isIdentifier()) { return this.get("init").getTypeAnnotation(); @@ -30,7 +30,7 @@ export function TemplateLiteral() { } export function UnaryExpression(node) { - let operator = node.operator; + const operator = node.operator; if (operator === "void") { return t.voidTypeAnnotation(); @@ -44,15 +44,15 @@ export function UnaryExpression(node) { } export function BinaryExpression(node) { - let operator = node.operator; + const operator = node.operator; if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { return t.numberTypeAnnotation(); } else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) { return t.booleanTypeAnnotation(); } else if (operator === "+") { - let right = this.get("right"); - let left = this.get("left"); + const right = this.get("right"); + const left = this.get("left"); if (left.isBaseType("number") && right.isBaseType("number")) { // both numbers so this will be a number @@ -65,7 +65,7 @@ export function BinaryExpression(node) { // unsure if left and right are strings or numbers so stay on the safe side return t.unionTypeAnnotation([ t.stringTypeAnnotation(), - t.numberTypeAnnotation() + t.numberTypeAnnotation(), ]); } } @@ -73,14 +73,14 @@ export function BinaryExpression(node) { export function LogicalExpression() { return t.createUnionTypeAnnotation([ this.get("left").getTypeAnnotation(), - this.get("right").getTypeAnnotation() + this.get("right").getTypeAnnotation(), ]); } export function ConditionalExpression() { return t.createUnionTypeAnnotation([ this.get("consequent").getTypeAnnotation(), - this.get("alternate").getTypeAnnotation() + this.get("alternate").getTypeAnnotation(), ]); } @@ -93,7 +93,7 @@ export function AssignmentExpression() { } export function UpdateExpression(node) { - let operator = node.operator; + const operator = node.operator; if (operator === "++" || operator === "--") { return t.numberTypeAnnotation(); } @@ -142,7 +142,7 @@ export { Func as ArrowFunctionExpression, Func as FunctionDeclaration, Func as ClassExpression, - Func as ClassDeclaration + Func as ClassDeclaration, }; export function CallExpression() { diff --git a/packages/babel-traverse/src/path/introspection.js b/packages/babel-traverse/src/path/introspection.js index be7a2755c5..9b7e7f9813 100644 --- a/packages/babel-traverse/src/path/introspection.js +++ b/packages/babel-traverse/src/path/introspection.js @@ -15,17 +15,17 @@ export function matchesPattern(pattern: string, allowPartial?: boolean): boolean // not a member expression if (!this.isMemberExpression()) return false; - let parts = pattern.split("."); - let search = [this.node]; + const parts = pattern.split("."); + const search = [this.node]; let i = 0; function matches(name) { - let part = parts[i]; + const part = parts[i]; return part === "*" || name === part; } while (search.length) { - let node = search.shift(); + const node = search.shift(); if (allowPartial && i === parts.length) { return true; @@ -68,7 +68,7 @@ export function matchesPattern(pattern: string, allowPartial?: boolean): boolean */ export function has(key): boolean { - let val = this.node && this.node[key]; + const val = this.node && this.node[key]; if (val && Array.isArray(val)) { return !!val.length; } else { @@ -88,7 +88,7 @@ export function isStatic() { * Alias of `has`. */ -export let is = has; +export const is = has; /** * Opposite of `has`. @@ -160,7 +160,7 @@ export function isCompletionRecord(allowInsideFunction?) { let first = true; do { - let container = path.container; + const container = path.container; // we're in a function so can't be a completion record if (path.isFunction() && !first) { @@ -199,11 +199,11 @@ export function isStatementOrBlock() { export function referencesImport(moduleSource, importName) { if (!this.isReferencedIdentifier()) return false; - let binding = this.scope.getBinding(this.node.name); + const binding = this.scope.getBinding(this.node.name); if (!binding || binding.kind !== "module") return false; - let path = binding.path; - let parent = path.parentPath; + const path = binding.path; + const parent = path.parentPath; if (!parent.isImportDeclaration()) return false; // check moduleSource @@ -233,7 +233,7 @@ export function referencesImport(moduleSource, importName) { */ export function getSource() { - let node = this.node; + const node = this.node; if (node.end) { return this.hub.file.code.slice(node.start, node.end); } else { @@ -254,13 +254,13 @@ export function willIMaybeExecuteBefore(target) { export function _guessExecutionStatusRelativeTo(target) { // check if the two paths are in different functions, we can't track execution of these - let targetFuncParent = target.scope.getFunctionParent(); - let selfFuncParent = this.scope.getFunctionParent(); + const targetFuncParent = target.scope.getFunctionParent(); + const selfFuncParent = this.scope.getFunctionParent(); // here we check the `node` equality as sometimes we may have different paths for the // same node due to path thrashing if (targetFuncParent.node !== selfFuncParent.node) { - let status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); + const status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); if (status) { return status; } else { @@ -268,17 +268,17 @@ export function _guessExecutionStatusRelativeTo(target) { } } - let targetPaths = target.getAncestry(); + const targetPaths = target.getAncestry(); if (targetPaths.indexOf(this) >= 0) return "after"; - let selfPaths = this.getAncestry(); + const selfPaths = this.getAncestry(); // get ancestor where the branches intersect let commonPath; let targetIndex; let selfIndex; for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) { - let selfPath = selfPaths[selfIndex]; + const selfPath = selfPaths[selfIndex]; targetIndex = targetPaths.indexOf(selfPath); if (targetIndex >= 0) { commonPath = selfPath; @@ -290,8 +290,8 @@ export function _guessExecutionStatusRelativeTo(target) { } // get the relationship paths that associate these nodes to their common ancestor - let targetRelationship = targetPaths[targetIndex - 1]; - let selfRelationship = selfPaths[selfIndex - 1]; + const targetRelationship = targetPaths[targetIndex - 1]; + const selfRelationship = selfPaths[selfIndex - 1]; if (!targetRelationship || !selfRelationship) { return "before"; } @@ -302,28 +302,28 @@ export function _guessExecutionStatusRelativeTo(target) { } // otherwise we're associated by a parent node, check which key comes before the other - let targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key); - let selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); + const targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key); + const selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); return targetKeyPosition > selfKeyPosition ? "before" : "after"; } export function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) { - let targetFuncPath = targetFuncParent.path; + const targetFuncPath = targetFuncParent.path; if (!targetFuncPath.isFunctionDeclaration()) return; // so we're in a completely different function, if this is a function declaration // then we can be a bit smarter and handle cases where the function is either // a. not called at all (part of an export) // b. called directly - let binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); + const binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); // no references! if (!binding.references) return "before"; - let referencePaths: Array = binding.referencePaths; + const referencePaths: Array = binding.referencePaths; // verify that all of the references are calls - for (let path of referencePaths) { + for (const path of referencePaths) { if (path.key !== "callee" || !path.parentPath.isCallExpression()) { return; } @@ -332,13 +332,13 @@ export function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncPare let allStatus; // verify that all the calls have the same execution status - for (let path of referencePaths) { + for (const path of referencePaths) { // if a reference is a child of the function we're checking against then we can // safelty ignore it - let childOfFunction = !!path.find((path) => path.node === targetFuncPath.node); + const childOfFunction = !!path.find((path) => path.node === targetFuncPath.node); if (childOfFunction) continue; - let status = this._guessExecutionStatusRelativeTo(path); + const status = this._guessExecutionStatusRelativeTo(path); if (allStatus) { if (allStatus !== status) return; @@ -374,7 +374,7 @@ export function _resolve(dangerous?, resolved?): ?NodePath { // otherwise it's a request for a pattern and that's a bit more tricky } } else if (this.isReferencedIdentifier()) { - let binding = this.scope.getBinding(this.node.name); + const binding = this.scope.getBinding(this.node.name); if (!binding) return; // reassigned so we can't really resolve it @@ -384,7 +384,7 @@ export function _resolve(dangerous?, resolved?): ?NodePath { if (binding.kind === "module") return; if (binding.path !== this) { - let ret = binding.path.resolve(dangerous, resolved); + const ret = binding.path.resolve(dangerous, resolved); // If the identifier resolves to parent node then we can't really resolve it. if (this.find((parent) => parent.node === ret.node)) return; return ret; @@ -395,19 +395,19 @@ export function _resolve(dangerous?, resolved?): ?NodePath { // this is dangerous, as non-direct target assignments will mutate it's state // making this resolution inaccurate - let targetKey = this.toComputedKey(); + const targetKey = this.toComputedKey(); if (!t.isLiteral(targetKey)) return; - let targetName = targetKey.value; + const targetName = targetKey.value; - let target = this.get("object").resolve(dangerous, resolved); + const target = this.get("object").resolve(dangerous, resolved); if (target.isObjectExpression()) { - let props = target.get("properties"); - for (let prop of (props: Array)) { + const props = target.get("properties"); + for (const prop of (props: Array)) { if (!prop.isProperty()) continue; - let key = prop.get("key"); + const key = prop.get("key"); // { foo: obj } let match = prop.isnt("computed") && key.isIdentifier({ name: targetName }); @@ -418,8 +418,8 @@ export function _resolve(dangerous?, resolved?): ?NodePath { if (match) return prop.get("value").resolve(dangerous, resolved); } } else if (target.isArrayExpression() && !isNaN(+targetName)) { - let elems = target.get("elements"); - let elem = elems[targetName]; + const elems = target.get("elements"); + const elem = elems[targetName]; if (elem) return elem.resolve(dangerous, resolved); } } diff --git a/packages/babel-traverse/src/path/lib/hoister.js b/packages/babel-traverse/src/path/lib/hoister.js index 3776b2d30e..0a942ecc10 100644 --- a/packages/babel-traverse/src/path/lib/hoister.js +++ b/packages/babel-traverse/src/path/lib/hoister.js @@ -1,42 +1,60 @@ import { react } from "babel-types"; import * as t from "babel-types"; -let referenceVisitor = { +const referenceVisitor = { + // This visitor looks for bindings to establish a topmost scope for hoisting. ReferencedIdentifier(path, state) { - if (path.isJSXIdentifier() && react.isCompatTag(path.node.name)) { + // Don't hoist regular JSX identifiers ('div', 'span', etc). + // We do have to consider member expressions for hoisting (e.g. `this.component`) + if ( + path.isJSXIdentifier() && + react.isCompatTag(path.node.name) && + !path.parentPath.isJSXMemberExpression() + ) { return; } + // If the identifier refers to `this`, we need to break on the closest non-arrow scope. + if (path.node.name === "this") { + let scope = path.scope; + do { + if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) break; + } while (scope = scope.parent); + if (scope) state.breakOnScopePaths.push(scope.path); + } + // direct references that we need to track to hoist this to the highest scope we can - let binding = path.scope.getBinding(path.node.name); + const binding = path.scope.getBinding(path.node.name); if (!binding) return; // this binding isn't accessible from the parent scope so we can safely ignore it // eg. it's in a closure etc if (binding !== state.scope.getBinding(path.node.name)) return; - if (binding.constant) { - state.bindings[path.node.name] = binding; - } else { - for (let violationPath of (binding.constantViolations: Array)) { - state.breakOnScopePaths = state.breakOnScopePaths.concat(violationPath.getAncestry()); - } - } - } + state.bindings[path.node.name] = binding; + }, }; export default class PathHoister { constructor(path, scope) { + // Storage for scopes we can't hoist above. this.breakOnScopePaths = []; - this.bindings = {}; - this.scopes = []; - this.scope = scope; - this.path = path; + // Storage for bindings that may affect what path we can hoist to. + this.bindings = {}; + // Storage for eligible scopes. + this.scopes = []; + // Our original scope and path. + this.scope = scope; + this.path = path; + // By default, we attach as far up as we can; but if we're trying + // to avoid referencing a binding, we may have to go after. + this.attachAfter = false; } + // A scope is compatible if all required bindings are reachable. isCompatibleScope(scope) { - for (let key in this.bindings) { - let binding = this.bindings[key]; + for (const key in this.bindings) { + const binding = this.bindings[key]; if (!scope.bindingIdentifierEquals(key, binding.identifier)) { return false; } @@ -45,6 +63,7 @@ export default class PathHoister { return true; } + // Look through all scopes and push compatible ones. getCompatibleScopes() { let scope = this.path.scope; do { @@ -54,6 +73,7 @@ export default class PathHoister { break; } + // deopt: These scopes are set in the visitor on const violations if (this.breakOnScopePaths.indexOf(scope.path) >= 0) { break; } @@ -73,17 +93,27 @@ export default class PathHoister { // avoid hoisting to a scope that contains bindings that are executed after our attachment path if (targetScope.path.isProgram() || targetScope.path.isFunction()) { - for (let name in this.bindings) { + for (const name in this.bindings) { // check binding is a direct child of this paths scope if (!targetScope.hasOwnBinding(name)) continue; - let binding = this.bindings[name]; + const binding = this.bindings[name]; // allow parameter references if (binding.kind === "param") continue; - // if this binding appears after our attachment point then don't hoist it - if (this.getAttachmentParentForPath(binding.path).key > path.key) return; + // if this binding appears after our attachment point, then we move after it. + if (this.getAttachmentParentForPath(binding.path).key > path.key) { + this.attachAfter = true; + path = binding.path; + + // We also move past any constant violations. + for (const violationPath of (binding.constantViolations: Array)) { + if (this.getAttachmentParentForPath(violationPath).key > path.key) { + path = violationPath; + } + } + } } } @@ -91,14 +121,15 @@ export default class PathHoister { } _getAttachmentPath() { - let scopes = this.scopes; + const scopes = this.scopes; - let scope = scopes.pop(); + const scope = scopes.pop(); + // deopt: no compatible scopes if (!scope) return; if (scope.path.isFunction()) { if (this.hasOwnParamBindings(scope)) { - // should ignore this scope since it's ourselves + // deopt: should ignore this scope since it's ourselves if (this.scope === scope) return; // needs to be attached to the body @@ -113,31 +144,40 @@ export default class PathHoister { } getNextScopeAttachmentParent() { - let scope = this.scopes.pop(); + const scope = this.scopes.pop(); if (scope) return this.getAttachmentParentForPath(scope.path); } + // Find an attachment for this path. getAttachmentParentForPath(path) { do { - if (!path.parentPath || - (Array.isArray(path.container) && path.isStatement()) || - (path.isVariableDeclarator() && path.parentPath.node.declarations.length > 1)) - return path; + if ( + // Beginning of the scope + !path.parentPath || + // Has siblings and is a statement + (Array.isArray(path.container) && path.isStatement()) || + // Is part of multiple var declarations + (path.isVariableDeclarator() && + path.parentPath.node !== null && + path.parentPath.node.declarations.length > 1)) + {return path;} } while ((path = path.parentPath)); } + // Returns true if a scope has param bindings. hasOwnParamBindings(scope) { - for (let name in this.bindings) { + for (const name in this.bindings) { if (!scope.hasOwnBinding(name)) continue; - let binding = this.bindings[name]; - if (binding.kind === "param") return true; + const binding = this.bindings[name]; + // Ensure constant; without it we could place behind a reassignment + if (binding.kind === "param" && binding.constant) return true; } return false; } run() { - let node = this.path.node; + const node = this.path.node; if (node._hoisted) return; node._hoisted = true; @@ -145,21 +185,23 @@ export default class PathHoister { this.getCompatibleScopes(); - let attachTo = this.getAttachmentPath(); + const attachTo = this.getAttachmentPath(); if (!attachTo) return; - // don't bother hoisting to the same function as this will cause multiple branches to be evaluated more than once leading to a bad optimisation + // don't bother hoisting to the same function as this will cause multiple branches to be + // evaluated more than once leading to a bad optimisation if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return; // generate declaration and insert it to our point let uid = attachTo.scope.generateUidIdentifier("ref"); - let declarator = t.variableDeclarator(uid, this.path.node); + const declarator = t.variableDeclarator(uid, this.path.node); - attachTo.insertBefore([ - attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator]) + const insertFn = this.attachAfter ? "insertAfter" : "insertBefore"; + attachTo[insertFn]([ + attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator]), ]); - let parent = this.path.parentPath; + const parent = this.path.parentPath; if (parent.isJSXElement() && this.path.container === parent.node.children) { // turning the `span` in `
` to an expression so we need to wrap it with // an expression container diff --git a/packages/babel-traverse/src/path/lib/removal-hooks.js b/packages/babel-traverse/src/path/lib/removal-hooks.js index e016c712f3..bd720222dd 100644 --- a/packages/babel-traverse/src/path/lib/removal-hooks.js +++ b/packages/babel-traverse/src/path/lib/removal-hooks.js @@ -4,37 +4,31 @@ * Pre hooks should be used for either rejecting removal or delegating removal */ -export let hooks = [ +export const hooks = [ function (self, parent) { - if (self.key === "body" && parent.isArrowFunctionExpression()) { - self.replaceWith(self.scope.buildUndefinedNode()); - return true; - } - }, + const removeParent = + // while (NODE); + // removing the test of a while/switch, we can either just remove it entirely *or* turn the + // `test` into `true` unlikely that the latter will ever be what's wanted so we just remove + // the loop to avoid infinite recursion + (self.key === "test" && (parent.isWhile() || parent.isSwitchCase())) || - function (self, parent) { - let removeParent = false; + // export NODE; + // just remove a declaration for an export as this is no longer valid + (self.key === "declaration" && parent.isExportDeclaration()) || - // while (NODE); - // removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true` - // unlikely that the latter will ever be what's wanted so we just remove the loop to avoid infinite recursion - removeParent = removeParent || (self.key === "test" && (parent.isWhile() || parent.isSwitchCase())); + // label: NODE + // stray labeled statement with no body + (self.key === "body" && parent.isLabeledStatement()) || - // export NODE; - // just remove a declaration for an export as this is no longer valid - removeParent = removeParent || (self.key === "declaration" && parent.isExportDeclaration()); + // let NODE; + // remove an entire declaration if there are no declarators left + (self.listKey === "declarations" && parent.isVariableDeclaration() && + parent.node.declarations.length === 1) || - // label: NODE - // stray labeled statement with no body - removeParent = removeParent || (self.key === "body" && parent.isLabeledStatement()); - - // let NODE; - // remove an entire declaration if there are no declarators left - removeParent = removeParent || (self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1); - - // NODE; - // remove the entire expression statement if there's no expression - removeParent = removeParent || (self.key === "expression" && parent.isExpressionStatement()); + // NODE; + // remove the entire expression statement if there's no expression + (self.key === "expression" && parent.isExpressionStatement()); if (removeParent) { parent.remove(); @@ -69,13 +63,13 @@ export let hooks = [ function (self, parent) { if ( (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate")) || - (parent.isLoop() && self.key === "body") + (self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) ) { self.replaceWith({ type: "BlockStatement", - body: [] + body: [], }); return true; } - } + }, ]; diff --git a/packages/babel-traverse/src/path/lib/virtual-types.js b/packages/babel-traverse/src/path/lib/virtual-types.js index 396be80b90..7bc4e1e2cb 100644 --- a/packages/babel-traverse/src/path/lib/virtual-types.js +++ b/packages/babel-traverse/src/path/lib/virtual-types.js @@ -2,7 +2,7 @@ import type NodePath from "../index"; import { react } from "babel-types"; import * as t from "babel-types"; -export let ReferencedIdentifier = { +export const ReferencedIdentifier = { types: ["Identifier", "JSXIdentifier"], checkPath({ node, parent }: NodePath, opts?: Object): boolean { if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) { @@ -16,24 +16,24 @@ export let ReferencedIdentifier = { // check if node is referenced return t.isReferenced(node, parent); - } + }, }; -export let ReferencedMemberExpression = { +export const ReferencedMemberExpression = { types: ["MemberExpression"], checkPath({ node, parent }) { return t.isMemberExpression(node) && t.isReferenced(node, parent); - } + }, }; -export let BindingIdentifier = { +export const BindingIdentifier = { types: ["Identifier"], checkPath({ node, parent }: NodePath): boolean { return t.isIdentifier(node) && t.isBinding(node, parent); - } + }, }; -export let Statement = { +export const Statement = { types: ["Statement"], checkPath({ node, parent }: NodePath): boolean { if (t.isStatement(node)) { @@ -46,10 +46,10 @@ export let Statement = { } else { return false; } - } + }, }; -export let Expression = { +export const Expression = { types: ["Expression"], checkPath(path: NodePath): boolean { if (path.isIdentifier()) { @@ -57,55 +57,55 @@ export let Expression = { } else { return t.isExpression(path.node); } - } + }, }; -export let Scope = { +export const Scope = { types: ["Scopable"], checkPath(path) { return t.isScope(path.node, path.parent); - } + }, }; -export let Referenced = { +export const Referenced = { checkPath(path: NodePath): boolean { return t.isReferenced(path.node, path.parent); - } + }, }; -export let BlockScoped = { +export const BlockScoped = { checkPath(path: NodePath): boolean { return t.isBlockScoped(path.node); - } + }, }; -export let Var = { +export const Var = { types: ["VariableDeclaration"], checkPath(path: NodePath): boolean { return t.isVar(path.node); - } + }, }; -export let User = { +export const User = { checkPath(path: NodePath): boolean { return path.node && !!path.node.loc; - } + }, }; -export let Generated = { +export const Generated = { checkPath(path: NodePath): boolean { return !path.isUser(); - } + }, }; -export let Pure = { +export const Pure = { checkPath(path: NodePath, opts?): boolean { return path.scope.isPure(path.node, opts); - } + }, }; -export let Flow = { - types: ["Flow", "ImportDeclaration", "ExportDeclaration"], +export const Flow = { + types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"], checkPath({ node }: NodePath): boolean { if (t.isFlow(node)) { return true; @@ -113,8 +113,40 @@ export let Flow = { return node.importKind === "type" || node.importKind === "typeof"; } else if (t.isExportDeclaration(node)) { return node.exportKind === "type"; + } else if (t.isImportSpecifier(node)) { + return node.importKind === "type" || node.importKind === "typeof"; } else { return false; } - } + }, +}; + +// TODO: 7.0 Backwards Compat +export const RestProperty = { + types: ["RestElement"], + checkPath(path: NodePath): boolean { + return path.parentPath && path.parentPath.isObjectPattern(); + }, +}; + +export const SpreadProperty = { + types: ["RestElement"], + checkPath(path: NodePath): boolean { + return path.parentPath && path.parentPath.isObjectExpression(); + }, +}; + +export const ExistentialTypeParam = { + types: ["ExistsTypeAnnotation"], +}; + +export const NumericLiteralTypeAnnotation = { + types: ["NumberLiteralTypeAnnotation"], +}; + +export const ForAwaitStatement = { + types: ["ForOfStatement"], + checkPath({ node }: NodePath): boolean { + return node.await === true; + }, }; diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index cb4568240c..052cd1afec 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -1,4 +1,3 @@ -/* eslint max-len: 0 */ // This file contains methods that modify the path/node in some ways. import { path as pathCache } from "../cache"; @@ -17,7 +16,10 @@ export function insertBefore(nodes) { if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) { return this.parentPath.insertBefore(nodes); - } else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) { + } else if ( + this.isNodeType("Expression") || + (this.parentPath.isForStatement() && this.key === "init") + ) { if (this.node) nodes.push(this.node); this.replaceExpressionWithStatements(nodes); } else { @@ -28,7 +30,8 @@ export function insertBefore(nodes) { if (this.node) nodes.push(this.node); this._replaceWith(t.blockStatement(nodes)); } else { - throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?"); + throw new Error("We don't know what to do with this node type. " + + "We were previously a Statement but we can't fit in here?"); } } @@ -38,15 +41,15 @@ export function insertBefore(nodes) { export function _containerInsert(from, nodes) { this.updateSiblingKeys(from, nodes.length); - let paths = []; + const paths = []; for (let i = 0; i < nodes.length; i++) { - let to = from + i; - let node = nodes[i]; + const to = from + i; + const node = nodes[i]; this.container.splice(to, 0, node); if (this.context) { - let path = this.context.create(this.parent, this.container, to, this.listKey); + const path = this.context.create(this.parent, this.container, to, this.listKey); // While this path may have a context, there is currently no guarantee that the context // will be the active context, because `popContext` may leave a final context in place. @@ -59,18 +62,18 @@ export function _containerInsert(from, nodes) { parent: this.parent, container: this.container, listKey: this.listKey, - key: to + key: to, })); } } - let contexts = this._getQueueContexts(); + const contexts = this._getQueueContexts(); - for (let path of paths) { + for (const path of paths) { path.setScope(); path.debug(() => "Inserted."); - for (let context of contexts) { + for (const context of contexts) { context.maybeQueue(path, true); } } @@ -87,8 +90,9 @@ export function _containerInsertAfter(nodes) { } export function _maybePopFromStatements(nodes) { - let last = nodes[nodes.length - 1]; - let isIdentifier = t.isIdentifier(last) || (t.isExpressionStatement(last) && t.isIdentifier(last.expression)); + const last = nodes[nodes.length - 1]; + const isIdentifier = t.isIdentifier(last) || + (t.isExpressionStatement(last) && t.isIdentifier(last.expression)); if (isIdentifier && !this.isCompletionRecord()) { nodes.pop(); @@ -107,9 +111,12 @@ export function insertAfter(nodes) { if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) { return this.parentPath.insertAfter(nodes); - } else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) { + } else if ( + this.isNodeType("Expression") || + (this.parentPath.isForStatement() && this.key === "init") + ) { if (this.node) { - let temp = this.scope.generateDeclaredUidIdentifier(); + const temp = this.scope.generateDeclaredUidIdentifier(); nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node))); nodes.push(t.expressionStatement(temp)); } @@ -122,7 +129,8 @@ export function insertAfter(nodes) { if (this.node) nodes.unshift(this.node); this._replaceWith(t.blockStatement(nodes)); } else { - throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?"); + throw new Error("We don't know what to do with this node type. " + + "We were previously a Statement but we can't fit in here?"); } } @@ -136,9 +144,9 @@ export function insertAfter(nodes) { export function updateSiblingKeys(fromIndex, incrementBy) { if (!this.parent) return; - let paths = pathCache.get(this.parent); + const paths = pathCache.get(this.parent); for (let i = 0; i < paths.length; i++) { - let path = paths[i]; + const path = paths[i]; if (path.key >= fromIndex) { path.key += incrementBy; } @@ -155,7 +163,7 @@ export function _verifyNodeList(nodes) { } for (let i = 0; i < nodes.length; i++) { - let node = nodes[i]; + const node = nodes[i]; let msg; if (!node) { @@ -169,7 +177,7 @@ export function _verifyNodeList(nodes) { } if (msg) { - let type = Array.isArray(node) ? "array" : typeof node; + const type = Array.isArray(node) ? "array" : typeof node; throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`); } } @@ -184,12 +192,12 @@ export function unshiftContainer(listKey, nodes) { // get the first path and insert our nodes before it, if it doesn't exist then it // doesn't matter, our nodes will be inserted anyway - let path = NodePath.get({ + const path = NodePath.get({ parentPath: this, parent: this.node, container: this.node[listKey], listKey, - key: 0 + key: 0, }); return path.insertBefore(nodes); @@ -203,13 +211,13 @@ export function pushContainer(listKey, nodes) { // get an invisible path that represents the last node + 1 and replace it with our // nodes, effectively inlining it - let container = this.node[listKey]; - let path = NodePath.get({ + const container = this.node[listKey]; + const path = NodePath.get({ parentPath: this, parent: this.node, container: container, listKey, - key: container.length + key: container.length, }); return path.replaceWithMultiple(nodes); @@ -221,6 +229,6 @@ export function pushContainer(listKey, nodes) { */ export function hoist(scope = this.scope) { - let hoister = new PathHoister(this, scope); + const hoister = new PathHoister(this, scope); return hoister.run(); } diff --git a/packages/babel-traverse/src/path/removal.js b/packages/babel-traverse/src/path/removal.js index f7686fce6b..6f6701ceee 100644 --- a/packages/babel-traverse/src/path/removal.js +++ b/packages/babel-traverse/src/path/removal.js @@ -18,7 +18,7 @@ export function remove() { } export function _callRemovalHooks() { - for (let fn of (hooks: Array)) { + for (const fn of (hooks: Array)) { if (fn(this, this.parentPath)) return true; } } @@ -34,8 +34,8 @@ export function _remove() { export function _markRemoved() { this.shouldSkip = true; - this.removed = true; - this.node = null; + this.removed = true; + this.node = null; } export function _assertUnremoved() { diff --git a/packages/babel-traverse/src/path/replacement.js b/packages/babel-traverse/src/path/replacement.js index 8ca15a4c09..e82bba5b39 100644 --- a/packages/babel-traverse/src/path/replacement.js +++ b/packages/babel-traverse/src/path/replacement.js @@ -1,4 +1,3 @@ -/* eslint max-len: 0 */ // This file contains methods responsible for replacing a node with another. import codeFrame from "babel-code-frame"; @@ -7,7 +6,7 @@ import NodePath from "./index"; import { parse } from "babylon"; import * as t from "babel-types"; -let hoistVariablesVisitor = { +const hoistVariablesVisitor = { Function(path) { path.skip(); }, @@ -15,14 +14,14 @@ let hoistVariablesVisitor = { VariableDeclaration(path) { if (path.node.kind !== "var") return; - let bindings = path.getBindingIdentifiers(); - for (let key in bindings) { + const bindings = path.getBindingIdentifiers(); + for (const key in bindings) { path.scope.push({ id: bindings[key] }); } - let exprs = []; + const exprs = []; - for (let declar of (path.node.declarations: Array)) { + for (const declar of (path.node.declarations: Array)) { if (declar.init) { exprs.push(t.expressionStatement( t.assignmentExpression("=", declar.id, declar.init) @@ -31,7 +30,7 @@ let hoistVariablesVisitor = { } path.replaceWithMultiple(exprs); - } + }, }; /** @@ -73,7 +72,7 @@ export function replaceWithSourceString(replacement) { replacement = `(${replacement})`; replacement = parse(replacement); } catch (err) { - let loc = err.loc; + const loc = err.loc; if (loc) { err.message += " - make sure this is an expression."; err.message += "\n" + codeFrame(replacement, loc.line, loc.column + 1); @@ -114,28 +113,37 @@ export function replaceWith(replacement) { } if (Array.isArray(replacement)) { - throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`"); + throw new Error( + "Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`"); } if (typeof replacement === "string") { - throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`"); + throw new Error( + "Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`"); } if (this.isNodeType("Statement") && t.isExpression(replacement)) { - if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) { + if ( + !this.canHaveVariableDeclarationOrExpression() && + !this.canSwapBetweenExpressionAndStatement(replacement) && + !this.parentPath.isExportDefaultDeclaration() + ) { // replacing a statement with an expression so wrap it in an expression statement replacement = t.expressionStatement(replacement); } } if (this.isNodeType("Expression") && t.isStatement(replacement)) { - if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) { + if ( + !this.canHaveVariableDeclarationOrExpression() && + !this.canSwapBetweenExpressionAndStatement(replacement) + ) { // replacing an expression with a statement so let's explode it return this.replaceExpressionWithStatements([replacement]); } } - let oldNode = this.node; + const oldNode = this.node; if (oldNode) { t.inheritsComments(replacement, oldNode); t.removeComments(oldNode); @@ -181,10 +189,10 @@ export function _replaceWith(node) { export function replaceExpressionWithStatements(nodes: Array) { this.resync(); - let toSequenceExpression = t.toSequenceExpression(nodes, this.scope); + const toSequenceExpression = t.toSequenceExpression(nodes, this.scope); if (t.isSequenceExpression(toSequenceExpression)) { - let exprs = toSequenceExpression.expressions; + const exprs = toSequenceExpression.expressions; if (exprs.length >= 2 && this.parentPath.isExpressionStatement()) { this._maybePopFromStatements(exprs); @@ -199,23 +207,29 @@ export function replaceExpressionWithStatements(nodes: Array) { } else if (toSequenceExpression) { this.replaceWith(toSequenceExpression); } else { - let container = t.functionExpression(null, [], t.blockStatement(nodes)); + const container = t.functionExpression(null, [], t.blockStatement(nodes)); container.shadow = true; this.replaceWith(t.callExpression(container, [])); this.traverse(hoistVariablesVisitor); // add implicit returns to all ending expression statements - let completionRecords: Array = this.get("callee").getCompletionRecords(); - for (let path of completionRecords) { + const completionRecords: Array = this.get("callee").getCompletionRecords(); + for (const path of completionRecords) { if (!path.isExpressionStatement()) continue; - let loop = path.findParent((path) => path.isLoop()); + const loop = path.findParent((path) => path.isLoop()); if (loop) { - let callee = this.get("callee"); + let uid = loop.getData("expressionReplacementReturnUid"); - let uid = callee.scope.generateDeclaredUidIdentifier("ret"); - callee.get("body").pushContainer("body", t.returnStatement(uid)); + if (!uid) { + const callee = this.get("callee"); + uid = callee.scope.generateDeclaredUidIdentifier("ret"); + callee.get("body").pushContainer("body", t.returnStatement(uid)); + loop.setData("expressionReplacementReturnUid", uid); + } else { + uid = t.identifier(uid.name); + } path.get("expression").replaceWith( t.assignmentExpression("=", uid, path.node.expression) diff --git a/packages/babel-traverse/src/scope/binding.js b/packages/babel-traverse/src/scope/binding.js index 32cfe54b99..3edd9407d4 100644 --- a/packages/babel-traverse/src/scope/binding.js +++ b/packages/babel-traverse/src/scope/binding.js @@ -14,9 +14,9 @@ import type NodePath from "../path"; export default class Binding { constructor({ existing, identifier, scope, path, kind }) { this.identifier = identifier; - this.scope = scope; - this.path = path; - this.kind = kind; + this.scope = scope; + this.path = path; + this.kind = kind; this.constantViolations = []; this.constant = true; @@ -56,13 +56,13 @@ export default class Binding { setValue(value: any) { if (this.hasDeoptedValue) return; this.hasValue = true; - this.value = value; + this.value = value; } clearValue() { this.hasDeoptedValue = false; - this.hasValue = false; - this.value = null; + this.hasValue = false; + this.value = null; } /** diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index 83e80df926..4b03b0b7c5 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -1,5 +1,3 @@ -/* eslint max-len: 0 */ - import includes from "lodash/includes"; import repeat from "lodash/repeat"; import Renamer from "./lib/renamer"; @@ -24,9 +22,9 @@ let _crawlCallsCount = 0; */ function getCache(path, parentScope, self) { - let scopes: Array = scopeCache.get(path.node) || []; + const scopes: Array = scopeCache.get(path.node) || []; - for (let scope of scopes) { + for (const scope of scopes) { if (scope.parent === parentScope && scope.path === path) return scope; } @@ -43,7 +41,7 @@ function gatherNodeParts(node: Object, parts: Array) { if (node.source) { gatherNodeParts(node.source, parts); } else if (node.specifiers && node.specifiers.length) { - for (let specifier of (node.specifiers: Array)) { + for (const specifier of (node.specifiers: Array)) { gatherNodeParts(specifier, parts); } } else if (node.declaration) { @@ -61,7 +59,7 @@ function gatherNodeParts(node: Object, parts: Array) { } else if (t.isCallExpression(node)) { gatherNodeParts(node.callee, parts); } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { - for (let prop of (node.properties: Array)) { + for (const prop of (node.properties: Array)) { gatherNodeParts(prop.key || prop.argument, parts); } } @@ -69,16 +67,16 @@ function gatherNodeParts(node: Object, parts: Array) { // -let collectorVisitor = { +const collectorVisitor = { For(path) { - for (let key of (t.FOR_INIT_KEYS: Array)) { - let declar = path.get(key); + for (const key of (t.FOR_INIT_KEYS: Array)) { + const declar = path.get(key); if (declar.isVar()) path.scope.getFunctionParent().registerBinding("var", declar); } }, Declaration(path) { - // delegate block scope handling to the `blockVariableVisitor` + // delegate block scope handling to the `BlockScoped` method if (path.isBlockScoped()) return; // this will be hit again once we traverse into it after this iteration @@ -96,7 +94,7 @@ let collectorVisitor = { }, ForXStatement(path, state) { - let left = path.get("left"); + const left = path.get("left"); if (left.isPattern() || left.isIdentifier()) { state.constantViolations.push(left); } @@ -105,23 +103,23 @@ let collectorVisitor = { ExportDeclaration: { exit(path) { const { node, scope } = path; - let declar = node.declaration; + const declar = node.declaration; if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) { - let id = declar.id; + const id = declar.id; if (!id) return; - let binding = scope.getBinding(id.name); + const binding = scope.getBinding(id.name); if (binding) binding.reference(path); } else if (t.isVariableDeclaration(declar)) { - for (let decl of (declar.declarations: Array)) { - let ids = t.getBindingIdentifiers(decl); - for (let name in ids) { - let binding = scope.getBinding(name); + for (const decl of (declar.declarations: Array)) { + const ids = t.getBindingIdentifiers(decl); + for (const name in ids) { + const binding = scope.getBinding(name); if (binding) binding.reference(path); } } } - } + }, }, LabeledStatement(path) { @@ -150,21 +148,21 @@ let collectorVisitor = { }, ClassDeclaration(path) { - let id = path.node.id; + const id = path.node.id; if (!id) return; - let name = id.name; + const name = id.name; path.scope.bindings[name] = path.scope.getBinding(name); }, Block(path) { - let paths = path.get("body"); - for (let bodyPath of (paths: Array)) { + const paths = path.get("body"); + for (const bodyPath of (paths: Array)) { if (bodyPath.isFunctionDeclaration()) { path.scope.getBlockParent().registerDeclaration(bodyPath); } } - } + }, }; let uid = 0; @@ -181,18 +179,18 @@ export default class Scope { return parentScope; } - let cached = getCache(path, parentScope, this); + const cached = getCache(path, parentScope, this); if (cached) return cached; this.uid = uid++; this.parent = parentScope; - this.hub = path.hub; + this.hub = path.hub; this.parentBlock = path.parent; - this.block = path.node; - this.path = path; + this.block = path.node; + this.path = path; - this.labels = new Map(); + this.labels = new Map(); } /** @@ -209,7 +207,7 @@ export default class Scope { "arguments", "undefined", "Infinity", - "NaN" + "NaN", ]; /** @@ -225,7 +223,7 @@ export default class Scope { */ generateDeclaredUidIdentifier(name: string = "temp") { - let id = this.generateUidIdentifier(name); + const id = this.generateUidIdentifier(name); this.push({ id }); return id; } @@ -252,7 +250,7 @@ export default class Scope { i++; } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); - let program = this.getProgramParent(); + const program = this.getProgramParent(); program.references[uid] = true; program.uids[uid] = true; @@ -273,7 +271,7 @@ export default class Scope { * Generate a unique identifier based on a node. */ - generateUidIdentifierBasedOnNode(parent: Object, defaultName?: String): Object { + generateUidIdentifierBasedOnNode(parent: Object, defaultName?: String): Object { let node = parent; if (t.isAssignmentExpression(parent)) { @@ -309,7 +307,7 @@ export default class Scope { } if (t.isIdentifier(node)) { - let binding = this.getBinding(node.name); + const binding = this.getBinding(node.name); if (binding) { return binding.constant; } else { @@ -328,7 +326,7 @@ export default class Scope { if (this.isStatic(node)) { return null; } else { - let id = this.generateUidIdentifierBasedOnNode(node); + const id = this.generateUidIdentifierBasedOnNode(node); if (!dontPush) this.push({ id }); return id; } @@ -341,13 +339,11 @@ export default class Scope { // ignore hoisted functions if there's also a local let if (kind === "hoisted" && local.kind === "let") return; - let duplicate = false; - - // don't allow duplicate bindings to exist alongside - if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module"; - - // don't allow a local of param with a kind of let - if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const"); + const duplicate = + // don't allow duplicate bindings to exist alongside + kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || + // don't allow a local of param with a kind of let + local.kind === "param" && (kind === "let" || kind === "const"); if (duplicate) { throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError); @@ -355,7 +351,7 @@ export default class Scope { } rename(oldName: string, newName: string, block?) { - let binding = this.getBinding(oldName); + const binding = this.getBinding(oldName); if (binding) { newName = newName || this.generateUidIdentifier(oldName).name; return new Renamer(binding, oldName, newName).rename(block); @@ -370,18 +366,18 @@ export default class Scope { } dump() { - let sep = repeat("-", 60); + const sep = repeat("-", 60); console.log(sep); let scope = this; do { console.log("#", scope.block.type); - for (let name in scope.bindings) { - let binding = scope.bindings[name]; + for (const name in scope.bindings) { + const binding = scope.bindings[name]; console.log(" -", name, { constant: binding.constant, references: binding.references, violations: binding.constantViolations.length, - kind: binding.kind + kind: binding.kind, }); } } while (scope = scope.parent); @@ -389,10 +385,10 @@ export default class Scope { } toArray(node: Object, i?: number) { - let file = this.hub.file; + const file = this.hub.file; if (t.isIdentifier(node)) { - let binding = this.getBinding(node.name); + const binding = this.getBinding(node.name); if (binding && binding.constant && binding.path.isGenericType("Array")) return node; } @@ -417,7 +413,7 @@ export default class Scope { } let helperName = "toArray"; - let args = [node]; + const args = [node]; if (i === true) { helperName = "toConsumableArray"; } else if (i) { @@ -446,19 +442,19 @@ export default class Scope { } else if (path.isFunctionDeclaration()) { this.registerBinding("hoisted", path.get("id"), path); } else if (path.isVariableDeclaration()) { - let declarations = path.get("declarations"); - for (let declar of (declarations: Array)) { + const declarations = path.get("declarations"); + for (const declar of (declarations: Array)) { this.registerBinding(path.node.kind, declar); } } else if (path.isClassDeclaration()) { this.registerBinding("let", path); } else if (path.isImportDeclaration()) { - let specifiers = path.get("specifiers"); - for (let specifier of (specifiers: Array)) { + const specifiers = path.get("specifiers"); + for (const specifier of (specifiers: Array)) { this.registerBinding("module", specifier); } } else if (path.isExportDeclaration()) { - let declar = path.get("declaration"); + const declar = path.get("declaration"); if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) { this.registerDeclaration(declar); } @@ -476,9 +472,9 @@ export default class Scope { } registerConstantViolation(path: NodePath) { - let ids = path.getBindingIdentifiers(); - for (let name in ids) { - let binding = this.getBinding(name); + const ids = path.getBindingIdentifiers(); + for (const name in ids) { + const binding = this.getBinding(name); if (binding) binding.reassign(path); } } @@ -487,18 +483,18 @@ export default class Scope { if (!kind) throw new ReferenceError("no `kind`"); if (path.isVariableDeclaration()) { - let declarators: Array = path.get("declarations"); - for (let declar of declarators) { + const declarators: Array = path.get("declarations"); + for (const declar of declarators) { this.registerBinding(kind, declar); } return; } - let parent = this.getProgramParent(); - let ids = path.getBindingIdentifiers(true); + const parent = this.getProgramParent(); + const ids = path.getBindingIdentifiers(true); - for (let name in ids) { - for (let id of (ids[name]: Array)) { + for (const name in ids) { + for (const id of (ids[name]: Array)) { let local = this.getOwnBinding(name); if (local) { // same identifier so continue safely as we're likely trying to register it @@ -517,10 +513,10 @@ export default class Scope { this.bindings[name] = new Binding({ identifier: id, - existing: local, - scope: this, - path: bindingPath, - kind: kind + existing: local, + scope: this, + path: bindingPath, + kind: kind, }); } } @@ -562,7 +558,7 @@ export default class Scope { isPure(node, constantsOnly?: boolean) { if (t.isIdentifier(node)) { - let binding = this.getBinding(node.name); + const binding = this.getBinding(node.name); if (!binding) return false; if (constantsOnly) return binding.constant; return true; @@ -570,19 +566,19 @@ export default class Scope { if (node.superClass && !this.isPure(node.superClass, constantsOnly)) return false; return this.isPure(node.body, constantsOnly); } else if (t.isClassBody(node)) { - for (let method of node.body) { + for (const method of node.body) { if (!this.isPure(method, constantsOnly)) return false; } return true; } else if (t.isBinary(node)) { return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); } else if (t.isArrayExpression(node)) { - for (let elem of (node.elements: Array)) { + for (const elem of (node.elements: Array)) { if (!this.isPure(elem, constantsOnly)) return false; } return true; } else if (t.isObjectExpression(node)) { - for (let prop of (node.properties: Array)) { + for (const prop of (node.properties: Array)) { if (!this.isPure(prop, constantsOnly)) return false; } return true; @@ -615,7 +611,7 @@ export default class Scope { getData(key) { let scope = this; do { - let data = scope.data[key]; + const data = scope.data[key]; if (data != null) return data; } while (scope = scope.parent); } @@ -628,7 +624,7 @@ export default class Scope { removeData(key) { let scope = this; do { - let data = scope.data[key]; + const data = scope.data[key]; if (data != null) scope.data[key] = null; } while (scope = scope.parent); } @@ -644,21 +640,21 @@ export default class Scope { } _crawl() { - let path = this.path; + const path = this.path; // this.references = Object.create(null); - this.bindings = Object.create(null); - this.globals = Object.create(null); - this.uids = Object.create(null); - this.data = Object.create(null); + this.bindings = Object.create(null); + this.globals = Object.create(null); + this.uids = Object.create(null); + this.data = Object.create(null); // ForStatement - left, init if (path.isLoop()) { - for (let key of (t.FOR_INIT_KEYS: Array)) { - let node = path.get(key); + for (const key of (t.FOR_INIT_KEYS: Array)) { + const node = path.get(key); if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); } } @@ -682,8 +678,8 @@ export default class Scope { // Function - params, rest if (path.isFunction()) { - let params: Array = path.get("params"); - for (let param of params) { + const params: Array = path.get("params"); + for (const param of params) { this.registerBinding("param", param); } } @@ -696,10 +692,10 @@ export default class Scope { // Program - let parent = this.getProgramParent(); + const parent = this.getProgramParent(); if (parent.crawling) return; - let state = { + const state = { references: [], constantViolations: [], assignments: [], @@ -710,14 +706,14 @@ export default class Scope { this.crawling = false; // register assignments - for (let path of state.assignments) { + for (const path of state.assignments) { // register undeclared bindings as globals - let ids = path.getBindingIdentifiers(); + const ids = path.getBindingIdentifiers(); let programParent; - for (let name in ids) { + for (const name in ids) { if (path.scope.getBinding(name)) continue; - programParent = programParent || path.scope.getProgramParent(); + programParent = programParent || path.scope.getProgramParent(); programParent.addGlobal(ids[name]); } @@ -726,8 +722,8 @@ export default class Scope { } // register references - for (let ref of state.references) { - let binding = ref.scope.getBinding(ref.node.name); + for (const ref of state.references) { + const binding = ref.scope.getBinding(ref.node.name); if (binding) { binding.reference(ref); } else { @@ -736,7 +732,7 @@ export default class Scope { } // register constant violations - for (let path of state.constantViolations) { + for (const path of state.constantViolations) { path.scope.registerConstantViolation(path); } } @@ -763,15 +759,15 @@ export default class Scope { path = path.get("body"); } - let unique = opts.unique; - let kind = opts.kind || "var"; - let blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; + const unique = opts.unique; + const kind = opts.kind || "var"; + const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; - let dataKey = `declaration:${kind}:${blockHoist}`; - let declarPath = !unique && path.getData(dataKey); + const dataKey = `declaration:${kind}:${blockHoist}`; + let declarPath = !unique && path.getData(dataKey); if (!declarPath) { - let declar = t.variableDeclaration(kind, []); + const declar = t.variableDeclaration(kind, []); declar._generated = true; declar._blockHoist = blockHoist; @@ -779,7 +775,7 @@ export default class Scope { if (!unique) path.setData(dataKey, declarPath); } - let declarator = t.variableDeclarator(opts.id, opts.init); + const declarator = t.variableDeclarator(opts.id, opts.init); declarPath.node.declarations.push(declarator); this.registerBinding(kind, declarPath.get("declarations").pop()); } @@ -833,7 +829,7 @@ export default class Scope { */ getAllBindings(): Object { - let ids = Object.create(null); + const ids = Object.create(null); let scope = this; do { @@ -849,13 +845,13 @@ export default class Scope { */ getAllBindingsOfKind(): Object { - let ids = Object.create(null); + const ids = Object.create(null); - for (let kind of (arguments: Array)) { + for (const kind of (arguments: Array)) { let scope = this; do { - for (let name in scope.bindings) { - let binding = scope.bindings[name]; + for (const name in scope.bindings) { + const binding = scope.bindings[name]; if (binding.kind === kind) ids[name] = binding; } scope = scope.parent; @@ -884,7 +880,7 @@ export default class Scope { let scope = this; do { - let binding = scope.getOwnBinding(name); + const binding = scope.getOwnBinding(name); if (binding) return this.warnOnFlowBinding(binding); } while (scope = scope.parent); } @@ -894,12 +890,12 @@ export default class Scope { } getBindingIdentifier(name: string) { - let info = this.getBinding(name); + const info = this.getBinding(name); return info && info.identifier; } getOwnBindingIdentifier(name: string) { - let binding = this.bindings[name]; + const binding = this.bindings[name]; return binding && binding.identifier; } @@ -926,7 +922,7 @@ export default class Scope { */ moveBindingTo(name, scope) { - let info = this.getBinding(name); + const info = this.getBinding(name); if (info) { info.scope.removeOwnBinding(name); info.scope = scope; @@ -940,7 +936,7 @@ export default class Scope { removeBinding(name: string) { // clear literal binding - let info = this.getBinding(name); + const info = this.getBinding(name); if (info) { info.scope.removeOwnBinding(name); } diff --git a/packages/babel-traverse/src/scope/lib/renamer.js b/packages/babel-traverse/src/scope/lib/renamer.js index b8c1fb3b9c..2079192e1c 100644 --- a/packages/babel-traverse/src/scope/lib/renamer.js +++ b/packages/babel-traverse/src/scope/lib/renamer.js @@ -1,7 +1,7 @@ import Binding from "../binding"; import * as t from "babel-types"; -let renameVisitor = { +const renameVisitor = { ReferencedIdentifier({ node }, state) { if (node.name === state.oldName) { node.name = state.newName; @@ -15,12 +15,12 @@ let renameVisitor = { }, "AssignmentExpression|Declaration"(path, state) { - let ids = path.getOuterBindingIdentifiers(); + const ids = path.getOuterBindingIdentifiers(); - for (let name in ids) { + for (const name in ids) { if (name === state.oldName) ids[name].name = state.newName; } - } + }, }; export default class Renamer { @@ -35,11 +35,11 @@ export default class Renamer { binding: Binding; maybeConvertFromExportDeclaration(parentDeclar) { - let exportDeclar = parentDeclar.parentPath.isExportDeclaration() && parentDeclar.parentPath; + const exportDeclar = parentDeclar.parentPath.isExportDeclaration() && parentDeclar.parentPath; if (!exportDeclar) return; // build specifiers that point back to this export declaration - let isDefault = exportDeclar.isExportDefaultDeclaration(); + const isDefault = exportDeclar.isExportDefaultDeclaration(); if (isDefault && (parentDeclar.isFunctionDeclaration() || parentDeclar.isClassDeclaration()) && !parentDeclar.node.id) { @@ -48,17 +48,17 @@ export default class Renamer { parentDeclar.node.id = parentDeclar.scope.generateUidIdentifier("default"); } - let bindingIdentifiers = parentDeclar.getOuterBindingIdentifiers(); - let specifiers = []; + const bindingIdentifiers = parentDeclar.getOuterBindingIdentifiers(); + const specifiers = []; - for (let name in bindingIdentifiers) { - let localName = name === this.oldName ? this.newName : name; - let exportedName = isDefault ? "default" : name; + for (const name in bindingIdentifiers) { + const localName = name === this.oldName ? this.newName : name; + const exportedName = isDefault ? "default" : name; specifiers.push(t.exportSpecifier(t.identifier(localName), t.identifier(exportedName))); } if (specifiers.length) { - let aliasDeclar = t.exportNamedDeclaration(null, specifiers); + const aliasDeclar = t.exportNamedDeclaration(null, specifiers); // hoist to the top if it's a function if (parentDeclar.isFunctionDeclaration()) { @@ -82,7 +82,7 @@ export default class Renamer { path.node._blockHoist = 3; path.replaceWith(t.variableDeclaration("let", [ - t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node)) + t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node)), ])); } @@ -97,17 +97,17 @@ export default class Renamer { path.node.id = t.identifier(this.oldName); this.binding.scope.parent.push({ - id: t.identifier(this.newName) + id: t.identifier(this.newName), }); path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node)); } rename(block?) { - let { binding, oldName, newName } = this; - let { scope, path } = binding; + const { binding, oldName, newName } = this; + const { scope, path } = binding; - let parentDeclar = path.find((path) => path.isDeclaration() || path.isFunctionExpression()); + const parentDeclar = path.find((path) => path.isDeclaration() || path.isFunctionExpression()); if (parentDeclar) { this.maybeConvertFromExportDeclaration(parentDeclar); } diff --git a/packages/babel-traverse/src/visitors.js b/packages/babel-traverse/src/visitors.js index 023cdb186c..f8de5b791d 100644 --- a/packages/babel-traverse/src/visitors.js +++ b/packages/babel-traverse/src/visitors.js @@ -24,16 +24,16 @@ export function explode(visitor) { visitor._exploded = true; // normalise pipes - for (let nodeType in visitor) { + for (const nodeType in visitor) { if (shouldIgnoreKey(nodeType)) continue; - let parts: Array = nodeType.split("|"); + const parts: Array = nodeType.split("|"); if (parts.length === 1) continue; - let fns = visitor[nodeType]; + const fns = visitor[nodeType]; delete visitor[nodeType]; - for (let part of parts) { + for (const part of parts) { visitor[part] = fns; } } @@ -52,15 +52,15 @@ export function explode(visitor) { ensureCallbackArrays(visitor); // add type wrappers - for (let nodeType of (Object.keys(visitor): Array)) { + for (const nodeType of (Object.keys(visitor): Array)) { if (shouldIgnoreKey(nodeType)) continue; - let wrapper = virtualTypes[nodeType]; + const wrapper = virtualTypes[nodeType]; if (!wrapper) continue; // wrap all the functions - let fns = visitor[nodeType]; - for (let type in fns) { + const fns = visitor[nodeType]; + for (const type in fns) { fns[type] = wrapCheck(wrapper, fns[type]); } @@ -68,7 +68,7 @@ export function explode(visitor) { delete visitor[nodeType]; if (wrapper.types) { - for (let type of (wrapper.types: Array)) { + for (const type of (wrapper.types: Array)) { // merge the visitor if necessary or just put it back in if (visitor[type]) { mergePair(visitor[type], fns); @@ -82,14 +82,14 @@ export function explode(visitor) { } // add aliases - for (let nodeType in visitor) { + for (const nodeType in visitor) { if (shouldIgnoreKey(nodeType)) continue; - let fns = visitor[nodeType]; + const fns = visitor[nodeType]; let aliases: ?Array = t.FLIPPED_ALIAS_KEYS[nodeType]; - let deprecratedKey = t.DEPRECATED_KEYS[nodeType]; + const deprecratedKey = t.DEPRECATED_KEYS[nodeType]; if (deprecratedKey) { console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`); aliases = [deprecratedKey]; @@ -100,8 +100,8 @@ export function explode(visitor) { // clear it from the visitor delete visitor[nodeType]; - for (let alias of aliases) { - let existing = visitor[alias]; + for (const alias of aliases) { + const existing = visitor[alias]; if (existing) { mergePair(existing, fns); } else { @@ -110,7 +110,7 @@ export function explode(visitor) { } } - for (let nodeType in visitor) { + for (const nodeType in visitor) { if (shouldIgnoreKey(nodeType)) continue; ensureCallbackArrays(visitor[nodeType]); @@ -126,7 +126,7 @@ export function verify(visitor) { throw new Error(messages.get("traverseVerifyRootFunction")); } - for (let nodeType in visitor) { + for (const nodeType in visitor) { if (nodeType === "enter" || nodeType === "exit") { validateVisitorMethods(nodeType, visitor[nodeType]); } @@ -137,9 +137,9 @@ export function verify(visitor) { throw new Error(messages.get("traverseVerifyNodeType", nodeType)); } - let visitors = visitor[nodeType]; + const visitors = visitor[nodeType]; if (typeof visitors === "object") { - for (let visitorKey in visitors) { + for (const visitorKey in visitors) { if (visitorKey === "enter" || visitorKey === "exit") { // verify that it just contains functions validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]); @@ -154,8 +154,8 @@ export function verify(visitor) { } function validateVisitorMethods(path, val) { - let fns = [].concat(val); - for (let fn of fns) { + const fns = [].concat(val); + for (const fn of fns) { if (typeof fn !== "function") { throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`); } @@ -163,15 +163,15 @@ function validateVisitorMethods(path, val) { } export function merge(visitors: Array, states: Array = [], wrapper?: ?Function) { - let rootVisitor = {}; + const rootVisitor = {}; for (let i = 0; i < visitors.length; i++) { - let visitor = visitors[i]; - let state = states[i]; + const visitor = visitors[i]; + const state = states[i]; explode(visitor); - for (let type in visitor) { + for (const type in visitor) { let visitorType = visitor[type]; // if we have state or wrapper then overload the callbacks to take it @@ -179,7 +179,7 @@ export function merge(visitors: Array, states: Array = [], wrapper?: ?Function) visitorType = wrapWithStateOrWrapper(visitorType, state, wrapper); } - let nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; + const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; mergePair(nodeVisitor, visitorType); } } @@ -188,9 +188,9 @@ export function merge(visitors: Array, states: Array = [], wrapper?: ?Function) } function wrapWithStateOrWrapper(oldVisitor, state, wrapper: ?Function) { - let newVisitor = {}; + const newVisitor = {}; - for (let key in oldVisitor) { + for (const key in oldVisitor) { let fns = oldVisitor[key]; // not an enter/exit array of callbacks @@ -219,10 +219,10 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper: ?Function) { } function ensureEntranceObjects(obj) { - for (let key in obj) { + for (const key in obj) { if (shouldIgnoreKey(key)) continue; - let fns = obj[key]; + const fns = obj[key]; if (typeof fns === "function") { obj[key] = { enter: fns }; } @@ -235,7 +235,7 @@ function ensureCallbackArrays(obj) { } function wrapCheck(wrapper, fn) { - let newFn = function (path) { + const newFn = function (path) { if (wrapper.checkPath(path)) { return fn.apply(this, arguments); } @@ -258,7 +258,7 @@ function shouldIgnoreKey(key) { } function mergePair(dest, src) { - for (let key in src) { + for (const key in src) { dest[key] = [].concat(dest[key] || [], src[key]); } } diff --git a/packages/babel-traverse/test/ancestry.js b/packages/babel-traverse/test/ancestry.js index 43e09859ef..d3587a71d0 100644 --- a/packages/babel-traverse/test/ancestry.js +++ b/packages/babel-traverse/test/ancestry.js @@ -1,63 +1,63 @@ -let traverse = require("../lib").default; -let assert = require("assert"); -let parse = require("babylon").parse; +const traverse = require("../lib").default; +const assert = require("assert"); +const parse = require("babylon").parse; describe("path/ancestry", function () { describe("isAncestor", function () { - let ast = parse("var a = 1; 'a';"); + const ast = parse("var a = 1; 'a';"); it("returns true if ancestor", function() { - let paths = []; + const paths = []; traverse(ast, { "Program|NumericLiteral"(path) { paths.push(path); }, }); - let [ programPath, numberPath ] = paths; + const [ programPath, numberPath ] = paths; assert(programPath.isAncestor(numberPath)); }); it("returns false if not ancestor", function() { - let paths = []; + const paths = []; traverse(ast, { "Program|NumericLiteral|StringLiteral"(path) { paths.push(path); - } + }, }); - let [ , numberPath, stringPath ] = paths; + const [ , numberPath, stringPath ] = paths; assert(!stringPath.isAncestor(numberPath)); }); }); describe("isDescendant", function () { - let ast = parse("var a = 1; 'a';"); + const ast = parse("var a = 1; 'a';"); it("returns true if descendant", function() { - let paths = []; + const paths = []; traverse(ast, { "Program|NumericLiteral"(path) { paths.push(path); }, }); - let [ programPath, numberPath ] = paths; + const [ programPath, numberPath ] = paths; assert(numberPath.isDescendant(programPath)); }); it("returns false if not descendant", function() { - let paths = []; + const paths = []; traverse(ast, { "Program|NumericLiteral|StringLiteral"(path) { paths.push(path); - } + }, }); - let [ , numberPath, stringPath ] = paths; + const [ , numberPath, stringPath ] = paths; assert(!numberPath.isDescendant(stringPath)); }); diff --git a/packages/babel-traverse/test/evaluation.js b/packages/babel-traverse/test/evaluation.js index 956d656eb3..1269f7c013 100644 --- a/packages/babel-traverse/test/evaluation.js +++ b/packages/babel-traverse/test/evaluation.js @@ -1,15 +1,15 @@ -let traverse = require("../lib").default; -let assert = require("assert"); -let parse = require("babylon").parse; +const traverse = require("../lib").default; +const assert = require("assert"); +const parse = require("babylon").parse; function getPath(code) { - let ast = parse(code); + const ast = parse(code); let path; traverse(ast, { Program: function (_path) { path = _path; _path.stop(); - } + }, }); return path; } @@ -33,7 +33,8 @@ describe("evaluation", function () { it("should bail out on recursive evaluation", function () { assert.strictEqual( - getPath("function fn(a) { var g = a ? 1 : 2, a = g * this.foo; }").get("body.0.body.body.0.declarations.1.init").evaluate().confident, + getPath("function fn(a) { var g = a ? 1 : 2, a = g * this.foo; }") + .get("body.0.body.body.0.declarations.1.init").evaluate().confident, false ); }); @@ -54,7 +55,8 @@ describe("evaluation", function () { it("should deopt when var is redeclared in the same scope", function () { assert.strictEqual( - getPath("var x = 2; var y = x + 2; { var x = 3 }").get("body.1.declarations.0.init").evaluate().confident, + getPath("var x = 2; var y = x + 2; { var x = 3 }") + .get("body.1.declarations.0.init").evaluate().confident, false ); }); @@ -73,7 +75,8 @@ describe("evaluation", function () { it("it should not deopt let/const inside blocks", function () { assert.strictEqual( - getPath("let x = 5; { let x = 1; } let y = x + 5").get("body.2.declarations.0.init").evaluate().value, + getPath("let x = 5; { let x = 1; } let y = x + 5") + .get("body.2.declarations.0.init").evaluate().value, 10 ); const constExample = "const d = true; if (d && true || false) { const d = false; d && 5; }"; @@ -98,4 +101,22 @@ describe("evaluation", function () { false ); }); + + it("should evaluate undefined, NaN and Infinity", () => { + assert.strictEqual(getPath("undefined").get("body.0.expression").evaluate().confident, true); + assert.strictEqual(getPath("NaN").get("body.0.expression").evaluate().confident, true); + assert.strictEqual(getPath("Infinity").get("body.0.expression").evaluate().confident, true); + }); + + it("should deopt redefined primitives - undefined, NaN and Infinity", () => { + const eval_undef = getPath("let undefined; undefined;").get("body.1.expression").evaluate(); + const eval_nan = getPath("let NaN; NaN;").get("body.1.expression").evaluate(); + const eval_inf = getPath("let Infinity; Infinity;").get("body.1.expression").evaluate(); + assert.strictEqual(eval_undef.confident, false); + assert.strictEqual(eval_nan.confident, false); + assert.strictEqual(eval_inf.confident, false); + + assert.strictEqual(eval_undef.deopt.type, "VariableDeclarator"); + assert.strictEqual(eval_undef.deopt.parentPath.node.kind, "let"); + }); }); diff --git a/packages/babel-traverse/test/family.js b/packages/babel-traverse/test/family.js index c6fc297f86..f261d4b87e 100644 --- a/packages/babel-traverse/test/family.js +++ b/packages/babel-traverse/test/family.js @@ -1,10 +1,10 @@ -let traverse = require("../lib").default; -let assert = require("assert"); -let parse = require("babylon").parse; +const traverse = require("../lib").default; +const assert = require("assert"); +const parse = require("babylon").parse; describe("path/family", function () { describe("getBindingIdentifiers", function () { - let ast = parse("var a = 1, {b} = c, [d] = e; function f() {}"); + const ast = parse("var a = 1, {b} = c, [d] = e; function f() {}"); let nodes = {}, paths = {}, outerNodes = {}, outerPaths = {}; traverse(ast, { VariableDeclaration(path) { @@ -14,7 +14,7 @@ describe("path/family", function () { FunctionDeclaration(path) { outerNodes = path.getOuterBindingIdentifiers(); outerPaths = path.getOuterBindingIdentifierPaths(); - } + }, }); it("should contain keys of nodes in paths", function () { @@ -52,6 +52,31 @@ describe("path/family", function () { assert.strictEqual(outerNodes[id], outerPaths[id].node, "nodes match"); }); }); + + }); + describe("getSibling", function () { + const ast = parse("var a = 1, {b} = c, [d] = e; function f() {} function g() {}"); + let sibling = {}, lastSibling = {}; + traverse(ast, { + VariableDeclaration(path) { + sibling = path.getSibling(path.key); + lastSibling = sibling.getNextSibling().getNextSibling(); + }, + }); + + it("should return traverse sibling nodes", function () { + assert.ok(sibling.getNextSibling().node, "has property node"); + assert.ok(lastSibling.getPrevSibling().node, "has property node"); + assert.equal(!!sibling.getPrevSibling().node, false, "out of scope"); + assert.equal(!!lastSibling.getNextSibling().node, false, "out of scope"); + }); + + it("should return all preceding and succeeding sibling nodes", function () { + assert.ok(sibling.getAllNextSiblings().length, "Has next sibling"); + assert.ok(lastSibling.getAllPrevSiblings().length, "Has prev sibling"); + assert.equal(sibling.getAllNextSiblings().length, 2, "Has 2 succeeding sibling"); + assert.equal(lastSibling.getAllPrevSiblings().length, 2, "Has 2 preceeding sibling"); + }); }); }); diff --git a/packages/babel-traverse/test/inference.js b/packages/babel-traverse/test/inference.js index 5819cd1b06..7fe06584d5 100644 --- a/packages/babel-traverse/test/inference.js +++ b/packages/babel-traverse/test/inference.js @@ -4,13 +4,13 @@ import { parse } from "babylon"; import * as t from "babel-types"; function getPath(code) { - const ast = parse(code, {plugins: ["flow", "asyncGenerators"]}); + const ast = parse(code, { plugins: ["flow", "asyncGenerators"] }); let path; traverse(ast, { Program: function (_path) { path = _path; _path.stop(); - } + }, }); return path; } @@ -36,7 +36,8 @@ describe("inference", function () { }); it("it should bail when type changes", function () { - const path = getPath("var x = 1; if (foo) x = null;else x = 3; x === 2").get("body")[2].get("expression"); + const path = getPath("var x = 1; if (foo) x = null;else x = 3; x === 2") + .get("body")[2].get("expression"); const left = path.get("left"); const right = path.get("right"); @@ -144,7 +145,8 @@ describe("inference", function () { it("should infer call return type using async generator function", function () { const path = getPath("(async function * (): string {})()").get("body")[0].get("expression"); const type = path.getTypeAnnotation(); - assert.ok(t.isGenericTypeAnnotation(type) && type.id.name === "AsyncIterator", "should be AsyncIterator"); + assert.ok(t.isGenericTypeAnnotation(type) && type.id.name === "AsyncIterator", + "should be AsyncIterator"); }); it("should infer number from x/y", function () { const path = getPath("x/y").get("body")[0].get("expression"); diff --git a/packages/babel-traverse/test/removal.js b/packages/babel-traverse/test/removal.js new file mode 100644 index 0000000000..a2a43acd34 --- /dev/null +++ b/packages/babel-traverse/test/removal.js @@ -0,0 +1,34 @@ +import traverse from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; +import generate from "babel-generator"; + +function getPath(code) { + const ast = parse(code); + let path; + traverse(ast, { + Program: function (_path) { + path = _path; + _path.stop(); + }, + }); + + return path; +} + +function generateCode(path) { + return generate(path.node).code; +} + +describe("removal", function () { + describe("ArrowFunction", function () { + it("remove body", function () { + const rootPath = getPath("x = () => b;"); + const path = rootPath.get("body")[0].get("expression").get("right"); + const body = path.get("body"); + body.remove(); + + assert.equal(generateCode(rootPath), "x = () => {};", "body should be replaced with BlockStatement"); + }); + }); +}); diff --git a/packages/babel-traverse/test/replacement.js b/packages/babel-traverse/test/replacement.js new file mode 100644 index 0000000000..eb29364f2f --- /dev/null +++ b/packages/babel-traverse/test/replacement.js @@ -0,0 +1,28 @@ +import traverse from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; +import * as t from "babel-types"; + +describe("path/replacement", function () { + describe("replaceWith", function () { + const ast = parse("export default function() {};", { sourceType: "module" }); + + it("replaces declaration in ExportDefaultDeclaration node", function() { + traverse(ast, { + FunctionDeclaration(path) { + path.replaceWith(t.arrayExpression([ + t.functionExpression( + path.node.id, + path.node.params, + path.node.body, + path.node.generator, + path.node.async + ), + ])); + }, + }); + + assert(ast.program.body[0].declaration.type == "ArrayExpression"); + }); + }); +}); diff --git a/packages/babel-traverse/test/scope.js b/packages/babel-traverse/test/scope.js index 332a3eabd9..75a01c7cdd 100644 --- a/packages/babel-traverse/test/scope.js +++ b/packages/babel-traverse/test/scope.js @@ -1,38 +1,58 @@ -let traverse = require("../lib").default; -let assert = require("assert"); -let parse = require("babylon").parse; +const traverse = require("../lib").default; +const assert = require("assert"); +const parse = require("babylon").parse; function getPath(code) { - let ast = parse(code); + const ast = parse(code); let path; traverse(ast, { Program: function (_path) { path = _path; _path.stop(); - } + }, }); return path; } +function getIdentifierPath(code) { + const ast = parse(code); + let nodePath; + traverse(ast, { + Identifier: function(path) { + nodePath = path; + path.stop(); + }, + }); + + return nodePath; +} + describe("scope", function () { describe("binding paths", function () { it("function declaration id", function () { - assert.ok(getPath("function foo() {}").scope.getBinding("foo").path.type === "FunctionDeclaration"); + assert.ok(getPath("function foo() {}") + .scope.getBinding("foo").path.type === "FunctionDeclaration"); }); it("function expression id", function () { - assert.ok(getPath("(function foo() {})").get("body")[0].get("expression").scope.getBinding("foo").path.type === "FunctionExpression"); + assert.ok(getPath("(function foo() {})").get("body")[0].get("expression") + .scope.getBinding("foo").path.type === "FunctionExpression"); }); it("function param", function () { - assert.ok(getPath("(function (foo) {})").get("body")[0].get("expression").scope.getBinding("foo").path.type === "Identifier"); + assert.ok(getPath("(function (foo) {})").get("body")[0].get("expression") + .scope.getBinding("foo").path.type === "Identifier"); }); it("variable declaration", function () { - assert.ok(getPath("var foo = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); - assert.ok(getPath("var { foo } = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); - assert.ok(getPath("var [ foo ] = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); - assert.ok(getPath("var { bar: [ foo ] } = null;").scope.getBinding("foo").path.type === "VariableDeclarator"); + assert.ok(getPath("var foo = null;") + .scope.getBinding("foo").path.type === "VariableDeclarator"); + assert.ok(getPath("var { foo } = null;") + .scope.getBinding("foo").path.type === "VariableDeclarator"); + assert.ok(getPath("var [ foo ] = null;") + .scope.getBinding("foo").path.type === "VariableDeclarator"); + assert.ok(getPath("var { bar: [ foo ] } = null;") + .scope.getBinding("foo").path.type === "VariableDeclarator"); }); it("purity", function () { @@ -60,5 +80,13 @@ describe("scope", function () { _foo2: { } `).scope.generateUid("foo"), "_foo3"); }); + + it("reference paths", function() { + const path = getIdentifierPath("function square(n) { return n * n}"); + const referencePaths = path.context.scope.bindings.n.referencePaths; + assert.equal(referencePaths.length, 2); + assert.deepEqual(referencePaths[0].node.loc.start, { line: 1, column: 28 }); + assert.deepEqual(referencePaths[1].node.loc.start, { line: 1, column: 32 }); + }); }); }); diff --git a/packages/babel-traverse/test/traverse.js b/packages/babel-traverse/test/traverse.js index cee7157150..57f6a343c4 100644 --- a/packages/babel-traverse/test/traverse.js +++ b/packages/babel-traverse/test/traverse.js @@ -1,45 +1,46 @@ -let traverse = require("../lib").default; -let assert = require("assert"); -let _ = require("lodash"); -let parse = require("babylon").parse; +const cloneDeep = require("lodash/cloneDeep"); +const traverse = require("../lib").default; +const assert = require("assert"); +const parse = require("babylon").parse; describe("traverse", function () { - let code = ` + const code = ` var foo = "bar"; this.test = "wow"; `; - let ast = parse(code); - let program = ast.program; - let body = program.body; + const ast = parse(code); + const program = ast.program; + const body = program.body; it("traverse replace", function () { - let replacement = { + const replacement = { type: "StringLiteral", - value: "foo" + value: "foo", }; - let ast2 = _.cloneDeep(program); + const ast2 = cloneDeep(program); traverse(ast2, { enter: function (path) { if (path.node.type === "ThisExpression") path.replaceWith(replacement); - } + }, }); assert.equal(ast2.body[1].expression.left.object, replacement); }); it("traverse", function () { - let expect = [ + const expect = [ body[0], body[0].declarations[0], body[0].declarations[0].id, body[0].declarations[0].init, - body[1], body[1].expression, body[1].expression.left, body[1].expression.left.object, body[1].expression.left.property, body[1].expression.right + body[1], body[1].expression, body[1].expression.left, body[1].expression.left.object, + body[1].expression.left.property, body[1].expression.right, ]; - let actual = []; + const actual = []; traverse(program, { enter: function (path) { actual.push(path.node); - } + }, }); assert.deepEqual(actual, expect); @@ -49,23 +50,23 @@ describe("traverse", function () { traverse(null, { enter: function () { throw new Error("should not be ran"); - } + }, }); }); it("traverse blacklistTypes", function () { - let expect = [ + const expect = [ body[0], body[0].declarations[0], body[0].declarations[0].id, body[0].declarations[0].init, - body[1], body[1].expression, body[1].expression.right + body[1], body[1].expression, body[1].expression.right, ]; - let actual = []; + const actual = []; traverse(program, { blacklist: ["MemberExpression"], enter: function (path) { actual.push(path.node); - } + }, }); assert.deepEqual(actual, expect); @@ -85,26 +86,26 @@ describe("traverse", function () { }); it("clearCache", function () { - let paths = []; - let scopes = []; + const paths = []; + const scopes = []; traverse(ast, { enter(path) { scopes.push(path.scope); paths.push(path); path.stop(); - } + }, }); traverse.clearCache(); - let paths2 = []; - let scopes2 = []; + const paths2 = []; + const scopes2 = []; traverse(ast, { enter(path) { scopes2.push(path.scope); paths2.push(path); path.stop(); - } + }, }); scopes2.forEach(function (_, i) { @@ -114,20 +115,20 @@ describe("traverse", function () { }); it("clearPath", function () { - let paths = []; + const paths = []; traverse(ast, { enter(path) { paths.push(path); - } + }, }); traverse.clearCache.clearPath(); - let paths2 = []; + const paths2 = []; traverse(ast, { enter(path) { paths2.push(path); - } + }, }); paths2.forEach(function (p, i) { @@ -136,22 +137,22 @@ describe("traverse", function () { }); it("clearScope", function () { - let scopes = []; + const scopes = []; traverse(ast, { enter(path) { scopes.push(path.scope); path.stop(); - } + }, }); traverse.clearCache.clearScope(); - let scopes2 = []; + const scopes2 = []; traverse(ast, { enter(path) { scopes2.push(path.scope); path.stop(); - } + }, }); scopes2.forEach(function (p, i) { diff --git a/packages/babel-types/README.md b/packages/babel-types/README.md index 13b2ec3a5a..d8532bd44f 100644 --- a/packages/babel-types/README.md +++ b/packages/babel-types/README.md @@ -575,12 +575,12 @@ Aliases: `Flow`, `FlowBaseAnnotation` --- -### existentialTypeParam +### existsTypeAnnotation ```javascript -t.existentialTypeParam() +t.existsTypeAnnotation() ``` -See also `t.isExistentialTypeParam(node, opts)` and `t.assertExistentialTypeParam(node, opts)`. +See also `t.isExistsTypeAnnotation(node, opts)` and `t.assertExistsTypeAnnotation(node, opts)`. Aliases: `Flow` @@ -694,21 +694,6 @@ See also `t.isFile(node, opts)` and `t.assertFile(node, opts)`. --- -### forAwaitStatement -```javascript -t.forAwaitStatement(left, right, body) -``` - -See also `t.isForAwaitStatement(node, opts)` and `t.assertForAwaitStatement(node, opts)`. - -Aliases: `Scopable`, `Statement`, `For`, `BlockParent`, `Loop`, `ForXStatement` - - - `left`: `VariableDeclaration | LVal` (required) - - `right`: `Expression` (required) - - `body`: `Statement` (required) - ---- - ### forInStatement ```javascript t.forInStatement(left, right, body) @@ -736,6 +721,7 @@ Aliases: `Scopable`, `Statement`, `For`, `BlockParent`, `Loop`, `ForXStatement` - `left`: `VariableDeclaration | LVal` (required) - `right`: `Expression` (required) - `body`: `Statement` (required) + - `await`: `boolean` (default: `false`) --- @@ -930,6 +916,7 @@ Aliases: `ModuleSpecifier` - `local`: `Identifier` (required) - `imported`: `Identifier` (required) + - `importKind`: `null | 'type' | 'typeof'` (default: `null`) --- @@ -1268,6 +1255,18 @@ Aliases: `Flow` - `typeAnnotation` (required) +--- + +### numberLiteralTypeAnnotation +```javascript +t.numberLiteralTypeAnnotation() +``` + +See also `t.isNumberLiteralTypeAnnotation(node, opts)` and `t.assertNumberLiteralTypeAnnotation(node, opts)`. + +Aliases: `Flow` + + --- ### numberTypeAnnotation @@ -1293,18 +1292,6 @@ Aliases: `Expression`, `Pureish`, `Literal`, `Immutable` - `value`: `number` (required) ---- - -### numericLiteralTypeAnnotation -```javascript -t.numericLiteralTypeAnnotation() -``` - -See also `t.isNumericLiteralTypeAnnotation(node, opts)` and `t.assertNumericLiteralTypeAnnotation(node, opts)`. - -Aliases: `Flow` - - --- ### objectExpression @@ -1316,7 +1303,7 @@ See also `t.isObjectExpression(node, opts)` and `t.assertObjectExpression(node, Aliases: `Expression` - - `properties`: `Array` (required) + - `properties`: `Array` (required) --- @@ -1351,7 +1338,7 @@ See also `t.isObjectPattern(node, opts)` and `t.assertObjectPattern(node, opts)` Aliases: `Pattern`, `LVal` - - `properties`: `Array` (required) + - `properties`: `Array` (required) - `typeAnnotation` (required) - `decorators`: `Array` (default: `null`) @@ -1501,19 +1488,6 @@ Aliases: `LVal` --- -### restProperty -```javascript -t.restProperty(argument) -``` - -See also `t.isRestProperty(node, opts)` and `t.assertRestProperty(node, opts)`. - -Aliases: `UnaryLike` - - - `argument`: `LVal` (required) - ---- - ### returnStatement ```javascript t.returnStatement(argument) @@ -1553,19 +1527,6 @@ Aliases: `UnaryLike` --- -### spreadProperty -```javascript -t.spreadProperty(argument) -``` - -See also `t.isSpreadProperty(node, opts)` and `t.assertSpreadProperty(node, opts)`. - -Aliases: `UnaryLike` - - - `argument`: `Expression` (required) - ---- - ### stringLiteral ```javascript t.stringLiteral(value) diff --git a/packages/babel-types/package.json b/packages/babel-types/package.json index 99172ac9bc..7c7c6580b5 100644 --- a/packages/babel-types/package.json +++ b/packages/babel-types/package.json @@ -1,6 +1,6 @@ { "name": "babel-types", - "version": "6.21.0", + "version": "7.0.0-alpha.1", "description": "Babel Types is a Lodash-esque utility library for AST nodes", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,12 +8,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-types", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^6.20.0", "esutils": "^2.0.2", "lodash": "^4.2.0", "to-fast-properties": "^1.0.1" }, "devDependencies": { - "babylon": "^6.8.2" + "babylon": "7.0.0-beta.4" } } diff --git a/packages/babel-types/src/constants.js b/packages/babel-types/src/constants.js index 72f0a16387..84c2aec646 100644 --- a/packages/babel-types/src/constants.js +++ b/packages/babel-types/src/constants.js @@ -1,28 +1,28 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ export const STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; -export const FLATTENABLE_KEYS = ["body", "expressions"]; -export const FOR_INIT_KEYS = ["left", "init"]; -export const COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"]; +export const FLATTENABLE_KEYS = ["body", "expressions"]; +export const FOR_INIT_KEYS = ["left", "init"]; +export const COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"]; export const LOGICAL_OPERATORS = ["||", "&&"]; -export const UPDATE_OPERATORS = ["++", "--"]; +export const UPDATE_OPERATORS = ["++", "--"]; export const BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="]; -export const EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="]; -export const COMPARISON_BINARY_OPERATORS = [...EQUALITY_BINARY_OPERATORS, "in", "instanceof"]; -export const BOOLEAN_BINARY_OPERATORS = [...COMPARISON_BINARY_OPERATORS, ...BOOLEAN_NUMBER_BINARY_OPERATORS]; -export const NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"]; -export const BINARY_OPERATORS = ["+", ...NUMBER_BINARY_OPERATORS, ...BOOLEAN_BINARY_OPERATORS]; +export const EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="]; +export const COMPARISON_BINARY_OPERATORS = [...EQUALITY_BINARY_OPERATORS, "in", "instanceof"]; +export const BOOLEAN_BINARY_OPERATORS = [...COMPARISON_BINARY_OPERATORS, ...BOOLEAN_NUMBER_BINARY_OPERATORS]; +export const NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"]; +export const BINARY_OPERATORS = ["+", ...NUMBER_BINARY_OPERATORS, ...BOOLEAN_BINARY_OPERATORS]; export const BOOLEAN_UNARY_OPERATORS = ["delete", "!"]; -export const NUMBER_UNARY_OPERATORS = ["+", "-", "++", "--", "~"]; -export const STRING_UNARY_OPERATORS = ["typeof"]; -export const UNARY_OPERATORS = ["void", ...BOOLEAN_UNARY_OPERATORS, ...NUMBER_UNARY_OPERATORS, ...STRING_UNARY_OPERATORS]; +export const NUMBER_UNARY_OPERATORS = ["+", "-", "++", "--", "~"]; +export const STRING_UNARY_OPERATORS = ["typeof"]; +export const UNARY_OPERATORS = ["void", ...BOOLEAN_UNARY_OPERATORS, ...NUMBER_UNARY_OPERATORS, ...STRING_UNARY_OPERATORS]; export const INHERIT_KEYS = { optional: ["typeAnnotation", "typeParameters", "returnType"], - force: ["start", "loc", "end"] + force: ["start", "loc", "end"], }; export const BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); diff --git a/packages/babel-types/src/converters.js b/packages/babel-types/src/converters.js index dcfc14d9f9..686ac2d419 100644 --- a/packages/babel-types/src/converters.js +++ b/packages/babel-types/src/converters.js @@ -1,7 +1,5 @@ import isPlainObject from "lodash/isPlainObject"; -import isNumber from "lodash/isNumber"; import isRegExp from "lodash/isRegExp"; -import isString from "lodash/isString"; import type { Scope } from "babel-traverse"; import * as t from "./index"; @@ -24,10 +22,10 @@ export function toComputedKey(node: Object, key: Object = node.key || node.prope export function toSequenceExpression(nodes: Array, scope: Scope): ?Object { if (!nodes || !nodes.length) return; - let declars = []; - let bailed = false; + const declars = []; + let bailed = false; - let result = convert(nodes); + const result = convert(nodes); if (bailed) return; for (let i = 0; i < declars.length; i++) { @@ -38,9 +36,9 @@ export function toSequenceExpression(nodes: Array, scope: Scope): ?Objec function convert(nodes) { let ensureLastUndefined = false; - let exprs = []; + const exprs = []; - for (let node of (nodes: Array)) { + for (const node of (nodes: Array)) { if (t.isExpression(node)) { exprs.push(node); } else if (t.isExpressionStatement(node)) { @@ -48,12 +46,12 @@ export function toSequenceExpression(nodes: Array, scope: Scope): ?Objec } else if (t.isVariableDeclaration(node)) { if (node.kind !== "var") return bailed = true; // bailed - for (let declar of (node.declarations: Array)) { - let bindings = t.getBindingIdentifiers(declar); - for (let key in bindings) { + for (const declar of (node.declarations: Array)) { + const bindings = t.getBindingIdentifiers(declar); + for (const key in bindings) { declars.push({ kind: node.kind, - id: bindings[key] + id: bindings[key], }); } @@ -65,8 +63,8 @@ export function toSequenceExpression(nodes: Array, scope: Scope): ?Objec ensureLastUndefined = true; continue; } else if (t.isIfStatement(node)) { - let consequent = node.consequent ? convert([node.consequent]) : scope.buildUndefinedNode(); - let alternate = node.alternate ? convert([node.alternate]) : scope.buildUndefinedNode(); + const consequent = node.consequent ? convert([node.consequent]) : scope.buildUndefinedNode(); + const alternate = node.alternate ? convert([node.alternate]) : scope.buildUndefinedNode(); if (!consequent || !alternate) return bailed = true; exprs.push(t.conditionalExpression(node.test, consequent, alternate)); @@ -272,19 +270,19 @@ export function valueToNode(value: any): Object { } // strings - if (isString(value)) { + if (typeof value === "string") { return t.stringLiteral(value); } // numbers - if (isNumber(value)) { + if (typeof value === "number") { return t.numericLiteral(value); } // regexes if (isRegExp(value)) { - let pattern = value.source; - let flags = value.toString().match(/\/([a-z]+|)$/)[1]; + const pattern = value.source; + const flags = value.toString().match(/\/([a-z]+|)$/)[1]; return t.regExpLiteral(pattern, flags); } @@ -295,8 +293,8 @@ export function valueToNode(value: any): Object { // object if (isPlainObject(value)) { - let props = []; - for (let key in value) { + const props = []; + for (const key in value) { let nodeKey; if (t.isValidIdentifier(key)) { nodeKey = t.identifier(key); diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index 19a37158a7..1e206ac50e 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -1,4 +1,4 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ import * as t from "../index"; @@ -26,62 +26,62 @@ defineType("ArrayExpression", { assertEach(assertNodeOrValueType("null", "Expression", "SpreadElement")) ), default: [], - } + }, }, visitor: ["elements"], - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("AssignmentExpression", { fields: { operator: { - validate: assertValueType("string") + validate: assertValueType("string"), }, left: { - validate: assertNodeType("LVal") + validate: assertNodeType("LVal"), }, right: { - validate: assertNodeType("Expression") - } + validate: assertNodeType("Expression"), + }, }, builder: ["operator", "left", "right"], visitor: ["left", "right"], - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("BinaryExpression", { builder: ["operator", "left", "right"], fields: { operator: { - validate: assertOneOf(...BINARY_OPERATORS) + validate: assertOneOf(...BINARY_OPERATORS), }, left: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, right: { - validate: assertNodeType("Expression") - } + validate: assertNodeType("Expression"), + }, }, visitor: ["left", "right"], - aliases: ["Binary", "Expression"] + aliases: ["Binary", "Expression"], }); defineType("Directive", { visitor: ["value"], fields: { value: { - validate: assertNodeType("DirectiveLiteral") - } - } + validate: assertNodeType("DirectiveLiteral"), + }, + }, }); defineType("DirectiveLiteral", { builder: ["value"], fields: { value: { - validate: assertValueType("string") - } - } + validate: assertValueType("string"), + }, + }, }); defineType("BlockStatement", { @@ -90,13 +90,13 @@ defineType("BlockStatement", { fields: { directives: { validate: chain(assertValueType("array"), assertEach(assertNodeType("Directive"))), - default: [] + default: [], }, body: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))) - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))), + }, }, - aliases: ["Scopable", "BlockParent", "Block", "Statement"] + aliases: ["Scopable", "BlockParent", "Block", "Statement"], }); defineType("BreakStatement", { @@ -104,52 +104,52 @@ defineType("BreakStatement", { fields: { label: { validate: assertNodeType("Identifier"), - optional: true - } + optional: true, + }, }, - aliases: ["Statement", "Terminatorless", "CompletionStatement"] + aliases: ["Statement", "Terminatorless", "CompletionStatement"], }); defineType("CallExpression", { visitor: ["callee", "arguments"], fields: { callee: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, arguments: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression", "SpreadElement"))) - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression", "SpreadElement"))), + }, }, - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("CatchClause", { visitor: ["param", "body"], fields: { param: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, body: { - validate: assertNodeType("BlockStatement") - } + validate: assertNodeType("BlockStatement"), + }, }, - aliases: ["Scopable"] + aliases: ["Scopable"], }); defineType("ConditionalExpression", { visitor: ["test", "consequent", "alternate"], fields: { test: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, consequent: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, alternate: { - validate: assertNodeType("Expression") - } + validate: assertNodeType("Expression"), + }, }, - aliases: ["Expression", "Conditional"] + aliases: ["Expression", "Conditional"], }); defineType("ContinueStatement", { @@ -157,41 +157,41 @@ defineType("ContinueStatement", { fields: { label: { validate: assertNodeType("Identifier"), - optional: true - } + optional: true, + }, }, - aliases: ["Statement", "Terminatorless", "CompletionStatement"] + aliases: ["Statement", "Terminatorless", "CompletionStatement"], }); defineType("DebuggerStatement", { - aliases: ["Statement"] + aliases: ["Statement"], }); defineType("DoWhileStatement", { visitor: ["test", "body"], fields: { test: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, body: { - validate: assertNodeType("Statement") - } + validate: assertNodeType("Statement"), + }, }, - aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"] + aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"], }); defineType("EmptyStatement", { - aliases: ["Statement"] + aliases: ["Statement"], }); defineType("ExpressionStatement", { visitor: ["expression"], fields: { expression: { - validate: assertNodeType("Expression") - } + validate: assertNodeType("Expression"), + }, }, - aliases: ["Statement", "ExpressionWrapper"] + aliases: ["Statement", "ExpressionWrapper"], }); defineType("File", { @@ -199,9 +199,9 @@ defineType("File", { visitor: ["program"], fields: { program: { - validate: assertNodeType("Program") - } - } + validate: assertNodeType("Program"), + }, + }, }); defineType("ForInStatement", { @@ -209,15 +209,15 @@ defineType("ForInStatement", { aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], fields: { left: { - validate: assertNodeType("VariableDeclaration", "LVal") + validate: assertNodeType("VariableDeclaration", "LVal"), }, right: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, body: { - validate: assertNodeType("Statement") - } - } + validate: assertNodeType("Statement"), + }, + }, }); defineType("ForStatement", { @@ -226,20 +226,20 @@ defineType("ForStatement", { fields: { init: { validate: assertNodeType("VariableDeclaration", "Expression"), - optional: true + optional: true, }, test: { validate: assertNodeType("Expression"), - optional: true + optional: true, }, update: { validate: assertNodeType("Expression"), - optional: true + optional: true, }, body: { - validate: assertNodeType("Statement") - } - } + validate: assertNodeType("Statement"), + }, + }, }); defineType("FunctionDeclaration", { @@ -247,22 +247,22 @@ defineType("FunctionDeclaration", { visitor: ["id", "params", "body", "returnType", "typeParameters"], fields: { id: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, params: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))), }, body: { - validate: assertNodeType("BlockStatement") + validate: assertNodeType("BlockStatement"), }, generator: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, async: { default: false, - validate: assertValueType("boolean") - } + validate: assertValueType("boolean"), + }, }, aliases: [ "Scopable", @@ -271,8 +271,8 @@ defineType("FunctionDeclaration", { "FunctionParent", "Statement", "Pureish", - "Declaration" - ] + "Declaration", + ], }); defineType("FunctionExpression", { @@ -281,23 +281,23 @@ defineType("FunctionExpression", { fields: { id: { validate: assertNodeType("Identifier"), - optional: true + optional: true, }, params: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))), }, body: { - validate: assertNodeType("BlockStatement") + validate: assertNodeType("BlockStatement"), }, generator: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, async: { default: false, - validate: assertValueType("boolean") - } - } + validate: assertValueType("boolean"), + }, + }, }); defineType("Identifier", { @@ -310,12 +310,12 @@ defineType("Identifier", { if (!t.isValidIdentifier(val)) { // todo } - } + }, }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("IfStatement", { @@ -323,16 +323,16 @@ defineType("IfStatement", { aliases: ["Statement", "Conditional"], fields: { test: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, consequent: { - validate: assertNodeType("Statement") + validate: assertNodeType("Statement"), }, alternate: { optional: true, - validate: assertNodeType("Statement") - } - } + validate: assertNodeType("Statement"), + }, + }, }); defineType("LabeledStatement", { @@ -340,22 +340,22 @@ defineType("LabeledStatement", { aliases: ["Statement"], fields: { label: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, body: { - validate: assertNodeType("Statement") - } - } + validate: assertNodeType("Statement"), + }, + }, }); defineType("StringLiteral", { builder: ["value"], fields: { value: { - validate: assertValueType("string") - } + validate: assertValueType("string"), + }, }, - aliases: ["Expression", "Pureish", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"], }); defineType("NumericLiteral", { @@ -363,24 +363,24 @@ defineType("NumericLiteral", { deprecatedAlias: "NumberLiteral", fields: { value: { - validate: assertValueType("number") - } + validate: assertValueType("number"), + }, }, - aliases: ["Expression", "Pureish", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"], }); defineType("NullLiteral", { - aliases: ["Expression", "Pureish", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"], }); defineType("BooleanLiteral", { builder: ["value"], fields: { value: { - validate: assertValueType("boolean") - } + validate: assertValueType("boolean"), + }, }, - aliases: ["Expression", "Pureish", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"], }); defineType("RegExpLiteral", { @@ -389,13 +389,13 @@ defineType("RegExpLiteral", { aliases: ["Expression", "Literal"], fields: { pattern: { - validate: assertValueType("string") + validate: assertValueType("string"), }, flags: { validate: assertValueType("string"), - default: "" - } - } + default: "", + }, + }, }); defineType("LogicalExpression", { @@ -404,15 +404,15 @@ defineType("LogicalExpression", { aliases: ["Binary", "Expression"], fields: { operator: { - validate: assertOneOf(...LOGICAL_OPERATORS) + validate: assertOneOf(...LOGICAL_OPERATORS), }, left: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, right: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("MemberExpression", { @@ -421,18 +421,18 @@ defineType("MemberExpression", { aliases: ["Expression", "LVal"], fields: { object: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, property: { validate(node, key, val) { - let expectedType = node.computed ? "Expression" : "Identifier"; + const expectedType = node.computed ? "Expression" : "Identifier"; assertNodeType(expectedType)(node, key, val); - } + }, }, computed: { - default: false - } - } + default: false, + }, + }, }); defineType("NewExpression", { @@ -440,12 +440,12 @@ defineType("NewExpression", { aliases: ["Expression"], fields: { callee: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, arguments: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression", "SpreadElement"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression", "SpreadElement"))), + }, + }, }); defineType("Program", { @@ -454,13 +454,13 @@ defineType("Program", { fields: { directives: { validate: chain(assertValueType("array"), assertEach(assertNodeType("Directive"))), - default: [] + default: [], }, body: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))) - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))), + }, }, - aliases: ["Scopable", "BlockParent", "Block", "FunctionParent"] + aliases: ["Scopable", "BlockParent", "Block", "FunctionParent"], }); defineType("ObjectExpression", { @@ -470,10 +470,10 @@ defineType("ObjectExpression", { properties: { validate: chain( assertValueType("array"), - assertEach(assertNodeType("ObjectMethod", "ObjectProperty", "SpreadProperty")) - ) - } - } + assertEach(assertNodeType("ObjectMethod", "ObjectProperty", "SpreadElement")) + ), + }, + }, }); defineType("ObjectMethod", { @@ -481,35 +481,35 @@ defineType("ObjectMethod", { fields: { kind: { validate: chain(assertValueType("string"), assertOneOf("method", "get", "set")), - default: "method" + default: "method", }, computed: { validate: assertValueType("boolean"), - default: false + default: false, }, key: { validate(node, key, val) { - let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; + const expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; assertNodeType(...expectedTypes)(node, key, val); - } + }, }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), }, body: { - validate: assertNodeType("BlockStatement") + validate: assertNodeType("BlockStatement"), }, generator: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, async: { default: false, - validate: assertValueType("boolean") - } + validate: assertValueType("boolean"), + }, }, visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"], - aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"] + aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"], }); defineType("ObjectProperty", { @@ -517,28 +517,28 @@ defineType("ObjectProperty", { fields: { computed: { validate: assertValueType("boolean"), - default: false + default: false, }, key: { validate(node, key, val) { - let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; + const expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; assertNodeType(...expectedTypes)(node, key, val); - } + }, }, value: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, shorthand: { validate: assertValueType("boolean"), - default: false + default: false, }, decorators: { validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), - optional: true - } + optional: true, + }, }, visitor: ["key", "value", "decorators"], - aliases: ["UserWhitespacable", "Property", "ObjectMember"] + aliases: ["UserWhitespacable", "Property", "ObjectMember"], }); defineType("RestElement", { @@ -546,12 +546,12 @@ defineType("RestElement", { aliases: ["LVal"], fields: { argument: { - validate: assertNodeType("LVal") + validate: assertNodeType("LVal"), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("ReturnStatement", { @@ -560,19 +560,19 @@ defineType("ReturnStatement", { fields: { argument: { validate: assertNodeType("Expression"), - optional: true - } - } + optional: true, + }, + }, }); defineType("SequenceExpression", { visitor: ["expressions"], fields: { expressions: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))) - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))), + }, }, - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("SwitchCase", { @@ -580,12 +580,12 @@ defineType("SwitchCase", { fields: { test: { validate: assertNodeType("Expression"), - optional: true + optional: true, }, consequent: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Statement"))), + }, + }, }); defineType("SwitchStatement", { @@ -593,16 +593,16 @@ defineType("SwitchStatement", { aliases: ["Statement", "BlockParent", "Scopable"], fields: { discriminant: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, cases: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("SwitchCase"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("SwitchCase"))), + }, + }, }); defineType("ThisExpression", { - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("ThrowStatement", { @@ -610,9 +610,9 @@ defineType("ThrowStatement", { aliases: ["Statement", "Terminatorless", "CompletionStatement"], fields: { argument: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); // todo: at least handler or finalizer should be set to be valid @@ -621,51 +621,51 @@ defineType("TryStatement", { aliases: ["Statement"], fields: { body: { - validate: assertNodeType("BlockStatement") + validate: assertNodeType("BlockStatement"), }, handler: { optional: true, - handler: assertNodeType("BlockStatement") + handler: assertNodeType("BlockStatement"), }, finalizer: { optional: true, - validate: assertNodeType("BlockStatement") - } - } + validate: assertNodeType("BlockStatement"), + }, + }, }); defineType("UnaryExpression", { builder: ["operator", "argument", "prefix"], fields: { prefix: { - default: true + default: true, }, argument: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, operator: { - validate: assertOneOf(...UNARY_OPERATORS) - } + validate: assertOneOf(...UNARY_OPERATORS), + }, }, visitor: ["argument"], - aliases: ["UnaryLike", "Expression"] + aliases: ["UnaryLike", "Expression"], }); defineType("UpdateExpression", { builder: ["operator", "argument", "prefix"], fields: { prefix: { - default: false + default: false, }, argument: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, operator: { - validate: assertOneOf(...UPDATE_OPERATORS) - } + validate: assertOneOf(...UPDATE_OPERATORS), + }, }, visitor: ["argument"], - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("VariableDeclaration", { @@ -674,25 +674,25 @@ defineType("VariableDeclaration", { aliases: ["Statement", "Declaration"], fields: { kind: { - validate: chain(assertValueType("string"), assertOneOf("var", "let", "const")) + validate: chain(assertValueType("string"), assertOneOf("var", "let", "const")), }, declarations: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("VariableDeclarator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("VariableDeclarator"))), + }, + }, }); defineType("VariableDeclarator", { visitor: ["id", "init"], fields: { id: { - validate: assertNodeType("LVal") + validate: assertNodeType("LVal"), }, init: { optional: true, - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("WhileStatement", { @@ -700,12 +700,12 @@ defineType("WhileStatement", { aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"], fields: { test: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, body: { - validate: assertNodeType("BlockStatement", "Statement") - } - } + validate: assertNodeType("BlockStatement", "Statement"), + }, + }, }); defineType("WithStatement", { @@ -713,10 +713,10 @@ defineType("WithStatement", { aliases: ["Statement"], fields: { object: { - object: assertNodeType("Expression") + object: assertNodeType("Expression"), }, body: { - validate: assertNodeType("BlockStatement", "Statement") - } - } + validate: assertNodeType("BlockStatement", "Statement"), + }, + }, }); diff --git a/packages/babel-types/src/definitions/es2015.js b/packages/babel-types/src/definitions/es2015.js index 4f4ff0807c..450ce3d40b 100644 --- a/packages/babel-types/src/definitions/es2015.js +++ b/packages/babel-types/src/definitions/es2015.js @@ -1,4 +1,4 @@ -/* eslint max-len: 0 */ +/* eslint max-len: "off" */ import defineType, { assertNodeType, @@ -13,15 +13,15 @@ defineType("AssignmentPattern", { aliases: ["Pattern", "LVal"], fields: { left: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, right: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("ArrayPattern", { @@ -29,12 +29,12 @@ defineType("ArrayPattern", { aliases: ["Pattern", "LVal"], fields: { elements: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("ArrowFunctionExpression", { @@ -43,25 +43,25 @@ defineType("ArrowFunctionExpression", { aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], fields: { params: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))), }, body: { - validate: assertNodeType("BlockStatement", "Expression") + validate: assertNodeType("BlockStatement", "Expression"), }, async: { validate: assertValueType("boolean"), - default: false - } - } + default: false, + }, + }, }); defineType("ClassBody", { visitor: ["body"], fields: { body: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("ClassMethod", "ClassProperty"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("ClassMethod", "ClassProperty"))), + }, + }, }); defineType("ClassDeclaration", { @@ -74,24 +74,24 @@ defineType("ClassDeclaration", { "typeParameters", "superTypeParameters", "implements", - "decorators" + "decorators", ], aliases: ["Scopable", "Class", "Statement", "Declaration", "Pureish"], fields: { id: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, body: { - validate: assertNodeType("ClassBody") + validate: assertNodeType("ClassBody"), }, superClass: { optional: true, - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("ClassExpression", { @@ -100,19 +100,19 @@ defineType("ClassExpression", { fields: { id: { optional: true, - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, body: { - validate: assertNodeType("ClassBody") + validate: assertNodeType("ClassBody"), }, superClass: { optional: true, - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("ExportAllDeclaration", { @@ -120,9 +120,9 @@ defineType("ExportAllDeclaration", { aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], fields: { source: { - validate: assertNodeType("StringLiteral") - } - } + validate: assertNodeType("StringLiteral"), + }, + }, }); defineType("ExportDefaultDeclaration", { @@ -130,9 +130,9 @@ defineType("ExportDefaultDeclaration", { aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], fields: { declaration: { - validate: assertNodeType("FunctionDeclaration", "ClassDeclaration", "Expression") - } - } + validate: assertNodeType("FunctionDeclaration", "ClassDeclaration", "Expression"), + }, + }, }); defineType("ExportNamedDeclaration", { @@ -141,16 +141,16 @@ defineType("ExportNamedDeclaration", { fields: { declaration: { validate: assertNodeType("Declaration"), - optional: true + optional: true, }, specifiers: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("ExportSpecifier"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("ExportSpecifier"))), }, source: { validate: assertNodeType("StringLiteral"), - optional: true - } - } + optional: true, + }, + }, }); defineType("ExportSpecifier", { @@ -158,12 +158,12 @@ defineType("ExportSpecifier", { aliases: ["ModuleSpecifier"], fields: { local: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, exported: { - validate: assertNodeType("Identifier") - } - } + validate: assertNodeType("Identifier"), + }, + }, }); defineType("ForOfStatement", { @@ -171,15 +171,19 @@ defineType("ForOfStatement", { aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], fields: { left: { - validate: assertNodeType("VariableDeclaration", "LVal") + validate: assertNodeType("VariableDeclaration", "LVal"), }, right: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, body: { - validate: assertNodeType("Statement") - } - } + validate: assertNodeType("Statement"), + }, + await: { + default: false, + validate: assertValueType("boolean"), + }, + }, }); defineType("ImportDeclaration", { @@ -190,12 +194,12 @@ defineType("ImportDeclaration", { validate: chain( assertValueType("array"), assertEach(assertNodeType("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier")) - ) + ), }, source: { - validate: assertNodeType("StringLiteral") - } - } + validate: assertNodeType("StringLiteral"), + }, + }, }); defineType("ImportDefaultSpecifier", { @@ -203,9 +207,9 @@ defineType("ImportDefaultSpecifier", { aliases: ["ModuleSpecifier"], fields: { local: { - validate: assertNodeType("Identifier") - } - } + validate: assertNodeType("Identifier"), + }, + }, }); defineType("ImportNamespaceSpecifier", { @@ -213,9 +217,9 @@ defineType("ImportNamespaceSpecifier", { aliases: ["ModuleSpecifier"], fields: { local: { - validate: assertNodeType("Identifier") - } - } + validate: assertNodeType("Identifier"), + }, + }, }); defineType("ImportSpecifier", { @@ -223,12 +227,16 @@ defineType("ImportSpecifier", { aliases: ["ModuleSpecifier"], fields: { local: { - validate: assertNodeType("Identifier") + validate: assertNodeType("Identifier"), }, imported: { - validate: assertNodeType("Identifier") - } - } + validate: assertNodeType("Identifier"), + }, + importKind: { + // Handle Flowtype's extension "import {typeof foo} from" + validate: assertOneOf(null, "type", "typeof"), + }, + }, }); defineType("MetaProperty", { @@ -237,12 +245,12 @@ defineType("MetaProperty", { fields: { // todo: limit to new.target meta: { - validate: assertValueType("string") + validate: assertValueType("string"), }, property: { - validate: assertValueType("string") - } - } + validate: assertValueType("string"), + }, + }, }); defineType("ClassMethod", { @@ -252,37 +260,37 @@ defineType("ClassMethod", { fields: { kind: { validate: chain(assertValueType("string"), assertOneOf("get", "set", "method", "constructor")), - default: "method" + default: "method", }, computed: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, static: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, key: { validate(node, key, val) { - let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; + const expectedTypes = node.computed ? ["Expression"] : ["Identifier", "StringLiteral", "NumericLiteral"]; assertNodeType(...expectedTypes)(node, key, val); - } + }, }, params: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))), }, body: { - validate: assertNodeType("BlockStatement") + validate: assertNodeType("BlockStatement"), }, generator: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, async: { default: false, - validate: assertValueType("boolean") - } - } + validate: assertValueType("boolean"), + }, + }, }); defineType("ObjectPattern", { @@ -290,12 +298,12 @@ defineType("ObjectPattern", { aliases: ["Pattern", "LVal"], fields: { properties: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("RestProperty", "Property"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("RestElement", "Property"))), }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + }, + }, }); defineType("SpreadElement", { @@ -303,13 +311,13 @@ defineType("SpreadElement", { aliases: ["UnaryLike"], fields: { argument: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("Super", { - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("TaggedTemplateExpression", { @@ -317,12 +325,12 @@ defineType("TaggedTemplateExpression", { aliases: ["Expression"], fields: { tag: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), }, quasi: { - validate: assertNodeType("TemplateLiteral") - } - } + validate: assertNodeType("TemplateLiteral"), + }, + }, }); defineType("TemplateElement", { @@ -333,9 +341,9 @@ defineType("TemplateElement", { }, tail: { validate: assertValueType("boolean"), - default: false - } - } + default: false, + }, + }, }); defineType("TemplateLiteral", { @@ -343,12 +351,12 @@ defineType("TemplateLiteral", { aliases: ["Expression", "Literal"], fields: { quasis: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("TemplateElement"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("TemplateElement"))), }, expressions: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))) - } - } + validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression"))), + }, + }, }); defineType("YieldExpression", { @@ -358,11 +366,11 @@ defineType("YieldExpression", { fields: { delegate: { validate: assertValueType("boolean"), - default: false + default: false, }, argument: { optional: true, validate: assertNodeType("Expression"), - } - } + }, + }, }); diff --git a/packages/babel-types/src/definitions/experimental.js b/packages/babel-types/src/definitions/experimental.js index 17949eaa4c..0bdd4fe7e9 100644 --- a/packages/babel-types/src/definitions/experimental.js +++ b/packages/babel-types/src/definitions/experimental.js @@ -7,24 +7,8 @@ defineType("AwaitExpression", { fields: { argument: { validate: assertNodeType("Expression"), - } - } -}); - -defineType("ForAwaitStatement", { - visitor: ["left", "right", "body"], - aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], - fields: { - left: { - validate: assertNodeType("VariableDeclaration", "LVal") }, - right: { - validate: assertNodeType("Expression") - }, - body: { - validate: assertNodeType("Statement") - } - } + }, }); defineType("BindExpression", { @@ -32,20 +16,20 @@ defineType("BindExpression", { aliases: ["Expression"], fields: { // todo - } + }, }); defineType("Import", { - aliases: ["Expression"] + aliases: ["Expression"], }); defineType("Decorator", { visitor: ["expression"], fields: { expression: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("DoExpression", { @@ -53,9 +37,9 @@ defineType("DoExpression", { aliases: ["Expression"], fields: { body: { - validate: assertNodeType("BlockStatement") - } - } + validate: assertNodeType("BlockStatement"), + }, + }, }); defineType("ExportDefaultSpecifier", { @@ -63,9 +47,9 @@ defineType("ExportDefaultSpecifier", { aliases: ["ModuleSpecifier"], fields: { exported: { - validate: assertNodeType("Identifier") - } - } + validate: assertNodeType("Identifier"), + }, + }, }); defineType("ExportNamespaceSpecifier", { @@ -73,27 +57,7 @@ defineType("ExportNamespaceSpecifier", { aliases: ["ModuleSpecifier"], fields: { exported: { - validate: assertNodeType("Identifier") - } - } -}); - -defineType("RestProperty", { - visitor: ["argument"], - aliases: ["UnaryLike"], - fields: { - argument: { - validate: assertNodeType("LVal") - } - } -}); - -defineType("SpreadProperty", { - visitor: ["argument"], - aliases: ["UnaryLike"], - fields: { - argument: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Identifier"), + }, + }, }); diff --git a/packages/babel-types/src/definitions/flow.js b/packages/babel-types/src/definitions/flow.js index 208382420c..75388fb4a3 100644 --- a/packages/babel-types/src/definitions/flow.js +++ b/packages/babel-types/src/definitions/flow.js @@ -1,12 +1,12 @@ import defineType, { - assertValueType + assertValueType, } from "./index"; defineType("AnyTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo - } + }, }); defineType("ArrayTypeAnnotation", { @@ -14,24 +14,24 @@ defineType("ArrayTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("BooleanTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo - } + }, }); defineType("BooleanLiteralTypeAnnotation", { aliases: ["Flow"], - fields: {} + fields: {}, }); defineType("NullLiteralTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], - fields: {} + fields: {}, }); defineType("ClassImplements", { @@ -39,7 +39,7 @@ defineType("ClassImplements", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("ClassProperty", { @@ -49,10 +49,10 @@ defineType("ClassProperty", { fields: { computed: { validate: assertValueType("boolean"), - default: false - } + default: false, + }, // todo - } + }, }); defineType("DeclareClass", { @@ -60,7 +60,7 @@ defineType("DeclareClass", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareFunction", { @@ -68,7 +68,7 @@ defineType("DeclareFunction", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareInterface", { @@ -76,7 +76,7 @@ defineType("DeclareInterface", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareModule", { @@ -84,7 +84,7 @@ defineType("DeclareModule", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareModuleExports", { @@ -92,7 +92,7 @@ defineType("DeclareModuleExports", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareTypeAlias", { @@ -100,7 +100,7 @@ defineType("DeclareTypeAlias", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("DeclareVariable", { @@ -108,11 +108,11 @@ defineType("DeclareVariable", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); -defineType("ExistentialTypeParam", { - aliases: ["Flow"] +defineType("ExistsTypeAnnotation", { + aliases: ["Flow"], }); defineType("FunctionTypeAnnotation", { @@ -120,7 +120,7 @@ defineType("FunctionTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("FunctionTypeParam", { @@ -128,7 +128,7 @@ defineType("FunctionTypeParam", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("GenericTypeAnnotation", { @@ -136,7 +136,7 @@ defineType("GenericTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("InterfaceExtends", { @@ -144,7 +144,7 @@ defineType("InterfaceExtends", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("InterfaceDeclaration", { @@ -152,7 +152,7 @@ defineType("InterfaceDeclaration", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("IntersectionTypeAnnotation", { @@ -160,15 +160,15 @@ defineType("IntersectionTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("MixedTypeAnnotation", { - aliases: ["Flow", "FlowBaseAnnotation"] + aliases: ["Flow", "FlowBaseAnnotation"], }); defineType("EmptyTypeAnnotation", { - aliases: ["Flow", "FlowBaseAnnotation"] + aliases: ["Flow", "FlowBaseAnnotation"], }); defineType("NullableTypeAnnotation", { @@ -176,40 +176,40 @@ defineType("NullableTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); -defineType("NumericLiteralTypeAnnotation", { +defineType("NumberLiteralTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("NumberTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo - } + }, }); defineType("StringLiteralTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("StringTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo - } + }, }); defineType("ThisTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], - fields: {} + fields: {}, }); defineType("TupleTypeAnnotation", { @@ -217,7 +217,7 @@ defineType("TupleTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("TypeofTypeAnnotation", { @@ -225,7 +225,7 @@ defineType("TypeofTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("TypeAlias", { @@ -233,7 +233,7 @@ defineType("TypeAlias", { aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { // todo - } + }, }); defineType("TypeAnnotation", { @@ -241,7 +241,7 @@ defineType("TypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("TypeCastExpression", { @@ -249,7 +249,7 @@ defineType("TypeCastExpression", { aliases: ["Flow", "ExpressionWrapper", "Expression"], fields: { // todo - } + }, }); defineType("TypeParameter", { @@ -257,7 +257,7 @@ defineType("TypeParameter", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("TypeParameterDeclaration", { @@ -265,7 +265,7 @@ defineType("TypeParameterDeclaration", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("TypeParameterInstantiation", { @@ -273,7 +273,7 @@ defineType("TypeParameterInstantiation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("ObjectTypeAnnotation", { @@ -281,7 +281,7 @@ defineType("ObjectTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("ObjectTypeCallProperty", { @@ -289,7 +289,7 @@ defineType("ObjectTypeCallProperty", { aliases: ["Flow", "UserWhitespacable"], fields: { // todo - } + }, }); defineType("ObjectTypeIndexer", { @@ -297,7 +297,7 @@ defineType("ObjectTypeIndexer", { aliases: ["Flow", "UserWhitespacable"], fields: { // todo - } + }, }); defineType("ObjectTypeProperty", { @@ -305,7 +305,7 @@ defineType("ObjectTypeProperty", { aliases: ["Flow", "UserWhitespacable"], fields: { // todo - } + }, }); defineType("QualifiedTypeIdentifier", { @@ -313,7 +313,7 @@ defineType("QualifiedTypeIdentifier", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("UnionTypeAnnotation", { @@ -321,12 +321,12 @@ defineType("UnionTypeAnnotation", { aliases: ["Flow"], fields: { // todo - } + }, }); defineType("VoidTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo - } + }, }); diff --git a/packages/babel-types/src/definitions/index.js b/packages/babel-types/src/definitions/index.js index d4ae802350..750a81193f 100644 --- a/packages/babel-types/src/definitions/index.js +++ b/packages/babel-types/src/definitions/index.js @@ -1,10 +1,10 @@ import * as t from "../index"; -export let VISITOR_KEYS = {}; -export let ALIAS_KEYS = {}; -export let NODE_FIELDS = {}; -export let BUILDER_KEYS = {}; -export let DEPRECATED_KEYS = {}; +export const VISITOR_KEYS = {}; +export const ALIAS_KEYS = {}; +export const NODE_FIELDS = {}; +export const BUILDER_KEYS = {}; +export const DEPRECATED_KEYS = {}; function getType(val) { if (Array.isArray(val)) { @@ -48,7 +48,7 @@ export function assertNodeType(...types: Array): Function { function validate(node, key, val) { let valid = false; - for (let type of types) { + for (const type of types) { if (t.is(type, val)) { valid = true; break; @@ -72,7 +72,7 @@ export function assertNodeOrValueType(...types: Array): Function { function validate(node, key, val) { let valid = false; - for (let type of types) { + for (const type of types) { if (getType(val) === type || t.is(type, val)) { valid = true; break; @@ -94,7 +94,7 @@ export function assertNodeOrValueType(...types: Array): Function { export function assertValueType(type: string): Function { function validate(node, key, val) { - let valid = getType(val) === type; + const valid = getType(val) === type; if (!valid) { throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); @@ -108,7 +108,7 @@ export function assertValueType(type: string): Function { export function chain(...fns: Array): Function { function validate(...args) { - for (let fn of fns) { + for (const fn of fns) { fn(...args); } } @@ -127,9 +127,9 @@ export default function defineType( deprecatedAlias?: string; } = {}, ) { - let inherits = (opts.inherits && store[opts.inherits]) || {}; + const inherits = (opts.inherits && store[opts.inherits]) || {}; - opts.fields = opts.fields || inherits.fields || {}; + opts.fields = opts.fields || inherits.fields || {}; opts.visitor = opts.visitor || inherits.visitor || []; opts.aliases = opts.aliases || inherits.aliases || []; opts.builder = opts.builder || inherits.builder || opts.visitor || []; @@ -139,12 +139,12 @@ export default function defineType( } // ensure all field keys are represented in `fields` - for (let key of (opts.visitor.concat(opts.builder): Array)) { + for (const key of (opts.visitor.concat(opts.builder): Array)) { opts.fields[key] = opts.fields[key] || {}; } - for (let key in opts.fields) { - let field = opts.fields[key]; + for (const key in opts.fields) { + const field = opts.fields[key]; if (opts.builder.indexOf(key) === -1) { field.optional = true; @@ -158,10 +158,10 @@ export default function defineType( VISITOR_KEYS[type] = opts.visitor; BUILDER_KEYS[type] = opts.builder; - NODE_FIELDS[type] = opts.fields; - ALIAS_KEYS[type] = opts.aliases; + NODE_FIELDS[type] = opts.fields; + ALIAS_KEYS[type] = opts.aliases; store[type] = opts; } -let store = {}; +const store = {}; diff --git a/packages/babel-types/src/definitions/jsx.js b/packages/babel-types/src/definitions/jsx.js index 51bcf1f9f9..28a8921c23 100644 --- a/packages/babel-types/src/definitions/jsx.js +++ b/packages/babel-types/src/definitions/jsx.js @@ -5,13 +5,13 @@ defineType("JSXAttribute", { aliases: ["JSX", "Immutable"], fields: { name: { - validate: assertNodeType("JSXIdentifier", "JSXNamespacedName") + validate: assertNodeType("JSXIdentifier", "JSXNamespacedName"), }, value: { optional: true, - validate: assertNodeType("JSXElement", "StringLiteral", "JSXExpressionContainer") - } - } + validate: assertNodeType("JSXElement", "StringLiteral", "JSXExpressionContainer"), + }, + }, }); defineType("JSXClosingElement", { @@ -19,9 +19,9 @@ defineType("JSXClosingElement", { aliases: ["JSX", "Immutable"], fields: { name: { - validate: assertNodeType("JSXIdentifier", "JSXMemberExpression") - } - } + validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"), + }, + }, }); defineType("JSXElement", { @@ -30,23 +30,23 @@ defineType("JSXElement", { aliases: ["JSX", "Immutable", "Expression"], fields: { openingElement: { - validate: assertNodeType("JSXOpeningElement") + validate: assertNodeType("JSXOpeningElement"), }, closingElement: { optional: true, - validate: assertNodeType("JSXClosingElement") + validate: assertNodeType("JSXClosingElement"), }, children: { validate: chain( assertValueType("array"), assertEach(assertNodeType("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement")) - ) - } - } + ), + }, + }, }); defineType("JSXEmptyExpression", { - aliases: ["JSX", "Expression"] + aliases: ["JSX", "Expression"], }); defineType("JSXExpressionContainer", { @@ -54,9 +54,9 @@ defineType("JSXExpressionContainer", { aliases: ["JSX", "Immutable"], fields: { expression: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("JSXSpreadChild", { @@ -64,9 +64,9 @@ defineType("JSXSpreadChild", { aliases: ["JSX", "Immutable"], fields: { expression: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("JSXIdentifier", { @@ -74,9 +74,9 @@ defineType("JSXIdentifier", { aliases: ["JSX", "Expression"], fields: { name: { - validate: assertValueType("string") - } - } + validate: assertValueType("string"), + }, + }, }); defineType("JSXMemberExpression", { @@ -84,12 +84,12 @@ defineType("JSXMemberExpression", { aliases: ["JSX", "Expression"], fields: { object: { - validate: assertNodeType("JSXMemberExpression", "JSXIdentifier") + validate: assertNodeType("JSXMemberExpression", "JSXIdentifier"), }, property: { - validate: assertNodeType("JSXIdentifier") - } - } + validate: assertNodeType("JSXIdentifier"), + }, + }, }); defineType("JSXNamespacedName", { @@ -97,12 +97,12 @@ defineType("JSXNamespacedName", { aliases: ["JSX"], fields: { namespace: { - validate: assertNodeType("JSXIdentifier") + validate: assertNodeType("JSXIdentifier"), }, name: { - validate: assertNodeType("JSXIdentifier") - } - } + validate: assertNodeType("JSXIdentifier"), + }, + }, }); defineType("JSXOpeningElement", { @@ -111,19 +111,19 @@ defineType("JSXOpeningElement", { aliases: ["JSX", "Immutable"], fields: { name: { - validate: assertNodeType("JSXIdentifier", "JSXMemberExpression") + validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"), }, selfClosing: { default: false, - validate: assertValueType("boolean") + validate: assertValueType("boolean"), }, attributes: { validate: chain( assertValueType("array"), assertEach(assertNodeType("JSXAttribute", "JSXSpreadAttribute")) - ) - } - } + ), + }, + }, }); defineType("JSXSpreadAttribute", { @@ -131,9 +131,9 @@ defineType("JSXSpreadAttribute", { aliases: ["JSX"], fields: { argument: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); defineType("JSXText", { @@ -141,7 +141,7 @@ defineType("JSXText", { builder: ["value"], fields: { value: { - validate: assertValueType("string") - } - } + validate: assertValueType("string"), + }, + }, }); diff --git a/packages/babel-types/src/definitions/misc.js b/packages/babel-types/src/definitions/misc.js index f063e42156..103d76c619 100644 --- a/packages/babel-types/src/definitions/misc.js +++ b/packages/babel-types/src/definitions/misc.js @@ -1,7 +1,7 @@ import defineType, { assertNodeType } from "./index"; defineType("Noop", { - visitor: [] + visitor: [], }); defineType("ParenthesizedExpression", { @@ -9,7 +9,7 @@ defineType("ParenthesizedExpression", { aliases: ["Expression", "ExpressionWrapper"], fields: { expression: { - validate: assertNodeType("Expression") - } - } + validate: assertNodeType("Expression"), + }, + }, }); diff --git a/packages/babel-types/src/flow.js b/packages/babel-types/src/flow.js index b2dbd43dbc..6deb48c23d 100644 --- a/packages/babel-types/src/flow.js +++ b/packages/babel-types/src/flow.js @@ -6,7 +6,7 @@ import * as t from "./index"; */ export function createUnionTypeAnnotation(types: Array) { - let flattened = removeTypeDuplicates(types); + const flattened = removeTypeDuplicates(types); if (flattened.length === 1) { return flattened[0]; @@ -20,16 +20,16 @@ export function createUnionTypeAnnotation(types: Array) { */ export function removeTypeDuplicates(nodes: Array): Array { - let generics = {}; - let bases = {}; + const generics = {}; + const bases = {}; // store union type groups to circular references - let typeGroups = []; + const typeGroups = []; - let types = []; + const types = []; for (let i = 0; i < nodes.length; i++) { - let node = nodes[i]; + const node = nodes[i]; if (!node) continue; // detect duplicates @@ -59,7 +59,7 @@ export function removeTypeDuplicates(nodes: Array): Array { // find a matching generic type and merge and deduplicate the type parameters if (t.isGenericTypeAnnotation(node)) { - let name = node.id.name; + const name = node.id.name; if (generics[name]) { let existing = generics[name]; @@ -83,12 +83,12 @@ export function removeTypeDuplicates(nodes: Array): Array { } // add back in bases - for (let type in bases) { + for (const type in bases) { types.push(bases[type]); } // add back in generics - for (let name in generics) { + for (const name in generics) { types.push(generics[name]); } diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index a5ae2c9325..a885410fc0 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -1,10 +1,8 @@ import toFastProperties from "to-fast-properties"; -import compact from "lodash/compact"; import loClone from "lodash/clone"; -import each from "lodash/each"; import uniq from "lodash/uniq"; -let t = exports; +const t = exports; /** * Registers `is[Type]` and `assert[Type]` generated functions for a given `type`. @@ -48,7 +46,7 @@ export { UNARY_OPERATORS, INHERIT_KEYS, BLOCK_SCOPED_SYMBOL, - NOT_LOCAL_BINDING + NOT_LOCAL_BINDING, } from "./constants"; import "./definitions/init"; @@ -62,7 +60,7 @@ export { _react as react }; * Registers `is[Type]` and `assert[Type]` for all types. */ -for (let type in t.VISITOR_KEYS) { +for (const type in t.VISITOR_KEYS) { registerType(type); } @@ -72,9 +70,9 @@ for (let type in t.VISITOR_KEYS) { t.FLIPPED_ALIAS_KEYS = {}; -each(t.ALIAS_KEYS, function (aliases, type) { - each(aliases, function (alias) { - let types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || []; +Object.keys(t.ALIAS_KEYS).forEach(function (type) { + t.ALIAS_KEYS[type].forEach(function (alias) { + const types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || []; types.push(type); }); }); @@ -83,8 +81,8 @@ each(t.ALIAS_KEYS, function (aliases, type) { * Registers `is[Alias]` and `assert[Alias]` functions for all aliases. */ -each(t.FLIPPED_ALIAS_KEYS, function (types, type) { - t[type.toUpperCase() + "_TYPES"] = types; +Object.keys(t.FLIPPED_ALIAS_KEYS).forEach(function (type) { + t[type.toUpperCase() + "_TYPES"] = t.FLIPPED_ALIAS_KEYS[type]; registerType(type); }); @@ -102,7 +100,7 @@ export const TYPES = Object.keys(t.VISITOR_KEYS) export function is(type: string, node: Object, opts?: Object): boolean { if (!node) return false; - let matches = isType(node.type, type); + const matches = isType(node.type, type); if (!matches) return false; if (typeof opts === "undefined") { @@ -123,11 +121,11 @@ export function isType(nodeType: string, targetType: string): boolean { // targetType was a primary node type, so there's no need to check the aliases. if (t.ALIAS_KEYS[targetType]) return false; - let aliases: ?Array = t.FLIPPED_ALIAS_KEYS[targetType]; + const aliases: ?Array = t.FLIPPED_ALIAS_KEYS[targetType]; if (aliases) { if (aliases[0] === nodeType) return true; - for (let alias of aliases) { + for (const alias of aliases) { if (nodeType === alias) return true; } } @@ -139,7 +137,9 @@ export function isType(nodeType: string, targetType: string): boolean { * Description */ -each(t.BUILDER_KEYS, function (keys, type) { +Object.keys(t.BUILDER_KEYS).forEach(function (type) { + const keys = t.BUILDER_KEYS[type]; + function builder() { if (arguments.length > keys.length) { throw new Error( @@ -148,13 +148,13 @@ each(t.BUILDER_KEYS, function (keys, type) { ); } - let node = {}; + const node = {}; node.type = type; let i = 0; - for (let key of (keys: Array)) { - let field = t.NODE_FIELDS[type][key]; + for (const key of (keys: Array)) { + const field = t.NODE_FIELDS[type][key]; let arg = arguments[i++]; if (arg === undefined) arg = loClone(field.default); @@ -162,7 +162,7 @@ each(t.BUILDER_KEYS, function (keys, type) { node[key] = arg; } - for (let key in node) { + for (const key in node) { validate(node, key, node[key]); } @@ -177,8 +177,8 @@ each(t.BUILDER_KEYS, function (keys, type) { * Description */ -for (let type in t.DEPRECATED_KEYS) { - let newType = t.DEPRECATED_KEYS[type]; +for (const type in t.DEPRECATED_KEYS) { + const newType = t.DEPRECATED_KEYS[type]; function proxy(fn) { return function () { @@ -199,10 +199,10 @@ for (let type in t.DEPRECATED_KEYS) { export function validate(node?: Object, key: string, val: any) { if (!node) return; - let fields = t.NODE_FIELDS[node.type]; + const fields = t.NODE_FIELDS[node.type]; if (!fields) return; - let field = fields[key]; + const field = fields[key]; if (!field || !field.validate) return; if (field.optional && val == null) return; @@ -214,9 +214,9 @@ export function validate(node?: Object, key: string, val: any) { */ export function shallowEqual(actual: Object, expected: Object): boolean { - let keys = Object.keys(expected); + const keys = Object.keys(expected); - for (let key of (keys: Array)) { + for (const key of (keys: Array)) { if (actual[key] !== expected[key]) { return false; } @@ -230,7 +230,7 @@ export function shallowEqual(actual: Object, expected: Object): boolean { */ export function appendToMemberExpression(member: Object, append: Object, computed?: boolean): Object { - member.object = t.memberExpression(member.object, member.property, member.computed); + member.object = t.memberExpression(member.object, member.property, member.computed); member.property = append; member.computed = !!computed; return member; @@ -260,8 +260,8 @@ export function ensureBlock(node: Object, key: string = "body"): Object { export function clone(node: Object): Object { if (!node) return node; - let newNode = {}; - for (let key in node) { + const newNode = {}; + for (const key in node) { if (key[0] === "_") continue; newNode[key] = node[key]; } @@ -273,7 +273,7 @@ export function clone(node: Object): Object { */ export function cloneWithoutLoc(node: Object): Object { - let newNode = clone(node); + const newNode = clone(node); delete newNode.loc; return newNode; } @@ -285,9 +285,9 @@ export function cloneWithoutLoc(node: Object): Object { export function cloneDeep(node: Object): Object { if (!node) return node; - let newNode = {}; + const newNode = {}; - for (let key in node) { + for (const key in node) { if (key[0] === "_") continue; let val = node[key]; @@ -315,17 +315,17 @@ export function cloneDeep(node: Object): Object { */ export function buildMatchMemberExpression(match:string, allowPartial?: boolean): Function { - let parts = match.split("."); + const parts = match.split("."); return function (member) { // not a member expression if (!t.isMemberExpression(member)) return false; - let search = [member]; + const search = [member]; let i = 0; while (search.length) { - let node = search.shift(); + const node = search.shift(); if (allowPartial && i === parts.length) { return true; @@ -366,7 +366,7 @@ export function buildMatchMemberExpression(match:string, allowPartial?: boolean) */ export function removeComments(node: Object): Object { - for (let key of t.COMMENT_KEYS) { + for (const key of t.COMMENT_KEYS) { delete node[key]; } return node; @@ -397,7 +397,10 @@ export function inheritInnerComments(child: Object, parent: Object) { function _inheritComments(key, child, parent) { if (child && parent) { - child[key] = uniq(compact([].concat(child[key], parent[key]))); + child[key] = uniq( + [].concat(child[key], parent[key]) + .filter(Boolean) + ); } } @@ -409,19 +412,19 @@ export function inherits(child: Object, parent: Object): Object { if (!child || !parent) return child; // optionally inherit specific properties if not null - for (let key of (t.INHERIT_KEYS.optional: Array)) { + for (const key of (t.INHERIT_KEYS.optional: Array)) { if (child[key] == null) { child[key] = parent[key]; } } // force inherit "private" properties - for (let key in parent) { + for (const key in parent) { if (key[0] === "_") child[key] = parent[key]; } // force inherit select properties - for (let key of (t.INHERIT_KEYS.force: Array)) { + for (const key of (t.INHERIT_KEYS.force: Array)) { child[key] = parent[key]; } @@ -460,17 +463,17 @@ toFastProperties(t.VISITOR_KEYS); export function traverseFast(node: Node, enter: (node: Node) => void, opts?: Object) { if (!node) return; - let keys = t.VISITOR_KEYS[node.type]; + const keys = t.VISITOR_KEYS[node.type]; if (!keys) return; opts = opts || {}; enter(node, opts); - for (let key of keys) { - let subNode = node[key]; + for (const key of keys) { + const subNode = node[key]; if (Array.isArray(subNode)) { - for (let node of subNode) { + for (const node of subNode) { traverseFast(node, enter, opts); } } else { @@ -482,11 +485,11 @@ export function traverseFast(node: Node, enter: (node: Node) => void, opts?: Obj const CLEAR_KEYS: Array = [ "tokens", "start", "end", "loc", - "raw", "rawValue" + "raw", "rawValue", ]; const CLEAR_KEYS_PLUS_COMMENTS: Array = t.COMMENT_KEYS.concat([ - "comments" + "comments", ]).concat(CLEAR_KEYS); /** @@ -496,17 +499,17 @@ const CLEAR_KEYS_PLUS_COMMENTS: Array = t.COMMENT_KEYS.concat([ export function removeProperties(node: Node, opts?: Object): void { opts = opts || {}; - let map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS; - for (let key of map) { + const map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS; + for (const key of map) { if (node[key] != null) node[key] = undefined; } - for (let key in node) { + for (const key in node) { if (key[0] === "_" && node[key] != null) node[key] = undefined; } - let syms: Array = Object.getOwnPropertySymbols(node); - for (let sym of syms) { + const syms: Array = Object.getOwnPropertySymbols(node); + for (const sym of syms) { node[sym] = null; } } @@ -519,7 +522,7 @@ export function removePropertiesDeep(tree: Node, opts?: Object): Node { // export { getBindingIdentifiers, - getOuterBindingIdentifiers + getOuterBindingIdentifiers, } from "./retrievers"; export { @@ -532,7 +535,7 @@ export { isSpecifierDefault, isScope, isImmutable, - isNodesEquivalent + isNodesEquivalent, } from "./validators"; export { @@ -544,11 +547,11 @@ export { toStatement, toExpression, toBlock, - valueToNode + valueToNode, } from "./converters"; export { createUnionTypeAnnotation, removeTypeDuplicates, - createTypeAnnotationBasedOnTypeof + createTypeAnnotationBasedOnTypeof, } from "./flow"; diff --git a/packages/babel-types/src/react.js b/packages/babel-types/src/react.js index 9b665d224d..ebf3829cae 100644 --- a/packages/babel-types/src/react.js +++ b/packages/babel-types/src/react.js @@ -1,6 +1,6 @@ import * as t from "./index"; -export let isReactComponent = t.buildMatchMemberExpression("React.Component"); +export const isReactComponent = t.buildMatchMemberExpression("React.Component"); export function isCompatTag(tagName?: string): boolean { return !!tagName && /^[a-z]|\-/.test(tagName); @@ -10,7 +10,7 @@ function cleanJSXElementLiteralChild( child: { value: string }, args: Array, ) { - let lines = child.value.split(/\r\n|\n|\r/); + const lines = child.value.split(/\r\n|\n|\r/); let lastNonEmptyLine = 0; @@ -23,11 +23,11 @@ function cleanJSXElementLiteralChild( let str = ""; for (let i = 0; i < lines.length; i++) { - let line = lines[i]; + const line = lines[i]; - let isFirstLine = i === 0; - let isLastLine = i === lines.length - 1; - let isLastNonEmptyLine = i === lastNonEmptyLine; + const isFirstLine = i === 0; + const isLastLine = i === lines.length - 1; + const isLastNonEmptyLine = i === lastNonEmptyLine; // replace rendered whitespace tabs with spaces let trimmedLine = line.replace(/\t/g, " "); @@ -55,7 +55,7 @@ function cleanJSXElementLiteralChild( } export function buildChildren(node: Object): Array { - let elems = []; + const elems = []; for (let i = 0; i < node.children.length; i++) { let child = node.children[i]; diff --git a/packages/babel-types/src/retrievers.js b/packages/babel-types/src/retrievers.js index 12bba815b0..734e4dfc7e 100644 --- a/packages/babel-types/src/retrievers.js +++ b/packages/babel-types/src/retrievers.js @@ -10,17 +10,17 @@ export function getBindingIdentifiers( outerOnly?: boolean ): Object { let search = [].concat(node); - let ids = Object.create(null); + const ids = Object.create(null); while (search.length) { - let id = search.shift(); + const id = search.shift(); if (!id) continue; - let keys = t.getBindingIdentifiers.keys[id.type]; + const keys = t.getBindingIdentifiers.keys[id.type]; if (t.isIdentifier(id)) { if (duplicates) { - let _ids = ids[id.name] = ids[id.name] || []; + const _ids = ids[id.name] = ids[id.name] || []; _ids.push(id); } else { ids[id.name] = id; @@ -29,8 +29,8 @@ export function getBindingIdentifiers( } if (t.isExportDeclaration(id)) { - if (t.isDeclaration(node.declaration)) { - search.push(node.declaration); + if (t.isDeclaration(id.declaration)) { + search.push(id.declaration); } continue; } @@ -48,7 +48,7 @@ export function getBindingIdentifiers( if (keys) { for (let i = 0; i < keys.length; i++) { - let key = keys[i]; + const key = keys[i]; if (id[key]) { search = search.concat(id[key]); } @@ -94,7 +94,6 @@ getBindingIdentifiers.keys = { RestElement: ["argument"], UpdateExpression: ["argument"], - RestProperty: ["argument"], ObjectProperty: ["value"], AssignmentPattern: ["left"], @@ -102,7 +101,7 @@ getBindingIdentifiers.keys = { ObjectPattern: ["properties"], VariableDeclaration: ["declarations"], - VariableDeclarator: ["id"] + VariableDeclarator: ["id"], }; export function getOuterBindingIdentifiers( diff --git a/packages/babel-types/src/validators.js b/packages/babel-types/src/validators.js index 78ea84cb40..c5f25327bd 100644 --- a/packages/babel-types/src/validators.js +++ b/packages/babel-types/src/validators.js @@ -1,5 +1,3 @@ -/* eslint indent: 0 */ - import { getBindingIdentifiers } from "./retrievers"; import esutils from "esutils"; import * as t from "./index"; @@ -10,11 +8,11 @@ import { BLOCK_SCOPED_SYMBOL } from "./constants"; */ export function isBinding(node: Object, parent: Object): boolean { - let keys = getBindingIdentifiers.keys[parent.type]; + const keys = getBindingIdentifiers.keys[parent.type]; if (keys) { for (let i = 0; i < keys.length; i++) { - let key = keys[i]; - let val = parent[key]; + const key = keys[i]; + const val = parent[key]; if (Array.isArray(val)) { if (val.indexOf(node) >= 0) return true; } else { @@ -73,7 +71,7 @@ export function isReferenced(node: Object, parent: Object): boolean { case "ArrowFunctionExpression": case "FunctionDeclaration": case "FunctionExpression": - for (let param of (parent.params: Array)) { + for (const param of (parent.params: Array)) { if (param === node) return false; } @@ -254,7 +252,7 @@ export function isNodesEquivalent(a, b) { const fields = Object.keys(t.NODE_FIELDS[a.type] || a.type); - for (let field of fields) { + for (const field of fields) { if (typeof a[field] !== typeof b[field]) { return false; } @@ -276,7 +274,7 @@ export function isNodesEquivalent(a, b) { } if (!isNodesEquivalent(a[field], b[field])) { - return false; + return false; } } diff --git a/packages/babel-types/test/cloning.js b/packages/babel-types/test/cloning.js index 817a4e1ec4..9e3b41f475 100644 --- a/packages/babel-types/test/cloning.js +++ b/packages/babel-types/test/cloning.js @@ -1,24 +1,24 @@ -let t = require("../lib"); -let assert = require("assert"); -let parse = require("babylon").parse; +import * as t from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; suite("cloning", function () { suite("clone", function () { it("should handle undefined", function () { - let node = undefined; - let cloned = t.clone(node); + const node = undefined; + const cloned = t.clone(node); assert(cloned === undefined); }); it("should handle null", function () { - let node = null; - let cloned = t.clone(node); + const node = null; + const cloned = t.clone(node); assert(cloned === null); }); it("should handle simple cases", function () { - let node = t.arrayExpression([null, t.identifier("a")]); - let cloned = t.clone(node); + const node = t.arrayExpression([null, t.identifier("a")]); + const cloned = t.clone(node); assert(node !== cloned); assert(t.isNodesEquivalent(node, cloned) === true); }); @@ -26,42 +26,42 @@ suite("cloning", function () { suite("cloneDeep", function () { it("should handle undefined", function () { - let node = undefined; - let cloned = t.cloneDeep(node); + const node = undefined; + const cloned = t.cloneDeep(node); assert(cloned === undefined); }); it("should handle null", function () { - let node = null; - let cloned = t.cloneDeep(node); + const node = null; + const cloned = t.cloneDeep(node); assert(cloned === null); }); it("should handle simple cases", function () { - let node = t.arrayExpression([null, t.identifier("a")]); - let cloned = t.cloneDeep(node); + const node = t.arrayExpression([null, t.identifier("a")]); + const cloned = t.cloneDeep(node); assert(node !== cloned); assert(t.isNodesEquivalent(node, cloned) === true); }); it("should handle full programs", function () { - let node = parse("1 + 1"); - let cloned = t.cloneDeep(node); + const node = parse("1 + 1"); + const cloned = t.cloneDeep(node); assert(node !== cloned); assert(t.isNodesEquivalent(node, cloned) === true); }); it("should handle complex programs", function () { - let program = "'use strict'; function lol() { wow();return 1; }"; - let node = parse(program); - let cloned = t.cloneDeep(node); + const program = "'use strict'; function lol() { wow();return 1; }"; + const node = parse(program); + const cloned = t.cloneDeep(node); assert(node !== cloned); assert(t.isNodesEquivalent(node, cloned) === true); }); it("should handle missing array element", function () { - let node = parse("[,0]"); - let cloned = t.cloneDeep(node); + const node = parse("[,0]"); + const cloned = t.cloneDeep(node); assert(node !== cloned); assert(t.isNodesEquivalent(node, cloned) === true); }); diff --git a/packages/babel-types/test/converters.js b/packages/babel-types/test/converters.js index 56dabf6586..d787265a7f 100644 --- a/packages/babel-types/test/converters.js +++ b/packages/babel-types/test/converters.js @@ -25,15 +25,16 @@ describe("converters", function () { assert.deepEqual(t.valueToNode(/abc.+/gm), t.regExpLiteral("abc.+", "gm")); }); it("array", function () { - assert.deepEqual(t.valueToNode([1, "a"]), t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")])); + assert.deepEqual(t.valueToNode([1, "a"]), + t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")])); }); it("object", function () { assert.deepEqual(t.valueToNode({ a: 1, - "b c": 2 + "b c": 2, }), t.objectExpression([ t.objectProperty(t.identifier("a"), t.numericLiteral(1)), - t.objectProperty(t.stringLiteral("b c"), t.numericLiteral(2)) + t.objectProperty(t.stringLiteral("b c"), t.numericLiteral(2)), ])); }); it("throws if cannot convert", function () { diff --git a/packages/babel-types/test/retrievers.js b/packages/babel-types/test/retrievers.js new file mode 100644 index 0000000000..15f4149cd1 --- /dev/null +++ b/packages/babel-types/test/retrievers.js @@ -0,0 +1,27 @@ +import * as t from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; + +function getBody(program) { + return parse(program, { sourceType: "module" }).program.body; +} + +describe("retrievers", function () { + describe("getBindingIdentifiers", function () { + it("variable declarations", function () { + const program = "var a = 1; let b = 2; const c = 3;"; + const ids = t.getBindingIdentifiers(getBody(program)); + assert.deepEqual(Object.keys(ids), ["a", "b", "c"]); + }); + it("function declarations", function () { + const program = "var foo = 1; function bar() { var baz = 2; }"; + const ids = t.getBindingIdentifiers(getBody(program)); + assert.deepEqual(Object.keys(ids), ["bar", "foo"]); + }); + it("export named declarations", function () { + const program = "export const foo = 'foo';"; + const ids = t.getBindingIdentifiers(getBody(program)); + assert.deepEqual(Object.keys(ids), ["foo"]); + }); + }); +}); diff --git a/packages/babel-types/test/validators.js b/packages/babel-types/test/validators.js index c269614f48..2e7e55d085 100644 --- a/packages/babel-types/test/validators.js +++ b/packages/babel-types/test/validators.js @@ -1,14 +1,14 @@ -let t = require("../lib"); -let assert = require("assert"); -let parse = require("babylon").parse; +import * as t from "../lib"; +import assert from "assert"; +import { parse } from "babylon"; suite("validators", function () { suite("isNodesEquivalent", function () { it("should handle simple cases", function () { - let mem = t.memberExpression(t.identifier("a"), t.identifier("b")); + const mem = t.memberExpression(t.identifier("a"), t.identifier("b")); assert(t.isNodesEquivalent(mem, mem) === true); - let mem2 = t.memberExpression(t.identifier("a"), t.identifier("c")); + const mem2 = t.memberExpression(t.identifier("a"), t.identifier("c")); assert(t.isNodesEquivalent(mem, mem2) === false); }); @@ -18,11 +18,11 @@ suite("validators", function () { }); it("should handle complex programs", function () { - let program = "'use strict'; function lol() { wow();return 1; }"; + const program = "'use strict'; function lol() { wow();return 1; }"; assert(t.isNodesEquivalent(parse(program), parse(program)) === true); - let program2 = "'use strict'; function lol() { wow();return -1; }"; + const program2 = "'use strict'; function lol() { wow();return -1; }"; assert(t.isNodesEquivalent(parse(program), parse(program2)) === false); }); diff --git a/packages/babel/README.md b/packages/babel/README.md deleted file mode 100644 index 17590de468..0000000000 --- a/packages/babel/README.md +++ /dev/null @@ -1 +0,0 @@ -# babel diff --git a/packages/babel/cli.js b/packages/babel/cli.js deleted file mode 100755 index 92c1235cd0..0000000000 --- a/packages/babel/cli.js +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env node - -console.error("You have mistakenly installed the `babel` package, which is a no-op in Babel 6.\n" + - "Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.\n" + - "\n" + - " npm uninstall babel\n" + - " npm install babel-cli\n" + - "\n" + - "See http://babeljs.io/docs/usage/cli/ for setup instructions."); -process.exit(1); diff --git a/packages/babel/index.js b/packages/babel/index.js deleted file mode 100644 index 06ca959245..0000000000 --- a/packages/babel/index.js +++ /dev/null @@ -1 +0,0 @@ -throw new Error("The node API for `babel` has been moved to `babel-core`."); diff --git a/packages/babel/package.json b/packages/babel/package.json deleted file mode 100644 index a4440b5718..0000000000 --- a/packages/babel/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "babel", - "version": "6.5.2", - "description": "Turn ES6 code into readable vanilla ES5 with source maps", - "author": "Sebastian McKenzie ", - "homepage": "https://babeljs.io/", - "license": "MIT", - "repository": "https://github.com/babel/babel/tree/master/packages/babel", - "bin": { - "babel": "./cli.js", - "babel-node": "./cli.js", - "babel-external-helpers": "./cli.js" - } -} diff --git a/scripts/add-module-exports.js b/scripts/add-module-exports.js deleted file mode 100644 index d0e89a17cf..0000000000 --- a/scripts/add-module-exports.js +++ /dev/null @@ -1,47 +0,0 @@ -// "add-module-exports" -module.exports = function (babel) { - var t = babel.types; - return { - visitor: { - Program: { - exit: function(path) { - if (path.BABEL_PLUGIN_ADD_MODULE_EXPORTS) { - return; - } - - var hasExportDefault = false; - var hasExportNamed = false; - var body = path.get("body"); - - path.get('body').forEach(function (path) { - if (path.isExportDefaultDeclaration()) { - hasExportDefault = true; - return; - } - - if (path.isExportNamedDeclaration()) { - if (path.node.specifiers.length === 1 && path.node.specifiers[0].exported.name === "default") { - hasExportDefault = true; - } else { - hasExportNamed = true; - } - return; - } - }); - - if (hasExportDefault && !hasExportNamed) { - path.pushContainer("body", [ - t.expressionStatement(t.assignmentExpression( - "=", - t.memberExpression(t.identifier("module"), t.identifier("exports")), - t.memberExpression(t.identifier("exports"), t.stringLiteral("default"), true) - )) - ]); - } - - path.BABEL_PLUGIN_ADD_MODULE_EXPORTS = true; - } - } - } - } -} diff --git a/scripts/build-website.sh b/scripts/build-website.sh deleted file mode 100755 index aa344fb868..0000000000 --- a/scripts/build-website.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -set -e - -if [ ! -d ./_babel.github.io ]; then - git clone git@github.com:babel/babel.github.io.git _babel.github.io -fi - -cd _babel.github.io - -if [ ! -d ./_babel ]; then - ln -s .. _babel -fi - -git pull -make build -git commit -am "v`babel -V`" -git push diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000000..b730d5b88e --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4614 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +JSONStream@^1.0.3: + version "1.3.0" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.0.tgz#680ab9ac6572a8a1a207e0b38721db1c77b215e5" + dependencies: + jsonparse "^1.2.0" + through ">=2.2.7 <3" + +abbrev@1: + version "1.0.9" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" + +acorn-jsx@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b" + dependencies: + acorn "^3.0.4" + +acorn@^1.0.3: + version "1.2.2" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-1.2.2.tgz#c8ce27de0acc76d896d2b1fad3df588d9e82f014" + +acorn@^2.1.0, acorn@^2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-2.7.0.tgz#ab6e7d9d886aaca8b085bc3312b79a198433f0e7" + +acorn@^3.0.4, acorn@^3.1.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" + +acorn@^4.0.1, acorn@^4.0.3: + version "4.0.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.4.tgz#17a8d6a7a6c4ef538b814ec9abac2779293bf30a" + +ajv-keywords@^1.0.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.0.tgz#c11e6859eafff83e0dafc416929472eca946aa2c" + +ajv@^4.7.0: + version "4.10.4" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.10.4.tgz#c0974dd00b3464984892d6010aa9c2c945933254" + dependencies: + co "^4.6.0" + json-stable-stringify "^1.0.1" + +align-text@^0.1.1, align-text@^0.1.3: + version "0.1.4" + resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" + dependencies: + kind-of "^3.0.2" + longest "^1.0.1" + repeat-string "^1.5.2" + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + +ansi-escapes@^1.1.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e" + +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + +ansi-styles@^2.1.0, ansi-styles@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + +anymatch@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507" + dependencies: + arrify "^1.0.0" + micromatch "^2.1.5" + +append-transform@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-0.4.0.tgz#d76ebf8ca94d276e247a36bad44a4b74ab611991" + dependencies: + default-require-extensions "^1.0.0" + +aproba@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.0.4.tgz#2713680775e7614c8ba186c065d4e2e52d1072c0" + +archy@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40" + +are-we-there-yet@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.2.tgz#80e470e95a084794fe1899262c5667c6e88de1b3" + dependencies: + delegates "^1.0.0" + readable-stream "^2.0.0 || ^1.1.13" + +argparse@^1.0.7: + version "1.0.9" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86" + dependencies: + sprintf-js "~1.0.2" + +argv@>=0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab" + +arr-diff@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" + dependencies: + arr-flatten "^1.0.1" + +arr-flatten@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.1.tgz#e5ffe54d45e19f32f216e91eb99c8ce892bb604b" + +array-differ@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/array-differ/-/array-differ-1.0.0.tgz#eff52e3758249d33be402b8bb8e564bb2b5d4031" + +array-filter@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec" + +array-find-index@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1" + +array-map@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662" + +array-reduce@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b" + +array-union@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39" + dependencies: + array-uniq "^1.0.1" + +array-uniq@^1.0.1, array-uniq@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6" + +array-unique@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" + +arrify@^1.0.0, arrify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" + +asn1.js@^4.0.0: + version "4.9.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.9.1.tgz#48ba240b45a9280e94748990ba597d216617fd40" + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +asn1@~0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" + +assert-plus@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234" + +assert-plus@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" + +assert@^1.4.0: + version "1.4.1" + resolved "https://registry.yarnpkg.com/assert/-/assert-1.4.1.tgz#99912d591836b5a6f5b345c0f07eefc08fc65d91" + dependencies: + util "0.10.3" + +assertion-error@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c" + +astw@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/astw/-/astw-2.0.0.tgz#08121ac8288d35611c0ceec663f6cd545604897d" + dependencies: + acorn "^1.0.3" + +async-each@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" + +async@^1.4.0, async@^1.4.2, async@^1.5.0: + version "1.5.2" + resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" + +async@~0.2.6: + version "0.2.10" + resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + +aws-sign2@~0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f" + +aws4@^1.2.1: + version "1.5.0" + resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.5.0.tgz#0a29ffb79c31c9e712eeb087e8e7a64b4a56d755" + +babel-code-frame@^6.16.0, babel-code-frame@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" + dependencies: + chalk "^1.1.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +babel-core@^6.0.2, babel-core@^6.13.2, babel-core@^6.22.0: + version "6.22.1" + resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.22.1.tgz#9c5fd658ba1772d28d721f6d25d968fc7ae21648" + dependencies: + babel-code-frame "^6.22.0" + babel-generator "^6.22.0" + babel-helpers "^6.22.0" + babel-messages "^6.22.0" + babel-register "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.1" + babel-types "^6.22.0" + babylon "^6.11.0" + convert-source-map "^1.1.0" + debug "^2.1.1" + json5 "^0.5.0" + lodash "^4.2.0" + minimatch "^3.0.2" + path-is-absolute "^1.0.0" + private "^0.1.6" + slash "^1.0.0" + source-map "^0.5.0" + +babel-eslint@^7.0.0: + version "7.1.1" + resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.1.1.tgz#8a6a884f085aa7060af69cfc77341c2f99370fb2" + dependencies: + babel-code-frame "^6.16.0" + babel-traverse "^6.15.0" + babel-types "^6.15.0" + babylon "^6.13.0" + lodash.pickby "^4.6.0" + +babel-generator@^6.18.0, babel-generator@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.22.0.tgz#d642bf4961911a8adc7c692b0c9297f325cda805" + dependencies: + babel-messages "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + detect-indent "^4.0.0" + jsesc "^1.3.0" + lodash "^4.2.0" + source-map "^0.5.0" + +babel-helper-bindify-decorators@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-bindify-decorators/-/babel-helper-bindify-decorators-6.22.0.tgz#d7f5bc261275941ac62acfc4e20dacfb8a3fe952" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-builder-binary-assignment-operator-visitor@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.22.0.tgz#29df56be144d81bdeac08262bfa41d2c5e91cdcd" + dependencies: + babel-helper-explode-assignable-expression "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-helper-call-delegate@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.22.0.tgz#119921b56120f17e9dae3f74b4f5cc7bcc1b37ef" + dependencies: + babel-helper-hoist-variables "^6.22.0" + babel-runtime "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-define-map@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-define-map/-/babel-helper-define-map-6.22.0.tgz#9544e9502b2d6dfe7d00ff60e82bd5a7a89e95b7" + dependencies: + babel-helper-function-name "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + lodash "^4.2.0" + +babel-helper-explode-assignable-expression@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.22.0.tgz#c97bf76eed3e0bae4048121f2b9dae1a4e7d0478" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-explode-class@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-explode-class/-/babel-helper-explode-class-6.22.0.tgz#646304924aa6388a516843ba7f1855ef8dfeb69b" + dependencies: + babel-helper-bindify-decorators "^6.22.0" + babel-runtime "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-function-name@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.22.0.tgz#51f1bdc4bb89b15f57a9b249f33d742816dcbefc" + dependencies: + babel-helper-get-function-arity "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-get-function-arity@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.22.0.tgz#0beb464ad69dc7347410ac6ade9f03a50634f5ce" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-helper-hoist-variables@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-hoist-variables/-/babel-helper-hoist-variables-6.22.0.tgz#3eacbf731d80705845dd2e9718f600cfb9b4ba72" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-helper-optimise-call-expression@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.22.0.tgz#f8d5d4b40a6e2605a6a7f9d537b581bea3756d15" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-helper-regex@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-regex/-/babel-helper-regex-6.22.0.tgz#79f532be1647b1f0ee3474b5f5c3da58001d247d" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + lodash "^4.2.0" + +babel-helper-remap-async-to-generator@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.22.0.tgz#2186ae73278ed03b8b15ced089609da981053383" + dependencies: + babel-helper-function-name "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helper-replace-supers@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.22.0.tgz#1fcee2270657548908c34db16bcc345f9850cf42" + dependencies: + babel-helper-optimise-call-expression "^6.22.0" + babel-messages "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-helpers@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.22.0.tgz#d275f55f2252b8101bff07bc0c556deda657392c" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-messages@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.22.0.tgz#36066a214f1217e4ed4164867669ecb39e3ea575" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-check-es2015-constants@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-istanbul@^2.0.1: + version "2.0.3" + resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-2.0.3.tgz#266b304b9109607d60748474394676982f660df4" + dependencies: + find-up "^1.1.2" + istanbul-lib-instrument "^1.1.4" + object-assign "^4.1.0" + test-exclude "^2.1.1" + +babel-plugin-syntax-async-functions@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" + +babel-plugin-syntax-async-generators@^6.5.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-generators/-/babel-plugin-syntax-async-generators-6.13.0.tgz#6bc963ebb16eccbae6b92b596eb7f35c342a8b9a" + +babel-plugin-syntax-class-constructor-call@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-constructor-call/-/babel-plugin-syntax-class-constructor-call-6.18.0.tgz#9cb9d39fe43c8600bec8146456ddcbd4e1a76416" + +babel-plugin-syntax-class-properties@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de" + +babel-plugin-syntax-decorators@^6.13.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b" + +babel-plugin-syntax-do-expressions@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-do-expressions/-/babel-plugin-syntax-do-expressions-6.13.0.tgz#5747756139aa26d390d09410b03744ba07e4796d" + +babel-plugin-syntax-dynamic-import@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-dynamic-import/-/babel-plugin-syntax-dynamic-import-6.18.0.tgz#8d6a26229c83745a9982a441051572caa179b1da" + +babel-plugin-syntax-exponentiation-operator@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" + +babel-plugin-syntax-export-extensions@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-export-extensions/-/babel-plugin-syntax-export-extensions-6.13.0.tgz#70a1484f0f9089a4e84ad44bac353c95b9b12721" + +babel-plugin-syntax-flow@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d" + +babel-plugin-syntax-function-bind@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-function-bind/-/babel-plugin-syntax-function-bind-6.13.0.tgz#48c495f177bdf31a981e732f55adc0bdd2601f46" + +babel-plugin-syntax-object-rest-spread@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" + +babel-plugin-syntax-trailing-function-commas@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" + +babel-plugin-transform-async-generator-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-generator-functions/-/babel-plugin-transform-async-generator-functions-6.22.0.tgz#a720a98153a7596f204099cd5409f4b3c05bab46" + dependencies: + babel-helper-remap-async-to-generator "^6.22.0" + babel-plugin-syntax-async-generators "^6.5.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-async-to-generator@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.22.0.tgz#194b6938ec195ad36efc4c33a971acf00d8cd35e" + dependencies: + babel-helper-remap-async-to-generator "^6.22.0" + babel-plugin-syntax-async-functions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-class-constructor-call@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-constructor-call/-/babel-plugin-transform-class-constructor-call-6.22.0.tgz#11a4d2216abb5b0eef298b493748f4f2f4869120" + dependencies: + babel-plugin-syntax-class-constructor-call "^6.18.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-class-properties@^6.22.0, babel-plugin-transform-class-properties@^6.6.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.22.0.tgz#aa78f8134495c7de06c097118ba061844e1dc1d8" + dependencies: + babel-helper-function-name "^6.22.0" + babel-plugin-syntax-class-properties "^6.8.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-decorators@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-decorators/-/babel-plugin-transform-decorators-6.22.0.tgz#c03635b27a23b23b7224f49232c237a73988d27c" + dependencies: + babel-helper-explode-class "^6.22.0" + babel-plugin-syntax-decorators "^6.13.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-do-expressions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-do-expressions/-/babel-plugin-transform-do-expressions-6.22.0.tgz#28ccaf92812d949c2cd1281f690c8fdc468ae9bb" + dependencies: + babel-plugin-syntax-do-expressions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-arrow-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoped-functions/-/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoping@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.22.0.tgz#00d6e3a0bebdcfe7536b9d653b44a9141e63e47e" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + lodash "^4.2.0" + +babel-plugin-transform-es2015-classes@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.22.0.tgz#54d44998fd823d9dca15292324161c331c1b6f14" + dependencies: + babel-helper-define-map "^6.22.0" + babel-helper-function-name "^6.22.0" + babel-helper-optimise-call-expression "^6.22.0" + babel-helper-replace-supers "^6.22.0" + babel-messages "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-computed-properties@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.22.0.tgz#7c383e9629bba4820c11b0425bdd6290f7f057e7" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-es2015-destructuring@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.22.0.tgz#8e0af2f885a0b2cf999d47c4c1dd23ce88cfa4c6" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-duplicate-keys@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.22.0.tgz#672397031c21610d72dd2bbb0ba9fb6277e1c36b" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-for-of@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.22.0.tgz#180467ad63aeea592a1caeee4bf1c8b3e2616265" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-function-name@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.22.0.tgz#f5fcc8b09093f9a23c76ac3d9e392c3ec4b77104" + dependencies: + babel-helper-function-name "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-literals/-/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-modules-amd@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.22.0.tgz#bf69cd34889a41c33d90dfb740e0091ccff52f21" + dependencies: + babel-plugin-transform-es2015-modules-commonjs "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-es2015-modules-commonjs@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.22.0.tgz#6ca04e22b8e214fb50169730657e7a07dc941145" + dependencies: + babel-plugin-transform-strict-mode "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-modules-systemjs@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.22.0.tgz#810cd0cd025a08383b84236b92c6e31f88e644ad" + dependencies: + babel-helper-hoist-variables "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-es2015-modules-umd@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.22.0.tgz#60d0ba3bd23258719c64391d9bf492d648dc0fae" + dependencies: + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + +babel-plugin-transform-es2015-object-super@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.22.0.tgz#daa60e114a042ea769dd53fe528fc82311eb98fc" + dependencies: + babel-helper-replace-supers "^6.22.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-parameters@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.22.0.tgz#57076069232019094f27da8c68bb7162fe208dbb" + dependencies: + babel-helper-call-delegate "^6.22.0" + babel-helper-get-function-arity "^6.22.0" + babel-runtime "^6.22.0" + babel-template "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-shorthand-properties@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.22.0.tgz#8ba776e0affaa60bff21e921403b8a652a2ff723" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-spread@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-spread/-/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-sticky-regex@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.22.0.tgz#ab316829e866ee3f4b9eb96939757d19a5bc4593" + dependencies: + babel-helper-regex "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-plugin-transform-es2015-template-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-typeof-symbol@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.22.0.tgz#87faf2336d3b6a97f68c4d906b0cd0edeae676e1" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-unicode-regex@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.22.0.tgz#8d9cc27e7ee1decfe65454fb986452a04a613d20" + dependencies: + babel-helper-regex "^6.22.0" + babel-runtime "^6.22.0" + regexpu-core "^2.0.0" + +babel-plugin-transform-exponentiation-operator@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.22.0.tgz#d57c8335281918e54ef053118ce6eb108468084d" + dependencies: + babel-helper-builder-binary-assignment-operator-visitor "^6.22.0" + babel-plugin-syntax-exponentiation-operator "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-export-extensions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-export-extensions/-/babel-plugin-transform-export-extensions-6.22.0.tgz#53738b47e75e8218589eea946cbbd39109bbe653" + dependencies: + babel-plugin-syntax-export-extensions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-flow-strip-types@^6.3.13: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf" + dependencies: + babel-plugin-syntax-flow "^6.18.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-function-bind@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-function-bind/-/babel-plugin-transform-function-bind-6.22.0.tgz#c6fb8e96ac296a310b8cf8ea401462407ddf6a97" + dependencies: + babel-plugin-syntax-function-bind "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-object-rest-spread@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.22.0.tgz#1d419b55e68d2e4f64a5ff3373bd67d73c8e83bc" + dependencies: + babel-plugin-syntax-object-rest-spread "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-regenerator@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.22.0.tgz#65740593a319c44522157538d690b84094617ea6" + dependencies: + regenerator-transform "0.9.8" + +babel-plugin-transform-strict-mode@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.22.0.tgz#e008df01340fdc87e959da65991b7e05970c8c7c" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.22.0" + +babel-preset-es2015@^6.13.2: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.22.0.tgz#af5a98ecb35eb8af764ad8a5a05eb36dc4386835" + dependencies: + babel-plugin-check-es2015-constants "^6.22.0" + babel-plugin-transform-es2015-arrow-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoping "^6.22.0" + babel-plugin-transform-es2015-classes "^6.22.0" + babel-plugin-transform-es2015-computed-properties "^6.22.0" + babel-plugin-transform-es2015-destructuring "^6.22.0" + babel-plugin-transform-es2015-duplicate-keys "^6.22.0" + babel-plugin-transform-es2015-for-of "^6.22.0" + babel-plugin-transform-es2015-function-name "^6.22.0" + babel-plugin-transform-es2015-literals "^6.22.0" + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-plugin-transform-es2015-modules-commonjs "^6.22.0" + babel-plugin-transform-es2015-modules-systemjs "^6.22.0" + babel-plugin-transform-es2015-modules-umd "^6.22.0" + babel-plugin-transform-es2015-object-super "^6.22.0" + babel-plugin-transform-es2015-parameters "^6.22.0" + babel-plugin-transform-es2015-shorthand-properties "^6.22.0" + babel-plugin-transform-es2015-spread "^6.22.0" + babel-plugin-transform-es2015-sticky-regex "^6.22.0" + babel-plugin-transform-es2015-template-literals "^6.22.0" + babel-plugin-transform-es2015-typeof-symbol "^6.22.0" + babel-plugin-transform-es2015-unicode-regex "^6.22.0" + babel-plugin-transform-regenerator "^6.22.0" + +babel-preset-stage-0@^6.0.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-preset-stage-0/-/babel-preset-stage-0-6.22.0.tgz#707eeb5b415da769eff9c42f4547f644f9296ef9" + dependencies: + babel-plugin-transform-do-expressions "^6.22.0" + babel-plugin-transform-function-bind "^6.22.0" + babel-preset-stage-1 "^6.22.0" + +babel-preset-stage-1@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-preset-stage-1/-/babel-preset-stage-1-6.22.0.tgz#7da05bffea6ad5a10aef93e320cfc6dd465dbc1a" + dependencies: + babel-plugin-transform-class-constructor-call "^6.22.0" + babel-plugin-transform-export-extensions "^6.22.0" + babel-preset-stage-2 "^6.22.0" + +babel-preset-stage-2@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-preset-stage-2/-/babel-preset-stage-2-6.22.0.tgz#ccd565f19c245cade394b21216df704a73b27c07" + dependencies: + babel-plugin-syntax-dynamic-import "^6.18.0" + babel-plugin-transform-class-properties "^6.22.0" + babel-plugin-transform-decorators "^6.22.0" + babel-preset-stage-3 "^6.22.0" + +babel-preset-stage-3@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-preset-stage-3/-/babel-preset-stage-3-6.22.0.tgz#a4e92bbace7456fafdf651d7a7657ee0bbca9c2e" + dependencies: + babel-plugin-syntax-trailing-function-commas "^6.22.0" + babel-plugin-transform-async-generator-functions "^6.22.0" + babel-plugin-transform-async-to-generator "^6.22.0" + babel-plugin-transform-exponentiation-operator "^6.22.0" + babel-plugin-transform-object-rest-spread "^6.22.0" + +babel-register@^6.14.0, babel-register@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.22.0.tgz#a61dd83975f9ca4a9e7d6eff3059494cd5ea4c63" + dependencies: + babel-core "^6.22.0" + babel-runtime "^6.22.0" + core-js "^2.4.0" + home-or-tmp "^2.0.0" + lodash "^4.2.0" + mkdirp "^0.5.1" + source-map-support "^0.4.2" + +babel-runtime@^6.18.0, babel-runtime@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.22.0.tgz#1cf8b4ac67c77a4ddb0db2ae1f74de52ac4ca611" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.10.0" + +babel-template@^6.16.0, babel-template@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.22.0.tgz#403d110905a4626b317a2a1fcb8f3b73204b2edb" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.22.0" + babel-types "^6.22.0" + babylon "^6.11.0" + lodash "^4.2.0" + +babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-traverse@^6.22.1: + version "6.22.1" + resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.22.1.tgz#3b95cd6b7427d6f1f757704908f2fc9748a5f59f" + dependencies: + babel-code-frame "^6.22.0" + babel-messages "^6.22.0" + babel-runtime "^6.22.0" + babel-types "^6.22.0" + babylon "^6.15.0" + debug "^2.2.0" + globals "^9.0.0" + invariant "^2.2.0" + lodash "^4.2.0" + +babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.22.0.tgz#2a447e8d0ea25d2512409e4175479fd78cc8b1db" + dependencies: + babel-runtime "^6.22.0" + esutils "^2.0.2" + lodash "^4.2.0" + to-fast-properties "^1.0.1" + +babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0: + version "6.15.0" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e" + +balanced-match@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" + +base64-js@^1.0.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1" + +bcrypt-pbkdf@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.0.tgz#3ca76b85241c7170bf7d9703e7b9aa74630040d4" + dependencies: + tweetnacl "^0.14.3" + +beeper@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809" + +binary-extensions@^1.0.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.8.0.tgz#48ec8d16df4377eae5fa5884682480af4d95c774" + +block-stream@*: + version "0.0.9" + resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" + dependencies: + inherits "~2.0.0" + +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: + version "4.11.6" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" + +boom@2.x.x: + version "2.10.1" + resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f" + dependencies: + hoek "2.x.x" + +brace-expansion@^1.0.0: + version "1.1.6" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9" + dependencies: + balanced-match "^0.4.1" + concat-map "0.0.1" + +braces@^1.8.2: + version "1.8.5" + resolved "https://registry.yarnpkg.com/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7" + dependencies: + expand-range "^1.8.1" + preserve "^0.2.0" + repeat-element "^1.1.2" + +brorand@^1.0.1: + version "1.0.6" + resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.0.6.tgz#4028706b915f91f7b349a2e0bf3c376039d216e5" + +browser-pack@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/browser-pack/-/browser-pack-5.0.1.tgz#4197719b20c6e0aaa09451c5111e53efb6fbc18d" + dependencies: + JSONStream "^1.0.3" + combine-source-map "~0.6.1" + defined "^1.0.0" + through2 "^1.0.0" + umd "^3.0.0" + +browser-pack@^6.0.1: + version "6.0.2" + resolved "https://registry.yarnpkg.com/browser-pack/-/browser-pack-6.0.2.tgz#f86cd6cef4f5300c8e63e07a4d512f65fbff4531" + dependencies: + JSONStream "^1.0.3" + combine-source-map "~0.7.1" + defined "^1.0.0" + through2 "^2.0.0" + umd "^3.0.0" + +browser-resolve@^1.11.0, browser-resolve@^1.7.0: + version "1.11.2" + resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.2.tgz#8ff09b0a2c421718a1051c260b32e48f442938ce" + dependencies: + resolve "1.1.7" + +browser-stdout@1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" + +browser-unpack@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/browser-unpack/-/browser-unpack-1.1.1.tgz#42d1423bf719074c1ef88d82e6b94752a41882bd" + dependencies: + acorn "^2.1.0" + browser-pack "^5.0.1" + concat-stream "^1.5.0" + minimist "^1.1.1" + +browserify-aes@^1.0.0, browserify-aes@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.0.6.tgz#5e7725dbdef1fd5930d4ebab48567ce451c48a0a" + dependencies: + buffer-xor "^1.0.2" + cipher-base "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.0" + inherits "^2.0.1" + +browserify-cipher@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/browserify-cipher/-/browserify-cipher-1.0.0.tgz#9988244874bf5ed4e28da95666dcd66ac8fc363a" + dependencies: + browserify-aes "^1.0.4" + browserify-des "^1.0.0" + evp_bytestokey "^1.0.0" + +browserify-des@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/browserify-des/-/browserify-des-1.0.0.tgz#daa277717470922ed2fe18594118a175439721dd" + dependencies: + cipher-base "^1.0.1" + des.js "^1.0.0" + inherits "^2.0.1" + +browserify-rsa@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524" + dependencies: + bn.js "^4.1.0" + randombytes "^2.0.1" + +browserify-sign@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.0.0.tgz#10773910c3c206d5420a46aad8694f820b85968f" + dependencies: + bn.js "^4.1.1" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.2" + elliptic "^6.0.0" + inherits "^2.0.1" + parse-asn1 "^5.0.0" + +browserify-zlib@~0.1.2: + version "0.1.4" + resolved "https://registry.yarnpkg.com/browserify-zlib/-/browserify-zlib-0.1.4.tgz#bb35f8a519f600e0fa6b8485241c979d0141fb2d" + dependencies: + pako "~0.2.0" + +browserify@^13.1.1: + version "13.3.0" + resolved "https://registry.yarnpkg.com/browserify/-/browserify-13.3.0.tgz#b5a9c9020243f0c70e4675bec8223bc627e415ce" + dependencies: + JSONStream "^1.0.3" + assert "^1.4.0" + browser-pack "^6.0.1" + browser-resolve "^1.11.0" + browserify-zlib "~0.1.2" + buffer "^4.1.0" + cached-path-relative "^1.0.0" + concat-stream "~1.5.1" + console-browserify "^1.1.0" + constants-browserify "~1.0.0" + crypto-browserify "^3.0.0" + defined "^1.0.0" + deps-sort "^2.0.0" + domain-browser "~1.1.0" + duplexer2 "~0.1.2" + events "~1.1.0" + glob "^7.1.0" + has "^1.0.0" + htmlescape "^1.1.0" + https-browserify "~0.0.0" + inherits "~2.0.1" + insert-module-globals "^7.0.0" + labeled-stream-splicer "^2.0.0" + module-deps "^4.0.8" + os-browserify "~0.1.1" + parents "^1.0.1" + path-browserify "~0.0.0" + process "~0.11.0" + punycode "^1.3.2" + querystring-es3 "~0.2.0" + read-only-stream "^2.0.0" + readable-stream "^2.0.2" + resolve "^1.1.4" + shasum "^1.0.0" + shell-quote "^1.6.1" + stream-browserify "^2.0.0" + stream-http "^2.0.0" + string_decoder "~0.10.0" + subarg "^1.0.0" + syntax-error "^1.1.1" + through2 "^2.0.0" + timers-browserify "^1.0.1" + tty-browserify "~0.0.0" + url "~0.11.0" + util "~0.10.1" + vm-browserify "~0.0.1" + xtend "^4.0.0" + +buffer-shims@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51" + +buffer-xor@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" + +buffer@^4.1.0: + version "4.9.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298" + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + isarray "^1.0.0" + +builtin-modules@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" + +builtin-status-codes@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" + +bundle-collapser@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/bundle-collapser/-/bundle-collapser-1.2.1.tgz#e119afc92638e440b9085f47ae081fa756cba33d" + dependencies: + browser-pack "^5.0.1" + browser-unpack "^1.1.0" + concat-stream "^1.5.0" + falafel "^1.2.0" + minimist "^1.1.1" + through2 "^2.0.0" + +cached-path-relative@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/cached-path-relative/-/cached-path-relative-1.0.0.tgz#d1094c577fbd9a8b8bd43c96af6188aa205d05f4" + +caching-transform@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/caching-transform/-/caching-transform-1.0.1.tgz#6dbdb2f20f8d8fbce79f3e94e9d1742dcdf5c0a1" + dependencies: + md5-hex "^1.2.0" + mkdirp "^0.5.1" + write-file-atomic "^1.1.4" + +caller-path@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f" + dependencies: + callsites "^0.2.0" + +callsites@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca" + +camelcase-keys@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-2.1.0.tgz#308beeaffdf28119051efa1d932213c91b8f92e7" + dependencies: + camelcase "^2.0.0" + map-obj "^1.0.0" + +camelcase@^1.0.2: + version "1.2.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" + +camelcase@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f" + +camelcase@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-3.0.0.tgz#32fc4b9fcdaf845fcdf7e73bb97cac2261f0ab0a" + +caseless@~0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7" + +center-align@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad" + dependencies: + align-text "^0.1.3" + lazy-cache "^1.0.3" + +chai@^3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247" + dependencies: + assertion-error "^1.0.1" + deep-eql "^0.1.3" + type-detect "^1.0.0" + +chalk@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.1.tgz#509afb67066e7499f7eb3535c77445772ae2d019" + dependencies: + ansi-styles "^2.1.0" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + +chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + +chokidar@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.1.tgz#2f4447ab5e96e50fb3d789fd90d4c72e0e4c70c2" + dependencies: + anymatch "^1.3.0" + async-each "^1.0.0" + glob-parent "^2.0.0" + inherits "^2.0.1" + is-binary-path "^1.0.0" + is-glob "^2.0.0" + path-is-absolute "^1.0.0" + readdirp "^2.0.0" + optionalDependencies: + fsevents "^1.0.0" + +cipher-base@^1.0.0, cipher-base@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.3.tgz#eeabf194419ce900da3018c207d212f2a6df0a07" + dependencies: + inherits "^2.0.1" + +circular-json@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d" + +cli-cursor@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987" + dependencies: + restore-cursor "^1.0.1" + +cli-cursor@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" + dependencies: + restore-cursor "^2.0.0" + +cli-width@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a" + +cliui@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1" + dependencies: + center-align "^0.1.1" + right-align "^0.1.1" + wordwrap "0.0.2" + +cliui@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d" + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + wrap-ansi "^2.0.0" + +clone-stats@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/clone-stats/-/clone-stats-0.0.1.tgz#b88f94a82cf38b8791d58046ea4029ad88ca99d1" + +clone@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/clone/-/clone-0.2.0.tgz#c6126a90ad4f72dbf5acdb243cc37724fe93fc1f" + +clone@^1.0.0, clone@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.2.tgz#260b7a99ebb1edfe247538175f783243cb19d149" + +cmd-shim@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/cmd-shim/-/cmd-shim-2.0.2.tgz#6fcbda99483a8fd15d7d30a196ca69d688a2efdb" + dependencies: + graceful-fs "^4.1.2" + mkdirp "~0.5.0" + +co@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" + +code-point-at@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" + +codecov@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/codecov/-/codecov-1.0.1.tgz#97260ceac0e96b8eda8d562006558a53a139dffd" + dependencies: + argv ">=0.0.2" + execSync "1.0.2" + request ">=2.42.0" + urlgrey ">=0.4.0" + +columnify@^1.5.4: + version "1.5.4" + resolved "https://registry.yarnpkg.com/columnify/-/columnify-1.5.4.tgz#4737ddf1c7b69a8a7c340570782e947eec8e78bb" + dependencies: + strip-ansi "^3.0.0" + wcwidth "^1.0.0" + +combine-source-map@~0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/combine-source-map/-/combine-source-map-0.6.1.tgz#9b4a09c316033d768e0f11e029fa2730e079ad96" + dependencies: + convert-source-map "~1.1.0" + inline-source-map "~0.5.0" + lodash.memoize "~3.0.3" + source-map "~0.4.2" + +combine-source-map@~0.7.1: + version "0.7.2" + resolved "https://registry.yarnpkg.com/combine-source-map/-/combine-source-map-0.7.2.tgz#0870312856b307a87cc4ac486f3a9a62aeccc09e" + dependencies: + convert-source-map "~1.1.0" + inline-source-map "~0.6.0" + lodash.memoize "~3.0.3" + source-map "~0.5.3" + +combined-stream@^1.0.5, combined-stream@~1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" + dependencies: + delayed-stream "~1.0.0" + +command-join@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/command-join/-/command-join-2.0.0.tgz#52e8b984f4872d952ff1bdc8b98397d27c7144cf" + +commander@2.9.0, commander@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" + dependencies: + graceful-readlink ">= 1.0.0" + +commondir@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +concat-stream@^1.4.6, concat-stream@^1.5.0, concat-stream@~1.5.0, concat-stream@~1.5.1: + version "1.5.2" + resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266" + dependencies: + inherits "~2.0.1" + readable-stream "~2.0.0" + typedarray "~0.0.5" + +console-browserify@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" + dependencies: + date-now "^0.1.4" + +console-control-strings@^1.0.0, console-control-strings@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" + +constants-browserify@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-1.0.0.tgz#c20b96d8c617748aaf1c16021760cd27fcb8cb75" + +convert-source-map@^1.1.0, convert-source-map@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.3.0.tgz#e9f3e9c6e2728efc2676696a70eb382f73106a67" + +convert-source-map@~1.1.0: + version "1.1.3" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.1.3.tgz#4829c877e9fe49b3161f3bf3673888e204699860" + +core-js@^2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e" + +core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + +create-ecdh@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d" + dependencies: + bn.js "^4.1.0" + elliptic "^6.0.0" + +create-hash@^1.1.0, create-hash@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.1.2.tgz#51210062d7bb7479f6c65bb41a92208b1d61abad" + dependencies: + cipher-base "^1.0.1" + inherits "^2.0.1" + ripemd160 "^1.0.0" + sha.js "^2.3.6" + +create-hmac@^1.1.0, create-hmac@^1.1.2: + version "1.1.4" + resolved "https://registry.yarnpkg.com/create-hmac/-/create-hmac-1.1.4.tgz#d3fb4ba253eb8b3f56e39ea2fbcb8af747bd3170" + dependencies: + create-hash "^1.1.0" + inherits "^2.0.1" + +cross-spawn@^4, cross-spawn@^4.0.0: + version "4.0.2" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41" + dependencies: + lru-cache "^4.0.1" + which "^1.2.9" + +cryptiles@2.x.x: + version "2.0.5" + resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8" + dependencies: + boom "2.x.x" + +crypto-browserify@^3.0.0: + version "3.11.0" + resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.11.0.tgz#3652a0906ab9b2a7e0c3ce66a408e957a2485522" + dependencies: + browserify-cipher "^1.0.0" + browserify-sign "^4.0.0" + create-ecdh "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.0" + diffie-hellman "^5.0.0" + inherits "^2.0.1" + pbkdf2 "^3.0.3" + public-encrypt "^4.0.0" + randombytes "^2.0.0" + +currently-unhandled@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea" + dependencies: + array-find-index "^1.0.1" + +d@^0.1.1, d@~0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309" + dependencies: + es5-ext "~0.10.2" + +dashdash@^1.12.0: + version "1.14.1" + resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" + dependencies: + assert-plus "^1.0.0" + +date-now@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" + +dateformat@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.0.0.tgz#2743e3abb5c3fc2462e527dca445e04e9f4dee17" + +debug-log@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f" + +debug@2.2.0, debug@~2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" + dependencies: + ms "0.7.1" + +debug@^2.1.1, debug@^2.2.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b" + dependencies: + ms "0.7.2" + +decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + +deep-eql@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2" + dependencies: + type-detect "0.1.1" + +deep-extend@~0.4.0: + version "0.4.1" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.1.tgz#efe4113d08085f4e6f9687759810f807469e2253" + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + +default-require-extensions@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-1.0.0.tgz#f37ea15d3e13ffd9b437d33e1a75b5fb97874cb8" + dependencies: + strip-bom "^2.0.0" + +defaults@^1.0.0, defaults@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d" + dependencies: + clone "^1.0.2" + +defined@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" + +del@^2.0.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/del/-/del-2.2.2.tgz#c12c981d067846c84bcaf862cff930d907ffd1a8" + dependencies: + globby "^5.0.0" + is-path-cwd "^1.0.0" + is-path-in-cwd "^1.0.0" + object-assign "^4.0.1" + pify "^2.0.0" + pinkie-promise "^2.0.0" + rimraf "^2.2.8" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + +delegates@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" + +deprecated@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/deprecated/-/deprecated-0.0.1.tgz#f9c9af5464afa1e7a971458a8bdef2aa94d5bb19" + +deps-sort@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/deps-sort/-/deps-sort-2.0.0.tgz#091724902e84658260eb910748cccd1af6e21fb5" + dependencies: + JSONStream "^1.0.3" + shasum "^1.0.0" + subarg "^1.0.0" + through2 "^2.0.0" + +derequire@^2.0.2: + version "2.0.6" + resolved "https://registry.yarnpkg.com/derequire/-/derequire-2.0.6.tgz#31a414bb7ca176239fa78b116636ef77d517e768" + dependencies: + acorn "^4.0.3" + concat-stream "^1.4.6" + escope "^3.6.0" + through2 "^2.0.0" + yargs "^6.5.0" + +des.js@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc" + dependencies: + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +detect-file@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-0.1.0.tgz#4935dedfd9488648e006b0129566e9386711ea63" + dependencies: + fs-exists-sync "^0.1.0" + +detect-indent@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208" + dependencies: + repeating "^2.0.0" + +detective@^4.0.0: + version "4.3.2" + resolved "https://registry.yarnpkg.com/detective/-/detective-4.3.2.tgz#77697e2e7947ac3fe7c8e26a6d6f115235afa91c" + dependencies: + acorn "^3.1.0" + defined "^1.0.0" + +diff@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" + +diffie-hellman@^5.0.0: + version "5.0.2" + resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e" + dependencies: + bn.js "^4.1.0" + miller-rabin "^4.0.0" + randombytes "^2.0.0" + +doctrine@^1.2.2: + version "1.5.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" + dependencies: + esutils "^2.0.2" + isarray "^1.0.0" + +domain-browser@~1.1.0: + version "1.1.7" + resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" + +duplexer2@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.0.2.tgz#c614dcf67e2fb14995a91711e5a617e8a60a31db" + dependencies: + readable-stream "~1.1.9" + +duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2: + version "0.1.4" + resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1" + dependencies: + readable-stream "^2.0.2" + +ecc-jsbn@~0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505" + dependencies: + jsbn "~0.1.0" + +elliptic@^6.0.0: + version "6.3.2" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.3.2.tgz#e4c81e0829cf0a65ab70e998b8232723b5c1bc48" + dependencies: + bn.js "^4.4.0" + brorand "^1.0.1" + hash.js "^1.0.0" + inherits "^2.0.1" + +end-of-stream@~0.1.5: + version "0.1.5" + resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-0.1.5.tgz#8e177206c3c80837d85632e8b9359dfe8b2f6eaf" + dependencies: + once "~1.3.0" + +error-ex@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.0.tgz#e67b43f3e82c96ea3a584ffee0b9fc3325d802d9" + dependencies: + is-arrayish "^0.2.1" + +es5-ext@^0.10.7, es5-ext@^0.10.8, es5-ext@~0.10.11, es5-ext@~0.10.2, es5-ext@~0.10.7: + version "0.10.12" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.12.tgz#aa84641d4db76b62abba5e45fd805ecbab140047" + dependencies: + es6-iterator "2" + es6-symbol "~3.1" + +es6-iterator@2: + version "2.0.0" + resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.0.tgz#bd968567d61635e33c0b80727613c9cb4b096bac" + dependencies: + d "^0.1.1" + es5-ext "^0.10.7" + es6-symbol "3" + +es6-map@^0.1.3: + version "0.1.4" + resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.4.tgz#a34b147be224773a4d7da8072794cefa3632b897" + dependencies: + d "~0.1.1" + es5-ext "~0.10.11" + es6-iterator "2" + es6-set "~0.1.3" + es6-symbol "~3.1.0" + event-emitter "~0.3.4" + +es6-set@~0.1.3: + version "0.1.4" + resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.4.tgz#9516b6761c2964b92ff479456233a247dc707ce8" + dependencies: + d "~0.1.1" + es5-ext "~0.10.11" + es6-iterator "2" + es6-symbol "3" + event-emitter "~0.3.4" + +es6-symbol@3, es6-symbol@~3.1, es6-symbol@~3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.0.tgz#94481c655e7a7cad82eba832d97d5433496d7ffa" + dependencies: + d "~0.1.1" + es5-ext "~0.10.11" + +es6-weak-map@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.1.tgz#0d2bbd8827eb5fb4ba8f97fbfea50d43db21ea81" + dependencies: + d "^0.1.1" + es5-ext "^0.10.8" + es6-iterator "2" + es6-symbol "3" + +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +escope@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/escope/-/escope-3.6.0.tgz#e01975e812781a163a6dadfdd80398dc64c889c3" + dependencies: + es6-map "^0.1.3" + es6-weak-map "^2.0.1" + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-config-babel@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-babel/-/eslint-config-babel-6.0.0.tgz#66feedf6ce6e04abe585cec1a65b5bcc96bed50a" + +eslint-plugin-flowtype@^2.20.0: + version "2.30.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.0.tgz#3054a265f9c8afe3046c3d41b72d32a736f9b4ae" + dependencies: + lodash "^4.15.0" + +eslint@^3.9.0: + version "3.13.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.13.1.tgz#564d2646b5efded85df96985332edd91a23bff25" + dependencies: + babel-code-frame "^6.16.0" + chalk "^1.1.3" + concat-stream "^1.4.6" + debug "^2.1.1" + doctrine "^1.2.2" + escope "^3.6.0" + espree "^3.3.1" + estraverse "^4.2.0" + esutils "^2.0.2" + file-entry-cache "^2.0.0" + glob "^7.0.3" + globals "^9.14.0" + ignore "^3.2.0" + imurmurhash "^0.1.4" + inquirer "^0.12.0" + is-my-json-valid "^2.10.0" + is-resolvable "^1.0.0" + js-yaml "^3.5.1" + json-stable-stringify "^1.0.0" + levn "^0.3.0" + lodash "^4.0.0" + mkdirp "^0.5.0" + natural-compare "^1.4.0" + optionator "^0.8.2" + path-is-inside "^1.0.1" + pluralize "^1.2.1" + progress "^1.1.8" + require-uncached "^1.0.2" + shelljs "^0.7.5" + strip-bom "^3.0.0" + strip-json-comments "~2.0.1" + table "^3.7.8" + text-table "~0.2.0" + user-home "^2.0.0" + +espree@^3.3.1: + version "3.3.2" + resolved "https://registry.yarnpkg.com/espree/-/espree-3.3.2.tgz#dbf3fadeb4ecb4d4778303e50103b3d36c88b89c" + dependencies: + acorn "^4.0.1" + acorn-jsx "^3.0.0" + +esprima@^2.6.0: + version "2.7.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" + +esrecurse@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.1.0.tgz#4713b6536adf7f2ac4f327d559e7756bff648220" + dependencies: + estraverse "~4.1.0" + object-assign "^4.0.1" + +estraverse@^4.1.1, estraverse@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" + +estraverse@~4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.1.1.tgz#f6caca728933a850ef90661d0e17982ba47111a2" + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +event-emitter@~0.3.4: + version "0.3.4" + resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.4.tgz#8d63ddfb4cfe1fae3b32ca265c4c720222080bb5" + dependencies: + d "~0.1.1" + es5-ext "~0.10.7" + +events@~1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" + +evp_bytestokey@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.0.tgz#497b66ad9fef65cd7c08a6180824ba1476b66e53" + dependencies: + create-hash "^1.1.1" + +execSync@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/execSync/-/execSync-1.0.2.tgz#1f42eda582225180053224ecdd3fd1960fdb3139" + dependencies: + temp "~0.5.1" + +exit-hook@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8" + +expand-brackets@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b" + dependencies: + is-posix-bracket "^0.1.0" + +expand-range@^1.8.1: + version "1.8.2" + resolved "https://registry.yarnpkg.com/expand-range/-/expand-range-1.8.2.tgz#a299effd335fe2721ebae8e257ec79644fc85337" + dependencies: + fill-range "^2.1.0" + +expand-tilde@^1.2.1, expand-tilde@^1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-1.2.2.tgz#0b81eba897e5a3d31d1c3d102f8f01441e559449" + dependencies: + os-homedir "^1.0.1" + +extend@^3.0.0, extend@~3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.0.tgz#5a474353b9f3353ddd8176dfd37b91c83a46f1d4" + +external-editor@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.0.1.tgz#4c597c6c88fa6410e41dbbaa7b1be2336aa31095" + dependencies: + tmp "^0.0.31" + +extglob@^0.3.1: + version "0.3.2" + resolved "https://registry.yarnpkg.com/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1" + dependencies: + is-extglob "^1.0.0" + +extsprintf@1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550" + +falafel@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/falafel/-/falafel-1.2.0.tgz#c18d24ef5091174a497f318cd24b026a25cddab4" + dependencies: + acorn "^1.0.3" + foreach "^2.0.5" + isarray "0.0.1" + object-keys "^1.0.6" + +fancy-log@^1.1.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/fancy-log/-/fancy-log-1.3.0.tgz#45be17d02bb9917d60ccffd4995c999e6c8c9948" + dependencies: + chalk "^1.1.1" + time-stamp "^1.0.0" + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + +figures@^1.3.5: + version "1.7.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" + dependencies: + escape-string-regexp "^1.0.5" + object-assign "^4.1.0" + +figures@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" + dependencies: + escape-string-regexp "^1.0.5" + +file-entry-cache@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-2.0.0.tgz#c392990c3e684783d838b8c84a45d8a048458361" + dependencies: + flat-cache "^1.2.1" + object-assign "^4.0.1" + +filename-regex@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.0.tgz#996e3e80479b98b9897f15a8a58b3d084e926775" + +fill-range@^2.1.0: + version "2.2.3" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723" + dependencies: + is-number "^2.1.0" + isobject "^2.0.0" + randomatic "^1.1.3" + repeat-element "^1.1.2" + repeat-string "^1.5.2" + +find-cache-dir@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9" + dependencies: + commondir "^1.0.1" + mkdirp "^0.5.1" + pkg-dir "^1.0.0" + +find-index@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/find-index/-/find-index-0.1.1.tgz#675d358b2ca3892d795a1ab47232f8b6e2e0dde4" + +find-up@^1.0.0, find-up@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f" + dependencies: + path-exists "^2.0.0" + pinkie-promise "^2.0.0" + +findup-sync@^0.4.2: + version "0.4.3" + resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-0.4.3.tgz#40043929e7bc60adf0b7f4827c4c6e75a0deca12" + dependencies: + detect-file "^0.1.0" + is-glob "^2.0.1" + micromatch "^2.3.7" + resolve-dir "^0.1.0" + +fined@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/fined/-/fined-1.0.2.tgz#5b28424b760d7598960b7ef8480dff8ad3660e97" + dependencies: + expand-tilde "^1.2.1" + lodash.assignwith "^4.0.7" + lodash.isempty "^4.2.1" + lodash.isplainobject "^4.0.4" + lodash.isstring "^4.0.1" + lodash.pick "^4.2.1" + parse-filepath "^1.0.1" + +first-chunk-stream@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/first-chunk-stream/-/first-chunk-stream-1.0.0.tgz#59bfb50cd905f60d7c394cd3d9acaab4e6ad934e" + +first-chunk-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/first-chunk-stream/-/first-chunk-stream-2.0.0.tgz#1bdecdb8e083c0664b91945581577a43a9f31d70" + dependencies: + readable-stream "^2.0.2" + +flagged-respawn@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/flagged-respawn/-/flagged-respawn-0.3.2.tgz#ff191eddcd7088a675b2610fffc976be9b8074b5" + +flat-cache@^1.2.1: + version "1.2.2" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.2.2.tgz#fa86714e72c21db88601761ecf2f555d1abc6b96" + dependencies: + circular-json "^0.3.1" + del "^2.0.2" + graceful-fs "^4.1.2" + write "^0.2.1" + +flow-bin@^0.34.0: + version "0.34.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.34.0.tgz#093ed36981e8fafc39d16f0b0878d0968aa80fad" + +for-in@^0.1.5: + version "0.1.6" + resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.6.tgz#c9f96e89bfad18a545af5ec3ed352a1d9e5b4dc8" + +for-own@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.4.tgz#0149b41a39088c7515f51ebe1c1386d45f935072" + dependencies: + for-in "^0.1.5" + +foreach@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" + +foreground-child@^1.3.3, foreground-child@^1.5.3: + version "1.5.6" + resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-1.5.6.tgz#4fd71ad2dfde96789b980a5c0a295937cb2f5ce9" + dependencies: + cross-spawn "^4" + signal-exit "^3.0.0" + +forever-agent@~0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" + +form-data@~2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + +fs-exists-sync@^0.1.0: + version "0.1.0" + resolved "http://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +fsevents@^1.0.0: + version "1.0.17" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.0.17.tgz#8537f3f12272678765b4fd6528c0f1f66f8f4558" + dependencies: + nan "^2.3.0" + node-pre-gyp "^0.6.29" + +fstream-ignore@~1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/fstream-ignore/-/fstream-ignore-1.0.5.tgz#9c31dae34767018fe1d249b24dada67d092da105" + dependencies: + fstream "^1.0.0" + inherits "2" + minimatch "^3.0.0" + +fstream@^1.0.0, fstream@^1.0.2, fstream@~1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.10.tgz#604e8a92fe26ffd9f6fae30399d4984e1ab22822" + dependencies: + graceful-fs "^4.1.2" + inherits "~2.0.0" + mkdirp ">=0.5 0" + rimraf "2" + +function-bind@^1.0.2: + version "1.1.0" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" + +gauge@~2.7.1: + version "2.7.2" + resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.2.tgz#15cecc31b02d05345a5d6b0e171cdb3ad2307774" + dependencies: + aproba "^1.0.3" + console-control-strings "^1.0.0" + has-unicode "^2.0.0" + object-assign "^4.1.0" + signal-exit "^3.0.0" + string-width "^1.0.1" + strip-ansi "^3.0.1" + supports-color "^0.2.0" + wide-align "^1.1.0" + +gaze@^0.5.1: + version "0.5.2" + resolved "https://registry.yarnpkg.com/gaze/-/gaze-0.5.2.tgz#40b709537d24d1d45767db5a908689dfe69ac44f" + dependencies: + globule "~0.1.0" + +generate-function@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.0.0.tgz#6858fe7c0969b7d4e9093337647ac79f60dfbe74" + +generate-object-property@^1.1.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/generate-object-property/-/generate-object-property-1.2.0.tgz#9c0e1c40308ce804f4783618b937fa88f99d50d0" + dependencies: + is-property "^1.0.0" + +get-caller-file@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" + +get-stdin@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" + +getpass@^0.1.1: + version "0.1.6" + resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.6.tgz#283ffd9fc1256840875311c1b60e8c40187110e6" + dependencies: + assert-plus "^1.0.0" + +glob-base@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" + dependencies: + glob-parent "^2.0.0" + is-glob "^2.0.0" + +glob-parent@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-2.0.0.tgz#81383d72db054fcccf5336daa902f182f6edbb28" + dependencies: + is-glob "^2.0.0" + +glob-parent@^3.0.1: + version "3.1.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae" + dependencies: + is-glob "^3.1.0" + path-dirname "^1.0.0" + +glob-stream@^3.1.5: + version "3.1.18" + resolved "https://registry.yarnpkg.com/glob-stream/-/glob-stream-3.1.18.tgz#9170a5f12b790306fdfe598f313f8f7954fd143b" + dependencies: + glob "^4.3.1" + glob2base "^0.0.12" + minimatch "^2.0.1" + ordered-read-streams "^0.1.0" + through2 "^0.6.1" + unique-stream "^1.0.0" + +glob-watcher@^0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/glob-watcher/-/glob-watcher-0.0.6.tgz#b95b4a8df74b39c83298b0c05c978b4d9a3b710b" + dependencies: + gaze "^0.5.1" + +glob2base@^0.0.12: + version "0.0.12" + resolved "http://registry.npmjs.org/glob2base/-/glob2base-0.0.12.tgz#9d419b3e28f12e83a362164a277055922c9c0d56" + dependencies: + find-index "^0.1.1" + +glob@7.0.5: + version "7.0.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + +glob@^4.3.1: + version "4.5.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f" + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "^2.0.1" + once "^1.3.0" + +glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.0: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + +glob@~3.1.21: + version "3.1.21" + resolved "https://registry.yarnpkg.com/glob/-/glob-3.1.21.tgz#d29e0a055dea5138f4d07ed40e8982e83c2066cd" + dependencies: + graceful-fs "~1.2.0" + inherits "1" + minimatch "~0.2.11" + +global-modules@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-0.2.3.tgz#ea5a3bed42c6d6ce995a4f8a1269b5dae223828d" + dependencies: + global-prefix "^0.1.4" + is-windows "^0.2.0" + +global-prefix@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-0.1.5.tgz#8d3bc6b8da3ca8112a160d8d496ff0462bfef78f" + dependencies: + homedir-polyfill "^1.0.0" + ini "^1.3.4" + is-windows "^0.2.0" + which "^1.2.12" + +globals@^9.0.0, globals@^9.14.0: + version "9.14.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-9.14.0.tgz#8859936af0038741263053b39d0e76ca241e4034" + +globby@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/globby/-/globby-5.0.0.tgz#ebd84667ca0dbb330b99bcfc68eac2bc54370e0d" + dependencies: + array-union "^1.0.1" + arrify "^1.0.0" + glob "^7.0.3" + object-assign "^4.0.1" + pify "^2.0.0" + pinkie-promise "^2.0.0" + +globule@~0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/globule/-/globule-0.1.0.tgz#d9c8edde1da79d125a151b79533b978676346ae5" + dependencies: + glob "~3.1.21" + lodash "~1.0.1" + minimatch "~0.2.11" + +glogg@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/glogg/-/glogg-1.0.0.tgz#7fe0f199f57ac906cf512feead8f90ee4a284fc5" + dependencies: + sparkles "^1.0.0" + +graceful-fs@^3.0.0: + version "3.0.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-3.0.11.tgz#7613c778a1afea62f25c630a086d7f3acbbdd818" + dependencies: + natives "^1.1.0" + +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4: + version "4.1.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" + +graceful-fs@~1, graceful-fs@~1.2.0: + version "1.2.3" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-1.2.3.tgz#15a4806a57547cb2d2dbf27f42e89a8c3451b364" + +"graceful-readlink@>= 1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" + +growl@1.9.2: + version "1.9.2" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" + +gulp-babel@^6.0.0: + version "6.1.2" + resolved "https://registry.yarnpkg.com/gulp-babel/-/gulp-babel-6.1.2.tgz#7c0176e4ba3f244c60588a0c4b320a45d1adefce" + dependencies: + babel-core "^6.0.2" + gulp-util "^3.0.0" + object-assign "^4.0.1" + replace-ext "0.0.1" + through2 "^2.0.0" + vinyl-sourcemaps-apply "^0.2.0" + +gulp-newer@^1.0.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/gulp-newer/-/gulp-newer-1.3.0.tgz#d50ecacbb822eda492b57324a6c85a07fd9a55c1" + dependencies: + glob "^7.0.3" + gulp-util "^3.0.7" + kew "^0.7.0" + +gulp-plumber@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/gulp-plumber/-/gulp-plumber-1.1.0.tgz#f12176c2d0422f60306c242fff6a01a394faba09" + dependencies: + gulp-util "^3" + through2 "^2" + +gulp-util@^3, gulp-util@^3.0.0, gulp-util@^3.0.7: + version "3.0.8" + resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f" + dependencies: + array-differ "^1.0.0" + array-uniq "^1.0.2" + beeper "^1.0.0" + chalk "^1.0.0" + dateformat "^2.0.0" + fancy-log "^1.1.0" + gulplog "^1.0.0" + has-gulplog "^0.1.0" + lodash._reescape "^3.0.0" + lodash._reevaluate "^3.0.0" + lodash._reinterpolate "^3.0.0" + lodash.template "^3.0.0" + minimist "^1.1.0" + multipipe "^0.1.2" + object-assign "^3.0.0" + replace-ext "0.0.1" + through2 "^2.0.0" + vinyl "^0.5.0" + +gulp-watch@^4.3.5: + version "4.3.11" + resolved "https://registry.yarnpkg.com/gulp-watch/-/gulp-watch-4.3.11.tgz#162fc563de9fc770e91f9a7ce3955513a9a118c0" + dependencies: + anymatch "^1.3.0" + chokidar "^1.6.1" + glob-parent "^3.0.1" + gulp-util "^3.0.7" + object-assign "^4.1.0" + path-is-absolute "^1.0.1" + readable-stream "^2.2.2" + slash "^1.0.0" + vinyl "^1.2.0" + vinyl-file "^2.0.0" + +gulp@^3.9.0: + version "3.9.1" + resolved "https://registry.yarnpkg.com/gulp/-/gulp-3.9.1.tgz#571ce45928dd40af6514fc4011866016c13845b4" + dependencies: + archy "^1.0.0" + chalk "^1.0.0" + deprecated "^0.0.1" + gulp-util "^3.0.0" + interpret "^1.0.0" + liftoff "^2.1.0" + minimist "^1.1.0" + orchestrator "^0.3.0" + pretty-hrtime "^1.0.0" + semver "^4.1.0" + tildify "^1.0.0" + v8flags "^2.0.2" + vinyl-fs "^0.3.0" + +gulplog@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/gulplog/-/gulplog-1.0.0.tgz#e28c4d45d05ecbbed818363ce8f9c5926229ffe5" + dependencies: + glogg "^1.0.0" + +handlebars@^4.0.3: + version "4.0.6" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.6.tgz#2ce4484850537f9c97a8026d5399b935c4ed4ed7" + dependencies: + async "^1.4.0" + optimist "^0.6.1" + source-map "^0.4.4" + optionalDependencies: + uglify-js "^2.6" + +har-validator@~2.0.6: + version "2.0.6" + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-2.0.6.tgz#cdcbc08188265ad119b6a5a7c8ab70eecfb5d27d" + dependencies: + chalk "^1.1.1" + commander "^2.9.0" + is-my-json-valid "^2.12.4" + pinkie-promise "^2.0.0" + +has-ansi@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + dependencies: + ansi-regex "^2.0.0" + +has-flag@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" + +has-gulplog@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/has-gulplog/-/has-gulplog-0.1.0.tgz#6414c82913697da51590397dafb12f22967811ce" + dependencies: + sparkles "^1.0.0" + +has-unicode@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" + +has@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28" + dependencies: + function-bind "^1.0.2" + +hash.js@^1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.0.3.tgz#1332ff00156c0a0ffdd8236013d07b77a0451573" + dependencies: + inherits "^2.0.1" + +hawk@~3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" + dependencies: + boom "2.x.x" + cryptiles "2.x.x" + hoek "2.x.x" + sntp "1.x.x" + +hoek@2.x.x: + version "2.16.3" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" + +home-or-tmp@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.1" + +homedir-polyfill@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc" + dependencies: + parse-passwd "^1.0.0" + +hosted-git-info@^2.1.4: + version "2.1.5" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.1.5.tgz#0ba81d90da2e25ab34a332e6ec77936e1598118b" + +htmlescape@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/htmlescape/-/htmlescape-1.1.1.tgz#3a03edc2214bca3b66424a3e7959349509cb0351" + +http-signature@~1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.1.1.tgz#df72e267066cd0ac67fb76adf8e134a8fbcf91bf" + dependencies: + assert-plus "^0.2.0" + jsprim "^1.2.2" + sshpk "^1.7.0" + +https-browserify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82" + +ieee754@^1.1.4: + version "1.1.8" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" + +ignore@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.0.tgz#8d88f03c3002a0ac52114db25d2c673b0bf1e435" + +imurmurhash@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" + +indent-string@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-2.1.0.tgz#8e2d48348742121b4a8218b7a137e9a52049dc80" + dependencies: + repeating "^2.0.0" + +indexof@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-1.0.2.tgz#ca4309dadee6b54cc0b8d247e8d7c7a0975bdc9b" + +inherits@2, inherits@^2.0.1, inherits@~2.0.0, inherits@~2.0.1: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +inherits@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" + +ini@^1.3.4, ini@~1.3.0: + version "1.3.4" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e" + +inline-source-map@~0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/inline-source-map/-/inline-source-map-0.5.0.tgz#4a4c5dd8e4fb5e9b3cda60c822dfadcaee66e0af" + dependencies: + source-map "~0.4.0" + +inline-source-map@~0.6.0: + version "0.6.2" + resolved "https://registry.yarnpkg.com/inline-source-map/-/inline-source-map-0.6.2.tgz#f9393471c18a79d1724f863fa38b586370ade2a5" + dependencies: + source-map "~0.5.3" + +inquirer@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-0.12.0.tgz#1ef2bfd63504df0bc75785fff8c2c41df12f077e" + dependencies: + ansi-escapes "^1.1.0" + ansi-regex "^2.0.0" + chalk "^1.0.0" + cli-cursor "^1.0.1" + cli-width "^2.0.0" + figures "^1.3.5" + lodash "^4.3.0" + readline2 "^1.0.1" + run-async "^0.1.0" + rx-lite "^3.1.2" + string-width "^1.0.1" + strip-ansi "^3.0.0" + through "^2.3.6" + +inquirer@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.0.1.tgz#6dfbffaf4d697dd76c8fe349f919de01c28afc4d" + dependencies: + ansi-escapes "^1.1.0" + chalk "^1.0.0" + cli-cursor "^2.1.0" + cli-width "^2.0.0" + external-editor "^2.0.1" + figures "^2.0.0" + lodash "^4.3.0" + mute-stream "0.0.7" + run-async "^2.2.0" + rx "^4.1.0" + string-width "^2.0.0" + strip-ansi "^3.0.0" + through "^2.3.6" + +insert-module-globals@^7.0.0: + version "7.0.1" + resolved "https://registry.yarnpkg.com/insert-module-globals/-/insert-module-globals-7.0.1.tgz#c03bf4e01cb086d5b5e5ace8ad0afe7889d638c3" + dependencies: + JSONStream "^1.0.3" + combine-source-map "~0.7.1" + concat-stream "~1.5.1" + is-buffer "^1.1.0" + lexical-scope "^1.2.0" + process "~0.11.0" + through2 "^2.0.0" + xtend "^4.0.0" + +interpret@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.1.tgz#d579fb7f693b858004947af39fa0db49f795602c" + +invariant@^2.2.0: + version "2.2.2" + resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" + dependencies: + loose-envify "^1.0.0" + +invert-kv@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" + +is-absolute@^0.2.3: + version "0.2.6" + resolved "https://registry.yarnpkg.com/is-absolute/-/is-absolute-0.2.6.tgz#20de69f3db942ef2d87b9c2da36f172235b1b5eb" + dependencies: + is-relative "^0.2.1" + is-windows "^0.2.0" + +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + +is-binary-path@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" + dependencies: + binary-extensions "^1.0.0" + +is-buffer@^1.0.2, is-buffer@^1.1.0: + version "1.1.4" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.4.tgz#cfc86ccd5dc5a52fa80489111c6920c457e2d98b" + +is-builtin-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" + dependencies: + builtin-modules "^1.0.0" + +is-dotfile@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.2.tgz#2c132383f39199f8edc268ca01b9b007d205cc4d" + +is-equal-shallow@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz#2238098fc221de0bcfa5d9eac4c45d638aa1c534" + dependencies: + is-primitive "^2.0.0" + +is-extendable@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" + +is-extglob@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0" + +is-extglob@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" + +is-finite@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa" + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb" + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + +is-glob@^2.0.0, is-glob@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863" + dependencies: + is-extglob "^1.0.0" + +is-glob@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" + dependencies: + is-extglob "^2.1.0" + +is-my-json-valid@^2.10.0, is-my-json-valid@^2.12.4: + version "2.15.0" + resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.15.0.tgz#936edda3ca3c211fd98f3b2d3e08da43f7b2915b" + dependencies: + generate-function "^2.0.0" + generate-object-property "^1.1.0" + jsonpointer "^4.0.0" + xtend "^4.0.0" + +is-number@^2.0.2, is-number@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" + dependencies: + kind-of "^3.0.2" + +is-path-cwd@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d" + +is-path-in-cwd@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-path-in-cwd/-/is-path-in-cwd-1.0.0.tgz#6477582b8214d602346094567003be8a9eac04dc" + dependencies: + is-path-inside "^1.0.0" + +is-path-inside@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-1.0.0.tgz#fc06e5a1683fbda13de667aff717bbc10a48f37f" + dependencies: + path-is-inside "^1.0.1" + +is-posix-bracket@^0.1.0: + version "0.1.1" + resolved "http://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" + +is-primitive@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" + +is-promise@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" + +is-property@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84" + +is-relative@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-relative/-/is-relative-0.2.1.tgz#d27f4c7d516d175fb610db84bbeef23c3bc97aa5" + dependencies: + is-unc-path "^0.1.1" + +is-resolvable@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.0.0.tgz#8df57c61ea2e3c501408d100fb013cf8d6e0cc62" + dependencies: + tryit "^1.0.1" + +is-typedarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" + +is-unc-path@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/is-unc-path/-/is-unc-path-0.1.2.tgz#6ab053a72573c10250ff416a3814c35178af39b9" + dependencies: + unc-path-regex "^0.1.0" + +is-utf8@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" + +is-windows@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-0.2.0.tgz#de1aa6d63ea29dd248737b69f1ff8b8002d2108c" + +isarray@0.0.1, isarray@~0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + +isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + +isexe@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-1.1.2.tgz#36f3e22e60750920f5e7241a476a8c6a42275ad0" + +isobject@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" + dependencies: + isarray "1.0.0" + +isstream@~0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" + +istanbul-lib-coverage@^1.0.0, istanbul-lib-coverage@^1.0.0-alpha, istanbul-lib-coverage@^1.0.0-alpha.0, istanbul-lib-coverage@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.0.1.tgz#f263efb519c051c5f1f3343034fc40e7b43ff212" + +istanbul-lib-hook@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-1.0.0.tgz#fc5367ee27f59268e8f060b0c7aaf051d9c425c5" + dependencies: + append-transform "^0.4.0" + +istanbul-lib-instrument@^1.1.4, istanbul-lib-instrument@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.4.2.tgz#0e2fdfac93c1dabf2e31578637dc78a19089f43e" + dependencies: + babel-generator "^6.18.0" + babel-template "^6.16.0" + babel-traverse "^6.18.0" + babel-types "^6.18.0" + babylon "^6.13.0" + istanbul-lib-coverage "^1.0.0" + semver "^5.3.0" + +istanbul-lib-report@^1.0.0-alpha.3: + version "1.0.0-alpha.3" + resolved "https://registry.yarnpkg.com/istanbul-lib-report/-/istanbul-lib-report-1.0.0-alpha.3.tgz#32d5f6ec7f33ca3a602209e278b2e6ff143498af" + dependencies: + async "^1.4.2" + istanbul-lib-coverage "^1.0.0-alpha" + mkdirp "^0.5.1" + path-parse "^1.0.5" + rimraf "^2.4.3" + supports-color "^3.1.2" + +istanbul-lib-source-maps@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.1.0.tgz#9d429218f35b823560ea300a96ff0c3bbdab785f" + dependencies: + istanbul-lib-coverage "^1.0.0-alpha.0" + mkdirp "^0.5.1" + rimraf "^2.4.4" + source-map "^0.5.3" + +istanbul-reports@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.0.0.tgz#24b4eb2b1d29d50f103b369bd422f6e640aa0777" + dependencies: + handlebars "^4.0.3" + +jodid25519@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/jodid25519/-/jodid25519-1.0.2.tgz#06d4912255093419477d425633606e0e90782967" + dependencies: + jsbn "~0.1.0" + +js-tokens@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.0.tgz#a2f2a969caae142fb3cd56228358c89366957bd1" + +js-yaml@^3.5.1: + version "3.7.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" + dependencies: + argparse "^1.0.7" + esprima "^2.6.0" + +jsbn@~0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.0.tgz#650987da0dd74f4ebf5a11377a2aa2d273e97dfd" + +jsesc@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" + +jsesc@~0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" + +json-schema@0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" + +json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" + dependencies: + jsonify "~0.0.0" + +json-stable-stringify@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45" + dependencies: + jsonify "~0.0.0" + +json-stringify-safe@~5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + +json3@3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" + +json5@^0.5.0: + version "0.5.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" + +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + +jsonparse@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.0.tgz#85fc245b1d9259acc6941960b905adf64e7de0e8" + +jsonpointer@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9" + +jsprim@^1.2.2: + version "1.3.1" + resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.3.1.tgz#2a7256f70412a29ee3670aaca625994c4dcff252" + dependencies: + extsprintf "1.0.2" + json-schema "0.2.3" + verror "1.3.6" + +kew@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/kew/-/kew-0.7.0.tgz#79d93d2d33363d6fdd2970b335d9141ad591d79b" + +kind-of@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.1.0.tgz#475d698a5e49ff5e53d14e3e732429dc8bf4cf47" + dependencies: + is-buffer "^1.0.2" + +labeled-stream-splicer@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/labeled-stream-splicer/-/labeled-stream-splicer-2.0.0.tgz#a52e1d138024c00b86b1c0c91f677918b8ae0a59" + dependencies: + inherits "^2.0.1" + isarray "~0.0.1" + stream-splicer "^2.0.0" + +lazy-cache@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" + +lcid@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835" + dependencies: + invert-kv "^1.0.0" + +lerna-changelog@^0.2.0: + version "0.2.3" + resolved "https://registry.yarnpkg.com/lerna-changelog/-/lerna-changelog-0.2.3.tgz#f27b33f924f629338e892db895045bccb3873bce" + dependencies: + chalk "^1.1.3" + mkdirp "^0.5.1" + +lerna@^2.0.0-beta.38: + version "2.0.0-beta.38" + resolved "https://registry.yarnpkg.com/lerna/-/lerna-2.0.0-beta.38.tgz#99236416a6699707336dcbdeef83c315d1f71833" + dependencies: + async "^1.5.0" + chalk "^1.1.1" + cmd-shim "^2.0.2" + columnify "^1.5.4" + command-join "^2.0.0" + cross-spawn "^4.0.0" + glob "^7.0.6" + inquirer "^3.0.1" + lodash "^4.17.4" + meow "^3.7.0" + minimatch "^3.0.0" + mkdirp "^0.5.1" + normalize-path "^2.0.1" + object-assign-sorted "^2.0.1" + path-exists "^2.1.0" + progress "^1.1.8" + read-cmd-shim "^1.0.1" + rimraf "^2.4.4" + semver "^5.1.0" + signal-exit "^3.0.2" + +levn@^0.3.0, levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +lexical-scope@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/lexical-scope/-/lexical-scope-1.2.0.tgz#fcea5edc704a4b3a8796cdca419c3a0afaf22df4" + dependencies: + astw "^2.0.0" + +liftoff@^2.1.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/liftoff/-/liftoff-2.3.0.tgz#a98f2ff67183d8ba7cfaca10548bd7ff0550b385" + dependencies: + extend "^3.0.0" + findup-sync "^0.4.2" + fined "^1.0.1" + flagged-respawn "^0.3.2" + lodash.isplainobject "^4.0.4" + lodash.isstring "^4.0.1" + lodash.mapvalues "^4.4.0" + rechoir "^0.6.2" + resolve "^1.1.7" + +load-json-file@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0" + dependencies: + graceful-fs "^4.1.2" + parse-json "^2.2.0" + pify "^2.0.0" + pinkie-promise "^2.0.0" + strip-bom "^2.0.0" + +lodash._baseassign@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" + dependencies: + lodash._basecopy "^3.0.0" + lodash.keys "^3.0.0" + +lodash._basecopy@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" + +lodash._basecreate@^3.0.0: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821" + +lodash._basetostring@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz#d1861d877f824a52f669832dcaf3ee15566a07d5" + +lodash._basevalues@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lodash._basevalues/-/lodash._basevalues-3.0.0.tgz#5b775762802bde3d3297503e26300820fdf661b7" + +lodash._getnative@^3.0.0: + version "3.9.1" + resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" + +lodash._isiterateecall@^3.0.0: + version "3.0.9" + resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c" + +lodash._reescape@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lodash._reescape/-/lodash._reescape-3.0.0.tgz#2b1d6f5dfe07c8a355753e5f27fac7f1cde1616a" + +lodash._reevaluate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lodash._reevaluate/-/lodash._reevaluate-3.0.0.tgz#58bc74c40664953ae0b124d806996daca431e2ed" + +lodash._reinterpolate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" + +lodash._root@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" + +lodash.assignwith@^4.0.7: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.assignwith/-/lodash.assignwith-4.2.0.tgz#127a97f02adc41751a954d24b0de17e100e038eb" + +lodash.create@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/lodash.create/-/lodash.create-3.1.1.tgz#d7f2849f0dbda7e04682bb8cd72ab022461debe7" + dependencies: + lodash._baseassign "^3.0.0" + lodash._basecreate "^3.0.0" + lodash._isiterateecall "^3.0.0" + +lodash.escape@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-3.2.0.tgz#995ee0dc18c1b48cc92effae71a10aab5b487698" + dependencies: + lodash._root "^3.0.0" + +lodash.isarguments@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" + +lodash.isarray@^3.0.0: + version "3.0.4" + resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" + +lodash.isempty@^4.2.1: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" + +lodash.isplainobject@^4.0.4: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + +lodash.keys@^3.0.0: + version "3.1.2" + resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" + dependencies: + lodash._getnative "^3.0.0" + lodash.isarguments "^3.0.0" + lodash.isarray "^3.0.0" + +lodash.mapvalues@^4.4.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.mapvalues/-/lodash.mapvalues-4.6.0.tgz#1bafa5005de9dd6f4f26668c30ca37230cc9689c" + +lodash.memoize@~3.0.3: + version "3.0.4" + resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-3.0.4.tgz#2dcbd2c287cbc0a55cc42328bd0c736150d53e3f" + +lodash.pick@^4.2.1: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" + +lodash.pickby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff" + +lodash.restparam@^3.0.0: + version "3.6.1" + resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" + +lodash.template@^3.0.0: + version "3.6.2" + resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-3.6.2.tgz#f8cdecc6169a255be9098ae8b0c53d378931d14f" + dependencies: + lodash._basecopy "^3.0.0" + lodash._basetostring "^3.0.0" + lodash._basevalues "^3.0.0" + lodash._isiterateecall "^3.0.0" + lodash._reinterpolate "^3.0.0" + lodash.escape "^3.0.0" + lodash.keys "^3.0.0" + lodash.restparam "^3.0.0" + lodash.templatesettings "^3.0.0" + +lodash.templatesettings@^3.0.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-3.1.1.tgz#fb307844753b66b9f1afa54e262c745307dba8e5" + dependencies: + lodash._reinterpolate "^3.0.0" + lodash.escape "^3.0.0" + +lodash@^4.0.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + +lodash@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-1.0.2.tgz#8f57560c83b59fc270bd3d561b690043430e2551" + +longest@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" + +loose-envify@^1.0.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" + dependencies: + js-tokens "^3.0.0" + +loud-rejection@^1.0.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f" + dependencies: + currently-unhandled "^0.4.1" + signal-exit "^3.0.0" + +lru-cache@2: + version "2.7.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952" + +lru-cache@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.0.2.tgz#1d17679c069cda5d040991a09dbc2c0db377e55e" + dependencies: + pseudomap "^1.0.1" + yallist "^2.0.0" + +map-cache@^0.2.0: + version "0.2.2" + resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" + +map-obj@^1.0.0, map-obj@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d" + +md5-hex@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-1.3.0.tgz#d2c4afe983c4370662179b8cad145219135046c4" + dependencies: + md5-o-matic "^0.1.1" + +md5-o-matic@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/md5-o-matic/-/md5-o-matic-0.1.1.tgz#822bccd65e117c514fab176b25945d54100a03c3" + +meow@^3.7.0: + version "3.7.0" + resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb" + dependencies: + camelcase-keys "^2.0.0" + decamelize "^1.1.2" + loud-rejection "^1.0.0" + map-obj "^1.0.1" + minimist "^1.1.3" + normalize-package-data "^2.3.4" + object-assign "^4.0.1" + read-pkg-up "^1.0.1" + redent "^1.0.0" + trim-newlines "^1.0.0" + +merge-source-map@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.0.3.tgz#da1415f2722a5119db07b14c4f973410863a2abf" + dependencies: + source-map "^0.5.3" + +micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7: + version "2.3.11" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" + dependencies: + arr-diff "^2.0.0" + array-unique "^0.2.1" + braces "^1.8.2" + expand-brackets "^0.1.4" + extglob "^0.3.1" + filename-regex "^2.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.1" + kind-of "^3.0.2" + normalize-path "^2.0.1" + object.omit "^2.0.0" + parse-glob "^3.0.4" + regex-cache "^0.4.2" + +miller-rabin@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.0.tgz#4a62fb1d42933c05583982f4c716f6fb9e6c6d3d" + dependencies: + bn.js "^4.0.0" + brorand "^1.0.1" + +mime-db@~1.26.0: + version "1.26.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.26.0.tgz#eaffcd0e4fc6935cf8134da246e2e6c35305adff" + +mime-types@^2.1.12, mime-types@~2.1.7: + version "2.1.14" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.14.tgz#f7ef7d97583fcaf3b7d282b6f8b5679dab1e94ee" + dependencies: + mime-db "~1.26.0" + +mimic-fn@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" + +minimalistic-assert@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" + +minimatch@^2.0.1: + version "2.0.10" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-2.0.10.tgz#8d087c39c6b38c001b97fca7ce6d0e1e80afbac7" + dependencies: + brace-expansion "^1.0.0" + +minimatch@^3.0.0, minimatch@^3.0.2: + version "3.0.3" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" + dependencies: + brace-expansion "^1.0.0" + +minimatch@~0.2.11: + version "0.2.14" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a" + dependencies: + lru-cache "2" + sigmund "~1.0.0" + +minimist@0.0.8, minimist@~0.0.1: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + +mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +mocha@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.2.0.tgz#7dc4f45e5088075171a68896814e6ae9eb7a85e3" + dependencies: + browser-stdout "1.3.0" + commander "2.9.0" + debug "2.2.0" + diff "1.4.0" + escape-string-regexp "1.0.5" + glob "7.0.5" + growl "1.9.2" + json3 "3.3.2" + lodash.create "3.1.1" + mkdirp "0.5.1" + supports-color "3.1.2" + +module-deps@^4.0.8: + version "4.0.8" + resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-4.0.8.tgz#55fd70623399706c3288bef7a609ff1e8c0ed2bb" + dependencies: + JSONStream "^1.0.3" + browser-resolve "^1.7.0" + cached-path-relative "^1.0.0" + concat-stream "~1.5.0" + defined "^1.0.0" + detective "^4.0.0" + duplexer2 "^0.1.2" + inherits "^2.0.1" + parents "^1.0.0" + readable-stream "^2.0.2" + resolve "^1.1.3" + stream-combiner2 "^1.1.1" + subarg "^1.0.0" + through2 "^2.0.0" + xtend "^4.0.0" + +ms@0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" + +ms@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" + +multipipe@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/multipipe/-/multipipe-0.1.2.tgz#2a8f2ddf70eed564dff2d57f1e1a137d9f05078b" + dependencies: + duplexer2 "0.0.2" + +mute-stream@0.0.5: + version "0.0.5" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" + +mute-stream@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" + +nan@^2.3.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.5.0.tgz#aa8f1e34531d807e9e27755b234b4a6ec0c152a8" + +natives@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/natives/-/natives-1.1.0.tgz#e9ff841418a6b2ec7a495e939984f78f163e6e31" + +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + +node-pre-gyp@^0.6.29: + version "0.6.32" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.32.tgz#fc452b376e7319b3d255f5f34853ef6fd8fe1fd5" + dependencies: + mkdirp "~0.5.1" + nopt "~3.0.6" + npmlog "^4.0.1" + rc "~1.1.6" + request "^2.79.0" + rimraf "~2.5.4" + semver "~5.3.0" + tar "~2.2.1" + tar-pack "~3.3.0" + +nopt@~3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9" + dependencies: + abbrev "1" + +normalize-package-data@^2.3.2, normalize-package-data@^2.3.4: + version "2.3.5" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.3.5.tgz#8d924f142960e1777e7ffe170543631cc7cb02df" + dependencies: + hosted-git-info "^2.1.4" + is-builtin-module "^1.0.0" + semver "2 || 3 || 4 || 5" + validate-npm-package-license "^3.0.1" + +normalize-path@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.0.1.tgz#47886ac1662760d4261b7d979d241709d3ce3f7a" + +npmlog@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.0.2.tgz#d03950e0e78ce1527ba26d2a7592e9348ac3e75f" + dependencies: + are-we-there-yet "~1.1.2" + console-control-strings "~1.1.0" + gauge "~2.7.1" + set-blocking "~2.0.0" + +number-is-nan@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" + +nyc@^10.0.0: + version "10.1.2" + resolved "https://registry.yarnpkg.com/nyc/-/nyc-10.1.2.tgz#ea7acaa20a235210101604f4e7d56d28453b0274" + dependencies: + archy "^1.0.0" + arrify "^1.0.1" + caching-transform "^1.0.0" + convert-source-map "^1.3.0" + debug-log "^1.0.1" + default-require-extensions "^1.0.0" + find-cache-dir "^0.1.1" + find-up "^1.1.2" + foreground-child "^1.5.3" + glob "^7.0.6" + istanbul-lib-coverage "^1.0.1" + istanbul-lib-hook "^1.0.0" + istanbul-lib-instrument "^1.4.2" + istanbul-lib-report "^1.0.0-alpha.3" + istanbul-lib-source-maps "^1.1.0" + istanbul-reports "^1.0.0" + md5-hex "^1.2.0" + merge-source-map "^1.0.2" + micromatch "^2.3.11" + mkdirp "^0.5.0" + resolve-from "^2.0.0" + rimraf "^2.5.4" + signal-exit "^3.0.1" + spawn-wrap "1.2.4" + test-exclude "^3.3.0" + yargs "^6.6.0" + yargs-parser "^4.0.2" + +oauth-sign@~0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" + +object-assign-sorted@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/object-assign-sorted/-/object-assign-sorted-2.0.1.tgz#c9983fa9e3ed5807b49cf1a9943378f245d9395b" + dependencies: + sorted-object "^2.0.0" + +object-assign@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2" + +object-assign@^4.0.1, object-assign@^4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + +object-keys@^1.0.6: + version "1.0.11" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" + +object.omit@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" + dependencies: + for-own "^0.1.4" + is-extendable "^0.1.1" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +once@~1.3.0, once@~1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/once/-/once-1.3.3.tgz#b2e261557ce4c314ec8304f3fa82663e4297ca20" + dependencies: + wrappy "1" + +onetime@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789" + +onetime@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.0.tgz#52aa8110e52fc5126ffc667bd8ec21c2ed209ce6" + dependencies: + mimic-fn "^1.0.0" + +optimist@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" + dependencies: + minimist "~0.0.1" + wordwrap "~0.0.2" + +optionator@^0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +orchestrator@^0.3.0: + version "0.3.8" + resolved "https://registry.yarnpkg.com/orchestrator/-/orchestrator-0.3.8.tgz#14e7e9e2764f7315fbac184e506c7aa6df94ad7e" + dependencies: + end-of-stream "~0.1.5" + sequencify "~0.0.7" + stream-consume "~0.1.0" + +ordered-read-streams@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/ordered-read-streams/-/ordered-read-streams-0.1.0.tgz#fd565a9af8eb4473ba69b6ed8a34352cb552f126" + +os-browserify@~0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.1.2.tgz#49ca0293e0b19590a5f5de10c7f265a617d8fe54" + +os-homedir@^1.0.0, os-homedir@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" + +os-locale@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-1.4.0.tgz#20f9f17ae29ed345e8bde583b13d2009803c14d9" + dependencies: + lcid "^1.0.0" + +os-tmpdir@^1.0.1, os-tmpdir@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + +output-file-sync@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-1.1.2.tgz#d0a33eefe61a205facb90092e826598d5245ce76" + dependencies: + graceful-fs "^4.1.4" + mkdirp "^0.5.1" + object-assign "^4.1.0" + +pako@~0.2.0: + version "0.2.9" + resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" + +parents@^1.0.0, parents@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parents/-/parents-1.0.1.tgz#fedd4d2bf193a77745fe71e371d73c3307d9c751" + dependencies: + path-platform "~0.11.15" + +parse-asn1@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.0.0.tgz#35060f6d5015d37628c770f4e091a0b5a278bc23" + dependencies: + asn1.js "^4.0.0" + browserify-aes "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.0" + pbkdf2 "^3.0.3" + +parse-filepath@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parse-filepath/-/parse-filepath-1.0.1.tgz#159d6155d43904d16c10ef698911da1e91969b73" + dependencies: + is-absolute "^0.2.3" + map-cache "^0.2.0" + path-root "^0.1.1" + +parse-glob@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c" + dependencies: + glob-base "^0.3.0" + is-dotfile "^1.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.0" + +parse-json@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" + dependencies: + error-ex "^1.2.0" + +parse-passwd@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" + +path-browserify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a" + +path-dirname@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" + +path-exists@^2.0.0, path-exists@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b" + dependencies: + pinkie-promise "^2.0.0" + +path-is-absolute@^1.0.0, path-is-absolute@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +path-is-inside@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" + +path-parse@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" + +path-platform@~0.11.15: + version "0.11.15" + resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2" + +path-root-regex@^0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/path-root-regex/-/path-root-regex-0.1.2.tgz#bfccdc8df5b12dc52c8b43ec38d18d72c04ba96d" + +path-root@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/path-root/-/path-root-0.1.1.tgz#9a4a6814cac1c0cd73360a95f32083c8ea4745b7" + dependencies: + path-root-regex "^0.1.0" + +path-type@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" + dependencies: + graceful-fs "^4.1.2" + pify "^2.0.0" + pinkie-promise "^2.0.0" + +pbkdf2@^3.0.3: + version "3.0.9" + resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.9.tgz#f2c4b25a600058b3c3773c086c37dbbee1ffe693" + dependencies: + create-hmac "^1.1.2" + +pify@^2.0.0, pify@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" + +pinkie-promise@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" + dependencies: + pinkie "^2.0.0" + +pinkie@^2.0.0: + version "2.0.4" + resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" + +pkg-dir@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4" + dependencies: + find-up "^1.0.0" + +pluralize@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45" + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + +preserve@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" + +pretty-hrtime@^1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1" + +private@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/private/-/private-0.1.6.tgz#55c6a976d0f9bafb9924851350fe47b9b5fbb7c1" + +process-nextick-args@~1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" + +process@~0.11.0: + version "0.11.9" + resolved "https://registry.yarnpkg.com/process/-/process-0.11.9.tgz#7bd5ad21aa6253e7da8682264f1e11d11c0318c1" + +progress@^1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be" + +pseudomap@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + +public-encrypt@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/public-encrypt/-/public-encrypt-4.0.0.tgz#39f699f3a46560dd5ebacbca693caf7c65c18cc6" + dependencies: + bn.js "^4.1.0" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + parse-asn1 "^5.0.0" + randombytes "^2.0.1" + +punycode@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" + +punycode@^1.3.2, punycode@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" + +qs@~6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.3.0.tgz#f403b264f23bc01228c74131b407f18d5ea5d442" + +querystring-es3@~0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" + +querystring@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" + +randomatic@^1.1.3: + version "1.1.6" + resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.6.tgz#110dcabff397e9dcff7c0789ccc0a49adf1ec5bb" + dependencies: + is-number "^2.0.2" + kind-of "^3.0.2" + +randombytes@^2.0.0, randombytes@^2.0.1: + version "2.0.3" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.3.tgz#674c99760901c3c4112771a31e521dc349cc09ec" + +rc@~1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.1.6.tgz#43651b76b6ae53b5c802f1151fa3fc3b059969c9" + dependencies: + deep-extend "~0.4.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~1.0.4" + +read-cmd-shim@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/read-cmd-shim/-/read-cmd-shim-1.0.1.tgz#2d5d157786a37c055d22077c32c53f8329e91c7b" + dependencies: + graceful-fs "^4.1.2" + +read-only-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/read-only-stream/-/read-only-stream-2.0.0.tgz#2724fd6a8113d73764ac288d4386270c1dbf17f0" + dependencies: + readable-stream "^2.0.2" + +read-pkg-up@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" + dependencies: + find-up "^1.0.0" + read-pkg "^1.0.0" + +read-pkg@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-1.1.0.tgz#f5ffaa5ecd29cb31c0474bca7d756b6bb29e3f28" + dependencies: + load-json-file "^1.0.0" + normalize-package-data "^2.3.2" + path-type "^1.0.0" + +"readable-stream@>=1.0.33-1 <1.1.0-0": + version "1.0.34" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +"readable-stream@>=1.1.13-1 <1.2.0-0", readable-stream@~1.1.9: + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@^2.1.0, readable-stream@^2.1.5, readable-stream@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.2.tgz#a9e6fec3c7dda85f8bb1b3ba7028604556fc825e" + dependencies: + buffer-shims "^1.0.0" + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + string_decoder "~0.10.x" + util-deprecate "~1.0.1" + +readable-stream@~2.0.0: + version "2.0.6" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + string_decoder "~0.10.x" + util-deprecate "~1.0.1" + +readable-stream@~2.1.4: + version "2.1.5" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.1.5.tgz#66fa8b720e1438b364681f2ad1a63c618448c9d0" + dependencies: + buffer-shims "^1.0.0" + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + string_decoder "~0.10.x" + util-deprecate "~1.0.1" + +readdirp@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.1.0.tgz#4ed0ad060df3073300c48440373f72d1cc642d78" + dependencies: + graceful-fs "^4.1.2" + minimatch "^3.0.2" + readable-stream "^2.0.2" + set-immediate-shim "^1.0.1" + +readline2@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/readline2/-/readline2-1.0.1.tgz#41059608ffc154757b715d9989d199ffbf372e35" + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + mute-stream "0.0.5" + +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + dependencies: + resolve "^1.1.6" + +redent@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" + dependencies: + indent-string "^2.1.0" + strip-indent "^1.0.1" + +regenerate@^1.2.1: + version "1.3.2" + resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.2.tgz#d1941c67bad437e1be76433add5b385f95b19260" + +regenerator-runtime@^0.10.0: + version "0.10.1" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.1.tgz#257f41961ce44558b18f7814af48c17559f9faeb" + +regenerator-transform@0.9.8: + version "0.9.8" + resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.9.8.tgz#0f88bb2bc03932ddb7b6b7312e68078f01026d6c" + dependencies: + babel-runtime "^6.18.0" + babel-types "^6.19.0" + private "^0.1.6" + +regex-cache@^0.4.2: + version "0.4.3" + resolved "http://registry.npmjs.org/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145" + dependencies: + is-equal-shallow "^0.1.3" + is-primitive "^2.0.0" + +regexpu-core@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" + dependencies: + regenerate "^1.2.1" + regjsgen "^0.2.0" + regjsparser "^0.1.4" + +regjsgen@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" + +regjsparser@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" + dependencies: + jsesc "~0.5.0" + +repeat-element@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" + +repeat-string@^1.5.2: + version "1.6.1" + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" + +repeating@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda" + dependencies: + is-finite "^1.0.0" + +replace-ext@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-0.0.1.tgz#29bbd92078a739f0bcce2b4ee41e837953522924" + +request@>=2.42.0, request@^2.79.0: + version "2.79.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de" + dependencies: + aws-sign2 "~0.6.0" + aws4 "^1.2.1" + caseless "~0.11.0" + combined-stream "~1.0.5" + extend "~3.0.0" + forever-agent "~0.6.1" + form-data "~2.1.1" + har-validator "~2.0.6" + hawk "~3.1.3" + http-signature "~1.1.0" + is-typedarray "~1.0.0" + isstream "~0.1.2" + json-stringify-safe "~5.0.1" + mime-types "~2.1.7" + oauth-sign "~0.8.1" + qs "~6.3.0" + stringstream "~0.0.4" + tough-cookie "~2.3.0" + tunnel-agent "~0.4.1" + uuid "^3.0.0" + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + +require-main-filename@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" + +require-uncached@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" + dependencies: + caller-path "^0.1.0" + resolve-from "^1.0.0" + +resolve-dir@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-0.1.1.tgz#b219259a5602fac5c5c496ad894a6e8cc430261e" + dependencies: + expand-tilde "^1.2.2" + global-modules "^0.2.3" + +resolve-from@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" + +resolve-from@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57" + +resolve@1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" + +resolve@^1.1.3, resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7: + version "1.2.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c" + +restore-cursor@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" + dependencies: + exit-hook "^1.0.0" + onetime "^1.0.0" + +restore-cursor@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" + dependencies: + onetime "^2.0.0" + signal-exit "^3.0.2" + +right-align@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef" + dependencies: + align-text "^0.1.1" + +rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@~2.5.1, rimraf@~2.5.4: + version "2.5.4" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" + dependencies: + glob "^7.0.5" + +rimraf@~2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.1.4.tgz#5a6eb62eeda068f51ede50f29b3e5cd22f3d9bb2" + optionalDependencies: + graceful-fs "~1" + +ripemd160@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-1.0.1.tgz#93a4bbd4942bc574b69a8fa57c71de10ecca7d6e" + +run-async@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-0.1.0.tgz#c8ad4a5e110661e402a7d21b530e009f25f8e389" + dependencies: + once "^1.3.0" + +run-async@^2.2.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0" + dependencies: + is-promise "^2.1.0" + +rx-lite@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102" + +rx@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782" + +"semver@2 || 3 || 4 || 5", semver@^5.0.0, semver@^5.1.0, semver@^5.3.0, semver@~5.3.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" + +semver@^4.1.0: + version "4.3.6" + resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da" + +sequencify@~0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/sequencify/-/sequencify-0.0.7.tgz#90cff19d02e07027fd767f5ead3e7b95d1e7380c" + +set-blocking@^2.0.0, set-blocking@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" + +set-immediate-shim@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61" + +sha.js@^2.3.6, sha.js@~2.4.4: + version "2.4.8" + resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.8.tgz#37068c2c476b6baf402d14a49c67f597921f634f" + dependencies: + inherits "^2.0.1" + +shasum@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/shasum/-/shasum-1.0.2.tgz#e7012310d8f417f4deb5712150e5678b87ae565f" + dependencies: + json-stable-stringify "~0.0.0" + sha.js "~2.4.4" + +shell-quote@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767" + dependencies: + array-filter "~0.0.0" + array-map "~0.0.0" + array-reduce "~0.0.0" + jsonify "~0.0.0" + +shelljs@^0.7.5: + version "0.7.6" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad" + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + +sigmund@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" + +signal-exit@^2.0.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-2.1.2.tgz#375879b1f92ebc3b334480d038dc546a6d558564" + +signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + +slash@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" + +slice-ansi@0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35" + +slide@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" + +sntp@1.x.x: + version "1.0.9" + resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" + dependencies: + hoek "2.x.x" + +sorted-object@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/sorted-object/-/sorted-object-2.0.1.tgz#7d631f4bd3a798a24af1dffcfbfe83337a5df5fc" + +source-map-support@^0.4.2: + version "0.4.10" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.10.tgz#d7b19038040a14c0837a18e630a196453952b378" + dependencies: + source-map "^0.5.3" + +source-map@^0.4.4, source-map@~0.4.0, source-map@~0.4.2: + version "0.4.4" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" + dependencies: + amdefine ">=0.0.4" + +source-map@^0.5.0, source-map@^0.5.1, source-map@^0.5.3, source-map@~0.5.1, source-map@~0.5.3: + version "0.5.6" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" + +sparkles@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/sparkles/-/sparkles-1.0.0.tgz#1acbbfb592436d10bbe8f785b7cc6f82815012c3" + +spawn-wrap@1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.2.4.tgz#920eb211a769c093eebfbd5b0e7a5d2e68ab2e40" + dependencies: + foreground-child "^1.3.3" + mkdirp "^0.5.0" + os-homedir "^1.0.1" + rimraf "^2.3.3" + signal-exit "^2.0.0" + which "^1.2.4" + +spdx-correct@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-1.0.2.tgz#4b3073d933ff51f3912f03ac5519498a4150db40" + dependencies: + spdx-license-ids "^1.0.2" + +spdx-expression-parse@~1.0.0: + version "1.0.4" + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-1.0.4.tgz#9bdf2f20e1f40ed447fbe273266191fced51626c" + +spdx-license-ids@^1.0.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57" + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + +sshpk@^1.7.0: + version "1.10.2" + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.10.2.tgz#d5a804ce22695515638e798dbe23273de070a5fa" + dependencies: + asn1 "~0.2.3" + assert-plus "^1.0.0" + dashdash "^1.12.0" + getpass "^0.1.1" + optionalDependencies: + bcrypt-pbkdf "^1.0.0" + ecc-jsbn "~0.1.1" + jodid25519 "^1.0.0" + jsbn "~0.1.0" + tweetnacl "~0.14.0" + +stream-browserify@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db" + dependencies: + inherits "~2.0.1" + readable-stream "^2.0.2" + +stream-combiner2@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/stream-combiner2/-/stream-combiner2-1.1.1.tgz#fb4d8a1420ea362764e21ad4780397bebcb41cbe" + dependencies: + duplexer2 "~0.1.0" + readable-stream "^2.0.2" + +stream-consume@~0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/stream-consume/-/stream-consume-0.1.0.tgz#a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f" + +stream-http@^2.0.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.6.3.tgz#4c3ddbf9635968ea2cfd4e48d43de5def2625ac3" + dependencies: + builtin-status-codes "^3.0.0" + inherits "^2.0.1" + readable-stream "^2.1.0" + to-arraybuffer "^1.0.0" + xtend "^4.0.0" + +stream-splicer@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/stream-splicer/-/stream-splicer-2.0.0.tgz#1b63be438a133e4b671cc1935197600175910d83" + dependencies: + inherits "^2.0.1" + readable-stream "^2.0.2" + +string-width@^1.0.1, string-width@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +string-width@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.0.0.tgz#635c5436cc72a6e0c387ceca278d4e2eec52687e" + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^3.0.0" + +string_decoder@~0.10.0, string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + +stringstream@~0.0.4: + version "0.0.5" + resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" + +strip-ansi@^3.0.0, strip-ansi@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + dependencies: + ansi-regex "^2.0.0" + +strip-bom-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strip-bom-stream/-/strip-bom-stream-2.0.0.tgz#f87db5ef2613f6968aa545abfe1ec728b6a829ca" + dependencies: + first-chunk-stream "^2.0.0" + strip-bom "^2.0.0" + +strip-bom@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-1.0.0.tgz#85b8862f3844b5a6d5ec8467a93598173a36f794" + dependencies: + first-chunk-stream "^1.0.0" + is-utf8 "^0.2.0" + +strip-bom@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e" + dependencies: + is-utf8 "^0.2.0" + +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + +strip-indent@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2" + dependencies: + get-stdin "^4.0.1" + +strip-json-comments@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" + +strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + +subarg@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" + dependencies: + minimist "^1.1.0" + +supports-color@3.1.2, supports-color@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5" + dependencies: + has-flag "^1.0.0" + +supports-color@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-0.2.0.tgz#d92de2694eb3f67323973d7ae3d8b55b4c22190a" + +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + +syntax-error@^1.1.1: + version "1.1.6" + resolved "https://registry.yarnpkg.com/syntax-error/-/syntax-error-1.1.6.tgz#b4549706d386cc1c1dc7c2423f18579b6cade710" + dependencies: + acorn "^2.7.0" + +table@^3.7.8: + version "3.8.3" + resolved "https://registry.yarnpkg.com/table/-/table-3.8.3.tgz#2bbc542f0fda9861a755d3947fefd8b3f513855f" + dependencies: + ajv "^4.7.0" + ajv-keywords "^1.0.0" + chalk "^1.1.1" + lodash "^4.0.0" + slice-ansi "0.0.4" + string-width "^2.0.0" + +tar-pack@~3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/tar-pack/-/tar-pack-3.3.0.tgz#30931816418f55afc4d21775afdd6720cee45dae" + dependencies: + debug "~2.2.0" + fstream "~1.0.10" + fstream-ignore "~1.0.5" + once "~1.3.3" + readable-stream "~2.1.4" + rimraf "~2.5.1" + tar "~2.2.1" + uid-number "~0.0.6" + +tar@~2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/tar/-/tar-2.2.1.tgz#8e4d2a256c0e2185c6b18ad694aec968b83cb1d1" + dependencies: + block-stream "*" + fstream "^1.0.2" + inherits "2" + +temp@~0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/temp/-/temp-0.5.1.tgz#77ab19c79aa7b593cbe4fac2441768cad987b8df" + dependencies: + rimraf "~2.1.4" + +test-exclude@^2.1.1: + version "2.1.3" + resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-2.1.3.tgz#a8d8968e1da83266f9864f2852c55e220f06434a" + dependencies: + arrify "^1.0.1" + micromatch "^2.3.11" + object-assign "^4.1.0" + read-pkg-up "^1.0.1" + require-main-filename "^1.0.1" + +test-exclude@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-3.3.0.tgz#7a17ca1239988c98367b0621456dbb7d4bc38977" + dependencies: + arrify "^1.0.1" + micromatch "^2.3.11" + object-assign "^4.1.0" + read-pkg-up "^1.0.1" + require-main-filename "^1.0.1" + +text-table@~0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" + +through2@^0.6.1: + version "0.6.5" + resolved "https://registry.yarnpkg.com/through2/-/through2-0.6.5.tgz#41ab9c67b29d57209071410e1d7a7a968cd3ad48" + dependencies: + readable-stream ">=1.0.33-1 <1.1.0-0" + xtend ">=4.0.0 <4.1.0-0" + +through2@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/through2/-/through2-1.1.1.tgz#0847cbc4449f3405574dbdccd9bb841b83ac3545" + dependencies: + readable-stream ">=1.1.13-1 <1.2.0-0" + xtend ">=4.0.0 <4.1.0-0" + +through2@^2, through2@^2.0.0: + version "2.0.3" + resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be" + dependencies: + readable-stream "^2.1.5" + xtend "~4.0.1" + +"through@>=2.2.7 <3", through@^2.3.6: + version "2.3.8" + resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" + +tildify@^1.0.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/tildify/-/tildify-1.2.0.tgz#dcec03f55dca9b7aa3e5b04f21817eb56e63588a" + dependencies: + os-homedir "^1.0.0" + +time-stamp@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-1.0.1.tgz#9f4bd23559c9365966f3302dbba2b07c6b99b151" + +timers-browserify@^1.0.1: + version "1.4.2" + resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-1.4.2.tgz#c9c58b575be8407375cb5e2462dacee74359f41d" + dependencies: + process "~0.11.0" + +tmp@^0.0.31: + version "0.0.31" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7" + dependencies: + os-tmpdir "~1.0.1" + +to-arraybuffer@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" + +to-fast-properties@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320" + +tough-cookie@~2.3.0: + version "2.3.2" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a" + dependencies: + punycode "^1.4.1" + +trim-newlines@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613" + +tryit@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb" + +tty-browserify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" + +tunnel-agent@~0.4.1: + version "0.4.3" + resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" + +tweetnacl@^0.14.3, tweetnacl@~0.14.0: + version "0.14.5" + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + dependencies: + prelude-ls "~1.1.2" + +type-detect@0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-0.1.1.tgz#0ba5ec2a885640e470ea4e8505971900dac58822" + +type-detect@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2" + +typedarray@~0.0.5: + version "0.0.6" + resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" + +uglify-js@^2.4.16, uglify-js@^2.6: + version "2.7.5" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8" + dependencies: + async "~0.2.6" + source-map "~0.5.1" + uglify-to-browserify "~1.0.0" + yargs "~3.10.0" + +uglify-to-browserify@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" + +uid-number@~0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" + +umd@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/umd/-/umd-3.0.1.tgz#8ae556e11011f63c2596708a8837259f01b3d60e" + +unc-path-regex@^0.1.0: + version "0.1.2" + resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa" + +unique-stream@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unique-stream/-/unique-stream-1.0.0.tgz#d59a4a75427447d9aa6c91e70263f8d26a4b104b" + +url@~0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" + dependencies: + punycode "1.3.2" + querystring "0.2.0" + +urlgrey@>=0.4.0: + version "0.4.4" + resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f" + +user-home@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190" + +user-home@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/user-home/-/user-home-2.0.0.tgz#9c70bfd8169bc1dcbf48604e0f04b8b49cde9e9f" + dependencies: + os-homedir "^1.0.0" + +util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + +util@0.10.3, util@~0.10.1: + version "0.10.3" + resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" + dependencies: + inherits "2.0.1" + +uuid@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" + +v8flags@^2.0.2: + version "2.0.11" + resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.0.11.tgz#bca8f30f0d6d60612cc2c00641e6962d42ae6881" + dependencies: + user-home "^1.1.1" + +validate-npm-package-license@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" + dependencies: + spdx-correct "~1.0.0" + spdx-expression-parse "~1.0.0" + +verror@1.3.6: + version "1.3.6" + resolved "https://registry.yarnpkg.com/verror/-/verror-1.3.6.tgz#cff5df12946d297d2baaefaa2689e25be01c005c" + dependencies: + extsprintf "1.0.2" + +vinyl-file@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/vinyl-file/-/vinyl-file-2.0.0.tgz#a7ebf5ffbefda1b7d18d140fcb07b223efb6751a" + dependencies: + graceful-fs "^4.1.2" + pify "^2.3.0" + pinkie-promise "^2.0.0" + strip-bom "^2.0.0" + strip-bom-stream "^2.0.0" + vinyl "^1.1.0" + +vinyl-fs@^0.3.0: + version "0.3.14" + resolved "https://registry.yarnpkg.com/vinyl-fs/-/vinyl-fs-0.3.14.tgz#9a6851ce1cac1c1cea5fe86c0931d620c2cfa9e6" + dependencies: + defaults "^1.0.0" + glob-stream "^3.1.5" + glob-watcher "^0.0.6" + graceful-fs "^3.0.0" + mkdirp "^0.5.0" + strip-bom "^1.0.0" + through2 "^0.6.1" + vinyl "^0.4.0" + +vinyl-sourcemaps-apply@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz#ab6549d61d172c2b1b87be5c508d239c8ef87705" + dependencies: + source-map "^0.5.1" + +vinyl@^0.4.0: + version "0.4.6" + resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.4.6.tgz#2f356c87a550a255461f36bbeb2a5ba8bf784847" + dependencies: + clone "^0.2.0" + clone-stats "^0.0.1" + +vinyl@^0.5.0: + version "0.5.3" + resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.5.3.tgz#b0455b38fc5e0cf30d4325132e461970c2091cde" + dependencies: + clone "^1.0.0" + clone-stats "^0.0.1" + replace-ext "0.0.1" + +vinyl@^1.1.0, vinyl@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-1.2.0.tgz#5c88036cf565e5df05558bfc911f8656df218884" + dependencies: + clone "^1.0.0" + clone-stats "^0.0.1" + replace-ext "0.0.1" + +vm-browserify@~0.0.1: + version "0.0.4" + resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73" + dependencies: + indexof "0.0.1" + +wcwidth@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" + dependencies: + defaults "^1.0.3" + +which-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/which-module/-/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f" + +which@^1.2.12, which@^1.2.4, which@^1.2.9: + version "1.2.12" + resolved "https://registry.yarnpkg.com/which/-/which-1.2.12.tgz#de67b5e450269f194909ef23ece4ebe416fa1192" + dependencies: + isexe "^1.1.1" + +wide-align@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.0.tgz#40edde802a71fea1f070da3e62dcda2e7add96ad" + dependencies: + string-width "^1.0.1" + +window-size@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" + +wordwrap@0.0.2, wordwrap@~0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + +wrap-ansi@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + +write-file-atomic@^1.1.4: + version "1.3.1" + resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-1.3.1.tgz#7d45ba32316328dd1ec7d90f60ebc0d845bb759a" + dependencies: + graceful-fs "^4.1.11" + imurmurhash "^0.1.4" + slide "^1.1.5" + +write@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/write/-/write-0.2.1.tgz#5fc03828e264cea3fe91455476f7a3c566cb0757" + dependencies: + mkdirp "^0.5.1" + +"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0, xtend@~4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" + +y18n@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" + +yallist@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.0.0.tgz#306c543835f09ee1a4cb23b7bce9ab341c91cdd4" + +yargs-parser@^4.0.2, yargs-parser@^4.2.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c" + dependencies: + camelcase "^3.0.0" + +yargs@^6.5.0, yargs@^6.6.0: + version "6.6.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208" + dependencies: + camelcase "^3.0.0" + cliui "^3.2.0" + decamelize "^1.1.1" + get-caller-file "^1.0.1" + os-locale "^1.4.0" + read-pkg-up "^1.0.1" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^1.0.2" + which-module "^1.0.0" + y18n "^3.2.1" + yargs-parser "^4.2.0" + +yargs@~3.10.0: + version "3.10.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1" + dependencies: + camelcase "^1.0.2" + cliui "^2.1.0" + decamelize "^1.0.0" + window-size "0.1.0"