Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcc86c47bc | ||
|
|
b6df9b583b | ||
|
|
52ea7b5f59 | ||
|
|
7bff8239a1 | ||
|
|
04d79c1740 | ||
|
|
e387da7c2b | ||
|
|
53cf453480 | ||
|
|
341528ee4a | ||
|
|
5f6808ba92 | ||
|
|
0b2f1fedcb | ||
|
|
c3c94f0a4a | ||
|
|
f2d60aab9e | ||
|
|
ab6bb35a4f | ||
|
|
e11b943514 | ||
|
|
b44a6eb297 | ||
|
|
f3288ddb1f | ||
|
|
476aa44a90 | ||
|
|
c5589e9336 | ||
|
|
404eb2f972 | ||
|
|
366257915e | ||
|
|
e0cd9bdbe3 | ||
|
|
39854dc088 | ||
|
|
81132aa942 | ||
|
|
5ba2e6254b | ||
|
|
61ea720637 | ||
|
|
55357a331d | ||
|
|
5deaeba3a0 | ||
|
|
a38ae381e2 | ||
|
|
9a2e56f003 | ||
|
|
5bc78b0237 |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -13,6 +13,29 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 4.4.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Handle inferred function ids to be reassigned and deopt to a slower but working equivalent.
|
||||
* Don't unpack array patterns that have more elements than their right hand array expression.
|
||||
* **Polish**
|
||||
* Improve syntax highlighting in the code frame. Thanks [@lydell](https://github.com/lydell)!
|
||||
* **Internal**
|
||||
* Upgrade `acorn-babel`.
|
||||
|
||||
## 4.4.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `for...of` iterator break returns being duplicated.
|
||||
* Only call `return` on the iterator if it exists.
|
||||
* **Internal**
|
||||
* Rename `selfContained` transformer to `runtime`.
|
||||
|
||||
## 4.4.2
|
||||
|
||||
* **New Feature**
|
||||
* Add `moduleId` option for specifying a custom module id.
|
||||
|
||||
## 4.4.0
|
||||
|
||||
* **New Feature**
|
||||
|
||||
4
Makefile
4
Makefile
@@ -119,5 +119,5 @@ publish-core:
|
||||
bootstrap:
|
||||
npm install
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
cd vendor/regenerator && npm install
|
||||
cd vendor/compat-table && npm install object-assign
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For more information view the <a href="https://babeljs.io/">documentation</a>. For
|
||||
support visit the <a href="https://gitter.im/babel/babel">gitter room</a>.
|
||||
For more information view the <a href="https://babeljs.io/">documentation</a>. For questions
|
||||
and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before
|
||||
creating an issue.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
@@ -50,7 +50,10 @@ var _eval = function (code, filename) {
|
||||
experimental: program.experimental,
|
||||
playground: program.playground
|
||||
}).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
|
||||
return vm.runInThisContext(code, {
|
||||
filename: filename
|
||||
});
|
||||
};
|
||||
|
||||
if (program.eval || program.print) {
|
||||
|
||||
@@ -1,42 +1,59 @@
|
||||
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
|
||||
|
||||
var repeating = require("repeating");
|
||||
var tokenize = require("js-tokenizer");
|
||||
var chalk = require("chalk");
|
||||
var lineNumbers = require("line-numbers");
|
||||
var repeating = require("repeating");
|
||||
var jsTokens = require("js-tokens");
|
||||
var esutils = require("esutils");
|
||||
var chalk = require("chalk");
|
||||
var ary = require("lodash/function/ary");
|
||||
|
||||
var defs = {
|
||||
string1: "red",
|
||||
string2: "red",
|
||||
punct: ["white", "bold"],
|
||||
curly: "green",
|
||||
parens: ["blue", "bold"],
|
||||
square: ["yellow"],
|
||||
name: "white",
|
||||
keyword: ["cyan"],
|
||||
number: "magenta",
|
||||
regexp: "magenta",
|
||||
comment1: "grey",
|
||||
comment2: "grey"
|
||||
string: chalk.red,
|
||||
punctuation: chalk.white.bold,
|
||||
operator: chalk.white.bold,
|
||||
curly: chalk.green,
|
||||
parens: chalk.blue.bold,
|
||||
square: chalk.yellow,
|
||||
name: chalk.white,
|
||||
keyword: chalk.cyan,
|
||||
number: chalk.magenta,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.inverse
|
||||
};
|
||||
|
||||
var highlight = function (text) {
|
||||
var colorize = function (str, col) {
|
||||
if (!col) return str;
|
||||
var newline = /\r\n|[\n\r\u2028\u2029]/;
|
||||
|
||||
if (Array.isArray(col)) {
|
||||
col.forEach(function (col) {
|
||||
str = chalk[col](str);
|
||||
});
|
||||
} else {
|
||||
str = chalk[col](str);
|
||||
var highlight = function (text) {
|
||||
var tokenType = function (match) {
|
||||
var token = jsTokens.matchToToken(match);
|
||||
if (token.type === "name" && esutils.keyword.isKeywordES6(token.value)) {
|
||||
return "keyword";
|
||||
}
|
||||
return str;
|
||||
|
||||
if (token.type === "punctuation") {
|
||||
switch (token.value) {
|
||||
case "{":
|
||||
case "}":
|
||||
return "curly";
|
||||
case "(":
|
||||
case ")":
|
||||
return "parens";
|
||||
case "[":
|
||||
case "]":
|
||||
return "square";
|
||||
}
|
||||
}
|
||||
|
||||
return token.type;
|
||||
};
|
||||
|
||||
return tokenize(text, true).map(function (str) {
|
||||
var type = tokenize.type(str);
|
||||
return colorize(str, defs[type]);
|
||||
}).join("");
|
||||
return text.replace(jsTokens, function (match) {
|
||||
var type = tokenType(arguments);
|
||||
if (type in defs) {
|
||||
var colorize = ary(defs[type], 1);
|
||||
return match.split(newline).map(colorize).join("\n");
|
||||
}
|
||||
return match;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
@@ -46,33 +63,29 @@ module.exports = function (lines, lineNumber, colNumber) {
|
||||
lines = highlight(lines);
|
||||
}
|
||||
|
||||
lines = lines.split(/\r\n|[\n\r\u2028\u2029]/);
|
||||
lines = lines.split(newline);
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
var width = (end + "").length;
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
return "\n" + lines.slice(start, end).map(function (line, i) {
|
||||
var curr = i + start + 1;
|
||||
|
||||
var gutter = curr === lineNumber ? "> " : " ";
|
||||
|
||||
var sep = curr + repeating(" ", width + 1);
|
||||
gutter += sep + "| ";
|
||||
|
||||
var str = gutter + line;
|
||||
|
||||
if (colNumber && curr === lineNumber) {
|
||||
str += "\n";
|
||||
str += repeating(" ", gutter.length - 2);
|
||||
str += "|" + repeating(" ", colNumber) + "^";
|
||||
return "\n" + lineNumbers(lines.slice(start, end), {
|
||||
start: start + 1,
|
||||
before: " ",
|
||||
after: " | ",
|
||||
transform: function (params) {
|
||||
if (params.number !== lineNumber) {
|
||||
return;
|
||||
}
|
||||
if (colNumber) {
|
||||
params.line += "\n" + params.before + repeating(" ", params.width) +
|
||||
params.after + repeating(" ", colNumber - 1) + "^";
|
||||
}
|
||||
params.before = params.before.replace(/^./, ">");
|
||||
}
|
||||
|
||||
return str;
|
||||
}).join("\n");
|
||||
};
|
||||
|
||||
@@ -89,7 +89,7 @@ File.validOptions = [
|
||||
"compact",
|
||||
|
||||
"resolveModuleSource",
|
||||
"getModuleName",
|
||||
"moduleId",
|
||||
|
||||
// legacy
|
||||
"format",
|
||||
@@ -138,6 +138,10 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
opts.sourceRoot = slash(opts.sourceRoot);
|
||||
}
|
||||
|
||||
if (opts.moduleId) {
|
||||
opts.moduleIds = true;
|
||||
}
|
||||
|
||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
@@ -172,7 +176,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
}
|
||||
|
||||
if (opts.externalHelpers) {
|
||||
this.set("runtimeIdentifier", t.identifier("babelHelpers"));
|
||||
this.set("helpersNamespace", t.identifier("babelHelpers"));
|
||||
}
|
||||
|
||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
@@ -329,7 +333,7 @@ File.prototype.addHelper = function (name) {
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var runtime = this.get("runtimeIdentifier");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (runtime) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, name);
|
||||
|
||||
@@ -5,15 +5,13 @@ var t = require("../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: state.id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
// check if this node is a referenced identifier that matches the same as our
|
||||
// function id
|
||||
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.id);
|
||||
var localDeclar = scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
@@ -21,33 +19,100 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var wrap = function (state, method, id, scope) {
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
return util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id.name + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
method.id = id;
|
||||
return method;
|
||||
}
|
||||
};
|
||||
|
||||
var visit = function (node, name, scope) {
|
||||
var state = {
|
||||
selfAssignment: false,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(name),
|
||||
references: [],
|
||||
name: name,
|
||||
};
|
||||
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
// the function, this is important as there are caveats associated
|
||||
|
||||
var bindingInfo = scope.getOwnBindingInfo(name);
|
||||
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.kind === "param") {
|
||||
// safari will blow up in strict mode with code like:
|
||||
//
|
||||
// var t = function t(t) {};
|
||||
//
|
||||
// with the error:
|
||||
//
|
||||
// Cannot declare a parameter named 't' as it shadows the name of a
|
||||
// strict mode function.
|
||||
//
|
||||
// this isn't to the spec and they've invented this behaviour which is
|
||||
// **extremely** annoying so we avoid setting the name if it has a param
|
||||
// with the same id
|
||||
state.selfReference = true;
|
||||
} else {
|
||||
// otherwise it's defined somewhere in scope like:
|
||||
//
|
||||
// var t = function () {
|
||||
// var t = 2;
|
||||
// };
|
||||
//
|
||||
// so we can safely just set the id and move along as it shadows the
|
||||
// bound function id
|
||||
}
|
||||
} else {
|
||||
scope.traverse(node, visitor, state);
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.property = function (node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var state = {
|
||||
id: id,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(id),
|
||||
};
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
var name = t.toIdentifier(key.value);
|
||||
var id = t.identifier(name);
|
||||
|
||||
var method = node.value;
|
||||
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
node.value = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
method.id = key;
|
||||
}
|
||||
var state = visit(method, name, scope);
|
||||
node.value = wrap(state, method, id, scope);
|
||||
};
|
||||
|
||||
exports.bare = function (node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
var id;
|
||||
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
|
||||
// { foo: function () {} };
|
||||
id = parent.key;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
// var foo = function () {};
|
||||
id = parent.id;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!t.isIdentifier(id)) return;
|
||||
|
||||
var name = t.toIdentifier(id.name);
|
||||
id = t.identifier(name);
|
||||
|
||||
var state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
};
|
||||
|
||||
@@ -146,7 +146,7 @@ DefaultFormatter.prototype.isLocalReference = function (node, scope) {
|
||||
|
||||
DefaultFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
if (opts.getModuleName) return opts.getModuleName(opts.filename);
|
||||
if (opts.moduleId) return opts.moduleId;
|
||||
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
(function () {
|
||||
function GET_OUTER_ID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
return FUNCTION;
|
||||
})()
|
||||
7
lib/babel/transformation/templates/named-function.js
Normal file
7
lib/babel/transformation/templates/named-function.js
Normal file
@@ -0,0 +1,7 @@
|
||||
(function () {
|
||||
function GET_OUTER_ID() {
|
||||
return FUNCTION_ID;
|
||||
}
|
||||
|
||||
return FUNCTION;
|
||||
})()
|
||||
@@ -1 +1,3 @@
|
||||
{}
|
||||
{
|
||||
"selfContained": "runtime"
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ var isLet = function (node, parent) {
|
||||
};
|
||||
|
||||
var isLetInitable = function (node, parent) {
|
||||
return !t.isFor(parent) || t.isFor(parent) && parent.left !== node;
|
||||
return !t.isFor(parent) || !t.isFor(parent, { left: node });
|
||||
};
|
||||
|
||||
var isVar = function (node, parent) {
|
||||
|
||||
@@ -168,6 +168,7 @@ DestructuringTransformer.prototype.canUnpackArrayPattern = function (pattern, ar
|
||||
|
||||
// pattern has less elements than the array and doesn't have a rest so some
|
||||
// elements wont be evaluated
|
||||
if (pattern.elements.length > arr.elements.length) return;
|
||||
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
|
||||
|
||||
// deopt on holes
|
||||
@@ -418,7 +419,7 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
|
||||
var variableDeclarationhasPattern = function (node) {
|
||||
var variableDeclarationHasPattern = function (node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (t.isPattern(node.declarations[i].id)) {
|
||||
return true;
|
||||
@@ -429,7 +430,7 @@ var variableDeclarationhasPattern = function (node) {
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
if (!variableDeclarationhasPattern(node)) return;
|
||||
if (!variableDeclarationHasPattern(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
var declar;
|
||||
|
||||
@@ -53,8 +53,9 @@ var breakVisitor = {
|
||||
var ret = t.expressionStatement(
|
||||
t.callExpression(t.memberExpression(state.iteratorKey, t.identifier("return")), [])
|
||||
);
|
||||
if (state.wrapReturn) ret = state.wrapReturn(ret);
|
||||
ret = state.wrapReturn(ret);
|
||||
|
||||
this.skip();
|
||||
return [ret, node];
|
||||
}
|
||||
}
|
||||
@@ -99,7 +100,13 @@ var loose = function (node, parent, scope, file) {
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
wrapReturn: function (node) {
|
||||
return t.ifStatement(t.unaryExpression("!", isArrayKey, true), node);
|
||||
return t.ifStatement(
|
||||
t.logicalExpression(
|
||||
"&&",
|
||||
t.unaryExpression("!", isArrayKey, true),
|
||||
t.memberExpression(iteratorKey, t.identifier("return")
|
||||
)
|
||||
), node);
|
||||
},
|
||||
label: t.isLabeledStatement(parent) && parent.label.name
|
||||
});
|
||||
@@ -145,6 +152,9 @@ var spec = function (node, parent, scope, file) {
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
wrapReturn: function (node) {
|
||||
return t.ifStatement(t.memberExpression(iteratorKey, t.identifier("return")), node);
|
||||
},
|
||||
label: t.isLabeledStatement(parent) && parent.label.name
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ var t = require("../../../types");
|
||||
exports.check = require("../internal/modules").check;
|
||||
|
||||
exports.ImportDeclaration = function (node, parent, scope, file) {
|
||||
// flow type
|
||||
if (node.isType) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
if (node.specifiers.length) {
|
||||
@@ -24,6 +27,9 @@ exports.ImportDeclaration = function (node, parent, scope, file) {
|
||||
};
|
||||
|
||||
exports.ExportDeclaration = function (node, parent, scope, file) {
|
||||
// flow type
|
||||
if (t.isTypeAlias(node.declaration)) return;
|
||||
|
||||
var nodes = [];
|
||||
var i;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ module.exports = {
|
||||
// needs to be after `regenerator` due to needing `regeneratorRuntime` references
|
||||
// needs to be after `es6.forOf` due to needing `Symbol.iterator` references
|
||||
// needs to be before `es6.modules` due to dynamic imports
|
||||
selfContained: require("./other/self-contained"),
|
||||
runtime: require("./other/runtime"),
|
||||
|
||||
// needs to be before `_blockHoist` due to function hoisting etc
|
||||
"es6.modules": require("./es6/modules"),
|
||||
|
||||
@@ -24,6 +24,9 @@ exports.ImportDeclaration = resolveModuleSource;
|
||||
exports.ExportDeclaration = function (node, parent, scope) {
|
||||
resolveModuleSource.apply(null, arguments);
|
||||
|
||||
// flow type
|
||||
if (node.isType) return;
|
||||
|
||||
var declar = node.declaration;
|
||||
|
||||
if (node.default) {
|
||||
|
||||
@@ -82,7 +82,7 @@ exports.Program = function (node, parent, scope, file) {
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
file.setDynamic("runtimeIdentifier", function () {
|
||||
file.setDynamic("helpersNamespace", function () {
|
||||
return file.addImport("babel-runtime/helpers", "babelHelpers");
|
||||
});
|
||||
|
||||
@@ -1,95 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../../types");
|
||||
var util = require("../../../util");
|
||||
var nameMethod = require("../../helpers/name-method");
|
||||
|
||||
var propertyFunctionVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isReferencedIdentifier(node, parent, { name: state.name }) && scope.getBindingIdentifier(node.name) === state.binding) {
|
||||
return state.getOuter();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//exports.ArrowFunctionExpression =
|
||||
exports.FunctionExpression = function (node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
var id;
|
||||
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
|
||||
// { foo: function () {} };
|
||||
id = parent.key;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
// var foo = function () {};
|
||||
id = parent.id;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!t.isIdentifier(id)) return;
|
||||
|
||||
var name = t.toIdentifier(id.name);
|
||||
id = t.identifier(name);
|
||||
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
// the function, this is important as there are caveats associated
|
||||
|
||||
var bindingInfo = scope.getOwnBindingInfo(name);
|
||||
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.type === "param") {
|
||||
// safari will blow up in strict mode with code like:
|
||||
//
|
||||
// var t = function t(t) {};
|
||||
//
|
||||
// with the error:
|
||||
//
|
||||
// Cannot declare a parameter named 't' as it shadows the name of a
|
||||
// strict mode function.
|
||||
//
|
||||
// this isn't to the spec and they've invented this behaviour which is
|
||||
// **extremely** annoying so we avoid setting the name if it has a param
|
||||
// with the same id
|
||||
} else {
|
||||
// otherwise it's defined somewhere in scope like:
|
||||
//
|
||||
// var t = function () {
|
||||
// var t = 2;
|
||||
// };
|
||||
//
|
||||
// so we can safely just set the id and move along as it shadows the
|
||||
// bound function id
|
||||
node.id = id;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var binding = scope.getBindingIdentifier(name);
|
||||
var outerId;
|
||||
|
||||
scope.traverse(node, propertyFunctionVisitor, {
|
||||
name: name,
|
||||
binding: binding,
|
||||
|
||||
getOuter: function () {
|
||||
return t.callExpression(
|
||||
outerId || (outerId = scope.generateUidIdentifier("getOuter")),
|
||||
[]
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
node.id = id;
|
||||
|
||||
if (outerId) {
|
||||
return util.template("named-func", {
|
||||
GET_OUTER_ID: outerId,
|
||||
FUNCTION: node,
|
||||
ID: id
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.FunctionExpression = nameMethod.bare;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "4.4.1",
|
||||
"version": "4.4.5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -36,7 +36,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-babel": "0.11.1-33",
|
||||
"acorn-babel": "0.11.1-34",
|
||||
"ast-types": "~0.6.1",
|
||||
"chalk": "^0.5.1",
|
||||
"chokidar": "^0.12.6",
|
||||
@@ -49,8 +49,9 @@
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.2.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokenizer": "^1.3.3",
|
||||
"js-tokens": "0.4.1",
|
||||
"leven": "^1.0.1",
|
||||
"line-numbers": "0.2.0",
|
||||
"lodash": "^3.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "4.3.0",
|
||||
"version": "4.4.4",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
var [a, [b], [c], d] = ["hello", [", ", "junk"], ["world"]];
|
||||
var [a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];
|
||||
|
||||
@@ -4,4 +4,3 @@ var a = "hello";
|
||||
var _ref = [", ", "junk"];
|
||||
var b = _ref[0];
|
||||
var c = "world";
|
||||
var d;
|
||||
|
||||
@@ -17,7 +17,7 @@ foo: for (var _iterator = foo(), _isArray = Array.isArray(_iterator), _i = 0, _i
|
||||
var x = _ref;
|
||||
|
||||
while (true) {
|
||||
if (!_isArray) _iterator["return"]();
|
||||
if (!_isArray && _iterator["return"]) _iterator["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ foo: for (var _iterator3 = foo(), _isArray3 = Array.isArray(_iterator3), _i3 = 0
|
||||
}
|
||||
|
||||
var x = _ref3;
|
||||
if (!_isArray3) _iterator3["return"]();
|
||||
if (!_isArray3 && _iterator3["return"]) _iterator3["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ for (var _iterator4 = foo(), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _it
|
||||
}
|
||||
|
||||
var x = _ref4;
|
||||
if (!_isArray4) _iterator4["return"]();
|
||||
if (!_isArray4 && _iterator4["return"]) _iterator4["return"]();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ foo: for (var _iterator = foo()[Symbol.iterator](), _step; !(_step = _iterator.n
|
||||
var x = _step.value;
|
||||
|
||||
while (true) {
|
||||
_iterator["return"]();
|
||||
if (_iterator["return"]) _iterator["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
@@ -22,8 +22,7 @@ foo: for (var _iterator2 = foo()[Symbol.iterator](), _step2; !(_step2 = _iterato
|
||||
|
||||
foo: for (var _iterator3 = foo()[Symbol.iterator](), _step3; !(_step3 = _iterator3.next()).done;) {
|
||||
var x = _step3.value;
|
||||
|
||||
_iterator3["return"]();
|
||||
if (_iterator3["return"]) _iterator3["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
@@ -32,8 +31,7 @@ foo: for (var _iterator3 = foo()[Symbol.iterator](), _step3; !(_step3 = _iterato
|
||||
|
||||
for (var _iterator4 = foo()[Symbol.iterator](), _step4; !(_step4 = _iterator4.next()).done;) {
|
||||
var x = _step4.value;
|
||||
|
||||
_iterator4["return"]();
|
||||
if (_iterator4["return"]) _iterator4["return"]();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
exports.getModuleName = function () {
|
||||
return "my custom module name";
|
||||
};
|
||||
|
||||
exports.moduleIds = true;
|
||||
4
test/fixtures/transformation/es6-modules-amd/get-module-name-option/options.json
vendored
Normal file
4
test/fixtures/transformation/es6-modules-amd/get-module-name-option/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
exports.getModuleName = function () {
|
||||
return "my custom module name";
|
||||
};
|
||||
|
||||
exports.moduleIds = true;
|
||||
4
test/fixtures/transformation/es6-modules-system/get-module-name-option/options.json
vendored
Normal file
4
test/fixtures/transformation/es6-modules-system/get-module-name-option/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
exports.getModuleName = function () {
|
||||
return "my custom module name";
|
||||
};
|
||||
|
||||
exports.moduleIds = true;
|
||||
4
test/fixtures/transformation/es6-modules-umd/get-module-name-option/options.json
vendored
Normal file
4
test/fixtures/transformation/es6-modules-umd/get-module-name-option/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
var t = function (t = "foo", f = 5) {
|
||||
return t + " bar " + f;
|
||||
var t = function (e = "foo", f = 5) {
|
||||
return e + " bar " + f;
|
||||
};
|
||||
|
||||
var a = function (t, f = 5) {
|
||||
return t + " bar " + f;
|
||||
var a = function (e, f = 5) {
|
||||
return e + " bar " + f;
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var t = function t() {
|
||||
var t = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
var e = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
var f = arguments[1] === undefined ? 5 : arguments[1];
|
||||
|
||||
return t + " bar " + f;
|
||||
return e + " bar " + f;
|
||||
};
|
||||
|
||||
var a = function a(t) {
|
||||
var a = function a(e) {
|
||||
var f = arguments[1] === undefined ? 5 : arguments[1];
|
||||
|
||||
return t + " bar " + f;
|
||||
return e + " bar " + f;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var t = function (t = "foo") {
|
||||
return t + " bar";
|
||||
var t = function (f = "foo") {
|
||||
return f + " bar";
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var t = function t() {
|
||||
var t = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
var f = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
|
||||
return t + " bar";
|
||||
return f + " bar";
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
var bar = {
|
||||
foo() {
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var bar = {
|
||||
foo() {
|
||||
var foo = 41;
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var foobar = 123;
|
||||
var foobar2 = {
|
||||
foobar() {
|
||||
console.log(foobar);
|
||||
}
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var bar = {
|
||||
foo: (function () {
|
||||
function _getOuter() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
return function foo() {
|
||||
console.log(_getOuter());
|
||||
};
|
||||
})()
|
||||
};
|
||||
|
||||
var bar = {
|
||||
foo: function foo() {
|
||||
var foo = 41;
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var foobar = 123;
|
||||
var foobar2 = {
|
||||
foobar: (function () {
|
||||
function _getOuter() {
|
||||
return foobar;
|
||||
}
|
||||
|
||||
return function foobar() {
|
||||
console.log(_getOuter());
|
||||
};
|
||||
})()
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"blacklist": ["es6.tailCall"]
|
||||
}
|
||||
4
test/fixtures/transformation/runtime/options.json
vendored
Normal file
4
test/fixtures/transformation/runtime/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"optional": ["runtime"],
|
||||
"experimental": true
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"optional": ["selfContained"],
|
||||
"experimental": true
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
var obj = {
|
||||
f: function () {
|
||||
(function f() {
|
||||
console.log(f);
|
||||
})();
|
||||
},
|
||||
|
||||
g: function () {
|
||||
console.log(g);
|
||||
},
|
||||
|
||||
h: function () {
|
||||
console.log(h);
|
||||
},
|
||||
|
||||
m: function () {
|
||||
doSmth();
|
||||
}
|
||||
};
|
||||
|
||||
var f = function () {
|
||||
console.log(f, g);
|
||||
};
|
||||
|
||||
var g = function () {
|
||||
doSmth();
|
||||
};
|
||||
48
test/fixtures/transformation/spec-function-name/all/actual.js
vendored
Normal file
48
test/fixtures/transformation/spec-function-name/all/actual.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
var obj = {
|
||||
// localy declared variable
|
||||
f: function () {
|
||||
(function f() {
|
||||
console.log(f);
|
||||
})();
|
||||
},
|
||||
|
||||
// self reference
|
||||
h: function () {
|
||||
console.log(h);
|
||||
},
|
||||
|
||||
// no reference
|
||||
m: function () {
|
||||
doSmth();
|
||||
}
|
||||
};
|
||||
|
||||
// locally declared variable
|
||||
var f = function () {
|
||||
var f = 2;
|
||||
};
|
||||
|
||||
// self reference
|
||||
var f = function () {
|
||||
console.log(f, g);
|
||||
};
|
||||
|
||||
// no reference
|
||||
var g = function () {
|
||||
doSmth();
|
||||
};
|
||||
|
||||
// param with the same name as id
|
||||
var h = function (h) {
|
||||
|
||||
};
|
||||
|
||||
// assignment to self
|
||||
var i = function () {
|
||||
i = 5;
|
||||
};
|
||||
|
||||
// assignment to self
|
||||
var j = function () {
|
||||
({ j }) = 5;
|
||||
};
|
||||
89
test/fixtures/transformation/spec-function-name/all/expected.js
vendored
Normal file
89
test/fixtures/transformation/spec-function-name/all/expected.js
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
|
||||
var obj = {
|
||||
// localy declared variable
|
||||
f: function f() {
|
||||
(function f() {
|
||||
console.log(f);
|
||||
})();
|
||||
},
|
||||
|
||||
// self reference
|
||||
h: (function (_h) {
|
||||
var _hWrapper = function h() {
|
||||
return _h.apply(this, arguments);
|
||||
};
|
||||
|
||||
_hWrapper.toString = function () {
|
||||
return _h.toString();
|
||||
};
|
||||
|
||||
return _hWrapper;
|
||||
})(function () {
|
||||
console.log(h);
|
||||
}),
|
||||
|
||||
// no reference
|
||||
m: function m() {
|
||||
doSmth();
|
||||
}
|
||||
};
|
||||
|
||||
// locally declared variable
|
||||
var f = function f() {
|
||||
var f = 2;
|
||||
};
|
||||
|
||||
// self reference
|
||||
var f = (function (_f) {
|
||||
var _fWrapper = function f() {
|
||||
return _f.apply(this, arguments);
|
||||
};
|
||||
|
||||
_fWrapper.toString = function () {
|
||||
return _f.toString();
|
||||
};
|
||||
|
||||
return _fWrapper;
|
||||
})(function () {
|
||||
console.log(f, g);
|
||||
});
|
||||
|
||||
// no reference
|
||||
var g = function g() {
|
||||
doSmth();
|
||||
};
|
||||
|
||||
// param with the same name as id
|
||||
var h = (function (_h) {
|
||||
var _hWrapper = function h() {
|
||||
return _h.apply(this, arguments);
|
||||
};
|
||||
|
||||
_hWrapper.toString = function () {
|
||||
return _h.toString();
|
||||
};
|
||||
|
||||
return _hWrapper;
|
||||
})(function (h) {});
|
||||
|
||||
// assignment to self
|
||||
var i = (function (_i) {
|
||||
var _iWrapper = function i() {
|
||||
return _i.apply(this, arguments);
|
||||
};
|
||||
|
||||
_iWrapper.toString = function () {
|
||||
return _i.toString();
|
||||
};
|
||||
|
||||
return _iWrapper;
|
||||
})(function () {
|
||||
i = 5;
|
||||
});
|
||||
|
||||
// assignment to self
|
||||
var j = function j() {
|
||||
var _ref = 5;
|
||||
j = _ref.j;
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _selfGlobal = typeof global === "undefined" ? self : global;
|
||||
var obj = {
|
||||
f: function f() {
|
||||
(function f() {
|
||||
console.log(f);
|
||||
})();
|
||||
},
|
||||
|
||||
g: (function () {
|
||||
function _getOuter() {
|
||||
return g;
|
||||
}
|
||||
|
||||
return function g() {
|
||||
console.log(_getOuter());
|
||||
};
|
||||
})(),
|
||||
|
||||
h: function h() {
|
||||
console.log(_selfGlobal.h);
|
||||
},
|
||||
|
||||
m: function m() {
|
||||
doSmth();
|
||||
}
|
||||
};
|
||||
|
||||
var f = (function () {
|
||||
function _getOuter() {
|
||||
return f;
|
||||
}
|
||||
|
||||
return function f() {
|
||||
console.log(_getOuter(), g);
|
||||
};
|
||||
})();
|
||||
|
||||
var g = function g() {
|
||||
doSmth();
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"whitelist": ["spec.functionName"]
|
||||
}
|
||||
Reference in New Issue
Block a user