Compare commits

...

56 Commits

Author SHA1 Message Date
Sebastian McKenzie
655cc8fcb9 v2.5.0 2015-01-05 00:17:35 +11:00
Sebastian McKenzie
97a504bbef 2.5.0 changelog 2015-01-05 00:16:39 +11:00
Sebastian McKenzie
bf3443962b disable failing esnext tests 2015-01-05 00:15:46 +11:00
Sebastian McKenzie
a4394494ef remove noDuplicateProperties test 2015-01-05 00:15:37 +11:00
Sebastian McKenzie
9a6c13a6a4 Merge branch 'esnext'
Conflicts:
	package.json
2015-01-05 00:03:53 +11:00
Sebastian McKenzie
ac8d77fb45 upgrade acorn-6to5 2015-01-04 21:14:59 +11:00
Sebastian McKenzie
09c88238e1 upgrade acorn-6to5 2015-01-04 20:37:14 +11:00
Sebastian McKenzie
05669204dd fix generation expression comment tests 2015-01-04 20:26:07 +11:00
Sebastian McKenzie
1abef2c1e2 more intelligent parens wrapping of no line terminator expressions - fixes #376, reference #349 2015-01-04 20:22:24 +11:00
Sebastian McKenzie
f16079c83f v2.4.10 2015-01-04 19:51:52 +11:00
Sebastian McKenzie
b7132f3529 upgrade acorn-6to5 2015-01-04 19:50:54 +11:00
Sebastian McKenzie
ed41f1652e v2.4.9 2015-01-04 19:49:54 +11:00
Sebastian McKenzie
c522bdb4b9 upgrade acorn-6to5 2015-01-04 19:48:47 +11:00
Sebastian McKenzie
005362a615 update tests to 2.4.9 fixes 2015-01-04 19:48:14 +11:00
Sebastian McKenzie
88e542634f fix linting errors 2015-01-04 19:45:18 +11:00
Sebastian McKenzie
c8304138eb add 2.4.9 changelog 2015-01-04 19:44:04 +11:00
Sebastian McKenzie
35608d497e make comprehension for-of loop a let 2015-01-04 19:42:25 +11:00
Sebastian McKenzie
b5a78355c4 add initProps to single call expression in computed property names - fixes #378 2015-01-04 19:42:16 +11:00
Sebastian McKenzie
223e28ba8f upgrade acorn-6to5 2015-01-04 19:40:51 +11:00
Sebastian McKenzie
18813f26bb Merge branch 'master' into esnext 2015-01-04 15:32:41 +11:00
Sebastian McKenzie
ccabb91f69 add back deleted object-define-properties-closure template 2015-01-04 15:30:59 +11:00
Sebastian McKenzie
35fda899a8 remove spec-no-duplicate-properties transformer 2015-01-04 15:30:40 +11:00
Sebastian McKenzie
e2f01d41a3 fix api test 2015-01-04 13:42:16 +11:00
Sebastian McKenzie
931a80f5b3 rename "declarations" to the more sane "helpers" 2015-01-04 13:34:56 +11:00
Sebastian McKenzie
9a2fd22e91 add newline to esnext super change proto test 2015-01-04 08:35:28 +11:00
Sebastian McKenzie
cbcad22d81 update default parameters transformer to use var a = arguments[0] === undefined ? 1 : arguments[0]; instead of if (a === undefined) a = 1; 2015-01-04 08:35:14 +11:00
Sebastian McKenzie
4d5861cfdc remove invalid strict-mode es6 next class test 2015-01-04 08:34:25 +11:00
Sebastian McKenzie
c578db7ae8 upgrade acorn-6to5 2015-01-04 08:34:14 +11:00
Sebastian McKenzie
dea73b7186 change code assertion to 6to5 output 2015-01-04 08:01:29 +11:00
Sebastian McKenzie
4506e39cf5 add toString key to instance keys as methods are enumerable 2015-01-04 08:01:08 +11:00
Sebastian McKenzie
7ab6df093b use Symbol.iterator instead of @@iterator 2015-01-04 08:00:49 +11:00
Sebastian McKenzie
22eeae1a93 use assert instead of expect 2015-01-04 08:00:40 +11:00
Sebastian McKenzie
a645ae0583 contextLiteral fallback in es6-spread transformer 2015-01-04 07:59:56 +11:00
Sebastian McKenzie
7f4efecb7d support for CallExpression in Scope.prototype.generateUidBasedOnNode 2015-01-04 07:59:43 +11:00
Sebastian McKenzie
0c0f40d14a only automatically assume test is exec if it has a js extension 2015-01-04 07:58:49 +11:00
Sebastian McKenzie
cb54c11d84 add esnext tests 2015-01-04 07:39:11 +11:00
Sebastian McKenzie
55123be7d7 use t.toComputedKey in computed property name transformer 2015-01-04 07:38:49 +11:00
Sebastian McKenzie
324a0b408a add optional protoToAssign transformer 2015-01-04 07:38:36 +11:00
Sebastian McKenzie
8b2788e930 fix es6-property-method-assignment tests name 2015-01-03 21:48:22 +11:00
Sebastian McKenzie
d945379b5b remove isDynamic checks and always execute those expressions **once** 2015-01-03 21:48:06 +11:00
Sebastian McKenzie
5a622ac9c7 update traversal api in optional-bluebird-coroutines transformer 2015-01-03 20:11:21 +11:00
Sebastian McKenzie
0e9eac610b rename es5-property-methods-assignment to es6-property-method-assignment and add function ids to object methods and remap them if they contain a reference to themselves - fixes #308 2015-01-03 20:11:00 +11:00
Sebastian McKenzie
1de94a2705 fix code styling on es6 arrow functions nested test 2015-01-03 20:09:14 +11:00
Sebastian McKenzie
71132c3538 add types.toComputedPropertyKey helper 2015-01-03 20:08:39 +11:00
Sebastian McKenzie
d20ab0eb05 rename traverse stop method to skip and add a stop method that actually breaks the current traversal 2015-01-03 20:08:31 +11:00
Sebastian McKenzie
51f7e75d2e fix formatting of code of conduct paragraph in CONTRIBUTING.md 2015-01-03 11:17:55 +11:00
Sebastian McKenzie
ab4b5ce994 Merge pull request #309 from antn/add-code-of-conduct
add code of conduct
2015-01-03 11:16:05 +11:00
Sebastian McKenzie
f0d50ca9a2 add browser.js to package.json 2015-01-03 08:19:18 +11:00
Sebastian McKenzie
5168355a64 fix differences copytext grammar 2015-01-03 08:19:11 +11:00
Sebastian McKenzie
2f209a9e4e v2.4.8 2015-01-03 07:37:15 +11:00
Sebastian McKenzie
20695eaba6 add 2.4.8 changelog 2015-01-03 07:36:34 +11:00
Sebastian McKenzie
340a4dd1f2 fix code styling #370 2015-01-03 07:35:45 +11:00
Sebastian McKenzie
ef1c7a5c69 Merge pull request #370 from hughsk/browserify-register
Make require("6to5/register") work with browserify
2015-01-03 07:33:15 +11:00
Hugh Kennedy
5a01beaa1f Make require("6to5/register") work with browserify
Previously, you'd have to create a separate file for using 6to5
with both node and browserify, as the latter wasn't able to properly
handle loading 6to5's dependency tree and would crash on attempting
to do so.

