Merge branch 'traceur'
This commit is contained in:
commit
62818d468e
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "vendor/traceur"]
|
||||||
|
path = vendor/traceur
|
||||||
|
url = https://github.com/google/traceur-compiler
|
||||||
|
[submodule "vendor/regenerator"]
|
||||||
|
path = vendor/regenerator
|
||||||
|
url = https://github.com/facebook/regenerator
|
||||||
6
Makefile
6
Makefile
@ -6,7 +6,7 @@ MOCHA_CMD = node_modules/mocha/bin/_mocha
|
|||||||
|
|
||||||
export NODE_ENV = test
|
export NODE_ENV = test
|
||||||
|
|
||||||
.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build
|
.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build bootstrap
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@ -81,3 +81,7 @@ publish:
|
|||||||
git push --follow-tags
|
git push --follow-tags
|
||||||
|
|
||||||
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
||||||
|
|
||||||
|
bootstrap:
|
||||||
|
git submodule update --init
|
||||||
|
cd vendor/regenerator; npm install
|
||||||
|
|||||||
@ -78,43 +78,43 @@ that when you turn it off and use your code in a full ES6 environment
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
|
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
|
||||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
|
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
|
||||||
| Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ |
|
| Source maps | ✓ | ✓ | ✓ | | ✓ |
|
||||||
| No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ |
|
| No compiler global pollution | ✓ | | ✓ | | ✓ |
|
||||||
| Optional runtime | ✓ | | ✓ | | | ✓ |
|
| Optional runtime | ✓ | | ✓ | | ✓ |
|
||||||
| Browser compiler | ✓ | ✓ | | ✓ | | |
|
| Browser compiler | ✓ | ✓ | | | |
|
||||||
|
|
||||||
### Language Support
|
### Language Support
|
||||||
|
|
||||||
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
|
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
|
||||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
|
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
|
||||||
| Abstract references | ✓ | | | | | |
|
| Abstract references | ✓ | | | | |
|
||||||
| Array comprehension | ✓ | ✓ | ✓ | | | |
|
| Array comprehension | ✓ | ✓ | ✓ | | |
|
||||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Async functions | ✓ | ✓ | | ✓ | | |
|
| Async functions | ✓ | ✓ | | | |
|
||||||
| Async generator functions | ✓ | ✓ | | | | |
|
| Async generator functions | ✓ | ✓ | | | |
|
||||||
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| Computed property names | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Constants | ✓ | ✓ | ✓ | | | |
|
| Constants | ✓ | ✓ | ✓ | | |
|
||||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| Default parameters | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Exponentiation operator | ✓ | ✓ | | | | |
|
| Exponentiation operator | ✓ | ✓ | | | |
|
||||||
| Flow types | ✓ | | | | | ✓ |
|
| Flow types | ✓ | | | | ✓ |
|
||||||
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| For-of | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Generators | ✓ | ✓ | | ✓ | | |
|
| Generators | ✓ | ✓ | | | |
|
||||||
| Generator comprehension | ✓ | ✓ | | | | |
|
| Generator comprehension | ✓ | ✓ | | | |
|
||||||
| JSX | ✓ | | | | | |
|
| JSX | ✓ | | | | |
|
||||||
| Let scoping | ✓ | ✓ | ✓ | | | |
|
| Let scoping | ✓ | ✓ | ✓ | | |
|
||||||
| Modules | ✓ | ✓ | | | ✓ | |
|
| Modules | ✓ | ✓ | | ✓ | |
|
||||||
| Object rest/spread | ✓ | | | | | ✓ |
|
| Object rest/spread | ✓ | | | | ✓ |
|
||||||
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| React | ✓ | | | | | |
|
| React | ✓ | | | | |
|
||||||
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
| Spread | ✓ | ✓ | ✓ | ✓ | |
|
||||||
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Unicode regex | ✓ | ✓ | ✓ | | | |
|
| Unicode regex | ✓ | ✓ | ✓ | | |
|
||||||
|
|
||||||
### [Traceur](https://github.com/google/traceur-compiler)
|
### [Traceur](https://github.com/google/traceur-compiler)
|
||||||
|
|
||||||
|
|||||||
@ -10,11 +10,12 @@ var t = require("./types");
|
|||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
function File(opts) {
|
function File(opts) {
|
||||||
this.dynamicImports = [];
|
this.dynamicImports = [];
|
||||||
this.opts = File.normaliseOptions(opts);
|
this.dynamicImportIds = {};
|
||||||
this.transformers = this.getTransformers();
|
this.opts = File.normaliseOptions(opts);
|
||||||
this.uids = {};
|
this.transformers = this.getTransformers();
|
||||||
this.ast = {};
|
this.uids = {};
|
||||||
|
this.ast = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
File.helpers = [
|
File.helpers = [
|
||||||
@ -29,12 +30,16 @@ File.helpers = [
|
|||||||
"object-without-properties",
|
"object-without-properties",
|
||||||
"has-own",
|
"has-own",
|
||||||
"slice",
|
"slice",
|
||||||
|
"bind",
|
||||||
"define-property",
|
"define-property",
|
||||||
"async-to-generator"
|
"async-to-generator",
|
||||||
|
"interop-require-wildcard",
|
||||||
|
"typeof"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.excludeHelpersFromRuntime = [
|
File.excludeHelpersFromRuntime = [
|
||||||
"async-to-generator"
|
"async-to-generator",
|
||||||
|
"typeof"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.normaliseOptions = function (opts) {
|
File.normaliseOptions = function (opts) {
|
||||||
@ -160,11 +165,20 @@ File.prototype.parseShebang = function (code) {
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.addImport = function (id, source) {
|
File.prototype.addImport = function (source, name) {
|
||||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
name = name || source;
|
||||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
var id = this.dynamicImportIds[name];
|
||||||
declar._blockHoist = 3;
|
|
||||||
this.dynamicImports.push(declar);
|
if (!id) {
|
||||||
|
id = this.dynamicImportIds[name] = this.generateUidIdentifier(name);
|
||||||
|
|
||||||
|
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||||
|
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||||
|
declar._blockHoist = 3;
|
||||||
|
this.dynamicImports.push(declar);
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.addHelper = function (name) {
|
File.prototype.addHelper = function (name) {
|
||||||
@ -273,7 +287,7 @@ File.prototype.generate = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.generateUid = function (name, scope) {
|
File.prototype.generateUid = function (name, scope) {
|
||||||
name = t.toIdentifier(name);
|
name = t.toIdentifier(name).replace(/^_+/, "");
|
||||||
|
|
||||||
scope = scope || this.scope;
|
scope = scope || this.scope;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.UnaryExpression = function (node, print) {
|
exports.UnaryExpression = function (node, print) {
|
||||||
var hasSpace = /[a-z]$/.test(node.operator);
|
var hasSpace = /[a-z]$/.test(node.operator);
|
||||||
@ -86,6 +87,7 @@ exports.ExpressionStatement = function (node, print) {
|
|||||||
|
|
||||||
exports.BinaryExpression =
|
exports.BinaryExpression =
|
||||||
exports.LogicalExpression =
|
exports.LogicalExpression =
|
||||||
|
exports.AssignmentPattern =
|
||||||
exports.AssignmentExpression = function (node, print) {
|
exports.AssignmentExpression = function (node, print) {
|
||||||
print(node.left);
|
print(node.left);
|
||||||
this.push(" " + node.operator + " ");
|
this.push(" " + node.operator + " ");
|
||||||
@ -102,7 +104,12 @@ exports.MemberExpression = function (node, print) {
|
|||||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.computed) {
|
var computed = node.computed;
|
||||||
|
if (t.isLiteral(node.property) && _.isNumber(node.property.value)) {
|
||||||
|
computed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (computed) {
|
||||||
this.push("[");
|
this.push("[");
|
||||||
print(node.property);
|
print(node.property);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
|
|||||||
@ -61,9 +61,12 @@ Node.prototype.needsParens = function () {
|
|||||||
if (!parent) return false;
|
if (!parent) return false;
|
||||||
|
|
||||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||||
return t.isCallExpression(node) || _.some(node, function (val) {
|
if (t.isCallExpression(node)) return true;
|
||||||
|
|
||||||
|
var hasCall = _.some(node, function (val) {
|
||||||
return t.isCallExpression(val);
|
return t.isCallExpression(val);
|
||||||
});
|
});
|
||||||
|
if (hasCall) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return find(parens, node, parent);
|
return find(parens, node, parent);
|
||||||
|
|||||||
@ -13,7 +13,8 @@ _.each([
|
|||||||
["<", ">", "<=", ">=", "in", "instanceof"],
|
["<", ">", "<=", ">=", "in", "instanceof"],
|
||||||
[">>", "<<", ">>>"],
|
[">>", "<<", ">>>"],
|
||||||
["+", "-"],
|
["+", "-"],
|
||||||
["*", "/", "%"]
|
["*", "/", "%"],
|
||||||
|
["**"]
|
||||||
], function (tier, i) {
|
], function (tier, i) {
|
||||||
_.each(tier, function (op) {
|
_.each(tier, function (op) {
|
||||||
PRECEDENCE[op] = i;
|
PRECEDENCE[op] = i;
|
||||||
@ -35,7 +36,7 @@ exports.ObjectExpression = function (node, parent) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.Binary = function (node, parent) {
|
exports.Binary = function (node, parent) {
|
||||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,12 @@ var types = require("ast-types");
|
|||||||
var def = types.Type.def;
|
var def = types.Type.def;
|
||||||
var or = types.Type.or;
|
var or = types.Type.or;
|
||||||
|
|
||||||
|
def("AssignmentPattern")
|
||||||
|
.bases("Pattern")
|
||||||
|
.build("left", "right")
|
||||||
|
.field("left", def("Pattern"))
|
||||||
|
.field("right", def("Expression"));
|
||||||
|
|
||||||
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
|
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
|
||||||
def("ImportBatchSpecifier")
|
def("ImportBatchSpecifier")
|
||||||
.bases("Specifier")
|
.bases("Specifier")
|
||||||
|
|||||||
@ -141,10 +141,17 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
|
|||||||
// export * from "foo";
|
// export * from "foo";
|
||||||
nodes.push(this._exportsWildcard(getRef(), node));
|
nodes.push(this._exportsWildcard(getRef(), node));
|
||||||
} else {
|
} else {
|
||||||
|
var ref;
|
||||||
|
if (t.isSpecifierDefault(specifier.id) || this.noInteropRequire) {
|
||||||
|
ref = t.memberExpression(getRef(), specifier.id);
|
||||||
|
} else {
|
||||||
|
ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]);
|
||||||
|
}
|
||||||
|
|
||||||
// export { foo } from "test";
|
// export { foo } from "test";
|
||||||
nodes.push(this._exportsAssign(
|
nodes.push(this._exportsAssign(
|
||||||
t.getSpecifierName(specifier),
|
t.getSpecifierName(specifier),
|
||||||
t.memberExpression(getRef(), specifier.id),
|
ref,
|
||||||
node
|
node
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,18 +32,24 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
|||||||
)
|
)
|
||||||
]));
|
]));
|
||||||
} else {
|
} else {
|
||||||
// import foo from "foo";
|
if (specifier.type === "ImportBatchSpecifier") {
|
||||||
|
// import * as bar from "foo";
|
||||||
var templateName = "require-assign";
|
nodes.push(t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(
|
||||||
// import * as bar from "foo";
|
variableName,
|
||||||
if (specifier.type !== "ImportBatchSpecifier") templateName += "-key";
|
t.callExpression(this.file.addHelper("interop-require-wildcard"), [
|
||||||
|
t.callExpression(t.identifier("require"), [node.source])
|
||||||
nodes.push(util.template(templateName, {
|
])
|
||||||
VARIABLE_NAME: variableName,
|
)
|
||||||
MODULE_NAME: node.source,
|
]));
|
||||||
KEY: specifier.id
|
} else {
|
||||||
}));
|
// import foo from "foo";
|
||||||
|
nodes.push(util.template("require-assign-key", {
|
||||||
|
VARIABLE_NAME: variableName,
|
||||||
|
MODULE_NAME: node.source,
|
||||||
|
KEY: specifier.id
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,7 +71,7 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
|||||||
// exports = module.exports = VALUE;
|
// exports = module.exports = VALUE;
|
||||||
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
|
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
|
||||||
|
|
||||||
if (t.isFunction(declar) || !this.hasNonDefaultExports) {
|
if (t.isFunctionDeclaration(declar) || !this.hasNonDefaultExports) {
|
||||||
assign = util.template(templateName, {
|
assign = util.template(templateName, {
|
||||||
VALUE: this._pushStatement(declar, nodes)
|
VALUE: this._pushStatement(declar, nodes)
|
||||||
}, true);
|
}, true);
|
||||||
|
|||||||
1
lib/6to5/transformation/templates/bind.js
Normal file
1
lib/6to5/transformation/templates/bind.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
Function.prototype.bind
|
||||||
@ -1,4 +1,7 @@
|
|||||||
(function (child, parent) {
|
(function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
(function (obj) {
|
||||||
|
return obj && obj.constructor === Object ? obj : { default: obj };
|
||||||
|
})
|
||||||
@ -1 +0,0 @@
|
|||||||
var VARIABLE_NAME = require(MODULE_NAME);
|
|
||||||
3
lib/6to5/transformation/templates/typeof.js
Normal file
3
lib/6to5/transformation/templates/typeof.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(function (obj) {
|
||||||
|
return obj && obj.constructor === Symbol ? "symbol" : typeof obj;
|
||||||
|
});
|
||||||
@ -89,6 +89,7 @@ _.each({
|
|||||||
_moduleFormatter: require("./transformers/_module-formatter"),
|
_moduleFormatter: require("./transformers/_module-formatter"),
|
||||||
useStrict: require("./transformers/use-strict"),
|
useStrict: require("./transformers/use-strict"),
|
||||||
|
|
||||||
|
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||||
|
|
||||||
|
|||||||
@ -8,20 +8,25 @@ function Transformer(key, transformer, opts) {
|
|||||||
this.manipulateOptions = transformer.manipulateOptions;
|
this.manipulateOptions = transformer.manipulateOptions;
|
||||||
this.experimental = !!transformer.experimental;
|
this.experimental = !!transformer.experimental;
|
||||||
this.secondPass = !!transformer.secondPass;
|
this.secondPass = !!transformer.secondPass;
|
||||||
this.transformer = Transformer.normalise(transformer);
|
this.transformer = this.normalise(transformer);
|
||||||
this.optional = !!transformer.optional;
|
this.optional = !!transformer.optional;
|
||||||
this.opts = opts || {};
|
this.opts = opts || {};
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transformer.normalise = function (transformer) {
|
Transformer.prototype.normalise = function (transformer) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (_.isFunction(transformer)) {
|
if (_.isFunction(transformer)) {
|
||||||
transformer = { ast: transformer };
|
transformer = { ast: transformer };
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each(transformer, function (fns, type) {
|
_.each(transformer, function (fns, type) {
|
||||||
// hidden property
|
// hidden property
|
||||||
if (type[0] === "_") return;
|
if (type[0] === "_") {
|
||||||
|
self[type] = fns;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_.isFunction(fns)) fns = { enter: fns };
|
if (_.isFunction(fns)) fns = { enter: fns };
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
var _ = require("lodash");
|
var useStrict = require("./use-strict");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
// Priority:
|
// Priority:
|
||||||
//
|
//
|
||||||
@ -17,13 +18,15 @@ exports.Program = {
|
|||||||
}
|
}
|
||||||
if (!hasChange) return;
|
if (!hasChange) return;
|
||||||
|
|
||||||
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
|
useStrict._wrap(node, function () {
|
||||||
var priority = bodyNode._blockHoist;
|
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
|
||||||
if (priority == null) priority = 1;
|
var priority = bodyNode._blockHoist;
|
||||||
if (priority === true) priority = 2;
|
if (priority == null) priority = 1;
|
||||||
return priority;
|
if (priority === true) priority = 2;
|
||||||
});
|
return priority;
|
||||||
|
});
|
||||||
|
|
||||||
node.body = _.flatten(_.values(nodePriorities).reverse());
|
node.body = _.flatten(_.values(nodePriorities).reverse());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
var t = require("../../types");
|
var useStrict = require("./use-strict");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.secondPass = true;
|
exports.secondPass = true;
|
||||||
|
|
||||||
@ -7,23 +8,25 @@ exports.Program = function (node) {
|
|||||||
var kinds = {};
|
var kinds = {};
|
||||||
var kind;
|
var kind;
|
||||||
|
|
||||||
for (var i in node._declarations) {
|
useStrict._wrap(node, function () {
|
||||||
var declar = node._declarations[i];
|
for (var i in node._declarations) {
|
||||||
|
var declar = node._declarations[i];
|
||||||
|
|
||||||
kind = declar.kind || "var";
|
kind = declar.kind || "var";
|
||||||
var declarNode = t.variableDeclarator(declar.id, declar.init);
|
var declarNode = t.variableDeclarator(declar.id, declar.init);
|
||||||
|
|
||||||
if (!declar.init) {
|
if (!declar.init) {
|
||||||
kinds[kind] = kinds[kind] || [];
|
kinds[kind] = kinds[kind] || [];
|
||||||
kinds[kind].push(declarNode);
|
kinds[kind].push(declarNode);
|
||||||
} else {
|
} else {
|
||||||
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
|
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (kind in kinds) {
|
for (kind in kinds) {
|
||||||
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
node._declarations = null;
|
node._declarations = null;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,11 +20,31 @@ var push = function (opts, nodes, elem, parentId) {
|
|||||||
pushObjectPattern(opts, nodes, elem, parentId);
|
pushObjectPattern(opts, nodes, elem, parentId);
|
||||||
} else if (t.isArrayPattern(elem)) {
|
} else if (t.isArrayPattern(elem)) {
|
||||||
pushArrayPattern(opts, nodes, elem, parentId);
|
pushArrayPattern(opts, nodes, elem, parentId);
|
||||||
|
} else if (t.isAssignmentPattern(elem)) {
|
||||||
|
pushAssignmentPattern(opts, nodes, elem, parentId);
|
||||||
} else {
|
} else {
|
||||||
nodes.push(buildVariableAssign(opts, elem, parentId));
|
nodes.push(buildVariableAssign(opts, elem, parentId));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
|
||||||
|
var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||||
|
|
||||||
|
nodes.push(t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(tempParentId, parentId)
|
||||||
|
]));
|
||||||
|
|
||||||
|
nodes.push(buildVariableAssign(
|
||||||
|
opts,
|
||||||
|
pattern.left,
|
||||||
|
t.conditionalExpression(
|
||||||
|
t.binaryExpression("===", tempParentId, t.identifier("undefined")),
|
||||||
|
pattern.right,
|
||||||
|
tempParentId
|
||||||
|
)
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||||
for (var i in pattern.properties) {
|
for (var i in pattern.properties) {
|
||||||
var prop = pattern.properties[i];
|
var prop = pattern.properties[i];
|
||||||
@ -48,6 +68,8 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
|||||||
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
|
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
|
||||||
nodes.push(buildVariableAssign(opts, prop.argument, value));
|
nodes.push(buildVariableAssign(opts, prop.argument, value));
|
||||||
} else {
|
} else {
|
||||||
|
if (t.isLiteral(prop.key)) prop.computed = true;
|
||||||
|
|
||||||
var pattern2 = prop.value;
|
var pattern2 = prop.value;
|
||||||
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
|
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
|
||||||
|
|
||||||
@ -183,6 +205,24 @@ exports.Function = function (node, parent, file, scope) {
|
|||||||
block.body = nodes.concat(block.body);
|
block.body = nodes.concat(block.body);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.CatchClause = function (node, parent, file, scope) {
|
||||||
|
var pattern = node.param;
|
||||||
|
if (!t.isPattern(pattern)) return;
|
||||||
|
|
||||||
|
var ref = file.generateUidIdentifier("ref", scope);
|
||||||
|
node.param = ref;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
|
||||||
|
push({
|
||||||
|
kind: "var",
|
||||||
|
file: file,
|
||||||
|
scope: scope
|
||||||
|
}, nodes, pattern, ref);
|
||||||
|
|
||||||
|
node.body.body = nodes.concat(node.body.body);
|
||||||
|
};
|
||||||
|
|
||||||
exports.ExpressionStatement = function (node, parent, file, scope) {
|
exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||||
var expr = node.expression;
|
var expr = node.expression;
|
||||||
if (expr.type !== "AssignmentExpression") return;
|
if (expr.type !== "AssignmentExpression") return;
|
||||||
|
|||||||
@ -376,7 +376,7 @@ LetScoping.prototype.getLetReferences = function () {
|
|||||||
|
|
||||||
// this scope has a variable with the same name so it couldn't belong
|
// this scope has a variable with the same name so it couldn't belong
|
||||||
// to our let scope
|
// to our let scope
|
||||||
if (scope.hasOwn(node.name)) return;
|
if (scope.hasOwn(node.name, true)) return;
|
||||||
|
|
||||||
closurify = true;
|
closurify = true;
|
||||||
|
|
||||||
@ -388,8 +388,6 @@ LetScoping.prototype.getLetReferences = function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.skip();
|
|
||||||
} else if (t.isLoop(node)) {
|
|
||||||
return this.skip();
|
return this.skip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
var getSpreadLiteral = function (spread, file) {
|
var getSpreadLiteral = function (spread, file) {
|
||||||
return file.toArray(spread.argument);
|
return file.toArray(spread.argument);
|
||||||
@ -98,7 +99,14 @@ exports.NewExpression = function (node, parent, file) {
|
|||||||
var args = node.arguments;
|
var args = node.arguments;
|
||||||
if (!hasSpread(args)) return;
|
if (!hasSpread(args)) return;
|
||||||
|
|
||||||
|
var nativeType = t.isIdentifier(node.callee) && _.contains(t.NATIVE_TYPES_NAMES, node.callee.name);
|
||||||
|
|
||||||
var nodes = build(args, file);
|
var nodes = build(args, file);
|
||||||
|
|
||||||
|
if (nativeType) {
|
||||||
|
nodes.unshift(t.arrayExpression([t.literal(null)]));
|
||||||
|
}
|
||||||
|
|
||||||
var first = nodes.shift();
|
var first = nodes.shift();
|
||||||
|
|
||||||
if (nodes.length) {
|
if (nodes.length) {
|
||||||
@ -107,5 +115,15 @@ exports.NewExpression = function (node, parent, file) {
|
|||||||
args = first;
|
args = first;
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
|
if (nativeType) {
|
||||||
|
return t.newExpression(
|
||||||
|
t.callExpression(
|
||||||
|
t.memberExpression(file.addHelper("bind"), t.identifier("apply")),
|
||||||
|
[node.callee, args]
|
||||||
|
),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -38,8 +38,6 @@ exports._Function = function (node, callId) {
|
|||||||
exports.Function = function (node, parent, file) {
|
exports.Function = function (node, parent, file) {
|
||||||
if (!node.async || node.generator) return;
|
if (!node.async || node.generator) return;
|
||||||
|
|
||||||
var id = t.identifier("Bluebird");
|
var id = file.addImport("bluebird");
|
||||||
file.addImport(id, "bluebird");
|
|
||||||
|
|
||||||
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
|
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -12,8 +12,7 @@ exports.optional = true;
|
|||||||
|
|
||||||
exports.ast = {
|
exports.ast = {
|
||||||
enter: function (ast, file) {
|
enter: function (ast, file) {
|
||||||
file._coreId = file.generateUidIdentifier("core");
|
file._coreId = file.addImport("core-js/library", "core");
|
||||||
file.addImport(file._coreId, "core-js/library");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
exit: function (ast, file) {
|
exit: function (ast, file) {
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
exports.optional = true;
|
||||||
|
|
||||||
|
exports.UnaryExpression = function (node, parent, file) {
|
||||||
|
if (node.operator === "typeof") {
|
||||||
|
return t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,14 +1,27 @@
|
|||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
|
exports._has = function (node) {
|
||||||
|
var first = node.body[0];
|
||||||
|
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports._wrap = function (node, callback) {
|
||||||
|
var useStrictNode;
|
||||||
|
if (exports._has(node)) {
|
||||||
|
useStrictNode = node.body.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
|
||||||
|
if (useStrictNode) {
|
||||||
|
node.body.unshift(useStrictNode);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.ast = {
|
exports.ast = {
|
||||||
exit: function (ast) {
|
exit: function (ast) {
|
||||||
var body = ast.program.body;
|
if (!exports._has(ast.program)) {
|
||||||
var first = body[0];
|
ast.program.body.unshift(t.expressionStatement(t.literal("use strict")));
|
||||||
|
|
||||||
var noStrict = !first || !t.isExpressionStatement(first) || !t.isLiteral(first.expression) || first.expression.value !== "use strict";
|
|
||||||
|
|
||||||
if (noStrict) {
|
|
||||||
body.unshift(t.expressionStatement(t.literal("use strict")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -39,8 +39,9 @@
|
|||||||
"ForInStatement": ["Statement", "For", "Scope", "Loop"],
|
"ForInStatement": ["Statement", "For", "Scope", "Loop"],
|
||||||
"ForStatement": ["Statement", "For", "Scope", "Loop"],
|
"ForStatement": ["Statement", "For", "Scope", "Loop"],
|
||||||
|
|
||||||
"ObjectPattern": ["Pattern"],
|
"ObjectPattern": ["Pattern"],
|
||||||
"ArrayPattern": ["Pattern"],
|
"ArrayPattern": ["Pattern"],
|
||||||
|
"AssignmentPattern": ["Pattern"],
|
||||||
|
|
||||||
"Property": ["UserWhitespacable"],
|
"Property": ["UserWhitespacable"],
|
||||||
"XJSElement": ["UserWhitespacable", "Expression"],
|
"XJSElement": ["UserWhitespacable", "Expression"],
|
||||||
|
|||||||
@ -3,6 +3,10 @@ var _ = require("lodash");
|
|||||||
|
|
||||||
var t = exports;
|
var t = exports;
|
||||||
|
|
||||||
|
t.NATIVE_TYPES_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
var addAssert = function (type, is) {
|
var addAssert = function (type, is) {
|
||||||
t["assert" + type] = function (node, opts) {
|
t["assert" + type] = function (node, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
@ -214,7 +218,7 @@ t.isReferenced = function (node, parent) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
t.isValidIdentifier = function (name) {
|
t.isValidIdentifier = function (name) {
|
||||||
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
|
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isReservedWordES6(name, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -227,6 +231,8 @@ t.isValidIdentifier = function (name) {
|
|||||||
t.toIdentifier = function (name) {
|
t.toIdentifier = function (name) {
|
||||||
if (t.isIdentifier(name)) return name.name;
|
if (t.isIdentifier(name)) return name.name;
|
||||||
|
|
||||||
|
name = name + "";
|
||||||
|
|
||||||
// replace all non-valid identifiers with dashes
|
// replace all non-valid identifiers with dashes
|
||||||
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
|
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
|
||||||
|
|
||||||
@ -241,6 +247,10 @@ t.toIdentifier = function (name) {
|
|||||||
// remove underscores from start of name
|
// remove underscores from start of name
|
||||||
name = name.replace(/^\_/, "");
|
name = name.replace(/^\_/, "");
|
||||||
|
|
||||||
|
if (!t.isValidIdentifier(name)) {
|
||||||
|
name = "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
return name || '_';
|
return name || '_';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
"ArrayPattern": ["elements"],
|
"ArrayPattern": ["elements"],
|
||||||
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
|
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
|
||||||
"AssignmentExpression": ["left", "right"],
|
"AssignmentExpression": ["left", "right"],
|
||||||
|
"AssignmentPattern": ["left", "right"],
|
||||||
"AwaitExpression": ["argument"],
|
"AwaitExpression": ["argument"],
|
||||||
"BinaryExpression": ["left", "right"],
|
"BinaryExpression": ["left", "right"],
|
||||||
"BindFunctionExpression": ["callee", "arguments"],
|
"BindFunctionExpression": ["callee", "arguments"],
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
"ast-types": "~0.6.1",
|
"ast-types": "~0.6.1",
|
||||||
"chokidar": "0.11.1",
|
"chokidar": "0.11.1",
|
||||||
"commander": "2.5.0",
|
"commander": "2.5.0",
|
||||||
"core-js": "^0.3.3",
|
"core-js": "^0.4.0",
|
||||||
"estraverse": "1.8.0",
|
"estraverse": "1.8.0",
|
||||||
"esutils": "1.1.6",
|
"esutils": "1.1.6",
|
||||||
"fs-readdir-recursive": "0.1.0",
|
"fs-readdir-recursive": "0.1.0",
|
||||||
@ -51,7 +51,7 @@
|
|||||||
"lodash": "2.4.1",
|
"lodash": "2.4.1",
|
||||||
"mkdirp": "0.5.0",
|
"mkdirp": "0.5.0",
|
||||||
"private": "0.1.6",
|
"private": "0.1.6",
|
||||||
"regenerator": "^0.8.2",
|
"regenerator": "^0.8.3",
|
||||||
"regexpu": "0.3.0",
|
"regexpu": "0.3.0",
|
||||||
"roadrunner": "^1.0.4",
|
"roadrunner": "^1.0.4",
|
||||||
"source-map": "0.1.40",
|
"source-map": "0.1.40",
|
||||||
|
|||||||
@ -3,7 +3,7 @@ var fs = require("fs");
|
|||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
var humanise = function (val) {
|
var humanise = function (val) {
|
||||||
return val.replace(/-/g, " ");
|
return path.basename(val, path.extname(val)).replace(/-/g, " ");
|
||||||
};
|
};
|
||||||
|
|
||||||
var readFile = exports.readFile = function (filename) {
|
var readFile = exports.readFile = function (filename) {
|
||||||
@ -16,11 +16,11 @@ var readFile = exports.readFile = function (filename) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.get = function (entryName) {
|
exports.get = function (entryName, entryLoc) {
|
||||||
if (exports.cache[entryName]) return exports.cache[entryName];
|
if (exports.cache[entryName]) return exports.cache[entryName];
|
||||||
|
|
||||||
var suites = [];
|
var suites = [];
|
||||||
var entryLoc = __dirname + "/fixtures/" + entryName;
|
var entryLoc = entryLoc || __dirname + "/fixtures/" + entryName;
|
||||||
|
|
||||||
_.each(fs.readdirSync(entryLoc), function (suiteName) {
|
_.each(fs.readdirSync(entryLoc), function (suiteName) {
|
||||||
if (suiteName[0] === ".") return;
|
if (suiteName[0] === ".") return;
|
||||||
@ -36,8 +36,18 @@ exports.get = function (entryName) {
|
|||||||
var suiteOptsLoc = suite.filename + "/options.json";
|
var suiteOptsLoc = suite.filename + "/options.json";
|
||||||
if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc);
|
if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc);
|
||||||
|
|
||||||
_.each(fs.readdirSync(suite.filename), function (taskName) {
|
if (fs.statSync(suite.filename).isFile()) {
|
||||||
var taskDir = suite.filename + "/" + taskName;
|
push(suiteName, suite.filename);
|
||||||
|
} else {
|
||||||
|
_.each(fs.readdirSync(suite.filename), function (taskName) {
|
||||||
|
var taskDir = suite.filename + "/" + taskName;
|
||||||
|
push(taskName, taskDir);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function push(taskName, taskDir) {
|
||||||
|
// tracuer error tests
|
||||||
|
if (taskName.indexOf("Error_") >= 0) return;
|
||||||
|
|
||||||
var actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
var actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
||||||
var expectLocAlias = suiteName + "/" + taskName + "/expected.js";
|
var expectLocAlias = suiteName + "/" + taskName + "/expected.js";
|
||||||
@ -49,7 +59,7 @@ exports.get = function (entryName) {
|
|||||||
|
|
||||||
if (fs.statSync(taskDir).isFile()) {
|
if (fs.statSync(taskDir).isFile()) {
|
||||||
var ext = path.extname(taskDir);
|
var ext = path.extname(taskDir);
|
||||||
if (ext !== ".js") return;
|
if (ext !== ".js" && ext !== ".module.js") return;
|
||||||
|
|
||||||
execLoc = taskDir;
|
execLoc = taskDir;
|
||||||
}
|
}
|
||||||
@ -84,6 +94,18 @@ exports.get = function (entryName) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// traceur checks
|
||||||
|
|
||||||
|
var shouldSkip = function (code) {
|
||||||
|
return code.indexOf("// Error:") >= 0 || code.indexOf("// Skip.") >= 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (shouldSkip(test.actual.code) || shouldSkip(test.exec.code)) {
|
||||||
|
return;
|
||||||
|
} else if (test.exec.code.indexOf("// Async.") >= 0) {
|
||||||
|
//test.options.asyncExec = true;
|
||||||
|
}
|
||||||
|
|
||||||
suite.tests.push(test);
|
suite.tests.push(test);
|
||||||
|
|
||||||
var sourceMappingsLoc = taskDir + "/source-mappings.json";
|
var sourceMappingsLoc = taskDir + "/source-mappings.json";
|
||||||
@ -97,7 +119,7 @@ exports.get = function (entryName) {
|
|||||||
test.options.sourceMap = true;
|
test.options.sourceMap = true;
|
||||||
test.sourceMap = require(sourceMap);
|
test.sourceMap = require(sourceMap);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return exports.cache[entryName] = suites;
|
return exports.cache[entryName] = suites;
|
||||||
@ -111,4 +133,5 @@ try {
|
|||||||
var cache = exports.cache = {};
|
var cache = exports.cache = {};
|
||||||
cache.transformation = exports.get("transformation");
|
cache.transformation = exports.get("transformation");
|
||||||
cache.generation = exports.get("generation");
|
cache.generation = exports.get("generation");
|
||||||
|
cache.esnext = exports.get("esnext");
|
||||||
}
|
}
|
||||||
|
|||||||
152
test/_transformation-helper.js
Normal file
152
test/_transformation-helper.js
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
var genHelpers = require("./_generator-helpers");
|
||||||
|
var transform = require("../lib/6to5/transformation/transform");
|
||||||
|
var sourceMap = require("source-map");
|
||||||
|
var Module = require("module");
|
||||||
|
var helper = require("./_helper");
|
||||||
|
var assert = require("assert");
|
||||||
|
var chai = require("chai");
|
||||||
|
var path = require("path");
|
||||||
|
var util = require("../lib/6to5/util");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
require("../lib/6to5/polyfill");
|
||||||
|
|
||||||
|
global.assertNoOwnProperties = function (obj) {
|
||||||
|
assert.equal(Object.getOwnPropertyNames(obj).length, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
global.assertArrayEquals = assert.deepEqual;
|
||||||
|
global.assert = chai.assert;
|
||||||
|
global.chai = chai;
|
||||||
|
global.genHelpers = genHelpers;
|
||||||
|
|
||||||
|
// Different Traceur generator message
|
||||||
|
chai.assert._throw = chai.assert.throw;
|
||||||
|
chai.assert.throw = function (fn, msg) {
|
||||||
|
if (msg === '"throw" on executing generator' ||
|
||||||
|
msg === '"next" on executing generator') {
|
||||||
|
msg = "Generator is already running";
|
||||||
|
} else if (msg === "Sent value to newborn generator") {
|
||||||
|
msg = /^attempt to send (.*?) to newborn generator$/;
|
||||||
|
}
|
||||||
|
|
||||||
|
return chai.assert._throw(fn, msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
var run = function (task, done) {
|
||||||
|
var actual = task.actual;
|
||||||
|
var expect = task.expect;
|
||||||
|
var exec = task.exec;
|
||||||
|
var opts = task.options;
|
||||||
|
|
||||||
|
var getOpts = function (self) {
|
||||||
|
return _.merge({
|
||||||
|
filename: self.loc
|
||||||
|
}, opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
var execCode = exec.code;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (execCode) {
|
||||||
|
result = transform(execCode, getOpts(exec));
|
||||||
|
execCode = result.code;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var fakeRequire = function (loc) {
|
||||||
|
if (loc === "../../../src/runtime/polyfills/Number.js") {
|
||||||
|
return Number;
|
||||||
|
} else if (loc === "../../../src/runtime/polyfills/Math.js") {
|
||||||
|
return Math;
|
||||||
|
} else {
|
||||||
|
return require(path.resolve(exec.loc, "..", loc));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var fn = new Function("require", "done", execCode);
|
||||||
|
fn.call(global, fakeRequire, chai.assert, done);
|
||||||
|
} catch (err) {
|
||||||
|
err.message = exec.loc + ": " + err.message;
|
||||||
|
err.message += util.codeFrame(execCode);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var actualCode = actual.code;
|
||||||
|
var expectCode = expect.code;
|
||||||
|
if (!execCode || actualCode) {
|
||||||
|
result = transform(actualCode, getOpts(actual));
|
||||||
|
actualCode = result.code;
|
||||||
|
|
||||||
|
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.sourceMap) {
|
||||||
|
chai.expect(result.map).to.deep.equal(task.sourceMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.sourceMappings) {
|
||||||
|
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||||
|
|
||||||
|
_.each(task.sourceMappings, function (mapping, i) {
|
||||||
|
var expect = mapping.original;
|
||||||
|
|
||||||
|
var actual = consumer.originalPositionFor(mapping.generated);
|
||||||
|
chai.expect({ line: actual.line, column: actual.column }).to.deep.equal(expect);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function (suiteOpts, taskOpts, dynamicOpts) {
|
||||||
|
taskOpts = taskOpts || {};
|
||||||
|
|
||||||
|
require("6to5/register")(taskOpts);
|
||||||
|
|
||||||
|
_.each(helper.get(suiteOpts.name, suiteOpts.loc), function (testSuite) {
|
||||||
|
if (_.contains(suiteOpts.ignoreSuites, testSuite.title)) return;
|
||||||
|
|
||||||
|
suite(suiteOpts.name + "/" + testSuite.title, function () {
|
||||||
|
_.each(testSuite.tests, function (task) {
|
||||||
|
if (_.contains(suiteOpts.ignoreTasks, task.title) || _.contains(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) return;
|
||||||
|
|
||||||
|
var runTest = function (done) {
|
||||||
|
var runTask = function () {
|
||||||
|
try {
|
||||||
|
run(task, done);
|
||||||
|
} catch (err) {
|
||||||
|
if (task.options.after) task.options.after();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_.extend(task.options, taskOpts);
|
||||||
|
if (dynamicOpts) dynamicOpts(task.options, task);
|
||||||
|
|
||||||
|
var throwMsg = task.options.throws;
|
||||||
|
if (throwMsg) {
|
||||||
|
// internal api doesn't have this option but it's best not to pollute
|
||||||
|
// the options object with useless options
|
||||||
|
delete task.options.throws;
|
||||||
|
|
||||||
|
assert.throws(runTask, function (err) {
|
||||||
|
return throwMsg === true || err.message.indexOf(throwMsg) >= 0;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
runTask();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var callback;
|
||||||
|
if (task.options.asyncExec) {
|
||||||
|
callback = runTest;
|
||||||
|
} else {
|
||||||
|
callback = function () {
|
||||||
|
return runTest();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test(task.title, !task.disabled && callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
5
test/esnext.js
Normal file
5
test/esnext.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
if (!process.env.ALL_6TO5_TESTS) return;
|
||||||
|
|
||||||
|
require("./_transformation-helper")({
|
||||||
|
name: "esnext"
|
||||||
|
});
|
||||||
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
var _slice = Array.prototype.slice;
|
var _slice = Array.prototype.slice;
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _inherits = function (child, parent) {
|
var _inherits = function (child, parent) {
|
||||||
|
if (typeof parent !== "function" && parent !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||||
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
child.prototype = Object.create(parent && parent.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: child,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user