Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d1b6701e | ||
|
|
eb3cc9ff07 | ||
|
|
b97a2bd61d | ||
|
|
49e7e3b998 | ||
|
|
11ac6ff084 | ||
|
|
54e7e495ac | ||
|
|
fafdb1a18a | ||
|
|
b599e2c794 | ||
|
|
7f57d3d6a2 | ||
|
|
a2b0ee6809 | ||
|
|
83e8c4bddd | ||
|
|
57aca3c77f | ||
|
|
f80527832c | ||
|
|
2ecceaac45 | ||
|
|
32f8f9e663 | ||
|
|
3447204d97 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,3 +1,22 @@
|
||||
# 1.13.8
|
||||
|
||||
* Only use a single reference in abstract references.
|
||||
|
||||
# 1.13.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental exponentiation operator support.
|
||||
|
||||
# 1.13.6
|
||||
|
||||
* Fix experimental object spread/rest helper.
|
||||
|
||||
# 1.13.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental support for object spread/rest.
|
||||
* Change `arguments` to array to an additional helper method.
|
||||
|
||||
# 1.13.4
|
||||
|
||||
* Fix single spread element returning itself.
|
||||
|
||||
@@ -4,14 +4,15 @@ In order for certain features to work they require certain polyfills. You can
|
||||
satisfy **all** 6to5 feature requirements by using the included
|
||||
[polyfill](polyfill.md). You may alternatively selectively include what you need:
|
||||
|
||||
| Feature | Requirements |
|
||||
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Abstract References | `Symbol` |
|
||||
| Array destructuring | `Array.isArray`, `Array.from` |
|
||||
| Async functions, Generators | [experimental option](usage.md#experimental), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
|
||||
| Comprehensions | [experimental option](usage.md#experimental), `Array.isArray`, `Array.from` |
|
||||
| For..Of | `Symbol`, `prototype[Symbol.iterator]` |
|
||||
| Spread | `Array.isArray`, `Array.from` |
|
||||
| Feature | Requirements |
|
||||
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Abstract References | [experimental](usage.md#experimental), `Symbol` |
|
||||
| Array destructuring | `Array.isArray`, `Array.from` |
|
||||
| Async functions, Generators | [experimental](usage.md#experimental), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
|
||||
| Comprehensions | [experimental](usage.md#experimental), `Array.isArray`, `Array.from` |
|
||||
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
|
||||
| Object spread/rest | [experimental](usage.md#experimental), `Object.assign` |
|
||||
| Spread | `Array.isArray`, `Array.from` |
|
||||
|
||||
## Classes
|
||||
|
||||
|
||||
@@ -78,11 +78,13 @@ better suited if you'd like a full ES6 environment with polyfills and all.
|
||||
| Constants | ✓ | ✓ | ✓ | | | |
|
||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Exponentiation operator | ✓ | ✓ | | | | |
|
||||
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Generators | ✓ | ✓ | | ✓ | | |
|
||||
| Generator comprehension | ✓ | ✓ | | | | |
|
||||
| Let scoping | ✓ | ✓ | ✓ | | | |
|
||||
| Modules | ✓ | ✓ | | | ✓ | |
|
||||
| Object rest/spread | ✓ | | | | | ✓ |
|
||||
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
@@ -94,7 +96,7 @@ better suited if you'd like a full ES6 environment with polyfills and all.
|
||||
|
||||
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
|
||||
While this can be trimmed down by selectively building the runtime, it's an
|
||||
unneccesary step when a runtime can be eliminated entirely.
|
||||
unneccesary step when a large runtime can be eliminated entirely.
|
||||
|
||||
### [es6now](https://github.com/zenparsing/es6now)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ foo::bar = baz;
|
||||
delete foo::bar;
|
||||
```
|
||||
|
||||
## Array comprehension ([experimental](usage.md#experimental))
|
||||
## Array comprehensions ([experimental](usage.md#experimental))
|
||||
|
||||
```javascript
|
||||
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
|
||||
@@ -130,6 +130,15 @@ var [a] = [];
|
||||
a === undefined;
|
||||
```
|
||||
|
||||
## Exponentiation operator ([experimental](usage.md#experimental)) ([spec](https://github.com/rwaldron/exponentiation-operator))
|
||||
|
||||
```javascript
|
||||
var a = 2;
|
||||
a **= 2;
|
||||
|
||||
var squared = 2 ** 2;
|
||||
```
|
||||
|
||||
## For-of
|
||||
|
||||
```javascript
|
||||
@@ -158,7 +167,7 @@ for (var n of fibonacci()) {
|
||||
}
|
||||
```
|
||||
|
||||
## Generator comprehension ([experimental](usage.md#experimental))
|
||||
## Generator comprehensions ([experimental](usage.md#experimental))
|
||||
|
||||
```javascript
|
||||
var nums = [1, 2, 3, 4, 5, 6];
|
||||
@@ -199,6 +208,13 @@ export default test;
|
||||
0o767 === 503; // true
|
||||
```
|
||||
|
||||
## Object spread/rest ([experimental](usage.md#experimental)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
|
||||
|
||||
```javascript
|
||||
var n = { x, y, ...z };
|
||||
var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
|
||||
```
|
||||
|
||||
## Property method assignment
|
||||
|
||||
```javascript
|
||||
@@ -252,7 +268,6 @@ var x = 5;
|
||||
var y = 10;
|
||||
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
|
||||
```
|
||||
|
||||
## Unicode regex
|
||||
|
||||
```javascript
|
||||
|
||||
@@ -40,12 +40,14 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
|
||||
- [Constants](features.md#constants)
|
||||
- [Default parameters](features.md#default-parameters)
|
||||
- [Destructuring](features.md#destructuring)
|
||||
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](usage.md#experimental))
|
||||
- [For-of](features.md#for-of)
|
||||
- [Generators](features.md#generators)
|
||||
- [Generator comprehension](features.md#generator-comprehension) ([experimental](usage.md#experimental))
|
||||
- [Let scoping](features.md#let-scoping)
|
||||
- [Modules](features.md#modules)
|
||||
- [Numeric literals](features.md#numeric-literals)
|
||||
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](usage.md#experimental))
|
||||
- [Property method assignment](features.md#property-method-assignment)
|
||||
- [Property name shorthand](features.md#property-name-shorthand)
|
||||
- [React/JSX](react.md)
|
||||
|
||||
@@ -13,13 +13,20 @@ function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
this.declarations = {};
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = ["extends", "class-props", "slice", "apply-constructor",
|
||||
"tagged-template-literal", "interop-require", "to-array"];
|
||||
File.declarations = [
|
||||
"extends",
|
||||
"class-props",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"arguments-to-array",
|
||||
"object-spread"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
@@ -73,11 +80,14 @@ File.normaliseOptions = function (opts) {
|
||||
File.prototype.toArray = function (node) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
return t.callExpression(this.addDeclaration("to-array"), [node]);
|
||||
}
|
||||
|
||||
var templateName = "to-array";
|
||||
if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
templateName = "arguments-to-array";
|
||||
}
|
||||
|
||||
return t.callExpression(this.addDeclaration(templateName), [node]);
|
||||
};
|
||||
|
||||
File.prototype.getModuleFormatter = function (type) {
|
||||
@@ -112,8 +122,10 @@ File.prototype.addDeclaration = function (name) {
|
||||
throw new ReferenceError("unknown declaration " + name);
|
||||
}
|
||||
|
||||
var declar = this.declarations[name];
|
||||
if (declar) return declar.uid;
|
||||
var program = this.ast.program;
|
||||
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var ref;
|
||||
var runtimeNamespace = this.opts.runtime;
|
||||
@@ -124,11 +136,8 @@ File.prototype.addDeclaration = function (name) {
|
||||
ref = util.template(name);
|
||||
}
|
||||
|
||||
var uid = t.identifier(this.generateUid(name));
|
||||
this.declarations[name] = {
|
||||
uid: uid,
|
||||
node: ref
|
||||
};
|
||||
var uid = this.generateUidIdentifier(name);
|
||||
this.scope.push(name, uid, ref);
|
||||
return uid;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ exports.Identifier = function (node) {
|
||||
this.push(node.name);
|
||||
};
|
||||
|
||||
exports.SpreadElement = function (node, print) {
|
||||
exports.SpreadElement =
|
||||
exports.SpreadProperty = function (node, print) {
|
||||
this.push("...");
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
@@ -9,6 +9,10 @@ exports.before = {
|
||||
}
|
||||
},
|
||||
|
||||
SpreadProperty: function (node, parent) {
|
||||
return exports.before.nodes.Property(node, parent);
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
if (parent.cases[0] === node) {
|
||||
return 1;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments, SLICE_ARG);
|
||||
@@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments);
|
||||
@@ -1 +0,0 @@
|
||||
SLICE_KEY.call(arguments);
|
||||
7
lib/6to5/templates/arguments-to-array.js
Normal file
7
lib/6to5/templates/arguments-to-array.js
Normal file
@@ -0,0 +1,7 @@
|
||||
(function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i< args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
return target;
|
||||
})
|
||||
9
lib/6to5/templates/object-spread.js
Normal file
9
lib/6to5/templates/object-spread.js
Normal file
@@ -0,0 +1,9 @@
|
||||
(function (obj, keys) {
|
||||
var target = {};
|
||||
for (var i in obj) {
|
||||
if (keys.indexOf(i) >= 0) continue;
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
||||
target[i] = obj[i];
|
||||
}
|
||||
return target;
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
Array.prototype.slice;
|
||||
@@ -38,6 +38,8 @@ _.each({
|
||||
_propertyLiterals: require("./transformers/_property-literals"),
|
||||
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
||||
|
||||
objectSpread: require("./transformers/es7-object-spread"),
|
||||
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||
spread: require("./transformers/es6-spread"),
|
||||
templateLiterals: require("./transformers/es6-template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (ast, file) {
|
||||
var body = ast.program.body;
|
||||
|
||||
for (var i in file.declarations) {
|
||||
var declar = file.declarations[i];
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(declar.uid, declar.node)
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
_.each(node._declarations, function (declar) {
|
||||
node.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(declar.id, declar.init)
|
||||
]));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -24,14 +24,33 @@ var push = function (opts, nodes, elem, parentId) {
|
||||
};
|
||||
|
||||
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
_.each(pattern.properties, function (prop) {
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
|
||||
_.each(pattern.properties, function (prop, i) {
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
// get all the keys that appear in this object before the current spread
|
||||
var keys = [];
|
||||
_.each(pattern.properties, function (prop2, i2) {
|
||||
if (i2 >= i) return false;
|
||||
if (t.isSpreadProperty(prop2)) return;
|
||||
|
||||
if (t.isPattern(pattern2)) {
|
||||
push(opts, nodes, pattern2, patternId2);
|
||||
var key = prop2.key;
|
||||
if (t.isIdentifier(key)) {
|
||||
key = t.literal(prop2.key.name);
|
||||
}
|
||||
keys.push(key);
|
||||
});
|
||||
keys = t.arrayExpression(keys);
|
||||
|
||||
var value = t.callExpression(opts.file.addDeclaration("object-spread"), [parentId, keys]);
|
||||
nodes.push(buildVariableAssign(opts.kind, prop.argument, value));
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(opts.kind, pattern2, patternId2));
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
|
||||
|
||||
if (t.isPattern(pattern2)) {
|
||||
push(opts, nodes, pattern2, patternId2);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(opts.kind, pattern2, patternId2));
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.rest) return;
|
||||
@@ -7,18 +6,20 @@ exports.Function = function (node, parent, file) {
|
||||
var rest = node.rest;
|
||||
delete node.rest;
|
||||
|
||||
var templateName = "arguments-slice-assign";
|
||||
if (node.params.length) templateName += "-arg";
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var template = util.template(templateName, {
|
||||
SLICE_KEY: file.addDeclaration("slice"),
|
||||
VARIABLE_NAME: rest,
|
||||
SLICE_ARG: t.literal(node.params.length)
|
||||
});
|
||||
var call = t.callExpression(
|
||||
file.addDeclaration("arguments-to-array"),
|
||||
[t.identifier("arguments")]
|
||||
);
|
||||
|
||||
template.declarations[0].init.arguments[0]._ignoreAliasFunctions = true;
|
||||
if (node.params.length) {
|
||||
call = t.callExpression(t.memberExpression(call, t.identifier("slice")), [t.literal(node.params.length)]);
|
||||
}
|
||||
|
||||
node.body.body.unshift(template);
|
||||
call._ignoreAliasFunctions = true;
|
||||
|
||||
node.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(rest, call)
|
||||
]));
|
||||
};
|
||||
|
||||
@@ -8,23 +8,48 @@ var container = function (parent, call, ret) {
|
||||
// we don't need to worry about return values
|
||||
return call;
|
||||
} else {
|
||||
return t.sequenceExpression([call, ret]);
|
||||
var exprs = [];
|
||||
if (t.isSequenceExpression(call)) {
|
||||
exprs = call.expressions;
|
||||
} else {
|
||||
exprs.push(call);
|
||||
}
|
||||
exprs.push(ret);
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent) {
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
var left = node.left;
|
||||
if (!t.isVirtualPropertyExpression(left)) return;
|
||||
|
||||
var right = node.right;
|
||||
var value = node.right;
|
||||
var temp;
|
||||
|
||||
// we need to return `node.right`
|
||||
if (!t.isExpressionStatement(parent)) {
|
||||
// `node.right` isn't a simple identifier so we need to reference it
|
||||
if (!t.isIdentifier(value)) {
|
||||
var tempName = file.generateUid("temp");
|
||||
temp = value = t.identifier(tempName);
|
||||
scope.push(tempName, temp);
|
||||
}
|
||||
}
|
||||
|
||||
var call = util.template("abstract-expression-set", {
|
||||
PROPERTY: left.property,
|
||||
OBJECT: left.object,
|
||||
VALUE: right
|
||||
VALUE: value
|
||||
});
|
||||
|
||||
return container(parent, call, right);
|
||||
if (temp) {
|
||||
call = t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, node.right),
|
||||
call
|
||||
]);
|
||||
}
|
||||
|
||||
return container(parent, call, value);
|
||||
};
|
||||
|
||||
exports.UnaryExpression = function (node, parent) {
|
||||
@@ -40,16 +65,33 @@ exports.UnaryExpression = function (node, parent) {
|
||||
return container(parent, call, t.literal(true));
|
||||
};
|
||||
|
||||
exports.CallExpression = function (node) {
|
||||
exports.CallExpression = function (node, parent, file, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp;
|
||||
if (!t.isIdentifier(callee.object)) {
|
||||
// we need to save `callee.object` so we can call it again
|
||||
var tempName = file.generateUid("temp");
|
||||
temp = t.identifier(tempName);
|
||||
scope.push(tempName, temp);
|
||||
}
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
OBJECT: callee.object
|
||||
OBJECT: temp || callee.object
|
||||
});
|
||||
|
||||
call.arguments = call.arguments.concat(node.arguments);
|
||||
return call;
|
||||
|
||||
if (temp) {
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, callee.object),
|
||||
call
|
||||
]);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VirtualPropertyExpression = function (node) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// https://github.com/rwaldron/exponentiation-operator
|
||||
|
||||
var t = require("../../types");
|
||||
var pow = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||
|
||||
exports.AssignmentExpression = function (node) {
|
||||
if (node.operator !== "**=") return;
|
||||
node.operator = "=";
|
||||
node.right = t.callExpression(pow, [node.left, node.right]);
|
||||
};
|
||||
|
||||
exports.BinaryExpression = function (node) {
|
||||
if (node.operator !== "**") return;
|
||||
|
||||
return t.callExpression(pow, [node.left, node.right]);
|
||||
};
|
||||
41
lib/6to5/transformation/transformers/es7-object-spread.js
Normal file
41
lib/6to5/transformation/transformers/es7-object-spread.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// https://github.com/sebmarkbage/ecmascript-rest-spread
|
||||
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
var hasSpread = false;
|
||||
_.each(node.properties, function (prop) {
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
hasSpread = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (!hasSpread) return;
|
||||
|
||||
var args = [];
|
||||
var props = [];
|
||||
|
||||
var push = function () {
|
||||
if (!props.length) return;
|
||||
args.push(t.objectExpression(props));
|
||||
props = [];
|
||||
};
|
||||
|
||||
_.each(node.properties, function (prop) {
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
push();
|
||||
args.push(prop.argument);
|
||||
} else {
|
||||
props.push(prop);
|
||||
}
|
||||
});
|
||||
|
||||
push();
|
||||
|
||||
if (!t.isObjectExpression(args[0])) {
|
||||
args.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), args);
|
||||
};
|
||||
@@ -90,6 +90,7 @@ function traverse(parent, callbacks, opts) {
|
||||
traverse.removeProperties = function (tree) {
|
||||
var clear = function (node) {
|
||||
delete node._scopeReferences;
|
||||
delete node._declarations;
|
||||
delete node.extendedRange;
|
||||
delete node._parent;
|
||||
delete node._scope;
|
||||
|
||||
@@ -97,6 +97,25 @@ Scope.prototype.getReferences = function () {
|
||||
return references;
|
||||
};
|
||||
|
||||
Scope.prototype.push = function (name, id, init) {
|
||||
var block = this.block;
|
||||
|
||||
if (t.isFor(block) || t.isCatchClause(block) || t.isFunction(block)) {
|
||||
t.ensureBlock(block);
|
||||
block = block.body;
|
||||
}
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
block._declarations = block._declarations || {};
|
||||
block._declarations[name] = {
|
||||
id: id,
|
||||
init: init
|
||||
};
|
||||
} else {
|
||||
throw new Error("wtf");
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.add = function (node, references) {
|
||||
if (!node) return;
|
||||
_.merge(references || this.references, t.getIds(node, true));
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"ReturnStatement": ["argument"],
|
||||
"SequenceExpression": ["expressions"],
|
||||
"SpreadElement": ["argument"],
|
||||
"SpreadProperty": ["argument"],
|
||||
"SwitchCase": ["test", "consequent"],
|
||||
"SwitchStatement": ["discriminant", "cases"],
|
||||
"TaggedTemplateExpression": ["tag", "quasi"],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.13.4",
|
||||
"version": "1.13.8",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -47,7 +47,7 @@
|
||||
"chokidar": "0.11.1",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.6",
|
||||
"acorn-6to5": "0.9.1-5",
|
||||
"acorn-6to5": "0.9.1-7",
|
||||
"estraverse": "1.8.0",
|
||||
"private": "0.1.6"
|
||||
},
|
||||
|
||||
3
test/fixtures/generation/types/VirualPropertyExpression/actual.js
vendored
Normal file
3
test/fixtures/generation/types/VirualPropertyExpression/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
foo::bar;
|
||||
foo::bar = baz;
|
||||
delete foo::bar;
|
||||
3
test/fixtures/generation/types/VirualPropertyExpression/expected.js
vendored
Normal file
3
test/fixtures/generation/types/VirualPropertyExpression/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
foo::bar;
|
||||
foo::bar = baz;
|
||||
delete foo::bar;
|
||||
@@ -1,6 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var _classProps = function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
@@ -25,11 +33,11 @@ var Test = (function (Foo) {
|
||||
Foo.prototype.test.call(this);
|
||||
foob(Foo);
|
||||
|
||||
Foo.call.apply(Foo, [this].concat(_slice.call(arguments)));
|
||||
Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.call.apply(Foo, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.call.apply(Foo, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
};
|
||||
|
||||
_extends(Test, Foo);
|
||||
@@ -39,8 +47,8 @@ var Test = (function (Foo) {
|
||||
writable: true,
|
||||
value: function () {
|
||||
Foo.foo.call(this);
|
||||
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -48,8 +56,8 @@ var Test = (function (Foo) {
|
||||
writable: true,
|
||||
value: function () {
|
||||
Foo.prototype.test.call(this);
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
3
test/fixtures/transformation/es6-destructuring/es7-object-rest/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-destructuring/es7-object-rest/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var { ...x } = z;
|
||||
var { x, ...y } = z;
|
||||
(function({ x, ...y }) { })
|
||||
22
test/fixtures/transformation/es6-destructuring/es7-object-rest/expected.js
vendored
Normal file
22
test/fixtures/transformation/es6-destructuring/es7-object-rest/expected.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
var _objectSpread = function (obj, keys) {
|
||||
var target = {};
|
||||
for (var i in obj) {
|
||||
if (keys.indexOf(i) >= 0) continue;
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
||||
target[i] = obj[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var x = _objectSpread(z, []);
|
||||
|
||||
var x = z.x;
|
||||
var y = _objectSpread(z, ["x"]);
|
||||
|
||||
(function (_ref) {
|
||||
var x = _ref.x;
|
||||
var y = _objectSpread(_ref, ["x"]);
|
||||
});
|
||||
3
test/fixtures/transformation/es6-destructuring/es7-object-rest/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-destructuring/es7-object-rest/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"experimental": true
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var concat = function () {
|
||||
var arrs = _slice.call(arguments);
|
||||
var _arguments = arguments;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var concat = function () {
|
||||
var arrs = _argumentsToArray(_arguments);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var t = function (f) {
|
||||
var items = _slice.call(arguments, 1);
|
||||
var items = _argumentsToArray(arguments).slice(1);
|
||||
};
|
||||
|
||||
function t(f) {
|
||||
var items = _slice.call(arguments, 1);
|
||||
var items = _argumentsToArray(arguments).slice(1);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var t = function () {
|
||||
var items = _slice.call(arguments);
|
||||
var items = _argumentsToArray(arguments);
|
||||
};
|
||||
|
||||
function t() {
|
||||
var items = _slice.call(arguments);
|
||||
var items = _argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
function foo() {
|
||||
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
|
||||
return bar.apply(null, ["test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
|
||||
1
test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-exponentian-operator/assignment/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
num **= 2;
|
||||
3
test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/assignment/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
num = Math.pow(num, 2);
|
||||
1
test/fixtures/transformation/es7-exponentian-operator/binary/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-exponentian-operator/binary/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
2 ** 2;
|
||||
3
test/fixtures/transformation/es7-exponentian-operator/binary/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/binary/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
Math.pow(2, 2);
|
||||
3
test/fixtures/transformation/es7-exponentian-operator/options.json
vendored
Normal file
3
test/fixtures/transformation/es7-exponentian-operator/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"experimental": true
|
||||
}
|
||||
1
test/fixtures/transformation/es7-object-spread/assignment/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-object-spread/assignment/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
z = { x, ...y };
|
||||
3
test/fixtures/transformation/es7-object-spread/assignment/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-object-spread/assignment/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
z = Object.assign({ x: x }, y);
|
||||
1
test/fixtures/transformation/es7-object-spread/expression/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-object-spread/expression/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
({ x, ...y, a, ...b, c });
|
||||
3
test/fixtures/transformation/es7-object-spread/expression/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-object-spread/expression/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
(Object.assign({ x: x }, y, { a: a }, b, { c: c }));
|
||||
3
test/fixtures/transformation/es7-object-spread/options.json
vendored
Normal file
3
test/fixtures/transformation/es7-object-spread/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"experimental": true
|
||||
}
|
||||
1
test/fixtures/transformation/es7-object-spread/variable-declaration/actual.js
vendored
Normal file
1
test/fixtures/transformation/es7-object-spread/variable-declaration/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var z = { ...x };
|
||||
3
test/fixtures/transformation/es7-object-spread/variable-declaration/expected.js
vendored
Normal file
3
test/fixtures/transformation/es7-object-spread/variable-declaration/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var z = Object.assign({}, x);
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = customNamespace.slice.call(arguments);
|
||||
var test = customNamespace.argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = to5Runtime.slice.call(arguments);
|
||||
var test = to5Runtime.argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user