Compare commits

...

19 Commits

Author SHA1 Message Date
Sebastian McKenzie
d69b0973e1 v5.5.4 2015-06-05 23:03:55 +01:00
Sebastian McKenzie
6296f49653 update minification.constantFolding transformer to deopt bindings that are reassigned in a different function scope 2015-06-05 23:01:31 +01:00
Sebastian McKenzie
9f2b739046 improve Scope#dump to print binding info 2015-06-05 23:00:50 +01:00
Sebastian McKenzie
da1d5e5577 simplify unary resolution and move operators to types 2015-06-05 23:00:06 +01:00
Sebastian McKenzie
7333b4e392 move staticPropBody class concat to after className check in es6.classes transformer 2015-06-05 22:44:03 +01:00
Sebastian McKenzie
b0442d0784 add back shouldIgnore check that went missing around 32f19aff99 - closes #1696, fixes #1693 2015-06-05 22:43:32 +01:00
Sebastian McKenzie
295e69f8f8 fix auxiliaryComment option name for istanbul interop - fixes #1695 2015-06-05 22:40:28 +01:00
Sebastian McKenzie
cfe844fa39 add boolean type to experimental option 2015-06-05 22:36:16 +01:00
Sebastian McKenzie
0f4ea2d2a6 use file.log.deprecate instead of throwing an error - fixes #1694 2015-06-05 22:35:46 +01:00
Sebastian McKenzie
4b85b05839 use actual parameter reference for non-last default parameters - fixes #1690 2015-06-05 14:08:18 +01:00
Sebastian McKenzie
2539d08dce 5.5.3 2015-06-05 14:07:34 +01:00
Sebastian McKenzie
c26fd7a819 fix regenerator version 2015-06-05 14:07:27 +01:00
Sebastian McKenzie
2053610429 v5.5.3 2015-06-05 12:20:22 +01:00
Sebastian McKenzie
cd4f83b299 fix linting errors 2015-06-05 12:19:32 +01:00
Sebastian McKenzie
ec29ba19a9 add 5.5.3 changelog 2015-06-05 12:18:43 +01:00
Sebastian McKenzie
9dc03e0978 traverse over ClassProperty path rather than node 2015-06-05 12:17:55 +01:00
Sebastian McKenzie
bc4258eca9 add type inferrence for template literals 2015-06-05 12:17:45 +01:00
Sebastian McKenzie
b0e58f9770 add completion statement test and enable experimental option on deadCodeElimination tests 2015-06-05 12:17:36 +01:00
Sebastian McKenzie
a1e2641c91 5.5.2 2015-06-05 12:17:18 +01:00
20 changed files with 166 additions and 64 deletions

View File

@@ -13,6 +13,11 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 5.5.3
* **Bug Fix**
* Fix weird state bug when traversing overa `node` `ClassProperty` instead of `path` in the `es6.classes` transformer.
## 5.5.2
* **Bug Fix**

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "A compiler for writing next generation JavaScript",
"version": "5.5.2",
"version": "5.5.4",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
@@ -51,7 +51,7 @@
"output-file-sync": "^1.1.0",
"path-is-absolute": "^1.0.0",
"private": "^0.1.6",
"regenerator": "^0.8.28",
"regenerator": "0.8.28",
"regexpu": "^1.1.2",
"repeating": "^1.1.2",
"resolve": "^1.1.6",

View File

@@ -1,14 +1,14 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.5.1",
"version": "5.5.3",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.5.1",
"babel-core": "^5.5.3",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

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

View File

