Compare commits

...

9 Commits

Author SHA1 Message Date
Sebastian McKenzie
b599e2c794 v1.13.6 2014-11-23 21:51:31 +11:00
Sebastian McKenzie
7f57d3d6a2 fix experimental object spread/rest helper 2014-11-23 21:50:49 +11:00
Sebastian McKenzie
a2b0ee6809 v1.13.5 2014-11-23 21:47:20 +11:00
Sebastian McKenzie
83e8c4bddd bump acorn-6to5 version 2014-11-23 21:46:07 +11:00
Sebastian McKenzie
57aca3c77f add 1.13.5 changelog 2014-11-23 21:45:18 +11:00
Sebastian McKenzie
f80527832c remove unused variables 2014-11-23 21:45:10 +11:00
Sebastian McKenzie
2ecceaac45 add VirtualPropertyExpression generator test 2014-11-23 21:43:39 +11:00
Sebastian McKenzie
32f8f9e663 change arguments to array to an additional faster helper method 2014-11-23 21:43:28 +11:00
Sebastian McKenzie
3447204d97 add experimental es7 object spread/rest - closes #200 2014-11-23 21:43:01 +11:00
41 changed files with 265 additions and 64 deletions

View File

@@ -1,3 +1,13 @@
# 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.

View File

@@ -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]` |
| Spread | `Array.isArray`, `Array.from` |
| Object spread/rest | [experimental](usage.md#experimental), `Object.assign` |
## Classes

View File

@@ -88,13 +88,14 @@ better suited if you'd like a full ES6 environment with polyfills and all.
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Object rest/spread | ✓ | | | | | ✓ |
| Unicode regex | ✓ | ✓ | ✓ | | | |
### [Traceur](https://github.com/google/traceur-compiler)
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)

View File

@@ -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 }]
@@ -158,7 +158,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];
@@ -253,6 +253,13 @@ var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
```
## 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 };
```
## Unicode regex
```javascript

View File

@@ -52,4 +52,5 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
- [Rest parameters](features.md#rest-parameters)
- [Spread](features.md#spread)
- [Template literals](features.md#template-literals)
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](usage.md#experimental))
- [Unicode regex](features.md#unicode-regex)

View File

@@ -18,8 +18,16 @@ function File(opts) {
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 +81,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) {

View File

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

View File

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

View File

@@ -1 +0,0 @@
var VARIABLE_NAME = SLICE_KEY.call(arguments, SLICE_ARG);

View File

@@ -1 +0,0 @@
var VARIABLE_NAME = SLICE_KEY.call(arguments);

View File

@@ -1 +0,0 @@
SLICE_KEY.call(arguments);

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

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

View File

@@ -1 +0,0 @@
Array.prototype.slice;

View File

@@ -38,6 +38,7 @@ _.each({
_propertyLiterals: require("./transformers/_property-literals"),
computedPropertyNames: require("./transformers/es6-computed-property-names"),
objectSpread: require("./transformers/es7-object-spread"),
spread: require("./transformers/es6-spread"),
templateLiterals: require("./transformers/es6-template-literals"),
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),

View File

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

View File

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

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

View File

@@ -48,6 +48,7 @@
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"SpreadElement": ["argument"],
"SpreadProperty": ["argument"],
"SwitchCase": ["test", "consequent"],
"SwitchStatement": ["discriminant", "cases"],
"TaggedTemplateExpression": ["tag", "quasi"],

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.13.4",
"version": "1.13.6",
"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-6",
"estraverse": "1.8.0",
"private": "0.1.6"
},

View File

@@ -0,0 +1,3 @@
foo::bar;
foo::bar = baz;
delete foo::bar;

View File

@@ -0,0 +1,3 @@
foo::bar;
foo::bar = baz;
delete foo::bar;

View File

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

View File

@@ -0,0 +1,3 @@
var { ...x } = z;
var { x, ...y } = z;
(function({ x, ...y }) { })

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

View File

@@ -0,0 +1,3 @@
{
"experimental": true
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1 @@
z = { x, ...y };

View File

@@ -0,0 +1,3 @@
"use strict";
z = Object.assign({ x: x }, y);

View File

@@ -0,0 +1 @@
({ x, ...y, a, ...b, c });

View File

@@ -0,0 +1,3 @@
"use strict";
(Object.assign({ x: x }, y, { a: a }, b, { c: c }));

View File

@@ -0,0 +1,3 @@
{
"experimental": true
}

View File

@@ -0,0 +1 @@
var z = { ...x };

View File

@@ -0,0 +1,3 @@
"use strict";
var z = Object.assign({}, x);

View File

@@ -1,5 +1,5 @@
"use strict";
function foo() {
var test = customNamespace.slice.call(arguments);
var test = customNamespace.argumentsToArray(arguments);
}

View File

@@ -1,5 +1,5 @@
"use strict";
function foo() {
var test = to5Runtime.slice.call(arguments);
var test = to5Runtime.argumentsToArray(arguments);
}