Compare commits

...

48 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
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
Sebastian McKenzie
301887f88d v1.14.0 2014-11-26 00:06:13 +11:00
Sebastian McKenzie
b519bb6a68 add playground experimental note 2014-11-26 00:04:03 +11:00
Sebastian McKenzie
b6e366ad94 remove unused variables 2014-11-26 00:03:22 +11:00
Sebastian McKenzie
ba2204156c make playground option enable experimental 2014-11-26 00:02:49 +11:00
Sebastian McKenzie
2545292bce add 1.14.0 changelog 2014-11-26 00:01:29 +11:00
Sebastian McKenzie
c763cf364c clarify playground warning note 2014-11-26 00:01:17 +11:00
Sebastian McKenzie
1db7247d9a remove weird sounding however in playground warning message 2014-11-25 23:57:43 +11:00
Sebastian McKenzie
1a1e6bc3ba remove arguments-to-array helper 2014-11-25 23:56:38 +11:00
Sebastian McKenzie
d184bc93b9 add playground 2014-11-25 23:50:50 +11:00
Sebastian McKenzie
e12cca974a remove irrelevant max line length 2014-11-25 23:49:35 +11:00
Sebastian McKenzie
b17bc95b4f v1.13.13 2014-11-25 19:49:51 +11:00
Sebastian McKenzie
a71f260377 add 1.13.13 changelog 2014-11-25 19:48:42 +11:00
Sebastian McKenzie
8cbc1f7f06 Merge pull request #218 from timoxley/no-no-timeouts
Remove --no-timeouts flag.
2014-11-25 19:47:54 +11:00
Tim Oxley
20dc8b05c9 Remove --no-timeouts flag.
Not a valid flag, causes errors when trying to use debug modes.
2014-11-25 14:54:36 +08:00
68 changed files with 783 additions and 219 deletions

View File

