Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afdde8b3a7 | ||
|
|
918ddb4124 | ||
|
|
18739ad78b | ||
|
|
74a84e2473 | ||
|
|
52ffc65a06 | ||
|
|
d4fbfbbe47 | ||
|
|
781467d423 | ||
|
|
44f5b7d013 | ||
|
|
dcf7f0b70b | ||
|
|
03efd69998 | ||
|
|
213003a007 | ||
|
|
b0503f2efe | ||
|
|
c8cf7ff286 | ||
|
|
ceb32816d7 | ||
|
|
32b94899a6 | ||
|
|
d951082b09 | ||
|
|
b49f6e33d6 | ||
|
|
c5fa6425a5 | ||
|
|
70d896d609 | ||
|
|
e00fa8c9b1 | ||
|
|
13933bc9b8 | ||
|
|
295bab544b | ||
|
|
cfe05ca10d | ||
|
|
da72182219 | ||
|
|
005f5b2174 | ||
|
|
8551c94fa0 | ||
|
|
c509d06bc2 | ||
|
|
f21743012b | ||
|
|
22dc33f93c | ||
|
|
6df6652629 | ||
|
|
4942ba6dd7 | ||
|
|
b63bd8cba0 | ||
|
|
cd1eb11171 | ||
|
|
6e1c12fd78 | ||
|
|
a4ea71b85d | ||
|
|
5c39685650 |
@@ -1,3 +1,3 @@
|
||||
node_modules
|
||||
test
|
||||
lib/6to5/templates
|
||||
lib/6to5/transformation/templates
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/templates
|
||||
lib/6to5/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
|
||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -2,6 +2,32 @@
|
||||
|
||||
Gaps between patch versions are faulty/broken releases.
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Make `system` module formatter modules anonymous by default.
|
||||
* Fix duplicate comments being output, breaking code.
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Add `cache` option to register hook.
|
||||
* Update `core-js`.
|
||||
* Fix starting newline not being added on case statements.
|
||||
* Fix destructuring `VariableDeclaration`s not inside `BlockStatement`s and `Program`.
|
||||
|
||||
## 2.0.4
|
||||
|
||||
* Avoid being greedy when destructuring array iterables.
|
||||
|
||||
## 2.0.3
|
||||
|
||||
* Hoist function declarations in system module formatter for circular references.
|
||||
* Hoist default function declarations in umd and amd module formatters for circular references.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
* Inherit comments in `for-of` transformer.
|
||||
* Remove `interopRequire` from `system` module formatter.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Remap `UpdateExpression` module export binding.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/runtime");
|
||||
var runtime = require("../lib/6to5/runtime-generator");
|
||||
console.log(runtime(process.argv[2]));
|
||||
|
||||
@@ -20,7 +20,8 @@ commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NO
|
||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
|
||||
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false);
|
||||
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
|
||||
commander.option("-m, --module-ids", "Insert module id in modules", false);
|
||||
|
||||
commander.on("--help", function(){
|
||||
var outKeys = function (title, obj) {
|
||||
@@ -89,9 +90,9 @@ if (errors.length) {
|
||||
|
||||
exports.opts = {
|
||||
sourceMapName: commander.outFile,
|
||||
amdModuleIds: commander.amdModuleIds,
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
|
||||
12
doc/usage.md
12
doc/usage.md
@@ -152,10 +152,10 @@ result.ast;
|
||||
// Default: `sourceRoot` option.
|
||||
moduleRoot: "my-app",
|
||||
|
||||
// If truthy, insert an explicit id for each defined AMD module.
|
||||
// By default, AMD modules are anonymous.
|
||||
// If truthy, insert an explicit id for each defined AMD/System module.
|
||||
// By default, AMD/System modules are anonymous.
|
||||
// Default: false
|
||||
amdModuleIds: true,
|
||||
moduleIds: true,
|
||||
|
||||
// Optionally replace all 6to5 helper declarations with a referenece to this
|
||||
// variable. If set to `true` then the default namespace is used "to5Runtime".
|
||||
@@ -250,6 +250,10 @@ require("6to5/register")({
|
||||
|
||||
// This will remove the currently hooked extensions of .es6 and .js so you'll
|
||||
// have to add them back if you want them to be used again.
|
||||
extensions: [".js", ".es6"]
|
||||
extensions: [".js", ".es6"],
|
||||
|
||||
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
|
||||
// Do not check this into git as it's user-specific
|
||||
cache: true
|
||||
});
|
||||
```
|
||||
|
||||
@@ -22,6 +22,7 @@ File.declarations = [
|
||||
"tagged-template-literal",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"sliced-to-array",
|
||||
"object-without-properties",
|
||||
"has-own",
|
||||
"slice"
|
||||
@@ -34,6 +35,7 @@ File.normaliseOptions = function (opts) {
|
||||
experimental: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
@@ -82,13 +84,19 @@ File.normaliseOptions = function (opts) {
|
||||
return opts;
|
||||
};
|
||||
|
||||
File.prototype.toArray = function (node) {
|
||||
File.prototype.toArray = function (node, i) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
return t.callExpression(this.addDeclaration("to-array"), [node]);
|
||||
var declarationName = "to-array";
|
||||
var args = [node];
|
||||
if (i) {
|
||||
args.push(t.literal(i));
|
||||
declarationName = "sliced-to-array";
|
||||
}
|
||||
return t.callExpression(this.addDeclaration(declarationName), args);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ exports.SwitchCase = function (node, print) {
|
||||
this.push("default:");
|
||||
}
|
||||
|
||||
this.space();
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ exports.Transformer = require("./transformation/transformer");
|
||||
|
||||
exports.types = require("./types");
|
||||
|
||||
exports.runtime = require("./runtime");
|
||||
exports.runtime = require("./runtime-generator");
|
||||
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require("./polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var roadrunner = require("roadrunner");
|
||||
var util = require("./util");
|
||||
var to5 = require("./index");
|
||||
var fs = require("fs");
|
||||
@@ -38,15 +39,22 @@ var blacklistTest = function (transformer, code) {
|
||||
};
|
||||
|
||||
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
|
||||
//blacklistTest("generatorComprehension", "");
|
||||
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
|
||||
blacklistTest("arrowFunctions", "var foo = x => x * x;");
|
||||
blacklistTest("classes", "class Foo {}");
|
||||
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
|
||||
//blacklistTest("constants", "const foo = 0;");
|
||||
blacklistTest("constants", function () {
|
||||
try {
|
||||
new Function("const foo = 'foo';\nfoo = 'wow';");
|
||||
} catch (err) {
|
||||
return; // constants are supported
|
||||
}
|
||||
throw new SyntaxError;
|
||||
});
|
||||
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
|
||||
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
|
||||
blacklistTest("forOf", "for (var foo of bar) {}");
|
||||
blacklistTest("generators", "function* foo() {}");
|
||||
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
|
||||
blacklistTest("letScoping", "let foo = 0;");
|
||||
blacklistTest("modules", 'import foo from "from";');
|
||||
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
|
||||
@@ -130,6 +138,11 @@ module.exports = function (opts) {
|
||||
|
||||
if (opts.cache) cache = opts.cache;
|
||||
if (opts.cache === false) cache = null;
|
||||
if (opts.cache === true) {
|
||||
roadrunner.load();
|
||||
roadrunner.setup();
|
||||
cache = roadrunner.get("6to5");
|
||||
}
|
||||
|
||||
_.extend(transformOpts, opts);
|
||||
};
|
||||
|
||||
@@ -169,30 +169,36 @@ DefaultFormatter.prototype._exportsAssign = function (id, init) {
|
||||
DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
var id = declar.id;
|
||||
|
||||
if (node.default) {
|
||||
nodes.push(
|
||||
this._exportsAssign(t.identifier("default"), this._pushStatement(declar, nodes))
|
||||
);
|
||||
} else {
|
||||
var assign;
|
||||
id = t.identifier("default");
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(declar)) {
|
||||
for (var i in declar.declarations) {
|
||||
var decl = declar.declarations[i];
|
||||
var assign;
|
||||
|
||||
decl.init = this._exportsAssign(decl.id, decl.init).expression;
|
||||
if (t.isVariableDeclaration(declar)) {
|
||||
for (var i in declar.declarations) {
|
||||
var decl = declar.declarations[i];
|
||||
|
||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||
if (i === "0") t.inherits(newDeclar, declar);
|
||||
nodes.push(newDeclar);
|
||||
}
|
||||
} else {
|
||||
assign = this._exportsAssign(declar.id, declar.id);
|
||||
decl.init = this._exportsAssign(decl.id, decl.init).expression;
|
||||
|
||||
nodes.push(t.toStatement(declar));
|
||||
nodes.push(assign);
|
||||
|
||||
this._hoistExport(declar, assign);
|
||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||
if (i === "0") t.inherits(newDeclar, declar);
|
||||
nodes.push(newDeclar);
|
||||
}
|
||||
} else {
|
||||
var ref = declar;
|
||||
|
||||
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
||||
ref = declar.id;
|
||||
nodes.push(declar);
|
||||
}
|
||||
|
||||
assign = this._exportsAssign(id, ref);
|
||||
|
||||
nodes.push(assign);
|
||||
|
||||
this._hoistExport(declar, assign);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ AMDFormatter.prototype.transform = function (ast) {
|
||||
*/
|
||||
|
||||
AMDFormatter.prototype.getModuleName = function () {
|
||||
if (this.file.opts.amdModuleIds) {
|
||||
if (this.file.opts.moduleIds) {
|
||||
return DefaultFormatter.prototype.getModuleName.apply(this, arguments);
|
||||
} else {
|
||||
return null;
|
||||
@@ -83,7 +83,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
|
||||
if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier)) {
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]);
|
||||
} else {
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
module.exports = SystemFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var AMDFormatter = require("./amd");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var AMDFormatter = require("./amd");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportIdentifier = file.generateUidIdentifier("export");
|
||||
this.noInteropRequire = true;
|
||||
|
||||
AMDFormatter.apply(this, arguments);
|
||||
|
||||
this.moduleNameLiteral = t.literal(this.getModuleName());
|
||||
}
|
||||
|
||||
util.inherits(SystemFormatter, AMDFormatter);
|
||||
|
||||
SystemFormatter.prototype.getModuleName = DefaultFormatter.prototype.getModuleName;
|
||||
|
||||
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier) {
|
||||
var leftIdentifier = t.identifier("i");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
@@ -65,20 +62,41 @@ SystemFormatter.prototype.buildRunnerSetters = function () {
|
||||
SystemFormatter.prototype.transform = function (ast) {
|
||||
var program = ast.program;
|
||||
|
||||
var moduleName = this.getModuleName();
|
||||
var moduleNameLiteral = t.literal(moduleName);
|
||||
|
||||
var runner = util.template("system", {
|
||||
MODULE_NAME: this.moduleNameLiteral,
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
SETTERS: this.buildRunnerSetters(),
|
||||
EXECUTE: t.functionExpression(null, [], t.blockStatement(program.body))
|
||||
}, true);
|
||||
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
if (!moduleName) runner.expression.arguments.shift();
|
||||
|
||||
var returnStatement = handlerBody.pop();
|
||||
|
||||
// hoist up function declarations for circular references
|
||||
traverse(program, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.stop();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!_.isEmpty(this.ids)) {
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
handlerBody.unshift(t.variableDeclaration("var", _.map(this.ids, function (uid) {
|
||||
handlerBody.push(t.variableDeclaration("var", _.map(this.ids, function (uid) {
|
||||
return t.variableDeclarator(uid);
|
||||
})));
|
||||
}
|
||||
|
||||
handlerBody.push(returnStatement);
|
||||
|
||||
program.body = [runner];
|
||||
};
|
||||
|
||||
12
lib/6to5/transformation/templates/sliced-to-array.js
Normal file
12
lib/6to5/transformation/templates/sliced-to-array.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(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;
|
||||
}
|
||||
});
|
||||
@@ -72,14 +72,13 @@ Transformer.prototype.transform = function (file) {
|
||||
Transformer.prototype.canRun = function (file) {
|
||||
var opts = file.opts;
|
||||
var key = this.key;
|
||||
if (key[0] === "_") return true;
|
||||
|
||||
var blacklist = opts.blacklist;
|
||||
if (blacklist.length && _.contains(blacklist, key)) return false;
|
||||
|
||||
if (key[0] !== "_") {
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist.length && !_.contains(whitelist, key)) return false;
|
||||
}
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist.length && !_.contains(whitelist, key)) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -61,13 +61,27 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
};
|
||||
|
||||
var pushArrayPattern = function (opts, nodes, pattern, parentId) {
|
||||
if (!pattern.elements) return;
|
||||
|
||||
var i;
|
||||
|
||||
var hasSpreadElement = false;
|
||||
for (i in pattern.elements) {
|
||||
if (t.isSpreadElement(pattern.elements[i])) {
|
||||
hasSpreadElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
|
||||
|
||||
var _parentId = opts.file.generateUidIdentifier("ref", opts.scope);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(_parentId, opts.file.toArray(parentId))
|
||||
t.variableDeclarator(_parentId, toArray)
|
||||
]));
|
||||
parentId = _parentId;
|
||||
|
||||
for (var i in pattern.elements) {
|
||||
for (i in pattern.elements) {
|
||||
var elem = pattern.elements[i];
|
||||
if (!elem) continue;
|
||||
|
||||
@@ -254,6 +268,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
}
|
||||
|
||||
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
|
||||
declar = null;
|
||||
|
||||
for (i in nodes) {
|
||||
node = nodes[i];
|
||||
|
||||
@@ -24,6 +24,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
OBJECT: node.right
|
||||
});
|
||||
|
||||
t.inheritsComments(node2, node);
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node2.body;
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
var t = require("../../types");
|
||||
|
||||
var inheritsComments = function (node, nodes) {
|
||||
if (nodes.length) {
|
||||
t.inheritsComments(nodes[0], node);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = function (node, parent, file) {
|
||||
var nodes = [];
|
||||
|
||||
if (node.specifiers.length) {
|
||||
if (!file.moduleFormatter.importSpecifier) return;
|
||||
for (var i in node.specifiers) {
|
||||
file.moduleFormatter.importSpecifier(node.specifiers[i], node, nodes, parent);
|
||||
}
|
||||
} else {
|
||||
if (!file.moduleFormatter.importDeclaration) return;
|
||||
file.moduleFormatter.importDeclaration(node, nodes, parent);
|
||||
}
|
||||
|
||||
inheritsComments(node, nodes);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
@@ -35,16 +25,12 @@ exports.ExportDeclaration = function (node, parent, file) {
|
||||
declar.init = declar.init || t.identifier("undefined");
|
||||
}
|
||||
|
||||
if (!file.moduleFormatter.exportDeclaration) return;
|
||||
file.moduleFormatter.exportDeclaration(node, nodes, parent);
|
||||
} else {
|
||||
if (!file.moduleFormatter.exportSpecifier) return;
|
||||
for (var i in node.specifiers) {
|
||||
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
|
||||
}
|
||||
}
|
||||
|
||||
inheritsComments(node, nodes);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
@@ -42,19 +42,35 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
if (result != null) {
|
||||
updated = true;
|
||||
|
||||
var isArray = _.isArray(result);
|
||||
|
||||
// inherit comments from original node to the first replacement node
|
||||
var inheritTo = result;
|
||||
if (isArray) inheritTo = result[0];
|
||||
if (inheritTo) t.inheritsComments(inheritTo, node);
|
||||
|
||||
// replace the node
|
||||
node = obj[key] = result;
|
||||
|
||||
if (_.isArray(result) && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
|
||||
// we're replacing a statement or block node with an array of statements so we better
|
||||
// ensure that it's a block
|
||||
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
|
||||
t.ensureBlock(obj, key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var stop = false;
|
||||
var stopped = false;
|
||||
var removed = false;
|
||||
|
||||
var context = {
|
||||
stop: function () {
|
||||
stop = true;
|
||||
stopped = true;
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
stopped = removed = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -67,8 +83,13 @@ function traverse(parent, opts, scope) {
|
||||
var result = opts.enter.call(context, node, parent, ourScope);
|
||||
maybeReplace(result);
|
||||
|
||||
if (removed) {
|
||||
delete obj[key];
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// stop iteration
|
||||
if (stop || result === false) return;
|
||||
if (stopped || result === false) return;
|
||||
}
|
||||
|
||||
// traverse node
|
||||
|
||||
@@ -293,8 +293,9 @@ t.removeComments = function (child) {
|
||||
};
|
||||
|
||||
t.inheritsComments = function (child, parent) {
|
||||
child.leadingComments = _.compact([].concat(child.leadingComments, parent.leadingComments));
|
||||
child.trailingComments = _.compact([].concat(child.trailingComments, parent.trailingComments));
|
||||
_.each(["leadingComments", "trailingComments"], function (key) {
|
||||
child[key] = _.uniq(_.compact([].concat(child[key], parent[key])));
|
||||
});
|
||||
return child;
|
||||
};
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ exports.parseTemplate = function (loc, code) {
|
||||
var loadTemplates = function () {
|
||||
var templates = {};
|
||||
|
||||
var templatesLoc = __dirname + "/templates";
|
||||
var templatesLoc = __dirname + "/transformation/templates";
|
||||
if (!fs.existsSync(templatesLoc)) {
|
||||
throw new Error("no templates directory - this is most likely the " +
|
||||
"result of a broken `npm publish`. Please report to " +
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.0.1",
|
||||
"version": "2.2.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -39,7 +39,7 @@
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
"core-js": "^0.3.2",
|
||||
"core-js": "^0.3.3",
|
||||
"estraverse": "1.8.0",
|
||||
"esutils": "1.1.6",
|
||||
"fs-readdir-recursive": "0.1.0",
|
||||
|
||||
@@ -33,7 +33,10 @@ switch (foo) {
|
||||
}
|
||||
|
||||
switch (foo) {
|
||||
case "foo": foo();
|
||||
case "bar": bar();
|
||||
default: yay();
|
||||
case "foo":
|
||||
foo();
|
||||
case "bar":
|
||||
bar();
|
||||
default:
|
||||
yay();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
System.register("es6-modules-system/exports-default/expected", [], function (_export) {
|
||||
System.register([], function (_export) {
|
||||
_export("default", foo);
|
||||
|
||||
function foo() {}
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
@@ -16,12 +19,9 @@ System.register("es6-modules-system/exports-default/expected", [], function (_ex
|
||||
|
||||
_export("default", function () {});
|
||||
|
||||
function foo() {}
|
||||
_export("default", foo);
|
||||
|
||||
var Foo = function Foo() {};
|
||||
|
||||
_export("default", Foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,12 @@
|
||||
System.register("es6-modules-system/exports-from/expected", ["foo"], function (_export) {
|
||||
System.register(["foo"], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
_foo = m
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
for (var i in _foo) {
|
||||
_export(i, _foo[i])
|
||||
}
|
||||
|
||||
_export("foo", _foo.foo);
|
||||
|
||||
_export("foo", _foo.foo);
|
||||
@@ -24,6 +20,10 @@ System.register("es6-modules-system/exports-from/expected", ["foo"], function (_
|
||||
_export("default", _foo.foo);
|
||||
|
||||
_export("bar", _foo.bar);
|
||||
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/exports-named/expected", [], function (_export) {
|
||||
System.register([], function (_export) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
@@ -1,21 +1,21 @@
|
||||
System.register("es6-modules-system/exports-variable/expected", [], function (_export) {
|
||||
System.register([], function (_export) {
|
||||
_export("foo7", foo7);
|
||||
|
||||
function foo7() {}
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
_export("foo7", foo7);
|
||||
|
||||
var foo = _export("foo", 1);
|
||||
var foo2 = _export("foo2", function () {});
|
||||
var foo3 = _export("foo3", undefined);
|
||||
var foo4 = _export("foo4", 2);
|
||||
var foo5 = _export("foo5", undefined);
|
||||
var foo6 = _export("foo6", 3);
|
||||
function foo7() {}
|
||||
var foo8 = function foo8() {};
|
||||
|
||||
_export("foo8", foo8);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,11 @@
|
||||
import { isEven } from "./evens";
|
||||
|
||||
export function nextOdd(n) {
|
||||
return isEven(n) ? n + 1 : n + 2;
|
||||
return p = isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
export var p = 5;
|
||||
|
||||
export var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
@@ -1,4 +1,12 @@
|
||||
System.register("es6-modules-system/hoist-function-exports/expected", ["./evens"], function (_export) {
|
||||
System.register(["./evens"], function (_export) {
|
||||
var p;
|
||||
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
function nextOdd(n) {
|
||||
return _export("p", p = isEven(n) ? n + 1 : n + 2);
|
||||
}
|
||||
|
||||
var _evens;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
@@ -7,12 +15,8 @@ System.register("es6-modules-system/hoist-function-exports/expected", ["./evens"
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
var isEven = _evens.isEven;
|
||||
function nextOdd(n) {
|
||||
return isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
_export("p", p = 5);
|
||||
|
||||
var isOdd = _export("isOdd", (function (isEven) {
|
||||
return function (n) {
|
||||
@@ -21,4 +25,4 @@ System.register("es6-modules-system/hoist-function-exports/expected", ["./evens"
|
||||
})(isEven));
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
14
test/fixtures/transformation/.es6-modules-system/imports-default/expected.js
vendored
Normal file
14
test/fixtures/transformation/.es6-modules-system/imports-default/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
System.register([], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
_foo = m
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
var foo = _foo["default"];
|
||||
var foo = _foo["default"];
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/imports-glob/expected", ["foo"], function (_export) {
|
||||
System.register(["foo"], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
14
test/fixtures/transformation/.es6-modules-system/imports-mixing/expected.js
vendored
Normal file
14
test/fixtures/transformation/.es6-modules-system/imports-mixing/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
_foo = m
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
var foo = _foo["default"];
|
||||
var xyz = _foo.baz;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/imports-named/expected", ["foo"], function (_export) {
|
||||
System.register(["foo"], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/imports/expected", ["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
var _foo, _fooBar, _directoryFooBar;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/overview/expected", ["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
var _foo, _fooBar, _directoryFooBar;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
@@ -11,12 +11,7 @@ System.register("es6-modules-system/overview/expected", ["foo", "foo-bar", "./di
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
var foo = _foo["default"];
|
||||
var foo = _foo;
|
||||
var bar = _foo.bar;
|
||||
var bar = _foo.foo;
|
||||
@@ -27,4 +22,4 @@ System.register("es6-modules-system/overview/expected", ["foo", "foo-bar", "./di
|
||||
_export("default", test);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
System.register("es6-modules-system/remap/expected", [], function (_export) {
|
||||
System.register([], function (_export) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
@@ -1,18 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = [1, 2];
|
||||
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
var a = _ref2[0];
|
||||
var b = _ref2[1];
|
||||
var _ref3 = [3, 4];
|
||||
|
||||
var _ref4 = _toArray(_ref3);
|
||||
var _ref4 = _slicedToArray(_ref3, 2);
|
||||
|
||||
var c = _ref4[0];
|
||||
var d = _ref4[1];
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = ["hello", [", ", "junk"], ["world"]];
|
||||
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 4);
|
||||
|
||||
var a = _ref2[0];
|
||||
var _ref3 = _toArray(_ref2[1]);
|
||||
var _ref3 = _slicedToArray(_ref2[1], 1);
|
||||
|
||||
var b = _ref3[0];
|
||||
var _ref4 = _toArray(_ref2[2]);
|
||||
var _ref4 = _slicedToArray(_ref2[2], 1);
|
||||
|
||||
var c = _ref4[0];
|
||||
var d = _ref2[3];
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
var _temp, _ref;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
console.log((_temp = [123], _ref = _toArray(_temp), x = _ref[0], _temp));
|
||||
console.log((_temp = [123], _ref = _slicedToArray(_temp, 1), x = _ref[0], _temp));
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = f();
|
||||
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
a = _ref2[0];
|
||||
b = _ref2[1];
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = ["foo", "hello", [", ", "junk"], ["world"]];
|
||||
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 5);
|
||||
|
||||
var a = _ref2[1];
|
||||
var _ref3 = _toArray(_ref2[2]);
|
||||
var _ref3 = _slicedToArray(_ref2[2], 1);
|
||||
|
||||
var b = _ref3[0];
|
||||
var _ref4 = _toArray(_ref2[3]);
|
||||
var _ref4 = _slicedToArray(_ref2[3], 1);
|
||||
|
||||
var c = _ref4[0];
|
||||
var d = _ref2[4];
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
for (var _ref in obj) {
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
var name = _ref2[0];
|
||||
var value = _ref2[1];
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
for (var _iterator = this.test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
var _ref = _step.value;
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 3);
|
||||
|
||||
var name = _ref2[0];
|
||||
var before = _ref2[1];
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = [1, 2];
|
||||
|
||||
var _ref2 = _toArray(_ref);
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
this.foo = _ref2[0];
|
||||
this.bar = _ref2[1];
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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 _ref = _toArray(rect.topLeft);
|
||||
var _ref = _slicedToArray(rect.topLeft, 2);
|
||||
|
||||
var x1 = _ref[0];
|
||||
var y1 = _ref[1];
|
||||
var _ref2 = _toArray(rect.bottomRight);
|
||||
var _ref2 = _slicedToArray(rect.bottomRight, 2);
|
||||
|
||||
var x2 = _ref2[0];
|
||||
var y2 = _ref2[1];
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
function somethingAdvanced(_ref) {
|
||||
@@ -20,12 +31,12 @@ function unpackObject(_ref2) {
|
||||
console.log(unpackObject({ title: "title", author: "author" }));
|
||||
|
||||
var unpackArray = function (_ref3, _ref5) {
|
||||
var _ref4 = _toArray(_ref3);
|
||||
var _ref4 = _slicedToArray(_ref3, 3);
|
||||
|
||||
var a = _ref4[0];
|
||||
var b = _ref4[1];
|
||||
var c = _ref4[2];
|
||||
var _ref6 = _toArray(_ref5);
|
||||
var _ref6 = _slicedToArray(_ref5, 3);
|
||||
|
||||
var x = _ref6[0];
|
||||
var y = _ref6[1];
|
||||
|
||||
@@ -17,8 +17,10 @@ _loop: for (var i in nums) {
|
||||
})(i);
|
||||
|
||||
switch (_ret) {
|
||||
case "break": break _loop;
|
||||
case "continue": continue _loop;
|
||||
case "break":
|
||||
break _loop;
|
||||
case "continue":
|
||||
continue _loop;
|
||||
default:
|
||||
if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
define(["exports"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
exports["default"] = foo;
|
||||
exports["default"] = 42;
|
||||
exports["default"] = {};
|
||||
exports["default"] = [];
|
||||
@@ -10,7 +11,6 @@ define(["exports"], function (exports) {
|
||||
exports["default"] = function () {};
|
||||
|
||||
function foo() {}
|
||||
exports["default"] = foo;
|
||||
var Foo = function Foo() {};
|
||||
|
||||
exports["default"] = Foo;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
System.register("es6-modules-system/imports-default/expected", ["foo"], function (_export) {
|
||||
var _foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
_foo = m
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
var foo = _interopRequire(_foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user