Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
750ec7783f | ||
|
|
14ae438735 | ||
|
|
2f8bdd7e27 | ||
|
|
87da9fcfc5 | ||
|
|
51f6cfddca | ||
|
|
b9ad4c2773 | ||
|
|
228b3dbc34 | ||
|
|
a01802300f | ||
|
|
51c6a3fffc | ||
|
|
4668e1d67b | ||
|
|
75e9097e19 | ||
|
|
0627cd94d4 | ||
|
|
71879d6e8f | ||
|
|
d7810cac08 | ||
|
|
dc9efd21d3 | ||
|
|
347e490614 | ||
|
|
e512264be7 | ||
|
|
9624663e60 | ||
|
|
3cf8a6df01 | ||
|
|
88eacecd72 | ||
|
|
fcd3c9ce65 | ||
|
|
1733bac3bb | ||
|
|
21cd063274 | ||
|
|
db5750643a | ||
|
|
60dae7a88d | ||
|
|
790c924b54 | ||
|
|
50d7a46c7f | ||
|
|
6f7da38957 | ||
|
|
80764c214a | ||
|
|
55054e45da | ||
|
|
060aa5ba0b | ||
|
|
688d619bfe | ||
|
|
6db7fce543 | ||
|
|
41ff1d4ace | ||
|
|
1c6eeba2e9 | ||
|
|
488b719fde | ||
|
|
af32080287 | ||
|
|
4c1cd13536 | ||
|
|
1002cf7796 | ||
|
|
081dd33e73 | ||
|
|
bd9dc4f15d | ||
|
|
c7ba566ad6 | ||
|
|
a1b326a0ab | ||
|
|
a452f781b8 | ||
|
|
e5463cc2a9 | ||
|
|
7d732ef503 | ||
|
|
25cb0c6344 | ||
|
|
45a52bf478 | ||
|
|
a14f971b8a | ||
|
|
da65500545 | ||
|
|
58a91ee9e9 | ||
|
|
19eaa181a5 | ||
|
|
c7c90acf3f | ||
|
|
c6f3a55c03 | ||
|
|
e01b7d288f | ||
|
|
98c0e185b8 | ||
|
|
bf66d78210 | ||
|
|
b60eca0a76 | ||
|
|
44f06c0b4c | ||
|
|
6c5606b7e8 | ||
|
|
07ddfbeb5d | ||
|
|
87b890c172 | ||
|
|
245fcfe110 | ||
|
|
4744719040 | ||
|
|
a3b814a897 | ||
|
|
f5f17f0ccb | ||
|
|
f6a2acdfb1 | ||
|
|
e8dba2ad1e | ||
|
|
8ce5c5b608 | ||
|
|
0dfea1a51b |
@@ -1,3 +1,4 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
|
||||
29
CHANGELOG.md
29
CHANGELOG.md
@@ -11,6 +11,35 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.12.5
|
||||
|
||||
* **Internal**
|
||||
* Fix incorrect `for...in` loop still causing `ember-script` issues.
|
||||
|
||||
## 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**
|
||||
* Exclude nodes in function parameters and catch clauses from `isReferenced` check.
|
||||
|
||||
## 2.12.1
|
||||
|
||||
* **Internal**
|
||||
* Add `.jsx` to list of allowed extensions.
|
||||
|
||||
## 2.12.0
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@@ -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.
|
||||
|
||||
2
NOTES.md
2
NOTES.md
@@ -10,4 +10,4 @@
|
||||
* Split up ES5 getter/setter transforming and ES6 property methods into separate transformers.
|
||||
* Add autoindentation.
|
||||
* Move `super` transformation from classes into a separate transformer that also supports object expressions.
|
||||
* Prefix all fast transformers with `fast`, make them declare that they're a fast transformer similar to optional transformers and add a `--fast` flag to enable them all.
|
||||
* Remove fast transformer backwards compatibility.
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
};
|
||||
@@ -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));
|
||||
@@ -123,7 +77,7 @@ var hookExtensions = function (_exts) {
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions([".es6", ".es", ".js"]);
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalise options
|
||||
|
||||
23
lib/6to5/transformation/helpers/build-comprehension.js
Normal file
23
lib/6to5/transformation/helpers/build-comprehension.js
Normal 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])
|
||||
);
|
||||
};
|
||||
43
lib/6to5/transformation/helpers/name-method.js
Normal file
43
lib/6to5/transformation/helpers/name-method.js
Normal 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;
|
||||
}
|
||||
};
|
||||
29
lib/6to5/transformation/helpers/remap-async-to-generator.js
Normal file
29
lib/6to5/transformation/helpers/remap-async-to-generator.js
Normal 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;
|
||||
}
|
||||
};
|
||||
19
lib/6to5/transformation/helpers/use-strict.js
Normal file
19
lib/6to5/transformation/helpers/use-strict.js
Normal 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);
|
||||
}
|
||||
};
|
||||
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,12 +39,12 @@ 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
|
||||
var has = scope.get(param.name);
|
||||
var has = scope.get(param.name, true);
|
||||
if (has && node.params.indexOf(has) < 0) {
|
||||
iife = true;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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, []);
|
||||
|
||||
|
||||
@@ -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,12 +231,10 @@ LetScoping.prototype.getInfo = function () {
|
||||
}
|
||||
};
|
||||
|
||||
var i;
|
||||
var declar;
|
||||
|
||||
for (i in opts.declarators) {
|
||||
for (var i = 0; i < opts.declarators.length; i++) {
|
||||
declar = opts.declarators[i];
|
||||
opts.declarators.push(declar);
|
||||
|
||||
var keys = t.getIds(declar, true);
|
||||
_.each(keys, duplicates);
|
||||
@@ -246,14 +244,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 +412,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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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));
|
||||
}));
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"));
|
||||
};
|
||||
|
||||
@@ -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"))
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
"&&",
|
||||
|
||||
13
lib/6to5/transformation/transformers/react.js
vendored
13
lib/6to5/transformation/transformers/react.js
vendored
@@ -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;
|
||||
|
||||
@@ -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")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -193,6 +226,21 @@ t.isReferenced = function (node, parent) {
|
||||
// we're a property key and we aren't computed so we aren't referenced
|
||||
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
|
||||
|
||||
if (t.isFunction(parent)) {
|
||||
// we're a function param
|
||||
if (_.contains(parent.params, node)) return false;
|
||||
|
||||
// we're a rest parameter
|
||||
if (parent.rest === node) return false;
|
||||
}
|
||||
|
||||
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we're a catch clause param
|
||||
if (t.isCatchClause(parent) && parent.param === node) return false;
|
||||
|
||||
// we're a variable declarator id so we aren't referenced
|
||||
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
|
||||
|
||||
@@ -392,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]);
|
||||
@@ -400,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] || []);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@ var _ = require("lodash");
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || [".js", ".jsx", ".es6", ".es"];
|
||||
var exts = altExts || exports.canCompile.EXTENSIONS;
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
|
||||
|
||||
exports.isInteger = function (i) {
|
||||
return _.isNumber(i) && i % 1 === 0;
|
||||
};
|
||||
|
||||
16
package.json
16
package.json
@@ -1,16 +1,10 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.12.0",
|
||||
"version": "2.12.5",
|
||||
"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",
|
||||
|
||||
25
test/bin.js
25
test/bin.js
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -10,7 +10,7 @@ var Test = (function () {
|
||||
|
||||
_prototypeProperties(Test, null, {
|
||||
test: {
|
||||
value: function () {
|
||||
value: function test() {
|
||||
return 5 + 5;
|
||||
},
|
||||
writable: true,
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -10,7 +10,7 @@ var A = (function () {
|
||||
|
||||
_prototypeProperties(A, {
|
||||
a: {
|
||||
value: function () {},
|
||||
value: function a() {},
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if (process.env.SIMPLE_6TO5_TESTS || process.env.running_under_istanbul) return;
|
||||
if (process.env.SIMPLE_6TO5_TESTS) return;
|
||||
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user