Compare commits

...

22 Commits

Author SHA1 Message Date
Sebastian McKenzie
b516ea596a v5.3.3 2015-05-13 22:08:32 +01:00
Sebastian McKenzie
248758eee3 fix version number 2015-05-13 22:07:33 +01:00
Sebastian McKenzie
a808602ae0 v3.5.3 2015-05-13 22:07:00 +01:00
Sebastian McKenzie
40e3436e95 add 3.5.3 changelog 2015-05-13 22:05:07 +01:00
Sebastian McKenzie
f704770b26 uncomment out return traversal path skipping - fixes #1523 2015-05-13 22:03:50 +01:00
Sebastian McKenzie
330665f150 ignore modules alongside param bindings in minification.deadCodeElimination transformer - fixes #1523 2015-05-13 21:49:28 +01:00
Sebastian McKenzie
af41899d74 5.3.2 2015-05-13 19:58:21 +01:00
Sebastian McKenzie
d12f4d0bc8 v5.3.2 2015-05-13 19:57:20 +01:00
Sebastian McKenzie
97680e9dfd properly hoist all var patterns when wrapping bodies in the es6.blockScoping transformer - fixes #1521 2015-05-13 19:55:40 +01:00
Sebastian McKenzie
51341ca6c3 fix and add missing module specifier reference detection - fixes #1520 2015-05-13 19:23:47 +01:00
Sebastian McKenzie
ab54bfa50e Merge pull request #1519 from zpao/package-licenses
Add license fields to packages
2015-05-13 18:36:25 +01:00
Paul O’Shannessy
60aa933fb6 Add license fields to packages 2015-05-13 10:21:42 -07:00
Sebastian McKenzie
b0317f9bab don't consider "globals" to cause incompatible scope hoist 2015-05-13 12:33:08 +01:00
Sebastian McKenzie
be2dfaf081 register variable declarator in scope when pushing 2015-05-13 09:11:09 +01:00
Sebastian McKenzie
2c8437ae92 ignore initializerless variable declaration when trying to inline single use variables - fixes #1516 2015-05-13 08:46:41 +01:00
Sebastian McKenzie
2a0bcfd086 add support for evaluating unary ~ 2015-05-13 08:45:16 +01:00
Sebastian McKenzie
2cf41afac3 move expression inlining to exit rather than enter in minification.inlineExpressions transformer 2015-05-13 08:45:06 +01:00
Sebastian McKenzie
e318f5f3be use ReferencedIdentifier virtual type in minification.deadCodeElimination transformer 2015-05-13 08:44:33 +01:00
Sebastian McKenzie
939decb86c stop entire unnecessary traversal for regenerator 2015-05-13 08:44:18 +01:00
Sebastian McKenzie
1baa0df948 clean up array inferrence for #1515 2015-05-13 08:44:03 +01:00
Sebastian McKenzie
e8956a8c44 upgrade dev dependency babel to 5.3.1 2015-05-13 08:43:25 +01:00
Sebastian McKenzie
2f0fdbbc26 5.3.1 2015-05-13 03:21:54 +01:00
20 changed files with 104 additions and 59 deletions

View File

@@ -13,6 +13,17 @@ _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**
@@ -37,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`.

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.3.1",
"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.3.0",
"babel": "5.3.1",
"browserify": "^9.0.8",
"chai": "^2.2.0",
"eslint": "^0.18.0",

View File

@@ -1,13 +1,14 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.3.0",
"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.3.0",
"babel-core": "^5.3.2",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

@@ -1,7 +1,8 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "5.3.0",
"version": "5.3.2",
"license": "MIT",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"dependencies": {

View File

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

View File

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

View File

@@ -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 = [];

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,4 +7,5 @@ export var metadata = {
export function Program(ast) {
regenerator.transform(ast);
this.stop();
}

View File

@@ -69,6 +69,15 @@ export default class Binding {
this.references++;
}
/**
* Description
*/
dereference() {
this.references--;
this.referenced = !!this.references;
}
/**
* Description
*/

View File

@@ -92,6 +92,7 @@ export function evaluate(): { confident: boolean; value: any } {
case "!": return !arg;
case "+": return +arg;
case "-": return -arg;
case "~": return ~arg;
}
}

View File

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

View File

@@ -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) {
@@ -947,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;
@@ -1025,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;
}
}

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
for (let i of nums) {
var x = 5;
var { f } = { f: 2 };
fns.push(function () {
return i * x;
});

View File

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