Compare commits

...

28 Commits

Author SHA1 Message Date
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
Sebastian McKenzie
5a96c2e015 v1.13.0 2014-11-22 23:46:00 +11:00
Sebastian McKenzie
43390c0d1f add experimental usage note about proposal changes 2014-11-22 23:45:05 +11:00
Sebastian McKenzie
d166656149 add constructor spread caveat and add additional Array.from cases 2014-11-22 23:44:47 +11:00
Sebastian McKenzie
acc4d289e4 link straight to caveats in no runtime on doc index 2014-11-22 23:44:28 +11:00
Sebastian McKenzie
717e6df407 use Array.from on single block array comprehensions - closes #199 2014-11-22 23:44:12 +11:00
Sebastian McKenzie
286404c6f2 update changelog for 1.13.0 2014-11-22 23:33:06 +11:00
Sebastian McKenzie
f191fd7883 update #203 test 2014-11-22 23:32:03 +11:00
Sebastian McKenzie
74f36cfaa0 Merge pull request #202 from RReverser/webworker-runtime
Fix runtime injection in Web Worker.
2014-11-22 23:29:07 +11:00
Sebastian McKenzie
71aed8b269 Merge branch 'ctor-spread-speedup' of https://github.com/RReverser/6to5 2014-11-22 23:28:06 +11:00
Sebastian McKenzie
9e6b0b45b3 Revert "Merge pull request #203 from RReverser/ctor-spread-speedup"
This reverts commit 714ca9fbc8, reversing
changes made to d50d4972a7.
2014-11-22 23:27:39 +11:00
Sebastian McKenzie
7bbb3725d4 bump next release version 2014-11-22 23:26:39 +11:00
Sebastian McKenzie
1210c92405 remove hound.yml 2014-11-22 23:26:39 +11:00
Sebastian McKenzie
714ca9fbc8 Merge pull request #203 from RReverser/ctor-spread-speedup
Speed up constructor spreads.
2014-11-22 23:22:53 +11:00
Ingvar Stepanyan
60713f0e5f Speed up constructor spreads.
Replace slow .bind with manual .create+.apply.
Gives up to 19x speed up depending on browser.

http://jsperf.com/apply-constructor
2014-11-22 14:22:50 +02:00
Ingvar Stepanyan
f1f5f8bb27 Speed up constructor spreads.
Replace slow .bind with manual .create+.apply.
Gives up to 19x speed up depending on browser.

http://jsperf.com/apply-constructor
2014-11-22 14:20:55 +02:00
Ingvar Stepanyan
a69f095720 Fix runtime injection in Web Worker.
Web Workers don't have `window` object but they have `self`
(which is available in regular windows as well).
2014-11-22 14:14:42 +02:00
Sebastian McKenzie
d50d4972a7 use experimental option in generation tests 2014-11-21 19:40:05 +11:00
Sebastian McKenzie
bd91bbee71 put experimental ES7 features behind a flag --experimental and experimental option 2014-11-21 19:36:35 +11:00
Sebastian McKenzie
8b46cce466 v1.12.26 2014-11-21 17:10:54 +11:00
Sebastian McKenzie
defa9108bd support computed property destructuring 2014-11-21 17:09:31 +11:00
Sebastian McKenzie
6b1d9b49b7 use generateUidIdentifier over the long form 2014-11-21 17:09:15 +11:00
Sebastian McKenzie
4e333cf357 add arrayify and regexify tests, add destructuring assignment expression statement only test 2014-11-21 17:08:56 +11:00
61 changed files with 354 additions and 154 deletions

View File

@@ -1,3 +0,0 @@
java_script:
enabled: true
config_file: .jshintrc

View File

@@ -1,3 +1,22 @@
# 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 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
* Support computed property destructuring.
# 1.12.25
* Update `acorn-6to5`, `ast-types`, `es6-shim`, `chokidar`, `estraverse` and `private`.

View File

