Compare commits

...

39 Commits

Author SHA1 Message Date
Sebastian McKenzie
a4c6660d21 v3.6.2 2015-02-13 21:07:45 +11:00
Sebastian McKenzie
9676666e7c 3.6.1 2015-02-13 21:05:56 +11:00
Sebastian McKenzie
388133642d add support for UnaryExpression to getBindingIdentifiers and add it as a reassignment in the scope tracking 2015-02-13 21:05:52 +11:00
Sebastian McKenzie
23b5eeb72f use Symbol.iterator in for symbol detection and add the conversion of it to the selfContained transformer - @zloirock 2015-02-13 21:05:21 +11:00
Sebastian McKenzie
db36c3a7c2 v3.6.1 2015-02-13 20:50:37 +11:00
Sebastian McKenzie
e841b88cbc fix 6to5-node test collisions 2015-02-13 20:48:52 +11:00
Sebastian McKenzie
3d874f2479 update sliceToArray helper, again... 2015-02-13 20:45:43 +11:00
Sebastian McKenzie
228719102a update sliceToArray tests 2015-02-13 20:39:37 +11:00
Sebastian McKenzie
c6ce1a248c better slicedToArray helper 2015-02-13 20:38:28 +11:00
Sebastian McKenzie
ba9b85f64b only use functions returnType if it hasn't been reassigned 2015-02-13 20:36:43 +11:00
Sebastian McKenzie
56c868efee fix incorrect generateUid references in File 2015-02-13 18:27:53 +11:00
Sebastian McKenzie
1f3c3832ba fix linting errors 2015-02-13 18:25:34 +11:00
Sebastian McKenzie
3b04a8c648 fix linting errors 2015-02-13 18:24:24 +11:00
Sebastian McKenzie
2270057b54 add 3.6.1 changelog 2015-02-13 18:23:46 +11:00
Sebastian McKenzie
c3206aa9a4 move File::generateUid to Scope and add return type inferrence 2015-02-13 18:21:28 +11:00
Sebastian McKenzie
1912d1b26a remove ExportSpecifier from t.getBindingIdentifiers as it has none 2015-02-13 18:19:27 +11:00
Sebastian McKenzie
9208e7e594 update common standard import test 2015-02-13 17:47:46 +11:00
Sebastian McKenzie
ce332b3384 fix module binding resolution - fixes #762 2015-02-13 17:37:35 +11:00
Sebastian McKenzie
a567531f77 ignore member expressions in constants transformer - fixes #770 2015-02-13 17:18:42 +11:00
Sebastian McKenzie
9cce72def0 update tests that use the toSlicedArray helper 2015-02-13 17:04:18 +11:00
Sebastian McKenzie
2d8581c6dc Merge branch 'master' of github.com:6to5/6to5
Conflicts:
	lib/6to5/transformation/transformers/minification/dead-code-elimination.js
2015-02-13 16:54:09 +11:00
Sebastian McKenzie
14a000396a add error message to the sliced-to-array helper on a non-iterable param - fixes #766 2015-02-13 16:50:03 +11:00
Sebastian McKenzie
4c41f5a22f bump acorn-6to5 and 6to5 devDependency 2015-02-13 15:09:28 +11:00
Sebastian McKenzie
6be2a6e02a add extra note to minification dead code elimination transformer 2015-02-13 15:09:17 +11:00
Sebastian McKenzie
0a4fc16ca0 add type inferrence that expires when a binding is reassigned 2015-02-13 15:08:58 +11:00
Sebastian McKenzie
25d8377411 normalise JSX attribute strings 2015-02-13 15:08:39 +11:00
Brian Donovan
14267a788d Fix a typo. 2015-02-12 19:12:09 -08:00
Sebastian McKenzie
ba5c5760b1 Merge pull request #769 from 6to5/if-truthy-minification-returns-consequent
Return the consequent if the test is truthy.
2015-02-13 14:08:32 +11:00
Brian Donovan
49904b3ab3 Fix a small grammar issue. 2015-02-12 19:07:54 -08:00
Brian Donovan
a212f035e4 Return the consequent if the test is truthy. 2015-02-12 19:06:06 -08:00
Brian Donovan
ea471a6a17 Fix a few typos. 2015-02-12 18:47:08 -08:00
Brian Donovan
f5bae0b696 Remove redundant variable. 2015-02-12 18:46:53 -08:00
Brian Donovan
9ec9e13aeb Update the jsdoc to indicate that key is optional. 2015-02-12 18:36:36 -08:00
Brian Donovan
0b042b2681 Use the posessive form of "its", not a contraction of "it is". 2015-02-12 18:36:02 -08:00
Brian Donovan
83b4d12884 Correct a jsdoc comment parameter name. 2015-02-12 18:35:35 -08:00
Brian Donovan
98d555498d Remove unused variable. 2015-02-12 18:29:14 -08:00
Sebastian McKenzie
fdc05cb977 Merge pull request #767 from 6to5/templates-should-not-recurse
Ensure that templates do not recurse.
2015-02-13 11:13:30 +11:00
Brian Donovan
928ebda5bc Ensure that templates do not recurse.
Closes #765.
2015-02-12 16:10:13 -08:00
Sebastian McKenzie
0a2003af66 3.6.0 2015-02-12 21:59:37 +11:00
43 changed files with 208 additions and 112 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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", [

View File

@@ -0,0 +1 @@
CORE_ID.$for.isIterable(VALUE);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,6 +22,9 @@
"FunctionDeclaration": ["Statement", "Declaration", "Scopable", "Function"],
"FunctionExpression": ["Scopable", "Function", "Expression"],
"ImportSpecifier": ["ModuleSpecifier"],
"ExportSpecifier": ["ModuleSpecifier"],
"BlockStatement": ["Statement", "Scopable"],
"Program": ["Scopable"],
"CatchClause": ["Scopable"],

View File

@@ -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"],

View File

@@ -88,6 +88,7 @@ var templateVisitor = {
node = node.expression;
}
if (t.isIdentifier(node) && has(nodes, node.name)) {
this.skip();
return nodes[node.name];
}
}

View File

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

View File

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

View File

@@ -1,3 +1,3 @@
{
"args": ["foo"]
"args": ["bar"]
}

View File

@@ -1,4 +1,4 @@
var foo = () => console.log("foo");
foo();
import "./bar";
import "./bar2";

View File

@@ -1,3 +1,3 @@
{
"args": ["foo"]
"args": ["foo2"]
}

View File

@@ -0,0 +1,2 @@
const x = {};
x.key = "value";

View File

@@ -0,0 +1,4 @@
"use strict";
var x = {};
x.key = "value";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1 @@
Symbol.iterator in Object(arr);

View File

@@ -0,0 +1,5 @@
"use strict";
var _core = require("6to5-runtime/core-js");
_core.$for.isIterable(Object(arr));

View File

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