Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
988ab0e823 | ||
|
|
e708394408 | ||
|
|
7c3ab8bc3c | ||
|
|
2b11a45117 | ||
|
|
d5666912d4 | ||
|
|
2eab56c38b | ||
|
|
888ab5473a | ||
|
|
5fe1c07d9a | ||
|
|
758a873894 | ||
|
|
e91926d094 | ||
|
|
5085b96753 | ||
|
|
66f67b92ce | ||
|
|
3c9fa13a1f | ||
|
|
5f21fc2f17 | ||
|
|
4bd4e4cdbe | ||
|
|
3c7b2d7872 | ||
|
|
5db757354a | ||
|
|
063b379d4f |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,3 +1,13 @@
|
||||
# 1.14.6
|
||||
|
||||
* Avoid ensuring a block on non-array node replacements.
|
||||
|
||||
# 1.14.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Fix JSON recursion error for unknown code generator node types.
|
||||
* Ensure that a statement is a block on block/statement types when replacing them with multiple nodes.
|
||||
|
||||
# 1.14.4
|
||||
|
||||
* Merge pretzel maps and method binding.
|
||||
|
||||
@@ -32,6 +32,7 @@ to5.register({
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, {
|
||||
modules: "commonInterop",
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"],
|
||||
experimental: commander.experimental
|
||||
|
||||
@@ -30,7 +30,9 @@ test.test();
|
||||
You can build a browser version of the compiler by running the following in the
|
||||
6to5 directory:
|
||||
|
||||
$ make build
|
||||
```sh
|
||||
$ make build
|
||||
```
|
||||
|
||||
This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
|
||||
|
||||
@@ -38,7 +40,9 @@ This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
|
||||
|
||||
To test 6to5 in your browser run:
|
||||
|
||||
$ make test-browser
|
||||
```sh
|
||||
$ make test-browser
|
||||
```
|
||||
|
||||
And open `test/browser.html` in your browser if it doesn't open automatically.
|
||||
|
||||
|
||||
@@ -19,12 +19,16 @@ how you want to use it.
|
||||
6to5 will simply compile your ES6+ script to ES5 if you pass it as an argument
|
||||
to the command-line tool `6to5`:
|
||||
|
||||
$ 6to5 script.js
|
||||
```sh
|
||||
$ 6to5 script.js
|
||||
```
|
||||
|
||||
If you have a file written using ES6+ and you just want to run it, `6to5-node`
|
||||
has you covered:
|
||||
|
||||
$ 6to5-node script.js
|
||||
```sh
|
||||
$ 6to5-node script.js
|
||||
```
|
||||
|
||||
And it doesn't end here! To see all the ways you can use 6to5, check out the
|
||||
[Usage](http://6to5.github.io/usage.html) page.
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
### CLI
|
||||
|
||||
$ 6to5 --modules common script.js
|
||||
```sh
|
||||
$ 6to5 --modules common script.js
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
@@ -17,13 +19,17 @@ to5.transform('import "foo";', { modules: "common" });
|
||||
|
||||
* [AMD](#amd)
|
||||
* [Common (Default)](#common-default)
|
||||
* [Common](#common)
|
||||
* [Common Interop](#common-interop)
|
||||
* [Ignore](#ignore)
|
||||
* [System](#system)
|
||||
* [UMD](#umd)
|
||||
|
||||
### Common (Default)
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules common
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -60,6 +66,10 @@ exports.default = test;
|
||||
|
||||
### Common interop
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules commonInterop
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -123,6 +133,10 @@ function foo() {
|
||||
|
||||
### AMD
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules amd
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -155,6 +169,10 @@ define("filename", ["exports", "foo"], function (exports, _foo) {})
|
||||
|
||||
### UMD
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules umd
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -187,6 +205,10 @@ export function bar() {
|
||||
|
||||
### Ignore
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules ignore
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -207,6 +229,10 @@ function bar() {
|
||||
|
||||
### System
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules system
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
@@ -244,7 +270,9 @@ System.register("bar", ["foo"], function (_export) {
|
||||
|
||||
You can alternatively specify module names instead of one of the built-in types.
|
||||
|
||||
$ 6to5 --modules custom-module-formatter
|
||||
```sh
|
||||
$ 6to5 --modules custom-module-formatter
|
||||
```
|
||||
|
||||
**node_modules/custom-module-formatter/index.js**
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ Simply use the following option if you're using the [Node API](usage.md#node):
|
||||
|
||||
or the following flag if you're using the [CLI](usage.md#cli):
|
||||
|
||||
$ 6to5 --runtime
|
||||
```ssh
|
||||
$ 6to5 --runtime
|
||||
```
|
||||
|
||||
Then just include the runtime before your generated code.
|
||||
|
||||
@@ -26,7 +28,9 @@ Then just include the runtime before your generated code.
|
||||
|
||||
You can get the runtime via either:
|
||||
|
||||
$ 6to5-runtime
|
||||
```sh
|
||||
$ 6to5-runtime
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
@@ -45,7 +49,9 @@ argument:
|
||||
require("6to5").runtime("myCustomNamespace");
|
||||
```
|
||||
|
||||
$ 6to5-runtime myCustomNamespace
|
||||
```sh
|
||||
$ 6to5-runtime myCustomNamespace
|
||||
```
|
||||
|
||||
See [Options - runtime](usage.md#options) for documentation on changing the
|
||||
reference in generated code.
|
||||
|
||||
@@ -18,7 +18,6 @@ to5.transform("code", { playground: true });
|
||||
|
||||
* [Memoization operator](#memoization-operator)
|
||||
* [Method binding](#method-binding)
|
||||
* [Pretzel map](#pretzel-map)
|
||||
|
||||
### Memoization assignment operator
|
||||
|
||||
@@ -48,7 +47,7 @@ var obj = {};
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
|
||||
```
|
||||
|
||||
### Method binding expression
|
||||
### Method binding
|
||||
|
||||
```javascript
|
||||
var fn = obj:method;
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
- [Gobble](https://github.com/gobblejs/gobble-6to5)
|
||||
- [Gulp](https://github.com/sindresorhus/gulp-6to5)
|
||||
- [Grunt](https://github.com/sindresorhus/grunt-6to5)
|
||||
- [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5
|
||||
- [Jade](https://github.com/Apoxx/jade-6to5)
|
||||
- [Jest](https://github.com/6to5/6to5-jest)
|
||||
- [JSXHint](https://github.com/STRML/JSXHint) (A wrapper around JSHint to allow linting of JSX files)
|
||||
- [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files
|
||||
- [Karma](https://github.com/shuhei/karma-6to5-preprocessor)
|
||||
- [Mocha](https://github.com/6to5/6to5-mocha)
|
||||
- [Rails](https://github.com/josh/sprockets-es6) or via [browserify-rails](https://github.com/6to5/6to5-rails)
|
||||
|
||||
@@ -12,5 +12,6 @@ To disable this behaviour add `react` to your blacklist:
|
||||
to5.transform("code", { blacklist: ["react"] });
|
||||
```
|
||||
|
||||
|
||||
$ 6to5 --blacklist react
|
||||
```sh
|
||||
$ 6to5 --blacklist react
|
||||
```
|
||||
|
||||
40
doc/usage.md
40
doc/usage.md
@@ -4,47 +4,67 @@
|
||||
|
||||
Compile the file `script.js` and output it to stdout.
|
||||
|
||||
$ 6to5 script.js
|
||||
```sh
|
||||
$ 6to5 script.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js`.
|
||||
|
||||
$ 6to5 script.js --out-file script-compiled.js
|
||||
```sh
|
||||
$ 6to5 script.js --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` and save a
|
||||
source map to `script-compiled.js.map`.
|
||||
|
||||
$ 6to5 script.js --source-maps --out-file script-compiled.js
|
||||
```sh
|
||||
$ 6to5 script.js --source-maps --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` with a source
|
||||
map embedded in a comment at the bottom.
|
||||
|
||||
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
|
||||
```sh
|
||||
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the entire `src` directory and output it to the `lib` directory.
|
||||
|
||||
$ 6to5 src --out-dir lib
|
||||
```sh
|
||||
$ 6to5 src --out-dir lib
|
||||
```
|
||||
|
||||
Compile the entire `src` directory and output it to the one concatenated file.
|
||||
|
||||
$ 6to5 src --out-file script-compiled.js
|
||||
```sh
|
||||
$ 6to5 src --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Pipe a file in via stdin and output it to `script-compiled.js`
|
||||
|
||||
$ 6to5 --out-file script-compiled.js < script.js
|
||||
```sh
|
||||
$ 6to5 --out-file script-compiled.js < script.js
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
Launch a repl.
|
||||
|
||||
$ 6to5-node
|
||||
```sh
|
||||
$ 6to5-node
|
||||
```
|
||||
|
||||
Evaluate code.
|
||||
|
||||
$ 6to5-node -e "class Test { }"
|
||||
```sh
|
||||
$ 6to5-node -e "class Test { }"
|
||||
```
|
||||
|
||||
Compile and run `test.js`.
|
||||
|
||||
$ 6to5-node test
|
||||
```sh
|
||||
$ 6to5-node test
|
||||
```
|
||||
|
||||
## Node
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
|
||||
this.printTrailingComments(node, parent);
|
||||
} else {
|
||||
throw new ReferenceError("unknown node " + node.type + " " + JSON.stringify(node));
|
||||
throw new ReferenceError("unknown node " + node.type);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
require("./polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var roadrunner = require('roadrunner');
|
||||
var util = require("./util");
|
||||
var to5 = require("./index");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
sourceMapSupport.install({
|
||||
@@ -61,22 +63,38 @@ var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var whitelist = [];
|
||||
var cache;
|
||||
var exts = {};
|
||||
var maps = {};
|
||||
var old = require.extensions[".js"];
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
var loader = function (m, filename) {
|
||||
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
|
||||
return old.apply(this, arguments);
|
||||
}
|
||||
|
||||
var result = to5.transformFileSync(filename, _.extend({
|
||||
var result;
|
||||
|
||||
if (cache && cache[filename].mtime === mtime(filename)) {
|
||||
result = cache[filename];
|
||||
}
|
||||
|
||||
result = result || to5.transformFileSync(filename, _.extend({
|
||||
whitelist: whitelist,
|
||||
blacklist: blacklist,
|
||||
sourceMap: true,
|
||||
modules: "commonInterop"
|
||||
}, transformOpts));
|
||||
|
||||
if (cache) {
|
||||
result.mtime = mtime(filename);
|
||||
cache[filename] = result;
|
||||
}
|
||||
|
||||
maps[filename] = result.map;
|
||||
|
||||
m._compile(result.code, filename);
|
||||
@@ -108,5 +126,8 @@ module.exports = function (opts) {
|
||||
|
||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||
|
||||
if (opts.cache) cache = roadrunner.get('6to5');
|
||||
if (opts.cache === false) cache = null;
|
||||
|
||||
_.extend(transformOpts, opts);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
exports.Property = function (node) {
|
||||
if (node.shorthand) node.shorthand = false;
|
||||
if (!node.shorthand) return;
|
||||
node.shorthand = false;
|
||||
};
|
||||
|
||||
@@ -64,7 +64,12 @@ exports.CallExpression = function (node, parent, file) {
|
||||
|
||||
node.arguments = [];
|
||||
|
||||
var nodes = build(args, file);
|
||||
var nodes;
|
||||
if (args.length === 1 && args[0].argument.name === 'arguments') {
|
||||
nodes = [args[0].argument];
|
||||
} else {
|
||||
nodes = build(args, file);
|
||||
}
|
||||
var first = nodes.shift();
|
||||
|
||||
if (nodes.length) {
|
||||
|
||||
@@ -50,6 +50,10 @@ function traverse(parent, callbacks, opts) {
|
||||
if (result != null) {
|
||||
updated = true;
|
||||
node = obj[key] = result;
|
||||
|
||||
if (_.isArray(result) && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
|
||||
t.ensureBlock(obj, key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ var addAssert = function (type, is) {
|
||||
};
|
||||
};
|
||||
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
|
||||
|
||||
//
|
||||
|
||||
t.VISITOR_KEYS = require("./visitor-keys");
|
||||
@@ -114,7 +116,7 @@ t.shallowEqual = function (actual, expected) {
|
||||
//
|
||||
|
||||
t.isDynamic = function (node) {
|
||||
if (t.isParenthesizedExpression(node)) {
|
||||
if (t.isParenthesizedExpression(node) || t.isExpressionStatement(node)) {
|
||||
return t.isDynamic(node.expression);
|
||||
} else if (t.isIdentifier(node) || t.isLiteral(node) || t.isThisExpression(node)) {
|
||||
return false;
|
||||
@@ -167,8 +169,9 @@ t.isValidIdentifier = function (name) {
|
||||
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
|
||||
};
|
||||
|
||||
t.ensureBlock = function (node) {
|
||||
node.body = t.toBlock(node.body, node);
|
||||
t.ensureBlock = function (node, key) {
|
||||
key = key || "body";
|
||||
node[key] = t.toBlock(node[key], node);
|
||||
};
|
||||
|
||||
t.toStatement = function (node, ignore) {
|
||||
|
||||
21
package.json
21
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.14.4",
|
||||
"version": "1.14.7",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -35,26 +35,27 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.9.1-11",
|
||||
"ast-types": "0.6.5",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
"es6-shim": "0.21.0",
|
||||
"es6-symbol": "0.1.1",
|
||||
"estraverse": "1.8.0",
|
||||
"esutils": "1.1.6",
|
||||
"fs-readdir-recursive": "0.1.0",
|
||||
"lodash": "2.4.1",
|
||||
"mkdirp": "0.5.0",
|
||||
"es6-shim": "0.21.0",
|
||||
"es6-symbol": "0.1.1",
|
||||
"private": "0.1.6",
|
||||
"regexpu": "0.3.0",
|
||||
"roadrunner": "^1.0.4",
|
||||
"source-map": "0.1.40",
|
||||
"chokidar": "0.11.1",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.6",
|
||||
"acorn-6to5": "0.9.1-10",
|
||||
"estraverse": "1.8.0",
|
||||
"private": "0.1.6"
|
||||
"source-map-support": "0.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.2",
|
||||
"matcha": "0.6.0",
|
||||
"mocha": "2.0.1",
|
||||
"mocha": "1.21.4",
|
||||
"uglify-js": "2.4.15",
|
||||
"browserify": "6.3.2",
|
||||
"rimraf": "2.2.8",
|
||||
|
||||
9
test/fixtures/transformation/es6-spread/arguments-array/actual.js
vendored
Normal file
9
test/fixtures/transformation/es6-spread/arguments-array/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
function foo() {
|
||||
return bar([...arguments]);
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
return [one, two, three];
|
||||
}
|
||||
|
||||
foo("foo", "bar");
|
||||
12
test/fixtures/transformation/es6-spread/arguments-array/expected.js
vendored
Normal file
12
test/fixtures/transformation/es6-spread/arguments-array/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
function foo() {
|
||||
return bar([].concat(_slice.call(arguments)));
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
return [one, two, three];
|
||||
}
|
||||
|
||||
foo("foo", "bar");
|
||||
9
test/fixtures/transformation/es6-spread/arguments-concat/actual.js
vendored
Normal file
9
test/fixtures/transformation/es6-spread/arguments-concat/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
function foo() {
|
||||
return bar("test", ...arguments);
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
return [one, two, three];
|
||||
}
|
||||
|
||||
foo("foo", "bar");
|
||||
12
test/fixtures/transformation/es6-spread/arguments-concat/expected.js
vendored
Normal file
12
test/fixtures/transformation/es6-spread/arguments-concat/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
function foo() {
|
||||
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
return [one, two, three];
|
||||
}
|
||||
|
||||
foo("foo", "bar");
|
||||
@@ -1,5 +1,5 @@
|
||||
function foo() {
|
||||
return bar("test", ...arguments);
|
||||
return bar(...arguments);
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
function foo() {
|
||||
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
|
||||
return bar.apply(null, arguments);
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
|
||||
Reference in New Issue
Block a user