@@ -11,6 +11,7 @@ commander.option("-s, --source-maps", "Save source map alongside the compiled co
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
commander.option("-w, --watch", "Recompile files on changes");
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
@@ -87,11 +88,12 @@ if (errors.length) {
exports.opts = {
sourceMapName: commander.outFile,
amdModuleIds: commander.amdModuleIds,
experimental: commander.experimental,
blacklist: commander.blacklist,
whitelist: commander.whitelist,
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
comments: !commander.removeComments,
amdModuleIds: commander.amdModuleIds,
runtime: commander.runtime,
modules: commander.modules
};

View File

@@ -8,10 +8,11 @@ var util = require("../lib/6to5/util");
var vm = require("vm");
var _ = require("lodash");
commander.option("-e, --eval [script]", "evaluate script");
commander.option("-p, --print", "evaluate script and print result");
commander.option("-i, --ignore [regex]", "ignore all files that match this regex when using the require hook");
commander.option("-x, --extensions [extensions]", "list of extensions to hook into [.es6,.js]", util.list);
commander.option("-e, --eval [script]", "Evaluate script");
commander.option("-p, --print", "Evaluate script and print result");
commander.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
var pkg = require("../package.json");
commander.version(pkg.version);
@@ -20,17 +21,11 @@ commander.parse(process.argv);
//
var registerOpts = {};
if (commander.ignore) {
registerOpts.ignoreRegex = new RegExp(commander.ignore);
}
if (commander.extensions && commander.extensions.length) {
registerOpts.extensions = commander.extensions;
}
to5.register(registerOpts);
to5.register({
experimental: commander.experimental,
extensions: commander.extensions,
ignore: commander.ignore
});
//

View File

@@ -5,6 +5,16 @@
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.isArray` and `Array.from`.
## Classes
Built-in classes such as `Date`, `Array` and `DOM` cannot be subclassed due to
@@ -31,13 +41,13 @@ 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.
### Array destructuring / Spread
An [ES6 polyfill](polyfill.md) is required for spread and array destructuring.
More specifically a polyfill for `Array.from`.

View File

@@ -1,6 +1,6 @@
# Features
## Array comprehension
## Array comprehension ([experimental](usage.md#experimental))
```javascript
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
@@ -31,7 +31,7 @@ var bob = {
};
```
## Async functions
## Async functions ([experimental](usage.md#experimental))
```javascript
async function chainAnimationsAsync(elem, animations) {
@@ -150,7 +150,7 @@ for (var n of fibonacci()) {
}
```
## Generator comprehension
## Generator comprehension ([experimental](usage.md#experimental))
```javascript
var nums = [1, 2, 3, 4, 5, 6];

View File

@@ -3,7 +3,7 @@
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
- **Extensible** - with a large range of [plugins](plugins.md) and **browser support**.
- **Lossless** - **source map support** so you can debug your compiled code with ease.
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](caveats.md#generators).
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](caveats.md).
## Installation
@@ -31,8 +31,8 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
## [Features](features.md)
- [Array comprehension](features.md#array-comprehension)
- [Async functions](features.md#async-functions)
- [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)
- [Classes](features.md#classes)
- [Computed property names](features.md#computed-property-names)
@@ -41,7 +41,7 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
- [Destructuring](features.md#destructuring)
- [For-of](features.md#for-of)
- [Generators](features.md#generators)
- [Generator comprehension](features.md#generator-comprehension)
- [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)

View File

@@ -135,7 +135,11 @@ to5.transformFile("filename.js", options, function (err, result) {
// Output comments in generated output
// Default: true
comments: false
comments: false,
// Enable support for experimental ES7 features
// Default: false
experimental: true
}
```
@@ -181,3 +185,11 @@ require("6to5/register")({
extensions: [".js", ".es6"]
});
```
## Experimental
6to5 also has experimental support for ES7 proposals. You can enable this with
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.

View File

@@ -19,21 +19,22 @@ function File(opts) {
}
File.declarations = ["extends", "class-props", "slice", "apply-constructor",
"tagged-template-literal", "interop-require"];
"tagged-template-literal", "interop-require", "to-array"];
File.normaliseOptions = function (opts) {
opts = _.cloneDeep(opts || {});
_.defaults(opts, {
whitespace: true,
blacklist: [],
whitelist: [],
sourceMap: false,
comments: true,
filename: "unknown",
modules: "common",
runtime: false,
code: true
experimental: false,
whitespace: true,
blacklist: [],
whitelist: [],
sourceMap: false,
comments: true,
filename: "unknown",
modules: "common",
runtime: false,
code: true
});
// normalise windows path separators to unix
@@ -69,6 +70,14 @@ File.normaliseOptions = function (opts) {
return opts;
};
File.prototype.toArray = function (node) {
if (t.isArrayExpression(node)) {
return node;
} else {
return t.callExpression(this.addDeclaration("to-array"), [node]);
}
};
File.prototype.getModuleFormatter = function (type) {
var ModuleFormatter = _.isFunction(type) ? type : transform.moduleFormatters[type];

View File

@@ -57,24 +57,25 @@ blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
//
var ignoreRegex = /node_modules/;
var transformOpts = {};
var ignoreRegex = /node_modules/;
var onlyRegex;
var whitelist = [];
var exts = {};
var maps = {};
var old = require.extensions[".js"];
var whitelist = [];
var exts = {};
var maps = {};
var old = require.extensions[".js"];
var loader = function (m, filename) {
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
return old.apply(this, arguments);
}
var result = to5.transformFileSync(filename, {
var result = to5.transformFileSync(filename, _.extend({
whitelist: whitelist,
blacklist: blacklist,
sourceMap: true,
modules: "commonInterop"
});
}, transformOpts));
maps[filename] = result.map;
@@ -107,6 +108,5 @@ module.exports = function (opts) {
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
if (opts.blacklist) blacklist = util.arrayify(opts.blacklist);
if (opts.whitelist) whitelist = util.arrayify(opts.whitelist);
_.extend(transformOpts, opts);
};

View File

@@ -8,15 +8,13 @@ module.exports = function (namespace) {
namespace = t.identifier(t.toIdentifier(namespace || "to5Runtime"));
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, []))]);
body.push(util.template("self-global", true));
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
t.assignmentExpression("=", t.memberExpression(t.identifier("self"), namespace), t.objectExpression([]))
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
)
]));

View File

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

View File

@@ -1 +1 @@
var self = typeof global === "undefined" ? window : global;
typeof global === "undefined" ? self : global

View File

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

View File

@@ -78,7 +78,7 @@ AMDFormatter.prototype._push = function (node) {
if (ids[id]) {
return ids[id];
} else {
return this.ids[id] = t.identifier(this.file.generateUid(id));
return this.ids[id] = this.file.generateUidIdentifier(id);
}
};

View File

@@ -2,7 +2,7 @@ var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var singleArrayExpression = function (node) {
var single = function (node, file) {
var block = node.blocks[0];
var templateName = "array-expression-comprehension-map";
@@ -11,7 +11,7 @@ var singleArrayExpression = function (node) {
var result = util.template(templateName, {
STATEMENT: node.body,
FILTER: node.filter,
ARRAY: block.right,
ARRAY: file.toArray(block.right),
KEY: block.left
});
@@ -25,7 +25,7 @@ var singleArrayExpression = function (node) {
};
var multiple = function (node, file) {
var uid = file.generateUid("arr");
var uid = file.generateUidIdentifier("arr");
var container = util.template("array-comprehension-container", {
KEY: uid
@@ -73,8 +73,8 @@ exports._build = function (node, buildBody) {
exports.ComprehensionExpression = function (node, parent, file) {
if (node.generator) return;
if (node.blocks.length === 1 && t.isArrayExpression(node.blocks[0].right)) {
return singleArrayExpression(node);
if (node.blocks.length === 1) {
return single(node, file);
} else {
return multiple(node, file);
}

View File

@@ -1,6 +1,5 @@
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var t = require("../../types");
var _ = require("lodash");
var buildVariableAssign = function (kind, id, init) {
if (kind === false) {
@@ -27,7 +26,7 @@ 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);
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
if (t.isPattern(pattern2)) {
push(opts, nodes, pattern2, patternId2);
@@ -38,11 +37,9 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
};
var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var _parentId = t.identifier(opts.file.generateUid("ref", opts.scope));
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 +49,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)]);

View File

@@ -19,7 +19,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
}
var node2 = util.template("for-of", {
ITERATOR_KEY: file.generateUid("iterator", scope),
ITERATOR_KEY: file.generateUidIdentifier("iterator", scope),
STEP_KEY: stepKey,
OBJECT: node.right
});

View File

@@ -129,7 +129,7 @@ LetScoping.prototype.run = function () {
// build a call and a unique id that we can assign the return value to
var call = t.callExpression(fn, params);
var ret = t.identifier(this.file.generateUid("ret", this.scope));
var ret = this.file.generateUidIdentifier("ret", this.scope);
var hasYield = traverse.hasType(fn.body, "YieldExpression", t.FUNCTION_TYPES);
if (hasYield) {
@@ -445,7 +445,7 @@ LetScoping.prototype.buildHas = function (ret, call) {
if (has.hasBreak || has.hasContinue) {
// ensure that the parent has a label as we're building a switch and we
// need to be able to access it
var label = forParent.label = forParent.label || t.identifier(this.file.generateUid("loop", this.scope));
var label = forParent.label = forParent.label || this.file.generateUidIdentifier("loop", this.scope);
if (has.hasBreak) {
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));

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,11 +41,11 @@ 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;
@@ -60,7 +53,7 @@ exports.ArrayExpression = function (node) {
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 +61,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 +93,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

@@ -218,7 +218,7 @@ exports.parse = function (opts, code, callback) {
var ast = acorn.parse(code, {
allowReturnOutsideFunction: true,
preserveParens: true,
ecmaVersion: Infinity,
ecmaVersion: opts.experimental ? 7 : 6,
strictMode: true,
onComment: comments,
locations: true,

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.12.25",
"version": "1.13.2",
"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.4",
"acorn-6to5": "0.9.1-3",
"acorn-6to5": "0.9.1-4",
"estraverse": "1.8.0",
"private": "0.1.6"
},

View File

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

View File

@@ -0,0 +1 @@
var arr = [for (i of nums) if (i > 1) i * i];

View File

@@ -0,0 +1,11 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var arr = _toArray(nums).filter(function (i) {
return i > 1;
}).map(function (i) {
return i * i;
});

View File

@@ -0,0 +1 @@
var arr = [for (i of nums) i * i];

View File

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

View File

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

View File

@@ -1,5 +1,9 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
@@ -24,11 +28,11 @@ var Test = (function (Foo) {
Foo.prototype.test.call(this);
foob(Foo);
Foo.call.apply(Foo, [this].concat(Array.from(arguments)));
Foo.call.apply(Foo, [this, "test"].concat(Array.from(arguments)));
Foo.call.apply(Foo, [this].concat(_toArray(arguments)));
Foo.call.apply(Foo, [this, "test"].concat(_toArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(Array.from(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(Array.from(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_toArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_toArray(arguments)));
};
_extends(Test, Foo);
@@ -38,8 +42,8 @@ var Test = (function (Foo) {
writable: true,
value: function () {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(Array.from(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(Array.from(arguments)));
Foo.foo.call.apply(Foo.foo, [this].concat(_toArray(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_toArray(arguments)));
}
}
}, {
@@ -47,8 +51,8 @@ var Test = (function (Foo) {
writable: true,
value: function () {
Foo.prototype.test.call(this);
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(Array.from(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(Array.from(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_toArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_toArray(arguments)));
}
}
});

View File

@@ -1,14 +1,18 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = [1, 2];
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var a = _ref2[0];
var b = _ref2[1];
var _ref3 = [3, 4];
var _ref4 = Array.from(_ref3);
var _ref4 = _toArray(_ref3);
var c = _ref4[0];
var d = _ref4[1];

View File

@@ -1,14 +1,18 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = ["hello", [", ", "junk"], ["world"]];
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var a = _ref2[0];
var _ref3 = Array.from(_ref2[1]);
var _ref3 = _toArray(_ref2[1]);
var b = _ref3[0];
var _ref4 = Array.from(_ref2[2]);
var _ref4 = _toArray(_ref2[2]);
var c = _ref4[0];
var d = _ref2[3];

View File

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

View File

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

View File

@@ -1,8 +1,12 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = f();
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
a = _ref2[0];
b = _ref2[1];

View File

@@ -1,14 +1,18 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var a = _ref2[1];
var _ref3 = Array.from(_ref2[2]);
var _ref3 = _toArray(_ref2[2]);
var b = _ref3[0];
var _ref4 = Array.from(_ref2[3]);
var _ref4 = _toArray(_ref2[3]);
var c = _ref4[0];
var d = _ref2[4];

View File

@@ -1,7 +1,11 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
for (var _ref in obj) {
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var name = _ref2[0];
var value = _ref2[1];

View File

@@ -1,8 +1,12 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
for (var _iterator = this.test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var _ref = _step.value;
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var name = _ref2[0];
var before = _ref2[1];

View File

@@ -1,8 +1,12 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = [1, 2];
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
this.foo = _ref2[0];
this.bar = _ref2[1];

View File

@@ -1,10 +1,14 @@
"use strict";
var _ref = Array.from(rect.topLeft);
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _ref = _toArray(rect.topLeft);
var x1 = _ref[0];
var y1 = _ref[1];
var _ref2 = Array.from(rect.bottomRight);
var _ref2 = _toArray(rect.bottomRight);
var x2 = _ref2[0];
var y2 = _ref2[1];

View File

@@ -1,5 +1,9 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
function somethingAdvanced(_ref) {
var x1 = _ref.topLeft.x;
var y1 = _ref.topLeft.y;
@@ -16,12 +20,12 @@ function unpackObject(_ref2) {
console.log(unpackObject({ title: "title", author: "author" }));
var unpackArray = function (_ref3, _ref5) {
var _ref4 = Array.from(_ref3);
var _ref4 = _toArray(_ref3);
var a = _ref4[0];
var b = _ref4[1];
var c = _ref4[2];
var _ref6 = Array.from(_ref5);
var _ref6 = _toArray(_ref5);
var x = _ref6[0];
var y = _ref6[1];

View File

@@ -1,11 +1,15 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var isSorted = function (_ref) {
var _ref2 = Array.from(_ref);
var _ref2 = _toArray(_ref);
var x = _ref2[0];
var y = _ref2[1];
var wow = Array.from(_ref2).slice(2);
var wow = _toArray(_ref2).slice(2);
if (!zs.length) return true;
if (y > x) return isSorted(zs);

View File

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

View File

@@ -1,5 +1,5 @@
var Component = React.createClass({
render: function () {
return null;
return null;
}
});

View File

@@ -1,7 +1,11 @@
"use strict";
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
function foo() {
return bar.apply(null, ["test"].concat(Array.from(arguments)));
return bar.apply(null, ["test"].concat(_toArray(arguments)));
}
function bar(one, two, three) {

View File

@@ -1,3 +1,7 @@
"use strict";
var lyrics = Array.from(parts).concat(["head", "and", "toes"]);
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var lyrics = _toArray(parts).concat(["head", "and", "toes"]);

View File

@@ -1,3 +1,7 @@
"use strict";
var a = [b].concat(Array.from(c), [d]);
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var a = [b].concat(_toArray(c), [d]);

View File

@@ -1,3 +1,7 @@
"use strict";
var a = [b].concat(Array.from(c), [d, e], Array.from(f));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var a = [b].concat(_toArray(c), [d, e], _toArray(f));

View File

@@ -1,3 +1,7 @@
"use strict";
var lyrics = ["head", "and", "toes"].concat(Array.from(parts));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var lyrics = ["head", "and", "toes"].concat(_toArray(parts));

View File

@@ -1,3 +1,7 @@
"use strict";
obj[method].apply(obj, [foo, bar].concat(Array.from(args)));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
obj[method].apply(obj, [foo, bar].concat(_toArray(args)));

View File

@@ -1,3 +1,7 @@
"use strict";
obj[method].apply(obj, Array.from(args));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
obj[method].apply(obj, _toArray(args));

View File

@@ -1,4 +1,8 @@
"use strict";
foob.add.apply(foob, [foo, bar].concat(Array.from(numbers)));
foob.test.add.apply(foob.test, [foo, bar].concat(Array.from(numbers)));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
foob.add.apply(foob, [foo, bar].concat(_toArray(numbers)));
foob.test.add.apply(foob.test, [foo, bar].concat(_toArray(numbers)));

View File

@@ -1,4 +1,8 @@
"use strict";
foob.add.apply(foob, Array.from(numbers));
foob.test.add.apply(foob.test, Array.from(numbers));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
foob.add.apply(foob, _toArray(numbers));
foob.test.add.apply(foob.test, _toArray(numbers));

View File

@@ -1,3 +1,7 @@
"use strict";
add.apply(null, Array.from(numbers).concat([foo, bar]));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
add.apply(null, _toArray(numbers).concat([foo, bar]));

View File

@@ -1,3 +1,7 @@
"use strict";
add.apply(null, [foo].concat(Array.from(numbers), [bar]));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
add.apply(null, [foo].concat(_toArray(numbers), [bar]));

View File

@@ -1,3 +1,7 @@
"use strict";
add.apply(null, [foo, bar].concat(Array.from(numbers)));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
add.apply(null, [foo, bar].concat(_toArray(numbers)));

View File

@@ -1,3 +1,7 @@
"use strict";
add.apply(null, [foo].concat(Array.from(numbers), [bar, what], Array.from(test)));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
add.apply(null, [foo].concat(_toArray(numbers), [bar, what], _toArray(test)));

View File

@@ -1,3 +1,7 @@
"use strict";
add.apply(null, Array.from(numbers));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
add.apply(null, _toArray(numbers));

View File

@@ -1,12 +1,16 @@
"use strict";
var _applyConstructor = function (Constructor, args) {
var bindArgs = [null].concat(args);
var instance = Object.create(Constructor.prototype);
var Factory = Constructor.bind.apply(Constructor, bindArgs);
var result = Constructor.apply(instance, args);
return new Factory();
return result != null && (typeof result == "object" || typeof result == "function") ? result : instance;
};
_applyConstructor(Numbers, Array.from(nums));
_applyConstructor(Numbers, [1].concat(Array.from(nums)));
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
_applyConstructor(Numbers, _toArray(nums));
_applyConstructor(Numbers, [1].concat(_toArray(nums)));

View File

@@ -1,3 +1,7 @@
"use strict";
Array.from(foo);
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
_toArray(foo);

View File

@@ -26,7 +26,7 @@ _.each(helper.get("generation"), function (testSuite) {
var expect = task.expect;
var actual = task.actual;
var actualAst = util.parse({ filename: actual.loc }, actual.code);
var actualAst = util.parse({ filename: actual.loc, experimental: true }, actual.code);
var actualCode = generate(actualAst, null, actual.code).code;
chai.expect(actualCode).to.equal(expect.code, actual.loc + " !== " + expect.loc);

View File

@@ -3,8 +3,6 @@ var util = require("../lib/6to5/util");
var t = require("../lib/6to5/types");
suite("util", function () {
test("duplicate mutator map");
test("invalid template", function () {
assert.throws(function () {
util.template("invalid template");
@@ -45,6 +43,34 @@ suite("util", function () {
assert.deepEqual(util.list("foo,bar"), ["foo", "bar"]);
});
test("arrayify", function () {
assert.deepEqual(util.arrayify(undefined), []);
assert.deepEqual(util.arrayify(false), []);
assert.deepEqual(util.arrayify(null), []);
assert.deepEqual(util.arrayify(""), []);
assert.deepEqual(util.arrayify("foo"), ["foo"]);
assert.deepEqual(util.arrayify("foo,bar"), ["foo", "bar"]);
assert.deepEqual(util.arrayify(["foo", "bar"]), ["foo", "bar"]);
assert.throws(function () {
util.arrayify({});
}, /illegal type for arrayify/);
});
test("regexify", function () {
assert.deepEqual(util.regexify(undefined), /(?:)/);
assert.deepEqual(util.regexify(false), /(?:)/);
assert.deepEqual(util.regexify(null), /(?:)/);
assert.deepEqual(util.regexify(""), /(?:)/);
assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/);
assert.deepEqual(util.regexify("foobar"), /foobar/);
assert.deepEqual(util.regexify(/foobar/), /foobar/);
assert.throws(function () {
util.regexify({});
}, /illegal type for regexify/);
});
test("getIds");
test("toStatement");