Compare commits

...

77 Commits

Author SHA1 Message Date
Sebastian McKenzie
d981c06444 v2.4.4 2015-01-02 19:24:56 +11:00
Sebastian McKenzie
8269e1488b fix incorrect scripts reference in browser 2015-01-02 19:23:50 +11:00
Sebastian McKenzie
ddda7a020f add 2.4.4 changelog 2015-01-02 19:22:03 +11:00
Sebastian McKenzie
7e9340864a lowercase object rest/spread feature name in doc/index 2015-01-02 19:20:14 +11:00
Sebastian McKenzie
5ec19f23c3 add test skeleton for types and add jsdoc comments to types 2015-01-02 19:20:05 +11:00
Sebastian McKenzie
ba48b66458 add types.appendToMemberExpression and types.prependToMemberExpression helpers 2015-01-02 16:46:58 +11:00
Sebastian McKenzie
6e8c73f65f fix incorrect member expression properties 2015-01-02 16:39:35 +11:00
Sebastian McKenzie
b34fcb0cd9 split up method binding and add description for memoization assignment operator 2015-01-02 14:33:51 +11:00
Sebastian McKenzie
ff7129f1aa remove ES5 methods from caveats and change IE classes note to IE 10 and below 2015-01-02 14:33:38 +11:00
Sebastian McKenzie
fbabd193a4 add module type to 6to5 browser 2015-01-02 14:33:18 +11:00
Sebastian McKenzie
876d69798c v2.4.3 2015-01-02 05:19:42 +11:00
Sebastian McKenzie
1a963ddc06 remove unused variable 2015-01-02 05:19:00 +11:00
Sebastian McKenzie
beb5acea6b better addImport with good hoisting etc 2015-01-02 05:18:03 +11:00
Sebastian McKenzie
6a290f233e add 2.4.3 changelog 2015-01-02 05:01:18 +11:00
Sebastian McKenzie
74563d88ed upgrade acorn-6to5 2015-01-02 05:00:23 +11:00
Sebastian McKenzie
a18177026c add support for statements in asyncToGenerator and bluebirdCoroutines transformers 2015-01-02 04:58:59 +11:00
Sebastian McKenzie
a813341433 v2.4.2 2015-01-02 04:25:44 +11:00
Sebastian McKenzie
4968de9803 fix linting errors 2015-01-02 04:24:56 +11:00
Sebastian McKenzie
0de2d33e8d add 2.4.2 changelog 2015-01-02 04:24:19 +11:00
Sebastian McKenzie
6f81ddd0d5 upgrade acorn-6to5 2015-01-02 04:24:19 +11:00
Sebastian McKenzie
6b83055b12 alias flat references in coreAliasing transformer 2015-01-02 04:24:19 +11:00
Sebastian McKenzie
080c23d5ed Merge pull request #360 from mquandalle/patch-1
Extend the license to the new year
2015-01-02 04:06:22 +11:00
Sebastian McKenzie
293bec58d7 remove appveyor badge 2015-01-02 03:53:33 +11:00
Sebastian McKenzie
93ceafc732 better uid names 2015-01-02 03:53:28 +11:00
Sebastian McKenzie
b2bac04b72 update object getter memoization docs to reflect new changes 2015-01-02 03:04:26 +11:00
Sebastian McKenzie
e549c37ca1 v2.4.1 2015-01-02 03:00:33 +11:00
Sebastian McKenzie
02512da38d fix generation tests with parenthesized expressions and trailing comments 2015-01-02 02:59:53 +11:00
Sebastian McKenzie
abe9c4fd30 add 2.4.1 changelog 2015-01-02 02:57:16 +11:00
Sebastian McKenzie
af21c52cc6 set generator on correct node #252 2015-01-02 02:55:55 +11:00
Sebastian McKenzie
706626f79a better whitespace handling of parenthesized comments due to trailing comments 2015-01-02 02:55:40 +11:00
Sebastian McKenzie
b8dd421073 v2.4.0 2015-01-02 02:26:14 +11:00
Sebastian McKenzie
5453c466d6 remove unused variable 2015-01-02 02:24:49 +11:00
Sebastian McKenzie
0cfb2e76b8 add 2.4.0 changelog 2015-01-02 02:24:01 +11:00
Sebastian McKenzie
ba67f57c1e use simple loops always in array comprehensions, support yield inside of array comprehensions - closes #325, fixes #252 2015-01-02 02:14:36 +11:00
Sebastian McKenzie
f1a178f8f9 compact body nodes in traversal 2015-01-02 01:59:49 +11:00
Sebastian McKenzie
b1d1909c64 forced closure on super classes - fixes #339 2015-01-02 01:59:42 +11:00
Sebastian McKenzie
9529f93690 move useStrict transformer to after _moduleFormatter 2015-01-02 01:58:56 +11:00
Sebastian McKenzie
925b1f7600 add optional asyncToGenerator transformer - closes #321 2015-01-02 01:31:14 +11:00
Sebastian McKenzie
40f8bc0a65 add optional bluebird coroutine transformer - @phpnode 2015-01-02 01:20:28 +11:00
Sebastian McKenzie
3a0dbabf5a v2.3.2 2015-01-02 01:04:43 +11:00
Sebastian McKenzie
383912c11b more reliable t.isExpression 2015-01-02 01:04:04 +11:00
Sebastian McKenzie
470c8fced0 add parens on expressions with trailing comments - fixes #349 2015-01-02 00:57:48 +11:00
Sebastian McKenzie
e3dc2355e8 v2.3.1 2015-01-02 00:46:14 +11:00
Sebastian McKenzie
9733cb58c9 remove unused variable 2015-01-02 00:45:26 +11:00
Sebastian McKenzie
edd5a3878a fix redefined variables 2015-01-02 00:45:01 +11:00
Sebastian McKenzie
78d2c4fa8d 2.3.1 changelog 2015-01-02 00:43:54 +11:00
Sebastian McKenzie
e268dc6138 return Object.defineProperties without a closure in property methods assignment unless it's really necessary 2015-01-02 00:42:28 +11:00
Sebastian McKenzie
5b6c0fcacd add whitespace after array and object expressions 2015-01-02 00:41:58 +11:00
Sebastian McKenzie
777f2be14e add undefinedToVoid optional transformer 2015-01-02 00:41:33 +11:00
Sebastian McKenzie
41d60a85e9 simplify define property by using a helper in playground object getter memoization 2015-01-02 00:40:47 +11:00
Sebastian McKenzie
800c350db6 use Object.defineProperty on computed properties - fixes #357 2015-01-02 00:40:37 +11:00
Sebastian McKenzie
7b5b8ab6ed add undefinedToVoid optional transformer 2015-01-02 00:25:17 +11:00
Maxime Quandalle
c7a02ca289 Extend the license to the new year 2015-01-01 13:03:38 +01:00
Sebastian McKenzie
52e23473ed allow export default non-functions mapping to module.exports in common module formatter - fixes #356 2015-01-01 22:58:46 +11:00
Sebastian McKenzie
af412cae28 v2.3.0 2015-01-01 22:40:44 +11:00
Sebastian McKenzie
4c2c96366f add 2.3.0 changelog 2015-01-01 22:40:02 +11:00
Sebastian McKenzie
de427936a6 remove invalid lval super classes in generation tests 2015-01-01 22:38:01 +11:00
Sebastian McKenzie
9d6850d576 fix linting errors 2015-01-01 22:35:08 +11:00
Sebastian McKenzie
20a0280a52 add support for optional transformers 2015-01-01 22:35:02 +11:00
Sebastian McKenzie
64b7d6fa93 more verbose unknown node error message in code generator 2015-01-01 22:34:51 +11:00
Sebastian McKenzie
d7ca7ebbb9 remove Transformer exposure 2015-01-01 22:34:29 +11:00
Sebastian McKenzie
9680730e24 remove forced closure on super classes 2015-01-01 22:34:22 +11:00
Sebastian McKenzie
07667d80ff clean up traverse 2015-01-01 22:34:05 +11:00
Sebastian McKenzie
9a633ebd9c update scope to use new traversal api 2015-01-01 22:33:40 +11:00
Sebastian McKenzie
fac4a61245 use Makefile command shortcuts 2015-01-01 22:33:30 +11:00
Sebastian McKenzie
0ebc073762 update traversal api, removing return false; in favor of this.stop(); 2015-01-01 22:33:17 +11:00
Sebastian McKenzie
860432cdfd hoist export default to very top 2015-01-01 22:31:59 +11:00
Sebastian McKenzie
c408432445 add support for circular references and hoist all variable declarations 2015-01-01 22:30:28 +11:00
Sebastian McKenzie
27e9f9d616 remove invalid lval super class test 2015-01-01 22:29:57 +11:00
Sebastian McKenzie
94a11cd602 add optional core aliasing transformer 2015-01-01 20:02:20 +11:00
Sebastian McKenzie
ab6e424cac make experimental transformers declare that they're experimental 2015-01-01 20:01:24 +11:00
Sebastian McKenzie
9ee7b07cbf add corejs aliasing transformer and support for optional transformers 2015-01-01 20:01:09 +11:00
Sebastian McKenzie
31fff092b6 upgrade acorn-6to5 - fixes #358 and #353 2014-12-31 11:56:04 +11:00
Sebastian McKenzie
e847ac11af add object-getter-memoization template 2014-12-31 11:54:51 +11:00
Sebastian McKenzie
aee1ca45b0 add isFalsyExpression check to superName and make classes a closure if they're inheriting 2014-12-31 11:54:39 +11:00
Sebastian McKenzie
46632e1a97 better object getter memoization - closes #353 2014-12-31 11:54:13 +11:00
Sebastian McKenzie
961e0b9b6b reenable system modules tests 2014-12-31 11:51:52 +11:00
194 changed files with 1837 additions and 805 deletions