@@ -105,7 +105,7 @@ if (process.env.running_under_istanbul) {
if (istanbulMonkey[filename]) {
delete istanbulMonkey[filename];
var code = compile(filename, {
attachAuxiliaryComment: "istanbul ignore next"
auxiliaryComment: "istanbul ignore next"
});
istanbulMonkey[filename] = true;
return code;

View File

@@ -115,7 +115,7 @@ export default class File {
if (!val && option.optional) continue;
if (val && option.deprecated) {
throw new Error("Deprecated option " + key + ": " + option.deprecated);
this.log.deprecate("Deprecated option " + key + ": " + option.deprecated);
}
if (val == null) {
@@ -509,7 +509,11 @@ export default class File {
code = code + "";
try {
return callback();
if (this.shouldIgnore()) {
return this.makeResult({ code, ignored: true });
} else {
return callback();
}
} catch (err) {
if (err._babel) {
throw err;

View File

@@ -47,6 +47,7 @@
},
"experimental": {
"type": "boolean",
"description": "allow use of experimental transformers",
"default": false
},

View File

@@ -3,7 +3,10 @@ import * as t from "../../types";
export default function (node) {
var lastNonDefault = 0;
for (var i = 0; i < node.params.length; i++) {
if (!t.isAssignmentPattern(node.params[i])) lastNonDefault = i + 1;
var param = node.params[i];
if (!t.isAssignmentPattern(param) && !t.isRestElement(param)) {
lastNonDefault = i + 1;
}
}
return lastNonDefault;
}

View File

@@ -0,0 +1 @@
if (VARIABLE_NAME === undefined) VARIABLE_NAME = DEFAULT_VALUE;

View File

@@ -200,6 +200,8 @@ class ClassTransformer {
}
}
body = body.concat(this.staticPropBody);
if (this.className) {
// named class with only a constructor
if (body.length === 1) return t.toExpression(body[0]);
@@ -214,8 +216,6 @@ class ClassTransformer {
t.inheritsComments(body[0], this.node);
}
body = body.concat(this.staticPropBody);
//
body.push(t.returnStatement(classRef));
@@ -293,7 +293,7 @@ class ClassTransformer {
this.pushMethod(node, path);
}
} else if (t.isClassProperty(node)) {
this.pushProperty(node);
this.pushProperty(node, path);
}
}
@@ -478,8 +478,8 @@ class ClassTransformer {
* Description
*/
pushProperty(node: { type: "ClassProperty" }) {
this.scope.traverse(node, collectPropertyReferencesVisitor, {
pushProperty(node: { type: "ClassProperty" }, path: NodePath) {
path.traverse(collectPropertyReferencesVisitor, {
references: this.instancePropRefs,
scope: this.scope
});

View File

@@ -1,4 +1,5 @@
import callDelegate from "../../helpers/call-delegate";
import getFunctionArity from "../../helpers/get-function-arity";
import * as util from "../../../util";
import * as t from "../../../types";
@@ -24,37 +25,54 @@ var iifeVisitor = {
export function Func/*tion*/(node, parent, scope, file) {
if (!hasDefaults(node)) return;
// ensure it's a block, useful for arrow functions
t.ensureBlock(node);
var state = {
iife: false,
scope: scope
};
var body = [];
//
var argsIdentifier = t.identifier("arguments");
argsIdentifier._shadowedFunctionLiteral = true;
var lastNonDefaultParam = 0;
var state = { iife: false, scope: scope };
var pushDefNode = function (left, right, i) {
var defNode = util.template("default-parameter", {
VARIABLE_NAME: left,
DEFAULT_VALUE: right,
ARGUMENT_KEY: t.literal(i),
ARGUMENTS: argsIdentifier
}, true);
// push a default parameter definition
function pushDefNode(left, right, i) {
var defNode;
if (exceedsLastNonDefault(i) || t.isPattern(left) || file.transformers["es6.spec.blockScoping"].canTransform()) {
defNode = util.template("default-parameter", {
VARIABLE_NAME: left,
DEFAULT_VALUE: right,
ARGUMENT_KEY: t.literal(i),
ARGUMENTS: argsIdentifier
}, true);
} else {
defNode = util.template("default-parameter-assign", {
VARIABLE_NAME: left,
DEFAULT_VALUE: right
}, true);
}
defNode._blockHoist = node.params.length - i;
body.push(defNode);
};
}
// check if an index exceeds the functions arity
function exceedsLastNonDefault(i) {
return i + 1 > lastNonDefaultParam;
}
//
var lastNonDefaultParam = getFunctionArity(node);
//
var params = this.get("params");
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (!param.isAssignmentPattern()) {
if (!param.isRestElement()) {
lastNonDefaultParam = i + 1;
}
if (!param.isIdentifier()) {
param.traverse(iifeVisitor, state);
}
@@ -69,9 +87,13 @@ export function Func/*tion*/(node, parent, scope, file) {
var left = param.get("left");
var right = param.get("right");
var placeholder = scope.generateUidIdentifier("x");
placeholder._isDefaultPlaceholder = true;
node.params[i] = placeholder;
if (exceedsLastNonDefault(i) || left.isPattern()) {
var placeholder = scope.generateUidIdentifier("x");
placeholder._isDefaultPlaceholder = true;
node.params[i] = placeholder;
} else {
node.params[i] = left.node;
}
if (!state.iife) {
if (right.isIdentifier() && scope.hasOwnBinding(right.node.name)) {

View File

@@ -11,7 +11,7 @@ export function AssignmentExpression() {
if (!left.isIdentifier()) return;
var binding = this.scope.getBinding(left.node.name);
if (!binding || binding.deoptValue) return;
if (!binding || binding.hasDeoptValue) return;
var evaluated = this.get("right").evaluate();
if (evaluated.confident) {
@@ -33,6 +33,25 @@ export function IfStatement() {
}
export var Scopable = {
enter() {
var funcScope = this.scope.getFunctionParent();
for (var name in this.scope.bindings) {
var binding = this.scope.bindings[name];
var deopt = false;
for (var path of (binding.constantViolations: Array)) {
var funcViolationScope = path.scope.getFunctionParent();
if (funcViolationScope !== funcScope) {
deopt = true;
break;
}
}
if (deopt) binding.deoptValue();
}
},
exit() {
for (var name in this.scope.bindings) {
var binding = this.scope.bindings[name];

View File

@@ -1,13 +1,6 @@
import type NodePath from "./index";
import * as t from "../../types";
const BOOLEAN_BINARY_OPERATORS = ["==", "===", "!=", "!==", ">", "<", ">=", "<=", "in", "instanceof"];
const NUMBER_BINARY_OPERATORS = ["-", "/", "*", "**", "&", "|", ">>", ">>>", "<<", "^"];
const BOOLEAN_UNARY_OPERATORS = ["delete"];
const NUMBER_UNARY_OPERATORS = ["+", "-", "++", "--", "~"];
const STRING_UNARY_OPERATORS = ["typeof"];
/**
* Description
*/
@@ -131,6 +124,11 @@ export function _inferTypeAnnotation(force?: boolean): ?Object {
var path = this.resolve();
var node = path.node;
if (!node && path.key === "init" && path.parentPath.isVariableDeclarator()) {
return t.voidTypeAnnotation();
}
if (!node) return;
if (node.typeAnnotation) {
@@ -190,16 +188,20 @@ export function _inferTypeAnnotation(force?: boolean): ?Object {
return t.genericTypeAnnotation(t.identifier("Function"));
}
if (path.isTemplateLiteral()) {
return t.stringTypeAnnotation();
}
if (path.isUnaryExpression()) {
let operator = node.operator;
if (operator === "void") {
return t.voidTypeAnnotation();
} else if (NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
return t.numberTypeAnnotation();
} else if (STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
return t.stringTypeAnnotation();
} else if (BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
return t.booleanTypeAnnotation();
}
}
@@ -207,9 +209,9 @@ export function _inferTypeAnnotation(force?: boolean): ?Object {
if (path.isBinaryExpression()) {
let operator = node.operator;
if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
return t.numberTypeAnnotation();
} else if (BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
return t.booleanTypeAnnotation();
} else if (operator === "+") {
var right = path.get("right").resolve();
@@ -256,15 +258,6 @@ export function _inferTypeAnnotation(force?: boolean): ?Object {
}
}
if (path.isUnaryExpression() && node.prefix) {
let operator = node.operator;
if (operator === "!") {
return t.booleanTypeAnnotation();
} else if (operator === "+" || operator === "-") {
return t.numberTypeAnnotation();
}
}
if (path.isLiteral()) {
var value = node.value;
if (typeof value === "string") return t.stringTypeAnnotation();
@@ -273,8 +266,11 @@ export function _inferTypeAnnotation(force?: boolean): ?Object {
if (node.regex) return t.genericTypeAnnotation(t.identifier("RegExp"));
}
if (path.isCallExpression()) {
var callee = path.get("callee").resolve();
var callPath;
if (path.isCallExpression()) callPath = path.get("callee");
if (path.isTaggedTemplateExpression()) callPath = path.get("tag");
if (callPath) {
var callee = callPath.resolve();
// todo: read typescript/flow interfaces
if (callee.isNodeType("Function")) return callee.node.returnType;
}

View File

@@ -1,4 +1,5 @@
import includes from "lodash/collection/includes";
import repeating from "repeating";
import type NodePath from "../path";
import type File from "../../transformation/file";
import traverse from "../index";
@@ -392,11 +393,20 @@ export default class Scope {
*/
dump() {
var sep = repeating("-", 60);
console.log(sep);
var scope = this;
do {
console.log(scope.block.type, "Bindings:", Object.keys(scope.bindings));
console.log("#", scope.block.type);
for (var name in scope.bindings) {
var binding = scope.bindings[name];
console.log(" -", name, {
constant: binding.constant,
references: binding.references
});
}
} while(scope = scope.parent);
console.log("-------------");
console.log(sep);
}
/**

View File

@@ -24,11 +24,17 @@ function registerType(type: string, skipAliasCheck?: boolean) {
};
}
export var STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
export var NATIVE_TYPE_NAMES = ["Array", "ArrayBuffer", "Boolean", "DataView", "Date", "Error", "EvalError", "Float32Array", "Float64Array", "Function", "Int8Array", "Int16Array", "Int32Array", "Map", "Number", "Object", "Proxy", "Promise", "RangeError", "ReferenceError", "RegExp", "Set", "String", "Symbol", "SyntaxError", "TypeError", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "URIError", "WeakMap", "WeakSet"];
export var FLATTENABLE_KEYS = ["body", "expressions"];
export var FOR_INIT_KEYS = ["left", "init"];
export var COMMENT_KEYS = ["leadingComments", "trailingComments"];
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"];
export const BOOLEAN_BINARY_OPERATORS = ["==", "===", "!=", "!==", ">", "<", ">=", "<=", "in", "instanceof"];
export const NUMBER_BINARY_OPERATORS = ["-", "/", "*", "**", "&", "|", ">>", ">>>", "<<", "^"];
export const BOOLEAN_UNARY_OPERATORS = ["delete", "!"];
export const NUMBER_UNARY_OPERATORS = ["+", "-", "++", "--", "~"];
export const STRING_UNARY_OPERATORS = ["typeof"];
export const VISITOR_KEYS = require("./visitor-keys");
export const BUILDER_KEYS = require("./builder-keys");

View File

@@ -0,0 +1,3 @@
function foo(a = "foo", b) {
}

View File

@@ -0,0 +1,5 @@
"use strict";
function foo(a, b) {
if (a === undefined) a = "foo";
}

View File

@@ -0,0 +1,13 @@
for (var key in foo) {
break;
foo();
}
function bar() {
yes();
bar();
return "wow";
nomore();
}
bar();

View File

@@ -0,0 +1,13 @@
"use strict";
for (var key in foo) {
break;
}
function bar() {
yes();
bar();
return "wow";
}
bar();

View File

@@ -1,4 +1,5 @@
{
"experimental": true,
"externalHelpers": true,
"noCheckAst": true,
"blacklist": ["regenerator"],