Merge branch 'master' into merge-master

# Conflicts:
#	lerna.json
#	packages/babel-cli/package.json
#	packages/babel-core/package.json
#	packages/babel-generator/package.json
#	packages/babel-helper-builder-react-jsx/package.json
#	packages/babel-helper-function-name/package.json
#	packages/babel-helper-optimise-call-expression/package.json
#	packages/babel-helper-replace-supers/package.json
#	packages/babel-helper-transform-fixture-test-runner/package.json
#	packages/babel-helpers/package.json
#	packages/babel-plugin-transform-class-properties/package.json
#	packages/babel-plugin-transform-es2015-block-scoping/package.json
#	packages/babel-plugin-transform-es2015-classes/package.json
#	packages/babel-plugin-transform-es2015-modules-commonjs/package.json
#	packages/babel-plugin-transform-es2015-modules-systemjs/package.json
#	packages/babel-plugin-transform-es2015-modules-umd/package.json
#	packages/babel-plugin-transform-es2015-parameters/package.json
#	packages/babel-plugin-transform-react-jsx/package.json
#	packages/babel-register/package.json
#	packages/babel-template/package.json
#	packages/babel-traverse/package.json
#	packages/babel/package.json
This commit is contained in:
Daniel Tschinder 2017-02-14 12:46:11 +01:00
commit 6c03cb0783
No known key found for this signature in database
GPG Key ID: 46A883CAEC8A94BD
87 changed files with 830 additions and 256 deletions

View File

@ -1,5 +1,11 @@
{
"userBlacklist": [ "amasad", "thejameskyle", "jmm", "kittens" ],
"userBlacklist": [
"amasad",
"greenkeeperio-bot",
"jmm",
"kittens",
"thejameskyle"
],
"fileBlacklist": ["*.md"],
"skipAlreadyAssignedPR": true,
"createReviewRequest": true

View File

@ -13,6 +13,96 @@ _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

View File

@ -1,6 +1,6 @@
{
"name": "babel-cli",
"version": "6.22.2",
"version": "6.23.0",
"description": "Babel command line.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -16,9 +16,9 @@
"compiler"
],
"dependencies": {
"babel-core": "^6.22.1",
"babel-register": "^6.22.0",
"babel-polyfill": "^6.22.0",
"babel-core": "^6.23.0",
"babel-register": "^6.23.0",
"babel-polyfill": "^6.23.0",
"commander": "^2.8.1",
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "babel-core",
"version": "6.22.1",
"version": "6.23.1",
"description": "Babel compiler core.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -27,13 +27,13 @@
},
"dependencies": {
"babel-code-frame": "^6.22.0",
"babel-generator": "^6.22.0",
"babel-helpers": "^6.22.0",
"babel-messages": "^6.22.0",
"babel-template": "^6.22.0",
"babel-register": "^6.22.0",
"babel-traverse": "^6.22.1",
"babel-types": "^6.22.0",
"babel-generator": "^6.23.0",
"babel-helpers": "^6.23.0",
"babel-messages": "^6.23.0",
"babel-template": "^6.23.0",
"babel-register": "^6.23.0",
"babel-traverse": "^6.23.1",
"babel-types": "^6.23.0",
"babylon": "^6.11.0",
"convert-source-map": "^1.1.0",
"debug": "^2.1.1",
@ -46,7 +46,7 @@
},
"devDependencies": {
"babel-helper-fixtures": "^6.22.0",
"babel-helper-transform-fixture-test-runner": "^6.22.0",
"babel-polyfill": "^6.22.0"
"babel-helper-transform-fixture-test-runner": "^6.23.0",
"babel-polyfill": "^6.23.0"
}
}

View File