@@ -1,3 +1,38 @@
# 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).
# 1.13.13
* Fix `--debug` in `bin/6to5-node`. Thanks [@timoxley](https://github.com/timoxley).
# 1.13.12
* Ignore `XJSEmptyExpression`s in `react` transformer output.

View File

@@ -9,7 +9,6 @@
* CamelCase all class names
* camelBack all variable names
* **Spacing**
* 80 character line max
* Spaces after all keywords
* Spaces before all left curly braces
* **Comments**

View File

@@ -14,13 +14,11 @@ process.argv.slice(2).forEach(function(arg){
switch (flag) {
case "-d":
args.unshift("--debug");
args.push("--no-timeouts");
break;
case "debug":
case "--debug":
case "--debug-brk":
args.unshift(arg);
args.push("--no-timeouts");
break;
case "-gc":
case "--expose-gc":

View File

@@ -12,6 +12,7 @@ commander.option("-f, --filename [filename]", "Filename to use when reading from
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("-p, --playground", "Enable playground support");
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);
@@ -90,6 +91,7 @@ exports.opts = {
sourceMapName: commander.outFile,
amdModuleIds: commander.amdModuleIds,
experimental: commander.experimental,
playground: commander.playground,
blacklist: commander.blacklist,
whitelist: commander.whitelist,
sourceMap: commander.sourceMaps || commander.sourceMapsInline,

View File

@@ -13,6 +13,7 @@ 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");
commander.option("-g, --playground", "Enable playground support");
var pkg = require("../package.json");
commander.version(pkg.version);
@@ -31,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.

68
doc/playground.md Normal file
View File

@@ -0,0 +1,68 @@
# Playground
Playground is a proving ground for **possible** ES7 proposals.
**NOTE: These features are in no way endorsed by Ecma International and are not a part of ES6. They might become a part of ECMAScript in the future.**
## Usage
$ 6to5 --playground
```javascript
to5.transform("code", { playground: true });
```
**NOTE:** Enabling `playground` also enables [experimental support](usage.md#experimental).
## Features
* [Memoization operator](#memoization-operator)
* [Method binding](#method-binding)
### Memoization assignment operator
```javascript
var obj = {};
obj.x ?= 2;
obj.x; // 2
obj = { x: 1 };
obj.x ?= 2;
obj.x; // 1
obj = { x: undefined }
obj.x ?= 2;
obj.x; // undefined
```
```javascript
var obj = {};
obj.x ?= 2;
```
equivalent to:
```javascript
var obj = {};
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
```
### 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:
```javascript
var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");
["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

@@ -22,8 +22,9 @@ File.declarations = [
"tagged-template-literal",
"interop-require",
"to-array",
"arguments-to-array",
"object-spread"
"object-spread",
"has-own",
"slice"
];
File.normaliseOptions = function (opts) {
@@ -31,6 +32,7 @@ File.normaliseOptions = function (opts) {
_.defaults(opts, {
experimental: false,
playground: false,
whitespace: true,
blacklist: [],
whitelist: [],
@@ -69,6 +71,10 @@ File.normaliseOptions = function (opts) {
opts.runtime = "to5Runtime";
}
if (opts.playground) {
opts.experimental = true;
}
transform._ensureTransformerNames("blacklist", opts.blacklist);
transform._ensureTransformerNames("whitelist", opts.whitelist);
@@ -78,14 +84,11 @@ File.normaliseOptions = function (opts) {
File.prototype.toArray = function (node) {
if (t.isArrayExpression(node)) {
return node;
} else if (t.isIdentifier(node) && node.name === "arguments") {
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
} else {
return t.callExpression(this.addDeclaration("to-array"), [node]);
}
var templateName = "to-array";
if (t.isIdentifier(node) && node.name === "arguments") {
templateName = "arguments-to-array";
}
return t.callExpression(this.addDeclaration(templateName), [node]);
};
File.prototype.getModuleFormatter = function (type) {
@@ -135,7 +138,11 @@ File.prototype.addDeclaration = function (name) {
}
var uid = this.generateUidIdentifier(name);
this.scope.push(name, uid, ref);
this.scope.push({
key: name,
id: uid,
init: ref
});
return uid;
};

View File

@@ -53,6 +53,7 @@ CodeGenerator.generators = {
comprehensions: require("./generators/comprehensions"),
expressions: require("./generators/expressions"),
statements: require("./generators/statements"),
playground: require("./generators/playground"),
classes: require("./generators/classes"),
methods: require("./generators/methods"),
modules: require("./generators/modules"),
@@ -160,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

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

View File

@@ -30,6 +30,20 @@ def("VirtualPropertyExpression")
.field("object", def("Expression"))
.field("property", or(def("Identifier"), def("Expression")));
// Playground
def("BindMemberExpression")
.bases("Expression")
.build("object", "property", "arguments")
.field("object", def("Expression"))
.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

@@ -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,7 +0,0 @@
(function (args) {
var target = new Array(args.length);
for (var i = 0; i< args.length; i++) {
target[i] = args[i];
}
return target;
})

View File

@@ -0,0 +1 @@
Object.prototype.hasOwnProperty;

View File

@@ -0,0 +1 @@
Array.prototype.slice;

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

@@ -36,7 +36,6 @@ _.each({
arrowFunctions: require("./transformers/es6-arrow-functions"),
classes: require("./transformers/es6-classes"),
_propertyLiterals: require("./transformers/_property-literals"),
computedPropertyNames: require("./transformers/es6-computed-property-names"),
objectSpread: require("./transformers/es7-object-spread"),
@@ -57,13 +56,18 @@ _.each({
generators: require("./transformers/es6-generators"),
// plyground
methodBinding: require("./transformers/playground-method-binding"),
memoizationOperator: require("./transformers/playground-memoization-operator"),
_blockHoist: require("./transformers/_block-hoist"),
_declarations: require("./transformers/_declarations"),
_aliasFunctions: require("./transformers/_alias-functions"),
useStrict: require("./transformers/use-strict"),
_memberExpressionKeywords: require("./transformers/_member-expression-keywords"),
_propertyLiterals: require("./transformers/_property-literals"),
_memberExpressioLiterals: require("./transformers/_member-expression-literals"),
_moduleFormatter: require("./transformers/_module-formatter")
}, function (transformer, key) {
transform.transformers[key] = new Transformer(key, transformer);

View File

@@ -3,9 +3,21 @@ var _ = require("lodash");
exports.BlockStatement =
exports.Program = function (node) {
var kinds = {};
_.each(node._declarations, function (declar) {
node.body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(declar.id, declar.init)
]));
var kind = declar.kind || "var";
var declarNode = t.variableDeclarator(declar.id, declar.init);
if (!declar.init) {
kinds[kind] = kinds[kind] || [];
kinds[kind].push(declarNode);
} else {
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
}
});
_.each(kinds, function (declars, kind) {
node.body.unshift(t.variableDeclaration(kind, declars));
});
};

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

@@ -0,0 +1,14 @@
var esutils = require("esutils");
var t = require("../../types");
exports.MemberExpression = function (node) {
var prop = node.property;
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
// 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

@@ -1,15 +1,14 @@
var esutils = require("esutils");
var t = require("../../types");
var _ = require("lodash");
exports.Property = function (node) {
// ignore key literals that are valid identifiers
var key = node.key;
if (t.isLiteral(key) && _.isString(key.value) && esutils.keyword.isIdentifierName(key.value)) {
key.type = "Identifier";
key.name = key.value;
delete key.value;
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
// property key is a literal but a valid identifier
node.key = t.identifier(key.value);
node.computed = false;
} else if (!node.computed && t.isIdentifier(key) && esutils.keyword.isKeywordES6(key.name, true)) {
// property key is a keyword
node.key = t.literal(key.name);
}
};

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

View File

@@ -3,11 +3,14 @@
var t = require("../../types");
var _ = require("lodash");
var buildVariableAssign = function (kind, id, init) {
if (kind === false) {
var buildVariableAssign = function (opts, id, init) {
var op = opts.operator;
if (t.isMemberExpression(id)) op = "=";
if (op) {
return t.expressionStatement(t.assignmentExpression("=", id, init));
} else {
return t.variableDeclaration(kind, [
return t.variableDeclaration(opts.kind, [
t.variableDeclarator(id, init)
]);
}
@@ -18,10 +21,8 @@ var push = function (opts, nodes, elem, parentId) {
pushObjectPattern(opts, nodes, elem, parentId);
} else if (t.isArrayPattern(elem)) {
pushArrayPattern(opts, nodes, elem, parentId);
} else if (t.isMemberExpression(elem)) {
nodes.push(buildVariableAssign(false, elem, parentId));
} else {
nodes.push(buildVariableAssign(opts.kind, elem, parentId));
nodes.push(buildVariableAssign(opts, elem, parentId));
}
};
@@ -43,7 +44,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
keys = t.arrayExpression(keys);
var value = t.callExpression(opts.file.addDeclaration("object-spread"), [parentId, keys]);
nodes.push(buildVariableAssign(opts.kind, prop.argument, value));
nodes.push(buildVariableAssign(opts, prop.argument, value));
} else {
var pattern2 = prop.value;
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
@@ -51,7 +52,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
if (t.isPattern(pattern2)) {
push(opts, nodes, pattern2, patternId2);
} else {
nodes.push(buildVariableAssign(opts.kind, pattern2, patternId2));
nodes.push(buildVariableAssign(opts, pattern2, patternId2));
}
}
});
@@ -177,7 +178,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
]));
push({
kind: false,
operator: expr.operator,
file: file,
scope: scope
}, nodes, expr.left, ref);
@@ -190,33 +191,24 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
if (!t.isPattern(node.left)) return;
var tempName = file.generateUid("temp", scope);
var temp = t.identifier(tempName);
scope.push(tempName, temp);
var nodes = [];
nodes.push(t.assignmentExpression("=", temp, node.right));
push({
kind: false,
file: file,
scope: scope
}, nodes, node.left, temp);
nodes.push(temp);
nodes = nodes.map(function (node) {
if (t.isExpressionStatement(node)) {
return node.expression;
} else if (t.isVariableDeclaration(node)) {
var declar = node.declarations[0];
scope.push(declar.id.name, declar.id);
return t.assignmentExpression("=", declar.id, declar.init);
} else {
return node;
}
var ref = t.identifier(tempName);
scope.push({
key: tempName,
id: ref
});
return t.sequenceExpression(nodes);
var nodes = [];
nodes.push(t.assignmentExpression("=", ref, node.right));
push({
operator: node.operator,
file: file,
scope: scope
}, nodes, node.left, ref);
nodes.push(ref);
return t.toSequenceExpression(nodes, scope);
};
exports.VariableDeclaration = function (node, parent, file, scope) {
@@ -236,17 +228,18 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
_.each(node.declarations, function (declar) {
var patternId = declar.init;
var pattern = declar.id;
var opts = {
kind: node.kind,
nodes: nodes,
pattern: pattern,
id: patternId,
file: file,
scope: scope
};
if (t.isPattern(pattern) && patternId) {
pushPattern({
kind: node.kind,
nodes: nodes,
pattern: pattern,
id: patternId,
file: file,
scope: scope
});
pushPattern(opts);
} else {
nodes.push(buildVariableAssign(node.kind, declar.id, declar.init));
nodes.push(buildVariableAssign(opts, declar.id, declar.init));
}
});
@@ -268,4 +261,3 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
return nodes;
};

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

@@ -8,13 +8,10 @@ exports.Function = function (node, parent, file) {
t.ensureBlock(node);
var call = t.callExpression(
file.addDeclaration("arguments-to-array"),
[t.identifier("arguments")]
);
var call = file.toArray(t.identifier("arguments"));
if (node.params.length) {
call = t.callExpression(t.memberExpression(call, t.identifier("slice")), [t.literal(node.params.length)]);
call.arguments.push(t.literal(node.params.length));
}
call._ignoreAliasFunctions = true;

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

@@ -32,7 +32,10 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
if (t.isDynamic(value)) {
var tempName = file.generateUid("temp");
temp = value = t.identifier(tempName);
scope.push(tempName, temp);
scope.push({
key: tempName,
id: temp
});
}
}
@@ -74,7 +77,10 @@ exports.CallExpression = function (node, parent, file, scope) {
// we need to save `callee.object` so we can call it again
var tempName = file.generateUid("temp");
temp = t.identifier(tempName);
scope.push(tempName, temp);
scope.push({
key: tempName,
id: temp
});
}
var call = util.template("abstract-expression-call", {

View File

@@ -0,0 +1,90 @@
var t = require("../../types");
var isMemo = function (node) {
var is = t.isAssignmentExpression(node) && node.operator === "?=";
if (is) t.assertMemberExpression(node.left);
return is;
};
var getPropRef = function (nodes, prop, file, scope) {
if (t.isIdentifier(prop)) {
return t.literal(prop.name);
} else {
var temp = file.generateUidIdentifier("propKey", scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(temp, prop)
]));
return temp;
}
};
var getObjRef = function (nodes, obj, file, scope) {
if (t.isDynamic(obj)) {
var temp = file.generateUidIdentifier("obj", scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(temp, obj)
]));
return temp;
} else {
return obj;
}
};
var buildHasOwn = function (obj, prop, file) {
return t.unaryExpression(
"!",
t.callExpression(
t.memberExpression(file.addDeclaration("has-own"), t.identifier("call")),
[obj, prop]
),
true
);
};
var buildAbsoluteRef = function (left, obj, prop) {
var computed = left.computed || t.isLiteral(prop);
return t.memberExpression(obj, prop, computed);
};
var buildAssignment = function (expr, obj, prop) {
return t.assignmentExpression("=", buildAbsoluteRef(expr.left, obj, prop), expr.right);
};
exports.ExpressionStatement = function (node, parent, file, scope) {
var expr = node.expression;
if (!isMemo(expr)) return;
var nodes = [];
var left = expr.left;
var obj = getObjRef(nodes, left.object, file, scope);
var prop = getPropRef(nodes, left.property, file, scope);
nodes.push(t.ifStatement(
buildHasOwn(obj, prop, file),
t.expressionStatement(buildAssignment(expr, obj, prop))
));
return nodes;
};
exports.AssignmentExpression = function (node, parent, file, scope) {
if (t.isExpressionStatement(parent)) return;
if (!isMemo(node)) return;
var nodes = [];
var left = node.left;
var obj = getObjRef(nodes, left.object, file, scope);
var prop = getPropRef(nodes, left.property, file, scope);
nodes.push(t.logicalExpression(
"&&",
buildHasOwn(obj, prop, file),
buildAssignment(node, obj, prop)
));
nodes.push(buildAbsoluteRef(left, obj, prop));
return t.toSequenceExpression(nodes, scope);
};

View File

@@ -0,0 +1,58 @@
var t = require("../../types");
var _ = require("lodash");
exports.BindMemberExpression = function (node, parent, file, scope) {
var object = node.object;
var prop = node.property;
var temp;
if (t.isDynamic(object)) {
var tempName = file.generateUid("temp", scope);
temp = object = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
}
var call = t.callExpression(
t.memberExpression(t.memberExpression(object, prop), t.identifier("bind")),
[object].concat(node.arguments)
);
if (temp) {
return t.sequenceExpression([
t.assignmentExpression("=", temp, node.object),
call
]);
} else {
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 argsIdName = file.generateUid("args", scope);
var argsId = t.identifier(argsIdName);
scope.push({
key: argsIdName,
id: argsId
});
return t.sequenceExpression([
t.assignmentExpression("=", argsId, t.arrayExpression(node.arguments)),
buildCall(node.arguments.map(function (node, i) {
return t.memberExpression(argsId, 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

@@ -101,7 +101,7 @@ Scope.prototype.getReferences = function () {
return references;
};
Scope.prototype.push = function (name, id, init) {
Scope.prototype.push = function (opts) {
var block = this.block;
if (t.isFor(block) || t.isCatchClause(block) || t.isFunction(block)) {
@@ -111,9 +111,10 @@ Scope.prototype.push = function (name, id, init) {
if (t.isBlockStatement(block) || t.isProgram(block)) {
block._declarations = block._declarations || {};
block._declarations[name] = {
id: id,
init: init
block._declarations[opts.key] = {
kind: opts.kind,
id: opts.id,
init: opts.init
};
} else {
throw new TypeError("cannot add a declaration here in node type " + block.type);

View File

@@ -11,6 +11,7 @@
"Identifier": ["name"],
"IfStatement": ["test", "consequent", "alternate"],
"Literal": ["value"],
"LogicalExpression": ["operator", "left", "right"],
"MemberExpression": ["object", "property", "computed"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],

View File

@@ -1,4 +1,5 @@
var _ = require("lodash");
var esutils = require("esutils");
var _ = require("lodash");
var t = exports;
@@ -11,6 +12,8 @@ var addAssert = function (type, is) {
};
};
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
//
t.VISITOR_KEYS = require("./visitor-keys");
@@ -71,6 +74,31 @@ addAssert("Expression", t.isExpression);
//
t.toSequenceExpression = function (nodes, scope) {
var exprs = [];
_.each(nodes, function (node) {
if (t.isExpression(node)) {
exprs.push(node);
} if (t.isExpressionStatement(node)) {
exprs.push(node.expression);
} else if (t.isVariableDeclaration(node)) {
_.each(node.declarations, function (declar) {
scope.push({
kind: node.kind,
key: declar.id.name,
id: declar.id
});
exprs.push(t.assignmentExpression("=", declar.id, declar.init));
});
}
});
return t.sequenceExpression(exprs);
};
//
t.shallowEqual = function (actual, expected) {
var same = true;
@@ -88,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);
@@ -135,8 +165,13 @@ t.toIdentifier = function (name) {
return name;
};
t.ensureBlock = function (node) {
node.body = t.toBlock(node.body, node);
t.isValidIdentifier = function (name) {
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
};
t.ensureBlock = function (node, key) {
key = key || "body";
node[key] = t.toBlock(node[key], node);
};
t.toStatement = function (node, ignore) {

View File

@@ -5,6 +5,7 @@
"AssignmentExpression": ["left", "right"],
"AwaitExpression": ["argument"],
"BinaryExpression": ["left", "right"],
"BindMemberExpression": ["object", "property", "arguments"],
"BlockStatement": ["body"],
"BreakStatement": ["label"],
"CallExpression": ["callee", "arguments"],
@@ -43,6 +44,7 @@
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties"],
"ParenthesizedExpression": ["expression"],
"BindFunctionExpression": ["callee", "arguments"],
"Program": ["body"],
"Property": ["key", "value"],
"ReturnStatement": ["argument"],

View File

@@ -219,6 +219,7 @@ exports.parse = function (opts, code, callback) {
allowReturnOutsideFunction: true,
preserveParens: true,
ecmaVersion: opts.experimental ? 7 : 6,
playground: opts.playground,
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.13.12",
"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-7",
"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

@@ -1,5 +1,5 @@
class Test {
constructor() {
arr.map(x => x * x);
arr.map(x => x * x);
}
}

View File

@@ -1,14 +1,6 @@
"use strict";
var _argumentsToArray = function (args) {
var target = new Array(args.length);
for (var i = 0; i < args.length; i++) {
target[i] = args[i];
}
return target;
};
var _slice = Array.prototype.slice;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
@@ -33,11 +25,11 @@ var Test = (function (Foo) {
Foo.prototype.test.call(this);
foob(Foo);
Foo.call.apply(Foo, [this].concat(_argumentsToArray(arguments)));
Foo.call.apply(Foo, [this, "test"].concat(_argumentsToArray(arguments)));
Foo.call.apply(Foo, [this].concat(_slice.call(arguments)));
Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_argumentsToArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_argumentsToArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_slice.call(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(arguments)));
};
_extends(Test, Foo);
@@ -47,8 +39,8 @@ var Test = (function (Foo) {
writable: true,
value: function () {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(_argumentsToArray(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_argumentsToArray(arguments)));
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
}
}
}, {
@@ -56,8 +48,8 @@ var Test = (function (Foo) {
writable: true,
value: function () {
Foo.prototype.test.call(this);
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_argumentsToArray(arguments)));
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_argumentsToArray(arguments)));
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)));
}
}
});

View File

@@ -1,9 +1,8 @@
"use strict";
var _ref;
var _temp, _ref;
var _toArray = function (arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
};
var _temp;
console.log((_temp = [123], _ref = _toArray(_temp), x = _ref[0], _temp));

View File

@@ -1,14 +1,6 @@
"use strict";
var _argumentsToArray = function (args) {
var target = new Array(args.length);
for (var i = 0; i < args.length; i++) {
target[i] = args[i];
}
return target;
};
var _slice = Array.prototype.slice;
var concat = function () {
var arrs = _argumentsToArray(arguments);
var arrs = _slice.call(arguments);
};

View File

@@ -1,18 +1,10 @@
"use strict";
var _argumentsToArray = function (args) {
var target = new Array(args.length);
for (var i = 0; i < args.length; i++) {
target[i] = args[i];
}
return target;
};
var _slice = Array.prototype.slice;
var t = function (f) {
var items = _argumentsToArray(arguments).slice(1);
var items = _slice.call(arguments, 1);
};
function t(f) {
var items = _argumentsToArray(arguments).slice(1);
var items = _slice.call(arguments, 1);
}

View File

@@ -1,18 +1,10 @@
"use strict";
var _argumentsToArray = function (args) {
var target = new Array(args.length);
for (var i = 0; i < args.length; i++) {
target[i] = args[i];
}
return target;
};
var _slice = Array.prototype.slice;
var t = function () {
var items = _argumentsToArray(arguments);
var items = _slice.call(arguments);
};
function t() {
var items = _argumentsToArray(arguments);
var items = _slice.call(arguments);
}

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,16 +1,7 @@
"use strict";
var _argumentsToArray = function (args) {
var target = new Array(args.length);
for (var i = 0; i < args.length; i++) {
target[i] = args[i];
}
return target;
};
function foo() {
return bar.apply(null, ["test"].concat(_argumentsToArray(arguments)));
return bar.apply(null, arguments);
}
function bar(one, two, three) {

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
"use strict";
function foo() {
var test = customNamespace.argumentsToArray(arguments);
var test = customNamespace.slice.call(arguments);
}

View File

@@ -1,5 +1,5 @@
"use strict";
function foo() {
var test = to5Runtime.argumentsToArray(arguments);
var test = to5Runtime.slice.call(arguments);
}

View File

@@ -0,0 +1,13 @@
var obj = {};
obj.x ?= 2;
console.log(obj.x ?= 2);
obj[x()] ?= 2;
console.log(obj[x()] ?= 2);
obj[y()][x()] ?= 2;
console.log(obj[y()][x()] ?= 2);

View File

@@ -0,0 +1,20 @@
var obj = {};
obj.x ?= 2;
assert.equal(obj.x, 2);
obj = {};
assert.equal(obj.x ?= 2, 2);
obj = { x: 1 };
obj.x ?= 2;
assert.equal(obj.x, 1);
obj = { x: 1 };
assert.equal(obj.x ?= 2, 1);
obj = { x: undefined }
obj.x ?= 2;
assert.equal(obj.x, undefined);
obj = { x: undefined }
assert.equal(obj.x ?= 2, undefined);

View File

@@ -0,0 +1,25 @@
"use strict";
var _propKey2, _obj2, _propKey4;
var _hasOwn = Object.prototype.hasOwnProperty;
var obj = {};
if (!_hasOwn.call(obj, "x")) obj.x = 2;
console.log((!_hasOwn.call(obj, "x") && (obj.x = 2), obj.x));
var _propKey = x();
if (!_hasOwn.call(obj, _propKey)) obj[_propKey] = 2;
console.log((_propKey2 = x(), !_hasOwn.call(obj, _propKey2) && (obj[_propKey2] = 2), obj[_propKey2]));
var _obj = obj[y()];
var _propKey3 = x();
if (!_hasOwn.call(_obj, _propKey3)) _obj[_propKey3] = 2;
console.log((_obj2 = obj[y()], _propKey4 = x(), !_hasOwn.call(_obj2, _propKey4) && (_obj2[_propKey4] = 2), _obj2[_propKey4]));

View File

@@ -0,0 +1,13 @@
var fn = obj:method;
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

@@ -0,0 +1,30 @@
var obj = {
foo: "foo",
bar: "bar",
getFoo: function () {
return this.foo;
},
getBar: function (arg) {
return arg + " " + this.bar;
},
getZoo: function (a, b) {
return this.foo + " " + this.bar + " " + a + " " + b;
}
};
var foo = obj:getFoo;
assert.equal(foo(), "foo");
var bar = obj:getBar("foo");
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

@@ -0,0 +1,22 @@
"use strict";
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]);
}));

View File

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

View File

@@ -37,10 +37,11 @@ var run = function (task, done) {
err.message += util.codeFrame(execCode);
throw err;
}
} else {
var actualCode = actual.code;
var expectCode = expect.code;
}
var actualCode = actual.code;
var expectCode = expect.code;
if (!execCode || actualCode) {
result = transform(actualCode, getOpts(actual));
actualCode = result.code;