Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44f2f701e1 | ||
|
|
032bc0af5e | ||
|
|
0e822a7e54 | ||
|
|
51e521f0e0 | ||
|
|
e5ce69d6af | ||
|
|
e3b8fa93e2 | ||
|
|
f4ce3a23ad | ||
|
|
39f4696ac7 | ||
|
|
4a9918ec6b | ||
|
|
c87e14f6a9 | ||
|
|
680771c81b | ||
|
|
cad3f63723 | ||
|
|
eceda64528 | ||
|
|
b8ec87e058 | ||
|
|
04bd023787 | ||
|
|
f1759dc419 | ||
|
|
2985f1b40b |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
# 1.13.11
|
||||
|
||||
* Fix `util.regexify` on falsy values.
|
||||
* Fix `_aliasFunction` with rest parameters.
|
||||
* Export as `module.exports` instead of `exports.default` if there are no other `ExportDeclaration`s in `commonInterop` module formatter.
|
||||
* Add `system` module formatter. Thanks [@douglasduteil](https://github.com/douglasduteil).
|
||||
|
||||
# 1.13.10
|
||||
|
||||
* Add support for `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
# 1.13.9
|
||||
|
||||
* Fix `VirtualPropertyExpression` visitor keys.
|
||||
|
||||
# 1.13.8
|
||||
|
||||
* Only use a single reference in abstract references.
|
||||
|
||||
100
doc/modules.md
100
doc/modules.md
@@ -51,6 +51,69 @@ var test = 5; exports.test = test;
|
||||
exports.default = test;
|
||||
```
|
||||
|
||||
### Common interop
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import "foo";
|
||||
|
||||
import foo from "foo";
|
||||
import * as foo from "foo";
|
||||
|
||||
import {bar} from "foo";
|
||||
import {foo as bar} from "foo";
|
||||
|
||||
export {test};
|
||||
export var test = 5;
|
||||
|
||||
export default test;
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
require("foo");
|
||||
|
||||
var foo = _interopRequire(require("foo"));
|
||||
var foo = require("foo");
|
||||
|
||||
var bar = require("foo").bar;
|
||||
var bar = require("foo").foo;
|
||||
|
||||
exports.test = test;
|
||||
var test = exports.test = 5;
|
||||
|
||||
exports["default"] = test;
|
||||
```
|
||||
|
||||
#### module.exports behaviour
|
||||
|
||||
If there exist no other non-default `export`s then `default exports` are
|
||||
exported as `module.exports` instead of `exports.default`.
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
export default function foo() {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
module.exports = foo;
|
||||
|
||||
function foo() {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### AMD
|
||||
|
||||
**In**
|
||||
@@ -135,6 +198,43 @@ function bar() {
|
||||
}
|
||||
```
|
||||
|
||||
### Register
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import foo from "foo";
|
||||
|
||||
export function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
System.register("bar", ["foo"], function ($__export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "bar";
|
||||
|
||||
var foo;
|
||||
function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m.default;
|
||||
}],
|
||||
execute: function () {
|
||||
$__export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Custom
|
||||
|
||||
You can alternatively specify module names instead of one of the built-in types.
|
||||
|
||||
@@ -10,9 +10,7 @@ var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
@@ -168,6 +166,7 @@ File.prototype.parse = function (code) {
|
||||
File.prototype.transform = function (ast) {
|
||||
this.ast = ast;
|
||||
this.scope = new Scope(ast.program);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
1
lib/6to5/templates/exports-default-module.js
Normal file
1
lib/6to5/templates/exports-default-module.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = VALUE;
|
||||
1
lib/6to5/templates/register.js
Normal file
1
lib/6to5/templates/register.js
Normal file
@@ -0,0 +1 @@
|
||||
System.register(MODULE_NAME, MODULE_DEPENDENCIES, MODULE_BODY);
|
||||
@@ -41,34 +41,11 @@ AMDFormatter.prototype.transform = function (ast) {
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (!opts.amdModuleIds) {
|
||||
if (this.file.opts.amdModuleIds) {
|
||||
return CommonJSFormatter.prototype.getModuleName.apply(this, arguments);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, "");
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
// remove sourceRoot from filename
|
||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
AMDFormatter.prototype._push = function (node) {
|
||||
|
||||
@@ -4,8 +4,9 @@ var CommonJSFormatter = require("./common");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function CommonJSInteropFormatter(file) {
|
||||
this.file = file;
|
||||
function CommonJSInteropFormatter() {
|
||||
this.has = false;
|
||||
CommonJSFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(CommonJSInteropFormatter, CommonJSFormatter);
|
||||
@@ -26,3 +27,27 @@ CommonJSInteropFormatter.prototype.importSpecifier = function (specifier, node,
|
||||
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSInteropFormatter.prototype.export = function (node, nodes) {
|
||||
if (node.default && !this.has) {
|
||||
var declar = node.declaration;
|
||||
|
||||
// module.exports = VALUE;
|
||||
var assign = util.template("exports-default-module", {
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true);
|
||||
|
||||
// hoist to the top if this default is a function
|
||||
nodes.push(this._hoistExport(declar, assign));
|
||||
return;
|
||||
} else {
|
||||
this.has = true;
|
||||
}
|
||||
|
||||
CommonJSFormatter.prototype.export.apply(this, arguments);
|
||||
};
|
||||
|
||||
CommonJSInteropFormatter.prototype.exportSpecifier = function () {
|
||||
this.has = true;
|
||||
CommonJSFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
};
|
||||
|
||||
@@ -7,6 +7,33 @@ function CommonJSFormatter(file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
CommonJSFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, "");
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
// remove sourceRoot from filename
|
||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.import = function (node, nodes) {
|
||||
// import "foo";
|
||||
nodes.push(util.template("require", {
|
||||
@@ -38,23 +65,32 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
}));
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype._hoistExport = function (declar, assign) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = true;
|
||||
}
|
||||
|
||||
return assign;
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype._pushStatement = function (ref, nodes) {
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
nodes.push(t.toStatement(ref));
|
||||
ref = ref.id;
|
||||
}
|
||||
}
|
||||
return ref;
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.export = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
if (node.default) {
|
||||
var ref = declar;
|
||||
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
nodes.push(t.toStatement(ref));
|
||||
ref = ref.id;
|
||||
}
|
||||
}
|
||||
|
||||
nodes.push(util.template("exports-default", {
|
||||
//inherits: node,
|
||||
|
||||
VALUE: ref
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true));
|
||||
} else {
|
||||
var assign;
|
||||
@@ -83,9 +119,7 @@ CommonJSFormatter.prototype.export = function (node, nodes) {
|
||||
nodes.push(t.toStatement(declar));
|
||||
nodes.push(assign);
|
||||
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = true;
|
||||
}
|
||||
this._hoistExport(declar, assign);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -126,7 +160,7 @@ CommonJSFormatter.prototype._exportSpecifier = function (getRef, specifier, node
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
return this._exportSpecifier(function () {
|
||||
this._exportSpecifier(function () {
|
||||
return t.callExpression(t.identifier("require"), [node.source]);
|
||||
}, specifier, node, nodes);
|
||||
};
|
||||
|
||||
203
lib/6to5/transformation/modules/system.js
Normal file
203
lib/6to5/transformation/modules/system.js
Normal file
@@ -0,0 +1,203 @@
|
||||
module.exports = SystemFormatter;
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var SETTER_MODULE_NAMESPACE = t.identifier("m");
|
||||
var DEFAULT_IDENTIFIER = t.identifier("default");
|
||||
var NULL_SETTER = t.literal(null);
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportedStatements = [];
|
||||
this.importedModule = {};
|
||||
|
||||
this.exportIdentifier = file.generateUidIdentifier("export");
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
SystemFormatter.prototype.transform = function (ast) {
|
||||
var program = ast.program;
|
||||
var body = program.body;
|
||||
|
||||
// extract the module name
|
||||
var moduleName = this.file.opts.filename
|
||||
.replace(/^.*\//, "").replace(/\..*$/, "");
|
||||
|
||||
// build an array of module names
|
||||
var dependencies = Object.keys(this.importedModule).map(t.literal);
|
||||
|
||||
// generate the __moduleName variable
|
||||
var moduleNameVariableNode = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
t.identifier("__moduleName"),
|
||||
t.literal(moduleName)
|
||||
)
|
||||
]);
|
||||
body.splice(1, 0, moduleNameVariableNode);
|
||||
|
||||
// generate an array of import variables
|
||||
|
||||
var declaredSetters = _(this.importedModule)
|
||||
.map()
|
||||
.flatten()
|
||||
.pluck("variableName")
|
||||
.pluck("name")
|
||||
.uniq()
|
||||
.map(t.identifier)
|
||||
.map(function (name) {
|
||||
return t.variableDeclarator(name);
|
||||
})
|
||||
.value();
|
||||
|
||||
if (declaredSetters.length) {
|
||||
body.splice(2, 0, t.variableDeclaration("var", declaredSetters));
|
||||
}
|
||||
|
||||
// generate the execute function expression
|
||||
var executeFunctionExpression = t.functionExpression(
|
||||
null, [], t.blockStatement(this.exportedStatements)
|
||||
);
|
||||
|
||||
// generate the execute function expression
|
||||
var settersArrayExpression = t.arrayExpression(this._buildSetters());
|
||||
|
||||
// generate the return statement
|
||||
var moduleReturnStatement = t.returnStatement(t.objectExpression([
|
||||
t.property("init", t.identifier("setters"), settersArrayExpression),
|
||||
t.property("init", t.identifier("execute"), executeFunctionExpression)
|
||||
]));
|
||||
body.push(moduleReturnStatement);
|
||||
|
||||
// runner
|
||||
var runner = util.template("register", {
|
||||
MODULE_NAME: t.literal(moduleName),
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(dependencies),
|
||||
MODULE_BODY: t.functionExpression(
|
||||
null,
|
||||
[this.exportIdentifier],
|
||||
t.blockStatement(body)
|
||||
)
|
||||
});
|
||||
|
||||
program.body = [t.expressionStatement(runner)];
|
||||
};
|
||||
|
||||
|
||||
SystemFormatter.prototype._buildSetters = function () {
|
||||
// generate setters array expression elements
|
||||
return _.map(this.importedModule, function (specs) {
|
||||
if (!specs.length) {
|
||||
return NULL_SETTER;
|
||||
}
|
||||
|
||||
var expressionStatements = _.map(specs, function (spec) {
|
||||
var right = SETTER_MODULE_NAMESPACE;
|
||||
if (!spec.isBatch) {
|
||||
right = t.memberExpression(right, spec.key);
|
||||
}
|
||||
|
||||
return t.expressionStatement(
|
||||
t.assignmentExpression("=", spec.variableName, right
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
return t.functionExpression(
|
||||
null, [SETTER_MODULE_NAMESPACE], t.blockStatement(expressionStatements)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.import = function (node) {
|
||||
var MODULE_NAME = node.source.value;
|
||||
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.importSpecifier = function (specifier, node) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
// import foo from "foo";
|
||||
if (specifier.default) {
|
||||
specifier.id = DEFAULT_IDENTIFIER;
|
||||
}
|
||||
|
||||
var MODULE_NAME = node.source.value;
|
||||
|
||||
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
|
||||
|
||||
this.importedModule[MODULE_NAME].push({
|
||||
variableName: variableName,
|
||||
isBatch: specifier.type === "ImportBatchSpecifier",
|
||||
key: specifier.id
|
||||
});
|
||||
};
|
||||
|
||||
SystemFormatter.prototype._export = function (name, identifier) {
|
||||
this.exportedStatements.push(t.expressionStatement(
|
||||
t.callExpression(this.exportIdentifier, [t.literal(name), identifier])
|
||||
));
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.export = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
var variableName, identifier;
|
||||
|
||||
if (node.default) {
|
||||
// export default foo
|
||||
variableName = DEFAULT_IDENTIFIER.name;
|
||||
if (t.isClass(declar) || t.isFunction(declar)) {
|
||||
if (!declar.id) {
|
||||
declar.id = this.file.generateUidIdentifier("anonymous");
|
||||
}
|
||||
|
||||
nodes.push(t.toStatement(declar));
|
||||
declar = declar.id;
|
||||
}
|
||||
|
||||
identifier = declar;
|
||||
} else if (t.isVariableDeclaration(declar)) {
|
||||
// export var foo
|
||||
variableName = declar.declarations[0].id.name;
|
||||
identifier = declar.declarations[0].id;
|
||||
|
||||
nodes.push(declar);
|
||||
} else {
|
||||
// export function foo () {}
|
||||
variableName = declar.id.name;
|
||||
identifier = declar.id;
|
||||
|
||||
nodes.push(declar);
|
||||
}
|
||||
|
||||
this._export(variableName, identifier);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.exportSpecifier = function (specifier, node) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
if (node.source) {
|
||||
if (t.isExportBatchSpecifier(specifier)) {
|
||||
// export * from "foo";
|
||||
var exportIdentifier = t.identifier("exports");
|
||||
this.exportedStatements.push(
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(exportIdentifier, this.exportIdentifier)
|
||||
])
|
||||
);
|
||||
|
||||
this.exportedStatements.push(util.template("exports-wildcard", {
|
||||
OBJECT: t.identifier(node.source.value)
|
||||
}, true));
|
||||
} else {
|
||||
// export { foo } from "test";
|
||||
this._export(variableName.name, t.memberExpression(
|
||||
t.identifier(node.source.value),
|
||||
specifier.id
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// export { foo };
|
||||
this._export(variableName.name, specifier.id);
|
||||
}
|
||||
};
|
||||
@@ -22,6 +22,7 @@ transform.transformers = {};
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
commonInterop: require("./modules/common-interop"),
|
||||
system: require("./modules/system"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
|
||||
@@ -31,7 +31,7 @@ var go = function (getBody, node, file, scope) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node._ignoreAliasFunctions) return;
|
||||
if (node._ignoreAliasFunctions) return false;
|
||||
|
||||
var getId;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// TODO: Clean up
|
||||
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -183,10 +185,38 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file) {
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
if (parent.type === "ExpressionStatement") return;
|
||||
if (!t.isPattern(node.left)) return;
|
||||
throw file.errorWithNode(node, "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations");
|
||||
|
||||
var tempName = file.generateUid("temp", scope);
|
||||
var temp = t.identifier(tempName);
|
||||
scope.push(tempName, temp);
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(t.assignmentExpression("=", temp, node.right));
|
||||
|
||||
push({
|
||||
kind: false,
|
||||
file: file,
|
||||
scope: scope
|
||||
}, nodes, node.left, temp);
|
||||
|
||||
nodes.push(temp);
|
||||
|
||||
nodes = nodes.map(function (node) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
return node.expression;
|
||||
} else if (t.isVariableDeclaration(node)) {
|
||||
var declar = node.declarations[0];
|
||||
scope.push(declar.id.name, declar.id);
|
||||
return t.assignmentExpression("=", declar.id, declar.init);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
});
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
|
||||
@@ -5,10 +5,10 @@ exports.ImportDeclaration = function (node, parent, file) {
|
||||
|
||||
if (node.specifiers.length) {
|
||||
_.each(node.specifiers, function (specifier) {
|
||||
file.moduleFormatter.importSpecifier(specifier, node, nodes);
|
||||
file.moduleFormatter.importSpecifier(specifier, node, nodes, parent);
|
||||
});
|
||||
} else {
|
||||
file.moduleFormatter.import(node, nodes);
|
||||
file.moduleFormatter.import(node, nodes, parent);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
@@ -18,10 +18,10 @@ exports.ExportDeclaration = function (node, parent, file) {
|
||||
var nodes = [];
|
||||
|
||||
if (node.declaration) {
|
||||
file.moduleFormatter.export(node, nodes);
|
||||
file.moduleFormatter.export(node, nodes, parent);
|
||||
} else {
|
||||
_.each(node.specifiers, function (specifier) {
|
||||
file.moduleFormatter.exportSpecifier(specifier, node, nodes);
|
||||
file.moduleFormatter.exportSpecifier(specifier, node, nodes, parent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ Scope.prototype.push = function (name, id, init) {
|
||||
init: init
|
||||
};
|
||||
} else {
|
||||
throw new Error("wtf");
|
||||
throw new TypeError("cannot add a declaration here in node type " + block.type);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
"UpdateExpression": ["argument"],
|
||||
"VariableDeclaration": ["declarations"],
|
||||
"VariableDeclarator": ["id", "init"],
|
||||
"VirtualPropertyExpression": ["left", "right"],
|
||||
"VirtualPropertyExpression": ["object", "property"],
|
||||
"WhileStatement": ["test", "body"],
|
||||
"WithStatement": ["object", "body"],
|
||||
"XJSAttribute": ["name", "value"],
|
||||
|
||||
@@ -38,9 +38,9 @@ exports.list = function (val) {
|
||||
};
|
||||
|
||||
exports.regexify = function (val) {
|
||||
if (!val) return new RegExp;
|
||||
if (!val) return new RegExp(/.^/);
|
||||
if (_.isArray(val)) val = val.join("|");
|
||||
if (_.isString(val)) return new RegExp(val || "");
|
||||
if (_.isString(val)) return new RegExp(val);
|
||||
if (_.isRegExp(val)) return val;
|
||||
throw new TypeError("illegal type for regexify");
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.13.8",
|
||||
"version": "1.13.11",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
console.log([x] = [1]);
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations"
|
||||
}
|
||||
9
test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js
vendored
Normal file
9
test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _ref;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
};
|
||||
|
||||
var _temp;
|
||||
console.log((_temp = [123], _ref = _toArray(_temp), x = _ref[0], _temp));
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations"
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
exports["default"] = 42;
|
||||
exports["default"] = {};
|
||||
exports["default"] = [];
|
||||
exports["default"] = foo;
|
||||
exports["default"] = function () {};
|
||||
exports["default"] = function () {};
|
||||
module.exports = foo;
|
||||
module.exports = 42;
|
||||
module.exports = {};
|
||||
module.exports = [];
|
||||
module.exports = foo;
|
||||
module.exports = function () {};
|
||||
module.exports = function () {};
|
||||
function foo() {}
|
||||
exports["default"] = foo;
|
||||
var Foo = function Foo() {};
|
||||
|
||||
exports["default"] = Foo;
|
||||
module.exports = Foo;
|
||||
|
||||
8
test/fixtures/transformation/es6-modules-system/exports-default/actual.js
vendored
Normal file
8
test/fixtures/transformation/es6-modules-system/exports-default/actual.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export default 42;
|
||||
export default {};
|
||||
export default [];
|
||||
export default foo;
|
||||
export default function () {}
|
||||
export default class {}
|
||||
export default function foo () {}
|
||||
export default class Foo {}
|
||||
32
test/fixtures/transformation/es6-modules-system/exports-default/expected.js
vendored
Normal file
32
test/fixtures/transformation/es6-modules-system/exports-default/expected.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
function _anonymous() {}
|
||||
var _anonymous2 = function _anonymous2() {};
|
||||
|
||||
function foo() {}
|
||||
var Foo = function Foo() {};
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("default", 42);
|
||||
|
||||
_export("default", {});
|
||||
|
||||
_export("default", []);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("default", _anonymous);
|
||||
|
||||
_export("default", _anonymous2);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("default", Foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
6
test/fixtures/transformation/es6-modules-system/exports-from/actual.js
vendored
Normal file
6
test/fixtures/transformation/es6-modules-system/exports-from/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from "foo";
|
||||
export {foo} from "foo";
|
||||
export {foo, bar} from "foo";
|
||||
export {foo as bar} from "foo";
|
||||
export {foo as default} from "foo";
|
||||
export {foo as default, bar} from "foo";
|
||||
31
test/fixtures/transformation/es6-modules-system/exports-from/expected.js
vendored
Normal file
31
test/fixtures/transformation/es6-modules-system/exports-from/expected.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
var exports = _export;
|
||||
(function (obj) {
|
||||
for (var i in obj) {
|
||||
exports[i] = obj[i];
|
||||
}
|
||||
})(foo);
|
||||
|
||||
_export("foo", foo.foo);
|
||||
|
||||
_export("foo", foo.foo);
|
||||
|
||||
_export("bar", foo.bar);
|
||||
|
||||
_export("bar", foo.foo);
|
||||
|
||||
_export("default", foo.foo);
|
||||
|
||||
_export("default", foo.foo);
|
||||
|
||||
_export("bar", foo.bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
5
test/fixtures/transformation/es6-modules-system/exports-named/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-modules-system/exports-named/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export {foo};
|
||||
export {foo, bar};
|
||||
export {foo as bar};
|
||||
export {foo as default};
|
||||
export {foo as default, bar};
|
||||
24
test/fixtures/transformation/es6-modules-system/exports-named/expected.js
vendored
Normal file
24
test/fixtures/transformation/es6-modules-system/exports-named/expected.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("foo", foo);
|
||||
|
||||
_export("foo", foo);
|
||||
|
||||
_export("bar", bar);
|
||||
|
||||
_export("bar", foo);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
8
test/fixtures/transformation/es6-modules-system/exports-variable/actual.js
vendored
Normal file
8
test/fixtures/transformation/es6-modules-system/exports-variable/actual.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export var foo = 1;
|
||||
export var foo2 = function () {};
|
||||
export var foo3;
|
||||
export let foo4 = 2;
|
||||
export let foo5;
|
||||
export const foo6 = 3;
|
||||
export function foo7 () {}
|
||||
export class foo8 {}
|
||||
35
test/fixtures/transformation/es6-modules-system/exports-variable/expected.js
vendored
Normal file
35
test/fixtures/transformation/es6-modules-system/exports-variable/expected.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo = 1;
|
||||
var foo2 = function () {};
|
||||
var foo3;
|
||||
var foo4 = 2;
|
||||
var foo5;
|
||||
var foo6 = 3;
|
||||
function foo7() {}
|
||||
var foo8 = function foo8() {};
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("foo", foo);
|
||||
|
||||
_export("foo2", foo2);
|
||||
|
||||
_export("foo3", foo3);
|
||||
|
||||
_export("foo4", foo4);
|
||||
|
||||
_export("foo5", foo5);
|
||||
|
||||
_export("foo6", foo6);
|
||||
|
||||
_export("foo7", foo7);
|
||||
|
||||
_export("foo8", foo8);
|
||||
}
|
||||
};
|
||||
});
|
||||
11
test/fixtures/transformation/es6-modules-system/hoist-function-exports/actual.js
vendored
Normal file
11
test/fixtures/transformation/es6-modules-system/hoist-function-exports/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { isEven } from "./evens";
|
||||
|
||||
export function nextOdd(n) {
|
||||
return isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
export var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(isEven);
|
||||
25
test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js
vendored
Normal file
25
test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
System.register("actual", ["./evens"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var isEven;
|
||||
function nextOdd(n) {
|
||||
return isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(isEven);return {
|
||||
setters: [function (m) {
|
||||
isEven = m.isEven;
|
||||
}],
|
||||
execute: function () {
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
_export("isOdd", isOdd);
|
||||
}
|
||||
};
|
||||
});
|
||||
2
test/fixtures/transformation/es6-modules-system/imports-default/actual.js
vendored
Normal file
2
test/fixtures/transformation/es6-modules-system/imports-default/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import foo from "foo";
|
||||
import {default as foo} from "foo";
|
||||
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("actual", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m.default;
|
||||
foo = m.default;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
1
test/fixtures/transformation/es6-modules-system/imports-glob/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-modules-system/imports-glob/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import * as foo from "foo";
|
||||
13
test/fixtures/transformation/es6-modules-system/imports-glob/expected.js
vendored
Normal file
13
test/fixtures/transformation/es6-modules-system/imports-glob/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
System.register("actual", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
1
test/fixtures/transformation/es6-modules-system/imports-mixing/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-modules-system/imports-mixing/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import foo, {baz as xyz} from "foo";
|
||||
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("actual", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo, xyz;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m.default;
|
||||
xyz = m.baz;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
4
test/fixtures/transformation/es6-modules-system/imports-named/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-modules-system/imports-named/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import {bar} from "foo";
|
||||
import {bar, baz} from "foo";
|
||||
import {bar as baz} from "foo";
|
||||
import {bar as baz, xyz} from "foo";
|
||||
18
test/fixtures/transformation/es6-modules-system/imports-named/expected.js
vendored
Normal file
18
test/fixtures/transformation/es6-modules-system/imports-named/expected.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
System.register("actual", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var bar, baz, xyz;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
bar = m.bar;
|
||||
bar = m.bar;
|
||||
baz = m.baz;
|
||||
baz = m.bar;
|
||||
baz = m.bar;
|
||||
xyz = m.xyz;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
3
test/fixtures/transformation/es6-modules-system/imports/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-modules-system/imports/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import "foo";
|
||||
import "foo-bar";
|
||||
import "./directory/foo-bar";
|
||||
10
test/fixtures/transformation/es6-modules-system/imports/expected.js
vendored
Normal file
10
test/fixtures/transformation/es6-modules-system/imports/expected.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
System.register("actual", ["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [null, null, null],
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
3
test/fixtures/transformation/es6-modules-system/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-modules-system/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"modules": "system"
|
||||
}
|
||||
12
test/fixtures/transformation/es6-modules-system/overview/actual.js
vendored
Normal file
12
test/fixtures/transformation/es6-modules-system/overview/actual.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import "foo";
|
||||
import "foo-bar";
|
||||
import "./directory/foo-bar";
|
||||
import foo from "foo";
|
||||
import * as foo from "foo";
|
||||
import {bar} from "foo";
|
||||
import {foo as bar} from "foo";
|
||||
|
||||
export {test};
|
||||
export var test = 5;
|
||||
|
||||
export default test;
|
||||
24
test/fixtures/transformation/es6-modules-system/overview/expected.js
vendored
Normal file
24
test/fixtures/transformation/es6-modules-system/overview/expected.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
System.register("actual", ["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo, bar;
|
||||
var test = 5;
|
||||
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m.default;
|
||||
foo = m;
|
||||
bar = m.bar;
|
||||
bar = m.foo;
|
||||
}, null, null],
|
||||
execute: function () {
|
||||
_export("test", test);
|
||||
|
||||
_export("test", test);
|
||||
|
||||
_export("default", test);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _arguments = arguments;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
@@ -11,5 +10,5 @@ var _argumentsToArray = function (args) {
|
||||
};
|
||||
|
||||
var concat = function () {
|
||||
var arrs = _argumentsToArray(_arguments);
|
||||
var arrs = _argumentsToArray(arguments);
|
||||
};
|
||||
|
||||
@@ -58,10 +58,10 @@ suite("util", function () {
|
||||
});
|
||||
|
||||
test("regexify", function () {
|
||||
assert.deepEqual(util.regexify(undefined), /(?:)/);
|
||||
assert.deepEqual(util.regexify(false), /(?:)/);
|
||||
assert.deepEqual(util.regexify(null), /(?:)/);
|
||||
assert.deepEqual(util.regexify(""), /(?:)/);
|
||||
assert.deepEqual(util.regexify(undefined), /.^/);
|
||||
assert.deepEqual(util.regexify(false), /.^/);
|
||||
assert.deepEqual(util.regexify(null), /.^/);
|
||||
assert.deepEqual(util.regexify(""), /.^/);
|
||||
assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/);
|
||||
assert.deepEqual(util.regexify("foobar"), /foobar/);
|
||||
assert.deepEqual(util.regexify(/foobar/), /foobar/);
|
||||
|
||||
Reference in New Issue
Block a user