Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c6660d21 | ||
|
|
9676666e7c | ||
|
|
388133642d | ||
|
|
23b5eeb72f | ||
|
|
db36c3a7c2 | ||
|
|
e841b88cbc | ||
|
|
3d874f2479 | ||
|
|
228719102a | ||
|
|
c6ce1a248c | ||
|
|
ba9b85f64b | ||
|
|
56c868efee | ||
|
|
1f3c3832ba | ||
|
|
3b04a8c648 | ||
|
|
2270057b54 | ||
|
|
c3206aa9a4 | ||
|
|
1912d1b26a | ||
|
|
9208e7e594 | ||
|
|
ce332b3384 | ||
|
|
a567531f77 | ||
|
|
9cce72def0 | ||
|
|
2d8581c6dc | ||
|
|
14a000396a | ||
|
|
4c41f5a22f | ||
|
|
6be2a6e02a | ||
|
|
0a4fc16ca0 | ||
|
|
25d8377411 | ||
|
|
14267a788d | ||
|
|
ba5c5760b1 | ||
|
|
49904b3ab3 | ||
|
|
a212f035e4 | ||
|
|
ea471a6a17 | ||
|
|
f5bae0b696 | ||
|
|
9ec9e13aeb | ||
|
|
0b042b2681 | ||
|
|
83b4d12884 | ||
|
|
98d555498d | ||
|
|
fdc05cb977 | ||
|
|
928ebda5bc | ||
|
|
0a2003af66 |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -11,6 +11,16 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.6.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Multiline JSX string literals are now supported.
|
||||
* Fix scope tracking import specifiers incorrectly.
|
||||
* Fix templates incorrectly recursing into their replacements.
|
||||
* **Internal**
|
||||
* Type inferrence now extends to function return types.
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 3.6.0
|
||||
|
||||
* **New Feature**
|
||||
@@ -19,6 +29,7 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
* Completely reimplemented scope tracking, can now track types and optimise certain helpers based on it.
|
||||
* Extremely fast tail recursion optimisation implementation. Thanks [@RReverser](https://github.com/RReverser)!
|
||||
* **Internal**
|
||||
* `kexec` has been removed as an optional dependency and must be user installed.
|
||||
* Upgrade `regenerator-6to5`.
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Upgrade `core-js`.
|
||||
|
||||
@@ -278,7 +278,7 @@ File.prototype.addImport = function (source, name) {
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
if (!id) {
|
||||
id = this.dynamicImportIds[name] = this.generateUidIdentifier(name);
|
||||
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
@@ -312,7 +312,7 @@ File.prototype.addHelper = function (name) {
|
||||
} else {
|
||||
var ref = util.template(name);
|
||||
ref._compact = true;
|
||||
var uid = this.generateUidIdentifier(name);
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
@@ -443,30 +443,3 @@ File.prototype.generate = function () {
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
File.prototype.generateUid = function (name, scope) {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "");
|
||||
|
||||
scope = scope || this.scope;
|
||||
|
||||
var uid;
|
||||
var i = 0;
|
||||
do {
|
||||
uid = this._generateUid(name, i);
|
||||
i++;
|
||||
} while (scope.hasBinding(uid) || scope.hasGlobal(uid));
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||
scope = scope || this.scope;
|
||||
var id = t.identifier(this.generateUid(name, scope));
|
||||
scope.getFunctionParent().registerBinding("uid", id);
|
||||
return id;
|
||||
};
|
||||
|
||||
File.prototype._generateUid = function (name, i) {
|
||||
var id = name;
|
||||
if (i > 1) id += i;
|
||||
return "_" + id;
|
||||
};
|
||||
|
||||
@@ -46,6 +46,11 @@ module.exports = function (exports, opts) {
|
||||
exports.JSXAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
|
||||
if (t.isLiteral(value) && isString(value.value)) {
|
||||
value.value = value.value.replace(/\n\s+/g, " ");
|
||||
}
|
||||
|
||||
return t.inherits(t.property("init", node.name, value), node);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,7 +143,7 @@ ReplaceSupers.prototype.getThisReference = function () {
|
||||
if (this.topLevelThisReference) {
|
||||
return this.topLevelThisReference;
|
||||
} else {
|
||||
var ref = this.topLevelThisReference = this.file.generateUidIdentifier("this");
|
||||
var ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this");
|
||||
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||
]));
|
||||
|
||||
@@ -9,8 +9,9 @@ var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function DefaultFormatter(file) {
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
|
||||
this.hasNonDefaultExports = false;
|
||||
|
||||
@@ -212,9 +213,6 @@ DefaultFormatter.prototype.checkExportIdentifier = function (node) {
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
var inherits = false;
|
||||
if (node.specifiers.length === 1) inherits = node;
|
||||
|
||||
if (node.source) {
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ AMDFormatter.prototype.getModuleName = function () {
|
||||
};
|
||||
|
||||
AMDFormatter.prototype._getExternalReference = function (node) {
|
||||
return this.file.generateUidIdentifier(node.source.value);
|
||||
return this.scope.generateUidIdentifier(node.source.value);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importDeclaration = function (node) {
|
||||
|
||||
@@ -93,7 +93,7 @@ CommonJSFormatter.prototype._getExternalReference = function (node, nodes) {
|
||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||
|
||||
if (this.localImportOccurences[source] > 1) {
|
||||
var uid = this.file.generateUidIdentifier(source);
|
||||
var uid = this.scope.generateUidIdentifier(source);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, call)
|
||||
]));
|
||||
|
||||
@@ -12,7 +12,7 @@ var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportIdentifier = file.generateUidIdentifier("export");
|
||||
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
||||
this.noInteropRequireExport = true;
|
||||
this.noInteropRequireImport = true;
|
||||
|
||||
@@ -29,7 +29,7 @@ SystemFormatter.prototype._addImportSource = function (node, exportNode) {
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportsWildcard = function (objectIdentifier, node) {
|
||||
var leftIdentifier = this.file.generateUidIdentifier("key");
|
||||
var leftIdentifier = this.scope.generateUidIdentifier("key");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
|
||||
var left = t.variableDeclaration("var", [
|
||||
|
||||
1
lib/6to5/transformation/templates/corejs-is-iterator.js
Normal file
1
lib/6to5/transformation/templates/corejs-is-iterator.js
Normal file
@@ -0,0 +1 @@
|
||||
CORE_ID.$for.isIterable(VALUE);
|
||||
@@ -1,12 +1,14 @@
|
||||
(function (arr, i) {
|
||||
if (Array.isArray(arr)) {
|
||||
return arr;
|
||||
} else {
|
||||
} else if (Symbol.iterator in Object(arr)) {
|
||||
var _arr = [];
|
||||
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
_arr.push(_step.value);
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
return _arr;
|
||||
} else {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ exports.ClassExpression = function (node, parent, scope, file) {
|
||||
* @param {Node} node
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @param {Boolean} closure
|
||||
* @param {Boolean} isStatement
|
||||
*/
|
||||
|
||||
function ClassTransformer(node, file, scope, isStatement) {
|
||||
@@ -99,8 +99,7 @@ ClassTransformer.prototype.run = function () {
|
||||
closureArgs.push(superName);
|
||||
|
||||
if (!t.isIdentifier(superName)) {
|
||||
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
superName = superRef;
|
||||
superName = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
}
|
||||
|
||||
closureParams.push(superName);
|
||||
@@ -207,7 +206,7 @@ ClassTransformer.prototype.buildBody = function () {
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a method to it's respective mutatorMap.
|
||||
* Push a method to its respective mutatorMap.
|
||||
*
|
||||
* @param {Node} node MethodDefinition
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,8 @@ exports.check = function (node) {
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
|
||||
if (t.isMemberExpression(node.left || node.argument)) return;
|
||||
|
||||
var ids = t.getBindingIdentifiers(node);
|
||||
|
||||
for (var name in ids) {
|
||||
|
||||
@@ -18,7 +18,7 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
// inherit comments from the original loop
|
||||
t.inheritsComments(loop, node);
|
||||
|
||||
// ensure that it's a block so we can take all it's statemetns
|
||||
// ensure that it's a block so we can take all its statements
|
||||
t.ensureBlock(node);
|
||||
|
||||
// add the value declaration to the new loop body
|
||||
|
||||
@@ -3,7 +3,8 @@ var t = require("../../../types");
|
||||
exports.optional = true;
|
||||
|
||||
exports.ExpressionStatement = function (node) {
|
||||
// remove consequenceless expressions such as local variables and literals
|
||||
// remove consequence-less expressions such as local variables and literals
|
||||
// note: will remove directives
|
||||
//
|
||||
// var foo = true; foo; -> var foo = true;
|
||||
// "foo"; ->
|
||||
@@ -33,7 +34,7 @@ exports.IfStatement = {
|
||||
//
|
||||
|
||||
if (t.isLiteral(test) && test.value) {
|
||||
return alternate;
|
||||
return consequent;
|
||||
}
|
||||
|
||||
// we can check if a test will be falsy 100% and if so we can inline the
|
||||
@@ -66,8 +67,7 @@ exports.IfStatement = {
|
||||
// if (foo) {} else { bar; } -> if (!foo) { bar; }
|
||||
//
|
||||
|
||||
if (t.blockStatement(consequent) && !consequent.body.length &&
|
||||
t.isBlockStatement(alternate) && alternate.body.length) {
|
||||
if (t.blockStatement(consequent) && !consequent.body.length && t.isBlockStatement(alternate) && alternate.body.length) {
|
||||
node.consequent = node.alternate;
|
||||
node.alternate = null;
|
||||
node.test = t.unaryExpression("!", test, true);
|
||||
|
||||
@@ -40,20 +40,34 @@ var astVisitor = {
|
||||
} else if (t.isCallExpression(node)) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
if (node.arguments.length) return;
|
||||
|
||||
var callee = node.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!callee.computed) return;
|
||||
if (node.arguments.length) return false;
|
||||
|
||||
if (!t.isMemberExpression(callee)) return false;
|
||||
if (!callee.computed) return false;
|
||||
|
||||
prop = callee.property;
|
||||
if (!t.isIdentifier(prop.object, { name: "Symbol" })) return;
|
||||
if (!t.isIdentifier(prop.property, { name: "iterator" })) return;
|
||||
if (!t.isIdentifier(prop.object, { name: "Symbol" })) return false;
|
||||
if (!t.isIdentifier(prop.property, { name: "iterator" })) return false;
|
||||
|
||||
return util.template("corejs-iterator", {
|
||||
CORE_ID: file.get("coreIdentifier"),
|
||||
VALUE: callee.object
|
||||
});
|
||||
} else if (t.isBinaryExpression(node)) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
|
||||
var left = node.left;
|
||||
if (!t.isMemberExpression(left)) return;
|
||||
if (!t.isIdentifier(left.object, { name: "Symbol" })) return;
|
||||
if (!t.isIdentifier(left.property, { name: "iterator" })) return;
|
||||
|
||||
return util.template("corejs-is-iterator", {
|
||||
CORE_ID: file.get("coreIdentifier"),
|
||||
VALUE: node.right
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -83,7 +97,7 @@ exports.pre = function (file) {
|
||||
};
|
||||
|
||||
exports.Identifier = function (node, parent, scope, file) {
|
||||
if (node.name === "regeneratorRuntime" && t.isReferenced(node, parent)) {
|
||||
if (t.isReferencedIdentifier(node, parent, { name: "regeneratorRuntime" })) {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ exports.BindMemberExpression = function (node, parent, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.BindFunctionExpression = function (node, parent, scope, file) {
|
||||
exports.BindFunctionExpression = function (node, parent, scope) {
|
||||
var buildCall = function (args) {
|
||||
var param = scope.generateUidIdentifier("val");
|
||||
return t.functionExpression(null, [param], t.blockStatement([
|
||||
@@ -34,7 +34,7 @@ exports.BindFunctionExpression = function (node, parent, scope, file) {
|
||||
]));
|
||||
};
|
||||
|
||||
var temp = scope.generateTemp(file, "args");
|
||||
var temp = scope.generateTemp("args");
|
||||
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
|
||||
@@ -50,12 +50,11 @@ Scope.prototype.traverse = function (node, opts, state) {
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {File} file
|
||||
* @param {String} [name="temp"]
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTemp = function (file, name) {
|
||||
var id = file.generateUidIdentifier(name || "temp", this);
|
||||
Scope.prototype.generateTemp = function (name) {
|
||||
var id = this.generateUidIdentifier(name || "temp");
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
@@ -70,7 +69,33 @@ Scope.prototype.generateTemp = function (file, name) {
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidIdentifier = function (name) {
|
||||
return this.file.generateUidIdentifier(name, this);
|
||||
var id = t.identifier(this.generateUid(name));
|
||||
this.getFunctionParent().registerBinding("uid", id);
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} name
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUid = function (name) {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "");
|
||||
|
||||
var uid;
|
||||
var i = 0;
|
||||
do {
|
||||
uid = this._generateUid(name, i);
|
||||
i++;
|
||||
} while (this.hasBinding(uid) || this.hasGlobal(uid));
|
||||
return uid;
|
||||
};
|
||||
|
||||
Scope.prototype._generateUid = function (name, i) {
|
||||
var id = name;
|
||||
if (i > 1) id += i;
|
||||
return "_" + id;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -111,7 +136,7 @@ Scope.prototype.generateUidBasedOnNode = function (parent) {
|
||||
var id = parts.join("$");
|
||||
id = id.replace(/^_/, "") || "ref";
|
||||
|
||||
return this.file.generateUidIdentifier(id, this);
|
||||
return this.generateUidIdentifier(id);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -141,7 +166,7 @@ Scope.prototype.checkBlockScopedCollisions = function (kind, name, id) {
|
||||
if (kind === "param") return;
|
||||
if (kind === "hoisted" && local.kind === "let") return;
|
||||
|
||||
if (local.kind === "let" || local.kind === "const") {
|
||||
if (local.kind === "let" || local.kind === "const" || local.kind === "module") {
|
||||
throw this.file.errorWithNode(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
|
||||
}
|
||||
};
|
||||
@@ -185,16 +210,28 @@ Scope.prototype.inferType = function (node) {
|
||||
target = node.init;
|
||||
}
|
||||
|
||||
if (t.isCallExpression(target)) {
|
||||
// todo: resolve this to a return type
|
||||
if (t.isArrayExpression(target)) {
|
||||
return t.genericTypeAnnotation(t.identifier("Array"));
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(target)) {
|
||||
// todo: crawl this and find the correct type, bail on anything that we cannot possibly be 100% confident on
|
||||
if (t.isObjectExpression(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isLiteral(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isCallExpression(target) && t.isIdentifier(target.callee)) {
|
||||
var funcInfo = this.getBindingInfo(target.callee.name);
|
||||
if (funcInfo) {
|
||||
var funcNode = funcInfo.node;
|
||||
return !funcInfo.reassigned && t.isFunction(funcNode) && node.returnType;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isIdentifier(target)) {
|
||||
// todo
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -217,7 +254,12 @@ Scope.prototype.assignType = function (name, type) {
|
||||
info.identifier.typeAnnotation = info.typeAnnotation = type;
|
||||
};
|
||||
|
||||
Scope.prototype.getTypeAnnotation = function (key, id, node) {
|
||||
Scope.prototype.getTypeAnnotation = function (name, id, node) {
|
||||
var info = {
|
||||
annotation: null,
|
||||
inferred: false
|
||||
};
|
||||
|
||||
var type;
|
||||
|
||||
if (id.typeAnnotation) {
|
||||
@@ -225,13 +267,16 @@ Scope.prototype.getTypeAnnotation = function (key, id, node) {
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
info.inferred = true;
|
||||
type = this.inferType(node);
|
||||
}
|
||||
|
||||
if (type) {
|
||||
if (t.isTypeAnnotation(type)) type = type.typeAnnotation;
|
||||
return type;
|
||||
info.annotation = type;
|
||||
}
|
||||
|
||||
return info;
|
||||
};
|
||||
|
||||
Scope.prototype.toArray = function (node, i) {
|
||||
@@ -284,7 +329,14 @@ Scope.prototype.registerBindingReassignment = function (node) {
|
||||
var ids = t.getBindingIdentifiers(node);
|
||||
for (var name in ids) {
|
||||
var info = this.getBindingInfo(name);
|
||||
if (info) info.reassigned = true;
|
||||
if (info) {
|
||||
info.reassigned = true;
|
||||
|
||||
if (info.typeAnnotationInferred) {
|
||||
// destroy the inferred typeAnnotation
|
||||
info.typeAnnotation = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -298,12 +350,16 @@ Scope.prototype.registerBinding = function (kind, node) {
|
||||
|
||||
this.checkBlockScopedCollisions(kind, name, id);
|
||||
|
||||
var typeInfo = this.getTypeAnnotation(name, id, node);
|
||||
|
||||
this.bindings[name] = {
|
||||
typeAnnotation: this.getTypeAnnotation(name, id, node),
|
||||
reassigned: false,
|
||||
identifier: id,
|
||||
scope: this,
|
||||
kind: kind
|
||||
typeAnnotationInferred: typeInfo.inferred,
|
||||
typeAnnotation: typeInfo.annotation,
|
||||
reassigned: false,
|
||||
identifier: id,
|
||||
scope: this,
|
||||
node: node,
|
||||
kind: kind
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -362,7 +418,7 @@ var programReferenceVisitor = {
|
||||
state.addGlobal(node);
|
||||
} else if (t.isLabeledStatement(node)) {
|
||||
state.addGlobal(node);
|
||||
} else if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
|
||||
} else if (t.isAssignmentExpression(node) || t.isUpdateExpression(node) || (t.isUnaryExpression(node) && node.operator === "delete")) {
|
||||
scope.registerBindingReassignment(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
"FunctionDeclaration": ["Statement", "Declaration", "Scopable", "Function"],
|
||||
"FunctionExpression": ["Scopable", "Function", "Expression"],
|
||||
|
||||
"ImportSpecifier": ["ModuleSpecifier"],
|
||||
"ExportSpecifier": ["ModuleSpecifier"],
|
||||
|
||||
"BlockStatement": ["Statement", "Scopable"],
|
||||
"Program": ["Scopable"],
|
||||
"CatchClause": ["Scopable"],
|
||||
|
||||
@@ -403,7 +403,7 @@ t.toIdentifier = function (name) {
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {String} key
|
||||
* @param {String=} key
|
||||
*/
|
||||
|
||||
t.ensureBlock = function (node, key) {
|
||||
@@ -418,7 +418,7 @@ t.ensureBlock = function (node, key) {
|
||||
* For example, given the match `React.createClass` it would match the
|
||||
* parsed nodes of `React.createClass` and `React["createClass"]`.
|
||||
*
|
||||
* @param {String} match Dot delimetered string
|
||||
* @param {String} match Dot-delimited string
|
||||
* @param {Boolean} [allowPartial] Allow a partial match
|
||||
* @returns {Function}
|
||||
*/
|
||||
@@ -590,6 +590,8 @@ t.getBindingIdentifiers = function (node) {
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (t.isImportSpecifier(id)) {
|
||||
search.push(id.name || id.id);
|
||||
} else if (t.isExportDeclaration(id)) {
|
||||
if (t.isDeclaration(node.declaration)) {
|
||||
search.push(node.declaration);
|
||||
@@ -606,10 +608,9 @@ t.getBindingIdentifiers = function (node) {
|
||||
};
|
||||
|
||||
t.getBindingIdentifiers.keys = {
|
||||
UnaryExpression: ["argument"],
|
||||
AssignmentExpression: ["left"],
|
||||
ImportBatchSpecifier: ["name"],
|
||||
ImportSpecifier: ["name", "id"],
|
||||
ExportSpecifier: ["name", "id"],
|
||||
VariableDeclarator: ["id"],
|
||||
FunctionDeclaration: ["id"],
|
||||
ClassDeclaration: ["id"],
|
||||
|
||||
@@ -88,6 +88,7 @@ var templateVisitor = {
|
||||
node = node.expression;
|
||||
}
|
||||
if (t.isIdentifier(node) && has(nodes, node.name)) {
|
||||
this.skip();
|
||||
return nodes[node.name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.6.0",
|
||||
"version": "3.6.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
@@ -33,7 +33,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-29",
|
||||
"acorn-6to5": "0.11.1-30",
|
||||
"ast-types": "~0.6.1",
|
||||
"chalk": "^0.5.1",
|
||||
"chokidar": "0.12.6",
|
||||
@@ -58,7 +58,7 @@
|
||||
"useragent": "^2.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"6to5": "3.5.3",
|
||||
"6to5": "3.6.0",
|
||||
"browserify": "8.1.1",
|
||||
"chai": "1.10.0",
|
||||
"esvalid": "1.1.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5-runtime",
|
||||
"description": "6to5 selfContained runtime",
|
||||
"version": "3.5.3",
|
||||
"version": "3.6.1",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
"args": ["bar"]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
|
||||
import "./bar";
|
||||
import "./bar2";
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
"args": ["foo2"]
|
||||
}
|
||||
|
||||
2
test/fixtures/transformation/es6-constants/ignore-member-expressions/actual.js
vendored
Normal file
2
test/fixtures/transformation/es6-constants/ignore-member-expressions/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
const x = {};
|
||||
x.key = "value";
|
||||
4
test/fixtures/transformation/es6-constants/ignore-member-expressions/expected.js
vendored
Normal file
4
test/fixtures/transformation/es6-constants/ignore-member-expressions/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var x = {};
|
||||
x.key = "value";
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
var _ref = ["hello", [", ", "junk"], ["world"]];
|
||||
|
||||
@@ -11,4 +11,4 @@ var b = _ref$1[0];
|
||||
var _ref$2 = _slicedToArray(_ref[2], 1);
|
||||
|
||||
var c = _ref$2[0];
|
||||
var d = _ref[3];
|
||||
var d = _ref[3];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _temp, _temp2;
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
console.log((_temp = [123], _temp2 = _slicedToArray(_temp, 1), x = _temp2[0], _temp));
|
||||
console.log((_temp = [123], _temp2 = _slicedToArray(_temp, 1), x = _temp2[0], _temp));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
var _ref = f();
|
||||
|
||||
@@ -8,4 +8,4 @@ var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
a = _ref2[0];
|
||||
b = _ref2[1];
|
||||
;
|
||||
;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
|
||||
|
||||
@@ -11,4 +11,4 @@ var b = _ref$2[0];
|
||||
var _ref$3 = _slicedToArray(_ref[3], 1);
|
||||
|
||||
var c = _ref$3[0];
|
||||
var d = _ref[4];
|
||||
var d = _ref[4];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
for (var _ref in obj) {
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
@@ -8,4 +8,4 @@ for (var _ref in obj) {
|
||||
var name = _ref2[0];
|
||||
var value = _ref2[1];
|
||||
print("Name: " + name + ", Value: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
for (var _iterator = test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
var _step$value = _slicedToArray(_step.value, 3);
|
||||
@@ -8,4 +8,4 @@ for (var _iterator = test.expectation.registers[Symbol.iterator](), _step; !(_st
|
||||
var name = _step$value[0];
|
||||
var before = _step$value[1];
|
||||
var after = _step$value[2];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
var _ref = [1, 2];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
var _rect$topLeft = _slicedToArray(rect.topLeft, 2);
|
||||
|
||||
@@ -9,4 +9,4 @@ var y1 = _rect$topLeft[1];
|
||||
var _rect$bottomRight = _slicedToArray(rect.bottomRight, 2);
|
||||
|
||||
var x2 = _rect$bottomRight[0];
|
||||
var y2 = _rect$bottomRight[1];
|
||||
var y2 = _rect$bottomRight[1];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } };
|
||||
|
||||
function somethingAdvanced(_ref) {
|
||||
var _ref$topLeft = _ref.topLeft;
|
||||
@@ -33,4 +33,4 @@ var unpackArray = function (_ref, _ref3) {
|
||||
return a + b + c;
|
||||
};
|
||||
|
||||
console.log(unpackArray(["hello", ", ", "world"], [1, 2, 3]));
|
||||
console.log(unpackArray(["hello", ", ", "world"], [1, 2, 3]));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import foo from "foo";
|
||||
import { default as foo } from "foo";
|
||||
import { foo } from "foo";
|
||||
import * as foo from "foo";
|
||||
import { default as foo2 } from "foo";
|
||||
import { foo3 } from "foo";
|
||||
import * as foo4 from "foo";
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
var _foo = require("foo");
|
||||
|
||||
var foo = _foo["default"];
|
||||
var foo = _foo["default"];
|
||||
var foo = _foo.foo;
|
||||
var foo = _foo;
|
||||
var foo2 = _foo["default"];
|
||||
var foo3 = _foo.foo3;
|
||||
var foo4 = _foo;
|
||||
|
||||
1
test/fixtures/transformation/self-contained/symbol-iterator-in/actual.js
vendored
Normal file
1
test/fixtures/transformation/self-contained/symbol-iterator-in/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Symbol.iterator in Object(arr);
|
||||
5
test/fixtures/transformation/self-contained/symbol-iterator-in/expected.js
vendored
Normal file
5
test/fixtures/transformation/self-contained/symbol-iterator-in/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
_core.$for.isIterable(Object(arr));
|
||||
18
test/util.js
18
test/util.js
@@ -1,5 +1,6 @@
|
||||
var assert = require("assert");
|
||||
var util = require("../lib/6to5/util");
|
||||
var parse = require("../lib/6to5/helpers/parse");
|
||||
var t = require("../lib/6to5/types");
|
||||
|
||||
suite("util", function () {
|
||||
@@ -9,6 +10,23 @@ suite("util", function () {
|
||||
}, /unknown template/);
|
||||
});
|
||||
|
||||
test("templates do not recurse", function () {
|
||||
var key = __filename;
|
||||
var KEY = parse({ loc: key }, "replacedKey").program.body[0].expression;
|
||||
var VALUE = parse({ loc: key }, "+KEY").program.body[0].expression;
|
||||
|
||||
util.templates[key] = util.parseTemplate(key, "KEY = VALUE;");
|
||||
var result = util.template(key, {KEY: KEY, VALUE: VALUE});
|
||||
delete util.templates[key];
|
||||
|
||||
assert.strictEqual(
|
||||
result.right.argument.name,
|
||||
"KEY",
|
||||
"template should not recurse into replaced nodes, " +
|
||||
"replacing KEY inside VALUE"
|
||||
);
|
||||
});
|
||||
|
||||
test("canCompile", function () {
|
||||
assert.ok(util.canCompile("test.js"));
|
||||
assert.ok(util.canCompile("/test.js"));
|
||||
|
||||
Reference in New Issue
Block a user