Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55dfb423ee | ||
|
|
9d1bc4817d | ||
|
|
fc8666e7a4 | ||
|
|
07b6881d67 | ||
|
|
1f208a06db | ||
|
|
b5c9c84542 | ||
|
|
492555bb4e | ||
|
|
53d88c0f63 | ||
|
|
8a5da57162 | ||
|
|
1627e2f47e | ||
|
|
e195d6ca55 | ||
|
|
71d5d4fb2c | ||
|
|
dfe13cda0d | ||
|
|
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 |
26
CHANGELOG.md
26
CHANGELOG.md
@@ -11,6 +11,31 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.6.4
|
||||
|
||||
* **New Feature**
|
||||
* Add support for flow type casts and module types.
|
||||
|
||||
## 3.6.3
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 3.6.2
|
||||
|
||||
* **Polish**
|
||||
* Use better iterator detection in `slicedToArray` helper and add support for it to the `selfContained` transformer.
|
||||
|
||||
## 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 +44,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`.
|
||||
|
||||
@@ -16,7 +16,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, { sourceMapName: dest });
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
});
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
var mapLoc = dest + ".map";
|
||||
|
||||
@@ -21,7 +21,7 @@ exports.addSourceMappingUrl = function (code, loc) {
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
opts = _.extend(opts || {}, index.opts);
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result;
|
||||
|
||||
@@ -30,6 +30,7 @@ exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.TypeCastExpression =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
|
||||
@@ -18,9 +18,10 @@ var each = require("lodash/collection/each");
|
||||
var t = require("../types");
|
||||
|
||||
function File(opts) {
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
this.dynamicImportedNoDefault = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
@@ -273,17 +274,19 @@ File.prototype.get = function (key) {
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.addImport = function (source, name) {
|
||||
File.prototype.addImport = function (source, name, noDefault) {
|
||||
name = name || source;
|
||||
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));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.dynamicImported.push(declar);
|
||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
}
|
||||
@@ -312,7 +315,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 +446,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);
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ module.exports = AMDFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var CommonFormatter = require("./common");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var values = require("lodash/object/values");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function AMDFormatter() {
|
||||
CommonFormatter.apply(this, arguments);
|
||||
@@ -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) {
|
||||
@@ -81,12 +81,12 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
if (includes(this.file.dynamicImported, node)) {
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = ref;
|
||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
|
||||
@@ -31,8 +31,8 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
if (!includes(this.file.dynamicImported, node)) {
|
||||
if (this.noInteropRequireImport) {
|
||||
if (!includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
if (this.noInteropRequireImport || includes(this.file.dynamicImported, node)) {
|
||||
ref = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
@@ -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);
|
||||
@@ -0,0 +1,2 @@
|
||||
var helpers = exports.default = {};
|
||||
exports.__esModule = true;
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -55,6 +55,8 @@ Transformer.prototype.normalize = function (transformer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "enter" || type === "exit") return;
|
||||
|
||||
if (isFunction(fns)) fns = { enter: fns };
|
||||
|
||||
if (!isObject(fns)) return;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = {
|
||||
"playground.objectGetterMemoization": require("./playground/object-getter-memoization"),
|
||||
|
||||
reactCompat: require("./other/react-compat"),
|
||||
flow: require("./other/flow"),
|
||||
react: require("./other/react"),
|
||||
|
||||
_modules: require("./internal/modules"),
|
||||
@@ -86,11 +87,12 @@ module.exports = {
|
||||
_declarations: require("./internal/declarations"),
|
||||
|
||||
_aliasFunctions: require("./internal/alias-functions"),
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
"spec.typeofSymbol": require("./spec/typeof-symbol"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
|
||||
exports.post = function (file) {
|
||||
exports.Program = function (program, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
var program = file.ast.program;
|
||||
|
||||
useStrict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.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);
|
||||
|
||||
@@ -15,7 +15,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
return remapAsyncToGenerator(
|
||||
node,
|
||||
t.memberExpression(file.addImport("bluebird"), t.identifier("coroutine")),
|
||||
t.memberExpression(file.addImport("bluebird", null, true), t.identifier("coroutine")),
|
||||
scope
|
||||
);
|
||||
};
|
||||
|
||||
13
lib/6to5/transformation/transformers/other/flow.js
Normal file
13
lib/6to5/transformation/transformers/other/flow.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.TypeCastExpression = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = function (node) {
|
||||
if (node.isType) this.remove();
|
||||
};
|
||||
|
||||
exports.ExportDeclaration = function (node) {
|
||||
if (t.isTypeAlias(node.declaration)) this.remove();
|
||||
};
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -64,8 +78,8 @@ exports.manipulateOptions = function (opts) {
|
||||
if (opts.whitelist.length) opts.whitelist.push("es6.modules");
|
||||
};
|
||||
|
||||
exports.post = function (file) {
|
||||
file.scope.traverse(file.ast, astVisitor, file);
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
scope.traverse(node, astVisitor, file);
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
@@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.post = function (file) {
|
||||
var program = file.ast.program;
|
||||
exports.Program = function (program) {
|
||||
if (!useStrict.has(program)) {
|
||||
program.body.unshift(t.expressionStatement(t.literal("use strict")));
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -109,7 +109,7 @@ TraversalPath.prototype.call = function (key) {
|
||||
if (!node) return;
|
||||
|
||||
var opts = this.opts;
|
||||
var fn = opts[key];
|
||||
var fn = opts[key] || opts;
|
||||
if (opts[node.type]) fn = opts[node.type][key] || fn;
|
||||
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
|
||||
@@ -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,14 +608,12 @@ 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"],
|
||||
MemberExpression: ["object"],
|
||||
SpreadElement: ["argument"],
|
||||
RestElement: ["argument"],
|
||||
UpdateExpression: ["argument"],
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"TypeofTypeAnnotation": [],
|
||||
"TypeAlias": [],
|
||||
"TypeAnnotation": [],
|
||||
"TypeCastExpression": ["expression"],
|
||||
"TypeParameterDeclaration": [],
|
||||
"TypeParameterInstantiation": [],
|
||||
"ObjectTypeAnnotation": [],
|
||||
|
||||
@@ -88,6 +88,7 @@ var templateVisitor = {
|
||||
node = node.expression;
|
||||
}
|
||||
if (t.isIdentifier(node) && has(nodes, node.name)) {
|
||||
this.skip();
|
||||
return nodes[node.name];
|
||||
}
|
||||
}
|
||||
@@ -108,6 +109,8 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
traverse(template, templateVisitor, null, nodes);
|
||||
}
|
||||
|
||||
if (template.body.length > 1) return template.body;
|
||||
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.6.0",
|
||||
"version": "3.6.4",
|
||||
"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-31",
|
||||
"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.3",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var buildHelpers = require("../lib/6to5/build-helpers");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var util = require("../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
@@ -16,8 +17,14 @@ var writeFile = function (filename, content) {
|
||||
fs.writeFileSync(filename, content);
|
||||
};
|
||||
|
||||
var readFile = function (filename) {
|
||||
return fs.readFileSync(require.resolve(filename), "utf8");
|
||||
var readFile = function (filename, defaultify) {
|
||||
var file = fs.readFileSync(require.resolve(filename), "utf8");
|
||||
|
||||
if (defaultify) {
|
||||
file += '\nmodule.exports = { "default": module.exports, __esModule: true };\n';
|
||||
}
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
var updatePackage = function () {
|
||||
@@ -37,10 +44,10 @@ var selfContainify = function (code) {
|
||||
};
|
||||
|
||||
var buildHelpers2 = function () {
|
||||
var body = [];
|
||||
var body = util.template("self-contained-helpers-head");
|
||||
var tree = t.program(body);
|
||||
|
||||
buildHelpers(body, t.identifier("exports"));
|
||||
buildHelpers(body, t.identifier("helpers"));
|
||||
|
||||
return transform.fromAst(tree, null, {
|
||||
optional: ["selfContained"]
|
||||
@@ -48,7 +55,7 @@ var buildHelpers2 = function () {
|
||||
};
|
||||
|
||||
writeFile("helpers.js", buildHelpers2());
|
||||
writeFile("core-js.js", readFile("core-js/library"));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module"));
|
||||
writeFile("core-js.js", readFile("core-js/library", true));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-6to5/runtime")));
|
||||
updatePackage();
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instance
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7SUFBTSxJQUFJLFlBQUosSUFBSTt3QkFBSixJQUFJIiwiZmlsZSI6InNyYy9iYXIvYmFyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iXX0=
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7SUFBTSxJQUFJLFlBQUosSUFBSTt3QkFBSixJQUFJIiwiZmlsZSI6InNyYy9iYXIvYmFyLmpzIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iXX0=
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFVBQUEsQ0FBQztTQUFJLENBQUMsR0FBRyxVQUFVO0NBQUEsQ0FBQyxDQUFDIiwiZmlsZSI6InNyYy9mb28uanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFVBQUEsQ0FBQztTQUFJLENBQUMsR0FBRyxVQUFVO0NBQUEsQ0FBQyxDQUFDIiwiZmlsZSI6InNyYy9mb28uanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["src/bar/bar.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI","file":"src/bar/bar.js","sourcesContent":["class Test {\n\n}"]}
|
||||
{"version":3,"sources":["../../src/bar/bar.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI","file":"src/bar/bar.js","sourcesContent":["class Test {\n\n}"]}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["src/foo.js"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,UAAU;CAAA,CAAC,CAAC","file":"src/foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]}
|
||||
{"version":3,"sources":["../src/foo.js"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,UAAU;CAAA,CAAC,CAAC","file":"src/foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]}
|
||||
|
||||
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,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
obj.constructor === Object;
|
||||
obj.constructor === _core.Promise;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) {
|
||||
var i = _step.value;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
var arr = (function () {
|
||||
var _arr = [];
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator")["default"];
|
||||
var _to5Helpers = require("6to5-runtime/helpers")["default"];
|
||||
var giveWord = _regeneratorRuntime.mark(function giveWord() {
|
||||
return _regeneratorRuntime.wrap(function giveWord$(context$1$0) {
|
||||
while (1) switch (context$1$0.prev = context$1$0.next) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(["exports", "foo", "6to5-runtime/helpers"], function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var _to5Helpers = _to5RuntimeHelpers["default"];
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var foo = _to5Helpers.interopRequire(require("foo"));
|
||||
var _to5Helpers = require("6to5-runtime/helpers")["default"];
|
||||
var foo = _to5Helpers.interopRequire(require("foo"));
|
||||
|
||||
@@ -4,10 +4,10 @@ System.register(["6to5-runtime/helpers"], function (_export) {
|
||||
var _to5Helpers;
|
||||
return {
|
||||
setters: [function (_to5RuntimeHelpers) {
|
||||
_to5Helpers = _to5RuntimeHelpers;
|
||||
_to5Helpers = _to5RuntimeHelpers["default"];
|
||||
}],
|
||||
execute: function () {
|
||||
foo.apply(undefined, _to5Helpers.toConsumableArray(bar));
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
})(function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var _to5Helpers = _to5RuntimeHelpers["default"];
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator")["default"];
|
||||
void _regeneratorRuntime.mark(function callee$0$0() {
|
||||
return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
|
||||
while (1) switch (context$1$0.prev = context$1$0.next) {
|
||||
|
||||
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);
|
||||
4
test/fixtures/transformation/self-contained/symbol-iterator-in/expected.js
vendored
Normal file
4
test/fixtures/transformation/self-contained/symbol-iterator-in/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
_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