Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ed7475c46 | ||
|
|
b2dc560a2d | ||
|
|
010dbe1cce | ||
|
|
75cd0bab02 | ||
|
|
3283991ed0 | ||
|
|
a66ce5b6ce | ||
|
|
9620f50f22 | ||
|
|
cc049ea851 | ||
|
|
e5a04ae117 | ||
|
|
e07e74f010 | ||
|
|
7b04c501eb | ||
|
|
70349dd4b3 | ||
|
|
2cedc843a8 | ||
|
|
cf40fe3430 | ||
|
|
09ffeed139 | ||
|
|
18f79d6253 | ||
|
|
6f5270f38f | ||
|
|
aac7aac373 | ||
|
|
9361470dc7 | ||
|
|
cf579f4b6e | ||
|
|
2e497eef98 | ||
|
|
7867daaa04 | ||
|
|
eabbcd31ad | ||
|
|
17d198f3d6 | ||
|
|
afd5376c8d | ||
|
|
02a50c9f7e | ||
|
|
df9fa32b82 | ||
|
|
831b420df3 | ||
|
|
123186003c | ||
|
|
ea627ed57c | ||
|
|
157bb48776 | ||
|
|
76a3771943 | ||
|
|
54f8889a30 | ||
|
|
bab159bc08 | ||
|
|
23950963e5 | ||
|
|
d1daac5550 | ||
|
|
d93ece5ccf | ||
|
|
c8c667bf16 | ||
|
|
49cdacbcb4 | ||
|
|
f97bd584f7 |
38
CHANGELOG.md
38
CHANGELOG.md
@@ -11,6 +11,44 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.11.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Allow a string to be passed as the `optional` option.
|
||||
|
||||
## 2.11.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Support esprima-style catch clause handlers.
|
||||
* **Polish**
|
||||
* Don't print a stacktrace for syntax errors in the CLI.
|
||||
|
||||
## 2.11.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove stray `console.log` outputting debug code.
|
||||
* Remove `Dict` from `coreAliasing`.
|
||||
|
||||
## 2.11.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix unnecessary IIFE in default parameters on method calls.
|
||||
* Add support for supers inside of closures.
|
||||
* **New Feature**
|
||||
* Add `--keep-module-id-extensions`/`keepModuleIdExtensions` option to keep extensions in module ids.
|
||||
* **Polish**
|
||||
* Special case single argument spread properties in `super` inside classes.
|
||||
* Don't use a variable declaration for class declaration IFFE.
|
||||
* Rename `inherits` helper parameters.
|
||||
* `coreAliasing` transformer now aliases `Promise`, `Set`, `Map` and more. Thanks [@AluisioASG](https://github.com/AluisioASG).
|
||||
|
||||
## 2.10.1
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.4.4`.
|
||||
* **New Feature**
|
||||
* Added `--include-regenerator` option to CLI and `includeRegenerator` option to API that includes the regenerator runtime if necessary.
|
||||
|
||||
## 2.10.0
|
||||
|
||||
* **New Feature**
|
||||
|
||||
1
NOTES.md
1
NOTES.md
@@ -10,3 +10,4 @@
|
||||
* Split up ES5 getter/setter transforming and ES6 property methods into separate transformers.
|
||||
* Add autoindentation.
|
||||
* Move `super` transformation from classes into a separate transformer that also supports object expressions.
|
||||
* Prefix all fast transformers with `fast`, make them declare that they're a fast transformer similar to optional transformers and add a `--fast` flag to enable them all.
|
||||
|
||||
@@ -25,6 +25,8 @@ commander.option("-I, --indent [width]", "Indent width [2]", 2);
|
||||
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.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
|
||||
commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false);
|
||||
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
|
||||
|
||||
commander.on("--help", function(){
|
||||
var outKeys = function (title, obj) {
|
||||
@@ -100,18 +102,20 @@ if (errors.length) {
|
||||
//
|
||||
|
||||
exports.opts = {
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
reactCompat: commander.reactCompat,
|
||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||
includeRegenerator: commander.includeRegenerator,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
format: {
|
||||
indent: {
|
||||
style: util.repeat(parseInt(commander.indent))
|
||||
|
||||
@@ -20,7 +20,17 @@ exports.transform = function (filename, code, opts) {
|
||||
opts = _.extend(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result = to5.transform(code, opts);
|
||||
var result;
|
||||
try {
|
||||
result = to5.transform(code, opts);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error("SyntaxError:", e.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
|
||||
@@ -48,21 +48,23 @@ File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
_.defaults(opts, {
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
keepModuleIdExtensions: false,
|
||||
includeRegenerator: false,
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalise windows path separators to unix
|
||||
@@ -70,6 +72,7 @@ File.normaliseOptions = function (opts) {
|
||||
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
opts.optional = util.arrayify(opts.optional);
|
||||
|
||||
_.defaults(opts, {
|
||||
moduleRoot: opts.sourceRoot
|
||||
|
||||
@@ -125,7 +125,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
|
||||
var lines = 0;
|
||||
|
||||
if (node.start != null) {
|
||||
if (node.start != null && !node._ignoreUserWhitespace) {
|
||||
// user node
|
||||
if (leading) {
|
||||
lines = self.whitespace.getNewlinesBefore(node);
|
||||
|
||||
@@ -107,7 +107,16 @@ exports.TryStatement = function (node, print) {
|
||||
this.keyword("try");
|
||||
print(node.block);
|
||||
this.space();
|
||||
print(node.handler);
|
||||
|
||||
// Esprima bug puts the catch clause in a `handlers` array.
|
||||
// see https://code.google.com/p/esprima/issues/detail?id=433
|
||||
// We run into this from regenerator generated ast.
|
||||
if (node.handlers) {
|
||||
print(node.handlers[0]);
|
||||
} else {
|
||||
print(node.handler);
|
||||
}
|
||||
|
||||
if (node.finalizer) {
|
||||
this.space();
|
||||
this.push("finally ");
|
||||
|
||||
@@ -62,11 +62,15 @@ _.each({
|
||||
CallExpression: { after: 1 },
|
||||
Literal: { after: 1 }
|
||||
}, function (amounts, type) {
|
||||
if (_.isNumber(amounts)) amounts = { after: amounts, before: amounts };
|
||||
if (_.isNumber(amounts)) {
|
||||
amounts = { after: amounts, before: amounts };
|
||||
}
|
||||
|
||||
_.each(amounts, function (amount, key) {
|
||||
exports[key].nodes[type] = function () {
|
||||
return amount;
|
||||
};
|
||||
_.each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||
_.each(amounts, function (amount, key) {
|
||||
exports[key].nodes[type] = function () {
|
||||
return amount;
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -156,8 +156,10 @@ DefaultFormatter.prototype.getModuleName = function () {
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
if (!opts.keepModuleIdExtensions) {
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
}
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
|
||||
@@ -31,15 +31,17 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
|
||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||
|
||||
// runner
|
||||
// amd
|
||||
|
||||
var defineArgs = [t.literal("exports")];
|
||||
if (this.passModuleArg) defineArgs.push(t.literal("module"));
|
||||
defineArgs = defineArgs.concat(names);
|
||||
defineArgs = [t.arrayExpression(defineArgs)];
|
||||
|
||||
// common
|
||||
|
||||
var testExports = util.template("test-exports");
|
||||
var testModule = util.template("test-module");
|
||||
var testModule = util.template("test-module");
|
||||
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
||||
|
||||
var commonArgs = [t.identifier("exports")];
|
||||
@@ -48,6 +50,12 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
}));
|
||||
|
||||
// globals
|
||||
|
||||
//var umdArgs = [];
|
||||
|
||||
//
|
||||
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
(function (child, parent) {
|
||||
if (typeof parent !== "function" && parent !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||
(function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
})
|
||||
|
||||
@@ -50,16 +50,20 @@ Class.prototype.run = function () {
|
||||
|
||||
var body = this.body = [];
|
||||
|
||||
var constructor = t.functionExpression(null, [], t.blockStatement([]));
|
||||
if (this.node.id) constructor.id = className;
|
||||
var constructor;
|
||||
if (this.node.id) {
|
||||
constructor = t.functionDeclaration(className, [], t.blockStatement([]));
|
||||
body.push(constructor);
|
||||
} else {
|
||||
constructor = t.functionExpression(null, [], t.blockStatement([]));
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(className, constructor)
|
||||
]));
|
||||
}
|
||||
this.constructor = constructor;
|
||||
|
||||
body.push(t.variableDeclaration("let", [
|
||||
t.variableDeclarator(className, constructor)
|
||||
]));
|
||||
|
||||
var closureArgs = [];
|
||||
var closureParams = [];
|
||||
var closureArgs = [];
|
||||
|
||||
//
|
||||
|
||||
@@ -85,7 +89,7 @@ Class.prototype.run = function () {
|
||||
|
||||
if (body.length === 1) {
|
||||
// only a constructor so no need for a closure container
|
||||
init = constructor;
|
||||
init = t.toExpression(constructor);
|
||||
} else {
|
||||
body.push(t.returnStatement(className));
|
||||
init = t.callExpression(
|
||||
@@ -225,54 +229,85 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
|
||||
var method = methodNode.value;
|
||||
var self = this;
|
||||
|
||||
traverse(method, {
|
||||
enter: function (node, parent) {
|
||||
var property;
|
||||
var computed;
|
||||
var args;
|
||||
var topLevelThisReference;
|
||||
|
||||
if (t.isIdentifier(node, { name: "super" })) {
|
||||
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
|
||||
throw self.file.errorWithNode(node, "illegal use of bare super");
|
||||
traverse2(method, true);
|
||||
|
||||
if (topLevelThisReference) {
|
||||
method.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(topLevelThisReference, t.thisExpression())
|
||||
]));
|
||||
}
|
||||
|
||||
function traverse2(node, topLevel) {
|
||||
traverse(node, {
|
||||
enter: function (node, parent) {
|
||||
if (t.isFunction(node) && !t.isArrowFunctionExpression(node)) {
|
||||
traverse2(node, false);
|
||||
return this.skip();
|
||||
}
|
||||
} else if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (t.isIdentifier(callee, { name: "super" })) {
|
||||
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||
property = methodNode.key;
|
||||
computed = methodNode.computed;
|
||||
args = node.arguments;
|
||||
} else {
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (callee.object.name !== "super") return;
|
||||
|
||||
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
var property;
|
||||
var computed;
|
||||
var args;
|
||||
|
||||
if (t.isIdentifier(node, { name: "super" })) {
|
||||
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
|
||||
throw self.file.errorWithNode(node, "illegal use of bare super");
|
||||
}
|
||||
} else if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (t.isIdentifier(callee, { name: "super" })) {
|
||||
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||
property = methodNode.key;
|
||||
computed = methodNode.computed;
|
||||
args = node.arguments;
|
||||
} else {
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (callee.object.name !== "super") return;
|
||||
|
||||
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
}
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
if (!t.isIdentifier(node.object, { name: "super" })) return;
|
||||
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
}
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
if (!t.isIdentifier(node.object, { name: "super" })) return;
|
||||
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
}
|
||||
if (property) {
|
||||
var thisReference;
|
||||
if (topLevel) {
|
||||
thisReference = t.thisExpression();
|
||||
} else {
|
||||
topLevelThisReference = thisReference = topLevelThisReference || self.file.generateUidIdentifier("this");
|
||||
}
|
||||
|
||||
if (property) {
|
||||
var thisExpression = t.thisExpression();
|
||||
var superProperty = self.superProperty(property, methodNode.static, computed, thisExpression);
|
||||
if (args) {
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("call"), false),
|
||||
[thisExpression].concat(args)
|
||||
);
|
||||
} else {
|
||||
return superProperty;
|
||||
var superProperty = self.superProperty(property, methodNode.static, computed, thisReference);
|
||||
if (args) {
|
||||
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
||||
// super(...arguments);
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("apply"), false),
|
||||
[thisReference, args[0].argument]
|
||||
);
|
||||
} else {
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("call"), false),
|
||||
[thisReference].concat(args)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return superProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -294,8 +329,9 @@ Class.prototype.pushConstructor = function (method) {
|
||||
t.inherits(construct, fn);
|
||||
t.inheritsComments(construct, method);
|
||||
|
||||
construct.defaults = fn.defaults;
|
||||
construct.params = fn.params;
|
||||
construct.body = fn.body;
|
||||
construct.rest = fn.rest;
|
||||
construct._ignoreUserWhitespace = true;
|
||||
construct.defaults = fn.defaults;
|
||||
construct.params = fn.params;
|
||||
construct.body = fn.body;
|
||||
construct.rest = fn.rest;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ exports.Function = function (node, parent, file, scope) {
|
||||
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
|
||||
}
|
||||
|
||||
if (scope.has(node.name)) {
|
||||
if (scope.has(node.name, true)) {
|
||||
iife = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
var regenerator = require("regenerator");
|
||||
|
||||
exports.ast = {
|
||||
before: require("regenerator").transform
|
||||
before: function (ast, file) {
|
||||
regenerator.transform(ast, {
|
||||
includeRuntime: file.opts.includeRegenerator && "if used"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,6 +37,7 @@ exports.VariableDeclaration = function (node, parent) {
|
||||
exports.Loop = function (node, parent, file, scope) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
t.ensureBlock(node);
|
||||
node.body._letDeclars = [init];
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,15 @@ var coreHas = function (node) {
|
||||
return node.name !== "_" && _.has(core, node.name);
|
||||
};
|
||||
|
||||
var ALIASABLE_CONSTRUCTORS = [
|
||||
"Symbol",
|
||||
"Promise",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"Set",
|
||||
"WeakSet"
|
||||
];
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.ast = {
|
||||
@@ -31,8 +40,8 @@ exports.ast = {
|
||||
this.skip();
|
||||
return t.prependToMemberExpression(node, file._coreId);
|
||||
}
|
||||
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && node.name === "Symbol") {
|
||||
// new Symbol -> new _core.Symbol
|
||||
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && _.contains(ALIASABLE_CONSTRUCTORS, node.name)) {
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
return t.memberExpression(file._coreId, node);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
24
lib/6to5/transformation/transformers/react.js
vendored
24
lib/6to5/transformation/transformers/react.js
vendored
@@ -61,11 +61,16 @@ exports.XJSOpeningElement = {
|
||||
}
|
||||
}
|
||||
|
||||
var props = node.attributes;
|
||||
if (props.length) {
|
||||
var attribs = node.attributes;
|
||||
if (attribs.length) {
|
||||
var _props = [];
|
||||
var objs = [];
|
||||
|
||||
// so basically in order to support spread elements we
|
||||
// loop over all the attributes, breaking on spreads
|
||||
// we then push a new object containing all prior attributes
|
||||
// to an array for later processing
|
||||
|
||||
var pushProps = function () {
|
||||
if (!_props.length) return;
|
||||
|
||||
@@ -73,8 +78,8 @@ exports.XJSOpeningElement = {
|
||||
_props = [];
|
||||
};
|
||||
|
||||
while (props.length) {
|
||||
var prop = props.shift();
|
||||
while (attribs.length) {
|
||||
var prop = attribs.shift();
|
||||
if (t.isXJSSpreadAttribute(prop)) {
|
||||
pushProps();
|
||||
objs.push(prop.argument);
|
||||
@@ -86,22 +91,25 @@ exports.XJSOpeningElement = {
|
||||
pushProps();
|
||||
|
||||
if (objs.length === 1) {
|
||||
props = objs[0];
|
||||
// only one object
|
||||
attribs = objs[0];
|
||||
} else {
|
||||
// looks like we have multiple objects
|
||||
if (!t.isObjectExpression(objs[0])) {
|
||||
objs.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
props = t.callExpression(
|
||||
// spread it
|
||||
attribs = t.callExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("__spread")),
|
||||
objs
|
||||
);
|
||||
}
|
||||
} else {
|
||||
props = t.literal(null);
|
||||
attribs = t.literal(null);
|
||||
}
|
||||
|
||||
args.push(props);
|
||||
args.push(attribs);
|
||||
|
||||
if (reactCompat) {
|
||||
if (tagName && isTag(tagName)) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"ExpressionStatement": ["expression"],
|
||||
"File": ["program", "comments", "tokens"],
|
||||
"FunctionExpression": ["id", "params", "body", "generator"],
|
||||
"FunctionDeclaration": ["id", "params", "body", "generator"],
|
||||
"Identifier": ["name"],
|
||||
"IfStatement": ["test", "consequent", "alternate"],
|
||||
"ImportDeclaration": ["specifiers", "source"],
|
||||
|
||||
@@ -307,6 +307,31 @@ t.toStatement = function (node, ignore) {
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
exports.toExpression = function (node) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
if (t.isClass(node)) {
|
||||
node.type = "ClassExpression";
|
||||
} else if (t.isFunction(node)) {
|
||||
node.type = "FunctionExpression";
|
||||
}
|
||||
|
||||
if (t.isExpression(node)) {
|
||||
return node;
|
||||
} else {
|
||||
throw new Error("cannot turn " + node.type + " to an expression");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.10.0",
|
||||
"version": "2.11.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -43,7 +43,7 @@
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
"core-js": "^0.4.1",
|
||||
"core-js": "^0.4.4",
|
||||
"estraverse": "1.8.0",
|
||||
"esutils": "1.1.6",
|
||||
"esvalid": "^1.1.0",
|
||||
|
||||
@@ -12,7 +12,7 @@ suite("browserify", function() {
|
||||
assert.ok(bundle.length, "bundle output code");
|
||||
|
||||
// ensure that the code runs without throwing an exception
|
||||
vm.runInNewContext(bundle, {});
|
||||
vm.runInNewContext("var global = this;\n" + bundle, {});
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
@@ -28,44 +28,44 @@ var _get = function get(object, property, receiver) {
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
var _get2, _get3, _get4, _get5;
|
||||
function Test() {
|
||||
var _get2, _get3;
|
||||
woops["super"].test();
|
||||
_get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this);
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
|
||||
|
||||
(_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this].concat(_slice.call(arguments)));
|
||||
(_get3 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments)));
|
||||
_get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments);
|
||||
(_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments)));
|
||||
|
||||
(_get4 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get4, [this].concat(_slice.call(arguments)));
|
||||
(_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments);
|
||||
(_get3 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments)));
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
_prototypeProperties(Test, {
|
||||
foo: {
|
||||
value: function () {
|
||||
var _get6, _get7;
|
||||
var _get4;
|
||||
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
|
||||
(_get6 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get6, [this].concat(_slice.call(arguments)));
|
||||
(_get7 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get7, [this, "test"].concat(_slice.call(arguments)));
|
||||
_get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments);
|
||||
(_get4 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get4, [this, "test"].concat(_slice.call(arguments)));
|
||||
},
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
@@ -74,10 +74,10 @@ var Test = (function (Foo) {
|
||||
}, {
|
||||
test: {
|
||||
value: function () {
|
||||
var _get8, _get9;
|
||||
var _get5;
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
|
||||
(_get8 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get8, [this].concat(_slice.call(arguments)));
|
||||
(_get9 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get9, [this, "test"].concat(_slice.call(arguments)));
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments);
|
||||
(_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments)));
|
||||
},
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
|
||||
@@ -22,26 +22,26 @@ var _get = function get(object, property, receiver) {
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this);
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever;
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
@@ -27,26 +27,26 @@ var _get = function get(object, property, receiver) {
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever();
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = function Test() {
|
||||
@@ -20,9 +20,9 @@ var Test = function Test() {
|
||||
};
|
||||
|
||||
var Foo = (function (Bar) {
|
||||
var Foo = function Foo() {
|
||||
function Foo() {
|
||||
this.state = "test";
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Foo, Bar);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var Test = (function () {
|
||||
var Test = function Test() {};
|
||||
function Test() {}
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var Test = (function () {
|
||||
var Test = function Test() {};
|
||||
function Test() {}
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var Test = (function () {
|
||||
var Test = function Test() {};
|
||||
function Test() {}
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var Test = (function () {
|
||||
var Test = function Test() {};
|
||||
function Test() {}
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var A = (function () {
|
||||
var A = function A() {};
|
||||
function A() {}
|
||||
|
||||
_prototypeProperties(A, {
|
||||
a: {
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var BaseController = (function (_Chaplin$Controller) {
|
||||
var BaseController = function BaseController() {
|
||||
function BaseController() {
|
||||
if (Object.getPrototypeOf(BaseController) !== null) {
|
||||
Object.getPrototypeOf(BaseController).apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(BaseController, _Chaplin$Controller);
|
||||
|
||||
@@ -28,11 +28,11 @@ var BaseController = (function (_Chaplin$Controller) {
|
||||
})(Chaplin.Controller);
|
||||
|
||||
var BaseController2 = (function (_Chaplin$Controller$Another) {
|
||||
var BaseController2 = function BaseController2() {
|
||||
function BaseController2() {
|
||||
if (Object.getPrototypeOf(BaseController2) !== null) {
|
||||
Object.getPrototypeOf(BaseController2).apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(BaseController2, _Chaplin$Controller$Another);
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
if (Object.getPrototypeOf(Test) !== null) {
|
||||
Object.getPrototypeOf(Test).apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
1
test/fixtures/transformation/es6-generators/include-regenerator/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-generators/include-regenerator/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
function *x() {}
|
||||
400
test/fixtures/transformation/es6-generators/include-regenerator/expected.js
vendored
Normal file
400
test/fixtures/transformation/es6-generators/include-regenerator/expected.js
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
"use strict";
|
||||
|
||||
!(function () {
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
var undefined;
|
||||
var iteratorSymbol = typeof Symbol === "function" && Symbol.iterator || "@@iterator";
|
||||
if (typeof regeneratorRuntime === "object") {
|
||||
return;
|
||||
}
|
||||
var runtime = regeneratorRuntime = typeof exports === "undefined" ? {} : exports;
|
||||
function wrap(innerFn, outerFn, self, tryList) {
|
||||
return new Generator(innerFn, outerFn, self || null, tryList || []);
|
||||
}
|
||||
|
||||
runtime.wrap = wrap;
|
||||
var GenStateSuspendedStart = "suspendedStart";
|
||||
|
||||
var GenStateSuspendedYield = "suspendedYield";
|
||||
|
||||
var GenStateExecuting = "executing";
|
||||
|
||||
var GenStateCompleted = "completed";
|
||||
|
||||
var ContinueSentinel = {};
|
||||
|
||||
function GeneratorFunction() {}
|
||||
|
||||
function GeneratorFunctionPrototype() {}
|
||||
|
||||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype;
|
||||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
||||
GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
||||
GeneratorFunction.displayName = "GeneratorFunction";
|
||||
runtime.isGeneratorFunction = function (genFun) {
|
||||
var ctor = typeof genFun === "function" && genFun.constructor;
|
||||
return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
||||
};
|
||||
|
||||
runtime.mark = function (genFun) {
|
||||
genFun.__proto__ = GeneratorFunctionPrototype;
|
||||
genFun.prototype = Object.create(Gp);
|
||||
return genFun;
|
||||
};
|
||||
|
||||
runtime.async = function (innerFn, outerFn, self, tryList) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var generator = wrap(innerFn, outerFn, self, tryList);
|
||||
|
||||
var callNext = step.bind(generator.next);
|
||||
|
||||
var callThrow = step.bind(generator["throw"]);
|
||||
|
||||
function step(arg) {
|
||||
try {
|
||||
var info = this(arg);
|
||||
|
||||
var value = info.value;
|
||||
} catch (error) {
|
||||
return reject(error);
|
||||
}
|
||||
if (info.done) {
|
||||
resolve(value);
|
||||
} else {
|
||||
Promise.resolve(value).then(callNext, callThrow);
|
||||
}
|
||||
}
|
||||
|
||||
callNext();
|
||||
});
|
||||
};
|
||||
|
||||
function Generator(innerFn, outerFn, self, tryList) {
|
||||
var generator = outerFn ? Object.create(outerFn.prototype) : this;
|
||||
var context = new Context(tryList);
|
||||
var state = GenStateSuspendedStart;
|
||||
function invoke(method, arg) {
|
||||
if (state === GenStateExecuting) {
|
||||
throw new Error("Generator is already running");
|
||||
}
|
||||
if (state === GenStateCompleted) {
|
||||
return doneResult();
|
||||
}
|
||||
while (true) {
|
||||
var delegate = context.delegate;
|
||||
if (delegate) {
|
||||
try {
|
||||
var info = delegate.iterator[method](arg);
|
||||
|
||||
method = "next";
|
||||
arg = undefined;
|
||||
} catch (uncaught) {
|
||||
context.delegate = null;
|
||||
method = "throw";
|
||||
arg = uncaught;
|
||||
continue;
|
||||
}
|
||||
if (info.done) {
|
||||
context[delegate.resultName] = info.value;
|
||||
context.next = delegate.nextLoc;
|
||||
} else {
|
||||
state = GenStateSuspendedYield;
|
||||
return info;
|
||||
}
|
||||
context.delegate = null;
|
||||
}
|
||||
if (method === "next") {
|
||||
if (state === GenStateSuspendedStart && typeof arg !== "undefined") {
|
||||
throw new TypeError("attempt to send " + JSON.stringify(arg) + " to newborn generator");
|
||||
}
|
||||
if (state === GenStateSuspendedYield) {
|
||||
context.sent = arg;
|
||||
} else {
|
||||
delete context.sent;
|
||||
}
|
||||
} else if (method === "throw") {
|
||||
if (state === GenStateSuspendedStart) {
|
||||
state = GenStateCompleted;
|
||||
throw arg;
|
||||
}
|
||||
if (context.dispatchException(arg)) {
|
||||
method = "next";
|
||||
arg = undefined;
|
||||
}
|
||||
} else if (method === "return") {
|
||||
context.abrupt("return", arg);
|
||||
}
|
||||
state = GenStateExecuting;
|
||||
try {
|
||||
var value = innerFn.call(self, context);
|
||||
|
||||
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
|
||||
var info = {
|
||||
value: value,
|
||||
done: context.done
|
||||
};
|
||||
|
||||
if (value === ContinueSentinel) {
|
||||
if (context.delegate && method === "next") {
|
||||
arg = undefined;
|
||||
}
|
||||
} else {
|
||||
return info;
|
||||
}
|
||||
} catch (thrown) {
|
||||
state = GenStateCompleted;
|
||||
if (method === "next") {
|
||||
context.dispatchException(thrown);
|
||||
} else {
|
||||
arg = thrown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generator.next = invoke.bind(generator, "next");
|
||||
generator["throw"] = invoke.bind(generator, "throw");
|
||||
generator["return"] = invoke.bind(generator, "return");
|
||||
return generator;
|
||||
}
|
||||
|
||||
Gp[iteratorSymbol] = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
Gp.toString = function () {
|
||||
return "[object Generator]";
|
||||
};
|
||||
|
||||
function pushTryEntry(triple) {
|
||||
var entry = {
|
||||
tryLoc: triple[0]
|
||||
};
|
||||
|
||||
if (1 in triple) {
|
||||
entry.catchLoc = triple[1];
|
||||
}
|
||||
if (2 in triple) {
|
||||
entry.finallyLoc = triple[2];
|
||||
}
|
||||
this.tryEntries.push(entry);
|
||||
}
|
||||
|
||||
function resetTryEntry(entry, i) {
|
||||
var record = entry.completion || {};
|
||||
record.type = i === 0 ? "normal" : "return";
|
||||
delete record.arg;
|
||||
entry.completion = record;
|
||||
}
|
||||
|
||||
function Context(tryList) {
|
||||
this.tryEntries = [{
|
||||
tryLoc: "root"
|
||||
}];
|
||||
tryList.forEach(pushTryEntry, this);
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
runtime.keys = function (object) {
|
||||
var keys = [];
|
||||
|
||||
for (var key in object) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
keys.reverse();
|
||||
|
||||
return function next() {
|
||||
while (keys.length) {
|
||||
var key = keys.pop();
|
||||
|
||||
if (key in object) {
|
||||
next.value = key;
|
||||
next.done = false;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
next.done = true;
|
||||
return next;
|
||||
};
|
||||
};
|
||||
|
||||
function values(iterable) {
|
||||
if (iterable) {
|
||||
var iteratorMethod = iterable[iteratorSymbol];
|
||||
if (iteratorMethod) {
|
||||
return iteratorMethod.call(iterable);
|
||||
}
|
||||
if (typeof iterable.next === "function") {
|
||||
return iterable;
|
||||
}
|
||||
if (!isNaN(iterable.length)) {
|
||||
var i = -1;
|
||||
function next() {
|
||||
while (++i < iterable.length) {
|
||||
if (hasOwn.call(iterable, i)) {
|
||||
next.value = iterable[i];
|
||||
next.done = false;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
next.value = undefined;
|
||||
next.done = true;
|
||||
return next;
|
||||
}
|
||||
|
||||
return next.next = next;
|
||||
}
|
||||
}
|
||||
return {
|
||||
next: doneResult
|
||||
};
|
||||
}
|
||||
|
||||
runtime.values = values;
|
||||
function doneResult() {
|
||||
return {
|
||||
value: undefined,
|
||||
done: true
|
||||
};
|
||||
}
|
||||
|
||||
Context.prototype = {
|
||||
constructor: Context,
|
||||
reset: function () {
|
||||
this.prev = 0;
|
||||
this.next = 0;
|
||||
this.sent = undefined;
|
||||
this.done = false;
|
||||
this.delegate = null;
|
||||
this.tryEntries.forEach(resetTryEntry);
|
||||
|
||||
for (var tempIndex = 0, tempName; hasOwn.call(this, tempName = "t" + tempIndex) || tempIndex < 20; ++tempIndex) {
|
||||
this[tempName] = null;
|
||||
}
|
||||
},
|
||||
stop: function () {
|
||||
this.done = true;
|
||||
var rootEntry = this.tryEntries[0];
|
||||
var rootRecord = rootEntry.completion;
|
||||
if (rootRecord.type === "throw") {
|
||||
throw rootRecord.arg;
|
||||
}
|
||||
return this.rval;
|
||||
},
|
||||
dispatchException: function (exception) {
|
||||
if (this.done) {
|
||||
throw exception;
|
||||
}
|
||||
var context = this;
|
||||
function handle(loc, caught) {
|
||||
record.type = "throw";
|
||||
record.arg = exception;
|
||||
context.next = loc;
|
||||
return !!caught;
|
||||
}
|
||||
|
||||
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
||||
var entry = this.tryEntries[i];
|
||||
var record = entry.completion;
|
||||
if (entry.tryLoc === "root") {
|
||||
return handle("end");
|
||||
}
|
||||
if (entry.tryLoc <= this.prev) {
|
||||
var hasCatch = hasOwn.call(entry, "catchLoc");
|
||||
|
||||
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
||||
|
||||
if (hasCatch && hasFinally) {
|
||||
if (this.prev < entry.catchLoc) {
|
||||
return handle(entry.catchLoc, true);
|
||||
} else if (this.prev < entry.finallyLoc) {
|
||||
return handle(entry.finallyLoc);
|
||||
}
|
||||
} else if (hasCatch) {
|
||||
if (this.prev < entry.catchLoc) {
|
||||
return handle(entry.catchLoc, true);
|
||||
}
|
||||
} else if (hasFinally) {
|
||||
if (this.prev < entry.finallyLoc) {
|
||||
return handle(entry.finallyLoc);
|
||||
}
|
||||
} else {
|
||||
throw new Error("try statement without catch or finally");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_findFinallyEntry: function (finallyLoc) {
|
||||
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
||||
var entry = this.tryEntries[i];
|
||||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && (entry.finallyLoc === finallyLoc || this.prev < entry.finallyLoc)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
},
|
||||
abrupt: function (type, arg) {
|
||||
var entry = this._findFinallyEntry();
|
||||
|
||||
var record = entry ? entry.completion : {};
|
||||
record.type = type;
|
||||
record.arg = arg;
|
||||
if (entry) {
|
||||
this.next = entry.finallyLoc;
|
||||
} else {
|
||||
this.complete(record);
|
||||
}
|
||||
return ContinueSentinel;
|
||||
},
|
||||
complete: function (record) {
|
||||
if (record.type === "throw") {
|
||||
throw record.arg;
|
||||
}
|
||||
if (record.type === "break" || record.type === "continue") {
|
||||
this.next = record.arg;
|
||||
} else if (record.type === "return") {
|
||||
this.rval = record.arg;
|
||||
this.next = "end";
|
||||
}
|
||||
return ContinueSentinel;
|
||||
},
|
||||
finish: function (finallyLoc) {
|
||||
var entry = this._findFinallyEntry(finallyLoc);
|
||||
|
||||
return this.complete(entry.completion);
|
||||
},
|
||||
"catch": function (tryLoc) {
|
||||
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
||||
var entry = this.tryEntries[i];
|
||||
if (entry.tryLoc === tryLoc) {
|
||||
var record = entry.completion;
|
||||
if (record.type === "throw") {
|
||||
var thrown = record.arg;
|
||||
resetTryEntry(entry, i);
|
||||
}
|
||||
return thrown;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("illegal catch attempt");
|
||||
},
|
||||
delegateYield: function (iterable, resultName, nextLoc) {
|
||||
this.delegate = {
|
||||
iterator: values(iterable),
|
||||
resultName: resultName,
|
||||
nextLoc: nextLoc
|
||||
};
|
||||
return ContinueSentinel;
|
||||
}
|
||||
};
|
||||
})();
|
||||
var x = regeneratorRuntime.mark(function x() {
|
||||
return regeneratorRuntime.wrap(function x$(context$1$0) {
|
||||
while (1) switch (context$1$0.prev = context$1$0.next) {
|
||||
case 0:
|
||||
case "end":
|
||||
return context$1$0.stop();
|
||||
}
|
||||
}, x, this);
|
||||
});
|
||||
4
test/fixtures/transformation/es6-generators/include-regenerator/options.json
vendored
Normal file
4
test/fixtures/transformation/es6-generators/include-regenerator/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"noCheckAst": true,
|
||||
"includeRegenerator": true
|
||||
}
|
||||
@@ -7,7 +7,7 @@ var D = (function () {
|
||||
var F = new WeakMap(),
|
||||
G = new WeakMap();
|
||||
var E = new WeakMap();
|
||||
var D = function D() {};
|
||||
function D() {}
|
||||
|
||||
return D;
|
||||
})();
|
||||
|
||||
@@ -6,23 +6,23 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
var _Foo$prototype$test, _Foo$prototype$test2;
|
||||
woops["super"].test();
|
||||
Foo.call(this);
|
||||
@@ -33,7 +33,7 @@ var Test = (function (Foo) {
|
||||
|
||||
(_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
Foo.prototype.test;
|
||||
Foo.prototype.test.whatever;
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
@@ -5,26 +5,26 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
Foo.prototype.test.whatever();
|
||||
Foo.prototype.test.call(this);
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var BaseController = (function (_Chaplin$Controller) {
|
||||
var BaseController = function BaseController() {
|
||||
function BaseController() {
|
||||
if (Chaplin.Controller != null) {
|
||||
Chaplin.Controller.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(BaseController, _Chaplin$Controller);
|
||||
|
||||
@@ -28,11 +28,11 @@ var BaseController = (function (_Chaplin$Controller) {
|
||||
})(Chaplin.Controller);
|
||||
|
||||
var BaseController2 = (function (_Chaplin$Controller$Another) {
|
||||
var BaseController2 = function BaseController2() {
|
||||
function BaseController2() {
|
||||
if (Chaplin.Controller.Another != null) {
|
||||
Chaplin.Controller.Another.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(BaseController2, _Chaplin$Controller$Another);
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
if (superClass) subClass.__proto__ = superClass;
|
||||
};
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = function Test() {
|
||||
function Test() {
|
||||
if (Foo != null) {
|
||||
Foo.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
|
||||
7
test/fixtures/transformation/optional-core-aliasing/aliased-constructors/actual.js
vendored
Normal file
7
test/fixtures/transformation/optional-core-aliasing/aliased-constructors/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
obj.constructor === Object;
|
||||
obj.constructor === Promise;
|
||||
|
||||
Symbol();
|
||||
Symbol("test");
|
||||
|
||||
new Map();
|
||||
@@ -6,5 +6,10 @@ var _interopRequire = function (obj) {
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
_core.Symbol("test");
|
||||
obj.constructor === Object;
|
||||
obj.constructor === _core.Promise;
|
||||
|
||||
_core.Symbol();
|
||||
_core.Symbol("test");
|
||||
|
||||
new _core.Map();
|
||||
@@ -1 +0,0 @@
|
||||
obj.constructor === Object;
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
obj.constructor === Object;
|
||||
@@ -1,2 +0,0 @@
|
||||
Symbol("test");
|
||||
Symbol();
|
||||
@@ -10,27 +10,27 @@ var _defaults = function (obj, defaults) {
|
||||
return obj;
|
||||
};
|
||||
|
||||
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);
|
||||
var _inherits = function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) _defaults(child, parent);
|
||||
if (superClass) _defaults(subClass, superClass);
|
||||
};
|
||||
|
||||
var Foo = (function (Bar) {
|
||||
var Foo = function Foo() {
|
||||
function Foo() {
|
||||
if (Object.getPrototypeOf(Foo) !== null) {
|
||||
Object.getPrototypeOf(Foo).apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_inherits(Foo, Bar);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var _defineProperty = function (obj, key, value) {
|
||||
};
|
||||
|
||||
var Foo = (function () {
|
||||
var Foo = function Foo() {};
|
||||
function Foo() {}
|
||||
|
||||
_prototypeProperties(Foo, null, _defineProperty({
|
||||
bar: {
|
||||
|
||||
@@ -6,7 +6,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
|
||||
};
|
||||
|
||||
var Test = (function () {
|
||||
var Test = function Test() {};
|
||||
function Test() {}
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
bar: {
|
||||
|
||||
Reference in New Issue
Block a user