Compare commits

...

43 Commits

Author SHA1 Message Date
Sebastian McKenzie
9ca05b1971 v1.15.0 2014-12-13 12:18:05 +11:00
Sebastian McKenzie
2a27b7c16c 1.15.0 2014-12-13 12:15:32 +11:00
Sebastian McKenzie
c92fd6f0bb remove useless GeneratorFunction aliasing causing issues #283 2014-12-13 12:13:03 +11:00
Sebastian McKenzie
0ee4a15d01 v1.14.17 2014-12-06 23:37:32 +11:00
Sebastian McKenzie
fbdaedc4f8 remove unused loopParent variable 2014-12-06 23:36:28 +11:00
Sebastian McKenzie
75c8d73d35 add default initializer to let variables within loop bodies and fix excessive break replacement inside of switches in let scoping - fixes #255 2014-12-06 23:35:47 +11:00
Sebastian McKenzie
21599d3a9a change memoisation to memoization 2014-12-06 20:49:33 +11:00
Sebastian McKenzie
9fbbabc7e4 v1.14.16 2014-12-06 20:48:31 +11:00
Sebastian McKenzie
8c1fe49b2e upgrade acorn-6to5 2014-12-06 20:47:40 +11:00
Sebastian McKenzie
763b4caf32 v1.14.15 2014-12-06 20:46:16 +11:00
Sebastian McKenzie
c0248cf04c add 1.14.15 changelog 2014-12-06 20:44:58 +11:00
Sebastian McKenzie
a7a6ee80f2 add object getter memoization and this shorthand to playground 2014-12-06 19:37:23 +11:00
Sebastian McKenzie
aa298b1e0a update doc/differences to reflect current status of project - fixes #253 2014-12-06 19:36:46 +11:00
Sebastian McKenzie
9c0a8e22d2 fix let scoping not working with while loops - fixes #254 2014-12-06 19:36:08 +11:00
Sebastian McKenzie
7c1a924ef6 v1.14.14 2014-12-06 00:04:00 +11:00
Sebastian McKenzie
1d975a2635 Fix tagged template literals 2014-12-06 00:03:11 +11:00
Sebastian McKenzie
67cfdbd447 better closure variable name in default parameters 2014-12-06 00:00:09 +11:00
Sebastian McKenzie
ab02231d39 fix template literals escaping 2014-12-06 00:00:00 +11:00
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
41 changed files with 466 additions and 237 deletions

View File

