Compare commits

...

11 Commits

Author SHA1 Message Date
Sebastian McKenzie
680771c81b v1.13.10 2014-11-24 01:02:18 +11:00
Sebastian McKenzie
cad3f63723 update assignment expression destructuring test 2014-11-24 01:01:13 +11:00
Sebastian McKenzie
eceda64528 add 1.13.10 changelog 2014-11-24 01:00:26 +11:00
Sebastian McKenzie
b8ec87e058 fix Scope::push block type error message 2014-11-24 00:59:56 +11:00
Sebastian McKenzie
04bd023787 add support for AssignmentExpression destructuring outside of ExpressionStatement 2014-11-24 00:56:06 +11:00
Sebastian McKenzie
f1759dc419 v1.13.9 2014-11-24 00:48:05 +11:00
Sebastian McKenzie
2985f1b40b fix VirtualPropertyExpression visitor keys - fixes #207 2014-11-24 00:47:10 +11:00
Sebastian McKenzie
14d1b6701e v1.13.8 2014-11-24 00:37:33 +11:00
Sebastian McKenzie
eb3cc9ff07 remove unused variables 2014-11-24 00:36:36 +11:00
Sebastian McKenzie
b97a2bd61d reorder object spread/rest 2014-11-24 00:35:39 +11:00
Sebastian McKenzie
49e7e3b998 fix multiple references in experimental abstract references #207 2014-11-24 00:35:18 +11:00
17 changed files with 150 additions and 48 deletions

View File

@@ -1,3 +1,15 @@
# 1.13.10
* Add support for `AssignmentExpression` destructuring outside of `ExpressionStatement`.
# 1.13.9
* Fix `VirtualPropertyExpression` visitor keys.
# 1.13.8
* Only use a single reference in abstract references.
# 1.13.7
* Upgrade `acorn-6to5`.

View File

@@ -11,8 +11,8 @@ satisfy **all** 6to5 feature requirements by using the included
| 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` |
| Spread | `Array.isArray`, `Array.from` |
## Classes

View File

@@ -84,12 +84,12 @@ better suited if you'd like a full ES6 environment with polyfills and all.
| Generator comprehension | ✓ | ✓ | | | | |
| Let scoping | ✓ | ✓ | ✓ | | | |
| Modules | ✓ | ✓ | | | ✓ | |
| Object rest/spread | ✓ | | | | | ✓ |
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Object rest/spread | ✓ | | | | | ✓ |
| Unicode regex | ✓ | ✓ | ✓ | | | |
### [Traceur](https://github.com/google/traceur-compiler)

View File

@@ -208,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
@@ -261,14 +268,6 @@ var x = 5;
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

@@ -47,11 +47,11 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
- [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)
- [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

@@ -13,9 +13,8 @@ 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 = [
@@ -123,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;
@@ -135,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;
};

View File

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

View File

@@ -1,3 +1,5 @@
// TODO: Clean up
var t = require("../../types");
var _ = require("lodash");
@@ -183,10 +185,38 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
return nodes;
};
exports.AssignmentExpression = function (node, parent, file) {
exports.AssignmentExpression = function (node, parent, file, scope) {
if (parent.type === "ExpressionStatement") return;
if (!t.isPattern(node.left)) return;
throw file.errorWithNode(node, "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations");
var tempName = file.generateUid("temp", scope);
var temp = t.identifier(tempName);
scope.push(tempName, temp);
var nodes = [];
nodes.push(t.assignmentExpression("=", temp, node.right));
push({
kind: false,
file: file,
scope: scope
}, nodes, node.left, temp);
nodes.push(temp);
nodes = nodes.map(function (node) {
if (t.isExpressionStatement(node)) {
return node.expression;
} else if (t.isVariableDeclaration(node)) {
var declar = node.declarations[0];
scope.push(declar.id.name, declar.id);
return t.assignmentExpression("=", declar.id, declar.init);
} else {
return node;
}
});
return t.sequenceExpression(nodes);
};
exports.VariableDeclaration = function (node, parent, file, scope) {

View File

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

View File

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

View File

@@ -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 TypeError("cannot add a declaration here in node type " + block.type);
}
};
Scope.prototype.add = function (node, references) {
if (!node) return;
_.merge(references || this.references, t.getIds(node, true));

View File

@@ -61,7 +61,7 @@
"UpdateExpression": ["argument"],
"VariableDeclaration": ["declarations"],
"VariableDeclarator": ["id", "init"],
"VirtualPropertyExpression": ["left", "right"],
"VirtualPropertyExpression": ["object", "property"],
"WhileStatement": ["test", "body"],
"WithStatement": ["object", "body"],
"XJSAttribute": ["name", "value"],

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.13.7",
"version": "1.13.10",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {

View File

@@ -1 +0,0 @@
console.log([x] = [1]);

View File

@@ -1,3 +0,0 @@
{
"throws": "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations"
}

View File

@@ -0,0 +1,9 @@
"use strict";
var _ref;
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _temp;
console.log((_temp = [123], _ref = _toArray(_temp), x = _ref[0], _temp));

View File

@@ -1,3 +0,0 @@
{
"throws": "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations"
}