Compare commits

..

69 Commits

Author SHA1 Message Date
Sebastian McKenzie
44f2f701e1 v1.13.11 2014-11-24 10:23:56 +11:00
Sebastian McKenzie
032bc0af5e fix util.regexify tests 2014-11-24 10:23:00 +11:00
Sebastian McKenzie
0e822a7e54 remove unused variables 2014-11-24 10:21:01 +11:00
Sebastian McKenzie
51e521f0e0 add 1.13.11 changelog 2014-11-24 10:19:40 +11:00
Sebastian McKenzie
e5ce69d6af clean up register module formatter and rename it to system 2014-11-24 10:19:06 +11:00
Sebastian McKenzie
e3b8fa93e2 export as module.exports if there are no other ExportDeclarations in commonInterop module formatter @guybedford 2014-11-24 10:05:50 +11:00
Sebastian McKenzie
f4ce3a23ad fix explicit arguments reference for rest parameters - fixes #210 2014-11-24 10:05:49 +11:00
Sebastian McKenzie
39f4696ac7 fix util.regexify on falsy values - fixes #208 2014-11-24 10:05:49 +11:00
Sebastian McKenzie
4a9918ec6b Merge pull request #209 from douglasduteil/feat-modules-add-register-module-type
Add "register" module formatter
2014-11-24 10:05:29 +11:00
Douglas Duteil
c87e14f6a9 feat(modules): add "register" module type
Inspired by https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained
2014-11-23 22:54:01 +01:00
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
Sebastian McKenzie
11ac6ff084 v1.13.7 2014-11-23 22:57:30 +11:00
Sebastian McKenzie
54e7e495ac add 1.13.7 changelog 2014-11-23 22:56:13 +11:00
Sebastian McKenzie
fafdb1a18a add exponentiation operator 2014-11-23 22:55:20 +11:00
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
Sebastian McKenzie
c500532469 v1.13.4 2014-11-23 20:17:14 +11:00
Sebastian McKenzie
3396cc84f1 fix spread not returning a new array with a single spread element 2014-11-23 20:16:10 +11:00
Sebastian McKenzie
1de4893a69 v1.13.3 2014-11-23 18:51:53 +11:00
Sebastian McKenzie
abba930f36 update sequence expression generator test 2014-11-23 18:51:07 +11:00
Sebastian McKenzie
c84097cf57 fix bin/6to5-node experimental option 2014-11-23 18:49:56 +11:00
Sebastian McKenzie
790b81938c fix Node::isUserWhitespacable 2014-11-23 18:47:38 +11:00
Sebastian McKenzie
187bbca731 add 1.13.3 changelog 2014-11-23 18:46:56 +11:00
Sebastian McKenzie
4ccc12b04d simplify Node::isUserWhitespacable method 2014-11-23 18:46:49 +11:00
Sebastian McKenzie
9a5f97d85b fix jshint errors 2014-11-23 18:46:30 +11:00
Sebastian McKenzie
4ed77e136b Merge branch 'abstract-references' 2014-11-23 18:38:24 +11:00
Sebastian McKenzie
0339d21c33 add WeakMap existence check to symbol polyfilling 2014-11-23 18:37:43 +11:00
Sebastian McKenzie
4502aee988 add support for call expression abstract references and more versatile tests 2014-11-23 18:37:30 +11:00
Sebastian McKenzie
55150853b4 remove SequenceExpression user whitespace 2014-11-23 18:36:57 +11:00
Sebastian McKenzie
b9da4f988c upgrade acorn-6to5 2014-11-23 18:36:38 +11:00
Sebastian McKenzie
bf0ca10253 add abstract reference CallExpression base 2014-11-23 16:54:51 +11:00
Sebastian McKenzie
fcc4734a1f complete abstract references support - parser support left 2014-11-23 16:47:13 +11:00
Sebastian McKenzie
d1c5c773fa make experimental warning more scary 2014-11-23 16:21:42 +11:00
Sebastian McKenzie
01ce38c5ac Merge branch 'master' into abstract-references 2014-11-23 16:17:56 +11:00
Sebastian McKenzie
cc6d440f0e update classes and destructuring test names 2014-11-23 16:17:49 +11:00
Sebastian McKenzie
2b21f4b571 Merge branch 'master' into abstract-references
Conflicts:
	lib/6to5/polyfill.js
2014-11-23 16:17:10 +11:00
Sebastian McKenzie
24d9833170 better categorisation of transformers 2014-11-23 16:15:39 +11:00
Sebastian McKenzie
20f21987de fix travis badge branch 2014-11-23 16:09:13 +11:00
Sebastian McKenzie
fad0be8a45 add spec references 2014-11-23 16:08:54 +11:00
Sebastian McKenzie
02c42b94f5 Add abstract references base #205 2014-11-23 16:04:25 +11:00
Sebastian McKenzie
4808689795 add support link to readme 2014-11-23 15:30:37 +11:00
Sebastian McKenzie
6231dceb1c clarify polyfill usage 2014-11-23 15:29:21 +11:00
Sebastian McKenzie
1753afa782 rename no runtime to optional runtime in differences table 2014-11-23 15:18:00 +11:00
Sebastian McKenzie
4097da09bd clarify polyfill usage 2014-11-23 15:17:49 +11:00
Sebastian McKenzie
c7965df42d update esutils and es6-shim 2014-11-23 15:16:42 +11:00
Sebastian McKenzie
1027f8a5a4 use slice helper on arguments instead of toArray 2014-11-23 13:09:31 +11:00
Sebastian McKenzie
cbd6be30bf v1.13.2 2014-11-23 12:02:26 +11:00
Sebastian McKenzie
7e299470fd remove unused variables 2014-11-23 12:01:19 +11:00
Sebastian McKenzie
c794c2aede upgrade acorn-6to5 2014-11-23 11:59:57 +11:00
Sebastian McKenzie
1a58087460 use toArray inline helper instead of Array.from #203 #199 2014-11-23 11:59:18 +11:00
Sebastian McKenzie
44f6fc67f8 v1.13.1 2014-11-23 01:17:14 +11:00
Sebastian McKenzie
e4a3d222d6 fix constructor spread optimisation - thanks @zloirock 2014-11-23 01:16:09 +11:00
630 changed files with 1754 additions and 499 deletions