@@ -1,239 +1,280 @@
# 1.14.6
# Changelog
Gaps between patch versions are faulty/broken releases.
## 1.15.0
* Don't alias `GeneratorFunction` and check the name which causes minifiers to remove the name and throw an error later on when we check if it's set.
## 1.14.18
* Fix files only containg comments not being output.
* Fix duplicate comments on property key shorthands.
## 1.14.17
* Add default initializer to let variables within loop bodies.
* Fix excessive `break` replacement inside of switches in let scoping.
## 1.14.16
* Add object getter memos and this shorthand to playground.
* Fix while loops in let scoping.
* Upgrade `acorn-6to5`.
## 1.14.14
* Fix template literals escaping.
## 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
## 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
## 1.14.4
* Merge pretzel maps and method binding.
# 1.14.3
## 1.14.3
* Add playground pretzel maps.
# 1.14.2
## 1.14.2
* Fix `commonInterop` default export handling.
* Fix keyworded property key identifiers being turned into computed property key literals.
# 1.14.1
## 1.14.1
* Inherit comments from `ClassDeclaration`.
# 1.14.0
## 1.14.0
* Add [playground](https://6to5.github.io/playground.html).
# 1.13.13
## 1.13.13
* Fix `--debug` in `bin/6to5-node`. Thanks [@timoxley](https://github.com/timoxley).
# 1.13.12
## 1.13.12
* Ignore `XJSEmptyExpression`s in `react` transformer output.
# 1.13.11
## 1.13.11
* Fix `util.regexify` on falsy values.
* Fix `_aliasFunction` with rest parameters.
* Export as `module.exports` instead of `exports.default` if there are no other `ExportDeclaration`s in `commonInterop` module formatter.
* Add `system` module formatter. Thanks [@douglasduteil](https://github.com/douglasduteil).
# 1.13.10
## 1.13.10
* Add support for `AssignmentExpression` destructuring outside of `ExpressionStatement`.
# 1.13.9
## 1.13.9
* Fix `VirtualPropertyExpression` visitor keys.
# 1.13.8
## 1.13.8
* Only use a single reference in abstract references.
# 1.13.7
## 1.13.7
* Upgrade `acorn-6to5`.
* Add experimental exponentiation operator support.
# 1.13.6
## 1.13.6
* Fix experimental object spread/rest helper.
# 1.13.5
## 1.13.5
* Upgrade `acorn-6to5`.
* Add experimental support for object spread/rest.
* Change `arguments` to array to an additional helper method.
# 1.13.4
## 1.13.4
* Fix single spread element returning itself.
# 1.13.3
## 1.13.3
* Upgrade `acorn-6to5`.
* Add experimental support for abstract references.
# 1.13.2
## 1.13.2
* Optimise `Array.from` usage by adding a helper method.
* Upgrade `acorn-6to5`.
# 1.13.1
## 1.13.1
* Fix constructor spread optimisation. Thanks [@zloirock](https://github.com/zloirock).
# 1.13.0
## 1.13.0
* Put experimental ES7 features behind a flag `--experimental` and `experimental` option.
* Constructor spread performance increase. Thanks [@RReverser](https://github.com/RReverser).
* Use `self` instead of `window` in the optional 6to5 runtime. Thanks [@RReverser](https://github.com/RReverser).
# 1.12.26
## 1.12.26
* Support computed property destructuring.
# 1.12.25
## 1.12.25
* Update `acorn-6to5`, `ast-types`, `es6-shim`, `chokidar`, `estraverse` and `private`.
# 1.12.24
## 1.12.24
* Collect references that haven't been declared in scope.
# 1.12.23
## 1.12.23
* Fix generator function export hoisting.
# 1.12.22
## 1.12.22
* Update `fs-readdir-recursive` and `chokidar`.
* Support array destructuring on iterables.
* Make amd module id optional. Thanks [@webpro](https://github.com/webpro).
# 1.12.21
## 1.12.21
* Fix unneccesary let scoping replacement.
* Add `commonInterop` module formatter. Thanks [@Naddiseo](https://github.com/Naddiseo).
* Fix `return` outside of function body bug. Thanks [@brentburg](https://github.com/brentburg).
* Add more flexible option types.
# 1.12.20
## 1.12.20
* Append `sourceMappingURL` when using `bin/6to5` and output sourcemaps.
# 1.12.19
## 1.12.19
* Add `comments` option and `--remove-comments` flag. Thanks [@webpro](htps://github.com/webpro).
* Embed `regenerator`.
# 1.12.18
## 1.12.18
* Use `global` reference instead of `window`.
# 1.12.17
## 1.12.17
* Add `moduleName`, `sourceRoot` and `filenameRelative` options. Thanks [@darvelo](https://github.com/darvelo).
* Traversal optimisations.
# 1.12.16
## 1.12.16
* Fix comments not being retained from `MethodDefinition` in classes.
* Add temporal dead zone in default parameters.
# 1.12.15
## 1.12.15
* Update `acorn-6to5`.
# 1.12.14
## 1.12.14
* Fix duplicate let scoping in functions.
* Make JSX whitespace more React-compliant.
* Add `_memberExpressionKeywords` transformer that turns keyword identifiers to computed literals.
* Upgrade `regenerator-6to5`.
# 1.12.13
## 1.12.13
* Support duplicate constants within different block scopes.
* Fix for-head duplication testing and replacement.
* Support `raw` property on tagged template literals.
# 1.12.12
## 1.12.12
* Make scope tracker more reliable to handle all edgecases.
# 1.12.11
## 1.12.11
* Block scope classes.
* Fix generation of integer `Literal`s in `MemberExpression`.
# 1.12.10
## 1.12.10
* Fix let scoping var hoisting.
# 1.12.9
## 1.12.9
* Escape unicode characters when generating string `Literal`s.
* Fix semicolons being output for statements in `ExportDeclaration`.
* Fix `WithStatement` missing parenthesis.
# 1.12.8
## 1.12.8
* Temporarily forbid `AssignmentExpression` destructuring outside of `ExpressionStatement`.
# 1.12.7
## 1.12.7
* Update to latest `acorn-6to5`.
# 1.12.6
## 1.12.6
* Update to latest `acorn-6to5`.
# 1.12.5
## 1.12.5
* Fix excessive whitespace trimming resulting in innaccurate sourcemap line.
# 1.12.4
## 1.12.4
* Add `doc` folder for documentation.
# 1.12.3
## 1.12.3
* Support generator comprehensions.
* Use `Array.from` instead of `Array.prototype.slice` in spread transformer.
* Support spread in `NewExpression`s.
# 1.12.2
## 1.12.2
* Upgrade `matcha` to `0.6.0` and `browserify` to `6.3.2`.
* Add own `trimRight` helper instead of relying on the string instance method.
* Support JSX spreads that aren't the first.
# 1.12.1
## 1.12.1
* Fix `this` and `arguments` mapping in the `_aliasFunctions` transformer.
# 1.12.0
## 1.12.0
* Combine `jsx` and `react` transformers to `react`.
* Update `react` syntax output to React v0.12.
# 1.11.15
## 1.11.15
* Fix JSX literal whitespace generation.
# 1.11.14
## 1.11.14
* Avoid using a switch for let-scoping continue and break statements and use an if statement instead.
* Remove excess whitespace and newlines from JSX literals.
# 1.11.13
## 1.11.13
* Update regenerator-6to5
* Add support for most escodegen formatting options

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

@@ -17,7 +17,7 @@ var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, a
is generated to the following with 6to5:
```javascript
var seattlers = customers.filter(function (c) {
var seattlers = Array.from(customers).filter(function (c) {
return c.city == "Seattle";
}).map(function (c) {
return {
@@ -51,8 +51,7 @@ As you can tell, it's not very pretty, unreadable even. Instead of mapping
directly to a runtime, like other transpilers, 6to5 maps directly to the
equivalent ES5.
I'm not saying 6to5 is for everyone or even suited for everything. Traceur is
better suited if you'd like a full ES6 environment with polyfills and all.
Sometimes there are little things that 6to5 needs
## Comparison to other transpilers

View File

@@ -18,6 +18,8 @@ to5.transform("code", { playground: true });
* [Memoization operator](#memoization-operator)
* [Method binding](#method-binding)
* [Object getter memoization](#object-getter-memoization)
* [This shorthand](#this-shorthand)
### Memoization assignment operator
@@ -66,3 +68,53 @@ 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); });
```
### Object getter memoization
```javascript
var foo = {
memo bar() {
return complex();
}
};
class Foo {
memo bar() {
return complex();
}
}
```
equivalent to
```javascript
var foo = {
get bar() {
if (this._barRan) return this._bar;
this._barRan = true;
return this._bar = complex();
}
};
class Foo {
get bar() {
if (this._barRan) return this._bar;
this._barRan = true;
return this._bar = complex();
}
}
```
**NOTE:** Memoised functions will return the result of the **first** execution, regardless of arguments.
### This shorthand
```javascript
@foo
```
equivalent to
```javascirpt
this.foo
```

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

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

@@ -1,7 +1,6 @@
require("./polyfill");
var sourceMapSupport = require("source-map-support");
var roadrunner = require('roadrunner');
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
@@ -79,15 +78,19 @@ var loader = function (m, filename) {
var result;
if (cache && cache[filename].mtime === mtime(filename)) {
result = cache[filename];
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) {
@@ -126,7 +129,7 @@ module.exports = function (opts) {
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
if (opts.cache) cache = roadrunner.get('6to5');
if (opts.cache) cache = opts.cache;
if (opts.cache === false) cache = null;
_.extend(transformOpts, opts);

View File

@@ -29,6 +29,11 @@ transform.moduleFormatters = {
};
_.each({
// plyground
methodBinding: require("./transformers/playground-method-binding"),
memoizationOperator: require("./transformers/playground-memoization-operator"),
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
modules: require("./transformers/es6-modules"),
propertyNameShorthand: require("./transformers/es6-property-name-shorthand"),
arrayComprehension: require("./transformers/es7-array-comprehension"),
@@ -56,10 +61,6 @@ _.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"),

View File

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

@@ -11,7 +11,7 @@ exports.Function = function (node, parent, file, scope) {
return t.getIds(param);
});
var closure = false;
var iife = false;
_.each(node.defaults, function (def, i) {
if (!def) return;
@@ -29,7 +29,7 @@ exports.Function = function (node, parent, file, scope) {
}
if (scope.has(node.name)) {
closure = true;
iife = true;
}
};
@@ -40,7 +40,7 @@ exports.Function = function (node, parent, file, scope) {
// we're accessing a variable that's already defined within this function
var has = scope.get(param.name);
if (has && !_.contains(node.params, has)) {
closure = true;
iife = true;
}
});
@@ -55,7 +55,7 @@ exports.Function = function (node, parent, file, scope) {
}, true));
});
if (closure) {
if (iife) {
var container = t.functionExpression(null, [], node.body, node.generator);
container._aliasFunction = true;

View File

@@ -27,20 +27,14 @@ var ContinueSentinel = {};
// Dummy constructor that we use as the .constructor property for
// functions that return Generator objects.
var GF = function GeneratorFunction() {};
function GeneratorFunction() {}
var GFp = function GeneratorFunctionPrototype() {};
var Gp = GFp.prototype = Generator.prototype;
(GFp.constructor = GF).prototype =
Gp.constructor = GFp;
// Ensure isGeneratorFunction works when Function#name not supported.
var GFName = "GeneratorFunction";
if (GF.name !== GFName) GF.name = GFName;
if (GF.name !== GFName) throw new Error(GFName + " renamed?");
(GFp.constructor = GeneratorFunction).prototype = Gp.constructor = GFp;
runtime.isGeneratorFunction = function (genFun) {
var ctor = genFun && genFun.constructor;
return ctor ? GF.name === ctor.name : false;
return ctor ? GeneratorFunction.name === ctor.name : false;
};
runtime.mark = function (genFun) {

View File

@@ -27,7 +27,7 @@ exports.VariableDeclaration = function (node) {
isLet(node);
};
exports.For = function (node, parent, file, scope) {
exports.Loop = function (node, parent, file, scope) {
var init = node.left || node.init;
if (isLet(init)) {
t.ensureBlock(node);
@@ -49,7 +49,7 @@ exports.For = function (node, parent, file, scope) {
};
exports.BlockStatement = function (block, parent, file, scope) {
if (!t.isFor(parent)) {
if (!t.isLoop(parent)) {
var letScoping = new LetScoping(false, block, parent, file, scope);
letScoping.run();
}
@@ -58,19 +58,19 @@ exports.BlockStatement = function (block, parent, file, scope) {
/**
* Description
*
* @param {Boolean|Node} forParent
* @param {Boolean|Node} loopParent
* @param {Node} block
* @param {Node} parent
* @param {File} file
* @param {Scope} scope
*/
function LetScoping(forParent, block, parent, file, scope) {
this.forParent = forParent;
this.parent = parent;
this.scope = scope;
this.block = block;
this.file = file;
function LetScoping(loopParent, block, parent, file, scope) {
this.loopParent = loopParent;
this.parent = parent;
this.scope = scope;
this.block = block;
this.file = file;
this.letReferences = {};
this.body = [];
@@ -91,6 +91,9 @@ LetScoping.prototype.run = function () {
// remap all let references that exist in upper scopes to their uid
this.remap();
// add default initializer to let variables in loop bodys
this.initialiseLoopLets();
// this is a block within a `Function` so we can safely leave it be
if (t.isFunction(this.parent)) return this.noClosure();
@@ -106,7 +109,7 @@ LetScoping.prototype.run = function () {
// if we're inside of a for loop then we search to see if there are any
// `break`s, `continue`s, `return`s etc
this.has = this.checkFor();
this.has = this.checkLoop();
// hoist var references to retain scope
this.hoistVarDeclarations();
@@ -172,11 +175,11 @@ LetScoping.prototype.remap = function () {
traverse(node, replace);
};
var forParent = this.forParent;
if (forParent) {
traverseReplace(forParent.right, forParent);
traverseReplace(forParent.test, forParent);
traverseReplace(forParent.update, forParent);
var loopParent = this.loopParent;
if (loopParent) {
traverseReplace(loopParent.right, loopParent);
traverseReplace(loopParent.test, loopParent);
traverseReplace(loopParent.update, loopParent);
}
traverse(block, replace);
@@ -244,6 +247,30 @@ LetScoping.prototype.getInfo = function () {
return opts;
};
/**
* Any let variable declared within a loop body need to have an initializer or
* else they'll be hoisted and subsequent iterations of the loop will have a
* previous state. This function adds a default initializer of `undefined` to
* those variables.
*/
LetScoping.prototype.initialiseLoopLets = function () {
var loopParent = this.loopParent;
if (!loopParent) return;
traverse(this.block, function (node) {
if (t.isFunction(node) || t.isLoop(node)) {
return false;
}
if (isLet(node)) {
_.each(node.declarations, function (declar) {
declar.init = declar.init || t.identifier("undefined");
});
}
});
};
/**
* If we're inside of a `For*Statement` then traverse it and check if it has one
* of the following node types `ReturnStatement`, `BreakStatement`,
@@ -253,24 +280,24 @@ LetScoping.prototype.getInfo = function () {
* @returns {Object}
*/
LetScoping.prototype.checkFor = function () {
LetScoping.prototype.checkLoop = function () {
var has = {
hasContinue: false,
hasReturn: false,
hasBreak: false,
};
var forParent = this.forParent;
traverse(this.block, function (node) {
traverse(this.block, function (node, parent) {
var replace;
if (t.isFunction(node) || t.isFor(node)) {
if (t.isFunction(node) || t.isLoop(node)) {
return false;
}
if (forParent && node && !node.label) {
if (node && !node.label) {
if (t.isBreakStatement(node)) {
if (t.isSwitchCase(parent)) return;
has.hasBreak = true;
replace = t.returnStatement(t.literal("break"));
} else if (t.isContinueStatement(node)) {
@@ -367,7 +394,7 @@ LetScoping.prototype.getLetReferences = function () {
});
return false;
} else if (t.isFor(node)) {
} else if (t.isLoop(node)) {
return false;
}
});
@@ -430,7 +457,7 @@ LetScoping.prototype.buildHas = function (ret, call) {
t.variableDeclarator(ret, call)
]));
var forParent = this.forParent;
var loopParent = this.loopParent;
var retCheck;
var has = this.has;
var cases = [];
@@ -445,7 +472,7 @@ LetScoping.prototype.buildHas = function (ret, call) {
if (has.hasBreak || has.hasContinue) {
// ensure that the parent has a label as we're building a switch and we
// need to be able to access it
var label = forParent.label = forParent.label || this.file.generateUidIdentifier("loop", this.scope);
var label = loopParent.label = loopParent.label || this.file.generateUidIdentifier("loop", this.scope);
if (has.hasBreak) {
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));

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

@@ -31,7 +31,7 @@ exports.TemplateLiteral = function (node) {
var nodes = [];
_.each(node.quasis, function (elem) {
nodes.push(t.literal(elem.value.raw));
nodes.push(t.literal(elem.value.cooked));
var expr = node.expressions.shift();
if (expr) {

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

@@ -7,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(
@@ -39,17 +34,12 @@ exports.BindFunctionExpression = function (node, parent, file, scope) {
};
if (_.find(node.arguments, t.isDynamic)) {
var argsIdName = file.generateUid("args", scope);
var argsId = t.identifier(argsIdName);
scope.push({
key: argsIdName,
id: argsId
});
var temp = scope.generateTemp(file, "args");
return t.sequenceExpression([
t.assignmentExpression("=", argsId, t.arrayExpression(node.arguments)),
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
buildCall(node.arguments.map(function (node, i) {
return t.memberExpression(argsId, t.literal(i), true);
return t.memberExpression(temp, t.literal(i), true);
}))
]);
} else {

View File

@@ -0,0 +1,37 @@
var traverse = require("../../traverse");
var t = require("../../types");
exports.Property =
exports.MethodDefinition = function (node, parent, file, scope) {
if (node.kind !== "memo") return;
node.kind = "get";
var value = node.value;
t.ensureBlock(value);
var body = value.body.body;
var key = node.key;
if (t.isIdentifier(key) && !node.computed) {
key = "_" + key.name;
} else {
key = file.generateUid("memo", scope);
}
var memoId = t.memberExpression(t.thisExpression(), t.identifier(key));
var doneId = t.memberExpression(t.thisExpression(), t.identifier(key + "Done"));
traverse(value, function (node) {
if (t.isFunction(node)) return;
if (t.isReturnStatement(node) && node.argument) {
node.argument = t.assignmentExpression("=", memoId, node.argument);
}
});
// this._barDone = true;
body.unshift(t.expressionStatement(t.assignmentExpression("=", doneId, t.literal(true))));
// if (this._barDone) return this._bar;
body.unshift(t.ifStatement(doneId, t.returnStatement(memoId)));
};

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,13 +3,13 @@
"BreakStatement": ["Statement"],
"ContinueStatement": ["Statement"],
"DebuggerStatement": ["Statement"],
"DoWhileStatement": ["Statement"],
"DoWhileStatement": ["Statement", "Loop", "While"],
"IfStatement": ["Statement"],
"ReturnStatement": ["Statement"],
"SwitchStatement": ["Statement"],
"ThrowStatement": ["Statement"],
"TryStatement": ["Statement"],
"WhileStatement": ["Statement"],
"WhileStatement": ["Statement", "Loop", "While"],
"WithStatement": ["Statement"],
"EmptyStatement": ["Statement"],
"LabeledStatement": ["Statement"],
@@ -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

@@ -162,7 +162,7 @@ t.toIdentifier = function (name) {
return c ? c.toUpperCase() : "";
});
return name;
return name || '_';
};
t.isValidIdentifier = function (name) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.14.7",
"version": "1.15.0",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -35,7 +35,7 @@
"test": "make test"
},
"dependencies": {
"acorn-6to5": "0.9.1-11",
"acorn-6to5": "0.9.1-12",
"ast-types": "0.6.5",
"chokidar": "0.11.1",
"commander": "2.5.0",
@@ -48,18 +48,18 @@
"mkdirp": "0.5.0",
"private": "0.1.6",
"regexpu": "0.3.0",
"roadrunner": "^1.0.4",
"source-map": "0.1.40",
"source-map-support": "0.2.8"
},
"devDependencies": {
"browserify": "6.3.2",
"chai": "^1.9.2",
"istanbul": "0.3.2",
"jshint": "2.5.10",
"jshint-stylish": "^1.0.0",
"matcha": "0.6.0",
"mocha": "1.21.4",
"uglify-js": "2.4.15",
"browserify": "6.3.2",
"rimraf": "2.2.8",
"jshint": "2.5.10",
"chai": "^1.9.2"
"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

@@ -0,0 +1,11 @@
while (value) {
let foo;
if (bar) {
foo = [];
}
if (foo) {
doIt();
}
}

View File

@@ -0,0 +1,13 @@
"use strict";
while (value) {
var foo = undefined;
if (bar) {
foo = [];
}
if (foo) {
doIt();
}
}

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,19 @@
class Foo {
memo bar() {
return complex();
}
memo [bar]() {
return complex();
}
}
var foo = {
memo bar() {
return complex();
},
memo [bar]() {
return complex();
}
};

View File

@@ -0,0 +1,53 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Foo = (function () {
var Foo = function Foo() {};
_classProps(Foo, null, (function (_ref) {
_ref[bar] = {
get: function () {
if (this._memoDone) return this._memo;
this._memoDone = true;
return this._memo = complex();
}
};
return _ref;
})({
bar: {
get: function () {
if (this._barDone) return this._bar;
this._barDone = true;
return this._bar = complex();
}
}
}));
return Foo;
})();
var foo = (function (_foo) {
_foo[bar] = function () {
if (this._memo2Done) return this._memo2;
this._memo2Done = true;
return this._memo2 = complex();
};
return _foo;
})((function (_ref2) {
Object.defineProperties(_ref2, {
bar: {
get: function () {
if (this._barDone) return this._bar;
this._barDone = true;
return this._bar = complex();
}
}
});
return _ref2;
})({}));