This change instructs browserify to use "register-browser.js" in place
of "register.js". "register-browser.js" still loads the 6to5 polyfill,
but is otherwise ignored.
2015-01-02 21:30:40 +01:00
antn
f4055612e5 add link to code of conduct [ci skip] 2014-12-16 22:29:37 -08:00
antn
46911bd28c add code of conduct 2014-12-16 22:17:35 -08:00
159 changed files with 1510 additions and 353 deletions

View File

@@ -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
View 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/)

View File

@@ -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

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -0,0 +1,4 @@
// Required to safely use 6to5/register within a browserify codebase.
module.exports = function () {};
require("./polyfill");

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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
})])
)

View File

@@ -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);

View File

@@ -0,0 +1 @@
var VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY];

View File

@@ -0,0 +1,8 @@
(function (obj, defaults) {
for (var key in defaults) {
if (obj[key] === undefined) {
obj[key] = defaults[key];
}
}
return obj;
})

View File

@@ -1 +0,0 @@
if (VARIABLE === undefined) VARIABLE = DEFAULT;

View File

@@ -0,0 +1,5 @@
(function (KEY) {
CONTENT;
return KEY;
})(OBJECT);

View File

@@ -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)

View File

@@ -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

View File

@@ -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)
});

View File

@@ -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();
}
});