@ -1,6 +1,6 @@
function wrapper(fn) {
return (...args) => {
if (someCondition) {
while (someCondition) {
const val = fn(...args);
return val.test(() => {
console.log(val);

View File

@ -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;
}
};
}
}

View File

@ -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

View File

@ -1,6 +1,6 @@
{
"name": "babel-generator",
"version": "6.22.0",
"version": "6.23.0",
"description": "Turns an AST into code.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -11,9 +11,9 @@
"lib"
],
"dependencies": {
"babel-messages": "^6.22.0",
"babel-types": "^6.22.0",
"detect-indent": "^5.0.0",
"babel-messages": "^6.23.0",
"babel-types": "^6.23.0",
"detect-indent": "^4.0.0",
"jsesc": "^1.3.0",
"lodash": "^4.2.0",
"source-map": "^0.5.0",

View File

@ -1,12 +1,12 @@
{
"name": "babel-helper-builder-react-jsx",
"version": "6.22.0",
"version": "6.23.0",
"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-types": "^6.22.0",
"babel-types": "^6.23.0",
"esutils": "^2.0.0",
"lodash": "^4.2.0"
}

View File

@ -1,13 +1,13 @@
{
"name": "babel-helper-define-map",
"version": "6.22.0",
"version": "6.23.0",
"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": {
"lodash": "^4.2.0",
"babel-types": "^6.22.0",
"babel-helper-function-name": "^6.22.0"
"babel-types": "^6.23.0",
"babel-helper-function-name": "^6.23.0"
}
}

View File

@ -1,14 +1,14 @@
{
"name": "babel-helper-function-name",
"version": "6.22.0",
"version": "6.23.0",
"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-types": "^6.22.0",
"babel-traverse": "^6.22.0",
"babel-types": "^6.23.0",
"babel-traverse": "^6.23.0",
"babel-helper-get-function-arity": "^6.22.0",
"babel-template": "^6.22.0"
"babel-template": "^6.23.0"
}
}

View File

@ -1,11 +1,11 @@
{
"name": "babel-helper-optimise-call-expression",
"version": "6.22.0",
"version": "6.23.0",
"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-types": "^6.22.0"
"babel-types": "^6.23.0"
}
}

View File

@ -1,15 +1,15 @@
{
"name": "babel-helper-replace-supers",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-traverse": "^6.22.0",
"babel-messages": "^6.22.0",
"babel-template": "^6.22.0",
"babel-types": "^6.22.0"
"babel-helper-optimise-call-expression": "^6.23.0",
"babel-traverse": "^6.23.0",
"babel-messages": "^6.23.0",
"babel-template": "^6.23.0",
"babel-types": "^6.23.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "babel-helper-transform-fixture-test-runner",
"version": "6.22.0",
"version": "6.23.0",
"description": "Transform test runner for babel-helper-fixtures module",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -8,8 +8,8 @@
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner",
"main": "lib/index.js",
"dependencies": {
"babel-core": "^6.22.0",
"babel-polyfill": "^6.22.0",
"babel-core": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-helper-fixtures": "^6.22.0",
"source-map": "^0.5.0",
"babel-code-frame": "^6.22.0",

View File

@ -1,6 +1,6 @@
{
"name": "babel-helpers",
"version": "6.22.0",
"version": "6.23.0",
"description": "Collection of helper functions used by Babel transforms.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -8,6 +8,6 @@
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers",
"main": "lib/index.js",
"dependencies": {
"babel-template": "^6.22.0"
"babel-template": "^6.23.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "babel-messages",
"version": "6.22.0",
"version": "6.23.0",
"description": "Collection of debug messages used by Babel.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-class-properties",
"version": "6.22.0",
"version": "6.23.0",
"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,9 +9,9 @@
"babel-plugin"
],
"dependencies": {
"babel-helper-function-name": "^6.22.0",
"babel-helper-function-name": "^6.23.0",
"babel-plugin-syntax-class-properties": "^6.8.0",
"babel-template": "^6.22.0"
"babel-template": "^6.23.0"
},
"devDependencies": {
"babel-helper-plugin-test-runner": "^6.22.0"

View File

@ -1,14 +1,14 @@
{
"name": "babel-plugin-transform-es2015-block-scoping",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-types": "^6.22.0",
"babel-template": "^6.22.0",
"babel-traverse": "^6.23.0",
"babel-types": "^6.23.0",
"babel-template": "^6.23.0",
"lodash": "^4.2.0"
},
"keywords": [

View File

@ -112,8 +112,21 @@ function isVar(node) {
}
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]);
@ -549,9 +562,19 @@ class BlockScoping {
const state = {
letReferences: this.letReferences,
closurify: false,
file: this.file
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);

View File

@ -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 {}) {}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}
}

View File

@ -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());
}
}
}
}

