put experimental ES7 features behind a flag --experimental and experimental option
This commit is contained in:
parent
8b46cce466
commit
bd91bbee71
@ -1,3 +1,7 @@
|
|||||||
|
# 1.12.27
|
||||||
|
|
||||||
|
* Put experimental ES7 features behind a flag `--experimental` and `experimental` option.
|
||||||
|
|
||||||
# 1.12.26
|
# 1.12.26
|
||||||
|
|
||||||
* Support computed property destructuring.
|
* Support computed property destructuring.
|
||||||
|
|||||||
@ -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("-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("-w, --watch", "Recompile files on changes");
|
||||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
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("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||||
@ -87,11 +88,12 @@ if (errors.length) {
|
|||||||
|
|
||||||
exports.opts = {
|
exports.opts = {
|
||||||
sourceMapName: commander.outFile,
|
sourceMapName: commander.outFile,
|
||||||
|
amdModuleIds: commander.amdModuleIds,
|
||||||
|
experimental: commander.experimental,
|
||||||
blacklist: commander.blacklist,
|
blacklist: commander.blacklist,
|
||||||
whitelist: commander.whitelist,
|
whitelist: commander.whitelist,
|
||||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||||
comments: !commander.removeComments,
|
comments: !commander.removeComments,
|
||||||
amdModuleIds: commander.amdModuleIds,
|
|
||||||
runtime: commander.runtime,
|
runtime: commander.runtime,
|
||||||
modules: commander.modules
|
modules: commander.modules
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,10 +8,11 @@ var util = require("../lib/6to5/util");
|
|||||||
var vm = require("vm");
|
var vm = require("vm");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
commander.option("-e, --eval [script]", "evaluate script");
|
commander.option("-e, --eval [script]", "Evaluate script");
|
||||||
commander.option("-p, --print", "evaluate script and print result");
|
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("-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("-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");
|
var pkg = require("../package.json");
|
||||||
commander.version(pkg.version);
|
commander.version(pkg.version);
|
||||||
@ -20,17 +21,11 @@ commander.parse(process.argv);
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var registerOpts = {};
|
to5.register({
|
||||||
|
experimental: commander.experimental,
|
||||||
if (commander.ignore) {
|
extensions: commander.extensions,
|
||||||
registerOpts.ignoreRegex = new RegExp(commander.ignore);
|
ignore: commander.ignore
|
||||||
}
|
});
|
||||||
|
|
||||||
if (commander.extensions && commander.extensions.length) {
|
|
||||||
registerOpts.extensions = commander.extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
to5.register(registerOpts);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# Features
|
# Features
|
||||||
|
|
||||||
## Array comprehension
|
## Array comprehension ([experimental](usage.md#experimental))
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
|
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
|
```javascript
|
||||||
async function chainAnimationsAsync(elem, animations) {
|
async function chainAnimationsAsync(elem, animations) {
|
||||||
@ -150,7 +150,7 @@ for (var n of fibonacci()) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generator comprehension
|
## Generator comprehension ([experimental](usage.md#experimental))
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var nums = [1, 2, 3, 4, 5, 6];
|
var nums = [1, 2, 3, 4, 5, 6];
|
||||||
|
|||||||
@ -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)
|
## [Features](features.md)
|
||||||
|
|
||||||
- [Array comprehension](features.md#array-comprehension)
|
- [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental))
|
||||||
- [Async functions](features.md#async-functions)
|
- [Async functions](features.md#async-functions) ([experimental](usage.md#experimental))
|
||||||
- [Arrow functions](features.md#arrow-functions)
|
- [Arrow functions](features.md#arrow-functions)
|
||||||
- [Classes](features.md#classes)
|
- [Classes](features.md#classes)
|
||||||
- [Computed property names](features.md#computed-property-names)
|
- [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)
|
- [Destructuring](features.md#destructuring)
|
||||||
- [For-of](features.md#for-of)
|
- [For-of](features.md#for-of)
|
||||||
- [Generators](features.md#generators)
|
- [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)
|
- [Let scoping](features.md#let-scoping)
|
||||||
- [Modules](features.md#modules)
|
- [Modules](features.md#modules)
|
||||||
- [Numeric literals](features.md#numeric-literals)
|
- [Numeric literals](features.md#numeric-literals)
|
||||||
|
|||||||
12
doc/usage.md
12
doc/usage.md
@ -135,7 +135,11 @@ to5.transformFile("filename.js", options, function (err, result) {
|
|||||||
|
|
||||||
// Output comments in generated output
|
// Output comments in generated output
|
||||||
// Default: true
|
// Default: true
|
||||||
comments: false
|
comments: false,
|
||||||
|
|
||||||
|
// Enable support for experimental ES7 features
|
||||||
|
// Default: false
|
||||||
|
experimental: true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -181,3 +185,9 @@ require("6to5/register")({
|
|||||||
extensions: [".js", ".es6"]
|
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).
|
||||||
|
|||||||
@ -25,15 +25,16 @@ File.normaliseOptions = function (opts) {
|
|||||||
opts = _.cloneDeep(opts || {});
|
opts = _.cloneDeep(opts || {});
|
||||||
|
|
||||||
_.defaults(opts, {
|
_.defaults(opts, {
|
||||||
whitespace: true,
|
experimental: false,
|
||||||
blacklist: [],
|
whitespace: true,
|
||||||
whitelist: [],
|
blacklist: [],
|
||||||
sourceMap: false,
|
whitelist: [],
|
||||||
comments: true,
|
sourceMap: false,
|
||||||
filename: "unknown",
|
comments: true,
|
||||||
modules: "common",
|
filename: "unknown",
|
||||||
runtime: false,
|
modules: "common",
|
||||||
code: true
|
runtime: false,
|
||||||
|
code: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// normalise windows path separators to unix
|
// normalise windows path separators to unix
|
||||||
|
|||||||
@ -57,24 +57,25 @@ blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var ignoreRegex = /node_modules/;
|
var transformOpts = {};
|
||||||
|
var ignoreRegex = /node_modules/;
|
||||||
var onlyRegex;
|
var onlyRegex;
|
||||||
var whitelist = [];
|
var whitelist = [];
|
||||||
var exts = {};
|
var exts = {};
|
||||||
var maps = {};
|
var maps = {};
|
||||||
var old = require.extensions[".js"];
|
var old = require.extensions[".js"];
|
||||||
|
|
||||||
var loader = function (m, filename) {
|
var loader = function (m, filename) {
|
||||||
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
|
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
|
||||||
return old.apply(this, arguments);
|
return old.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = to5.transformFileSync(filename, {
|
var result = to5.transformFileSync(filename, _.extend({
|
||||||
whitelist: whitelist,
|
whitelist: whitelist,
|
||||||
blacklist: blacklist,
|
blacklist: blacklist,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
modules: "commonInterop"
|
modules: "commonInterop"
|
||||||
});
|
}, transformOpts));
|
||||||
|
|
||||||
maps[filename] = result.map;
|
maps[filename] = result.map;
|
||||||
|
|
||||||
@ -107,6 +108,5 @@ module.exports = function (opts) {
|
|||||||
|
|
||||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||||
|
|
||||||
if (opts.blacklist) blacklist = util.arrayify(opts.blacklist);
|
_.extend(transformOpts, opts);
|
||||||
if (opts.whitelist) whitelist = util.arrayify(opts.whitelist);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -218,7 +218,7 @@ exports.parse = function (opts, code, callback) {
|
|||||||
var ast = acorn.parse(code, {
|
var ast = acorn.parse(code, {
|
||||||
allowReturnOutsideFunction: true,
|
allowReturnOutsideFunction: true,
|
||||||
preserveParens: true,
|
preserveParens: true,
|
||||||
ecmaVersion: Infinity,
|
ecmaVersion: opts.experimental ? 7 : 6,
|
||||||
strictMode: true,
|
strictMode: true,
|
||||||
onComment: comments,
|
onComment: comments,
|
||||||
locations: true,
|
locations: true,
|
||||||
|
|||||||
3
test/fixtures/transformation/array-comprehension/options.json
vendored
Normal file
3
test/fixtures/transformation/array-comprehension/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"experimental": true
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"asyncExec": true
|
"asyncExec": true,
|
||||||
|
"experimental": true
|
||||||
}
|
}
|
||||||
|
|||||||
3
test/fixtures/transformation/generator-comprehension/options.json
vendored
Normal file
3
test/fixtures/transformation/generator-comprehension/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"experimental": true
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user