Compare commits

...

58 Commits

Author SHA1 Message Date
Sebastian McKenzie
b9ad4c2773 v2.12.4 2015-01-16 02:41:23 +11:00
Sebastian McKenzie
228b3dbc34 fix linting errors 2015-01-16 02:38:45 +11:00
Sebastian McKenzie
a01802300f fix default parameters transformer for loops 2015-01-16 02:36:56 +11:00
Sebastian McKenzie
51c6a3fffc fix let scoping body not existing 2015-01-16 02:31:36 +11:00
Sebastian McKenzie
4668e1d67b fix linting errors 2015-01-16 02:29:35 +11:00
Sebastian McKenzie
75e9097e19 add 2.12.4 changelog 2015-01-16 02:29:02 +11:00
Sebastian McKenzie
0627cd94d4 turn array for ins into fors 2015-01-16 02:25:41 +11:00
Sebastian McKenzie
71879d6e8f Merge branch 'master' of github.com:6to5/6to5 2015-01-16 00:50:55 +11:00
Sebastian McKenzie
d7810cac08 add ambiguous rest parameters comment 2015-01-16 00:50:38 +11:00
Sebastian McKenzie
dc9efd21d3 Merge pull request #507 from leebyron/unused
Rm unused dependencies (pass lint)
2015-01-16 00:47:55 +11:00
Lee Byron
347e490614 Rm unused dependencies (pass lint) 2015-01-15 08:47:03 -05:00
Sebastian McKenzie
e512264be7 Merge pull request #506 from leebyron/rest
Improve performance of rest parameter.
2015-01-16 00:43:56 +11:00
Lee Byron
9624663e60 Improve performance of rest parameter.
Rather than initing an empty array and filling, create an array of the correct size up-front. Minor gain on chromium, but considerably (~5x) faster in spidermonkey/firefox.
2015-01-15 08:41:53 -05:00
Sebastian McKenzie
3cf8a6df01 rename replaceInstanceSuperReferences to replaceSuperReferences in classes transformer and add breaks on method definitions 2015-01-15 23:08:28 +11:00
Sebastian McKenzie
88eacecd72 clarify traceur ignore tests 2015-01-15 23:08:06 +11:00
Sebastian McKenzie
fcd3c9ce65 remove register blacklist tests 2015-01-15 23:07:52 +11:00
Sebastian McKenzie
1733bac3bb move chokidar to top 2015-01-15 23:07:46 +11:00
Sebastian McKenzie
21cd063274 Merge pull request #503 from shinnn/output-file-sync
Use output-file-sync instead of mkdirp
2015-01-15 20:32:48 +11:00
Shinnosuke Watanabe
db5750643a use output-file-sync instead of mkdirp
https://github.com/shinnn/output-file-sync
2015-01-15 18:29:40 +09:00
Sebastian McKenzie
60dae7a88d add build comprehension helper 2015-01-15 20:13:24 +11:00
Sebastian McKenzie
790c924b54 abstract out build comprehension helper 2015-01-15 20:13:16 +11:00
Sebastian McKenzie
50d7a46c7f abstract away remap async to generator helper 2015-01-15 20:09:50 +11:00
Sebastian McKenzie
6f7da38957 abstract out named method helper 2015-01-15 20:07:32 +11:00
Sebastian McKenzie
80764c214a add rest parameter comments 2015-01-15 19:52:53 +11:00
Sebastian McKenzie
55054e45da Revert "Improve performance of rest parameter."
This reverts commit e5463cc2a9.
2015-01-15 19:34:33 +11:00
Sebastian McKenzie
060aa5ba0b fix rest parameter check in types.isReferenced 2015-01-15 19:29:54 +11:00
Sebastian McKenzie
688d619bfe add identifier check to class id inheritance 2015-01-15 19:29:54 +11:00
Sebastian McKenzie
6db7fce543 fix computed member expressions in playground memoization 2015-01-15 19:29:54 +11:00
Sebastian McKenzie
41ff1d4ace upgrade acorn-6to5 2015-01-15 19:29:54 +11:00
Sebastian McKenzie
1c6eeba2e9 Merge pull request #499 from leebyron/rest
Improve performance of rest parameter.
2015-01-15 19:28:32 +11:00
Sebastian McKenzie
488b719fde Merge pull request #494 from gaearon/perf-2
Performance impovements
2015-01-15 19:28:04 +11:00
Sebastian McKenzie
af32080287 Merge pull request #498 from leebyron/patch-1
Update CONTRIBUTING.md
2015-01-15 19:27:07 +11:00
Sebastian McKenzie
4c1cd13536 Merge pull request #501 from shinnn/package-json
Update repository info and homepage URL
2015-01-15 14:36:39 +11:00
Dan Abramov
1002cf7796 Avoid Node allocations by making prototype call statics 2015-01-15 04:18:18 +03:00
Shinnosuke Watanabe
081dd33e73 Update repository info and homepage URL
* link to https://6to5.org
* use user/repo style
2015-01-15 10:07:54 +09:00
Sebastian McKenzie
bd9dc4f15d Merge pull request #500 from shinnn/container-based-build
Use container-based infrastructure on Travis CI
2015-01-15 12:01:33 +11:00
Shinnosuke Watanabe
c7ba566ad6 Use container-based infrastructure on Travis CI
http://docs.travis-ci.com/user/workers/container-based-infrastructure/
2015-01-15 09:55:10 +09:00
Dan Abramov
a1b326a0ab Use object lookup instead of array 2015-01-15 03:51:22 +03:00
Dan Abramov
a452f781b8 Slightly refactor and add explanations for optimized functions 2015-01-15 03:39:24 +03:00
Lee Byron
e5463cc2a9 Improve performance of rest parameter.
Rather than initing an empty array and filling, create an array of the correct size up-front. Minor gain on chromium, but considerably (~5x) faster in spidermonkey/firefox.
2015-01-14 19:08:14 -05:00
Lee Byron
7d732ef503 Update CONTRIBUTING.md 2015-01-14 19:01:53 -05:00
Lee Byron
25cb0c6344 Update CONTRIBUTING.md
Explain git init submodules step when checking out
2015-01-14 18:23:49 -05:00
Sebastian McKenzie
45a52bf478 Merge pull request #496 from swirlycheetah/master
Expand upon the contributing guidelines
2015-01-15 09:41:12 +11:00
Chris Wheatley
a14f971b8a add further commands required for workflow 2015-01-14 22:25:20 +00:00
Chris Wheatley
da65500545 expand upon the contributing guidelines 2015-01-14 22:11:46 +00:00
Dan Abramov
58a91ee9e9 Optimize node type lookup 2015-01-14 23:01:58 +03:00
Dan Abramov
19eaa181a5 Speed up common case where consumer moves only forward 2015-01-14 20:02:40 +03:00
Dan Abramov
c7c90acf3f Store ranges instead of line indexes for performance 2015-01-14 19:14:47 +03:00
Dan Abramov
c6f3a55c03 Refactor buffer for clarity and avoid regex for performance 2015-01-14 19:14:47 +03:00
Sebastian McKenzie
e01b7d288f v2.12.3 2015-01-15 02:29:44 +11:00
Sebastian McKenzie
98c0e185b8 add missing semicolon 2015-01-15 02:27:45 +11:00
Sebastian McKenzie
bf66d78210 add 2.12.3 changelog 2015-01-15 02:27:17 +11:00
Sebastian McKenzie
b60eca0a76 better typeof symbol transformer 2015-01-15 02:24:32 +11:00
Sebastian McKenzie
44f06c0b4c instance and static class method names 2015-01-15 02:24:23 +11:00
Sebastian McKenzie
6c5606b7e8 call transformer methods on traverse context 2015-01-15 02:24:05 +11:00
Sebastian McKenzie
07ddfbeb5d remove pointless prototypeProperties helper call 2015-01-15 01:20:06 +11:00
Sebastian McKenzie
87b890c172 fix parentheses deletion not support multilines - fixes #490 2015-01-15 01:14:49 +11:00
Sebastian McKenzie
245fcfe110 move mutator map checking to after loose test 2015-01-15 01:09:13 +11:00
58 changed files with 539 additions and 420 deletions