View File

@@ -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;
};

View File

@@ -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)
});
}
};

View File

@@ -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)
));
}
};

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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();
}
}
});

View File

@@ -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)
});
}
};

View File

@@ -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]);
};

View File

@@ -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)
]));

View File

@@ -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,

View File

@@ -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])
);

View File

@@ -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"));
};

View File

@@ -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";

View File

@@ -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)) {

View File

@@ -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);
}
};

View File

@@ -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

View File

@@ -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);
}))
]);
};

View File

@@ -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

View File

@@ -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);
}
}
};

View File

@@ -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();
}
}
});

View File

@@ -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);
};

View File

@@ -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
*

View File

@@ -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",

View File

@@ -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,

View File

@@ -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
View 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
View File

@@ -0,0 +1,3 @@
require("../../../register")({
ignore: false
});

View File

@@ -3,9 +3,8 @@ var test = {
* Before bracket init
*/
["a"]: "1",
[( /*
* Inside bracket init
*/
"b"
)]: "2"
[/*
* Inside bracket init
*/
"b"]: "2"
}, ok = 42;

View File

@@ -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

View File

@@ -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);
};

View File

@@ -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);
});
});
});
}
};

View File

@@ -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;

View File

@@ -0,0 +1,4 @@
var obj = {
first: "first",
["second"]: "second",
};

View 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");

View File

@@ -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;
};

View File

@@ -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";
};

View File

@@ -1,8 +1,8 @@
var obj = {
get foo() {
return 5 + 5;
return 5 + 5;
},
set foo(value) {
this._foo = value;
this._foo = value;
}
};

View 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);
}
};

View 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);
})
};

View File

@@ -1,7 +1,7 @@
"use strict";
var obj = {
method: function () {
method: function method() {
return 5 + 5;
}
};

View File

@@ -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)));

View File

@@ -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));

View File

@@ -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)));

View File

@@ -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));

View File

@@ -1,2 +1,6 @@
foo::bar();
foo::bar("arg");
var test = "test";
test::bar();
test::bar("arg");

View File

@@ -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");

View File

@@ -1,3 +1,3 @@
delete foo::bar;
if (delete foo::bar);
if (delete foo::bar) {}

View File

@@ -2,4 +2,4 @@
bar[Symbol.referenceDelete](foo);
if ((bar[Symbol.referenceDelete](foo), true)) ;
if ((bar[Symbol.referenceDelete](foo), true)) {}

View File

@@ -1,2 +1,3 @@
var baz = "foo";
foo::bar = baz;
if (foo::bar = baz);
if (foo::bar = baz) {}

View File

@@ -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)) {}

View File

@@ -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);
}
}

View File

@@ -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 });
}
}
}

View File

@@ -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);
}
}

View 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'
);

View File

@@ -0,0 +1,5 @@
var dynamicThisGetter = () => function () { return this; };
assert.equal(
'(' + dynamicThisGetter.toString() + ')',
'(function () {\n return function () {\n return this;\n };\n})'
);

View File

@@ -0,0 +1,2 @@
var empty = () => {};
assert.equal(empty(), undefined);

View 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);

View File

@@ -0,0 +1,2 @@
var square = x => x * x;
assert.equal(square(4), 16);

View File

@@ -0,0 +1,2 @@
var keyMaker = val => ({ key: val });
assert.deepEqual(keyMaker(9), { key: 9 });

View File

@@ -0,0 +1,7 @@
var obj = {
method: function() {
return () => this;
}
};
assert.strictEqual(obj.method()(), obj);

View File

@@ -0,0 +1,2 @@
var odds = [0, 2, 4].map(v => v + 1);
assert.deepEqual(odds, [1, 3, 5]);

View File

@@ -0,0 +1,2 @@
var identity = x => x;
assert.equal(identity(1), 1);

View 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!');

View 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]');

View 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);

View 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?!');

View 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');

View 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!');

View 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);

View 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');

View 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