Compare commits

..

59 Commits

Author SHA1 Message Date
Sebastian McKenzie
40a2d14c7c v1.14.13 2014-12-05 23:12:01 +11:00
Sebastian McKenzie
573283f260 fix bin/6to5 error message test 2014-12-05 23:11:04 +11:00
Sebastian McKenzie
0497860462 Fix linting error 2014-12-05 23:08:35 +11:00
Sebastian McKenzie
a173775fec 1.14.13 2014-12-05 23:07:21 +11:00
Sebastian McKenzie
c5214ffe70 enumerable es6 class methods 2014-12-05 23:06:36 +11:00
Sebastian McKenzie
3d62af004d fix bin/6to5-node code formatting 2014-12-05 23:06:17 +11:00
Sebastian McKenzie
d7af8c6261 whitespace after function assignment 2014-12-05 23:06:05 +11:00
Sebastian McKenzie
680c6b166a Fix let scoping to work with while loops 2014-12-05 23:05:47 +11:00
Sebastian McKenzie
5bad458b09 Fix tests 2014-12-05 23:05:20 +11:00
Sebastian McKenzie
055f894a88 Use stylish jshint reporter 2014-12-05 23:05:05 +11:00
Sebastian McKenzie
da8edecc09 v1.14.12 2014-12-05 10:57:27 +11:00
Sebastian McKenzie
cd6dea6480 fix version in changelog 2014-12-05 10:56:33 +11:00
Sebastian McKenzie
69d7ac0e0c 1.14.11 2014-12-05 10:54:25 +11:00
Sebastian McKenzie
dae46bfbfa DRY up isDynamic checks - add isDynamic check to spread - fixes #232 2014-12-05 10:53:46 +11:00
Sebastian McKenzie
b5b175c45a v1.14.11 2014-12-05 10:10:31 +11:00
Sebastian McKenzie
569c681c4f v1.14.10 2014-12-05 09:58:16 +11:00
Sebastian McKenzie
ed1e4a7820 fix changelog version 2014-12-05 09:57:14 +11:00
Sebastian McKenzie
b55f941dae v1.14.1 2014-12-05 09:56:36 +11:00
Sebastian McKenzie
a0219ef278 fix let scoping unneccesary override - fixes #245 2014-12-05 09:55:26 +11:00
Sebastian McKenzie
b9266b0c4c v1.14.10 2014-12-04 10:35:52 +11:00
Sebastian McKenzie
a1239e5f5a add ast return transform option 2014-12-04 10:34:52 +11:00
Sebastian McKenzie
2f279de7d1 v1.14.9 2014-12-04 10:31:08 +11:00
Sebastian McKenzie
c70b3586fb Remove roadrunner 2014-12-04 10:30:16 +11:00
Sebastian McKenzie
3928384c27 v1.14.8 2014-12-04 10:25:02 +11:00
Sebastian McKenzie
e469f7f589 fix require caching 2014-12-04 10:23:55 +11:00
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
Sebastian McKenzie
af42fe3d30 v1.14.4 2014-11-26 17:24:55 +11:00
Sebastian McKenzie
3c808fcef2 merge pretzel maps and method binding 2014-11-26 17:23:33 +11:00
Sebastian McKenzie
a29505f75d v1.14.3 2014-11-26 16:21:40 +11:00
Sebastian McKenzie
05942d17bf add 1.14.3 changelog 2014-11-26 16:19:15 +11:00
Sebastian McKenzie
be0d4b344b add playground pretzel maps 2014-11-26 16:17:27 +11:00
Sebastian McKenzie
f1a2401681 v1.14.2 2014-11-26 10:54:45 +11:00
Sebastian McKenzie
2d61672cdb add 1.14.2 changelog 2014-11-26 10:53:52 +11:00
Sebastian McKenzie
1b00ba21a1 fix commonInterop default export handling - fixes #223 2014-11-26 10:48:30 +11:00
Sebastian McKenzie
f8ea386f3c fix computed property literals - fixes #221 2014-11-26 10:47:23 +11:00
Sebastian McKenzie
2527fffbad merge memberExpressionKeywords and memberExpressionLiterals transformer 2014-11-26 10:46:32 +11:00
Sebastian McKenzie
86498ad990 fix memoisation operator example 2014-11-26 10:46:10 +11:00
Sebastian McKenzie
27c8804214 v1.14.1 2014-11-26 00:43:24 +11:00
Sebastian McKenzie
2b6f0ee780 add changelog for 1.14.1 2014-11-26 00:42:05 +11:00
Sebastian McKenzie
c7c9660c79 classes: make VariableDeclaration inherit comments from ClassDeclaration 2014-11-26 00:41:07 +11:00
Sebastian McKenzie
ff025e63ec add ParenthesizedExpression support to t.isDynamic 2014-11-26 00:40:42 +11:00
Sebastian McKenzie
9fb6681ad3 fix dot in playground docs 2014-11-26 00:08:34 +11:00
63 changed files with 442 additions and 212 deletions

