Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b516ea596a | ||
|
|
248758eee3 | ||
|
|
a808602ae0 | ||
|
|
40e3436e95 | ||
|
|
f704770b26 | ||
|
|
330665f150 | ||
|
|
af41899d74 | ||
|
|
d12f4d0bc8 | ||
|
|
97680e9dfd | ||
|
|
51341ca6c3 | ||
|
|
ab54bfa50e | ||
|
|
60aa933fb6 | ||
|
|
b0317f9bab | ||
|
|
be2dfaf081 | ||
|
|
2c8437ae92 | ||
|
|
2a0bcfd086 | ||
|
|
2cf41afac3 | ||
|
|
e318f5f3be | ||
|
|
939decb86c | ||
|
|
1baa0df948 | ||
|
|
e8956a8c44 | ||
|
|
2f0fdbbc26 | ||
|
|
5f931525bc | ||
|
|
b86545a320 | ||
|
|
06e75c42bf | ||
|
|
05dd65244d | ||
|
|
c4ebfeb0fa | ||
|
|
1aa0bbfac9 | ||
|
|
58f1e6cbc6 | ||
|
|
83e0be3038 | ||
|
|
5fc242e4ec | ||
|
|
dc101adad3 | ||
|
|
faade72787 | ||
|
|
2a78ae9889 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -13,6 +13,24 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.3.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `minification.deadCodeElimination` transformer incorrectly trying to inline import declarations.
|
||||
* Fix `minification.inlineExpression` transformer getting into an infinite loop.
|
||||
|
||||
## 5.3.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix patterns not being considered when hoisting variables in the `es6.blockScoping` transformer.
|
||||
|
||||
## 5.3.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix unique export specifiers not being cloned when exploding class and function exports,
|
||||
* **Polish**
|
||||
* Turn import remaps to sequence expressions to remove their context and improve performance.
|
||||
|
||||
## 5.3.0
|
||||
|
||||
**Speeeeeeed**
|
||||
@@ -30,6 +48,7 @@ See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
* Properly hoist temp param declarations when doing TCO.
|
||||
* **Internal**
|
||||
* Add `--harmony_generators` flag to `$ babel-node`.
|
||||
* Internal AST traversals have been minimised **drastically**. Transformers have been grouped together which means entire tree traversals are much fewer. Visiting nodes is now also skipped if the traversal context can detect that the handler is a noop. This sames precious cycles as it avoids constructing traversal paths and creating a new traversal context. See issues [#1472](https://github.com/babel/babel/issues/1472) and [#1486](https://github.com/babel/babel/issues/1486) for related discussion.
|
||||
* **Polish**
|
||||
* Move many `utility` transformers to `minification`.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.3.0",
|
||||
"version": "5.3.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
@@ -64,7 +64,7 @@
|
||||
"user-home": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "5.1.13",
|
||||
"babel": "5.3.1",
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"eslint": "^0.18.0",
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.17",
|
||||
"version": "5.3.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.2.17",
|
||||
"babel-core": "^5.3.2",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.2.17",
|
||||
"version": "5.3.2",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
@@ -461,16 +461,6 @@ export default class File {
|
||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||
this.scope = this.path.scope;
|
||||
this.ast = ast;
|
||||
|
||||
this.path.traverse({
|
||||
enter(node, parent, scope) {
|
||||
if (this.isScope()) {
|
||||
for (var key in scope.bindings) {
|
||||
scope.bindings[key].setTypeAnnotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addAst(ast) {
|
||||
|
||||
@@ -17,7 +17,11 @@ var remapVisitor = {
|
||||
|
||||
if (remap && node !== remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
if (this.key === "callee" && this.parentPath.isCallExpression()) {
|
||||
return t.sequenceExpression([t.literal(0), remap]);
|
||||
} else {
|
||||
return remap;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
for (var LEN = ARGUMENTS.length, ARRAY = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
|
||||
for (var LEN = ARGUMENTS.length, ARRAY: ARRAY_TYPE = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
|
||||
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
|
||||
}
|
||||
|
||||
@@ -557,9 +557,13 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
|
||||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
|
||||
return t.variableDeclarator(declar.id);
|
||||
})));
|
||||
var declars = [];
|
||||
var names = t.getBindingIdentifiers(node);
|
||||
for (var name in names) {
|
||||
declars.push(t.variableDeclarator(names[name]));
|
||||
}
|
||||
|
||||
this.body.push(t.variableDeclaration(node.kind, declars));
|
||||
|
||||
var replace = [];
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ export function VariableDeclaration(node, parent, scope, file) {
|
||||
file: file
|
||||
});
|
||||
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
if (t.isPattern(pattern)) {
|
||||
destructuring.init(pattern, patternId);
|
||||
|
||||
if (+i !== node.declarations.length - 1) {
|
||||
|
||||
@@ -56,7 +56,8 @@ var hasRest = function (node) {
|
||||
export function Func(node, parent, scope, file) {
|
||||
if (!hasRest(node)) return;
|
||||
|
||||
var rest = node.params.pop().argument;
|
||||
var restParam = node.params.pop();
|
||||
var rest = restParam.argument;
|
||||
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
@@ -125,13 +126,14 @@ export function Func(node, parent, scope, file) {
|
||||
}
|
||||
|
||||
var loop = util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len
|
||||
ARRAY_TYPE: restParam.typeAnnotation,
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
|
||||
@@ -20,8 +20,7 @@ function returnBlock(expr) {
|
||||
return t.blockStatement([t.returnStatement(expr)]);
|
||||
}
|
||||
|
||||
// looks for and replaces tail recursion calls
|
||||
var firstPass = {
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
@@ -33,7 +32,6 @@ var firstPass = {
|
||||
},
|
||||
|
||||
ReturnStatement(node, parent, scope, state) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
},
|
||||
|
||||
@@ -42,46 +40,18 @@ var firstPass = {
|
||||
},
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// hoists up function declarations, replaces `this` and `arguments` and marks
|
||||
// them as needed
|
||||
var secondPass = {
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
state.thisPaths.push(this);
|
||||
},
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name !== "arguments") return;
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
},
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
this.skip();
|
||||
if (this.isFunctionDeclaration()) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
node._blockHoist = 2;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// optimizes recursion by removing `this` and `arguments` if they aren't used
|
||||
var thirdPass = {
|
||||
AssignmentExpression(node, parent, scope, state) {
|
||||
if (!state.needsThis && node.left === state.getThisId()) {
|
||||
this.remove();
|
||||
} else if (!state.needsArguments && node.left === state.getArgumentsId() && t.isArrayExpression(node.right)) {
|
||||
return map(node.right.elements, function (elem) {
|
||||
return t.expressionStatement(elem);
|
||||
});
|
||||
if (node.name === "arguments") {
|
||||
state.needsArguments = true;
|
||||
state.argumentsPaths.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -89,11 +59,16 @@ var thirdPass = {
|
||||
class TailCallTransformer {
|
||||
constructor(path, scope, file) {
|
||||
this.hasTailRecursion = false;
|
||||
this.needsArguments = false;
|
||||
this.setsArguments = false;
|
||||
this.needsThis = false;
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.needsArguments = false;
|
||||
this.argumentsPaths = [];
|
||||
this.setsArguments = false;
|
||||
|
||||
this.needsThis = false;
|
||||
this.thisPaths = [];
|
||||
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
@@ -159,10 +134,12 @@ class TailCallTransformer {
|
||||
if (!ownerId) return;
|
||||
|
||||
// traverse the function and look for tail recursion
|
||||
this.path.traverse(firstPass, this);
|
||||
this.path.traverse(visitor, this);
|
||||
|
||||
// has no tail call recursion
|
||||
if (!this.hasTailRecursion) return;
|
||||
|
||||
// the function binding isn't constant so we can't be sure that it's the same function :(
|
||||
if (this.hasDeopt()) {
|
||||
this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt"));
|
||||
return;
|
||||
@@ -170,14 +147,18 @@ class TailCallTransformer {
|
||||
|
||||
//
|
||||
|
||||
this.path.traverse(secondPass, this);
|
||||
|
||||
if (!this.needsThis || !this.needsArguments) {
|
||||
this.path.traverse(thirdPass, this);
|
||||
}
|
||||
|
||||
var body = t.ensureBlock(node).body;
|
||||
|
||||
for (var i = 0; i < body.length; i++) {
|
||||
var bodyNode = body[i];
|
||||
if (!t.isFunctionDeclaration(bodyNode)) continue;
|
||||
|
||||
bodyNode = body[i] = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(bodyNode.id, t.toExpression(bodyNode))
|
||||
]);
|
||||
bodyNode._blockHoist = 2;
|
||||
}
|
||||
|
||||
if (this.vars.length > 0) {
|
||||
var declarations = flatten(map(this.vars, function (decl) {
|
||||
return decl.declarations;
|
||||
@@ -204,22 +185,28 @@ class TailCallTransformer {
|
||||
);
|
||||
|
||||
node.body = util.template("tail-call-body", {
|
||||
AGAIN_ID: this.getAgainId(),
|
||||
THIS_ID: this.thisId,
|
||||
ARGUMENTS_ID: this.argumentsId,
|
||||
FUNCTION_ID: this.getFunctionId(),
|
||||
BLOCK: node.body
|
||||
FUNCTION_ID: this.getFunctionId(),
|
||||
AGAIN_ID: this.getAgainId(),
|
||||
BLOCK: node.body
|
||||
});
|
||||
|
||||
var topVars = [];
|
||||
|
||||
if (this.needsThis) {
|
||||
for (var path of (this.thisPaths: Array)) {
|
||||
path.replaceWith(this.getThisId());
|
||||
}
|
||||
|
||||
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
|
||||
}
|
||||
|
||||
if (this.needsArguments || this.setsArguments) {
|
||||
var decl = t.variableDeclarator(this.getArgumentsId());
|
||||
if (this.needsArguments) {
|
||||
for (var path of (this.argumentsPaths: Array)) {
|
||||
path.replaceWith(this.argumentsId);
|
||||
}
|
||||
|
||||
var decl = t.variableDeclarator(this.argumentsId);
|
||||
if (this.argumentsId) {
|
||||
decl.init = t.identifier("arguments");
|
||||
}
|
||||
topVars.push(decl);
|
||||
@@ -332,7 +319,7 @@ class TailCallTransformer {
|
||||
|
||||
var body = [];
|
||||
|
||||
if (!t.isThisExpression(thisBinding)) {
|
||||
if (this.needsThis && !t.isThisExpression(thisBinding)) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
this.getThisId(),
|
||||
@@ -345,29 +332,35 @@ class TailCallTransformer {
|
||||
}
|
||||
|
||||
var argumentsId = this.getArgumentsId();
|
||||
var params = this.getParams();
|
||||
var params = this.getParams();
|
||||
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
argumentsId,
|
||||
args
|
||||
)));
|
||||
|
||||
var i, param;
|
||||
if (this.needsArguments) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
argumentsId,
|
||||
args
|
||||
)));
|
||||
}
|
||||
|
||||
if (t.isArrayExpression(args)) {
|
||||
var elems = args.elements;
|
||||
for (i = 0; i < elems.length && i < params.length; i++) {
|
||||
param = params[i];
|
||||
for (let i = 0; i < elems.length && i < params.length; i++) {
|
||||
let param = params[i];
|
||||
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
elems[i] = t.assignmentExpression("=", param, elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.needsArguments) {
|
||||
for (var elem of (elems: Array)) {
|
||||
body.push(t.expressionStatement(elem));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.setsArguments = true;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
param = params[i];
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
let param = params[i];
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
@@ -381,6 +374,7 @@ class TailCallTransformer {
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", this.getAgainId(), t.literal(true))
|
||||
));
|
||||
|
||||
body.push(t.continueStatement(this.getFunctionId()));
|
||||
|
||||
return body;
|
||||
|
||||
@@ -13,6 +13,18 @@ function buildClone(bindingKey, refKey) {
|
||||
};
|
||||
}
|
||||
|
||||
function buildListClone(listKey, bindingKey, refKey) {
|
||||
var clone = buildClone(bindingKey, refKey);
|
||||
|
||||
return function (node) {
|
||||
if (!node[listKey]) return;
|
||||
|
||||
for (var subNode of (node[listKey]: Array)) {
|
||||
clone(subNode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export var Property = buildClone("value", "key");
|
||||
export var ExportSpecifier = buildClone("local", "exported");
|
||||
export var ImportSpecifier = buildClone("local", "imported");
|
||||
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
|
||||
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");
|
||||
|
||||
@@ -49,6 +49,10 @@ export function ExportDefaultDeclaration(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildExportSpecifier(id) {
|
||||
return t.exportSpecifier(clone(id), clone(id));
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration(node, parent, scope) {
|
||||
ImportDeclaration.apply(this, arguments);
|
||||
|
||||
@@ -61,12 +65,12 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
|
||||
if (t.isClassDeclaration(declar)) {
|
||||
// export class Foo {}
|
||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||
node.declaration = null;
|
||||
return [getDeclar(), node];
|
||||
} else if (t.isFunctionDeclaration(declar)) {
|
||||
// export function Foo() {}
|
||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||
node.declaration = null;
|
||||
node._blockHoist = 2;
|
||||
return [getDeclar(), node];
|
||||
@@ -75,8 +79,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
var specifiers = [];
|
||||
var bindings = this.get("declaration").getBindingIdentifiers();
|
||||
for (var key in bindings) {
|
||||
var id = bindings[key];
|
||||
specifiers.push(t.exportSpecifier(clone(id), clone(id)));
|
||||
specifiers.push(buildExportSpecifier(bindings[key]));
|
||||
}
|
||||
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
||||
}
|
||||
|
||||
@@ -22,21 +22,19 @@ export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
export function ReferencedIdentifier(node, parent, scope) {
|
||||
var binding = scope.getBinding(node.name);
|
||||
if (!binding || binding.references > 1 || !binding.constant) return;
|
||||
if (binding.kind === "param") return;
|
||||
if (binding.kind === "param" || binding.kind === "module") return;
|
||||
|
||||
var replacement = binding.path.node;
|
||||
if (t.isVariableDeclarator(replacement)) {
|
||||
replacement = replacement.init;
|
||||
}
|
||||
if (!replacement) return;
|
||||
|
||||
t.toExpression(replacement);
|
||||
|
||||
scope.removeBinding(node.name);
|
||||
|
||||
binding.path.remove();
|
||||
return replacement;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Expression(node, parent, scope) {
|
||||
var res = this.evaluate();
|
||||
if (res.confident) return t.valueToNode(res.value);
|
||||
}
|
||||
export var Expression = {
|
||||
exit(node, parent, scope) {
|
||||
var res = this.evaluate();
|
||||
if (res.confident) return t.valueToNode(res.value);
|
||||
}
|
||||
};
|
||||
|
||||
export function Identifier() {
|
||||
// override Expression
|
||||
|
||||
@@ -7,4 +7,5 @@ export var metadata = {
|
||||
|
||||
export function Program(ast) {
|
||||
regenerator.transform(ast);
|
||||
this.stop();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,15 @@ export default class Binding {
|
||||
this.references++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
dereference() {
|
||||
this.references--;
|
||||
this.referenced = !!this.references;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
@@ -92,6 +92,7 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
case "!": return !arg;
|
||||
case "+": return +arg;
|
||||
case "-": return -arg;
|
||||
case "~": return ~arg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@ var referenceVisitor = {
|
||||
// eg. it's in a closure etc
|
||||
if (bindingInfo !== state.scope.getBinding(node.name)) return;
|
||||
|
||||
if (bindingInfo && bindingInfo.constant) {
|
||||
state.bindings[node.name] = bindingInfo;
|
||||
} else {
|
||||
state.foundIncompatible = true;
|
||||
this.stop();
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.constant) {
|
||||
state.bindings[node.name] = bindingInfo;
|
||||
} else {
|
||||
state.foundIncompatible = true;
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,14 +228,16 @@ export default class TraversalPath {
|
||||
paths.push(TraversalPath.get(this, null, node, this.container, to));
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
_containerInsertBefore(nodes) {
|
||||
this._containerInsert(this.key, nodes);
|
||||
return this._containerInsert(this.key, nodes);
|
||||
}
|
||||
|
||||
_containerInsertAfter(nodes) {
|
||||
this._containerInsert(this.key + 1, nodes);
|
||||
return this._containerInsert(this.key + 1, nodes);
|
||||
}
|
||||
|
||||
_maybePopFromStatements(nodes) {
|
||||
@@ -922,6 +924,14 @@ export default class TraversalPath {
|
||||
return !this.has(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
equals(key, value): boolean {
|
||||
return this.node[key] === value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -939,7 +949,7 @@ export default class TraversalPath {
|
||||
annotation: null
|
||||
};
|
||||
|
||||
var type = this.node.typeAnnotation;
|
||||
var type = this.node && this.node.typeAnnotation;
|
||||
|
||||
if (!type) {
|
||||
info.inferred = true;
|
||||
@@ -1017,36 +1027,36 @@ export default class TraversalPath {
|
||||
path = path.resolve();
|
||||
if (!path) return;
|
||||
|
||||
if (path.isRestElement() || path.parentPath.isRestElement() || path.isArrayExpression()) {
|
||||
if (path.isPreviousType("RestElement") || path.parentPath.isPreviousType("RestElement") || path.isPreviousType("ArrayExpression")) {
|
||||
return t.genericTypeAnnotation(t.identifier("Array"));
|
||||
}
|
||||
|
||||
if (path.parentPath.isTypeCastExpression()) {
|
||||
if (path.parentPath.isPreviousType("TypeCastExpression")) {
|
||||
return path.parentPath.node.typeAnnotation;
|
||||
}
|
||||
|
||||
if (path.isTypeCastExpression()) {
|
||||
if (path.isPreviousType("TypeCastExpression")) {
|
||||
return path.node.typeAnnotation;
|
||||
}
|
||||
|
||||
if (path.isObjectExpression()) {
|
||||
if (path.isPreviousType("ObjectExpression")) {
|
||||
return t.genericTypeAnnotation(t.identifier("Object"));
|
||||
}
|
||||
|
||||
if (path.isFunction()) {
|
||||
if (path.isPreviousType("Function")) {
|
||||
return t.identifier("Function");
|
||||
}
|
||||
|
||||
if (path.isLiteral()) {
|
||||
if (path.isPreviousType("Literal")) {
|
||||
var value = path.node.value;
|
||||
if (isString(value)) return t.stringTypeAnnotation();
|
||||
if (isNumber(value)) return t.numberTypeAnnotation();
|
||||
if (isBoolean(value)) return t.booleanTypeAnnotation();
|
||||
}
|
||||
|
||||
if (path.isCallExpression()) {
|
||||
if (path.isPreviousType("CallExpression")) {
|
||||
var callee = path.get("callee").resolve();
|
||||
if (callee && callee.isFunction()) return callee.node.returnType;
|
||||
if (callee && callee.isPreviousType("Function")) return callee.node.returnType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -631,13 +631,14 @@ export default class Scope {
|
||||
var declar = !unique && path.getData(dataKey);
|
||||
|
||||
if (!declar) {
|
||||
declar = t.variableDeclaration(opts.kind || "var", []);
|
||||
declar = t.variableDeclaration(kind, []);
|
||||
declar._generated = true;
|
||||
declar._blockHoist = 2;
|
||||
|
||||
this.file.attachAuxiliaryComment(declar);
|
||||
|
||||
path.get("body")[0]._containerInsertBefore([declar]);
|
||||
var [declarPath] = path.get("body")[0]._containerInsertBefore([declar]);
|
||||
this.registerBinding(kind, declarPath);
|
||||
if (!unique) path.setData(dataKey, declar);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,27 @@ export function isReferenced(node: Object, parent: Object): boolean {
|
||||
return parent.id !== node;
|
||||
|
||||
// no: export { foo as NODE };
|
||||
// yes: export { NODE as foo };
|
||||
// no: export { NODE as foo } from "foo";
|
||||
case "ExportSpecifier":
|
||||
return parent.exported !== node;
|
||||
if (parent.source) {
|
||||
return false;
|
||||
} else {
|
||||
return parent.local === node;
|
||||
}
|
||||
|
||||
// no: import NODE from "foo";
|
||||
case "ImportDefaultSpecifier":
|
||||
return false;
|
||||
|
||||
// no: import * as NODE from "foo";
|
||||
case "ImportNamespaceSpecifier":
|
||||
return false;
|
||||
|
||||
// no: import { NODE as foo } from "foo";
|
||||
// no: import { foo as NODE } from "foo";
|
||||
case "ImportSpecifier":
|
||||
return parent.imported !== node;
|
||||
return false;
|
||||
|
||||
// no: class NODE {}
|
||||
case "ClassDeclaration":
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
for (let i of nums) {
|
||||
var x = 5;
|
||||
var { f } = { f: 2 };
|
||||
fns.push(function () {
|
||||
return i * x;
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ try {
|
||||
var _loop = function () {
|
||||
var i = _step.value;
|
||||
x = 5;
|
||||
var _f = { f: 2 };
|
||||
f = _f.f;
|
||||
|
||||
fns.push(function () {
|
||||
return i * x;
|
||||
@@ -16,6 +18,7 @@ try {
|
||||
|
||||
for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var x;
|
||||
var f;
|
||||
|
||||
_loop();
|
||||
}
|
||||
@@ -32,4 +35,4 @@ try {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ define(["exports", "./evens"], function (exports, _evens) {
|
||||
exports.nextOdd = nextOdd;
|
||||
|
||||
function nextOdd(n) {
|
||||
return _evens.isEven(n) ? n + 1 : n + 2;
|
||||
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
|
||||
@@ -8,7 +8,7 @@ exports.nextOdd = nextOdd;
|
||||
var _evens = require("./evens");
|
||||
|
||||
function nextOdd(n) {
|
||||
return _evens.isEven(n) ? n + 1 : n + 2;
|
||||
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
@@ -16,4 +16,4 @@ var isOdd = (function (isEven) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(_evens.isEven);
|
||||
exports.isOdd = isOdd;
|
||||
exports.isOdd = isOdd;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
exports.nextOdd = nextOdd;
|
||||
|
||||
function nextOdd(n) {
|
||||
return _evens.isEven(n) ? n + 1 : n + 2;
|
||||
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
@@ -28,4 +28,4 @@
|
||||
};
|
||||
})(_evens.isEven);
|
||||
exports.isOdd = isOdd;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ var Foo = (function () {
|
||||
}
|
||||
|
||||
var _Foo = Foo;
|
||||
Foo = _foo2["default"](Foo) || Foo;
|
||||
Foo = (0, _foo2["default"])(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
define(["exports", "foo", "babel-runtime/helpers/interop-require"], function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = _babelRuntimeHelpersInteropRequire["default"](_foo);
|
||||
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
|
||||
|
||||
_foo2;
|
||||
});
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
})(this, function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = _babelRuntimeHelpersInteropRequire["default"](_foo);
|
||||
});
|
||||
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
|
||||
});
|
||||
|
||||
@@ -20,11 +20,11 @@ var Container = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
return _lodashArrayLast2["default"](this.tokens.get(key));
|
||||
return (0, _lodashArrayLast2["default"])(this.tokens.get(key));
|
||||
}
|
||||
}]);
|
||||
return Container;
|
||||
})();
|
||||
|
||||
exports["default"] = Container;
|
||||
module.exports = exports["default"];
|
||||
module.exports = exports["default"];
|
||||
|
||||
@@ -19,11 +19,11 @@ var Login = (function (_React$Component) {
|
||||
babelHelpers.createClass(Login, [{
|
||||
key: "getForm",
|
||||
value: function getForm() {
|
||||
return _store.getForm().toJS();
|
||||
return (0, _store.getForm)().toJS();
|
||||
}
|
||||
}]);
|
||||
return Login;
|
||||
})(React.Component);
|
||||
|
||||
exports["default"] = Login;
|
||||
module.exports = exports["default"];
|
||||
module.exports = exports["default"];
|
||||
|
||||
Reference in New Issue
Block a user