View File

@@ -2,6 +2,51 @@
Gaps between patch versions are faulty/broken releases.
## 2.4.4
* Add `module` type to browser build `<script>` handler.
* Fix some `MemberExpression` modifying incorrectly setting `property` to a `MemberExpression`.
## 2.4.3
* Upgrade `acorn-6to5`.
* Add support for `FunctionDeclaration`s in `bluebirdCoroutines` and `asyncToGenerators` transformers.
## 2.4.2
* Upgrade `acorn-6to5`.
* Better uids generated for various transformers based on parent node.
* Alias flat references in `coreAliasing` transformer.
## 2.4.1
* Better whitespace handling of parenthesized expressions due to trailing comments.
* Fix `yield` inside of comprehensions.
## 2.4.0
* Use a closure always for classes with a super.
* Always use native loops for array comprehensions.
* Allow `yield` inside of comprehensions.
* Add optional `bluebirdCoroutine` transformer.
* Add optional `asyncToGenerator` transformer.
* Move `useStrict` transformer to before `_moduleFormatter` causing `"use strict";` to always be placed the very top.
## 2.3.2
* Add parens on expressions with trailing comments.
## 2.3.1
* Add `undefinedToVoid` optional transformer.
* Use `Object.defineProperty` for computed properties.
## 2.3.0
* Upgrade `acorn-6to5`.
* Support circular references and hoist variable declarations in `system` module formatter.
* Add optional transformers, including a new `coreAliasing` transformer that aliases native ES6 static properties to their `core-js` equivalent.
## 2.2.0
* Make `system` module formatter modules anonymous by default.

View File

@@ -1,4 +1,4 @@
Copyright (c) 2014 Sebastian McKenzie
Copyright (c) 2014-2015 Sebastian McKenzie
MIT License

View File

@@ -21,8 +21,7 @@ lint:
test-clean:
rm -rf test/tmp
test:
make lint
test: lint
$(MOCHA_CMD)
make test-clean
@@ -33,8 +32,7 @@ test-cov:
test-spec:
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
test-travis:
make test-spec
test-travis: test-spec
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
test-browser:

View File

@@ -11,10 +11,6 @@
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&amp;label=travis">
</a>
<a href="https://ci.appveyor.com/project/sebmck/6to5">
<img alt="Appveyor Status" src="http://img.shields.io/appveyor/ci/sebmck/6to5.svg?style=flat&amp;label=appveyor">
</a>
<a href="https://codeclimate.com/github/6to5/6to5">
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
</a>

View File