View File

@@ -1,3 +1,43 @@
# 1.14.13
* Fix let scoping of `while` loops.
* Make class methods enumerable.
# 1.14.12
* Fix duplicate dynamic expressions in call spread.
# 1.14.10
* Fix let scoping unneccesary override.
# 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.
# 1.14.3
* Add playground pretzel maps.
# 1.14.2
* Fix `commonInterop` default export handling.
* Fix keyworded property key identifiers being turned into computed property key literals.
# 1.14.1
* Inherit comments from `ClassDeclaration`.
# 1.14.0
* Add [playground](https://6to5.github.io/playground.html).

View File

@@ -16,7 +16,7 @@ bench:
node node_modules/matcha/bin/_matcha
lint:
$(JSHINT_CMD) lib bin benchmark/index.js
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin benchmark/index.js
test-clean:
rm -rf test/tmp

View File

@@ -15,15 +15,18 @@ process.argv.slice(2).forEach(function(arg){
case "-d":
args.unshift("--debug");
break;
case "debug":
case "--debug":
case "--debug-brk":
args.unshift(arg);
break;
case "-gc":
case "--expose-gc":
args.unshift("--expose-gc");
break;
case "--gc-global":
case "--harmony":
case "--harmony-proxies":
@@ -35,16 +38,20 @@ process.argv.slice(2).forEach(function(arg){
case "--trace-deprecation":
args.unshift(arg);
break;
default:
if (0 == arg.indexOf("--trace")) args.unshift(arg);
else args.push(arg);
if (arg.indexOf("--trace") === 0) {
args.unshift(arg);
} else {
args.push(arg);
}
break;
}
});
var proc = spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function (){
process.on("exit", function () {
if (signal) {
process.kill(process.pid, signal);
} else {

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

@@ -44,14 +44,17 @@ equivalent to:
```javascript
var obj = {};
if (Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
```
### Method binding expression.
### Method binding
```javascript
var fn = obj:method;
var fn = obj:method("foob");
["foo", "bar"].map(:toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(:toFixed(2)); // ["1.12", "23.53", "3.00"]
```
equivalent to:
@@ -59,7 +62,7 @@ equivalent to:
```javascript
var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");
```
**NOTE:** Method binding can **only** be used as an **expression** and not as
statement.
["foo", "bar"].map(function (val) { return val.toUpperCase(); });
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });
```

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

@@ -41,7 +41,8 @@ File.normaliseOptions = function (opts) {
filename: "unknown",
modules: "common",
runtime: false,
code: true
code: true,
ast: true
});
// normalise windows path separators to unix
@@ -186,15 +187,18 @@ File.prototype.generate = function () {
var opts = this.opts;
var ast = this.ast;
if (!opts.code) {
return {
code: "",
map: null,
ast: ast
};
}
var result = {
code: "",
map: null,
ast: null
};
var result = generate(ast, opts, this.code);
if (opts.ast) result.ast = ast;
if (!opts.code) return result;
var _result = generate(ast, opts, this.code);
result.code = _result.code;
result.map = _result.map;
if (this.shebang) {
// add back shebang
@@ -205,8 +209,6 @@ File.prototype.generate = function () {
result.code += "\n" + util.sourceMapToComment(result.map);
}
result.ast = result;
return result;
};

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,6 +1,6 @@
var _ = require("lodash");
_.each(["BindMemberExpression"], function (type) {
_.each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
exports[type] = function () {
throw new ReferenceError("Trying to render non-standard playground node " + JSON.stringify(type));
};

View File

@@ -28,7 +28,13 @@ exports.before = {
};
exports.after = {
nodes: {},
nodes: {
AssignmentExpression: function (node) {
if (t.isFunction(node.right)) {
return 1;
}
}
},
list: {
VariableDeclaration: function (node) {

View File

@@ -38,6 +38,12 @@ def("BindMemberExpression")
.field("property", or(def("Identifier"), def("Expression")))
.field("arguments", [def("Expression")]);
def("BindFunctionExpression")
.bases("Expression")
.build("callee", "arguments")
.field("callee", def("Expression"))
.field("arguments", [def("Expression")]);
types.finalize();
var estraverse = require("estraverse");

View File

@@ -3,6 +3,7 @@ require("./polyfill");
var sourceMapSupport = require("source-map-support");
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
var _ = require("lodash");
sourceMapSupport.install({
@@ -61,22 +62,42 @@ 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) {
var cached = cache[filename];
if (cached && cached.mtime === mtime(filename)) {
result = cached;
}
}
result = result || to5.transformFileSync(filename, _.extend({
whitelist: whitelist,
blacklist: blacklist,
sourceMap: true,
modules: "commonInterop"
modules: "commonInterop",
ast: false
}, transformOpts));
if (cache) {
result.mtime = mtime(filename);
cache[filename] = result;
}
maps[filename] = result.map;
m._compile(result.code, filename);
@@ -108,5 +129,8 @@ module.exports = function (opts) {
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
if (opts.cache) cache = opts.cache;
if (opts.cache === false) cache = null;
_.extend(transformOpts, opts);
};

View File

@@ -3,10 +3,16 @@ module.exports = CommonJSInteropFormatter;
var CommonJSFormatter = require("./common");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
function CommonJSInteropFormatter() {
this.has = false;
function CommonJSInteropFormatter(file) {
CommonJSFormatter.apply(this, arguments);
var has = false;
_.each(file.ast.program.body, function (node) {
if (t.isExportDeclaration(node) && !node.default) has = true;
});
this.has = has;
}
util.inherits(CommonJSInteropFormatter, CommonJSFormatter);
@@ -40,14 +46,11 @@ CommonJSInteropFormatter.prototype.export = function (node, nodes) {
// 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

@@ -68,7 +68,6 @@ _.each({
_propertyLiterals: require("./transformers/_property-literals"),
_memberExpressioLiterals: require("./transformers/_member-expression-literals"),
_memberExpressionKeywords: require("./transformers/_member-expression-keywords"),
_moduleFormatter: require("./transformers/_module-formatter")
}, function (transformer, key) {
transform.transformers[key] = new Transformer(key, transformer);

View File

@@ -1,10 +0,0 @@
var esutils = require("esutils");
var t = require("../../types");
exports.MemberExpression = function (node) {
var prop = node.property;
if (t.isIdentifier(prop) && esutils.keyword.isKeywordES6(prop.name, true)) {
node.property = t.literal(prop.name);
node.computed = true;
}
};

View File

@@ -1,4 +1,5 @@
var t = require("../../types");
var esutils = require("esutils");
var t = require("../../types");
exports.MemberExpression = function (node) {
var prop = node.property;
@@ -6,5 +7,8 @@ exports.MemberExpression = function (node) {
// computed literal that is a valid identifier
node.property = t.identifier(prop.value);
node.computed = false;
} else if (!node.computed && t.isIdentifier(prop) && esutils.keyword.isKeywordES6(prop.name, true)) {
node.property = t.literal(prop.name);
node.computed = true;
}
};

View File

@@ -7,9 +7,8 @@ exports.Property = function (node) {
// property key is a literal but a valid identifier
node.key = t.identifier(key.value);
node.computed = false;
} else if (t.isIdentifier(key) && esutils.keyword.isKeywordES6(key.name, true)) {
} else if (!node.computed && t.isIdentifier(key) && esutils.keyword.isKeywordES6(key.name, true)) {
// property key is a keyword
node.key = t.literal(key.name);
node.computed = true;
}
};

View File

@@ -4,9 +4,13 @@ var t = require("../../types");
var _ = require("lodash");
exports.ClassDeclaration = function (node, parent, file, scope) {
return t.variableDeclaration("let", [
t.variableDeclarator(node.id, new Class(node, file, scope).run())
var built = new Class(node, file, scope).run();
var declar = t.variableDeclaration("let", [
t.variableDeclarator(node.id, built)
]);
t.inheritsComments(declar, node);
return declar;
};
exports.ClassExpression = function (node, parent, file, scope) {
@@ -158,17 +162,22 @@ Class.prototype.buildBody = function () {
Class.prototype.pushMethod = function (node) {
var methodName = node.key;
var mutatorMap = this.instanceMutatorMap;
if (node.static) mutatorMap = this.staticMutatorMap;
var kind = node.kind;
if (kind === "") {
kind = "value";
util.pushMutatorMap(mutatorMap, methodName, "writable", t.identifier("true"));
}
// method
util.pushMutatorMap(mutatorMap, methodName, kind, node);
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
this.body.push(t.expressionStatement(t.assignmentExpression("=", methodName, node.value)));
} else {
// mutator
var mutatorMap = this.instanceMutatorMap;
if (node.static) mutatorMap = this.staticMutatorMap;
util.pushMutatorMap(mutatorMap, methodName, kind, node);
}
};
/**

View File

@@ -260,16 +260,14 @@ LetScoping.prototype.checkFor = function () {
hasBreak: false,
};
var forParent = this.forParent;
traverse(this.block, function (node) {
var replace;
if (t.isFunction(node) || t.isFor(node)) {
if (t.isFunction(node) || t.isLoop(node) || t.isSwitchStatement(node)) {
return false;
}
if (forParent && node && !node.label) {
if (node && !node.label) {
if (t.isBreakStatement(node)) {
has.hasBreak = true;
replace = t.returnStatement(t.literal("break"));

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

@@ -56,7 +56,7 @@ exports.ArrayExpression = function (node, parent, file) {
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
};
exports.CallExpression = function (node, parent, file) {
exports.CallExpression = function (node, parent, file, scope) {
var args = node.arguments;
if (!hasSpread(args)) return;
@@ -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) {
@@ -74,10 +79,16 @@ exports.CallExpression = function (node, parent, file) {
}
var callee = node.callee;
var temp;
if (t.isMemberExpression(callee)) {
contextLiteral = callee.object;
if (t.isDynamic(contextLiteral)) {
temp = contextLiteral = scope.generateTemp(file);
callee.object = t.assignmentExpression("=", temp, callee.object);
}
if (callee.computed) {
callee.object = t.memberExpression(callee.object, callee.property, true);
callee.property = t.identifier("apply");

View File

@@ -30,12 +30,7 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
if (!t.isExpressionStatement(parent)) {
// `node.right` isn't a simple identifier so we need to reference it
if (t.isDynamic(value)) {
var tempName = file.generateUid("temp");
temp = value = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
temp = value = scope.generateTemp(file);
}
}
@@ -75,12 +70,7 @@ exports.CallExpression = function (node, parent, file, scope) {
var temp;
if (t.isDynamic(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({
key: tempName,
id: temp
});
temp = scope.generateTemp(file);
}
var call = util.template("abstract-expression-call", {

View File

@@ -1,4 +1,5 @@
var t = require("../../types");
var _ = require("lodash");
exports.BindMemberExpression = function (node, parent, file, scope) {
var object = node.object;
@@ -6,12 +7,7 @@ exports.BindMemberExpression = function (node, parent, file, scope) {
var temp;
if (t.isDynamic(object)) {
var tempName = file.generateUid("temp", scope);
temp = object = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
temp = object = scope.generateTemp(file);
}
var call = t.callExpression(
@@ -28,3 +24,25 @@ exports.BindMemberExpression = function (node, parent, file, scope) {
return call;
}
};
exports.BindFunctionExpression = function (node, parent, file, scope) {
var buildCall = function (args) {
var param = file.generateUidIdentifier("val", scope);
return t.functionExpression(null, [param], t.blockStatement([
t.returnStatement(t.callExpression(t.memberExpression(param, node.callee), args))
]));
};
if (_.find(node.arguments, t.isDynamic)) {
var temp = scope.generateTemp(file, "args");
return t.sequenceExpression([
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
buildCall(node.arguments.map(function (node, i) {
return t.memberExpression(temp, t.literal(i), true);
}))
]);
} else {
return buildCall(node.arguments);
}
};

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

@@ -23,7 +23,16 @@ function Scope(block, parent) {
Scope.add = function (node, references) {
if (!node) return;
_.merge(references, t.getIds(node, true));
_.defaults(references, t.getIds(node, true));
};
Scope.prototype.generateTemp = function (file, name) {
var id = file.generateUidIdentifier(name || "temp", this);
this.push({
key: id.name,
id: id
});
return id;
};
Scope.prototype.getReferences = function () {

View File

@@ -3,14 +3,14 @@
"BreakStatement": ["Statement"],
"ContinueStatement": ["Statement"],
"DebuggerStatement": ["Statement"],
"DoWhileStatement": ["Statement"],
"DoWhileStatement": ["Statement", "Loop", "With"],
"IfStatement": ["Statement"],
"ReturnStatement": ["Statement"],
"SwitchStatement": ["Statement"],
"ThrowStatement": ["Statement"],
"TryStatement": ["Statement"],
"WhileStatement": ["Statement"],
"WithStatement": ["Statement"],
"WithStatement": ["Statement", "Loop", "With"],
"EmptyStatement": ["Statement"],
"LabeledStatement": ["Statement"],
"VariableDeclaration": ["Statement", "Declaration"],
@@ -35,9 +35,9 @@
"ClassDeclaration": ["Statement", "Declaration", "Class"],
"ClassExpression": ["Class"],
"ForOfStatement": ["Statement", "For", "Scope"],
"ForInStatement": ["Statement", "For", "Scope"],
"ForStatement": ["Statement", "For", "Scope"],
"ForOfStatement": ["Statement", "For", "Scope", "Loop"],
"ForInStatement": ["Statement", "For", "Scope", "Loop"],
"ForStatement": ["Statement", "For", "Scope", "Loop"],
"ObjectPattern": ["Pattern"],
"ArrayPattern": ["Pattern"],

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,9 @@ t.shallowEqual = function (actual, expected) {
//
t.isDynamic = function (node) {
if (t.isIdentifier(node) || t.isLiteral(node) || t.isThisExpression(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;
} else if (t.isMemberExpression(node)) {
return t.isDynamic(node.object) || t.isDynamic(node.property);
@@ -158,15 +162,16 @@ t.toIdentifier = function (name) {
return c ? c.toUpperCase() : "";
});
return name;
return name || '_';
};
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

@@ -44,6 +44,7 @@
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"ParenthesizedExpression": ["expression"],
"BindFunctionExpression": ["callee", "arguments"],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.14.0",
"version": "1.14.13",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -35,30 +35,31 @@
"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",
"source-map": "0.1.40",
"chokidar": "0.11.1",
"source-map-support": "0.2.8",
"esutils": "1.1.6",
"acorn-6to5": "0.9.1-8",
"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",
"uglify-js": "2.4.15",
"browserify": "6.3.2",
"rimraf": "2.2.8",
"chai": "^1.9.2",
"istanbul": "0.3.2",
"jshint": "2.5.10",
"chai": "^1.9.2"
"jshint-stylish": "^1.0.0",
"matcha": "0.6.0",
"mocha": "1.21.4",
"rimraf": "2.2.8",
"uglify-js": "2.4.15"
}
}

View File

@@ -1 +1 @@
SyntaxError: test.js: Unexpected character '@'
SyntaxError: test.js: Unexpected character '#'

View File

@@ -1,3 +1,3 @@
arr.map(x => {
$@!
$#!
});

View File

@@ -1,3 +1,3 @@
arr.map(function () {
return $@!@#;
return $#!;
});

View File

@@ -1,3 +1,3 @@
{
"throws": "Unexpected character '@'"
"throws": "Unexpected character '#'"
}

View File

@@ -1,11 +1,6 @@
"use strict";
var _slice = Array.prototype.slice;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _extends = function (child, parent) {
child.prototype = Object.create(parent.prototype, {
constructor: {
@@ -34,25 +29,17 @@ var Test = (function (Foo) {
_extends(Test, Foo);
_classProps(Test, {
foo: {
writable: true,
value: function () {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
}
}
}, {
test: {
writable: true,
value: function () {
Foo.prototype.test.call(this);
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_slice.call(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
}
}
});
Test.prototype.test = function () {
Foo.prototype.test.call(this);
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_slice.call(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
};
Test.foo = function () {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
};
return Test;
})(Foo);

View File

@@ -1,10 +1,5 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _extends = function (child, parent) {
child.prototype = Object.create(parent.prototype, {
constructor: {
@@ -25,14 +20,9 @@ var Test = (function (Foo) {
_extends(Test, Foo);
_classProps(Test, {
test: {
writable: true,
value: function () {
return Foo.wow.call(this);
}
}
});
Test.test = function () {
return Foo.wow.call(this);
};
return Test;
})(Foo);

View File

@@ -1,21 +1,11 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = (function () {
var Test = function Test() {};
_classProps(Test, null, {
test: {
writable: true,
value: function () {
return 5 + 5;
}
}
});
Test.prototype.test = function () {
return 5 + 5;
};
return Test;
})();

View File

@@ -1,10 +1,5 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var BaseView = function BaseView() {
this.autoRender = true;
};
@@ -16,14 +11,9 @@ var BaseView = function () {
var BaseView = (function () {
var _class2 = function () {};
_classProps(_class2, null, {
foo: {
writable: true,
value: function () {
this.autoRender = true;
}
}
});
_class2.prototype.foo = function () {
this.autoRender = true;
};
return _class2;
})();

View File

@@ -8,11 +8,9 @@ var _classProps = function (child, staticProps, instanceProps) {
var A = (function () {
var A = function A() {};
A.a = function () {};
_classProps(A, {
a: {
writable: true,
value: function () {}
},
b: {
get: function () {},
set: function (b) {}

View File

@@ -1,5 +1,5 @@
var obj = {
[foobar]() {
return "foobar";
return "foobar";
}
};

View File

@@ -4,5 +4,6 @@ var obj = (function (_obj) {
_obj[foobar] = function () {
return "foobar";
};
return _obj;
})({});

View File

@@ -6,7 +6,9 @@ define(["exports"], function (exports) {
exports["default"] = [];
exports["default"] = foo;
exports["default"] = function () {};
exports["default"] = function () {};
function foo() {}
exports["default"] = foo;
var Foo = function Foo() {};

View File

@@ -6,7 +6,9 @@ module.exports = {};
module.exports = [];
module.exports = foo;
module.exports = function () {};
module.exports = function () {};
function foo() {}
var Foo = function Foo() {};

View File

@@ -5,7 +5,9 @@ exports["default"] = {};
exports["default"] = [];
exports["default"] = foo;
exports["default"] = function () {};
exports["default"] = function () {};
function foo() {}
exports["default"] = foo;
var Foo = function Foo() {};

View File

@@ -12,7 +12,9 @@
exports["default"] = [];
exports["default"] = foo;
exports["default"] = function () {};
exports["default"] = function () {};
function foo() {}
exports["default"] = foo;
var Foo = function Foo() {};

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

View File

@@ -1,4 +0,0 @@
test.catch;
test.catch["foo"];
test["catch"];
test["catch"]["foo"];

View File

@@ -1,6 +0,0 @@
"use strict";
test["catch"];
test["catch"].foo;
test["catch"];
test["catch"].foo;

View File

@@ -1 +1,6 @@
obj["x"] = 2;
test.catch;
test.catch["foo"];
test["catch"];
test["catch"]["foo"];

View File

@@ -1,3 +1,8 @@
"use strict";
obj.x = 2;
test["catch"];
test["catch"].foo;
test["catch"];
test["catch"].foo;

View File

@@ -3,3 +3,11 @@ var fn = obj:method("foob");
var fn = obj[foo]:method;
var fn = obj.foo:method;
var fn = obj[foo()]:method;
["foo", "bar"].map(:toUpperCase);
[1.1234, 23.53245, 3].map(:toFixed(2));
var get = function () {
return 2;
};
[1.1234, 23.53245, 3].map(:toFixed(get()));

View File

@@ -20,3 +20,11 @@ assert.equal(bar(), "foo bar");
var zoo = obj:getZoo("foo");
assert.equal(zoo("bar"), "foo bar foo bar");
assert.deepEqual(["foo", "bar"].map(:toUpperCase), ["FOO", "BAR"]);
assert.deepEqual([1.1234, 23.53245, 3].map(:toFixed(2)), ["1.12", "23.53", "3.00"]);
var get = function () {
return 2;
}
assert.deepEqual([1.1234, 23.53245, 3].map(:toFixed(get())), ["1.12", "23.53", "3.00"]);

View File

@@ -1,8 +1,22 @@
"use strict";
var _temp;
var _temp, _args;
var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");
var fn = obj[foo].method.bind(obj[foo]);
var fn = obj.foo.method.bind(obj.foo);
var fn = (_temp = obj[foo()], _temp.method.bind(_temp));
["foo", "bar"].map(function (_val) {
return _val.toUpperCase();
});
[1.1234, 23.53245, 3].map(function (_val2) {
return _val2.toFixed(2);
});
var get = function () {
return 2;
};
[1.1234, 23.53245, 3].map((_args = [get()], function (_val3) {
return _val3.toFixed(_args[0]);
}));