View File

@ -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());
}
}
})();
}
}

View File

@ -0,0 +1,6 @@
for (var i = 0; i < 5; i++) {
var l = i;
setTimeout(function () {
console.log(l);
}, 1);
}

View File

@ -1,16 +0,0 @@
function foo() {
switch (2) {
case 0: {
if (true) {
return;
}
const stuff = new Map();
const data = 0;
stuff.forEach(() => {
const d = data;
});
break;
}
}
}

View File

@ -1,3 +0,0 @@
{
"throws": "Compiling let/const in this block would add a closure (throwIfClosureRequired)."
}

View File

@ -1,19 +1,19 @@
{
"name": "babel-plugin-transform-es2015-classes",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-helper-function-name": "^6.22.0",
"babel-helper-replace-supers": "^6.22.0",
"babel-template": "^6.22.0",
"babel-traverse": "^6.22.0",
"babel-helper-define-map": "^6.22.0",
"babel-messages": "^6.22.0",
"babel-types": "^6.22.0"
"babel-helper-optimise-call-expression": "^6.23.0",
"babel-helper-function-name": "^6.23.0",
"babel-helper-replace-supers": "^6.23.0",
"babel-template": "^6.23.0",
"babel-traverse": "^6.23.0",
"babel-helper-define-map": "^6.23.0",
"babel-messages": "^6.23.0",
"babel-types": "^6.23.0"
},
"keywords": [
"babel-plugin"

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-es2015-destructuring",
"version": "6.22.0",
"version": "6.23.0",
"description": "Compile ES2015 destructuring to ES5",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-destructuring",
"license": "MIT",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-es2015-for-of",
"version": "6.22.0",
"version": "6.23.0",
"description": "Compile ES2015 for...of to ES5",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-for-of",
"license": "MIT",

View File

@ -135,9 +135,8 @@ export default function ({ messages, template, types: t }) {
};
function loose(path, file) {
const { node, scope } = path;
const left = node.left;
const { node, scope, parent } = path;
const { left } = node;
let declar, id;
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
@ -171,11 +170,18 @@ export default function ({ messages, template, types: t }) {
}
//
const isLabeledParent = t.isLabeledStatement(parent);
let labeled;
if (isLabeledParent) {
labeled = t.labeledStatement(parent.label, loop);
}
return {
declar: declar,
node: loop,
loop: loop
replaceParent: isLabeledParent,
declar: declar,
node: labeled || loop,
loop: loop
};
}

View File

@ -0,0 +1,5 @@
b: for (let c of d()) {
for (let e of f()) {
continue b;
}
}

View File

@ -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;
}
}

View File