@@ -17,6 +17,7 @@ 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);
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
@@ -28,8 +29,16 @@ commander.on("--help", function(){
console.log(" " + title + ":");
console.log();
var hasOptional = true;
_.each(_.keys(obj).sort(), function (key) {
if (key[0] === "_") return;
if (obj[key].optional) {
hasOptional = true;
key = "[" + key + "]";
}
console.log(" - " + key);
});
@@ -96,6 +105,7 @@ exports.opts = {
blacklist: commander.blacklist,
whitelist: commander.whitelist,
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
optional: commander.optional,
comments: !commander.removeComments,
runtime: commander.runtime,
modules: commander.modules

View File

@@ -9,12 +9,12 @@ You may alternatively selectively include what you need:
| Feature | Requirements |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Abstract References | [experimental](experimental.md), `Symbol` |
| Array destructuring | `Array.isArray`, `Array.from` |
| Array destructuring | `Array.from` |
| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
| Comprehensions | [experimental](experimental.md), `Array.isArray`, `Array.from` |
| Comprehensions | [experimental](experimental.md), `Array.from` |
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
| Spread | `Array.isArray`, `Array.from` |
| Spread | `Array.from` |
## ES5
@@ -26,13 +26,13 @@ ES5 such as lower versions of IE then using the
## Internet Explorer
### Classes (9 and below)
### Classes (10 and below)
If you're inheriting from a class then static properties are inherited from it
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
this is widely supported but you may run into problems with much older browsers.
**NOTE:** `__proto__` is not supported on IE <= 9 so static properties
**NOTE:** `__proto__` is not supported in IE <= 10 so static properties
**will not** be inherited. A possible workaround is to use `super();`:
```javascript
@@ -56,4 +56,4 @@ unfortunate as it's required to set getters and setters. Due to this if
you plan on supporting IE8 or below then the user of getters and setters
isn't recommended.
Reference: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).
**Reference**: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).

View File

@@ -52,7 +52,7 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
- [Let scoping](features.md#let-scoping)
- [Modules](features.md#modules)
- [Numeric literals](features.md#numeric-literals)
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](experimental.md))
- [Object rest/spread](features.md#object-rest-spread) ([experimental](experimental.md))
- [Property method assignment](features.md#property-method-assignment)
- [Property name shorthand](features.md#property-name-shorthand)
- [React/JSX](react.md)

View File

@@ -18,11 +18,19 @@ to5.transform("code", { playground: true });
* [Memoization operator](#memoization-operator)
* [Method binding](#method-binding)
* [Method binding function shorthand](#method-binding-function-shorthand)
* [Object getter memoization](#object-getter-memoization)
* [This shorthand](#this-shorthand)
### Memoization assignment operator
The memoization assignment operator allows you to lazily set an object property.
It checks whether there's a property defined on the object and if there isn't then
the right hand value is set.
This means that `obj.x` in the following `var x = { x: undefined }; obj.x ?= 2;`
will still be `undefined` because it's already been defined on the object.
```javascript
var obj = {};
obj.x ?= 2;
@@ -42,7 +50,7 @@ var obj = {};
obj.x ?= 2;
```
equivalent to:
equivalent to
```javascript
var obj = {};
@@ -54,17 +62,25 @@ if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
```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:
equivalent to
```javascript
var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");
```
### Method binding function shorthand
```javascript
["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"]
```
equivalent to
```javascript
["foo", "bar"].map(function (val) { return val.toUpperCase(); });
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });
```
@@ -90,23 +106,27 @@ equivalent to
```javascript
var foo = {
get bar() {
if (this._barRan) return this._bar;
this._barRan = true;
return this._bar = complex();
return Object.defineProperty(this, "bar", {
value: complex(),
enumerable: true,
configurable: true,
writable: true
}).bar;
}
};
class Foo {
get bar() {
if (this._barRan) return this._bar;
this._barRan = true;
return this._bar = complex();
return Object.defineProperty(this, "bar", {
value: complex(),
enumerable: true,
configurable: true,
writable: true
}).bar;
}
}
```
**NOTE:** Memoised functions will return the result of the **first** execution, regardless of arguments.
### This shorthand
```javascript

View File

@@ -34,7 +34,7 @@ transform.load = function (url, callback, opts, hold) {
var runScripts = function () {
var scripts = [];
var types = ["text/ecmascript-6", "text/6to5"];
var types = ["text/ecmascript-6", "text/6to5", "module"];
var index = 0;
var exec = function () {
@@ -60,8 +60,9 @@ var runScripts = function () {
}
};
var _scripts = global.document.getElementsByTagName("script");
for (var i in _scripts) {
var _scripts = global.document .getElementsByTagName("script");
for (var i = 0; i < _scripts.length; ++i) {
var _script = _scripts[i];
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
}

View File

@@ -10,9 +10,11 @@ var t = require("./types");
var _ = require("lodash");
function File(opts) {
this.opts = File.normaliseOptions(opts);
this.uids = {};
this.ast = {};
this.dynamicImports = [];
this.opts = File.normaliseOptions(opts);
this.transformers = this.getTransformers();
this.uids = {};
this.ast = {};
}
File.declarations = [
@@ -25,7 +27,13 @@ File.declarations = [
"sliced-to-array",
"object-without-properties",
"has-own",
"slice"
"slice",
"define-property",
"async-to-generator"
];
File.excludeDeclarationsFromRuntime = [
"async-to-generator"
];
File.normaliseOptions = function (opts) {
@@ -39,6 +47,7 @@ File.normaliseOptions = function (opts) {
blacklist: [],
whitelist: [],
sourceMap: false,
optional: [],
comments: true,
filename: "unknown",
modules: "common",
@@ -80,10 +89,28 @@ File.normaliseOptions = function (opts) {
transform._ensureTransformerNames("blacklist", opts.blacklist);
transform._ensureTransformerNames("whitelist", opts.whitelist);
transform._ensureTransformerNames("optional", opts.optional);
return opts;
};
File.prototype.getTransformers = function () {
var file = this;
var transformers = [];
_.each(transform.transformers, function (transformer) {
if (transformer.canRun(file)) {
transformers.push(transformer);
if (transformer.manipulateOptions) {
transformer.manipulateOptions(file.opts, file);
}
}
});
return transformers;
};
File.prototype.toArray = function (node, i) {
if (t.isArrayExpression(node)) {
return node;
@@ -127,6 +154,13 @@ File.prototype.parseShebang = function (code) {
return code;
};
File.prototype.addImport = function (id, source) {
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
var declar = t.importDeclaration(specifiers, t.literal(source));
declar._blockHoist = 3;
this.dynamicImports.push(declar);
};
File.prototype.addDeclaration = function (name) {
if (!_.contains(File.declarations, name)) {
throw new ReferenceError("unknown declaration " + name);
@@ -139,7 +173,7 @@ File.prototype.addDeclaration = function (name) {
var ref;
var runtimeNamespace = this.opts.runtime;
if (runtimeNamespace) {
if (runtimeNamespace && !_.contains(File.excludeDeclarationsFromRuntime, name)) {
name = t.identifier(t.toIdentifier(name));
return t.memberExpression(t.identifier(runtimeNamespace), name);
} else {
@@ -182,15 +216,25 @@ File.prototype.parse = function (code) {
};
File.prototype.transform = function (ast) {
var self = this;
this.ast = ast;
this.scope = new Scope(ast.program);
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
var self = this;
var astRun = function (key) {
_.each(self.transformers, function (transformer) {
transformer.astRun(self, key);
});
};
_.each(transform.transformers, function (transformer) {
astRun("enter");
_.each(this.transformers, function (transformer) {
transformer.transform(self);
});
astRun("exit");
};
File.prototype.generate = function () {

View File

@@ -115,6 +115,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
if (!node) return "";
var self = this;
opts = opts || {};
var newline = function (leading) {
@@ -147,6 +148,12 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
};
if (this[node.type]) {
var needsCommentParens = t.isExpression(node) && node.leadingComments && node.leadingComments.length;
var needsParens = needsCommentParens || n.needsParens(node, parent);
if (needsParens) this.push("(");
if (needsCommentParens) this.indent();
this.printLeadingComments(node, parent);
newline(true);
@@ -154,13 +161,12 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
if (opts.before) opts.before();
this.map.mark(node, "start");
// only compute if this node needs parens if our parent has been changed
// since acorn would've wrapped us in a ParanthesizedExpression
var needsParens = n.needsParens(node, parent);
if (needsParens) this.push("(");
this[node.type](node, this.buildPrint(node), parent);
if (needsCommentParens) {
this.newline();
this.dedent();
}
if (needsParens) this.push(")");
this.map.mark(node, "end");
@@ -170,7 +176,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
this.printTrailingComments(node, parent);
} else {
throw new ReferenceError("unknown node " + node.type);
throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name));
}
};

View File

@@ -98,6 +98,10 @@ exports.MemberExpression = function (node, print) {
var obj = node.object;
print(obj);
if (!node.computed && t.isMemberExpression(node.property)) {
throw new TypeError("Got a MemberExpression for MemberExpression property");
}
if (node.computed) {
this.push("[");
print(node.property);

View File

@@ -55,6 +55,8 @@ _.each({
Function: 1,
Class: 1,
For: 1,
ArrayExpression: { after: 1 },
ObjectExpression: { after: 1 },
SwitchStatement: 1,
IfStatement: { before: 1 },
CallExpression: { after: 1 },

View File

@@ -3,8 +3,6 @@ var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
exports.Transformer = require("./transformation/transformer");
exports.types = require("./types");
exports.runtime = require("./runtime-generator");

View File

@@ -19,6 +19,10 @@ module.exports = function (namespace) {
]));
_.each(File.declarations, function (name) {
if (_.contains(File.excludeDeclarationsFromRuntime, name)) {
return false;
}
var key = t.identifier(t.toIdentifier(name));
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))

View File

@@ -124,9 +124,9 @@ DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
return ref;
};
DefaultFormatter.prototype._hoistExport = function (declar, assign) {
DefaultFormatter.prototype._hoistExport = function (declar, assign, priority) {
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
assign._blockHoist = priority || 2;
}
return assign;
@@ -139,17 +139,18 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
if (node.source) {
if (t.isExportBatchSpecifier(specifier)) {
// export * from "foo";
nodes.push(this._exportsWildcard(getRef()));
nodes.push(this._exportsWildcard(getRef(), node));
} else {
// export { foo } from "test";
nodes.push(this._exportsAssign(
t.getSpecifierName(specifier),
t.memberExpression(getRef(), specifier.id)
t.memberExpression(getRef(), specifier.id),
node
));
}
} else {
// export { foo };
nodes.push(this._exportsAssign(t.getSpecifierName(specifier), specifier.id));
nodes.push(this._exportsAssign(t.getSpecifierName(specifier), specifier.id, node));
}
};
@@ -181,7 +182,7 @@ DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
for (var i in declar.declarations) {
var decl = declar.declarations[i];
decl.init = this._exportsAssign(decl.id, decl.init).expression;
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
if (i === "0") t.inherits(newDeclar, declar);
@@ -195,7 +196,7 @@ DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
nodes.push(declar);
}
assign = this._exportsAssign(id, ref);
assign = this._exportsAssign(id, ref, node);
nodes.push(assign);

View File

@@ -57,6 +57,7 @@ CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
if (node.default) {
var declar = node.declaration;
var assign;
// module.exports = VALUE;
var templateName = "exports-default-module";
@@ -64,15 +65,29 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
// exports = module.exports = VALUE;
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
var assign = util.template(templateName, {
VALUE: this._pushStatement(declar, nodes)
}, true);
if (t.isFunction(declar) || !this.hasNonDefaultExports) {
assign = util.template(templateName, {
VALUE: this._pushStatement(declar, nodes)
}, true);
// hoist to the top if this default is a function
nodes.push(this._hoistExport(declar, assign));
} else {
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
// hoist to the top if this default is a function
nodes.push(this._hoistExport(declar, assign, 3));
return;
} else {
// this export isn't a function so we can't hoist it to the top so we need to set it
// at the very end of the file with something like:
//
// module.exports = Object.assign(exports["default"], exports)
//
assign = util.template("common-export-default-assign", true);
assign._blockHoist = 0;
nodes.push(assign);
}
}
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
};
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {

View File

@@ -15,8 +15,13 @@ function SystemFormatter(file) {
util.inherits(SystemFormatter, AMDFormatter);
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier) {
var leftIdentifier = t.identifier("i");
SystemFormatter.prototype._addImportSource = function (node, exportNode) {
node._importSource = exportNode.source && exportNode.source.value;
return node;
};
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier, node) {
var leftIdentifier = this.file.generateUidIdentifier("key");
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
var left = t.variableDeclaration("var", [
@@ -29,11 +34,12 @@ SystemFormatter.prototype._exportsWildcard = function (objectIdentifier) {
this.buildExportCall(leftIdentifier, valIdentifier)
]);
return t.forInStatement(left, right, block);
return this._addImportSource(t.forInStatement(left, right, block), node);
};
SystemFormatter.prototype._exportsAssign = function (id, init) {
return this.buildExportCall(t.literal(id.name), init, true);
SystemFormatter.prototype._exportsAssign = function (id, init, node) {
var call = this.buildExportCall(t.literal(id.name), init, true);
return this._addImportSource(call, node);
};
SystemFormatter.prototype.remapExportAssignment = function (node) {
@@ -49,28 +55,53 @@ SystemFormatter.prototype.buildExportCall = function (id, init, isStatement) {
}
};
SystemFormatter.prototype.buildRunnerSetters = function () {
return t.arrayExpression(_.map(this.ids, function (uid) {
var moduleIdentifier = t.identifier("m");
SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
this._addImportSource(_.last(nodes), node);
};
return t.functionExpression(null, [moduleIdentifier], t.blockStatement([
t.assignmentExpression("=", uid, moduleIdentifier)
]));
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
return t.arrayExpression(_.map(this.ids, function (uid, source) {
var nodes = [];
traverse(block, {
enter: function (node) {
if (node._importSource === source) {
if (t.isVariableDeclaration(node)) {
_.each(node.declarations, function (declar) {
hoistDeclarators.push(t.variableDeclarator(declar.id));
nodes.push(t.expressionStatement(
t.assignmentExpression("=", declar.id, declar.init)
));
});
} else {
nodes.push(node);
}
this.remove();
}
}
});
return t.functionExpression(null, [uid], t.blockStatement(nodes));
}));
};
SystemFormatter.prototype.transform = function (ast) {
var program = ast.program;
var hoistDeclarators = [];
var moduleName = this.getModuleName();
var moduleNameLiteral = t.literal(moduleName);
var block = t.blockStatement(program.body);
var runner = util.template("system", {
MODULE_NAME: moduleNameLiteral,
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
EXPORT_IDENTIFIER: this.exportIdentifier,
SETTERS: this.buildRunnerSetters(),
EXECUTE: t.functionExpression(null, [], t.blockStatement(program.body))
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
EXECUTE: t.functionExpression(null, [], block)
}, true);
var handlerBody = runner.expression.arguments[2].body.body;
@@ -78,8 +109,55 @@ SystemFormatter.prototype.transform = function (ast) {
var returnStatement = handlerBody.pop();
// hoist up all variable declarations
traverse(block, {
enter: function (node, parent, scope) {
if (t.isFunction(node)) {
// nothing inside is accessible
return this.stop();
}
if (t.isVariableDeclaration(node)) {
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
// can't be accessed
return;
}
var nodes = [];
_.each(node.declarations, function (declar) {
hoistDeclarators.push(t.variableDeclarator(declar.id));
if (declar.init) {
// no initializer so we can just hoist it as-is
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
nodes.push(assign);
}
});
// for (var i in test)
// for (var i = 0;;)
if (t.isFor(parent)) {
if (parent.left === node) {
return node.declarations[0].id;
}
if (parent.init === node) {
return t.toSequenceExpression(nodes, scope);
}
}
return nodes;
}
}
});
if (hoistDeclarators.length) {
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
hoistDeclar._blockHoist = true;
handlerBody.unshift(hoistDeclar);
}
// hoist up function declarations for circular references
traverse(program, {
traverse(block, {
enter: function (node) {
if (t.isFunction(node)) this.stop();
@@ -90,12 +168,6 @@ SystemFormatter.prototype.transform = function (ast) {
}
});
if (!_.isEmpty(this.ids)) {
handlerBody.push(t.variableDeclaration("var", _.map(this.ids, function (uid) {
return t.variableDeclarator(uid);
})));
}
handlerBody.push(returnStatement);
program.body = [runner];

View File

@@ -1,5 +0,0 @@
ARRAY.filter(function (KEY) {
return FILTER;
}).map(function (KEY) {
return STATEMENT;
});

View File

@@ -1,3 +0,0 @@
ARRAY.map(function (KEY) {
return STATEMENT;
});

View File

@@ -0,0 +1,37 @@
(function (fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(getNext) {
var next;
try {
next = getNext();
} catch(e) {
reject(e);
return;
}
if (next.done) {
resolve(next.value);
return;
}
Promise.resolve(next.value).then(function (v) {
step(function () {
return gen.next(v);
});
}, function (e) {
step(function () {
return gen["throw"](e);
});
});
}
step(function () {
return gen.next();
});
});
}
})

View File

@@ -0,0 +1 @@
module.exports = Object.assign(exports["default"], exports);

View File

@@ -0,0 +1 @@
CORE_ID.$for.getIterator(VALUE);

View File

@@ -0,0 +1,8 @@
(function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
});

View File

@@ -1,3 +0,0 @@
(function (KEY) {
return KEY;
})(OBJECT)

View File

@@ -1,4 +0,0 @@
(function (KEY) {
CONTENT;
return KEY;
})(OBJECT);

View File

@@ -49,6 +49,9 @@ _.each({
memoizationOperator: require("./transformers/playground-memoization-operator"),
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
asyncToGenerator: require("./transformers/optional-async-to-generator"),
bluebirdCoroutines: require("./transformers/optional-bluebird-coroutines"),
react: require("./transformers/react"),
modules: require("./transformers/es6-modules"),
propertyNameShorthand: require("./transformers/es6-property-name-shorthand"),
@@ -80,10 +83,13 @@ _.each({
_declarations: require("./transformers/_declarations"),
coreAliasing: require("./transformers/optional-core-aliasing"),
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
// wrap up
_aliasFunctions: require("./transformers/_alias-functions"),
useStrict: require("./transformers/use-strict"),
_moduleFormatter: require("./transformers/_module-formatter"),
useStrict: require("./transformers/use-strict"),
// spec
specPropertyLiterals: require("./transformers/spec-property-literals"),

View File

@@ -5,9 +5,12 @@ var t = require("../types");
var _ = require("lodash");
function Transformer(key, transformer, opts) {
this.transformer = Transformer.normalise(transformer);
this.opts = opts || {};
this.key = key;
this.manipulateOptions = transformer.manipulateOptions;
this.experimental = !!transformer.experimental;
this.transformer = Transformer.normalise(transformer);
this.optional = !!transformer.optional;
this.opts = opts || {};
this.key = key;
}
Transformer.normalise = function (transformer) {
@@ -16,8 +19,13 @@ Transformer.normalise = function (transformer) {
}
_.each(transformer, function (fns, type) {
// hidden property
if (type[0] === "_") return;
if (_.isFunction(fns)) fns = { enter: fns };
if (!_.isObject(fns)) return;
transformer[type] = fns;
var aliases = t.FLIPPED_ALIAS_KEYS[type];
@@ -41,13 +49,9 @@ Transformer.prototype.astRun = function (file, key) {
};
Transformer.prototype.transform = function (file) {
if (!this.canRun(file)) return;
var transformer = this.transformer;
var ast = file.ast;
this.astRun(file, "enter");
var build = function (exit) {
return function (node, parent, scope) {
var fns = transformer[node.type];
@@ -61,12 +65,14 @@ Transformer.prototype.transform = function (file) {
};
};
this.astRun(file, "before");
traverse(ast, {
enter: build(),
exit: build(true)
});
this.astRun(file, "exit");
this.astRun(file, "after");
};
Transformer.prototype.canRun = function (file) {
@@ -80,5 +86,9 @@ Transformer.prototype.canRun = function (file) {
var whitelist = opts.whitelist;
if (whitelist.length && !_.contains(whitelist, key)) return false;
if (this.optional && !_.contains(opts.optional, key)) return false;
if (this.experimental && !opts.experimental) return false;
return true;
};

View File

@@ -20,7 +20,7 @@ var go = function (getBody, node, file, scope) {
if (!node._aliasFunction) {
if (t.isFunction(node)) {
// stop traversal of this node as it'll be hit again by this transformer
return false;
return this.stop();
} else {
return;
}
@@ -30,10 +30,10 @@ var go = function (getBody, node, file, scope) {
traverse(node, {
enter: function (node, parent) {
if (t.isFunction(node) && !node._aliasFunction) {
return false;
return this.stop();
}
if (node._ignoreAliasFunctions) return false;
if (node._ignoreAliasFunctions) return this.stop();
var getId;
@@ -49,7 +49,7 @@ var go = function (getBody, node, file, scope) {
}
});
return false;
return this.stop();
}
});

View File

@@ -1,17 +1,29 @@
var _ = require("lodash");
// Priority:
//
// - 0 We want this to be at the **very** bottom
// - 1 Default node position
// - 2 Priority over normal nodes
// - 3 We want this to be at the **very** top
exports.BlockStatement =
exports.Program = {
exit: function (node) {
var unshift = [];
var hasChange = false;
for (var i in node.body) {
var bodyNode = node.body[i];
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
}
if (!hasChange) return;
node.body = node.body.filter(function (bodyNode) {
if (bodyNode._blockHoist) {
unshift.push(bodyNode);
return false;
} else {
return true;
}
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
var priority = bodyNode._blockHoist;
if (priority == null) priority = 1;
if (priority === true) priority = 2;
return priority;
});
node.body = unshift.concat(node.body);
node.body = _.flatten(_.values(nodePriorities).reverse());
}
};

View File

@@ -1,4 +1,5 @@
var util = require("../../util");
var t = require("../../types");
exports.Property = function (node) {
if (node.method) node.method = false;
@@ -20,14 +21,21 @@ exports.ObjectExpression = function (node, parent, file) {
if (!hasAny) return;
var objId = util.getUid(parent, file);
if (node.properties.length) {
var objId = t.getUid(parent, file);
return util.template("object-define-properties-closure", {
KEY: objId,
OBJECT: node,
CONTENT: util.template("object-define-properties", {
OBJECT: objId,
return util.template("object-define-properties-closure", {
KEY: objId,
OBJECT: node,
CONTENT: util.template("object-define-properties", {
OBJECT: objId,
PROPS: util.buildDefineProperties(mutatorMap)
})
});
} else {
return util.template("object-define-properties", {
OBJECT: node,
PROPS: util.buildDefineProperties(mutatorMap)
})
});
});
}
};

View File

@@ -21,7 +21,7 @@ exports.ClassDeclaration = function (node, parent, file, scope) {
});
return t.assignmentExpression("=", node.id, newNode);
} else {
// likely has a PrivateDeclaration etc
// has a super class or PrivateDeclaration etc
return t.variableDeclaration("let", [
t.variableDeclarator(node.id, newNode)
]);
@@ -85,23 +85,17 @@ Class.prototype.run = function () {
//
if (superName && t.isDynamic(superName)) {
// so we're only evaluating it once
var superRefName = "super";
if (className) superRefName = className.name + "Super";
if (superName) {
this.closure = true;
var superRef = file.generateUidIdentifier(superRefName, this.scope);
// so we're only evaluating it once
var superRef = t.getUid(superName, this.file);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(superRef, superName)
]));
superName = superRef;
}
this.superName = superName;
//
if (superName) {
this.superName = superName;
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName])));
}
@@ -153,7 +147,7 @@ Class.prototype.buildBody = function () {
}
}
if (!this.hasConstructor && superName) {
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
constructor.body.body.push(util.template("class-super-constructor-call", {
SUPER_NAME: superName
}, true));
@@ -282,7 +276,7 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
callee.property = t.memberExpression(callee.property, t.identifier("call"));
t.appendToMemberExpression(callee, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
}
}

View File

@@ -1,47 +1,96 @@
var util = require("../../util");
var t = require("../../types");
var t = require("../../types");
exports.ObjectExpression = function (node, parent, file) {
var hasComputed = false;
var prop;
var key;
var i;
var computed = [];
node.properties = node.properties.filter(function (prop) {
if (prop.computed) {
hasComputed = true;
computed.unshift(prop);
return false;
} else {
return true;
}
});
for (i in node.properties) {
hasComputed = t.isProperty(node.properties[i], { computed: true });
if (hasComputed) break;
}
if (!hasComputed) return;
var objId = util.getUid(parent, file);
var objId = t.getUid(parent, file);
var container = util.template("function-return-obj", {
KEY: objId,
OBJECT: node
});
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
container._aliasFunction = true;
var containerCallee = container.callee;
var containerBody = containerCallee.body.body;
var props = node.properties;
containerCallee._aliasFunction = true;
// normalise key
for (var i in computed) {
var prop = computed[i];
containerBody.unshift(
t.expressionStatement(
t.assignmentExpression(
"=",
t.memberExpression(objId, prop.key, true),
prop.value
)
)
);
for (i in props) {
prop = props[i];
key = prop.key;
if (!prop.computed && t.isIdentifier(key)) {
prop.key = t.literal(key.name);
}
}
return container;
// add all non-computed properties and `__proto__` properties to the initializer
var initProps = [];
var broken = false;
for (i in props) {
prop = props[i];
if (prop.computed) {
broken = true;
}
if (!broken || t.isLiteral(prop.key, { value: "__proto__" })) {
initProps.push(prop);
props[i] = null;
}
}
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
// otherwise use Object.defineProperty
for (i in props) {
prop = props[i];
if (!prop) continue;
key = prop.key;
var bodyNode;
if (prop.computed && t.isMemberExpression(key) && t.isIdentifier(key.object, { name: "Symbol" })) {
bodyNode = t.assignmentExpression(
"=",
t.memberExpression(objId, key, true),
prop.value
);
} else {
bodyNode = t.callExpression(file.addDeclaration("define-property"), [objId, key, prop.value]);
}
body.push(t.expressionStatement(bodyNode));
}
// only one node and it's a Object.defineProperty that returns the object
if (body.length === 1) {
var first = body[0].expression;
if (t.isCallExpression(first)) {
first.arguments[0] = t.objectExpression([]);
return first;
}
}
//
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(objId, t.objectExpression(initProps))
]));
body.push(t.returnStatement(objId));
return t.callExpression(container, []);
};

View File

@@ -75,7 +75,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
var _parentId = opts.file.generateUidIdentifier("ref", opts.scope);
var _parentId = t.getUid(parentId, opts.file, opts.scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(_parentId, toArray)
]));
@@ -113,7 +113,7 @@ var pushPattern = function (opts) {
var scope = opts.scope;
if (!t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
var key = file.generateUidIdentifier("ref", scope);
var key = t.getUid(parentId, file, scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(key, parentId)

View File

@@ -1 +1,3 @@
module.exports = require("regenerator").transform;
exports.ast = {
before: require("regenerator").transform
};

View File

@@ -280,7 +280,7 @@ LetScoping.prototype.checkLoop = function () {
var replace;
if (t.isFunction(node) || t.isLoop(node)) {
return false;
return this.stop();
}
if (node && !node.label) {
@@ -329,7 +329,7 @@ LetScoping.prototype.hoistVarDeclarations = function () {
} else if (isVar(node, parent)) {
return self.pushDeclar(node).map(t.expressionStatement);
} else if (t.isFunction(node)) {
return false;
return this.stop();
}
}
});
@@ -388,9 +388,9 @@ LetScoping.prototype.getLetReferences = function () {
}
});
return false;
return this.stop();
} else if (t.isLoop(node)) {
return false;
return this.stop();
}
}
});

View File

@@ -1,5 +1,11 @@
var t = require("../../types");
exports.ast = {
before: function (ast, file) {
ast.program.body = file.dynamicImports.concat(ast.program.body);
}
};
exports.ImportDeclaration = function (node, parent, file) {
var nodes = [];
@@ -11,6 +17,12 @@ exports.ImportDeclaration = function (node, parent, file) {
file.moduleFormatter.importDeclaration(node, nodes, parent);
}
if (nodes.length === 1) {
// inherit `_blockHoist`
// this for `_blockHoist` in File.prototype.addImport
nodes[0]._blockHoist = node._blockHoist;
}
return nodes;
};

View File

@@ -87,13 +87,7 @@ exports.CallExpression = function (node, parent, file, scope) {
callee.object = t.assignmentExpression("=", temp, callee.object);
}
if (callee.computed) {
callee.object = t.memberExpression(callee.object, callee.property, true);
callee.property = t.identifier("apply");
callee.computed = false;
} else {
callee.property = t.memberExpression(callee.property, t.identifier("apply"));
}
t.appendToMemberExpression(callee, t.identifier("apply"));
} else {
node.callee = t.memberExpression(node.callee, t.identifier("apply"));
}

View File

@@ -3,6 +3,8 @@
var util = require("../../util");
var t = require("../../types");
exports.experimental = true;
var container = function (parent, call, ret) {
if (t.isExpressionStatement(parent)) {
// we don't need to worry about return values

View File

@@ -1,41 +1,25 @@
var util = require("../../util");
var t = require("../../types");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var single = function (node, file) {
var block = node.blocks[0];
exports.experimental = true;
var templateName = "array-expression-comprehension-map";
if (node.filter) templateName = "array-expression-comprehension-filter";
var result = util.template(templateName, {
STATEMENT: node.body,
FILTER: node.filter,
ARRAY: file.toArray(block.right),
KEY: block.left
});
var aliasPossibles = [result.callee.object, result];
for (var i in aliasPossibles) {
var call = aliasPossibles[i];
if (t.isCallExpression(call)) {
call.arguments[0]._aliasFunction = true;
}
}
return result;
};
var multiple = function (node, file) {
var uid = file.generateUidIdentifier("arr");
var build = function (node, parent, file, scope) {
var uid = t.getUid(parent, file, scope);
var container = util.template("array-comprehension-container", {
KEY: uid
});
container.callee.expression._aliasFunction = true;
container.callee._aliasFunction = true;
var block = container.callee.body;
var body = block.body;
if (traverse.hasType(node, "YieldExpression", t.FUNCTION_TYPES)) {
container.callee.generator = true;
container = t.yieldExpression(container, true);
}
var returnStatement = body.pop();
body.push(exports._build(node, function () {
@@ -71,12 +55,8 @@ exports._build = function (node, buildBody) {
);
};
exports.ComprehensionExpression = function (node, parent, file) {
exports.ComprehensionExpression = function (node, parent, file, scope) {
if (node.generator) return;
if (node.blocks.length === 1) {
return single(node, file);
} else {
return multiple(node, file);
}
return build(node, parent, file, scope);
};

View File

@@ -1,5 +1,7 @@
// https://github.com/rwaldron/exponentiation-operator
exports.experimental = true;
var t = require("../../types");
var pow = t.memberExpression(t.identifier("Math"), t.identifier("pow"));

View File

@@ -1,6 +1,8 @@
var arrayComprehension = require("./es7-array-comprehension");
var t = require("../../types");
exports.experimental = true;
exports.ComprehensionExpression = function (node) {
if (!node.generator) return;

View File

@@ -2,6 +2,8 @@
var t = require("../../types");
exports.experimental = true;
exports.ObjectExpression = function (node) {
var hasSpread = false;
var i;

View File

@@ -0,0 +1,11 @@
var bluebirdCoroutines = require("./optional-bluebird-coroutines");
exports.optional = true;
exports.manipulateOptions = bluebirdCoroutines.manipulateOptions;
exports.Function = function (node, parent, file) {
if (!node.async || node.generator) return;
return bluebirdCoroutines._Function(node, file.addDeclaration("async-to-generator"));
};

View File

@@ -0,0 +1,45 @@
var traverse = require("../../traverse");
var t = require("../../types");
exports.manipulateOptions = function (opts) {
opts.experimental = true;
opts.blacklist.push("generators");
};
exports.optional = true;
exports._Function = function (node, callId) {
node.async = false;
node.generator = true;
traverse(node, {
enter: function (node) {
if (t.isFunction(node)) this.stop();
if (t.isAwaitExpression(node)) {
node.type = "YieldExpression";
}
}
});
var call = t.callExpression(callId, [node]);
if (t.isFunctionDeclaration(node)) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(node.id, call)
]);
declar._blockHoist = true;
return declar;
} else {
return call;
}
};
exports.Function = function (node, parent, file) {
if (!node.async || node.generator) return;
var id = t.identifier("Bluebird");
file.addImport(id, "bluebird");
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
};

View File

@@ -0,0 +1,59 @@
var traverse = require("../../traverse");
var util = require("../../util");
var core = require("core-js/library");
var t = require("../../types");
var _ = require("lodash");
var coreHas = function (node) {
return node.name !== "_" && _.has(core, node.name);
};
exports.optional = true;
exports.ast = {
enter: function (ast, file) {
file._coreId = file.generateUidIdentifier("core");
file.addImport(file._coreId, "core-js/library");
},
exit: function (ast, file) {
traverse(ast, {
enter: function (node, parent) {
var prop;
if (t.isMemberExpression(node) && t.isReferenced(node, parent)) {
// Array.from -> _core.Array.from
var obj = node.object;
prop = node.property;
if (!t.isReferenced(obj, node)) return;
if (!node.computed && coreHas(obj) && _.has(core[obj.name], prop.name)) {
this.stop();
return t.prependToMemberExpression(node, file._coreId);
}
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && coreHas(node)) {
// new Promise -> new _core.Promise
return t.memberExpression(file._coreId, node);
} else if (t.isCallExpression(node)) {
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
if (node.arguments.length) return;
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (!callee.computed) return;
prop = callee.property;
if (!t.isIdentifier(prop.object, { name: "Symbol" })) return;
if (!t.isIdentifier(prop.property, { name: "iterator" })) return;
return util.template("corejs-iterator", {
CORE_ID: file._coreId,
VALUE: callee.object
});
}
}
});
}
};

View File

@@ -0,0 +1,9 @@
var t = require("../../types");
exports.optional = true;
exports.Identifier = function (node, parent) {
if (node.name === "undefined" && t.isReferenced(node, parent)) {
return t.unaryExpression("void", t.literal(0), true);
}
};

View File

@@ -10,7 +10,7 @@ var getPropRef = function (nodes, prop, file, scope) {
if (t.isIdentifier(prop)) {
return t.literal(prop.name);
} else {
var temp = file.generateUidIdentifier("propKey", scope);
var temp = t.getUid(prop, file, scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(temp, prop)
]));
@@ -20,7 +20,7 @@ var getPropRef = function (nodes, prop, file, scope) {
var getObjRef = function (nodes, obj, file, scope) {
if (t.isDynamic(obj)) {
var temp = file.generateUidIdentifier("obj", scope);
var temp = t.getUid(obj, file, scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(temp, obj)
]));

View File

@@ -2,38 +2,30 @@ var traverse = require("../../traverse");
var t = require("../../types");
exports.Property =
exports.MethodDefinition = function (node, parent, file, scope) {
exports.MethodDefinition = function (node, parent, file) {
if (node.kind !== "memo") return;
node.kind = "get";
var value = node.value;
t.ensureBlock(value);
var body = value.body.body;
var key = node.key;
var key = node.key;
if (t.isIdentifier(key) && !node.computed) {
key = "_" + key.name;
} else {
key = file.generateUid("memo", scope);
key = t.literal(key.name);
}
var memoId = t.memberExpression(t.thisExpression(), t.identifier(key));
var doneId = t.memberExpression(t.thisExpression(), t.identifier(key + "Done"));
traverse(value, {
enter: function (node) {
if (t.isFunction(node)) return;
if (t.isReturnStatement(node) && node.argument) {
node.argument = t.assignmentExpression("=", memoId, node.argument);
node.argument = t.memberExpression(t.callExpression(file.addDeclaration("define-property"), [
t.thisExpression(),
key,
node.argument
]), key, true);
}
}
});
// 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

@@ -1,12 +1,14 @@
var t = require("../../types");
module.exports = function (ast) {
var body = ast.program.body;
var first = body[0];
exports.ast = {
exit: function (ast) {
var body = ast.program.body;
var first = body[0];
var noStrict = !first || !t.isExpressionStatement(first) || !t.isLiteral(first.expression) || first.expression.value !== "use strict";
var noStrict = !first || !t.isExpressionStatement(first) || !t.isLiteral(first.expression) || first.expression.value !== "use strict";
if (noStrict) {
body.unshift(t.expressionStatement(t.literal("use strict")));
if (noStrict) {
body.unshift(t.expressionStatement(t.literal("use strict")));
}
}
};

View File

@@ -39,25 +39,23 @@ function traverse(parent, opts, scope) {
// replace node
var maybeReplace = function (result) {
if (result === false) return;
if (result == null) return;
if (result != null) {
updated = true;
var isArray = _.isArray(result);
var isArray = _.isArray(result);
// inherit comments from original node to the first replacement node
var inheritTo = result;
if (isArray) inheritTo = result[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// inherit comments from original node to the first replacement node
var inheritTo = result;
if (isArray) inheritTo = result[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// replace the node
node = obj[key] = result;
updated = true;
// replace the node
node = obj[key] = result;
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
};
@@ -70,7 +68,8 @@ function traverse(parent, opts, scope) {
},
remove: function () {
stopped = removed = true;
this.stop();
removed = true;
}
};
@@ -84,12 +83,12 @@ function traverse(parent, opts, scope) {
maybeReplace(result);
if (removed) {
delete obj[key];
obj[key] = null;
updated = true;
}
// stop iteration
if (stopped || result === false) return;
if (stopped) return;
}
// traverse node
@@ -106,7 +105,14 @@ function traverse(parent, opts, scope) {
handle(nodes, i);
}
if (updated) parent[key] = _.flatten(parent[key]);
if (updated) {
parent[key] = _.flatten(parent[key]);
if (key === "body") {
// we can safely compact this
parent[key] = _.compact(parent[key]);
}
}
} else {
handle(parent, key);
}
@@ -155,7 +161,7 @@ traverse.hasType = function (tree, type, blacklistTypes) {
enter: function (node) {
if (node.type === type) {
has = true;
return false;
this.stop();
}
}
});

View File

@@ -93,7 +93,7 @@ Scope.prototype.getInfo = function () {
// this block is a function so we'll stop since none of the variables
// declared within are accessible
if (t.isFunction(node)) return false;
if (t.isFunction(node)) return this.stop();
// function identifier doesn't belong to this scope
if (block.id && node === block.id) return;

View File

@@ -17,23 +17,23 @@
"ExportDeclaration": ["Statement", "Declaration"],
"ImportDeclaration": ["Statement", "Declaration"],
"ArrowFunctionExpression": ["Scope", "Function"],
"ArrowFunctionExpression": ["Scope", "Function", "Expression"],
"FunctionDeclaration": ["Statement", "Declaration", "Scope", "Function"],
"FunctionExpression": ["Scope", "Function"],
"FunctionExpression": ["Scope", "Function", "Expression"],
"BlockStatement": ["Statement", "Scope"],
"Program": ["Scope"],
"CatchClause": ["Scope"],
"LogicalExpression": ["Binary"],
"BinaryExpression": ["Binary"],
"LogicalExpression": ["Binary", "Expression"],
"BinaryExpression": ["Binary", "Expression"],
"UnaryExpression": ["UnaryLike"],
"UnaryExpression": ["UnaryLike", "Expression"],
"SpreadProperty": ["UnaryLike"],
"SpreadElement": ["UnaryLike"],
"ClassDeclaration": ["Statement", "Declaration", "Class"],
"ClassExpression": ["Class"],
"ClassExpression": ["Class", "Expression"],
"ForOfStatement": ["Statement", "For", "Scope", "Loop"],
"ForInStatement": ["Statement", "For", "Scope", "Loop"],
@@ -43,5 +43,27 @@
"ArrayPattern": ["Pattern"],
"Property": ["UserWhitespacable"],
"XJSElement": ["UserWhitespacable"]
"XJSElement": ["UserWhitespacable", "Expression"],
"ArrayExpression": ["Expression"],
"AssignmentExpression": ["Expression"],
"AwaitExpression": ["Expression"],
"BindFunctionExpression": ["Expression"],
"BindMemberExpression": ["Expression"],
"CallExpression": ["Expression"],
"ComprehensionExpression": ["Expression"],
"ConditionalExpression": ["Expression"],
"Identifier": ["Expression"],
"Literal": ["Expression"],
"MemberExpression": ["Expression"],
"NewExpression": ["Expression"],
"ObjectExpression": ["Expression"],
"SequenceExpression": ["Expression"],
"TaggedTemplateExpression": ["Expression"],
"ThisExpression": ["Expression"],
"UpdateExpression": ["Expression"],
"VirtualPropertyExpression": ["Expression"],
"XJSEmptyExpression": ["Expression"],
"XJSMemberExpression": ["Expression"],
"YieldExpression": ["Expression"]
}

View File

@@ -11,6 +11,8 @@
"FunctionExpression": ["id", "params", "body", "generator"],
"Identifier": ["name"],
"IfStatement": ["test", "consequent", "alternate"],
"ImportDeclaration": ["specifiers", "source"],
"ImportSpecifier": ["id", "name"],
"Literal": ["value"],
"LogicalExpression": ["operator", "left", "right"],
"MemberExpression": ["object", "property", "computed"],

View File

@@ -64,15 +64,32 @@ _.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
addAssert(type, is);
});
//
/*
* Shallowly checks to see if the passed `node` will evaluate to a
* falsy. This is if `node` is a `Literal` and `value` is falsy or
* `node` is an `Identifier` with a name of `undefiend`.
*
* @param {Object} node
* @returns {Boolean}
*/
t.isExpression = function (node) {
return !t.isStatement(node);
t.isFalsyExpression = function (node) {
if (t.isLiteral(node)) {
return !node.value;
} else if (t.isIdentifier(node)) {
return node.name === "undefined";
}
return false;
};
addAssert("Expression", t.isExpression);
//
/**
* Turn an array of statement `nodes` into a `SequenceExpression`.
*
* Variable declarations are turned into simple assignments and their
* declarations hoisted to the top of the current scope.
*
* Expression statements are just resolved to their standard expression.
*/
t.toSequenceExpression = function (nodes, scope) {
var exprs = [];
@@ -113,7 +130,41 @@ t.shallowEqual = function (actual, expected) {
return same;
};
//
/**
* Description
*
* @param {Object} member
* @param {Object} append
* @param {Boolean} [computed]
* @returns {Object} member
*/
t.appendToMemberExpression = function (member, append, computed) {
member.object = t.memberExpression(member.object, member.property, member.computed);
member.property = append;
member.computed = !!computed;
return member;
};
/**
* Description
*
* @param {Object} member
* @param {Object} append
* @returns {Object} member
*/
t.prependToMemberExpression = function (member, append) {
member.object = t.memberExpression(append, member.object);
return member;
};
/*
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isDynamic = function (node) {
if (t.isExpressionStatement(node)) {
@@ -127,7 +178,14 @@ t.isDynamic = function (node) {
}
};
// todo: https://github.com/eventualbuddha/ast-util/blob/9bf91c5ce8/lib/index.js#L454-L507
/**
* Description
*
* @param {Object} node
* @param {Object} parent
* @returns {Boolean}
*/
t.isReferenced = function (node, parent) {
// we're a property key and we aren't computed so we aren't referenced
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
@@ -149,11 +207,29 @@ t.isReferenced = function (node, parent) {
return false;
};
/**
* Description
*
* @param {String} name
* @returns {Boolean}
*/
t.isValidIdentifier = function (name) {
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
};
/*
* Description
*
* @param {String} name
* @returns {String}
*/
t.toIdentifier = function (name) {
if (t.isIdentifier(name)) return name.name;
// replace all non-valid identifiers with dashes
name = name.replace(/[^a-zA-Z0-9]/g, "-");
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
// remove all dashes and numbers from start of name
name = name.replace(/^[-0-9]+/, "");
@@ -163,18 +239,32 @@ t.toIdentifier = function (name) {
return c ? c.toUpperCase() : "";
});
// remove underscores from start of name
name = name.replace(/^\_/, "");
return name || '_';
};
t.isValidIdentifier = function (name) {
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isKeywordES6(name, true);
};
/**
* Description
*
* @param {Object} node
* @param {String} key
*/
t.ensureBlock = function (node, key) {
key = key || "body";
node[key] = t.toBlock(node[key], node);
};
/**
* Description
*
* @param {Object} node
* @param {Boolean} [ignore]
* @returns {Object|Boolean}
*/
t.toStatement = function (node, ignore) {
if (t.isStatement(node)) {
return node;
@@ -208,6 +298,14 @@ t.toStatement = function (node, ignore) {
return node;
};
/**
* Description
*
* @param {Object} node
* @param {Object} parent
* @returns {Object}
*/
t.toBlock = function (node, parent) {
if (t.isBlockStatement(node)) {
return node;
@@ -228,6 +326,67 @@ t.toBlock = function (node, parent) {
return t.blockStatement(node);
};
/*
* Description
*
* @param {Object} parent
* @param {File} file
* @param {Scope} scope
* @returns {Object}
*/
t.getUid = function (parent, file, scope) {
var node = parent;
if (t.isAssignmentExpression(parent)) {
node = parent.left;
} else if (t.isVariableDeclarator(parent)) {
node = parent.id;
}
var id = "ref";
if (t.isProperty(node)) {
node = node.key;
}
if (t.isIdentifier(node)) {
id = node.name;
} else if (t.isLiteral(node)) {
id = node.value;
} else if (t.isMemberExpression(node)) {
var parts = [];
var add = function (node) {
if (t.isMemberExpression(node)) {
add(node.object);
add(node.property);
} else if (t.isIdentifier(node)) {
parts.push(node.name);
} else if (t.isLiteral(node)) {
parts.push(node.value);
}
};
add(node);
id = parts.join("$");
}
id = id.replace(/^_/, "");
return file.generateUidIdentifier(id, scope);
};
/**
* Description
*
* @param {Object} node
* @param {Boolean} [map]
* @param {Array} [ignoreTypes]
* @returns {Array|Object}
*/
t.getIds = function (node, map, ignoreTypes) {
ignoreTypes = ignoreTypes || [];
@@ -278,27 +437,69 @@ t.getIds.arrays = {
ObjectPattern: ["properties"]
};
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isLet = function (node) {
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
};
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isVar = function (node) {
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
};
//
t.COMMENT_KEYS = ["leadingComments", "trailingComments"];
/**
* Description
*
* @param {Object} child
* @returns {Object} child
*/
t.removeComments = function (child) {
delete child.leadingComments;
delete child.trailingComments;
_.each(t.COMMENT_KEYS, function (key) {
delete child[key];
});
return child;
};
/**
* Description
*
* @param {Object} child
* @param {Object} parent
* @returns {Object} child
*/
t.inheritsComments = function (child, parent) {
_.each(["leadingComments", "trailingComments"], function (key) {
_.each(t.COMMENT_KEYS, function (key) {
child[key] = _.uniq(_.compact([].concat(child[key], parent[key])));
});
return child;
};
/**
* Description
*
* @param {Object} child
* @param {Object} parent
* @returns {Object} child
*/
t.inherits = function (child, parent) {
child.loc = parent.loc;
child.end = parent.end;
@@ -308,10 +509,24 @@ t.inherits = function (child, parent) {
return child;
};
/**
* Description
*
* @param {Object} specifier
* @returns {String}
*/
t.getSpecifierName = function (specifier) {
return specifier.name || specifier.id;
};
/**
* Description
*
* @param {Object} specifier
* @returns {Boolean}
*/
t.isSpecifierDefault = function (specifier) {
return t.isIdentifier(specifier.id) && specifier.id.name === "default";
};

View File

@@ -52,22 +52,6 @@ exports.arrayify = function (val) {
throw new TypeError("illegal type for arrayify");
};
exports.getUid = function (parent, file) {
var node;
if (t.isAssignmentExpression(parent)) {
node = parent.left;
} else if (t.isVariableDeclarator(parent)) {
node = parent.id;
}
var id = "ref";
if (t.isIdentifier(node)) id = node.name;
return file.generateUidIdentifier(id);
};
exports.isAbsolute = function (loc) {
if (!loc) return false;
if (loc[0] === "/") return true; // unix

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.2.0",
"version": "2.4.4",
"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-16",
"acorn-6to5": "0.11.1-3",
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",

View File

@@ -3,8 +3,9 @@ var test = {
* Before bracket init
*/
["a"]: "1",
[/*
* Inside bracket init
*/
"b"]: "2"
[( /*
* Inside bracket init
*/
"b"
)]: "2"
}, ok = 42;

View File

@@ -4,10 +4,11 @@ var test = {
*/
["a"]: "1",
[/*
* Inside bracket init
*/
"b"]: "2",
[( /*
* Inside bracket init
*/
"b"
)]: "2",
["c"
/*
@@ -17,9 +18,10 @@ var test = {
// Before bracket, line comment
["d"]: "4",
[
// Inside bracket, line comment
"e"]: "5",
[(
// Inside bracket, line comment
"e"
)]: "5",
["f"
// After bracket, line comment

View File

@@ -2,8 +2,6 @@ class Test {
}
class Derived extends Super {
}
class Derived2 extends Super() {
}
class StaticMethods {
static n1() {
}

View File

@@ -1,6 +1,5 @@
class Test {}
class Derived extends Super {}
class Derived2 extends Super() {}
class StaticMethods {
static n1() {}

View File

@@ -1,6 +1,5 @@
(class Test { });
(class Derived extends Super { });
(class Derived2 extends Super() { });
(class StaticMethods {
static n1() {
}
@@ -54,4 +53,3 @@
}
});
(class { });
(class extends Super() { });

View File

@@ -1,6 +1,5 @@
(class Test {});
(class Derived extends Super {});
(class Derived2 extends Super() {});
(class StaticMethods {
static n1() {}
@@ -38,4 +37,3 @@
*[gen1]() {}
});
(class {});
(class extends Super() {});

View File

@@ -1,21 +0,0 @@
System.register([], function (_export) {
_export("foo7", foo7);
function foo7() {}
return {
setters: [],
execute: function () {
"use strict";
var foo = _export("foo", 1);
var foo2 = _export("foo2", function () {});
var foo3 = _export("foo3", undefined);
var foo4 = _export("foo4", 2);
var foo5 = _export("foo5", undefined);
var foo6 = _export("foo6", 3);
var foo8 = function foo8() {};
_export("foo8", foo8);
}
};
});

View File

@@ -1,14 +0,0 @@
System.register([], function (_export) {
var _foo;
return {
setters: [function (m) {
_foo = m
}],
execute: function () {
"use strict";
var foo = _foo["default"];
var foo = _foo["default"];
}
};
});

View File

@@ -1,13 +0,0 @@
System.register(["foo"], function (_export) {
var _foo;
return {
setters: [function (m) {
_foo = m
}],
execute: function () {
"use strict";
var foo = _foo;
}
};
});

View File

@@ -1,14 +0,0 @@
System.register(["foo"], function (_export) {
var _foo;
return {
setters: [function (m) {
_foo = m
}],
execute: function () {
"use strict";
var foo = _foo["default"];
var xyz = _foo.baz;
}
};
});

View File

@@ -1,18 +0,0 @@
System.register(["foo"], function (_export) {
var _foo;
return {
setters: [function (m) {
_foo = m
}],
execute: function () {
"use strict";
var bar = _foo.bar;
var bar = _foo.bar;
var baz = _foo.baz;
var baz = _foo.bar;
var baz = _foo.bar;
var xyz = _foo.xyz;
}
};
});

View File

@@ -1,15 +0,0 @@
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
var _foo, _fooBar, _directoryFooBar;
return {
setters: [function (m) {
_foo = m
}, function (m) {
_fooBar = m
}, function (m) {
_directoryFooBar = m
}],
execute: function () {
"use strict";
}
};
});

View File

@@ -1,25 +0,0 @@
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
var _foo, _fooBar, _directoryFooBar;
return {
setters: [function (m) {
_foo = m
}, function (m) {
_fooBar = m
}, function (m) {
_directoryFooBar = m
}],
execute: function () {
"use strict";
var foo = _foo["default"];
var foo = _foo;
var bar = _foo.bar;
var bar = _foo.foo;
_export("test", test);
var test = _export("test", 5);
_export("default", test);
}
};
});

View File

@@ -1,17 +1,13 @@
"use strict";
var obj = (function (_obj) {
Object.defineProperties(_obj, {
foo: {
get: function () {
return 5 + 5;
},
set: function (value) {
this._foo = value;
},
enumerable: true
}
});
return _obj;
})({});
var obj = Object.defineProperties({}, {
foo: {
get: function () {
return 5 + 5;
},
set: function (value) {
this._foo = value;
},
enumerable: true
}
});

View File

@@ -1,14 +1,10 @@
"use strict";
var obj = (function (_obj) {
Object.defineProperties(_obj, {
foo: {
get: function () {
return 5 + 5;
},
enumerable: true
}
});
return _obj;
})({});
var obj = Object.defineProperties({}, {
foo: {
get: function () {
return 5 + 5;
},
enumerable: true
}
});

View File

@@ -1,14 +1,10 @@
"use strict";
var obj = (function (_obj) {
Object.defineProperties(_obj, {
foo: {
set: function (value) {
this._foo = value;
},
enumerable: true
}
});
return _obj;
})({});
var obj = Object.defineProperties({}, {
foo: {
set: function (value) {
this._foo = value;
},
enumerable: true
}
});

View File

@@ -13,29 +13,34 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = function Test() {
woops["super"].test();
Foo.call(this);
Foo.prototype.test.call(this);
foob(Foo);
var Test = (function () {
var _Foo = Foo;
var Test = function Test() {
woops["super"].test();
_Foo.call(this);
_Foo.prototype.test.call(this);
foob(_Foo);
Foo.call.apply(Foo, [this].concat(_slice.call(arguments)));
Foo.call.apply(Foo, [this, "test"].concat(_slice.call(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(_slice.call(arguments)));
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(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)));
};
_inherits(Test, Foo);
_inherits(Test, _Foo);
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.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)));
};
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;
})();

View File

@@ -12,9 +12,14 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = function Test() {
Foo.prototype.test;
Foo.prototype.test.whatever;
};
var Test = (function () {
var _Foo = Foo;
var Test = function Test() {
_Foo.prototype.test;
_Foo.prototype.test.whatever;
};
_inherits(Test, Foo);
_inherits(Test, _Foo);
return Test;
})();

View File

@@ -12,13 +12,18 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = function Test() {
Foo.prototype.test.whatever();
Foo.prototype.test.call(this);
};
var Test = (function () {
var _Foo = Foo;
var Test = function Test() {
_Foo.prototype.test.whatever();
_Foo.prototype.test.call(this);
};
_inherits(Test, Foo);
_inherits(Test, _Foo);
Test.test = function () {
return Foo.wow.call(this);
};
Test.test = function () {
return _Foo.wow.call(this);
};
return Test;
})();

View File

@@ -16,8 +16,13 @@ var Test = function Test() {
this.state = "test";
};
var Foo = function Foo() {
this.state = "test";
};
var Foo = (function () {
var _Bar = Bar;
var Foo = function Foo() {
this.state = "test";
};
_inherits(Foo, Bar);
_inherits(Foo, _Bar);
return Foo;
})();

View File

@@ -12,18 +12,28 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var BaseController = function BaseController() {
if (Chaplin.Controller) {
Chaplin.Controller.apply(this, arguments);
}
};
var BaseController = (function () {
var _Chaplin$Controller = Chaplin.Controller;
var BaseController = function BaseController() {
if (_Chaplin$Controller) {
_Chaplin$Controller.apply(this, arguments);
}
};
_inherits(BaseController, Chaplin.Controller);
_inherits(BaseController, _Chaplin$Controller);
var BaseController2 = function BaseController2() {
if (Chaplin.Controller.Another) {
Chaplin.Controller.Another.apply(this, arguments);
}
};
return BaseController;
})();
_inherits(BaseController2, Chaplin.Controller.Another);
var BaseController2 = (function () {
var _Chaplin$Controller$Another = Chaplin.Controller.Another;
var BaseController2 = function BaseController2() {
if (_Chaplin$Controller$Another) {
_Chaplin$Controller$Another.apply(this, arguments);
}
};
_inherits(BaseController2, _Chaplin$Controller$Another);
return BaseController2;
})();

View File

@@ -1,3 +0,0 @@
class Q extends function () {} {
}

View File

@@ -1,23 +0,0 @@
"use strict";
var _inherits = function (child, parent) {
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,
enumerable: false,
writable: true,
configurable: true
}
});
if (parent) child.__proto__ = parent;
};
var _QSuper = function () {};
var Q = function Q() {
if (_QSuper) {
_QSuper.apply(this, arguments);
}
};
_inherits(Q, _QSuper);

View File

@@ -12,10 +12,15 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = function Test() {
if (Foo) {
Foo.apply(this, arguments);
}
};
var Test = (function () {
var _Foo = Foo;
var Test = function Test() {
if (_Foo) {
_Foo.apply(this, arguments);
}
};
_inherits(Test, Foo);
_inherits(Test, _Foo);
return Test;
})();

View File

@@ -1,6 +1,12 @@
"use strict";
foo((function (_ref) {
_ref[bar] = "foobar";
return _ref;
})({}));
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
foo(_defineProperty({}, bar, "foobar"));

View File

@@ -1,6 +1,12 @@
"use strict";
foo = (function (_foo) {
_foo[bar] = "foobar";
return _foo;
})({});
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
foo = _defineProperty({}, bar, "foobar");

View File

@@ -0,0 +1,3 @@
var foo = {
[Symbol.iterator]: "foobar"
};

View File

@@ -0,0 +1,8 @@
"use strict";
var foo = (function () {
var _foo = {};
_foo[Symbol.iterator] = "foobar";
return _foo;
})();

View File

@@ -1,9 +1,14 @@
"use strict";
var obj = (function (_obj) {
_obj[foobar] = function () {
return "foobar";
};
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
return _obj;
})({});
var obj = _defineProperty({}, foobar, function () {
return "foobar";
});

View File

@@ -1,10 +1,24 @@
"use strict";
var obj = (function (_obj) {
_obj["x" + foo] = "heh";
_obj["y" + bar] = "noo";
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
var obj = (function () {
var _obj = {};
_defineProperty(_obj, "x" + foo, "heh");
_defineProperty(_obj, "y" + bar, "noo");
_defineProperty(_obj, "foo", "foo");
_defineProperty(_obj, "bar", "bar");
return _obj;
})({
foo: "foo",
bar: "bar"
});
})();

View File

@@ -1,7 +1,20 @@
"use strict";
var obj = (function (_obj) {
_obj["x" + foo] = "heh";
_obj["y" + bar] = "noo";
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
var obj = (function () {
var _obj = {};
_defineProperty(_obj, "x" + foo, "heh");
_defineProperty(_obj, "y" + bar, "noo");
return _obj;
})({});
})();

View File

@@ -1,6 +1,12 @@
"use strict";
var obj = (function (_obj) {
_obj["x" + foo] = "heh";
return _obj;
})({});
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
var obj = _defineProperty({}, "x" + foo, "heh");

View File

@@ -1,7 +1,12 @@
"use strict";
var _this = this;
var obj = (function (_obj) {
_obj["x" + _this.foo] = "heh";
return _obj;
})({});
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
var obj = _defineProperty({}, "x" + this.foo, "heh");

View File

@@ -1,6 +1,12 @@
"use strict";
var foo = (function (_foo) {
_foo[bar] = "foobar";
return _foo;
})({});
var _defineProperty = function (obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
};
var foo = _defineProperty({}, bar, "foobar");

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
@@ -23,13 +24,15 @@ var a = _ref2[0];
var b = _ref2[1];
var _ref3 = [3, 4];
var _ref4 = _slicedToArray(_ref3, 2);
var _ref3 = _slicedToArray(_ref3, 2);
var c = _ref4[0];
var d = _ref4[1];
var _ref5 = { e: 5, f: 6 };
var e = _ref5.e;
var f = _ref5.f;
var _ref6 = { a: 7, b: 8 };
var g = _ref6.a;
var h = _ref6.b;
var c = _ref3[0];
var d = _ref3[1];
var _ref4 = { e: 5, f: 6 };
var e = _ref4.e;
var f = _ref4.f;
var _ref5 = { a: 7, b: 8 };
var g = _ref5.a;
var h = _ref5.b;

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
@@ -20,10 +21,10 @@ var _ref = ["hello", [", ", "junk"], ["world"]];
var _ref2 = _slicedToArray(_ref, 4);
var a = _ref2[0];
var _ref3 = _slicedToArray(_ref2[1], 1);
var _ref2$1 = _slicedToArray(_ref2[1], 1);
var b = _ref3[0];
var _ref4 = _slicedToArray(_ref2[2], 1);
var b = _ref2$1[0];
var _ref2$2 = _slicedToArray(_ref2[2], 1);
var c = _ref4[0];
var c = _ref2$2[0];
var d = _ref2[3];

View File

@@ -1,11 +1,12 @@
"use strict";
var _temp, _ref;
var _temp, _temp2;
var _slicedToArray = function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
@@ -16,4 +17,4 @@ var _slicedToArray = function (arr, i) {
}
};
console.log((_temp = [123], _ref = _slicedToArray(_temp, 1), x = _ref[0], _temp));
console.log((_temp = [123], _temp2 = _slicedToArray(_temp, 1), x = _temp2[0], _temp));

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
@@ -20,10 +21,10 @@ var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
var _ref2 = _slicedToArray(_ref, 5);
var a = _ref2[1];
var _ref3 = _slicedToArray(_ref2[2], 1);
var _ref2$2 = _slicedToArray(_ref2[2], 1);
var b = _ref3[0];
var _ref4 = _slicedToArray(_ref2[3], 1);
var b = _ref2$2[0];
var _ref2$3 = _slicedToArray(_ref2[3], 1);
var c = _ref4[0];
var c = _ref2$3[0];
var d = _ref2[4];

View File

@@ -2,6 +2,7 @@
var _objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);

View File

@@ -5,6 +5,7 @@ var _slicedToArray = function (arr, i) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);

Some files were not shown because too many files have changed in this diff Show More