View File

@@ -1,7 +1,59 @@
# 1.13.11
* Fix `util.regexify` on falsy values.
* Fix `_aliasFunction` with rest parameters.
* Export as `module.exports` instead of `exports.default` if there are no other `ExportDeclaration`s in `commonInterop` module formatter.
* Add `system` module formatter. Thanks [@douglasduteil](https://github.com/douglasduteil).
# 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`.
* 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.
# 1.13.3
* Upgrade `acorn-6to5`.
* Add experimental support for abstract references.
# 1.13.2
* Optimise `Array.from` usage by adding a helper method.
* Upgrade `acorn-6to5`.
# 1.13.1
* Fix constructor spread optimisation. Thanks [@zloirock](https://github.com/zloirock).
# 1.13.0
* Put experimental ES7 features behind a flag `--experimental` and `experimental` option.
* Constructor speed performance increase. Thanks [@RReverser](https://github.com/RReverser).
* Constructor spread performance increase. Thanks [@RReverser](https://github.com/RReverser).
* Use `self` instead of `window` in the optional 6to5 runtime. Thanks [@RReverser](https://github.com/RReverser).
# 1.12.26

View File

@@ -4,7 +4,7 @@
<p align="center">
<a href="https://travis-ci.org/6to5/6to5">
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5.svg?branch=master&amp;style=flat&amp;label=travis">
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&amp;label=travis">
</a>
<a href="https://ci.appveyor.com/project/sebmck/6to5">
@@ -26,4 +26,5 @@
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
For more information view the [documentation](https://6to5.github.io).
For more information view the [documentation](https://6to5.github.io). For
support visit the [gitter room](https://gitter.im/6to5/6to5).

View File

@@ -30,7 +30,11 @@ to5.register({
//
var _eval = function (code, filename) {
code = to5.transform(code, { filename: filename, blacklist: ["useStrict"] }).code;
code = to5.transform(code, {
filename: filename,
blacklist: ["useStrict"],
experimental: commander.experimental
}).code;
return vm.runInThisContext(code, filename);
};

View File

@@ -1,19 +1,18 @@
# Caveats
## Async/Generators
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:
The [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js)
and an [ES6 polyfill](polyfill.md) are required in order for generators to work.
### Async/Comprehensions
[Experimental support](usage.md#experimental) must be enabled for these proposed
ES7 features to work.
### Array comprehension/Array destructuring/Spread
An [ES6 polyfill](polyfill.md) is required. More specifically a polyfill for
`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
@@ -40,14 +39,3 @@ class Bar extends Foo {
}
}
```
## Constructor spread
Constructor spreads do not currently support built-ins. ie.
`new Array(...items)`.
## For-of
A polyfill is required for for-of functionality that implements `Symbol` and
adds `prototype[Symbol.iterator]` behaviour to built-ins. Using the polyfills
specified in [polyfill](polyfill.md) suffices.

View File

@@ -62,13 +62,14 @@ better suited if you'd like a full ES6 environment with polyfills and all.
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
| Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ |
| No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ |
| No runtime | ✓ | | ✓ | | | ✓ |
| Optional runtime | ✓ | | ✓ | | | ✓ |
| Browser support | ✓ | ✓ | | ✓ | | |
### Language Support
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- |
| Abstract references | ✓ | | | | | |
| Array comprehension | ✓ | ✓ | ✓ | | | |
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async functions | ✓ | ✓ | | ✓ | | |
@@ -77,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 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
@@ -89,15 +92,11 @@ better suited if you'd like a full ES6 environment with polyfills and all.
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| 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

@@ -1,6 +1,14 @@
# Features
## Array comprehension ([experimental](usage.md#experimental))
## Abstract references ([experimental](usage.md#experimental)) ([spec](https://github.com/zenparsing/es-abstract-refs))
```javascript
foo::bar;
foo::bar = baz;
delete foo::bar;
```
## Array comprehensions ([experimental](usage.md#experimental))
```javascript
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
@@ -31,7 +39,7 @@ var bob = {
};
```
## Async functions ([experimental](usage.md#experimental))
## Async functions ([experimental](usage.md#experimental)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
```javascript
async function chainAnimationsAsync(elem, animations) {
@@ -122,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
@@ -150,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];
@@ -191,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
@@ -244,7 +268,6 @@ var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
```
## Unicode regex
```javascript

View File

@@ -31,6 +31,7 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
## [Features](features.md)
- [Abstract references](features.md#abstract-references) ([experimental](usage.md#experimental))
- [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental))
- [Async functions](features.md#async-functions) ([experimental](usage.md#experimental))
- [Arrow functions](features.md#arrow-functions)
@@ -39,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)

View File

@@ -51,6 +51,69 @@ var test = 5; exports.test = test;
exports.default = test;
```
### Common interop
**In**
```javascript
import "foo";
import foo from "foo";
import * as foo from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
export {test};
export var test = 5;
export default test;
```
**Out**
```javascript
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
require("foo");
var foo = _interopRequire(require("foo"));
var foo = require("foo");
var bar = require("foo").bar;
var bar = require("foo").foo;
exports.test = test;
var test = exports.test = 5;
exports["default"] = test;
```
#### module.exports behaviour
If there exist no other non-default `export`s then `default exports` are
exported as `module.exports` instead of `exports.default`.
**In**
```javascript
export default function foo() {
}
```
**Out**
```javascript
module.exports = foo;
function foo() {
}
```
### AMD
**In**
@@ -135,6 +198,43 @@ function bar() {
}
```
### Register
**In**
```javascript
import foo from "foo";
export function bar() {
return foo("foobar");
}
```
**Out**
```javascript
System.register("bar", ["foo"], function ($__export) {
"use strict";
var __moduleName = "bar";
var foo;
function bar() {
return foo("foobar");
}
return {
setters: [function (m) {
foo = m.default;
}],
execute: function () {
$__export("bar", bar);
}
};
});
```
## Custom
You can alternatively specify module names instead of one of the built-in types.

View File

@@ -5,13 +5,23 @@
[es6-shim](https://github.com/paulmillr/es6-shim) and
[es6-symbol](https://github.com/medikoo/es6-symbol) polyfills.
## Node
This will emulate a full ES6 environment. This polyfill is automatically loaded
when using [6to5-node](usage.md#node).
## Usage
### Node
You need to include the polyfill require at the top the **entry point** to your
application.
```javascript
require("6to5/polyfill");
```
## Browser
### Browser
Available from the `browser-polyfill.js` file within the 6to5 directory of an
npm release.
npm release. This needs to be included **before** all your compiled 6to5 code.
You can either prepend it to your compiled code or include it in a `<script>`
before it.

View File

@@ -192,4 +192,5 @@ require("6to5/register")({
the `experimental: true` option when using the [Node API](#node) or
`--experimental` when using the [CLI](#cli).
**NOTE:** That these are subject to change as their proposal status progresses.
**WARNING:** These proposals are subject to change so use with
**extreme caution**.

View File

@@ -10,16 +10,21 @@ var t = require("./types");
var _ = require("lodash");
function File(opts) {
this.opts = File.normaliseOptions(opts);
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
this.declarations = {};
this.uids = {};
this.ast = {};
this.opts = File.normaliseOptions(opts);
this.uids = {};
this.ast = {};
}
File.declarations = ["extends", "class-props", "slice", "apply-constructor",
"tagged-template-literal", "interop-require"];
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 || {});
@@ -70,6 +75,19 @@ File.normaliseOptions = function (opts) {
return opts;
};
File.prototype.toArray = function (node) {
if (t.isArrayExpression(node)) {
return 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) {
var ModuleFormatter = _.isFunction(type) ? type : transform.moduleFormatters[type];
@@ -102,8 +120,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;
@@ -114,11 +134,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;
};
@@ -149,6 +166,7 @@ File.prototype.parse = function (code) {
File.prototype.transform = function (ast) {
this.ast = ast;
this.scope = new Scope(ast.program);
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
var self = this;

View File

@@ -4,11 +4,18 @@ 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);
};
exports.VirtualPropertyExpression = function (node, print) {
print(node.object);
this.push("::");
print(node.property);
};
exports.ObjectExpression =
exports.ObjectPattern = function (node, print) {
var props = node.properties;

View File

@@ -24,15 +24,7 @@ function Node(node, parent) {
}
Node.prototype.isUserWhitespacable = function () {
var parent = this.parent;
var node = this.node;
if (t.isUserWhitespacable(node) ||
t.isSequenceExpression(parent)) {
return true;
}
return false;
return t.isUserWhitespacable(this.node);
};
Node.prototype.needsWhitespace = function (type) {

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,6 +1,37 @@
/* jshint newcap: false */
var ensureSymbol = function (key) {
Symbol[key] = Symbol[key] || Symbol();
};
var ensureProto = function (Constructor, key, val) {
var proto = Constructor.prototype;
proto[key] = proto[key] || val;
};
//
if (typeof Symbol === "undefined") {
require("es6-symbol/implement");
}
require("es6-shim");
require("./transformation/transformers/generators/runtime");
require("./transformation/transformers/es6-generators/runtime");
// Abstract references
ensureSymbol("referenceGet");
ensureSymbol("referenceSet");
ensureSymbol("referenceDelete");
ensureProto(Function, Symbol.referenceGet, function () { return this; });
ensureProto(Map, Symbol.referenceGet, Map.prototype.get);
ensureProto(Map, Symbol.referenceSet, Map.prototype.set);
ensureProto(Map, Symbol.referenceDelete, Map.prototype.delete);
if (global.WeakMap) {
ensureProto(WeakMap, Symbol.referenceGet, WeakMap.prototype.get);
ensureProto(WeakMap, Symbol.referenceSet, WeakMap.prototype.set);
ensureProto(WeakMap, Symbol.referenceDelete, WeakMap.prototype.delete);
}

View File

@@ -0,0 +1 @@
PROPERTY[Symbol.referenceGet](OBJECT).call(OBJECT)

View File

@@ -0,0 +1 @@
PROPERTY[Symbol.referenceDelete](OBJECT)

View File

@@ -0,0 +1 @@
PROPERTY[Symbol.referenceGet](OBJECT)

View File

@@ -0,0 +1 @@
PROPERTY[Symbol.referenceSet](OBJECT, VALUE)

View File

@@ -1,5 +1,5 @@
(function (Constructor, args) {
var instance = Object.create(Constructor.prototype);
Constructor.apply(instance, args);
return instance;
var result = Constructor.apply(instance, args);
return result != null && (typeof result == "object" || typeof result == "function") ? result : instance;
});

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 @@
module.exports = VALUE;

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

@@ -0,0 +1 @@
System.register(MODULE_NAME, MODULE_DEPENDENCIES, MODULE_BODY);

View File

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

View File

@@ -0,0 +1,3 @@
(function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
});

View File

@@ -41,34 +41,11 @@ AMDFormatter.prototype.transform = function (ast) {
};
AMDFormatter.prototype.getModuleName = function () {
var opts = this.file.opts;
var filenameRelative = opts.filenameRelative;
var moduleName = "";
if (!opts.amdModuleIds) {
if (this.file.opts.amdModuleIds) {
return CommonJSFormatter.prototype.getModuleName.apply(this, arguments);
} else {
return null;
}
if (opts.moduleRoot) {
moduleName = opts.moduleRoot + "/";
}
if (!opts.filenameRelative) {
return moduleName + opts.filename.replace(/^\//, "");
}
if (opts.sourceRoot) {
// remove sourceRoot from filename
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
}
// remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
moduleName += filenameRelative;
return moduleName;
};
AMDFormatter.prototype._push = function (node) {

View File

@@ -4,8 +4,9 @@ var CommonJSFormatter = require("./common");
var util = require("../../util");
var t = require("../../types");
function CommonJSInteropFormatter(file) {
this.file = file;
function CommonJSInteropFormatter() {
this.has = false;
CommonJSFormatter.apply(this, arguments);
}
util.inherits(CommonJSInteropFormatter, CommonJSFormatter);
@@ -26,3 +27,27 @@ CommonJSInteropFormatter.prototype.importSpecifier = function (specifier, node,
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
}
};
CommonJSInteropFormatter.prototype.export = function (node, nodes) {
if (node.default && !this.has) {
var declar = node.declaration;
// module.exports = VALUE;
var assign = util.template("exports-default-module", {
VALUE: this._pushStatement(declar, nodes)
}, true);
// hoist to the top if this default is a function
nodes.push(this._hoistExport(declar, assign));
return;
} else {
this.has = true;
}
CommonJSFormatter.prototype.export.apply(this, arguments);
};
CommonJSInteropFormatter.prototype.exportSpecifier = function () {
this.has = true;
CommonJSFormatter.prototype.exportSpecifier.apply(this, arguments);
};

View File

@@ -7,6 +7,33 @@ function CommonJSFormatter(file) {
this.file = file;
}
CommonJSFormatter.prototype.getModuleName = function () {
var opts = this.file.opts;
var filenameRelative = opts.filenameRelative;
var moduleName = "";
if (opts.moduleRoot) {
moduleName = opts.moduleRoot + "/";
}
if (!opts.filenameRelative) {
return moduleName + opts.filename.replace(/^\//, "");
}
if (opts.sourceRoot) {
// remove sourceRoot from filename
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
}
// remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
moduleName += filenameRelative;
return moduleName;
};
CommonJSFormatter.prototype.import = function (node, nodes) {
// import "foo";
nodes.push(util.template("require", {
@@ -38,23 +65,32 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
}));
};
CommonJSFormatter.prototype._hoistExport = function (declar, assign) {
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
return assign;
};
CommonJSFormatter.prototype._pushStatement = function (ref, nodes) {
if (t.isClass(ref) || t.isFunction(ref)) {
if (ref.id) {
nodes.push(t.toStatement(ref));
ref = ref.id;
}
}
return ref;
};
CommonJSFormatter.prototype.export = function (node, nodes) {
var declar = node.declaration;
if (node.default) {
var ref = declar;
if (t.isClass(ref) || t.isFunction(ref)) {
if (ref.id) {
nodes.push(t.toStatement(ref));
ref = ref.id;
}
}
nodes.push(util.template("exports-default", {
//inherits: node,
VALUE: ref
VALUE: this._pushStatement(declar, nodes)
}, true));
} else {
var assign;
@@ -83,9 +119,7 @@ CommonJSFormatter.prototype.export = function (node, nodes) {
nodes.push(t.toStatement(declar));
nodes.push(assign);
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
this._hoistExport(declar, assign);
}
}
};
@@ -126,7 +160,7 @@ CommonJSFormatter.prototype._exportSpecifier = function (getRef, specifier, node
};
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
return this._exportSpecifier(function () {
this._exportSpecifier(function () {
return t.callExpression(t.identifier("require"), [node.source]);
}, specifier, node, nodes);
};

View File

@@ -0,0 +1,203 @@
module.exports = SystemFormatter;
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var SETTER_MODULE_NAMESPACE = t.identifier("m");
var DEFAULT_IDENTIFIER = t.identifier("default");
var NULL_SETTER = t.literal(null);
function SystemFormatter(file) {
this.exportedStatements = [];
this.importedModule = {};
this.exportIdentifier = file.generateUidIdentifier("export");
this.file = file;
}
SystemFormatter.prototype.transform = function (ast) {
var program = ast.program;
var body = program.body;
// extract the module name
var moduleName = this.file.opts.filename
.replace(/^.*\//, "").replace(/\..*$/, "");
// build an array of module names
var dependencies = Object.keys(this.importedModule).map(t.literal);
// generate the __moduleName variable
var moduleNameVariableNode = t.variableDeclaration("var", [
t.variableDeclarator(
t.identifier("__moduleName"),
t.literal(moduleName)
)
]);
body.splice(1, 0, moduleNameVariableNode);
// generate an array of import variables
var declaredSetters = _(this.importedModule)
.map()
.flatten()
.pluck("variableName")
.pluck("name")
.uniq()
.map(t.identifier)
.map(function (name) {
return t.variableDeclarator(name);
})
.value();
if (declaredSetters.length) {
body.splice(2, 0, t.variableDeclaration("var", declaredSetters));
}
// generate the execute function expression
var executeFunctionExpression = t.functionExpression(
null, [], t.blockStatement(this.exportedStatements)
);
// generate the execute function expression
var settersArrayExpression = t.arrayExpression(this._buildSetters());
// generate the return statement
var moduleReturnStatement = t.returnStatement(t.objectExpression([
t.property("init", t.identifier("setters"), settersArrayExpression),
t.property("init", t.identifier("execute"), executeFunctionExpression)
]));
body.push(moduleReturnStatement);
// runner
var runner = util.template("register", {
MODULE_NAME: t.literal(moduleName),
MODULE_DEPENDENCIES: t.arrayExpression(dependencies),
MODULE_BODY: t.functionExpression(
null,
[this.exportIdentifier],
t.blockStatement(body)
)
});
program.body = [t.expressionStatement(runner)];
};
SystemFormatter.prototype._buildSetters = function () {
// generate setters array expression elements
return _.map(this.importedModule, function (specs) {
if (!specs.length) {
return NULL_SETTER;
}
var expressionStatements = _.map(specs, function (spec) {
var right = SETTER_MODULE_NAMESPACE;
if (!spec.isBatch) {
right = t.memberExpression(right, spec.key);
}
return t.expressionStatement(
t.assignmentExpression("=", spec.variableName, right
)
);
});
return t.functionExpression(
null, [SETTER_MODULE_NAMESPACE], t.blockStatement(expressionStatements)
);
});
};
SystemFormatter.prototype.import = function (node) {
var MODULE_NAME = node.source.value;
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
};
SystemFormatter.prototype.importSpecifier = function (specifier, node) {
var variableName = t.getSpecifierName(specifier);
// import foo from "foo";
if (specifier.default) {
specifier.id = DEFAULT_IDENTIFIER;
}
var MODULE_NAME = node.source.value;
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
this.importedModule[MODULE_NAME].push({
variableName: variableName,
isBatch: specifier.type === "ImportBatchSpecifier",
key: specifier.id
});
};
SystemFormatter.prototype._export = function (name, identifier) {
this.exportedStatements.push(t.expressionStatement(
t.callExpression(this.exportIdentifier, [t.literal(name), identifier])
));
};
SystemFormatter.prototype.export = function (node, nodes) {
var declar = node.declaration;
var variableName, identifier;
if (node.default) {
// export default foo
variableName = DEFAULT_IDENTIFIER.name;
if (t.isClass(declar) || t.isFunction(declar)) {
if (!declar.id) {
declar.id = this.file.generateUidIdentifier("anonymous");
}
nodes.push(t.toStatement(declar));
declar = declar.id;
}
identifier = declar;
} else if (t.isVariableDeclaration(declar)) {
// export var foo
variableName = declar.declarations[0].id.name;
identifier = declar.declarations[0].id;
nodes.push(declar);
} else {
// export function foo () {}
variableName = declar.id.name;
identifier = declar.id;
nodes.push(declar);
}
this._export(variableName, identifier);
};
SystemFormatter.prototype.exportSpecifier = function (specifier, node) {
var variableName = t.getSpecifierName(specifier);
if (node.source) {
if (t.isExportBatchSpecifier(specifier)) {
// export * from "foo";
var exportIdentifier = t.identifier("exports");
this.exportedStatements.push(
t.variableDeclaration("var", [
t.variableDeclarator(exportIdentifier, this.exportIdentifier)
])
);
this.exportedStatements.push(util.template("exports-wildcard", {
OBJECT: t.identifier(node.source.value)
}, true));
} else {
// export { foo } from "test";
this._export(variableName.name, t.memberExpression(
t.identifier(node.source.value),
specifier.id
));
}
} else {
// export { foo };
this._export(variableName.name, specifier.id);
}
};

View File

@@ -22,36 +22,40 @@ transform.transformers = {};
transform.moduleFormatters = {
common: require("./modules/common"),
commonInterop: require("./modules/common-interop"),
system: require("./modules/system"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
};
_.each({
modules: require("./transformers/modules"),
propertyNameShorthand: require("./transformers/property-name-shorthand"),
arrayComprehension: require("./transformers/array-comprehension"),
generatorComprehension: require("./transformers/generator-comprehension"),
arrowFunctions: require("./transformers/arrow-functions"),
classes: require("./transformers/classes"),
modules: require("./transformers/es6-modules"),
propertyNameShorthand: require("./transformers/es6-property-name-shorthand"),
arrayComprehension: require("./transformers/es7-array-comprehension"),
generatorComprehension: require("./transformers/es7-generator-comprehension"),
arrowFunctions: require("./transformers/es6-arrow-functions"),
classes: require("./transformers/es6-classes"),
_propertyLiterals: require("./transformers/_property-literals"),
computedPropertyNames: require("./transformers/computed-property-names"),
computedPropertyNames: require("./transformers/es6-computed-property-names"),
spread: require("./transformers/spread"),
templateLiterals: require("./transformers/template-literals"),
propertyMethodAssignment: require("./transformers/property-method-assignment"),
defaultParameters: require("./transformers/default-parameters"),
restParameters: require("./transformers/rest-parameters"),
destructuring: require("./transformers/destructuring"),
forOf: require("./transformers/for-of"),
unicodeRegex: require("./transformers/unicode-regex"),
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"),
defaultParameters: require("./transformers/es6-default-parameters"),
restParameters: require("./transformers/es6-rest-parameters"),
destructuring: require("./transformers/es6-destructuring"),
forOf: require("./transformers/es6-for-of"),
unicodeRegex: require("./transformers/es6-unicode-regex"),
abstractReferences: require("./transformers/es7-abstract-references"),
react: require("./transformers/react"),
constants: require("./transformers/constants"),
letScoping: require("./transformers/let-scoping"),
constants: require("./transformers/es6-constants"),
letScoping: require("./transformers/es6-let-scoping"),
generators: require("./transformers/generators"),
generators: require("./transformers/es6-generators"),
_blockHoist: require("./transformers/_block-hoist"),
_declarations: require("./transformers/_declarations"),

View File

@@ -31,7 +31,7 @@ var go = function (getBody, node, file, scope) {
return false;
}
if (node._ignoreAliasFunctions) return;
if (node._ignoreAliasFunctions) return false;
var getId;

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,6 +1,7 @@
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
// TODO: Clean up
var t = require("../../types");
var _ = require("lodash");
var buildVariableAssign = function (kind, id, init) {
if (kind === false) {
@@ -25,14 +26,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));
}
}
});
};
@@ -40,9 +60,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var _parentId = opts.file.generateUidIdentifier("ref", opts.scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(_parentId, util.template("array-from", {
VALUE: parentId
}))
t.variableDeclarator(_parentId, opts.file.toArray(parentId))
]));
parentId = _parentId;
@@ -52,9 +70,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var newPatternId;
if (t.isSpreadElement(elem)) {
newPatternId = util.template("array-from", {
VALUE: parentId
});
newPatternId = opts.file.toArray(parentId);
if (+i > 0) {
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);
@@ -169,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

@@ -5,10 +5,10 @@ exports.ImportDeclaration = function (node, parent, file) {
if (node.specifiers.length) {
_.each(node.specifiers, function (specifier) {
file.moduleFormatter.importSpecifier(specifier, node, nodes);
file.moduleFormatter.importSpecifier(specifier, node, nodes, parent);
});
} else {
file.moduleFormatter.import(node, nodes);
file.moduleFormatter.import(node, nodes, parent);
}
return nodes;
@@ -18,10 +18,10 @@ exports.ExportDeclaration = function (node, parent, file) {
var nodes = [];
if (node.declaration) {
file.moduleFormatter.export(node, nodes);
file.moduleFormatter.export(node, nodes, parent);
} else {
_.each(node.specifiers, function (specifier) {
file.moduleFormatter.exportSpecifier(specifier, node, nodes);
file.moduleFormatter.exportSpecifier(specifier, node, nodes, parent);
});
}

View File

@@ -0,0 +1,25 @@
var t = require("../../types");
exports.Function = function (node, parent, file) {
if (!node.rest) return;
var rest = node.rest;
delete node.rest;
t.ensureBlock(node);
var call = t.callExpression(
file.addDeclaration("arguments-to-array"),
[t.identifier("arguments")]
);
if (node.params.length) {
call = t.callExpression(t.memberExpression(call, t.identifier("slice")), [t.literal(node.params.length)]);
}
call._ignoreAliasFunctions = true;
node.body.body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(rest, call)
]));
};

View File

@@ -1,15 +1,8 @@
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var t = require("../../types");
var _ = require("lodash");
var getSpreadLiteral = function (spread) {
var literal = spread.argument;
if (!t.isArrayExpression(literal)) {
literal = util.template("array-from", {
VALUE: literal
});
}
return literal;
var getSpreadLiteral = function (spread, file) {
return file.toArray(spread.argument);
};
var hasSpread = function (nodes) {
@@ -23,7 +16,7 @@ var hasSpread = function (nodes) {
return has;
};
var build = function (props) {
var build = function (props, file) {
var nodes = [];
var _props = [];
@@ -37,7 +30,7 @@ var build = function (props) {
_.each(props, function (prop) {
if (t.isSpreadElement(prop)) {
push();
nodes.push(getSpreadLiteral(prop));
nodes.push(getSpreadLiteral(prop, file));
} else {
_props.push(prop);
}
@@ -48,19 +41,22 @@ var build = function (props) {
return nodes;
};
exports.ArrayExpression = function (node) {
exports.ArrayExpression = function (node, parent, file) {
var elements = node.elements;
if (!hasSpread(elements)) return;
var nodes = build(elements);
var nodes = build(elements, file);
var first = nodes.shift();
if (!nodes.length) return first;
if (!t.isArrayExpression(first)) {
nodes.unshift(first);
first = t.arrayExpression([]);
}
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
};
exports.CallExpression = function (node) {
exports.CallExpression = function (node, parent, file) {
var args = node.arguments;
if (!hasSpread(args)) return;
@@ -68,7 +64,7 @@ exports.CallExpression = function (node) {
node.arguments = [];
var nodes = build(args);
var nodes = build(args, file);
var first = nodes.shift();
if (nodes.length) {
@@ -100,7 +96,7 @@ exports.NewExpression = function (node, parent, file) {
var args = node.arguments;
if (!hasSpread(args)) return;
var nodes = build(args);
var nodes = build(args, file);
var first = nodes.shift();
if (nodes.length) {

View File

@@ -0,0 +1,102 @@
// https://github.com/zenparsing/es-abstract-refs
var util = require("../../util");
var t = require("../../types");
var container = function (parent, call, ret) {
if (t.isExpressionStatement(parent)) {
// we don't need to worry about return values
return call;
} else {
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, file, scope) {
var left = node.left;
if (!t.isVirtualPropertyExpression(left)) return;
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: value
});
if (temp) {
call = t.sequenceExpression([
t.assignmentExpression("=", temp, node.right),
call
]);
}
return container(parent, call, value);
};
exports.UnaryExpression = function (node, parent) {
var arg = node.argument;
if (!t.isVirtualPropertyExpression(arg)) return;
if (node.operator !== "delete") return;
var call = util.template("abstract-expression-delete", {
PROPERTY: arg.property,
OBJECT: arg.object
});
return container(parent, call, t.literal(true));
};
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: temp || callee.object
});
call.arguments = call.arguments.concat(node.arguments);
if (temp) {
return t.sequenceExpression([
t.assignmentExpression("=", temp, callee.object),
call
]);
} else {
return call;
}
};
exports.VirtualPropertyExpression = function (node) {
return util.template("abstract-expression-get", {
PROPERTY: node.property,
OBJECT: node.object
});
};

View File

@@ -2,21 +2,16 @@ var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var single = function (node) {
var single = function (node, file) {
var block = node.blocks[0];
var templateName = "array-expression-comprehension-map";
if (node.filter) templateName = "array-expression-comprehension-filter";
var right = block.right;
if (!t.isArrayExpression(right)) {
right = util.template("array-from", { VALUE: right });
}
var result = util.template(templateName, {
STATEMENT: node.body,
FILTER: node.filter,
ARRAY: right,
ARRAY: file.toArray(block.right),
KEY: block.left
});
@@ -79,7 +74,7 @@ exports.ComprehensionExpression = function (node, parent, file) {
if (node.generator) return;
if (node.blocks.length === 1) {
return single(node);
return single(node, file);
} else {
return multiple(node, file);
}

View File

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

View File

@@ -1,4 +1,4 @@
var arrayComprehension = require("./array-comprehension");
var arrayComprehension = require("./es7-array-comprehension");
var t = require("../../types");
exports.ComprehensionExpression = function (node) {

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

@@ -1,24 +0,0 @@
var util = require("../../util");
var t = require("../../types");
exports.Function = function (node, parent, file) {
if (!node.rest) return;
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)
});
template.declarations[0].init.arguments[0]._ignoreAliasFunctions = true;
node.body.body.unshift(template);
};

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

@@ -1,76 +1,78 @@
{
"ArrayExpression": ["elements"],
"ArrayPattern": ["elements"],
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
"AssignmentExpression": ["left", "right"],
"AwaitExpression": ["argument"],
"BinaryExpression": ["left", "right"],
"BlockStatement": ["body"],
"BreakStatement": ["label"],
"CallExpression": ["callee", "arguments"],
"CatchClause": ["param", "body"],
"ClassBody": ["body"],
"ClassDeclaration": ["id", "body", "superClass"],
"ClassExpression": ["id", "body", "superClass"],
"ComprehensionBlock": ["left", "right", "body"],
"ComprehensionExpression": ["filter", "blocks", "body"],
"ConditionalExpression": ["test", "consequent", "alternate"],
"ContinueStatement": ["label"],
"DebuggerStatement": [],
"DoWhileStatement": ["body", "test"],
"EmptyStatement": [],
"ExportBatchSpecifier": [],
"ExportDeclaration": ["declaration", "specifiers", "source"],
"ExportSpecifier": ["id", "name"],
"ExpressionStatement": ["expression"],
"File": ["program"],
"ForInStatement": ["left", "right", "body"],
"ForOfStatement": ["left", "right", "body"],
"ForStatement": ["init", "test", "update", "body"],
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body"],
"FunctionExpression": ["id", "params", "defaults", "rest", "body"],
"Identifier": [],
"IfStatement": ["test", "consequent", "alternate"],
"ImportBatchSpecifier": ["id"],
"ImportDeclaration": ["specifiers", "source"],
"ImportSpecifier": ["id", "name"],
"LabeledStatement": ["label", "body"],
"Literal": [],
"LogicalExpression": ["left", "right"],
"MemberExpression": ["object", "property"],
"MethodDefinition": ["key", "value"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"ParenthesizedExpression": ["expression"],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"SpreadElement": ["argument"],
"SwitchCase": ["test", "consequent"],
"SwitchStatement": ["discriminant", "cases"],
"TaggedTemplateExpression": ["tag", "quasi"],
"TemplateElement": [],
"TemplateLiteral": ["quasis", "expressions"],
"ThisExpression": [],
"ThrowStatement": ["argument"],
"TryStatement": ["block", "handlers", "handler", "guardedHandlers", "finalizer"],
"UnaryExpression": ["argument"],
"UpdateExpression": ["argument"],
"VariableDeclaration": ["declarations"],
"VariableDeclarator": ["id", "init"],
"WhileStatement": ["test", "body"],
"WithStatement": ["object", "body"],
"XJSAttribute": ["name", "value"],
"XJSClosingElement": ["name"],
"XJSElement": ["openingElement", "closingElement", "children"],
"XJSEmptyExpression": [],
"XJSExpressionContainer": ["expression"],
"XJSIdentifier": [],
"XJSMemberExpression": ["object", "property"],
"XJSNamespacedName": ["namespace", "name"],
"XJSOpeningElement": ["name", "attributes"],
"XJSSpreadAttribute": ["argument"],
"YieldExpression": ["argument"]
"ArrayExpression": ["elements"],
"ArrayPattern": ["elements"],
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
"AssignmentExpression": ["left", "right"],
"AwaitExpression": ["argument"],
"BinaryExpression": ["left", "right"],
"BlockStatement": ["body"],
"BreakStatement": ["label"],
"CallExpression": ["callee", "arguments"],
"CatchClause": ["param", "body"],
"ClassBody": ["body"],
"ClassDeclaration": ["id", "body", "superClass"],
"ClassExpression": ["id", "body", "superClass"],
"ComprehensionBlock": ["left", "right", "body"],
"ComprehensionExpression": ["filter", "blocks", "body"],
"ConditionalExpression": ["test", "consequent", "alternate"],
"ContinueStatement": ["label"],
"DebuggerStatement": [],
"DoWhileStatement": ["body", "test"],
"EmptyStatement": [],
"ExportBatchSpecifier": [],
"ExportDeclaration": ["declaration", "specifiers", "source"],
"ExportSpecifier": ["id", "name"],
"ExpressionStatement": ["expression"],
"File": ["program"],
"ForInStatement": ["left", "right", "body"],
"ForOfStatement": ["left", "right", "body"],
"ForStatement": ["init", "test", "update", "body"],
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body"],
"FunctionExpression": ["id", "params", "defaults", "rest", "body"],
"Identifier": [],
"IfStatement": ["test", "consequent", "alternate"],
"ImportBatchSpecifier": ["id"],
"ImportDeclaration": ["specifiers", "source"],
"ImportSpecifier": ["id", "name"],
"LabeledStatement": ["label", "body"],
"Literal": [],
"LogicalExpression": ["left", "right"],
"MemberExpression": ["object", "property"],
"MethodDefinition": ["key", "value"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"ParenthesizedExpression": ["expression"],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"SpreadElement": ["argument"],
"SpreadProperty": ["argument"],
"SwitchCase": ["test", "consequent"],
"SwitchStatement": ["discriminant", "cases"],
"TaggedTemplateExpression": ["tag", "quasi"],
"TemplateElement": [],
"TemplateLiteral": ["quasis", "expressions"],
"ThisExpression": [],
"ThrowStatement": ["argument"],
"TryStatement": ["block", "handlers", "handler", "guardedHandlers", "finalizer"],
"UnaryExpression": ["argument"],
"UpdateExpression": ["argument"],
"VariableDeclaration": ["declarations"],
"VariableDeclarator": ["id", "init"],
"VirtualPropertyExpression": ["object", "property"],
"WhileStatement": ["test", "body"],
"WithStatement": ["object", "body"],
"XJSAttribute": ["name", "value"],
"XJSClosingElement": ["name"],
"XJSElement": ["openingElement", "closingElement", "children"],
"XJSEmptyExpression": [],
"XJSExpressionContainer": ["expression"],
"XJSIdentifier": [],
"XJSMemberExpression": ["object", "property"],
"XJSNamespacedName": ["namespace", "name"],
"XJSOpeningElement": ["name", "attributes"],
"XJSSpreadAttribute": ["argument"],
"YieldExpression": ["argument"]
}

View File

@@ -38,9 +38,9 @@ exports.list = function (val) {
};
exports.regexify = function (val) {
if (!val) return new RegExp;
if (!val) return new RegExp(/.^/);
if (_.isArray(val)) val = val.join("|");
if (_.isString(val)) return new RegExp(val || "");
if (_.isString(val)) return new RegExp(val);
if (_.isRegExp(val)) return val;
throw new TypeError("illegal type for regexify");
};

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.13.0",
"version": "1.13.11",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -40,14 +40,14 @@
"fs-readdir-recursive": "0.1.0",
"lodash": "2.4.1",
"mkdirp": "0.5.0",
"es6-shim": "0.20.3",
"es6-shim": "0.21.0",
"es6-symbol": "0.1.1",
"regexpu": "0.3.0",
"source-map": "0.1.40",
"chokidar": "0.11.1",
"source-map-support": "0.2.8",
"esutils": "1.1.4",
"acorn-6to5": "0.9.1-3",
"esutils": "1.1.6",
"acorn-6to5": "0.9.1-7",
"estraverse": "1.8.0",
"private": "0.1.6"
},

View File

@@ -1,4 +1,3 @@
foo, bar;
foo,
bar;
foo, bar;

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,7 +0,0 @@
"use strict";
var arr = Array.from(nums).filter(function (i) {
return i > 1;
}).map(function (i) {
return i * i;
});

View File

@@ -1,5 +0,0 @@
"use strict";
var arr = Array.from(nums).map(function (i) {
return i * i;
});

View File

@@ -1,14 +0,0 @@
"use strict";
var _ref = ["hello", [", ", "junk"], ["world"]];
var _ref2 = Array.from(_ref);
var a = _ref2[0];
var _ref3 = Array.from(_ref2[1]);
var b = _ref3[0];
var _ref4 = Array.from(_ref2[2]);
var c = _ref4[0];
var d = _ref2[3];

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

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

View File

@@ -1,8 +0,0 @@
"use strict";
var _ref = f();
var _ref2 = Array.from(_ref);
a = _ref2[0];
b = _ref2[1];

View File

@@ -1,14 +0,0 @@
"use strict";
var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
var _ref2 = Array.from(_ref);
var a = _ref2[1];
var _ref3 = Array.from(_ref2[2]);
var b = _ref3[0];
var _ref4 = Array.from(_ref2[3]);
var c = _ref4[0];
var d = _ref2[4];

View File

@@ -1,8 +0,0 @@
"use strict";
var _ref = [1, 2];
var _ref2 = Array.from(_ref);
this.foo = _ref2[0];
this.bar = _ref2[1];

View File

@@ -1,10 +0,0 @@
"use strict";
var _ref = Array.from(rect.topLeft);
var x1 = _ref[0];
var y1 = _ref[1];
var _ref2 = Array.from(rect.bottomRight);
var x2 = _ref2[0];
var y2 = _ref2[1];

Some files were not shown because too many files have changed in this diff Show More