@ -1,13 +1,13 @@
{
"name": "babel-plugin-transform-es2015-modules-commonjs",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-template": "^6.22.0",
"babel-types": "^6.23.0",
"babel-template": "^6.23.0",
"babel-plugin-transform-strict-mode": "^6.22.0"
},
"keywords": [

View File

@ -1,12 +1,12 @@
{
"name": "babel-plugin-transform-es2015-modules-systemjs",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-template": "^6.23.0",
"babel-helper-hoist-variables": "^6.22.0"
},
"keywords": [

View File

@ -1,13 +1,13 @@
{
"name": "babel-plugin-transform-es2015-modules-umd",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-template": "^6.22.0"
"babel-template": "^6.23.0"
},
"keywords": [
"babel-plugin"

View File

@ -1,16 +1,16 @@
{
"name": "babel-plugin-transform-es2015-parameters",
"version": "6.22.0",
"version": "6.23.0",
"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.22.0",
"babel-traverse": "^6.23.0",
"babel-helper-call-delegate": "^6.22.0",
"babel-helper-get-function-arity": "^6.22.0",
"babel-template": "^6.22.0",
"babel-types": "^6.22.0"
"babel-template": "^6.23.0",
"babel-types": "^6.23.0"
},
"keywords": [
"babel-plugin"

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-es2015-typeof-symbol",
"version": "6.22.0",
"version": "6.23.0",
"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",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-object-rest-spread",
"version": "6.22.0",
"version": "6.23.0",
"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",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-proto-to-assign",
"version": "6.22.0",
"version": "6.23.0",
"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",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-constant-elements",
"version": "6.22.0",
"version": "6.23.0",
"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",

View File

@ -1,4 +1,4 @@
export default function () {
export default function ({ types: t }) {
const immutabilityVisitor = {
enter(path, state) {
const stop = () => {
@ -11,15 +11,39 @@ 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();
}
}
};

View File

@ -1,18 +1,19 @@
var _ref = <p>Parent</p>;
var _ref2 = <div>child</div>;
var _ref3 = <p>Parent</p>;
(function () {
class App extends React.Component {
render() {
return <div>
{_ref}
<AppItem />
</div>;
return _ref;
}
}
const AppItem = () => {
return _ref2;
};
});
},
_ref = <div>
{_ref3}
<AppItem />
</div>;
});

View File

@ -1,16 +1,14 @@
var _ref = <p>Parent</p>;
export default class App extends React.Component {
render() {
return <div>
{_ref}
<AppItem />
</div>;
return _ref;
}
}
var _ref2 = <div>child</div>;
const AppItem = () => {
const _ref2 = <div>child</div>,
AppItem = () => {
return _ref2;
};
},
_ref = <div>
<p>Parent</p>
<AppItem />
</div>;

View File

@ -0,0 +1,15 @@
import React from "react";
const Parent = ({}) => (
<div className="parent">
<Child/>
</div>
);
export default Parent;
let Child = () => (
<div className="child">
ChildTextContent
</div>
);

View File

@ -0,0 +1,13 @@
import React from "react";
const Parent = ({}) => _ref;
export default Parent;
let _ref2 = <div className="child">
ChildTextContent
</div>,
Child = () => _ref2,
_ref = <div className="parent">
<Child />
</div>;

View File

@ -8,8 +8,9 @@ function render() {
function render() {
const bar = "bar",
renderFoo = () => <foo bar={bar} baz={baz} />,
baz = "baz";
renderFoo = () => _ref2,
baz = "baz",
_ref2 = <foo bar={bar} baz={baz} />;
return renderFoo();
}

View File

@ -0,0 +1,18 @@
import React from "react";
const HOC = component => component;
const Parent = ({}) => (
<div className="parent">
<Child/>
</div>
);
export default Parent;
let Child = () => (
<div className="child">
ChildTextContent
</div>
);
Child = HOC(Child);

View File

@ -0,0 +1,18 @@
import React from "react";
const HOC = component => component;
const Parent = ({}) => _ref;
export default Parent;
var _ref2 = <div className="child">
ChildTextContent
</div>;
let Child = () => _ref2;
Child = HOC(Child);
var _ref = <div className="parent">
<Child />
</div>;

View File

@ -1,17 +1,11 @@
function render(flag) {
if (flag) {
var _ret = function () {
var bar = "bar";
var bar = "bar";
[].map(() => bar);
[].map(() => bar);
return {
v: <foo bar={bar} />
};
}();
if (typeof _ret === "object") return _ret.v;
return <foo bar={bar} />;
}
return null;
}
}

View File

@ -0,0 +1,4 @@
function render() {
this.component = "div";
return () => <this.component />;
}

View File

@ -0,0 +1,7 @@
function render() {
this.component = "div";
var _ref = <this.component />;
return () => _ref;
}

View File

@ -0,0 +1,5 @@
class Component extends React.Component {
subComponent = () => <span>Sub Component</span>
render = () => <this.subComponent />
}

View File

@ -0,0 +1,12 @@
var _ref = <span>Sub Component</span>;
class Component extends React.Component {
constructor(...args) {
var _temp;
var _ref2 = <this.subComponent />;
return _temp = super(...args), this.subComponent = () => _ref, this.render = () => _ref2, _temp;
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"]
}

View File

@ -0,0 +1,6 @@
const els = {
subComponent: () => <span>Sub Component</span>
};
class Component extends React.Component {
render = () => <els.subComponent />
}

View File

@ -0,0 +1,16 @@
var _ref = <span>Sub Component</span>;
const els = {
subComponent: () => _ref
};
var _ref2 = <els.subComponent />;
class Component extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.render = () => _ref2, _temp;
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["syntax-jsx", "transform-react-constant-elements", "transform-class-properties"]
}

View File

@ -0,0 +1,5 @@
// https://github.com/facebook/react/issues/3226
// Not safe to reuse because it is mutable
function render() {
return <div style={{ width: 100 }} />;
}

View File

@ -0,0 +1,5 @@
// https://github.com/facebook/react/issues/3226
// Not safe to reuse because it is mutable
function render() {
return <div style={{ width: 100 }} />;
}

View File

@ -0,0 +1,5 @@
function render(offset) {
return function () {
return <div tabIndex={offset + 1} />;
};
}

View File

@ -0,0 +1,8 @@
function render(offset) {
var _ref = <div tabIndex={offset + 1} />;
return function () {
return _ref;
};
}

View File

@ -0,0 +1,10 @@
const OFFSET = 3;
var Foo = React.createClass({
render: function () {
return (
<div tabIndex={OFFSET + 1} />
);
}
});

View File

@ -0,0 +1,10 @@
const OFFSET = 3;
var _ref = <div tabIndex={OFFSET + 1} />;
var Foo = React.createClass({
render: function () {
return _ref;
}
});

View File

@ -0,0 +1,11 @@
var Foo = React.createClass({
render: function () {
return (
<div data-text={
"Some text, " +
"and some more too."
} />
);
}
});

View File

@ -0,0 +1,8 @@
var _ref = <div data-text={"Some text, " + "and some more too."} />;
var Foo = React.createClass({
render: function () {
return _ref;
}
});

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-display-name",
"version": "6.22.0",
"version": "6.23.0",
"description": "Add displayName to React.createClass calls",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-display-name",
"license": "MIT",

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-jsx",
"version": "6.22.0",
"version": "6.23.0",
"description": "Turn JSX into React function calls",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx",
"license": "MIT",
@ -9,7 +9,7 @@
"babel-plugin"
],
"dependencies": {
"babel-helper-builder-react-jsx": "^6.22.0",
"babel-helper-builder-react-jsx": "^6.23.0",
"babel-plugin-syntax-jsx": "^6.8.0"
},
"devDependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-runtime",
"version": "6.22.0",
"version": "6.23.0",
"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",

View File

@ -1,6 +1,6 @@
{
"name": "babel-polyfill",
"version": "6.22.0",
"version": "6.23.0",
"description": "Provides polyfills necessary for a full ES2015+ environment",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@ -0,0 +1,3 @@
src
test
node_modules

View File

@ -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"]
});
```

View File

@ -0,0 +1,18 @@
{
"name": "babel-preset-flow",
"version": "6.23.0",
"description": "Babel preset for all Flow plugins.",
"author": "James Kyle <me@thejameskyle.com>",
"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": "^6.22.0"
}
}

View File

@ -0,0 +1,7 @@
import transformFlowStripTypes from "babel-plugin-transform-flow-strip-types";
export default {
plugins: [
transformFlowStripTypes
]
};

View File

@ -2,11 +2,10 @@
> Babel preset for all React plugins.
This preset includes the following plugins:
This preset includes the following plugins/presets:
- [syntax-flow](https://babeljs.io/docs/plugins/syntax-flow/)
- [preset-flow](https://babeljs.io/docs/plugins/preset-flow/)
- [syntax-jsx](https://babeljs.io/docs/plugins/syntax-jsx/)
- [transform-flow-strip-types](https://babeljs.io/docs/plugins/transform-flow-strip-types/)
- [transform-react-jsx](https://babeljs.io/docs/plugins/transform-react-jsx/)
- [transform-react-display-name](https://babeljs.io/docs/plugins/transform-react-display-name/)

View File

@ -1,6 +1,6 @@
{
"name": "babel-preset-react",
"version": "6.22.0",
"version": "6.23.0",
"description": "Babel preset for all React plugins.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -8,11 +8,10 @@
"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-preset-flow": "^6.23.0",
"babel-plugin-syntax-jsx": "^6.3.13",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-react-display-name": "^6.22.0",
"babel-plugin-transform-react-jsx": "^6.22.0",
"babel-plugin-transform-react-display-name": "^6.23.0",
"babel-plugin-transform-react-jsx": "^6.23.0",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-plugin-transform-react-jsx-self": "^6.22.0"
}

View File

@ -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";
@ -9,10 +8,11 @@ import transformReactDisplayName from "babel-plugin-transform-react-display-name
// import transformReactJSXSelf from "babel-plugin-transform-react-jsx-self";
export default {
presets: [
presetFlow
],
plugins: [
transformReactJSX,
transformFlowStripTypes,
transformSyntaxFlow,
transformSyntaxJSX,
transformReactDisplayName
],

View File

@ -1,6 +1,6 @@
{
"name": "babel-register",
"version": "6.22.0",
"version": "6.23.0",
"description": "babel require hook",
"license": "MIT",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-register",
@ -8,7 +8,7 @@
"main": "lib/node.js",
"browser": "lib/browser.js",
"dependencies": {
"babel-core": "^6.22.0",
"babel-core": "^6.23.0",
"core-js": "^2.4.0",
"home-or-tmp": "^3.0.0",
"lodash": "^4.2.0",

View File

@ -1,6 +1,6 @@
{
"name": "babel-template",
"version": "6.22.0",
"version": "6.23.0",
"description": "Generate an AST from a string template.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -9,8 +9,8 @@
"main": "lib/index.js",
"dependencies": {
"babylon": "^6.11.0",
"babel-traverse": "^6.22.0",
"babel-types": "^6.22.0",
"babel-traverse": "^6.23.0",
"babel-types": "^6.23.0",
"lodash": "^4.2.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "babel-traverse",
"version": "6.22.1",
"version": "6.23.1",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@ -9,8 +9,8 @@
"main": "lib/index.js",
"dependencies": {
"babel-code-frame": "^6.22.0",
"babel-messages": "^6.22.0",
"babel-types": "^6.22.0",
"babel-messages": "^6.23.0",
"babel-types": "^6.23.0",
"babylon": "^6.15.0",
"debug": "^2.2.0",
"globals": "^9.0.0",
@ -18,6 +18,6 @@
"lodash": "^4.2.0"
},
"devDependencies": {
"babel-generator": "^6.22.0"
"babel-generator": "^6.23.0"
}
}

View File

@ -2,11 +2,27 @@ import { react } from "babel-types";
import * as t from "babel-types";
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
const binding = path.scope.getBinding(path.node.name);
if (!binding) return;
@ -15,25 +31,27 @@ const referenceVisitor = {
// 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 (const 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 = [];
// 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 (const key in this.bindings) {
const binding = this.bindings[key];
@ -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;
}
@ -61,7 +81,7 @@ export default class PathHoister {
}
getAttachmentPath() {
const path = this._getAttachmentPath();
let path = this._getAttachmentPath();
if (!path) return;
let targetScope = path.scope;
@ -82,8 +102,18 @@ export default class PathHoister {
// 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;
}
}
}
}
}
@ -94,11 +124,12 @@ export default class PathHoister {
const scopes = this.scopes;
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
@ -117,26 +148,30 @@ export default class PathHoister {
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 !== null &&
path.parentPath.node.declarations.length > 1
)
)
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 (const name in this.bindings) {
if (!scope.hasOwnBinding(name)) continue;
const binding = this.bindings[name];
if (binding.kind === "param") return true;
// Ensure constant; without it we could place behind a reassignment
if (binding.kind === "param" && binding.constant) return true;
}
return false;
}
@ -161,7 +196,8 @@ export default class PathHoister {
let uid = attachTo.scope.generateUidIdentifier("ref");
const declarator = t.variableDeclarator(uid, this.path.node);
attachTo.insertBefore([
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
attachTo[insertFn]([
attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])
]);

View File

@ -930,6 +930,7 @@ Aliases: `ModuleSpecifier`
- `local`: `Identifier` (required)
- `imported`: `Identifier` (required)
- `importKind`: `null | 'type' | 'typeof'` (default: `null`)
---

View File

@ -1,6 +1,6 @@
{
"name": "babel-types",
"version": "6.22.0",
"version": "6.23.0",
"description": "Babel Types is a Lodash-esque utility library for AST nodes",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",