Compare commits

..

18 Commits

Author SHA1 Message Date
Sebastian McKenzie
988ab0e823 v1.14.7 2014-12-04 10:18:57 +11:00
Sebastian McKenzie
e708394408 start fixing shorthand comment issue 2014-12-04 10:17:37 +11:00
Sebastian McKenzie
7c3ab8bc3c add isparta to docs/plugins 2014-12-04 10:17:28 +11:00
Sebastian McKenzie
2b11a45117 Add support for ExpressionStatement in t.isDynamic 2014-12-04 10:17:13 +11:00
Sebastian McKenzie
d5666912d4 Add cache option to 6to5-node 2014-12-04 10:17:04 +11:00
Sebastian McKenzie
2eab56c38b Merge pull request #240 from thejameskyle/arguments-spread
Only slice arguments when necessary - fixes #239
2014-12-03 12:28:14 +11:00
James Kyle
888ab5473a Only slice arguments when necessary - fixes #239 2014-12-02 16:46:48 -08:00
Sebastian McKenzie
5fe1c07d9a v1.14.6 2014-11-30 23:40:12 +11:00
Sebastian McKenzie
758a873894 avoid ensuring a block on non-array node replacements 2014-11-30 23:39:08 +11:00
Sebastian McKenzie
e91926d094 v1.14.5 2014-11-30 11:15:54 +11:00
Sebastian McKenzie
5085b96753 update 1.14.5 changelog 2014-11-30 11:12:36 +11:00
Sebastian McKenzie
66f67b92ce upgrade acorn-6to5 2014-11-30 11:10:58 +11:00
Sebastian McKenzie
3c9fa13a1f remove JSON.stringify of unknown generator node types 2014-11-30 11:10:58 +11:00
Sebastian McKenzie
5f21fc2f17 ensureBlock on multiple node replacements - fixes #229 2014-11-30 11:10:57 +11:00
Sebastian McKenzie
4bd4e4cdbe fix sh doc code blocks 2014-11-30 11:10:57 +11:00
Sebastian McKenzie
3c7b2d7872 Merge pull request #231 from thejameskyle/module-names
Add CLI commands for module docs
2014-11-30 10:52:42 +11:00
James Kyle
5db757354a Add CLI commands for module docs 2014-11-29 11:31:34 -08:00
Sebastian McKenzie
063b379d4f remove dead playground docs 2014-11-26 22:21:18 +11:00
23 changed files with 195 additions and 45 deletions

View File

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

View File

@@ -32,6 +32,7 @@ to5.register({
var _eval = function (code, filename) {
code = to5.transform(code, {
modules: "commonInterop",
filename: filename,
blacklist: ["useStrict"],
experimental: commander.experimental

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,3 +1,4 @@
exports.Property = function (node) {
if (node.shorthand) node.shorthand = false;
if (!node.shorthand) return;
node.shorthand = false;
};

View File

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

View File

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

View File

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

View File

@@ -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",

View File

@@ -0,0 +1,9 @@
function foo() {
return bar([...arguments]);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View 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");

View File

@@ -0,0 +1,9 @@
function foo() {
return bar("test", ...arguments);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View 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");

View File

@@ -1,5 +1,5 @@
function foo() {
return bar("test", ...arguments);
return bar(...arguments);
}
function bar(one, two, three) {

View File

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