View File

@@ -1,3 +1,4 @@
sudo: false
language: node_js
node_js:
- "0.10"

View File

@@ -11,6 +11,20 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 2.12.4
* **Polish**
* Rest parameters now allocate the array before populating.
* **Internal**
* `for...in` loops have been changed to optimised `for` loops - better performance and no enumeration of protoype keys.
* Parts of the code generator have now been optimised thanks to [gaearon](https://github.com/gaearon).
## 2.12.3
* **Spec Compliancy**
* Optional `typeof` transformer checks for `undefined` before passing it to the helper.
* Class methods are now named.
## 2.12.2
* **Internal**

View File

@@ -1,6 +1,20 @@
# Contributing
Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
Contributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
## Developing
#### Workflow
* Fork the repository
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/6to5.git && cd 6to5`)
* Install the project dependencies (`make bootstrap`)
* Link your forked clone (`npm link`)
* Develop your changes ensuring you're fetching updates from upstream often
* Ensure the test are passing (`make test`)
* Create new pull request explaining your proposed change or reference an issue in your commit message
#### Code Standards
* **General**
* No ES6 syntax features or methods, exclusively ES5.

View File

@@ -1,9 +1,9 @@
var chokidar = require("chokidar");
var mkdirp = require("mkdirp");
var path = require("path");
var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
var outputFileSync = require("output-file-sync");
var chokidar = require("chokidar");
var path = require("path");
var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
module.exports = function (commander, filenames, opts) {
if (commander.sourceMapsInline) {
@@ -15,16 +15,13 @@ module.exports = function (commander, filenames, opts) {
var data = util.compile(src, { sourceMapName: dest });
var up = path.normalize(dest + "/..");
mkdirp.sync(up);
if (commander.sourceMaps) {
var mapLoc = dest + ".map";
data.code = util.addSourceMappingUrl(data.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(data.map));
outputFileSync(mapLoc, JSON.stringify(data.map));
}
fs.writeFileSync(dest, data.code);
outputFileSync(dest, data.code);
console.log(src + " -> " + dest);
};

View File

@@ -96,8 +96,8 @@ function replEval(code, context, filename, callback) {
var result;
try {
if (/^\((.*?)\n\)$/.test(code)) {
code = code.slice(1, -2); // remove "(" and "\n)"
if (code[0] === "(" && code[code.length - 1] === ")") {
code = code.slice(1, -1); // remove "(" and ")"
}
result = _eval(code, filename);

View File

@@ -67,32 +67,57 @@ Buffer.prototype.removeLast = function (cha) {
Buffer.prototype.newline = function (i, removeLast) {
if (this.format.compact) return;
if (_.isBoolean(i)) {
removeLast = i;
i = null;
}
removeLast = removeLast || false;
if (_.isNumber(i)) {
if (this.endsWith("{\n")) i--;
if (this.endsWith(util.repeat(i, "\n"))) return;
for (var j = 0; j < i; j++) {
this.newline(null, removeLast);
while (i--) {
this._newline(removeLast);
}
return;
}
if (_.isBoolean(i)) {
removeLast = i;
}
this._newline(removeLast);
};
Buffer.prototype._newline = function (removeLast) {
if (removeLast && this.isLast("\n")) this.removeLast("\n");
this.removeLast(" ");
// remove whitespace if last character was a newline
this.buf = this.buf.replace(/\n +$/, "\n");
this._removeSpacesAfterLastNewline();
this._push("\n");
};
/**
* If buffer ends with a newline and some spaces after it, trim those spaces.
*/
Buffer.prototype._removeSpacesAfterLastNewline = function () {
var lastNewlineIndex = this.buf.lastIndexOf('\n');
if (lastNewlineIndex === -1)
return;
var index = this.buf.length - 1;
while (index > lastNewlineIndex) {
if (this.buf[index] !== ' ') {
break;
}
index--;
}
if (index === lastNewlineIndex) {
this.buf = this.buf.substring(0, index + 1);
}
};
Buffer.prototype.push = function (str, noIndent) {
if (this._indent && !noIndent && str !== "\n") {
// we have an indent level and we aren't pushing a newline

View File

@@ -169,7 +169,7 @@ exports.VariableDeclaration = function (node, print, parent) {
var inits = 0;
var noInits = 0;
for (var i in node.declarations) {
for (var i = 0; i < node.declarations.length; i++) {
if (node.declarations[i].init) {
inits++;
} else {

View File

@@ -13,7 +13,7 @@ var find = function (obj, node, parent) {
for (var i = 0; i < types.length; i++) {
var type = types[i];
if (t["is" + type](node)) {
if (t.is(type, node)) {
var fn = obj[type];
result = fn(node, parent);
if (result != null) break;
@@ -28,13 +28,11 @@ function Node(node, parent) {
this.node = node;
}
Node.prototype.isUserWhitespacable = function () {
return t.isUserWhitespacable(this.node);
Node.isUserWhitespacable = function (node) {
return t.isUserWhitespacable(node);
};
Node.prototype.needsWhitespace = function (type) {
var parent = this.parent;
var node = this.node;
Node.needsWhitespace = function (node, parent, type) {
if (!node) return 0;
if (t.isExpressionStatement(node)) {
@@ -51,18 +49,15 @@ Node.prototype.needsWhitespace = function (type) {
return lines || 0;
};
Node.prototype.needsWhitespaceBefore = function () {
return this.needsWhitespace("before");
Node.needsWhitespaceBefore = function (node, parent) {
return Node.needsWhitespace(node, parent, "before");
};
Node.prototype.needsWhitespaceAfter = function () {
return this.needsWhitespace("after");
Node.needsWhitespaceAfter = function (node, parent) {
return Node.needsWhitespace(node, parent, "after");
};
Node.prototype.needsParens = function () {
var parent = this.parent;
var node = this.node;
Node.needsParens = function (node, parent) {
if (!parent) return false;
if (t.isNewExpression(parent) && parent.callee === node) {
@@ -77,10 +72,7 @@ Node.prototype.needsParens = function () {
return find(parens, node, parent);
};
Node.prototype.needsParensNoLineTerminator = function () {
var parent = this.parent;
var node = this.node;
Node.needsParensNoLineTerminator = function (node, parent) {
if (!parent) return false;
// no comments
@@ -100,17 +92,18 @@ Node.prototype.needsParensNoLineTerminator = function () {
return false;
};
_.each(Node.prototype, function (fn, key) {
Node[key] = function (node, parent) {
var n = new Node(node, parent);
_.each(Node, function (fn, key) {
Node.prototype[key] = function () {
// Avoid leaking arguments to prevent deoptimization
var skipCount = 2;
var args = new Array(arguments.length - skipCount);
var args = new Array(arguments.length + 2);
args[0] = this.node;
args[1] = this.parent;
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 2];
args[i + 2] = arguments[i];
}
return n[key].apply(n, args);
return Node[key].apply(null, args);
};
});

View File

@@ -1,10 +1,38 @@
module.exports = Whitespace;
var _ = require("lodash");
var _ = require("lodash");
/**
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
* Useful for shifting `for` loop by a fixed number but going over all items.
*
* @param {Number} i Current index in the loop
* @param {Number} base Start index for which to return 0
* @param {Number} max Array length
* @returns {Number} shiftedIndex
*/
function getLookupIndex(i, base, max) {
i += base;
if (i >= max)
i -= max;
return i;
}
function Whitespace(tokens, comments) {
this.tokens = _.sortBy(tokens.concat(comments), "start");
this.used = [];
this.used = {};
// Profiling this code shows that while generator passes over it, indexes
// returned by `getNewlinesBefore` and `getNewlinesAfter` are always increasing.
// We use this implementation detail for an optimization: instead of always
// starting to look from `this.tokens[0]`, we will start `for` loops from the
// previous successful match. We will enumerate all tokens—but the common
// case will be much faster.
this._lastFoundIndex = 0;
}
Whitespace.prototype.getNewlinesBefore = function (node) {
@@ -13,13 +41,17 @@ Whitespace.prototype.getNewlinesBefore = function (node) {
var tokens = this.tokens;
var token;
for (var i = 0; i < tokens.length; i++) {
for (var j = 0; j < tokens.length; j++) {
// optimize for forward traversal by shifting for loop index
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
token = tokens[i];
// this is the token this node starts with
if (node.start === token.start) {
startToken = tokens[i - 1];
endToken = token;
this._lastFoundIndex = i;
break;
}
}
@@ -33,13 +65,17 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
var tokens = this.tokens;
var token;
for (var i = 0; i < tokens.length; i++) {
for (var j = 0; j < tokens.length; j++) {
// optimize for forward traversal by shifting for loop index
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
token = tokens[i];
// this is the token this node ends with
if (node.end === token.end) {
startToken = token;
endToken = tokens[i + 1];
this._lastFoundIndex = i;
break;
}
}
@@ -60,15 +96,14 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
var start = startToken ? startToken.loc.end.line : 1;
var end = endToken.loc.start.line;
var lines = 0;
for (var line = start; line < end; line++) {
if (!_.contains(this.used, line)) {
this.used.push(line);
if (typeof this.used[line] === 'undefined') {
this.used[line] = true;
lines++;
}
}
return lines;
};
};

View File

@@ -21,51 +21,6 @@ sourceMapSupport.install({
}
});
//
var blacklist = [];
var blacklistTest = function (transformer, code) {
try {
if (_.isFunction(code)) {
code();
} else {
new Function(code);
}
blacklist.push(transformer);
} catch (err) {
if (err.name !== "SyntaxError") throw err;
}
};
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
blacklistTest("arrowFunctions", "var foo = x => x * x;");
blacklistTest("classes", "class Foo {}");
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
blacklistTest("constants", function () {
try {
new Function("const foo = 'foo';\nfoo = 'wow';");
} catch (err) {
return; // constants are supported
}
throw new SyntaxError;
});
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
blacklistTest("forOf", "for (var foo of bar) {}");
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
blacklistTest("letScoping", "let foo = 0;");
blacklistTest("modules", 'import foo from "from";');
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
blacklistTest("propertyNameShorthand", "var foo = { x, y };");
blacklistTest("restParameters", "function foo(...bar) {}");
blacklistTest("spread", "foo(...bar);");
blacklistTest("templateLiterals", "var foo = `foo`;");
blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
//
var transformOpts = {};
var ignoreRegex = /node_modules/;
var onlyRegex;
@@ -95,7 +50,6 @@ var loader = function (m, filename) {
result = result || to5.transformFileSync(filename, _.extend({
whitelist: whitelist,
blacklist: blacklist,
sourceMap: true,
ast: false
}, transformOpts));

View File

@@ -0,0 +1,23 @@
var t = require("../../types");
module.exports = function build(node, buildBody) {
var self = node.blocks.shift();
if (!self) return;
var child = build(node, buildBody);
if (!child) {
// last item
child = buildBody();
// add a filter as this is our final stop
if (node.filter) {
child = t.ifStatement(node.filter, t.blockStatement([child]));
}
}
return t.forOfStatement(
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
self.right,
t.blockStatement([child])
);
};

View File

@@ -0,0 +1,43 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
module.exports = function (node, file, scope) {
var key = t.toComputedKey(node, node.key);
if (!t.isLiteral(key)) return node; // 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;
}
};

View File

@@ -0,0 +1,29 @@
var traverse = require("../../traverse");
var t = require("../../types");
module.exports = function (node, callId) {
node.async = false;
node.generator = true;
traverse(node, {
enter: function (node) {
if (t.isFunction(node)) this.skip();
if (t.isAwaitExpression(node)) {
node.type = "YieldExpression";
}
}
});
var call = t.callExpression(callId, [node]);
if (t.isFunctionDeclaration(node)) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(node.id, call)
]);
declar._blockHoist = true;
return declar;
} else {
return call;
}
};

View File

@@ -0,0 +1,19 @@
var t = require("../../types");
exports.has = function (node) {
var first = node.body[0];
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
};
exports.wrap = function (node, callback) {
var useStrictNode;
if (exports.has(node)) {
useStrictNode = node.body.shift();
}
callback();
if (useStrictNode) {
node.body.unshift(useStrictNode);
}
};

View File

@@ -244,13 +244,13 @@ DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
var assign;
if (t.isVariableDeclaration(declar)) {
for (var i in declar.declarations) {
for (var i = 0; i < declar.declarations.length; i++) {
var decl = declar.declarations[i];
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
if (i === "0") t.inherits(newDeclar, declar);
if (i === 0) t.inherits(newDeclar, declar);
nodes.push(newDeclar);
}
} else {

View File

@@ -1,7 +1,7 @@
module.exports = SystemFormatter;
var AMDFormatter = require("./amd");
var useStrict = require("../transformers/use-strict");
var useStrict = require("../helpers/use-strict");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
@@ -171,7 +171,7 @@ SystemFormatter.prototype.transform = function (ast) {
handlerBody.push(returnStatement);
if (useStrict._has(block)) {
if (useStrict.has(block)) {
handlerBody.unshift(block.body.shift());
}

View File

@@ -1,3 +1,3 @@
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
for (var LEN = ARGUMENTS.length, ARRAY = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
}

View File

@@ -20,7 +20,7 @@ transform.fromAst = function (ast, code, opts) {
};
transform._ensureTransformerNames = function (type, keys) {
for (var i in keys) {
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!_.has(transform.transformers, key)) {
throw new ReferenceError("unknown transformer " + key + " specified in " + type);

View File

@@ -65,7 +65,7 @@ Transformer.prototype.transform = function (file) {
if (exit) fn = fns.exit;
if (!fn) return;
return fn(node, parent, file, scope);
return fn.call(this, node, parent, file, scope);
};
};

View File

@@ -1,4 +1,4 @@
var useStrict = require("./use-strict");
var useStrict = require("../helpers/use-strict");
var _ = require("lodash");
// Priority:
@@ -12,13 +12,13 @@ exports.BlockStatement =
exports.Program = {
exit: function (node) {
var hasChange = false;
for (var i in node.body) {
for (var i = 0; i < node.body.length; i++) {
var bodyNode = node.body[i];
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
}
if (!hasChange) return;
useStrict._wrap(node, function () {
useStrict.wrap(node, function () {
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
var priority = bodyNode._blockHoist;
if (priority == null) priority = 1;

View File

@@ -1,14 +1,16 @@
var useStrict = require("./use-strict");
var useStrict = require("../helpers/use-strict");
var t = require("../../types");
exports.secondPass = true;
exports.BlockStatement =
exports.Program = function (node) {
if (!node._declarations) return;
var kinds = {};
var kind;
useStrict._wrap(node, function () {
useStrict.wrap(node, function () {
for (var i in node._declarations) {
var declar = node._declarations[i];

View File

@@ -1,12 +1,25 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var nameMethod = require("../helpers/name-method");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
exports.ClassDeclaration = function (node, parent, file, scope) {
return new Class(node, file, scope, true).run();
};
exports.ClassExpression = function (node, parent, file, scope) {
if (!node.id) {
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
// var o = { foo: class {} };
node.id = parent.key;
}
if (t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)) {
// var foo = class {};
node.id = parent.id;
}
}
return new Class(node, file, scope, false).run();
};
@@ -119,10 +132,10 @@ Class.prototype.buildBody = function () {
var classBody = this.node.body.body;
var body = this.body;
for (var i in classBody) {
for (var i = 0; i < classBody.length; i++) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
this.replaceInstanceSuperReferences(node);
this.replaceSuperReferences(node);
if (node.key.name === "constructor") {
this.pushConstructor(node);
@@ -179,15 +192,10 @@ Class.prototype.pushMethod = function (node) {
var methodName = node.key;
var kind = node.kind;
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
if (kind === "") {
nameMethod(node, this.file, this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes
@@ -204,6 +212,14 @@ Class.prototype.pushMethod = function (node) {
kind = "value";
}
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node);
};
@@ -284,7 +300,7 @@ Class.prototype.looseSuperProperty = function (methodNode, id, parent) {
* @param {Node} methodNode MethodDefinition
*/
Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
Class.prototype.replaceSuperReferences = function (methodNode) {
var method = methodNode.value;
var self = this;
@@ -307,6 +323,11 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
return this.skip();
}
if (t.isProperty(node, { method: true }) || t.isMethodDefinition(node)) {
// break on object methods
return this.skip();
}
var getThisReference = function () {
if (topLevel) {
// top level so `this` is the instance

View File

@@ -3,7 +3,7 @@ var t = require("../../types");
exports.ObjectExpression = function (node, parent, file, scope) {
var hasComputed = false;
for (var i in node.properties) {
for (var i = 0; i < node.properties.length; i++) {
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
if (hasComputed) break;
}
@@ -39,7 +39,7 @@ exports.ObjectExpression = function (node, parent, file, scope) {
};
var loose = function (node, body, objId) {
for (var i in node.properties) {
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
body.push(t.expressionStatement(
@@ -58,7 +58,7 @@ var spec = function (node, body, objId, initProps, file) {
// normalise key
for (var i in props) {
for (var i = 0; i < props.length; i++) {
prop = props[i];
if (prop.kind !== "init") continue;
@@ -73,7 +73,7 @@ var spec = function (node, body, objId, initProps, file) {
var broken = false;
for (i in props) {
for (i = 0; i < props.length; i++) {
prop = props[i];
if (prop.computed) {
@@ -89,7 +89,7 @@ var spec = function (node, body, objId, initProps, file) {
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
// otherwise use Object.defineProperty
for (i in props) {
for (i = 0; i < props.length; i++) {
prop = props[i];
if (!prop) continue;

View File

@@ -44,7 +44,7 @@ exports.ForStatement = function (node, parent, file) {
}
if (t.isVariableDeclaration(child, { kind: "const" })) {
for (var i in child.declarations) {
for (var i = 0; i < child.declarations.length; i++) {
var declar = child.declarations[i];
var ids = getIds(declar);

View File

@@ -11,7 +11,6 @@ exports.Function = function (node, parent, file, scope) {
});
var iife = false;
var i;
var def;
var checkTDZ = function (ids) {
@@ -31,7 +30,7 @@ exports.Function = function (node, parent, file, scope) {
traverse(def, { enter: check });
};
for (i in node.defaults) {
for (var i = 0; i < node.defaults.length; i++) {
def = node.defaults[i];
if (!def) continue;
@@ -40,8 +39,8 @@ exports.Function = function (node, parent, file, scope) {
// temporal dead zone check - here we prevent accessing of params that
// are to the right - ie. uninitialized parameters
var rightIds = ids.slice(i);
for (i in rightIds) {
checkTDZ(rightIds[i]);
for (var i2 = 0; i2 < rightIds.length; i2++) {
checkTDZ(rightIds[i2]);
}
// we're accessing a variable that's already defined within this function
@@ -58,7 +57,7 @@ exports.Function = function (node, parent, file, scope) {
var lastNonDefaultParam = 0;
for (i in node.defaults) {
for (i = 0; i < node.defaults.length; i++) {
def = node.defaults[i];
if (!def) {
lastNonDefaultParam = +i + 1;

View File

@@ -46,12 +46,12 @@ var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
};
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
for (var i in pattern.properties) {
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i2 in pattern.properties) {
for (var i2 = 0; i2 < pattern.properties.length; i2++) {
var prop2 = pattern.properties[i2];
if (i2 >= i) break;
@@ -88,7 +88,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var i;
var hasSpreadElement = false;
for (i in pattern.elements) {
for (i = 0; i < pattern.elements.length; i++) {
if (t.isSpreadElement(pattern.elements[i])) {
hasSpreadElement = true;
break;
@@ -103,7 +103,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
]));
parentId = _parentId;
for (i in pattern.elements) {
for (i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
if (!elem) continue;
@@ -278,7 +278,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
var declar;
var hasPattern = false;
for (i in node.declarations) {
for (i = 0; i < node.declarations.length; i++) {
declar = node.declarations[i];
if (t.isPattern(declar.id)) {
hasPattern = true;
@@ -287,7 +287,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
}
if (!hasPattern) return;
for (i in node.declarations) {
for (i = 0; i < node.declarations.length; i++) {
declar = node.declarations[i];
var patternId = declar.init;
@@ -317,7 +317,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
declar = null;
for (i in nodes) {
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
declar = declar || t.variableDeclaration(node.kind, []);

View File

@@ -25,7 +25,7 @@ var isVar = function (node, parent) {
};
var standardiseLets = function (declars) {
for (var i in declars) {
for (var i = 0; i < declars.length; i++) {
delete declars[i]._let;
}
};
@@ -231,10 +231,9 @@ LetScoping.prototype.getInfo = function () {
}
};
var i;
var declar;
for (i in opts.declarators) {
for (var i in opts.declarators) {
declar = opts.declarators[i];
opts.declarators.push(declar);
@@ -246,14 +245,16 @@ LetScoping.prototype.getInfo = function () {
opts.keys = opts.keys.concat(keys);
}
for (i in block.body) {
declar = block.body[i];
if (!isLet(declar, block)) continue;
if (block.body) {
for (i = 0; i < block.body.length; i++) {
declar = block.body[i];
if (!isLet(declar, block)) continue;
var declars = t.getIds(declar, true);
for (var key in declars) {
duplicates(declars[key], key);
opts.keys.push(key);
var declars = t.getIds(declar, true);
for (var key in declars) {
duplicates(declars[key], key);
opts.keys.push(key);
}
}
}
@@ -412,7 +413,7 @@ LetScoping.prototype.pushDeclar = function (node) {
var replace = [];
for (var i in node.declarations) {
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
if (!declar.init) continue;

View File

@@ -10,7 +10,7 @@ exports.ImportDeclaration = function (node, parent, file) {
var nodes = [];
if (node.specifiers.length) {
for (var i in node.specifiers) {
for (var i = 0; i < node.specifiers.length; i++) {
file.moduleFormatter.importSpecifier(node.specifiers[i], node, nodes, parent);
}
} else {
@@ -39,7 +39,7 @@ exports.ExportDeclaration = function (node, parent, file) {
file.moduleFormatter.exportDeclaration(node, nodes, parent);
} else {
for (var i in node.specifiers) {
for (var i = 0; i < node.specifiers.length; i++) {
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
}
}

View File

@@ -1,49 +1,13 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var nameMethod = require("../helpers/name-method");
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;
}
nameMethod(node, file, scope);
};
exports.ObjectExpression = function (node) {

View File

@@ -10,27 +10,42 @@ exports.Function = function (node, parent, file) {
t.ensureBlock(node);
var argsId = t.identifier("arguments");
// otherwise `arguments` will be remapped in arrow functions
argsId._ignoreAliasFunctions = true;
var start = t.literal(node.params.length);
var key = file.generateUidIdentifier("key");
var len = file.generateUidIdentifier("len");
var arrKey = key;
var arrLen = len;
if (node.params.length) {
arrKey = t.binaryExpression("-", arrKey, start);
// this method has additional params, so we need to subtract
// the index of the current argument position from the
// position in the array that we want to populate
arrKey = t.binaryExpression("-", key, start);
// we need to work out the size of the array that we're
// going to store all the rest parameters in, if there
// are less arguments than params then the array can be
// constructed with <1 which will cause an error
arrLen = t.conditionalExpression(
t.binaryExpression(">", len, start),
t.binaryExpression("-", len, start),
t.literal(0)
);
}
node.body.body.unshift(
t.variableDeclaration("var", [
t.variableDeclarator(rest, t.arrayExpression([]))
]),
util.template("rest", {
ARGUMENTS: argsId,
ARRAY_KEY: arrKey,
ARRAY_LEN: arrLen,
START: start,
ARRAY: rest,
KEY: key
KEY: key,
LEN: len,
})
);
};

View File

@@ -6,7 +6,7 @@ var getSpreadLiteral = function (spread, file) {
};
var hasSpread = function (nodes) {
for (var i in nodes) {
for (var i = 0; i < nodes.length; i++) {
if (t.isSpreadElement(nodes[i])) {
return true;
}
@@ -25,7 +25,7 @@ var build = function (props, file) {
_props = [];
};
for (var i in props) {
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (t.isSpreadElement(prop)) {
push();

View File

@@ -11,7 +11,7 @@ exports.TaggedTemplateExpression = function (node, parent, file) {
var strings = [];
var raw = [];
for (var i in quasi.quasis) {
for (var i = 0; i < quasi.quasis.length; i++) {
var elem = quasi.quasis[i];
strings.push(t.literal(elem.value.cooked));
raw.push(t.literal(elem.value.raw));
@@ -33,7 +33,7 @@ exports.TemplateLiteral = function (node) {
var nodes = [];
var i;
for (i in node.quasis) {
for (i = 0; i < node.quasis.length; i++) {
var elem = node.quasis[i];
nodes.push(t.literal(elem.value.cooked));
@@ -49,7 +49,7 @@ exports.TemplateLiteral = function (node) {
var root = buildBinaryExpression(nodes.shift(), nodes.shift());
for (i in nodes) {
for (i = 0; i < nodes.length; i++) {
root = buildBinaryExpression(root, nodes[i]);
}

View File

@@ -1,6 +1,7 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var buildComprehension = require("../helpers/build-comprehension");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
exports.experimental = true;
@@ -22,7 +23,7 @@ var build = function (node, parent, file, scope) {
var returnStatement = body.pop();
body.push(exports._build(node, function () {
body.push(buildComprehension(node, function () {
return util.template("array-push", {
STATEMENT: node.body,
KEY: uid
@@ -33,28 +34,6 @@ var build = function (node, parent, file, scope) {
return container;
};
exports._build = function (node, buildBody) {
var self = node.blocks.shift();
if (!self) return;
var child = exports._build(node, buildBody);
if (!child) {
// last item
child = buildBody();
// add a filter as this is our final stop
if (node.filter) {
child = t.ifStatement(node.filter, t.blockStatement([child]));
}
}
return t.forOfStatement(
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
self.right,
t.blockStatement([child])
);
};
exports.ComprehensionExpression = function (node, parent, file, scope) {
if (node.generator) return;

View File

@@ -1,4 +1,4 @@
var arrayComprehension = require("./es7-array-comprehension");
var buildComprehension = require("../helpers/build-comprehension");
var t = require("../../types");
exports.experimental = true;
@@ -10,7 +10,7 @@ exports.ComprehensionExpression = function (node) {
var container = t.functionExpression(null, [], t.blockStatement(body), true);
container._aliasFunction = true;
body.push(arrayComprehension._build(node, function () {
body.push(buildComprehension(node, function () {
return t.expressionStatement(t.yieldExpression(node.body));
}));

View File

@@ -8,7 +8,7 @@ exports.ObjectExpression = function (node, parent, file) {
var hasSpread = false;
var i;
var prop;
for (i in node.properties) {
for (i = 0; i < node.properties.length; i++) {
prop = node.properties[i];
if (t.isSpreadProperty(prop)) {
hasSpread = true;
@@ -26,7 +26,7 @@ exports.ObjectExpression = function (node, parent, file) {
props = [];
};
for (i in node.properties) {
for (i = 0; i < node.properties.length; i++) {
prop = node.properties[i];
if (t.isSpreadProperty(prop)) {
push();

View File

@@ -1,4 +1,5 @@
var bluebirdCoroutines = require("./optional-bluebird-coroutines");
var remapAsyncToGenerator = require("../helpers/remap-async-to-generator");
var bluebirdCoroutines = require("./optional-bluebird-coroutines");
exports.optional = true;
@@ -7,5 +8,5 @@ exports.manipulateOptions = bluebirdCoroutines.manipulateOptions;
exports.Function = function (node, parent, file) {
if (!node.async || node.generator) return;
return bluebirdCoroutines._Function(node, file.addHelper("async-to-generator"));
return remapAsyncToGenerator(node, file.addHelper("async-to-generator"));
};

View File

@@ -1,5 +1,5 @@
var traverse = require("../../traverse");
var t = require("../../types");
var remapAsyncToGenerator = require("../helpers/remap-async-to-generator");
var t = require("../../types");
exports.manipulateOptions = function (opts) {
opts.experimental = true;
@@ -8,36 +8,12 @@ exports.manipulateOptions = function (opts) {
exports.optional = true;
exports._Function = function (node, callId) {
node.async = false;
node.generator = true;
traverse(node, {
enter: function (node) {
if (t.isFunction(node)) this.skip();
if (t.isAwaitExpression(node)) {
node.type = "YieldExpression";
}
}
});
var call = t.callExpression(callId, [node]);
if (t.isFunctionDeclaration(node)) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(node.id, call)
]);
declar._blockHoist = true;
return declar;
} else {
return call;
}
};
exports.Function = function (node, parent, file) {
if (!node.async || node.generator) return;
var id = file.addImport("bluebird");
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
return remapAsyncToGenerator(
node,
t.memberExpression(file.addImport("bluebird"), t.identifier("coroutine"))
);
};

View File

@@ -44,7 +44,7 @@ exports.ExpressionStatement = function (node, parent, file) {
exports.ObjectExpression = function (node, parent, file) {
var proto;
for (var i in node.properties) {
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
if (isProtoKey(prop)) {

View File

@@ -3,7 +3,19 @@ var t = require("../../types");
exports.optional = true;
exports.UnaryExpression = function (node, parent, file) {
this.skip();
if (node.operator === "typeof") {
return t.callExpression(file.addHelper("typeof"), [node.argument]);
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
if (t.isIdentifier(node.argument)) {
var undefLiteral = t.literal("undefined");
return t.conditionalExpression(
t.binaryExpression("===", t.unaryExpression("typeof", node.argument), undefLiteral),
undefLiteral,
call
);
} else {
return call;
}
}
};

View File

@@ -6,9 +6,11 @@ var isMemo = function (node) {
return is;
};
var getPropRef = function (nodes, prop, file, scope) {
if (t.isIdentifier(prop)) {
return t.literal(prop.name);
var getPropRef = function (nodes, member, file, scope) {
var prop = member.property;
var key = t.toComputedKey(member, member.property);
if (t.isLiteral(key)) {
return key;
} else {
var temp = scope.generateUidBasedOnNode(prop, file);
nodes.push(t.variableDeclaration("var", [
@@ -54,7 +56,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
var left = expr.left;
var obj = getObjRef(nodes, left.object, file, scope);
var prop = getPropRef(nodes, left.property, file, scope);
var prop = getPropRef(nodes, left, file, scope);
nodes.push(t.ifStatement(
buildHasOwn(obj, prop, file),
@@ -72,7 +74,7 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
var left = node.left;
var obj = getObjRef(nodes, left.object, file, scope);
var prop = getPropRef(nodes, left.property, file, scope);
var prop = getPropRef(nodes, left, file, scope);
nodes.push(t.logicalExpression(
"&&",

View File

@@ -134,19 +134,18 @@ exports.XJSOpeningElement = {
exports.XJSElement = {
exit: function (node) {
var callExpr = node.openingElement;
var i;
for (i in node.children) {
for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
if (t.isLiteral(child) && _.isString(child.value)) {
var lines = child.value.split(/\r\n|\n|\r/);
for (i in lines) {
var line = lines[i];
for (var i2 = 0; i2 < lines.length; i2++) {
var line = lines[i2];
var isFirstLine = i === "0";
var isLastLine = +i === lines.length - 1;
var isFirstLine = i2 === 0;
var isLastLine = i2 === lines.length - 1;
// replace rendered whitespace tabs with spaces
var trimmedLine = line.replace(/\t/g, " ");
@@ -209,7 +208,7 @@ var addDisplayName = function (id, call) {
var props = first.properties;
var safe = true;
for (var i in props) {
for (var i = 0; i < props.length; i++) {
prop = props[i];
if (t.isIdentifier(prop.key, { name: "displayName" })) {
safe = false;

View File

@@ -1,26 +1,9 @@
var t = require("../../types");
exports._has = function (node) {
var first = node.body[0];
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
};
exports._wrap = function (node, callback) {
var useStrictNode;
if (exports._has(node)) {
useStrictNode = node.body.shift();
}
callback();
if (useStrictNode) {
node.body.unshift(useStrictNode);
}
};
var useStrict = require("../helpers/use-strict");
var t = require("../../types");
exports.ast = {
exit: function (ast) {
if (!exports._has(ast.program)) {
if (!useStrict.has(ast.program)) {
ast.program.body.unshift(t.expressionStatement(t.literal("use strict")));
}
}

View File

@@ -7,14 +7,25 @@ t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array",
//
var addAssert = function (type, is) {
/**
* Registers `is[Type]` and `assert[Type]` generated functions for a given `type`.
* Pass `skipAliasCheck` to force it to directly compare `node.type` with `type`.
*
* @param {String} type
* @param {Boolean?} skipAliasCheck
*/
function registerType(type, skipAliasCheck) {
var is = t["is" + type] = function (node, opts) {
return t.is(type, node, opts, skipAliasCheck);
};
t["assert" + type] = function (node, opts) {
opts = opts || {};
if (!is(node, opts)) {
throw new Error("Expected type " + JSON.stringify(type) + " with option " + JSON.stringify(opts));
}
};
};
}
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
@@ -22,14 +33,59 @@ t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
t.VISITOR_KEYS = require("./visitor-keys");
_.each(t.VISITOR_KEYS, function (keys, type) {
var is = t["is" + type] = function (node, opts) {
return node && node.type === type && t.shallowEqual(node, opts);
};
t.ALIAS_KEYS = require("./alias-keys");
addAssert(type, is);
t.FLIPPED_ALIAS_KEYS = {};
_.each(t.VISITOR_KEYS, function (keys, type) {
registerType(type, true);
});
_.each(t.ALIAS_KEYS, function (aliases, type) {
_.each(aliases, function (alias) {
var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || [];
types.push(type);
});
});
_.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
t[type.toUpperCase() + "_TYPES"] = types;
registerType(type, false);
});
/**
* Returns whether `node` is of given `type`.
* For better performance, use this instead of `is[Type]` when `type` is unknown.
* Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`.
*
* @param {String} type
* @param {Node} node
* @param {Object?} opts
* @param {Boolean?} skipAliasCheck
* @returns {Boolean} isOfType
*/
t.is = function (type, node, opts, skipAliasCheck) {
if (!node) return;
var typeMatches = (type === node.type);
if (!typeMatches && !skipAliasCheck) {
var aliases = t.FLIPPED_ALIAS_KEYS[type];
if (typeof aliases !== 'undefined')
typeMatches = aliases.indexOf(node.type) > -1;
}
if (!typeMatches) {
return false;
}
if (typeof opts !== 'undefined')
return t.shallowEqual(node, opts);
return true;
};
//
t.BUILDER_KEYS = _.defaults(require("./builder-keys"), t.VISITOR_KEYS);
@@ -45,29 +101,6 @@ _.each(t.BUILDER_KEYS, function (keys, type) {
};
});
//
t.ALIAS_KEYS = require("./alias-keys");
t.FLIPPED_ALIAS_KEYS = {};
_.each(t.ALIAS_KEYS, function (aliases, type) {
_.each(aliases, function (alias) {
var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || [];
types.push(type);
});
});
_.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
t[type.toUpperCase() + "_TYPES"] = types;
var is = t["is" + type] = function (node, opts) {
return node && types.indexOf(node.type) >= 0 && t.shallowEqual(node, opts);
};
addAssert(type, is);
});
/**
* Description
*
@@ -139,17 +172,17 @@ t.toSequenceExpression = function (nodes, scope) {
//
t.shallowEqual = function (actual, expected) {
var same = true;
var keys = Object.keys(expected);
var key;
if (expected) {
_.each(expected, function (val, key) {
if (actual[key] !== val) {
return same = false;
}
});
for (var i = 0; i < keys.length; i++) {
key = keys[i];
if (actual[key] !== expected[key])
return false;
}
return same;
return true;
};
/**
@@ -198,7 +231,11 @@ t.isReferenced = function (node, parent) {
if (_.contains(parent.params, node)) return false;
// we're a rest parameter
if (_.contains(parent.params, node)) return false;
if (parent.rest === node) return false;
}
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
return false;
}
// we're a catch clause param
@@ -403,7 +440,7 @@ t.getIds = function (node, map, ignoreTypes) {
if (t.isIdentifier(id)) {
ids[id.name] = id;
} else if (nodeKeys) {
for (i in nodeKeys) {
for (i = 0; i < nodeKeys.length; i++) {
key = nodeKeys[i];
if (id[key]) {
search.push(id[key]);
@@ -411,7 +448,7 @@ t.getIds = function (node, map, ignoreTypes) {
}
}
} else if (arrKeys) {
for (i in arrKeys) {
for (i = 0; i < arrKeys.length; i++) {
key = arrKeys[i];
search = search.concat(id[key] || []);
}

View File

@@ -1,16 +1,10 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.12.2",
"version": "2.12.4",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
"type": "git",
"url": "https://github.com/6to5/6to5.git"
},
"bugs": {
"url": "https://github.com/6to5/6to5/issues"
},
"homepage": "https://6to5.org/",
"repository": "6to5/6to5",
"preferGlobal": true,
"main": "lib/6to5/index.js",
"bin": {
@@ -39,7 +33,7 @@
"test": "make test"
},
"dependencies": {
"acorn-6to5": "0.11.1-14",
"acorn-6to5": "0.11.1-16",
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",
@@ -50,7 +44,7 @@
"fs-readdir-recursive": "0.1.0",
"jshint": "2.5.10",
"lodash": "2.4.1",
"mkdirp": "0.5.0",
"output-file-sync": "^1.1.0",
"private": "0.1.6",
"regenerator": "0.8.3",
"regexpu": "0.3.0",

View File

@@ -1,15 +1,15 @@
if (process.env.running_under_istanbul) return;
var readdir = require("fs-readdir-recursive");
var helper = require("./_helper");
var assert = require("assert");
var rimraf = require("rimraf");
var mkdirp = require("mkdirp");
var child = require("child_process");
var path = require("path");
var chai = require("chai");
var fs = require("fs");
var _ = require("lodash");
var readdir = require("fs-readdir-recursive");
var helper = require("./_helper");
var assert = require("assert");
var rimraf = require("rimraf");
var outputFileSync = require("output-file-sync");
var child = require("child_process");
var path = require("path");
var chai = require("chai");
var fs = require("fs");
var _ = require("lodash");
var fixtureLoc = __dirname + "/fixtures/bin";
var tmpLoc = __dirname + "/tmp";
@@ -27,10 +27,7 @@ var readDir = function (loc) {
var saveInFiles = function (files) {
_.each(files, function (content, filename) {
var up = path.normalize(filename + "/..");
mkdirp.sync(up);
fs.writeFileSync(filename, content);
outputFileSync(filename, content);
});
};

View File

@@ -1,11 +1,6 @@
"use strict";
var _slice = Array.prototype.slice;
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
@@ -37,21 +32,19 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
Test.prototype.test = function () {
Test.prototype.test = function test() {
var _Foo$prototype$test3, _Foo$prototype$test4;
Foo.prototype.test.call(this);
(_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 () {
Test.foo = function foo() {
var _Foo$foo, _Foo$foo2;
Foo.foo.call(this);
(_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)));
};
_prototypeProperties(Test, {}, {});
return Test;
})(Foo);

View File

@@ -1,10 +1,5 @@
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
@@ -28,11 +23,9 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
Test.test = function () {
Test.test = function test() {
return Foo.wow.call(this);
};
_prototypeProperties(Test, {});
return Test;
})(Foo);

View File

@@ -61,7 +61,7 @@ var Test = (function (Foo) {
_prototypeProperties(Test, {
foo: {
value: function () {
value: function foo() {
var _get4;
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
_get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments);
@@ -73,7 +73,7 @@ var Test = (function (Foo) {
}
}, {
test: {
value: function () {
value: function test() {
var _get5;
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments);

View File

@@ -52,7 +52,7 @@ var Test = (function (Foo) {
_prototypeProperties(Test, {
test: {
value: function () {
value: function test() {
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
},
writable: true,

View File

@@ -10,7 +10,7 @@ var Test = (function () {
_prototypeProperties(Test, null, {
test: {
value: function () {
value: function test() {
return 5 + 5;
},
writable: true,

View File

@@ -9,16 +9,16 @@ var BaseView = function BaseView() {
this.autoRender = true;
};
var BaseView = function () {
var BaseView = function BaseView() {
this.autoRender = true;
};
var BaseView = (function () {
var _class2 = function () {};
function BaseView() {}
_prototypeProperties(_class2, null, {
_prototypeProperties(BaseView, null, {
foo: {
value: function () {
value: function foo() {
this.autoRender = true;
},
writable: true,
@@ -27,5 +27,5 @@ var BaseView = (function () {
}
});
return _class2;
return BaseView;
})();

View File

@@ -10,7 +10,7 @@ var A = (function () {
_prototypeProperties(A, {
a: {
value: function () {},
value: function a() {},
writable: true,
enumerable: true,
configurable: true

View File

@@ -1,9 +1,9 @@
"use strict";
var concat = function () {
var arrs = [];
for (var _key = 0; _key < arguments.length; _key++) {
for (var _len = arguments.length,
arrs = Array(_len),
_key = 0; _key < _len; _key++) {
arrs[_key] = arguments[_key];
}
};

View File

@@ -1,17 +1,17 @@
"use strict";
var t = function (f) {
var items = [];
for (var _key = 1; _key < arguments.length; _key++) {
for (var _len = arguments.length,
items = Array(_len > 1 ? _len - 1 : 0),
_key = 1; _key < _len; _key++) {
items[_key - 1] = arguments[_key];
}
};
function t(f) {
var items = [];
for (var _key2 = 1; _key2 < arguments.length; _key2++) {
for (var _len2 = arguments.length,
items = Array(_len2 > 1 ? _len2 - 1 : 0),
_key2 = 1; _key2 < _len2; _key2++) {
items[_key2 - 1] = arguments[_key2];
}
}

View File

@@ -1,17 +1,17 @@
"use strict";
var t = function () {
var items = [];
for (var _key = 0; _key < arguments.length; _key++) {
for (var _len = arguments.length,
items = Array(_len),
_key = 0; _key < _len; _key++) {
items[_key] = arguments[_key];
}
};
function t() {
var items = [];
for (var _key2 = 0; _key2 < arguments.length; _key2++) {
for (var _len2 = arguments.length,
items = Array(_len2),
_key2 = 0; _key2 < _len2; _key2++) {
items[_key2] = arguments[_key2];
}
}

View File

@@ -16,7 +16,7 @@ var H = (function () {
var J = new WeakMap(),
K = new WeakMap();
var I = new WeakMap();
var _class = function () {};
function H() {}
return _class;
return H;
})();

View File

@@ -5,4 +5,4 @@ var _typeof = function (obj) {
};
var s = Symbol("s");
assert.equal(_typeof(s), "symbol");
assert.equal(typeof s === "undefined" ? "undefined" : _typeof(s), "symbol");

View File

@@ -14,6 +14,7 @@ require("./_transformation-helper")({
loc: traceurLoc + "/test/feature",
ignoreSuites: [
// these are all internal traceur tests or non-standard features
"ObjectMixin",
"Annotations",
"TestRunner",
@@ -40,10 +41,13 @@ require("./_transformation-helper")({
"Syntax/UseStrictEscapeSequence",
"Syntax/UseStrictLineContinuation",
// the spec for these doesn't define syntax (as far as i could tell)
// experimental es7 - the spec hasn't been finalised yet
// these both fail because of filter between blocks
"ArrayComprehension/Simple",
"GeneratorComprehension/Simple"
"GeneratorComprehension/Simple",
// yield has been added as a keyword in ES6 so this test is actually incorrect
"Yield/YieldIdentifier"
]
}, {
optional: ["typeofSymbol"],