Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
655cc8fcb9 | ||
|
|
97a504bbef | ||
|
|
bf3443962b | ||
|
|
a4394494ef | ||
|
|
9a6c13a6a4 | ||
|
|
ac8d77fb45 | ||
|
|
09c88238e1 | ||
|
|
05669204dd | ||
|
|
1abef2c1e2 | ||
|
|
f16079c83f | ||
|
|
b7132f3529 | ||
|
|
ed41f1652e | ||
|
|
c522bdb4b9 | ||
|
|
005362a615 | ||
|
|
88e542634f | ||
|
|
c8304138eb | ||
|
|
35608d497e | ||
|
|
b5a78355c4 | ||
|
|
223e28ba8f | ||
|
|
18813f26bb | ||
|
|
ccabb91f69 | ||
|
|
35fda899a8 | ||
|
|
e2f01d41a3 | ||
|
|
931a80f5b3 | ||
|
|
9a2fd22e91 | ||
|
|
cbcad22d81 | ||
|
|
4d5861cfdc | ||
|
|
c578db7ae8 | ||
|
|
dea73b7186 | ||
|
|
4506e39cf5 | ||
|
|
7ab6df093b | ||
|
|
22eeae1a93 | ||
|
|
a645ae0583 | ||
|
|
7f4efecb7d | ||
|
|
0c0f40d14a | ||
|
|
cb54c11d84 | ||
|
|
55123be7d7 | ||
|
|
324a0b408a | ||
|
|
8b2788e930 | ||
|
|
d945379b5b | ||
|
|
5a622ac9c7 | ||
|
|
0e9eac610b | ||
|
|
1de94a2705 | ||
|
|
71132c3538 | ||
|
|
d20ab0eb05 | ||
|
|
51f7e75d2e | ||
|
|
ab4b5ce994 | ||
|
|
f0d50ca9a2 | ||
|
|
5168355a64 | ||
|
|
2f209a9e4e | ||
|
|
20695eaba6 | ||
|
|
340a4dd1f2 | ||
|
|
ef1c7a5c69 | ||
|
|
5a01beaa1f | ||
|
|
f4055612e5 | ||
|
|
46911bd28c |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -2,6 +2,27 @@
|
||||
|
||||
Gaps between patch versions are faulty/broken releases.
|
||||
|
||||
## 2.5.0
|
||||
|
||||
* Remove `noDuplicateProperties` transformer.
|
||||
* Better generated UIDs based on nodes.
|
||||
* Default parameters now use `arguments[i]`, conditionals and variable declarations instead of using long-form if statements.
|
||||
|
||||
## 2.4.10
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 2.4.9
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add optional `protoToAssign` transformer.
|
||||
* Fix missing properties from computed property keys.
|
||||
* Make ES7 comprehensions `let` variables.
|
||||
|
||||
## 2.4.8
|
||||
|
||||
* Make `require("6to5/register")` work with browserify - [#370](https://github.com/6to5/6to5/pull/370). Thanks [@hughsk](https://github.com/hughsk)!
|
||||
|
||||
## 2.4.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
13
CODE_OF_CONDUCT.md
Normal file
13
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
||||
|
||||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
||||
@@ -1,5 +1,7 @@
|
||||
# Contributing
|
||||
|
||||
Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
* **General**
|
||||
* No ES6 syntax features or methods, exclusively ES5.
|
||||
* Max of five arguments for functions
|
||||
|
||||
@@ -49,13 +49,12 @@ var seattlers = (function() {
|
||||
}());
|
||||
```
|
||||
|
||||
As you can tell, it's not very pretty, unreadable even. Instead of mapping
|
||||
directly to a runtime, like other transpilers, 6to5 maps directly to the
|
||||
equivalent ES5.
|
||||
As you can tell, it's not very pretty. Instead of mapping directly to a
|
||||
runtime, like other transpilers, 6to5 maps directly to the equivalent ES5.
|
||||
|
||||
Sometimes there are little inline functions that 6to5 needs. These are
|
||||
placed at the top of your file much like coffee-script does. If these
|
||||
are bother you then you can use the [optional runtime](optional-runtime.md).
|
||||
bother you then you can use the [optional runtime](optional-runtime.md).
|
||||
We promise that these inline functions will never be significant and will
|
||||
always be used as little as possible.
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ function File(opts) {
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = [
|
||||
File.helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
"prototype-properties",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
@@ -32,7 +33,7 @@ File.declarations = [
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
File.excludeDeclarationsFromRuntime = [
|
||||
File.excludeHelpersFromRuntime = [
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
@@ -97,25 +98,30 @@ File.normaliseOptions = function (opts) {
|
||||
File.prototype.getTransformers = function () {
|
||||
var file = this;
|
||||
var transformers = [];
|
||||
var secondPassTransformers = [];
|
||||
|
||||
_.each(transform.transformers, function (transformer) {
|
||||
if (transformer.canRun(file)) {
|
||||
transformers.push(transformer);
|
||||
|
||||
if (transformer.secondPass) {
|
||||
secondPassTransformers.push(transformer);
|
||||
}
|
||||
|
||||
if (transformer.manipulateOptions) {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return transformers;
|
||||
return transformers.concat(secondPassTransformers);
|
||||
};
|
||||
|
||||
File.prototype.toArray = function (node, i) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
|
||||
return t.callExpression(t.memberExpression(this.addHelper("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
var declarationName = "to-array";
|
||||
var args = [node];
|
||||
@@ -123,7 +129,7 @@ File.prototype.toArray = function (node, i) {
|
||||
args.push(t.literal(i));
|
||||
declarationName = "sliced-to-array";
|
||||
}
|
||||
return t.callExpression(this.addDeclaration(declarationName), args);
|
||||
return t.callExpression(this.addHelper(declarationName), args);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -161,8 +167,8 @@ File.prototype.addImport = function (id, source) {
|
||||
this.dynamicImports.push(declar);
|
||||
};
|
||||
|
||||
File.prototype.addDeclaration = function (name) {
|
||||
if (!_.contains(File.declarations, name)) {
|
||||
File.prototype.addHelper = function (name) {
|
||||
if (!_.contains(File.helpers, name)) {
|
||||
throw new ReferenceError("unknown declaration " + name);
|
||||
}
|
||||
|
||||
@@ -173,7 +179,7 @@ File.prototype.addDeclaration = function (name) {
|
||||
|
||||
var ref;
|
||||
var runtimeNamespace = this.opts.runtime;
|
||||
if (runtimeNamespace && !_.contains(File.excludeDeclarationsFromRuntime, name)) {
|
||||
if (runtimeNamespace && !_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(t.identifier(runtimeNamespace), name);
|
||||
} else {
|
||||
|
||||
@@ -148,11 +148,11 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
};
|
||||
|
||||
if (this[node.type]) {
|
||||
var needsCommentParens = t.isExpression(node) && node.leadingComments && node.leadingComments.length;
|
||||
var needsParens = needsCommentParens || n.needsParens(node, parent);
|
||||
var needsNoLineTermParens = n.needsParensNoLineTerminator(node, parent);
|
||||
var needsParens = needsNoLineTermParens || n.needsParens(node, parent);
|
||||
|
||||
if (needsParens) this.push("(");
|
||||
if (needsCommentParens) this.indent();
|
||||
if (needsNoLineTermParens) this.indent();
|
||||
|
||||
this.printLeadingComments(node, parent);
|
||||
|
||||
@@ -163,7 +163,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
|
||||
this[node.type](node, this.buildPrint(node), parent);
|
||||
|
||||
if (needsCommentParens) {
|
||||
if (needsNoLineTermParens) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,29 @@ Node.prototype.needsParens = function () {
|
||||
return find(parens, node, parent);
|
||||
};
|
||||
|
||||
Node.prototype.needsParensNoLineTerminator = function () {
|
||||
var parent = this.parent;
|
||||
var node = this.node;
|
||||
|
||||
if (!parent) return false;
|
||||
|
||||
// no comments
|
||||
if (!node.leadingComments || !node.leadingComments.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isYieldExpression(parent) || t.isAwaitExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isContinueStatement(parent) || t.isBreakStatement(parent) ||
|
||||
t.isReturnStatement(parent) || t.isThrowStatement(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
_.each(Node.prototype, function (fn, key) {
|
||||
Node[key] = function (node, parent) {
|
||||
var n = new Node(node, parent);
|
||||
|
||||
@@ -20,6 +20,20 @@ _.each([
|
||||
});
|
||||
});
|
||||
|
||||
exports.ObjectExpression = function (node, parent) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
// ({ foo: "bar" });
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
// ({ foo: "bar" }).foo
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.Binary = function (node, parent) {
|
||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
||||
return true;
|
||||
|
||||
4
lib/6to5/register-browser.js
Normal file
4
lib/6to5/register-browser.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// Required to safely use 6to5/register within a browserify codebase.
|
||||
module.exports = function () {};
|
||||
|
||||
require("./polyfill");
|
||||
@@ -18,8 +18,8 @@ module.exports = function (namespace) {
|
||||
)
|
||||
]));
|
||||
|
||||
_.each(File.declarations, function (name) {
|
||||
if (_.contains(File.excludeDeclarationsFromRuntime, name)) {
|
||||
_.each(File.helpers, function (name) {
|
||||
if (_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
||||
this.stop();
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
@@ -79,7 +79,7 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
||||
this.stop();
|
||||
this.skip();
|
||||
return self.remapExportAssignment(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]);
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
// import {foo} from "foo";
|
||||
ref = t.memberExpression(ref, specifier.id, false);
|
||||
|
||||
@@ -26,7 +26,7 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName,
|
||||
t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", {
|
||||
t.callExpression(this.file.addHelper("interop-require"), [util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
})])
|
||||
)
|
||||
|
||||
@@ -114,7 +114,7 @@ SystemFormatter.prototype.transform = function (ast) {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
@@ -159,7 +159,7 @@ SystemFormatter.prototype.transform = function (ast) {
|
||||
// hoist up function declarations for circular references
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.stop();
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
|
||||
1
lib/6to5/transformation/templates/default-parameter.js
Normal file
1
lib/6to5/transformation/templates/default-parameter.js
Normal file
@@ -0,0 +1 @@
|
||||
var VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY];
|
||||
8
lib/6to5/transformation/templates/defaults.js
Normal file
8
lib/6to5/transformation/templates/defaults.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function (obj, defaults) {
|
||||
for (var key in defaults) {
|
||||
if (obj[key] === undefined) {
|
||||
obj[key] = defaults[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
if (VARIABLE === undefined) VARIABLE = DEFAULT;
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
@@ -0,0 +1,11 @@
|
||||
(function (FUNCTION_KEY) {
|
||||
var WRAPPER_KEY = function FUNCTION_ID() {
|
||||
return FUNCTION_KEY.apply(this, arguments);
|
||||
};
|
||||
|
||||
WRAPPER_KEY.toString = function () {
|
||||
return FUNCTION_KEY.toString();
|
||||
};
|
||||
|
||||
return WRAPPER_KEY;
|
||||
})(FUNCTION)
|
||||
@@ -42,7 +42,6 @@ _.each({
|
||||
// spec
|
||||
specBlockHoistFunctions: require("./transformers/spec-block-hoist-functions"),
|
||||
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||
specNoDuplicateProperties: require("./transformers/spec-no-duplicate-properties"),
|
||||
|
||||
// playground
|
||||
methodBinding: require("./transformers/playground-method-binding"),
|
||||
@@ -66,7 +65,7 @@ _.each({
|
||||
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||
spread: require("./transformers/es6-spread"),
|
||||
templateLiterals: require("./transformers/es6-template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
|
||||
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
|
||||
destructuring: require("./transformers/es6-destructuring"),
|
||||
defaultParameters: require("./transformers/es6-default-parameters"),
|
||||
forOf: require("./transformers/es6-for-of"),
|
||||
@@ -81,6 +80,8 @@ _.each({
|
||||
generators: require("./transformers/es6-generators"),
|
||||
restParameters: require("./transformers/es6-rest-parameters"),
|
||||
|
||||
protoToAssign: require("./transformers/optional-proto-to-assign"),
|
||||
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
// wrap up
|
||||
|
||||
@@ -7,6 +7,7 @@ var _ = require("lodash");
|
||||
function Transformer(key, transformer, opts) {
|
||||
this.manipulateOptions = transformer.manipulateOptions;
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.secondPass = !!transformer.secondPass;
|
||||
this.transformer = Transformer.normalise(transformer);
|
||||
this.optional = !!transformer.optional;
|
||||
this.opts = opts || {};
|
||||
@@ -41,16 +42,14 @@ Transformer.normalise = function (transformer) {
|
||||
|
||||
Transformer.prototype.astRun = function (file, key) {
|
||||
var transformer = this.transformer;
|
||||
var ast = file.ast;
|
||||
|
||||
if (transformer.ast && transformer.ast[key]) {
|
||||
transformer.ast[key](ast, file);
|
||||
transformer.ast[key](file.ast, file);
|
||||
}
|
||||
};
|
||||
|
||||
Transformer.prototype.transform = function (file) {
|
||||
var transformer = this.transformer;
|
||||
var ast = file.ast;
|
||||
|
||||
var build = function (exit) {
|
||||
return function (node, parent, scope) {
|
||||
@@ -67,7 +66,7 @@ Transformer.prototype.transform = function (file) {
|
||||
|
||||
this.astRun(file, "before");
|
||||
|
||||
traverse(ast, {
|
||||
traverse(file.ast, {
|
||||
enter: build(),
|
||||
exit: build(true)
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ var go = function (getBody, node, file, scope) {
|
||||
if (!node._aliasFunction) {
|
||||
if (t.isFunction(node)) {
|
||||
// stop traversal of this node as it'll be hit again by this transformer
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -30,10 +30,10 @@ var go = function (getBody, node, file, scope) {
|
||||
traverse(node, {
|
||||
enter: function (node, parent) {
|
||||
if (t.isFunction(node) && !node._aliasFunction) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node._ignoreAliasFunctions) return this.stop();
|
||||
if (node._ignoreAliasFunctions) return this.skip();
|
||||
|
||||
var getId;
|
||||
|
||||
@@ -49,7 +49,7 @@ var go = function (getBody, node, file, scope) {
|
||||
}
|
||||
});
|
||||
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
var kinds = {};
|
||||
@@ -22,4 +24,6 @@ exports.Program = function (node) {
|
||||
for (kind in kinds) {
|
||||
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
||||
}
|
||||
|
||||
node._declarations = null;
|
||||
};
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property = function (node) {
|
||||
if (node.method) node.method = false;
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
if (node.properties.length) {
|
||||
var objId = t.getUid(parent, file);
|
||||
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.template("object-define-properties", {
|
||||
OBJECT: objId,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
})
|
||||
});
|
||||
} else {
|
||||
return util.template("object-define-properties", {
|
||||
OBJECT: node,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -89,14 +89,14 @@ Class.prototype.run = function () {
|
||||
this.closure = true;
|
||||
|
||||
// so we're only evaluating it once
|
||||
var superRef = t.getUid(superName, this.file);
|
||||
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(superRef, superName)
|
||||
]));
|
||||
superName = superRef;
|
||||
|
||||
this.superName = superName;
|
||||
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName])));
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
|
||||
}
|
||||
|
||||
this.buildBody();
|
||||
@@ -175,7 +175,7 @@ Class.prototype.buildBody = function () {
|
||||
if (instanceProps) args.push(instanceProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addDeclaration("prototype-properties"), args)
|
||||
t.callExpression(this.file.addHelper("prototype-properties"), args)
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
var hasComputed = false;
|
||||
var prop;
|
||||
var key;
|
||||
@@ -13,7 +13,7 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
|
||||
if (!hasComputed) return;
|
||||
|
||||
var objId = t.getUid(parent, file);
|
||||
var objId = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
@@ -44,7 +44,7 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
broken = true;
|
||||
}
|
||||
|
||||
if (!broken || t.isLiteral(prop.key, { value: "__proto__" })) {
|
||||
if (!broken || t.isLiteral(t.toComputedKey(prop, prop.key), { value: "__proto__" })) {
|
||||
initProps.push(prop);
|
||||
props[i] = null;
|
||||
}
|
||||
@@ -61,13 +61,14 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
var bodyNode;
|
||||
|
||||
if (prop.computed && t.isMemberExpression(key) && t.isIdentifier(key.object, { name: "Symbol" })) {
|
||||
// { [Symbol.iterator]: "foo" }
|
||||
bodyNode = t.assignmentExpression(
|
||||
"=",
|
||||
t.memberExpression(objId, key, true),
|
||||
prop.value
|
||||
);
|
||||
} else {
|
||||
bodyNode = t.callExpression(file.addDeclaration("define-property"), [objId, key, prop.value]);
|
||||
bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]);
|
||||
}
|
||||
|
||||
body.push(t.expressionStatement(bodyNode));
|
||||
@@ -79,7 +80,7 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
var first = body[0].expression;
|
||||
|
||||
if (t.isCallExpression(first)) {
|
||||
first.arguments[0] = t.objectExpression([]);
|
||||
first.arguments[0] = t.objectExpression(initProps);
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,16 +49,29 @@ exports.Function = function (node, parent, file, scope) {
|
||||
|
||||
var body = [];
|
||||
|
||||
var argsIdentifier = t.identifier("arguments");
|
||||
argsIdentifier._ignoreAliasFunctions = true;
|
||||
|
||||
var lastNonDefaultParam = 0;
|
||||
|
||||
for (i in node.defaults) {
|
||||
def = node.defaults[i];
|
||||
if (!def) continue;
|
||||
if (!def) {
|
||||
lastNonDefaultParam = +i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
body.push(util.template("if-undefined-set-to", {
|
||||
VARIABLE: node.params[i],
|
||||
DEFAULT: def
|
||||
body.push(util.template("default-parameter", {
|
||||
VARIABLE_NAME: node.params[i],
|
||||
DEFAULT_VALUE: def,
|
||||
ARGUMENT_KEY: t.literal(+i),
|
||||
ARGUMENTS: argsIdentifier
|
||||
}, true));
|
||||
}
|
||||
|
||||
// we need to cut off all trailing default parameters
|
||||
node.params = node.params.slice(0, lastNonDefaultParam);
|
||||
|
||||
if (iife) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator);
|
||||
container._aliasFunction = true;
|
||||
|
||||
@@ -45,7 +45,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
}
|
||||
keys = t.arrayExpression(keys);
|
||||
|
||||
var value = t.callExpression(opts.file.addDeclaration("object-without-properties"), [parentId, keys]);
|
||||
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
|
||||
nodes.push(buildVariableAssign(opts, prop.argument, value));
|
||||
} else {
|
||||
var pattern2 = prop.value;
|
||||
@@ -75,7 +75,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
|
||||
|
||||
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
|
||||
|
||||
var _parentId = t.getUid(parentId, opts.file, opts.scope);
|
||||
var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(_parentId, toArray)
|
||||
]));
|
||||
@@ -113,7 +113,7 @@ var pushPattern = function (opts) {
|
||||
var scope = opts.scope;
|
||||
|
||||
if (!t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
|
||||
var key = t.getUid(parentId, file, scope);
|
||||
var key = scope.generateUidBasedOnNode(parentId, file);
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(key, parentId)
|
||||
|
||||
@@ -280,7 +280,7 @@ LetScoping.prototype.checkLoop = function () {
|
||||
var replace;
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node && !node.label) {
|
||||
@@ -329,7 +329,7 @@ LetScoping.prototype.hoistVarDeclarations = function () {
|
||||
} else if (isVar(node, parent)) {
|
||||
return self.pushDeclar(node).map(t.expressionStatement);
|
||||
} else if (t.isFunction(node)) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -388,9 +388,9 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
}
|
||||
});
|
||||
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
} else if (t.isLoop(node)) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property = function (node, parent, file, scope) {
|
||||
if (!node.method) return;
|
||||
|
||||
node.method = false;
|
||||
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var selfReference = false;
|
||||
var outerDeclar = scope.get(id, true);
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node, parent, scope) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.get(id, true);
|
||||
if (localDeclar !== outerDeclar) return;
|
||||
|
||||
selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
}, scope);
|
||||
|
||||
if (selfReference) {
|
||||
node.value = util.template("property-method-assignment-wrapper", {
|
||||
FUNCTION: node.value,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: file.generateUidIdentifier(id, scope),
|
||||
WRAPPER_KEY: file.generateUidIdentifier(id + "Wrapper", scope)
|
||||
});
|
||||
} else {
|
||||
node.value.id = key;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
if (node.properties.length) {
|
||||
var objId = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.template("object-define-properties", {
|
||||
OBJECT: objId,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
})
|
||||
});
|
||||
} else {
|
||||
return util.template("object-define-properties", {
|
||||
OBJECT: node,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -77,16 +77,15 @@ exports.CallExpression = function (node, parent, file, scope) {
|
||||
}
|
||||
|
||||
var callee = node.callee;
|
||||
var temp;
|
||||
|
||||
if (t.isMemberExpression(callee)) {
|
||||
contextLiteral = callee.object;
|
||||
|
||||
if (t.isDynamic(contextLiteral)) {
|
||||
temp = contextLiteral = scope.generateTemp(file);
|
||||
var temp = scope.generateTempBasedOnNode(callee.object, file);
|
||||
if (temp) {
|
||||
callee.object = t.assignmentExpression("=", temp, callee.object);
|
||||
contextLiteral = temp;
|
||||
} else {
|
||||
contextLiteral = callee.object;
|
||||
}
|
||||
|
||||
t.appendToMemberExpression(callee, t.identifier("apply"));
|
||||
} else {
|
||||
node.callee = t.memberExpression(node.callee, t.identifier("apply"));
|
||||
@@ -108,5 +107,5 @@ exports.NewExpression = function (node, parent, file) {
|
||||
args = first;
|
||||
}
|
||||
|
||||
return t.callExpression(file.addDeclaration("apply-constructor"), [node.callee, args]);
|
||||
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ exports.TaggedTemplateExpression = function (node, parent, file) {
|
||||
raw.push(t.literal(elem.value.raw));
|
||||
}
|
||||
|
||||
args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [
|
||||
args.push(t.callExpression(file.addHelper("tagged-template-literal"), [
|
||||
t.arrayExpression(strings),
|
||||
t.arrayExpression(raw)
|
||||
]));
|
||||
|
||||
@@ -30,10 +30,8 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
|
||||
// we need to return `node.right`
|
||||
if (!t.isExpressionStatement(parent)) {
|
||||
// `node.right` isn't a simple identifier so we need to reference it
|
||||
if (t.isDynamic(value)) {
|
||||
temp = value = scope.generateTemp(file);
|
||||
}
|
||||
temp = scope.generateTempBasedOnNode(node.right, file);
|
||||
if (temp) value = temp;
|
||||
}
|
||||
|
||||
if (node.operator !== "=") {
|
||||
@@ -80,11 +78,7 @@ exports.CallExpression = function (node, parent, file, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp;
|
||||
if (t.isDynamic(callee.object)) {
|
||||
// we need to save `callee.object` so we can call it again
|
||||
temp = scope.generateTemp(file);
|
||||
}
|
||||
var temp = scope.generateTempBasedOnNode(callee.object, file);
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
|
||||
@@ -5,7 +5,7 @@ var t = require("../../types");
|
||||
exports.experimental = true;
|
||||
|
||||
var build = function (node, parent, file, scope) {
|
||||
var uid = t.getUid(parent, file, scope);
|
||||
var uid = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
var container = util.template("array-comprehension-container", {
|
||||
KEY: uid
|
||||
@@ -49,7 +49,7 @@ exports._build = function (node, buildBody) {
|
||||
}
|
||||
|
||||
return t.forOfStatement(
|
||||
t.variableDeclaration("var", [t.variableDeclarator(self.left)]),
|
||||
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
|
||||
self.right,
|
||||
t.blockStatement([child])
|
||||
);
|
||||
|
||||
@@ -7,5 +7,5 @@ exports.manipulateOptions = bluebirdCoroutines.manipulateOptions;
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return bluebirdCoroutines._Function(node, file.addDeclaration("async-to-generator"));
|
||||
return bluebirdCoroutines._Function(node, file.addHelper("async-to-generator"));
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ exports._Function = function (node, callId) {
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.stop();
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isAwaitExpression(node)) {
|
||||
node.type = "YieldExpression";
|
||||
|
||||
@@ -29,7 +29,7 @@ exports.ast = {
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (!node.computed && coreHas(obj) && _.has(core[obj.name], prop.name)) {
|
||||
this.stop();
|
||||
this.skip();
|
||||
return t.prependToMemberExpression(node, file._coreId);
|
||||
}
|
||||
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && coreHas(node)) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var OBJECT_ASSIGN_MEMBER = t.memberExpression(t.identifier("Object"), t.identifier("assign"));
|
||||
|
||||
var isProtoKey = function (node) {
|
||||
return t.isLiteral(t.toComputedKey(node, node.key), { value: "__proto__" });
|
||||
};
|
||||
|
||||
var isProtoAssignmentExpression = function (node) {
|
||||
var left = node.left;
|
||||
return t.isMemberExpression(left) && t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" });
|
||||
};
|
||||
|
||||
var buildDefaultsCallExpression = function (expr, ref, file) {
|
||||
return t.expressionStatement(t.callExpression(file.addHelper("defaults"), [ref, expr.right]));
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
if (t.isExpressionStatement(parent)) return;
|
||||
if (!isProtoAssignmentExpression(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
var left = node.left.object;
|
||||
var temp = scope.generateTempBasedOnNode(node.left.object, file);
|
||||
|
||||
nodes.push(t.expressionStatement(t.assignmentExpression("=", temp, left)));
|
||||
nodes.push(buildDefaultsCallExpression(node, temp, file));
|
||||
if (temp) nodes.push(temp);
|
||||
|
||||
return t.toSequenceExpression(nodes);
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, file) {
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr, { operator: "=" })) return;
|
||||
|
||||
if (isProtoAssignmentExpression(expr)) {
|
||||
return buildDefaultsCallExpression(expr, expr.left.object, file);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
var proto;
|
||||
|
||||
for (var i in node.properties) {
|
||||
var prop = node.properties[i];
|
||||
|
||||
if (isProtoKey(prop)) {
|
||||
proto = prop.value;
|
||||
_.pull(node.properties, prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (proto) {
|
||||
var args = [t.objectExpression([]), proto];
|
||||
if (node.properties.length) args.push(node);
|
||||
return t.callExpression(OBJECT_ASSIGN_MEMBER, args);
|
||||
}
|
||||
};
|
||||
@@ -10,7 +10,7 @@ var getPropRef = function (nodes, prop, file, scope) {
|
||||
if (t.isIdentifier(prop)) {
|
||||
return t.literal(prop.name);
|
||||
} else {
|
||||
var temp = t.getUid(prop, file, scope);
|
||||
var temp = scope.generateUidBasedOnNode(prop, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
@@ -19,22 +19,18 @@ var getPropRef = function (nodes, prop, file, scope) {
|
||||
};
|
||||
|
||||
var getObjRef = function (nodes, obj, file, scope) {
|
||||
if (t.isDynamic(obj)) {
|
||||
var temp = t.getUid(obj, file, scope);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, obj)
|
||||
]));
|
||||
return temp;
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
var temp = scope.generateUidBasedOnNode(obj, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, obj)
|
||||
]));
|
||||
return temp;
|
||||
};
|
||||
|
||||
var buildHasOwn = function (obj, prop, file) {
|
||||
return t.unaryExpression(
|
||||
"!",
|
||||
t.callExpression(
|
||||
t.memberExpression(file.addDeclaration("has-own"), t.identifier("call")),
|
||||
t.memberExpression(file.addHelper("has-own"), t.identifier("call")),
|
||||
[obj, prop]
|
||||
),
|
||||
true
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.BindMemberExpression = function (node, parent, file, scope) {
|
||||
var object = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
var temp;
|
||||
if (t.isDynamic(object)) {
|
||||
temp = object = scope.generateTemp(file);
|
||||
}
|
||||
var temp = scope.generateTempBasedOnNode(node.object, file);
|
||||
if (temp) object = temp;
|
||||
|
||||
var call = t.callExpression(
|
||||
t.memberExpression(t.memberExpression(object, prop), t.identifier("bind")),
|
||||
@@ -33,16 +30,12 @@ exports.BindFunctionExpression = function (node, parent, file, scope) {
|
||||
]));
|
||||
};
|
||||
|
||||
if (_.find(node.arguments, t.isDynamic)) {
|
||||
var temp = scope.generateTemp(file, "args");
|
||||
var temp = scope.generateTemp(file, "args");
|
||||
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
buildCall(node.arguments.map(function (node, i) {
|
||||
return t.memberExpression(temp, t.literal(i), true);
|
||||
}))
|
||||
]);
|
||||
} else {
|
||||
return buildCall(node.arguments);
|
||||
}
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
buildCall(node.arguments.map(function (node, i) {
|
||||
return t.memberExpression(temp, t.literal(i), true);
|
||||
}))
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ exports.MethodDefinition = function (node, parent, file) {
|
||||
if (t.isFunction(node)) return;
|
||||
|
||||
if (t.isReturnStatement(node) && node.argument) {
|
||||
node.argument = t.memberExpression(t.callExpression(file.addDeclaration("define-property"), [
|
||||
node.argument = t.memberExpression(t.callExpression(file.addHelper("define-property"), [
|
||||
t.thisExpression(),
|
||||
key,
|
||||
node.argument
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var keys = [];
|
||||
|
||||
for (var i in node.properties) {
|
||||
var prop = node.properties[i];
|
||||
if (prop.computed || prop.kind !== "init") continue;
|
||||
|
||||
var key = prop.key;
|
||||
if (t.isIdentifier(key)) {
|
||||
key = key.name;
|
||||
} else if (t.isLiteral(key)) {
|
||||
key = key.value;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (keys.indexOf(key) >= 0) {
|
||||
throw file.errorWithNode(prop.key, "Duplicate property key");
|
||||
} else {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -22,12 +22,14 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var stopped = false;
|
||||
|
||||
for (var i in keys) {
|
||||
var key = keys[i];
|
||||
var nodes = parent[key];
|
||||
if (!nodes) continue;
|
||||
|
||||
var updated = false;
|
||||
var flatten = false;
|
||||
|
||||
var handle = function (obj, key) {
|
||||
var node = obj[key];
|
||||
@@ -50,7 +52,8 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
// replace the node
|
||||
node = obj[key] = result;
|
||||
updated = true;
|
||||
|
||||
if (isArray) flatten = true;
|
||||
|
||||
// we're replacing a statement or block node with an array of statements so we better
|
||||
// ensure that it's a block
|
||||
@@ -59,16 +62,20 @@ function traverse(parent, opts, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
var stopped = false;
|
||||
var skipped = false;
|
||||
var removed = false;
|
||||
|
||||
var context = {
|
||||
stop: function () {
|
||||
stopped = true;
|
||||
skipped = stopped = true;
|
||||
},
|
||||
|
||||
skip: function () {
|
||||
skipped = true;
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this.stop();
|
||||
this.skip();
|
||||
removed = true;
|
||||
}
|
||||
};
|
||||
@@ -84,11 +91,11 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
if (removed) {
|
||||
obj[key] = null;
|
||||
updated = true;
|
||||
flatten = true;
|
||||
}
|
||||
|
||||
// stop iteration
|
||||
if (stopped) return;
|
||||
if (skipped) return;
|
||||
}
|
||||
|
||||
// traverse node
|
||||
@@ -103,9 +110,10 @@ function traverse(parent, opts, scope) {
|
||||
if (_.isArray(nodes)) {
|
||||
for (i in nodes) {
|
||||
handle(nodes, i);
|
||||
if (stopped) return;
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
if (flatten) {
|
||||
parent[key] = _.flatten(parent[key]);
|
||||
|
||||
if (key === "body") {
|
||||
@@ -115,6 +123,7 @@ function traverse(parent, opts, scope) {
|
||||
}
|
||||
} else {
|
||||
handle(parent, key);
|
||||
if (stopped) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,7 +170,7 @@ traverse.hasType = function (tree, type, blacklistTypes) {
|
||||
enter: function (node) {
|
||||
if (node.type === type) {
|
||||
has = true;
|
||||
this.stop();
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -31,6 +31,13 @@ Scope.add = function (node, references) {
|
||||
_.defaults(references, t.getIds(node, true));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {File} file
|
||||
* @param {String} [name="temp"]
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTemp = function (file, name) {
|
||||
var id = file.generateUidIdentifier(name || "temp", this);
|
||||
this.push({
|
||||
@@ -40,6 +47,70 @@ Scope.prototype.generateTemp = function (file, name) {
|
||||
return id;
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} parent
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidBasedOnNode = function (parent, file) {
|
||||
var node = parent;
|
||||
|
||||
if (t.isAssignmentExpression(parent)) {
|
||||
node = parent.left;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
node = parent.id;
|
||||
} else if (t.isProperty(node)) {
|
||||
node = node.key;
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
|
||||
var add = function (node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
add(node.object);
|
||||
add(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
parts.push(node.name);
|
||||
} else if (t.isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
add(node.callee);
|
||||
}
|
||||
};
|
||||
|
||||
add(node);
|
||||
|
||||
var id = parts.join("$");
|
||||
id = id.replace(/^_/, "") || "ref";
|
||||
|
||||
return file.generateUidIdentifier(id, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {File} file
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTempBasedOnNode = function (node, file) {
|
||||
if (t.isIdentifier(node) && this.has(node.name, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var id = this.generateUidBasedOnNode(node, file);
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
Scope.prototype.getInfo = function () {
|
||||
var block = this.block;
|
||||
if (block._scopeInfo) return block._scopeInfo;
|
||||
@@ -93,7 +164,7 @@ Scope.prototype.getInfo = function () {
|
||||
|
||||
// this block is a function so we'll stop since none of the variables
|
||||
// declared within are accessible
|
||||
if (t.isFunction(node)) return this.stop();
|
||||
if (t.isFunction(node)) return this.skip();
|
||||
|
||||
// function identifier doesn't belong to this scope
|
||||
if (block.id && node === block.id) return;
|
||||
@@ -123,6 +194,12 @@ Scope.prototype.getInfo = function () {
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} opts
|
||||
*/
|
||||
|
||||
Scope.prototype.push = function (opts) {
|
||||
var block = this.block;
|
||||
|
||||
@@ -143,33 +220,84 @@ Scope.prototype.push = function (opts) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
*/
|
||||
|
||||
Scope.prototype.add = function (node) {
|
||||
Scope.add(node, this.references);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.get = function (id, decl) {
|
||||
return id && (this.getOwn(id, decl) || this.parentGet(id, decl));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.getOwn = function (id, decl) {
|
||||
var refs = this.references;
|
||||
if (decl) refs = this.declarations;
|
||||
return _.has(refs, id) && refs[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.parentGet = function (id, decl) {
|
||||
return this.parent && this.parent.get(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.has = function (id, decl) {
|
||||
return (id && (this.hasOwn(id, decl) || this.parentHas(id, decl))) ||
|
||||
_.contains(Scope.defaultDeclarations, id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.hasOwn = function (id, decl) {
|
||||
return !!this.getOwn(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.parentHas = function (id, decl) {
|
||||
return this.parent && this.parent.has(id, decl);
|
||||
};
|
||||
|
||||
@@ -64,6 +64,20 @@ _.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
|
||||
addAssert(type, is);
|
||||
});
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.toComputedKey = function (node, key) {
|
||||
if (!node.computed) {
|
||||
if (t.isIdentifier(key)) key = t.literal(key.name);
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
/*
|
||||
* Shallowly checks to see if the passed `node` will evaluate to a
|
||||
* falsy. This is if `node` is a `Literal` and `value` is falsy or
|
||||
@@ -111,7 +125,11 @@ t.toSequenceExpression = function (nodes, scope) {
|
||||
}
|
||||
});
|
||||
|
||||
return t.sequenceExpression(exprs);
|
||||
if (exprs.length === 1) {
|
||||
return exprs[0];
|
||||
} else {
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -159,25 +177,6 @@ t.prependToMemberExpression = function (member, append) {
|
||||
return member;
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isDynamic = function (node) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
return t.isDynamic(node.expression);
|
||||
} else if (t.isIdentifier(node) || t.isLiteral(node) || t.isThisExpression(node)) {
|
||||
return false;
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
return t.isDynamic(node.object) || t.isDynamic(node.property);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
@@ -326,58 +325,6 @@ t.toBlock = function (node, parent) {
|
||||
return t.blockStatement(node);
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} parent
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.getUid = function (parent, file, scope) {
|
||||
var node = parent;
|
||||
|
||||
if (t.isAssignmentExpression(parent)) {
|
||||
node = parent.left;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
node = parent.id;
|
||||
}
|
||||
|
||||
var id = "ref";
|
||||
|
||||
if (t.isProperty(node)) {
|
||||
node = node.key;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node)) {
|
||||
id = node.name;
|
||||
} else if (t.isLiteral(node)) {
|
||||
id = node.value;
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
var parts = [];
|
||||
|
||||
var add = function (node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
add(node.object);
|
||||
add(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
parts.push(node.name);
|
||||
} else if (t.isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
}
|
||||
};
|
||||
|
||||
add(node);
|
||||
|
||||
id = parts.join("$");
|
||||
}
|
||||
|
||||
id = id.replace(/^_/, "");
|
||||
|
||||
return file.generateUidIdentifier(id, scope);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.4.7",
|
||||
"version": "2.5.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -18,6 +18,10 @@
|
||||
"6to5-node": "./bin/6to5-node",
|
||||
"6to5-runtime": "./bin/6to5-runtime"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/6to5/index.js": "./lib/6to5/browser.js",
|
||||
"./lib/6to5/register.js": "./lib/6to5/register-browser.js"
|
||||
},
|
||||
"keywords": [
|
||||
"harmony",
|
||||
"classes",
|
||||
@@ -35,7 +39,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-4",
|
||||
"acorn-6to5": "0.11.1-10",
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var humanise = function (val) {
|
||||
return val.replace(/-/g, " ");
|
||||
@@ -37,7 +38,6 @@ exports.get = function (entryName) {
|
||||
|
||||
_.each(fs.readdirSync(suite.filename), function (taskName) {
|
||||
var taskDir = suite.filename + "/" + taskName;
|
||||
if (fs.statSync(taskDir).isFile()) return;
|
||||
|
||||
var actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
||||
var expectLocAlias = suiteName + "/" + taskName + "/expected.js";
|
||||
@@ -47,6 +47,13 @@ exports.get = function (entryName) {
|
||||
var expectLoc = taskDir + "/expected.js";
|
||||
var execLoc = taskDir + "/exec.js";
|
||||
|
||||
if (fs.statSync(taskDir).isFile()) {
|
||||
var ext = path.extname(taskDir);
|
||||
if (ext !== ".js") return;
|
||||
|
||||
execLoc = taskDir;
|
||||
}
|
||||
|
||||
var taskOpts = _.merge({
|
||||
filenameRelative: expectLocAlias,
|
||||
sourceFileName: actualLocAlias,
|
||||
|
||||
@@ -13,10 +13,10 @@ suite("api", function () {
|
||||
assert.ok(!result.ast);
|
||||
});
|
||||
|
||||
test("addDeclaration unknown", function () {
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File;
|
||||
assert.throws(function () {
|
||||
file.addDeclaration("foob");
|
||||
file.addHelper("foob");
|
||||
}, /unknown declaration foob/);
|
||||
});
|
||||
});
|
||||
|
||||
19
test/browserify.js
Normal file
19
test/browserify.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var browserify = require("browserify");
|
||||
var assert = require("assert");
|
||||
var path = require("path");
|
||||
var vm = require("vm");
|
||||
|
||||
suite("browserify", function() {
|
||||
test("6to5/register may be used without breaking browserify", function(done) {
|
||||
var bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
|
||||
bundler.bundle(function(err, bundle) {
|
||||
if (err) return done(err);
|
||||
assert.ok(bundle.length, "bundle output code");
|
||||
|
||||
// ensure that the code runs without throwing an exception
|
||||
vm.runInNewContext(bundle, {});
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
3
test/fixtures/browserify/register.js
vendored
Normal file
3
test/fixtures/browserify/register.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
require("../../../register")({
|
||||
ignore: false
|
||||
});
|
||||
@@ -3,9 +3,8 @@ var test = {
|
||||
* Before bracket init
|
||||
*/
|
||||
["a"]: "1",
|
||||
[( /*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"
|
||||
)]: "2"
|
||||
[/*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"]: "2"
|
||||
}, ok = 42;
|
||||
|
||||
@@ -4,11 +4,10 @@ var test = {
|
||||
*/
|
||||
["a"]: "1",
|
||||
|
||||
[( /*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"
|
||||
)]: "2",
|
||||
[/*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"]: "2",
|
||||
|
||||
["c"
|
||||
/*
|
||||
@@ -18,10 +17,9 @@ var test = {
|
||||
// Before bracket, line comment
|
||||
["d"]: "4",
|
||||
|
||||
[(
|
||||
// Inside bracket, line comment
|
||||
"e"
|
||||
)]: "5",
|
||||
[
|
||||
// Inside bracket, line comment
|
||||
"e"]: "5",
|
||||
|
||||
["f"
|
||||
// After bracket, line comment
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var some = function (count) {
|
||||
if (count === undefined) count = "30";
|
||||
var some = function () {
|
||||
var count = arguments[0] === undefined ? "30" : arguments[0];
|
||||
console.log("count", count);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
module.exports = {
|
||||
init() {
|
||||
return new Promise((resolve, reject) => {
|
||||
MongoClient.connect(config.mongodb, (err, db) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.db = db;
|
||||
resolve(this);
|
||||
init: function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
MongoClient.connect(config.mongodb, (err, db) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.db = db;
|
||||
resolve(this);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ var _inherits = function (child, parent) {
|
||||
var Test = (function () {
|
||||
var _Foo = Foo;
|
||||
var Test = function Test() {
|
||||
var _Foo$prototype$test, _Foo$prototype$test2;
|
||||
woops["super"].test();
|
||||
_Foo.call(this);
|
||||
_Foo.prototype.test.call(this);
|
||||
@@ -24,22 +25,24 @@ var Test = (function () {
|
||||
_Foo.call.apply(_Foo, [this].concat(_slice.call(arguments)));
|
||||
_Foo.call.apply(_Foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
|
||||
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this].concat(_slice.call(arguments)));
|
||||
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
|
||||
(_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);
|
||||
|
||||
Test.prototype.test = function () {
|
||||
var _Foo$prototype$test3, _Foo$prototype$test4;
|
||||
_Foo.prototype.test.call(this);
|
||||
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this].concat(_slice.call(arguments)));
|
||||
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test3 = _Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test4 = _Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
|
||||
Test.foo = function () {
|
||||
var _Foo$foo, _Foo$foo2;
|
||||
_Foo.foo.call(this);
|
||||
_Foo.foo.call.apply(_Foo.foo, [this].concat(_slice.call(arguments)));
|
||||
_Foo.foo.call.apply(_Foo.foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
(_Foo$foo = _Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$foo2 = _Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
|
||||
return Test;
|
||||
|
||||
4
test/fixtures/transformation/es6-computed-property-names/two/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-computed-property-names/two/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var obj = {
|
||||
first: "first",
|
||||
["second"]: "second",
|
||||
};
|
||||
13
test/fixtures/transformation/es6-computed-property-names/two/expected.js
vendored
Normal file
13
test/fixtures/transformation/es6-computed-property-names/two/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var _defineProperty = function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
};
|
||||
|
||||
var obj = _defineProperty({
|
||||
first: "first" }, "second", "second");
|
||||
@@ -1,12 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var t = function (t, f) {
|
||||
if (t === undefined) t = "foo";
|
||||
if (f === undefined) f = 5;
|
||||
var t = function () {
|
||||
var t = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
var f = arguments[1] === undefined ? 5 : arguments[1];
|
||||
return t + " bar " + f;
|
||||
};
|
||||
|
||||
var a = function (t, f) {
|
||||
if (f === undefined) f = 5;
|
||||
var a = function (t) {
|
||||
var f = arguments[1] === undefined ? 5 : arguments[1];
|
||||
return t + " bar " + f;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var t = function (t) {
|
||||
if (t === undefined) t = "foo";
|
||||
var t = function () {
|
||||
var t = arguments[0] === undefined ? "foo" : arguments[0];
|
||||
return t + " bar";
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var obj = {
|
||||
get foo() {
|
||||
return 5 + 5;
|
||||
return 5 + 5;
|
||||
},
|
||||
set foo(value) {
|
||||
this._foo = value;
|
||||
this._foo = value;
|
||||
}
|
||||
};
|
||||
19
test/fixtures/transformation/es6-property-method-assignment/method-self-reference/actual.js
vendored
Normal file
19
test/fixtures/transformation/es6-property-method-assignment/method-self-reference/actual.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var bar = {
|
||||
foo() {
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var bar = {
|
||||
foo() {
|
||||
var foo = 41;
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var foobar = 123;
|
||||
var foobar2 = {
|
||||
foobar() {
|
||||
console.log(foobar);
|
||||
}
|
||||
};
|
||||
41
test/fixtures/transformation/es6-property-method-assignment/method-self-reference/expected.js
vendored
Normal file
41
test/fixtures/transformation/es6-property-method-assignment/method-self-reference/expected.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
var bar = {
|
||||
foo: (function (_foo) {
|
||||
var _fooWrapper = function foo() {
|
||||
return _foo.apply(this, arguments);
|
||||
};
|
||||
|
||||
_fooWrapper.toString = function () {
|
||||
return _foo.toString();
|
||||
};
|
||||
|
||||
return _fooWrapper;
|
||||
})(function () {
|
||||
console.log(foo);
|
||||
})
|
||||
};
|
||||
|
||||
var bar = {
|
||||
foo: function foo() {
|
||||
var foo = 41;
|
||||
console.log(foo);
|
||||
}
|
||||
};
|
||||
|
||||
var foobar = 123;
|
||||
var foobar2 = {
|
||||
foobar: (function (_foobar) {
|
||||
var _foobarWrapper = function foobar() {
|
||||
return _foobar.apply(this, arguments);
|
||||
};
|
||||
|
||||
_foobarWrapper.toString = function () {
|
||||
return _foobar.toString();
|
||||
};
|
||||
|
||||
return _foobarWrapper;
|
||||
})(function () {
|
||||
console.log(foobar);
|
||||
})
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
var obj = {
|
||||
method() {
|
||||
return 5 + 5;
|
||||
return 5 + 5;
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var obj = {
|
||||
method: function () {
|
||||
method: function method() {
|
||||
return 5 + 5;
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _obj;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
};
|
||||
|
||||
obj[method].apply(obj, [foo, bar].concat(_toArray(args)));
|
||||
(_obj = obj)[method].apply(_obj, [foo, bar].concat(_toArray(args)));
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _obj;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
};
|
||||
|
||||
obj[method].apply(obj, _toArray(args));
|
||||
(_obj = obj)[method].apply(_obj, _toArray(args));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _foob, _foob$test;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
};
|
||||
|
||||
foob.add.apply(foob, [foo, bar].concat(_toArray(numbers)));
|
||||
foob.test.add.apply(foob.test, [foo, bar].concat(_toArray(numbers)));
|
||||
(_foob = foob).add.apply(_foob, [foo, bar].concat(_toArray(numbers)));
|
||||
(_foob$test = foob.test).add.apply(_foob$test, [foo, bar].concat(_toArray(numbers)));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _foob, _foob$test;
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : Array.from(arr);
|
||||
};
|
||||
|
||||
foob.add.apply(foob, _toArray(numbers));
|
||||
foob.test.add.apply(foob.test, _toArray(numbers));
|
||||
(_foob = foob).add.apply(_foob, _toArray(numbers));
|
||||
(_foob$test = foob.test).add.apply(_foob$test, _toArray(numbers));
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
foo::bar();
|
||||
foo::bar("arg");
|
||||
|
||||
var test = "test";
|
||||
test::bar();
|
||||
test::bar("arg");
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
bar[Symbol.referenceGet](foo).call(foo);
|
||||
bar[Symbol.referenceGet](foo).call(foo, "arg");
|
||||
var _foo, _foo2;
|
||||
_foo = foo, bar[Symbol.referenceGet](_foo).call(_foo);
|
||||
_foo2 = foo, bar[Symbol.referenceGet](_foo2).call(_foo2, "arg");
|
||||
|
||||
var test = "test";
|
||||
bar[Symbol.referenceGet](test).call(test);
|
||||
bar[Symbol.referenceGet](test).call(test, "arg");
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
delete foo::bar;
|
||||
|
||||
if (delete foo::bar);
|
||||
if (delete foo::bar) {}
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
bar[Symbol.referenceDelete](foo);
|
||||
|
||||
if ((bar[Symbol.referenceDelete](foo), true)) ;
|
||||
if ((bar[Symbol.referenceDelete](foo), true)) {}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
var baz = "foo";
|
||||
foo::bar = baz;
|
||||
if (foo::bar = baz);
|
||||
if (foo::bar = baz) {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var baz = "foo";
|
||||
bar[Symbol.referenceSet](foo, baz);
|
||||
if ((bar[Symbol.referenceSet](foo, baz), baz)) ;
|
||||
if ((bar[Symbol.referenceSet](foo, baz), baz)) {}
|
||||
|
||||
@@ -4,9 +4,9 @@ var arr = (function () {
|
||||
var _arr = [];
|
||||
|
||||
for (var _iterator = [1, 2, 3][Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
var i = _step.value;
|
||||
if (i > 1) {
|
||||
_arr.push(i * i);
|
||||
var _i = _step.value;
|
||||
if (_i > 1) {
|
||||
_arr.push(_i * _i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ var seattlers = (function () {
|
||||
for (var _iterator = countries[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
var customers = _step.value;
|
||||
for (var _iterator2 = customers[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) {
|
||||
var c = _step2.value;
|
||||
if (c.city == "Seattle") {
|
||||
_seattlers.push({ name: c.name, age: c.age });
|
||||
var _c = _step2.value;
|
||||
if (_c.city == "Seattle") {
|
||||
_seattlers.push({ name: _c.name, age: _c.age });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ var arr = (function () {
|
||||
var _arr = [];
|
||||
|
||||
for (var _iterator = nums[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
|
||||
var i = _step.value;
|
||||
if (i > 1) {
|
||||
_arr.push(i * i);
|
||||
var _i = _step.value;
|
||||
if (_i > 1) {
|
||||
_arr.push(_i * _i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
57
test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js
vendored
Normal file
57
test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
function makeMultiplier() {
|
||||
// `arguments` should refer to `makeMultiplier`'s arguments.
|
||||
return (n) => [].slice.call(arguments).reduce((a, b) => a * b) * n;
|
||||
}
|
||||
|
||||
function toArray() {
|
||||
// Intentionally nest arrow functions to ensure `arguments` is put inside
|
||||
// `toArray`'s scope.
|
||||
return (() => (arguments, (() => [].slice.call(arguments)).call())).call();
|
||||
}
|
||||
|
||||
function returnDotArguments(object) {
|
||||
// Ensure `arguments` is not treated as a reference to the magic value.
|
||||
return (() => object.arguments).call();
|
||||
}
|
||||
|
||||
function returnArgumentsObject() {
|
||||
// Ensure `arguments` is not treated as a reference to the magic value.
|
||||
return (() => ({arguments: 1})).call();
|
||||
}
|
||||
|
||||
function makeArgumentsReturner() {
|
||||
return (() => function() {
|
||||
return [].slice.call(arguments);
|
||||
}).call();
|
||||
}
|
||||
|
||||
// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4)
|
||||
assert.equal(
|
||||
makeMultiplier(2, 3)(4),
|
||||
24,
|
||||
'ensure `arguments` is hoisted out to the first non-arrow scope'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
toArray(1, 2, 3),
|
||||
[1, 2, 3],
|
||||
'ensure `arguments` is hoisted out to the first non-arrow scope'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
returnDotArguments({arguments: 1}),
|
||||
1,
|
||||
'member accesses with `arguments` property should not be replaced'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
returnArgumentsObject(),
|
||||
{arguments: 1},
|
||||
'object property keys named `arguments` should not be replaced'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
makeArgumentsReturner()(1, 2, 3),
|
||||
[1, 2, 3],
|
||||
'arguments should not be hoisted from inside non-arrow functions'
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
var dynamicThisGetter = () => function () { return this; };
|
||||
assert.equal(
|
||||
'(' + dynamicThisGetter.toString() + ')',
|
||||
'(function () {\n return function () {\n return this;\n };\n})'
|
||||
);
|
||||
2
test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js
vendored
Normal file
2
test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var empty = () => {};
|
||||
assert.equal(empty(), undefined);
|
||||
12
test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js
vendored
Normal file
12
test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var obj = {
|
||||
method: function() {
|
||||
return () => (this, () => this);
|
||||
},
|
||||
|
||||
method2: function() {
|
||||
return () => () => this;
|
||||
}
|
||||
};
|
||||
|
||||
assert.strictEqual(obj.method()()(), obj);
|
||||
assert.strictEqual(obj.method2()()(), obj);
|
||||
@@ -0,0 +1,2 @@
|
||||
var square = x => x * x;
|
||||
assert.equal(square(4), 16);
|
||||
2
test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js
vendored
Normal file
2
test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var keyMaker = val => ({ key: val });
|
||||
assert.deepEqual(keyMaker(9), { key: 9 });
|
||||
@@ -0,0 +1,7 @@
|
||||
var obj = {
|
||||
method: function() {
|
||||
return () => this;
|
||||
}
|
||||
};
|
||||
|
||||
assert.strictEqual(obj.method()(), obj);
|
||||
2
test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js
vendored
Normal file
2
test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var odds = [0, 2, 4].map(v => v + 1);
|
||||
assert.deepEqual(odds, [1, 3, 5]);
|
||||
2
test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js
vendored
Normal file
2
test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var identity = x => x;
|
||||
assert.equal(identity(1), 1);
|
||||
15
test/fixtures/transformation/esnext-es6-classes/.getter-setter-super.js
vendored
Normal file
15
test/fixtures/transformation/esnext-es6-classes/.getter-setter-super.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
class Animal {
|
||||
get sound() {
|
||||
return 'I am a ' + this.type + '.';
|
||||
}
|
||||
}
|
||||
|
||||
class Cat extends Animal {
|
||||
get type() { return 'cat'; }
|
||||
|
||||
get sound() {
|
||||
return super.sound + ' MEOW!';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Cat().sound, 'I am a cat. MEOW!');
|
||||
21
test/fixtures/transformation/esnext-es6-classes/.super-change-proto.js
vendored
Normal file
21
test/fixtures/transformation/esnext-es6-classes/.super-change-proto.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
var log = '';
|
||||
|
||||
class Base {
|
||||
p() { log += '[Base]'; }
|
||||
}
|
||||
|
||||
class OtherBase {
|
||||
p() { log += '[OtherBase]'; }
|
||||
}
|
||||
|
||||
class Derived extends Base {
|
||||
p() {
|
||||
log += '[Derived]';
|
||||
super();
|
||||
Derived.prototype.__proto__ = OtherBase.prototype;
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
new Derived().p();
|
||||
assert.equal(log, '[Derived][Base][OtherBase]');
|
||||
29
test/fixtures/transformation/esnext-es6-classes/anonymous-class.js
vendored
Normal file
29
test/fixtures/transformation/esnext-es6-classes/anonymous-class.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var Animal = class {
|
||||
sayHi() {
|
||||
return 'Hi, I am a '+this.type()+'.';
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'Animal';
|
||||
}
|
||||
};
|
||||
|
||||
var Dog = class extends Animal {
|
||||
type() { return 'dog'; }
|
||||
|
||||
sayHi() {
|
||||
return super() + ' WOOF!';
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return super() + '/Dog';
|
||||
}
|
||||
};
|
||||
|
||||
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
|
||||
assert.equal(Dog.getName(), 'Animal/Dog');
|
||||
|
||||
var count = 0;
|
||||
var Cat = class extends (function(){ count++; return Animal; })() {};
|
||||
|
||||
assert.equal(count, 1);
|
||||
21
test/fixtures/transformation/esnext-es6-classes/call-super-function.js
vendored
Normal file
21
test/fixtures/transformation/esnext-es6-classes/call-super-function.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
class Animal {
|
||||
sayHi() {
|
||||
return 'I am an animal.'
|
||||
}
|
||||
|
||||
sayOther() {
|
||||
return 'WAT?!';
|
||||
}
|
||||
}
|
||||
|
||||
class Horse extends Animal {
|
||||
sayHi() {
|
||||
return super.sayOther();
|
||||
}
|
||||
|
||||
sayOther() {
|
||||
return 'I see dead objects.';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Horse().sayHi(), 'WAT?!');
|
||||
9
test/fixtures/transformation/esnext-es6-classes/class-expressions.js
vendored
Normal file
9
test/fixtures/transformation/esnext-es6-classes/class-expressions.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var Person = (class Person {});
|
||||
assert.equal(typeof Person, 'function');
|
||||
|
||||
assert.equal(
|
||||
(function(){ return (class Person {}); })().name,
|
||||
'Person'
|
||||
);
|
||||
|
||||
assert.equal(typeof (class {}), 'function');
|
||||
15
test/fixtures/transformation/esnext-es6-classes/class-extend.js
vendored
Normal file
15
test/fixtures/transformation/esnext-es6-classes/class-extend.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
class Animal {
|
||||
sayHi() {
|
||||
return 'Hi, I am a '+this.type()+'.';
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
type() { return 'dog'; }
|
||||
|
||||
sayHi() {
|
||||
return super() + ' WOOF!';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
|
||||
14
test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js
vendored
Normal file
14
test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
class Multiplier {
|
||||
constructor(n=1) {
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
multiply(n=1) {
|
||||
return n * this.n;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Multiplier().n, 1);
|
||||
assert.equal(new Multiplier(6).n, 6);
|
||||
assert.equal(new Multiplier().multiply(), 1);
|
||||
assert.equal(new Multiplier(2).multiply(3), 6);
|
||||
10
test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js
vendored
Normal file
10
test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
class Person {
|
||||
getName() {
|
||||
return this.firstName + ' ' + this.lastName;
|
||||
}
|
||||
}
|
||||
|
||||
var me = new Person();
|
||||
me.firstName = 'Brian';
|
||||
me.lastName = 'Donovan';
|
||||
assert.equal(me.getName(), 'Brian Donovan');
|
||||
5
test/fixtures/transformation/esnext-es6-classes/empty-named-class.js
vendored
Normal file
5
test/fixtures/transformation/esnext-es6-classes/empty-named-class.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
}
|
||||
|
||||
assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor');
|
||||
assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user