Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed41f1652e | ||
|
|
c522bdb4b9 | ||
|
|
005362a615 | ||
|
|
88e542634f | ||
|
|
c8304138eb | ||
|
|
35608d497e | ||
|
|
b5a78355c4 | ||
|
|
223e28ba8f | ||
|
|
e2f01d41a3 | ||
|
|
931a80f5b3 | ||
|
|
55123be7d7 | ||
|
|
324a0b408a | ||
|
|
8b2788e930 | ||
|
|
d945379b5b | ||
|
|
5a622ac9c7 | ||
|
|
0e9eac610b | ||
|
|
1de94a2705 | ||
|
|
71132c3538 | ||
|
|
d20ab0eb05 | ||
|
|
51f7e75d2e | ||
|
|
ab4b5ce994 | ||
|
|
f0d50ca9a2 | ||
|
|
5168355a64 | ||
|
|
2f209a9e4e | ||
|
|
20695eaba6 | ||
|
|
340a4dd1f2 | ||
|
|
ef1c7a5c69 | ||
|
|
5a01beaa1f | ||
|
|
5a5bf7b4ac | ||
|
|
88ee15bb4d | ||
|
|
3e51b65095 | ||
|
|
371df9ad09 | ||
|
|
d43d5ff409 | ||
|
|
c2c8e52430 | ||
|
|
57c0ebc5f4 | ||
|
|
339bf82481 | ||
|
|
d981c06444 | ||
|
|
8269e1488b | ||
|
|
ddda7a020f | ||
|
|
7e9340864a | ||
|
|
5ec19f23c3 | ||
|
|
ba48b66458 | ||
|
|
6e8c73f65f | ||
|
|
b34fcb0cd9 | ||
|
|
ff7129f1aa | ||
|
|
fbabd193a4 | ||
|
|
876d69798c | ||
|
|
1a963ddc06 | ||
|
|
beb5acea6b | ||
|
|
6a290f233e | ||
|
|
74563d88ed | ||
|
|
a18177026c | ||
|
|
a813341433 | ||
|
|
4968de9803 | ||
|
|
0de2d33e8d | ||
|
|
6f81ddd0d5 | ||
|
|
6b83055b12 | ||
|
|
080c23d5ed | ||
|
|
293bec58d7 | ||
|
|
93ceafc732 | ||
|
|
b2bac04b72 | ||
|
|
e549c37ca1 | ||
|
|
02512da38d | ||
|
|
abe9c4fd30 | ||
|
|
af21c52cc6 | ||
|
|
706626f79a | ||
|
|
b8dd421073 | ||
|
|
5453c466d6 | ||
|
|
0cfb2e76b8 | ||
|
|
ba67f57c1e | ||
|
|
f1a178f8f9 | ||
|
|
b1d1909c64 | ||
|
|
9529f93690 | ||
|
|
925b1f7600 | ||
|
|
40f8bc0a65 | ||
|
|
3a0dbabf5a | ||
|
|
383912c11b | ||
|
|
470c8fced0 | ||
|
|
e3dc2355e8 | ||
|
|
9733cb58c9 | ||
|
|
edd5a3878a | ||
|
|
78d2c4fa8d | ||
|
|
e268dc6138 | ||
|
|
5b6c0fcacd | ||
|
|
777f2be14e | ||
|
|
41d60a85e9 | ||
|
|
800c350db6 | ||
|
|
7b5b8ab6ed | ||
|
|
c7a02ca289 | ||
|
|
52e23473ed | ||
|
|
f4055612e5 | ||
|
|
46911bd28c |
62
CHANGELOG.md
62
CHANGELOG.md
@@ -2,6 +2,68 @@
|
||||
|
||||
Gaps between patch versions are faulty/broken releases.
|
||||
|
||||
## 2.4.9
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add optional `protoToAssign` transformer.
|
||||
* Fix missing properties from computed property keys.
|
||||
* Make ES7 comprehensions `let` variables.
|
||||
|
||||
## 2.4.8
|
||||
|
||||
* Make `require("6to5/register")` work with browserify - [#370](https://github.com/6to5/6to5/pull/370). Thanks [@hughsk](https://github.com/hughsk)!
|
||||
|
||||
## 2.4.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 2.4.6
|
||||
|
||||
* Move `coreAliasing` and `undefinedToVoid` transformers down to catch `moduleFormatter` transforms.
|
||||
|
||||
## 2.4.5
|
||||
|
||||
* Avoid printing comments if they've already been output.
|
||||
|
||||
## 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`.
|
||||
|
||||
13
CODE_OF_CONDUCT.md
Normal file
13
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
||||
|
||||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
||||
@@ -1,5 +1,7 @@
|
||||
# Contributing
|
||||
|
||||
Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
* **General**
|
||||
* No ES6 syntax features or methods, exclusively ES5.
|
||||
* Max of five arguments for functions
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014 Sebastian McKenzie
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie
|
||||
|
||||
MIT License
|
||||
|
||||
|
||||
@@ -11,10 +11,6 @@
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&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&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>
|
||||
|
||||
@@ -9,12 +9,15 @@ 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]` |
|
||||
| Modules | `Object.assign`* |
|
||||
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
|
||||
| Spread | `Array.isArray`, `Array.from` |
|
||||
| Spread | `Array.from` |
|
||||
|
||||
*Only required for exporting a non-function `default` with additional `export`s.
|
||||
|
||||
## ES5
|
||||
|
||||
@@ -26,13 +29,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 +59,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).
|
||||
|
||||
@@ -49,13 +49,12 @@ var seattlers = (function() {
|
||||
}());
|
||||
```
|
||||
|
||||
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.
|
||||
As you can tell, it's not very pretty. Instead of mapping directly to a
|
||||
runtime, like other transpilers, 6to5 maps directly to the equivalent ES5.
|
||||
|
||||
Sometimes there are little inline functions that 6to5 needs. These are
|
||||
placed at the top of your file much like coffee-script does. If these
|
||||
are bother you then you can use the [optional runtime](optional-runtime.md).
|
||||
bother you then you can use the [optional runtime](optional-runtime.md).
|
||||
We promise that these inline functions will never be significant and will
|
||||
always be used as little as possible.
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,16 @@ var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
this.dynamicImports = [];
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = [
|
||||
File.helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
"prototype-properties",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
@@ -26,7 +28,13 @@ File.declarations = [
|
||||
"sliced-to-array",
|
||||
"object-without-properties",
|
||||
"has-own",
|
||||
"slice"
|
||||
"slice",
|
||||
"define-property",
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
@@ -90,21 +98,30 @@ File.normaliseOptions = function (opts) {
|
||||
File.prototype.getTransformers = function () {
|
||||
var file = this;
|
||||
var transformers = [];
|
||||
var secondPassTransformers = [];
|
||||
|
||||
_.each(transform.transformers, function (transformer) {
|
||||
if (transformer.canRun(file)) {
|
||||
transformers.push(transformer);
|
||||
|
||||
if (transformer.secondPass) {
|
||||
secondPassTransformers.push(transformer);
|
||||
}
|
||||
|
||||
if (transformer.manipulateOptions) {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return transformers;
|
||||
return transformers.concat(secondPassTransformers);
|
||||
};
|
||||
|
||||
File.prototype.toArray = function (node, i) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
|
||||
return t.callExpression(t.memberExpression(this.addHelper("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
var declarationName = "to-array";
|
||||
var args = [node];
|
||||
@@ -112,7 +129,7 @@ File.prototype.toArray = function (node, i) {
|
||||
args.push(t.literal(i));
|
||||
declarationName = "sliced-to-array";
|
||||
}
|
||||
return t.callExpression(this.addDeclaration(declarationName), args);
|
||||
return t.callExpression(this.addHelper(declarationName), args);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,8 +160,15 @@ File.prototype.parseShebang = function (code) {
|
||||
return code;
|
||||
};
|
||||
|
||||
File.prototype.addDeclaration = function (name) {
|
||||
if (!_.contains(File.declarations, name)) {
|
||||
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.addHelper = function (name) {
|
||||
if (!_.contains(File.helpers, name)) {
|
||||
throw new ReferenceError("unknown declaration " + name);
|
||||
}
|
||||
|
||||
@@ -155,7 +179,7 @@ File.prototype.addDeclaration = function (name) {
|
||||
|
||||
var ref;
|
||||
var runtimeNamespace = this.opts.runtime;
|
||||
if (runtimeNamespace) {
|
||||
if (runtimeNamespace && !_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(t.identifier(runtimeNamespace), name);
|
||||
} else {
|
||||
|
||||
@@ -148,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);
|
||||
@@ -155,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");
|
||||
@@ -269,14 +274,21 @@ CodeGenerator.prototype._printComments = function (comments) {
|
||||
var self = this;
|
||||
|
||||
_.each(comments, function (comment) {
|
||||
var skip = false;
|
||||
|
||||
// find the original comment in the ast and set it as displayed
|
||||
_.each(self.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
|
||||
origComment._displayed = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (skip) return;
|
||||
|
||||
// whitespace before
|
||||
self.newline(self.whitespace.getNewlinesBefore(comment));
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 },
|
||||
|
||||
4
lib/6to5/register-browser.js
Normal file
4
lib/6to5/register-browser.js
Normal file
@@ -0,0 +1,4 @@
|
||||
// Required to safely use 6to5/register within a browserify codebase.
|
||||
module.exports = function () {};
|
||||
|
||||
require("./polyfill");
|
||||
@@ -18,7 +18,11 @@ module.exports = function (namespace) {
|
||||
)
|
||||
]));
|
||||
|
||||
_.each(File.declarations, function (name) {
|
||||
_.each(File.helpers, function (name) {
|
||||
if (_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
|
||||
@@ -51,7 +51,7 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
||||
this.stop();
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
@@ -79,7 +79,7 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
||||
this.stop();
|
||||
this.skip();
|
||||
return self.remapExportAssignment(node);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
|
||||
|
||||
DefaultFormatter.prototype._hoistExport = function (declar, assign, priority) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = priority || 1;
|
||||
assign._blockHoist = priority || 2;
|
||||
}
|
||||
|
||||
return assign;
|
||||
|
||||
@@ -85,7 +85,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]);
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
// import {foo} from "foo";
|
||||
ref = t.memberExpression(ref, specifier.id, false);
|
||||
|
||||
@@ -26,7 +26,7 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName,
|
||||
t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", {
|
||||
t.callExpression(this.file.addHelper("interop-require"), [util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
})])
|
||||
)
|
||||
@@ -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, 2));
|
||||
} 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) {
|
||||
|
||||
@@ -114,7 +114,7 @@ SystemFormatter.prototype.transform = function (ast) {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
@@ -159,7 +159,7 @@ SystemFormatter.prototype.transform = function (ast) {
|
||||
// hoist up function declarations for circular references
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.stop();
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
ARRAY.filter(function (KEY) {
|
||||
return FILTER;
|
||||
}).map(function (KEY) {
|
||||
return STATEMENT;
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
ARRAY.map(function (KEY) {
|
||||
return STATEMENT;
|
||||
});
|
||||
37
lib/6to5/transformation/templates/async-to-generator.js
Normal file
37
lib/6to5/transformation/templates/async-to-generator.js
Normal 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();
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = Object.assign(exports["default"], exports);
|
||||
8
lib/6to5/transformation/templates/defaults.js
Normal file
8
lib/6to5/transformation/templates/defaults.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function (obj, defaults) {
|
||||
for (var key in defaults) {
|
||||
if (obj[key] === undefined) {
|
||||
obj[key] = defaults[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
})
|
||||
8
lib/6to5/transformation/templates/define-property.js
Normal file
8
lib/6to5/transformation/templates/define-property.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
(function (KEY) {
|
||||
return KEY;
|
||||
})(OBJECT)
|
||||
@@ -1,4 +0,0 @@
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
@@ -1,6 +0,0 @@
|
||||
Object.defineProperty(this, KEY, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: VALUE
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
(function (FUNCTION_KEY) {
|
||||
var WRAPPER_KEY = function FUNCTION_ID() {
|
||||
return FUNCTION_KEY.apply(this, arguments);
|
||||
};
|
||||
|
||||
WRAPPER_KEY.toString = function () {
|
||||
return FUNCTION_KEY.toString();
|
||||
};
|
||||
|
||||
return WRAPPER_KEY;
|
||||
})(FUNCTION)
|
||||
@@ -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"),
|
||||
@@ -63,7 +66,7 @@ _.each({
|
||||
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||
spread: require("./transformers/es6-spread"),
|
||||
templateLiterals: require("./transformers/es6-template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
|
||||
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
|
||||
destructuring: require("./transformers/es6-destructuring"),
|
||||
defaultParameters: require("./transformers/es6-default-parameters"),
|
||||
forOf: require("./transformers/es6-for-of"),
|
||||
@@ -78,14 +81,17 @@ _.each({
|
||||
generators: require("./transformers/es6-generators"),
|
||||
restParameters: require("./transformers/es6-rest-parameters"),
|
||||
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
protoToAssign: require("./transformers/optional-proto-to-assign"),
|
||||
|
||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
// wrap up
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
_moduleFormatter: require("./transformers/_module-formatter"),
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
|
||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||
|
||||
// spec
|
||||
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
||||
|
||||
@@ -5,11 +5,13 @@ var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function Transformer(key, transformer, opts) {
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.transformer = Transformer.normalise(transformer);
|
||||
this.optional = !!transformer.optional;
|
||||
this.opts = opts || {};
|
||||
this.key = key;
|
||||
this.manipulateOptions = transformer.manipulateOptions;
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.secondPass = !!transformer.secondPass;
|
||||
this.transformer = Transformer.normalise(transformer);
|
||||
this.optional = !!transformer.optional;
|
||||
this.opts = opts || {};
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
Transformer.normalise = function (transformer) {
|
||||
@@ -40,16 +42,14 @@ Transformer.normalise = function (transformer) {
|
||||
|
||||
Transformer.prototype.astRun = function (file, key) {
|
||||
var transformer = this.transformer;
|
||||
var ast = file.ast;
|
||||
|
||||
if (transformer.ast && transformer.ast[key]) {
|
||||
transformer.ast[key](ast, file);
|
||||
transformer.ast[key](file.ast, file);
|
||||
}
|
||||
};
|
||||
|
||||
Transformer.prototype.transform = function (file) {
|
||||
var transformer = this.transformer;
|
||||
var ast = file.ast;
|
||||
|
||||
var build = function (exit) {
|
||||
return function (node, parent, scope) {
|
||||
@@ -66,7 +66,7 @@ Transformer.prototype.transform = function (file) {
|
||||
|
||||
this.astRun(file, "before");
|
||||
|
||||
traverse(ast, {
|
||||
traverse(file.ast, {
|
||||
enter: build(),
|
||||
exit: build(true)
|
||||
});
|
||||
|
||||
@@ -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 this.stop();
|
||||
return this.skip();
|
||||
} 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 this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node._ignoreAliasFunctions) return this.stop();
|
||||
if (node._ignoreAliasFunctions) return this.skip();
|
||||
|
||||
var getId;
|
||||
|
||||
@@ -49,7 +49,7 @@ var go = function (getBody, node, file, scope) {
|
||||
}
|
||||
});
|
||||
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
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 hasChange = false;
|
||||
for (var i in node.body) {
|
||||
var bodyNode = node.body[i];
|
||||
if (bodyNode && bodyNode._blockHoist) hasChange = true;
|
||||
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
|
||||
}
|
||||
if (!hasChange) return;
|
||||
|
||||
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
|
||||
return bodyNode._blockHoist || 0;
|
||||
var priority = bodyNode._blockHoist;
|
||||
if (priority == null) priority = 1;
|
||||
if (priority === true) priority = 2;
|
||||
return priority;
|
||||
});
|
||||
|
||||
node.body = _.flatten(_.values(nodePriorities).reverse());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
var kinds = {};
|
||||
@@ -22,4 +24,6 @@ exports.Program = function (node) {
|
||||
for (kind in kinds) {
|
||||
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
||||
}
|
||||
|
||||
node._declarations = null;
|
||||
};
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
var util = require("../../util");
|
||||
|
||||
exports.Property = function (node) {
|
||||
if (node.method) node.method = false;
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
var objId = util.getUid(parent, file);
|
||||
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.template("object-define-properties", {
|
||||
OBJECT: objId,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
})
|
||||
});
|
||||
};
|
||||
@@ -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,24 +85,18 @@ 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 = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(superRef, superName)
|
||||
]));
|
||||
superName = superRef;
|
||||
}
|
||||
|
||||
this.superName = superName;
|
||||
|
||||
//
|
||||
|
||||
if (superName) {
|
||||
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName])));
|
||||
this.superName = superName;
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
|
||||
}
|
||||
|
||||
this.buildBody();
|
||||
@@ -181,7 +175,7 @@ Class.prototype.buildBody = function () {
|
||||
if (instanceProps) args.push(instanceProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addDeclaration("prototype-properties"), args)
|
||||
t.callExpression(this.file.addHelper("prototype-properties"), args)
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,97 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
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 = scope.generateUidBasedOnNode(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(t.toComputedKey(prop, 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" })) {
|
||||
// { [Symbol.iterator]: "foo" }
|
||||
bodyNode = t.assignmentExpression(
|
||||
"=",
|
||||
t.memberExpression(objId, key, true),
|
||||
prop.value
|
||||
);
|
||||
} else {
|
||||
bodyNode = t.callExpression(file.addHelper("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(initProps);
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.returnStatement(objId));
|
||||
|
||||
return t.callExpression(container, []);
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
}
|
||||
keys = t.arrayExpression(keys);
|
||||
|
||||
var value = t.callExpression(opts.file.addDeclaration("object-without-properties"), [parentId, keys]);
|
||||
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
|
||||
nodes.push(buildVariableAssign(opts, prop.argument, value));
|
||||
} else {
|
||||
var pattern2 = prop.value;
|
||||
@@ -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 = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
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 = scope.generateUidBasedOnNode(parentId, file);
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(key, parentId)
|
||||
|
||||
@@ -280,7 +280,7 @@ LetScoping.prototype.checkLoop = function () {
|
||||
var replace;
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
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 this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -388,9 +388,9 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
}
|
||||
});
|
||||
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
} else if (t.isLoop(node)) {
|
||||
return this.stop();
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property = function (node, parent, file, scope) {
|
||||
if (!node.method) return;
|
||||
|
||||
node.method = false;
|
||||
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var selfReference = false;
|
||||
var outerDeclar = scope.get(id, true);
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node, parent, scope) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.get(id, true);
|
||||
if (localDeclar !== outerDeclar) return;
|
||||
|
||||
selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
}, scope);
|
||||
|
||||
if (selfReference) {
|
||||
node.value = util.template("property-method-assignment-wrapper", {
|
||||
FUNCTION: node.value,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: file.generateUidIdentifier(id, scope),
|
||||
WRAPPER_KEY: file.generateUidIdentifier(id + "Wrapper", scope)
|
||||
});
|
||||
} else {
|
||||
node.value.id = key;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
if (node.properties.length) {
|
||||
var objId = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
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)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -77,23 +77,14 @@ exports.CallExpression = function (node, parent, file, scope) {
|
||||
}
|
||||
|
||||
var callee = node.callee;
|
||||
var temp;
|
||||
|
||||
if (t.isMemberExpression(callee)) {
|
||||
contextLiteral = callee.object;
|
||||
|
||||
if (t.isDynamic(contextLiteral)) {
|
||||
temp = contextLiteral = scope.generateTemp(file);
|
||||
var temp = scope.generateTempBasedOnNode(callee.object, file);
|
||||
if (temp) {
|
||||
callee.object = t.assignmentExpression("=", temp, callee.object);
|
||||
contextLiteral = temp;
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
@@ -114,5 +105,5 @@ exports.NewExpression = function (node, parent, file) {
|
||||
args = first;
|
||||
}
|
||||
|
||||
return t.callExpression(file.addDeclaration("apply-constructor"), [node.callee, args]);
|
||||
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ exports.TaggedTemplateExpression = function (node, parent, file) {
|
||||
raw.push(t.literal(elem.value.raw));
|
||||
}
|
||||
|
||||
args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [
|
||||
args.push(t.callExpression(file.addHelper("tagged-template-literal"), [
|
||||
t.arrayExpression(strings),
|
||||
t.arrayExpression(raw)
|
||||
]));
|
||||
|
||||
@@ -30,10 +30,8 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
|
||||
// we need to return `node.right`
|
||||
if (!t.isExpressionStatement(parent)) {
|
||||
// `node.right` isn't a simple identifier so we need to reference it
|
||||
if (t.isDynamic(value)) {
|
||||
temp = value = scope.generateTemp(file);
|
||||
}
|
||||
temp = scope.generateTempBasedOnNode(node.right, file);
|
||||
if (temp) value = temp;
|
||||
}
|
||||
|
||||
if (node.operator !== "=") {
|
||||
@@ -80,11 +78,7 @@ exports.CallExpression = function (node, parent, file, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp;
|
||||
if (t.isDynamic(callee.object)) {
|
||||
// we need to save `callee.object` so we can call it again
|
||||
temp = scope.generateTemp(file);
|
||||
}
|
||||
var temp = scope.generateTempBasedOnNode(callee.object, file);
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
|
||||
@@ -1,43 +1,25 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
var single = function (node, file) {
|
||||
var block = node.blocks[0];
|
||||
|
||||
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 = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
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 () {
|
||||
@@ -67,18 +49,14 @@ exports._build = function (node, buildBody) {
|
||||
}
|
||||
|
||||
return t.forOfStatement(
|
||||
t.variableDeclaration("var", [t.variableDeclarator(self.left)]),
|
||||
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
|
||||
self.right,
|
||||
t.blockStatement([child])
|
||||
);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -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.addHelper("async-to-generator"));
|
||||
};
|
||||
@@ -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.skip();
|
||||
|
||||
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")));
|
||||
};
|
||||
@@ -4,14 +4,16 @@ 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");
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), file._coreId)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal("core-js/library"));
|
||||
ast.program.body.unshift(declar);
|
||||
file.addImport(file._coreId, "core-js/library");
|
||||
},
|
||||
|
||||
exit: function (ast, file) {
|
||||
@@ -26,11 +28,13 @@ exports.ast = {
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
var coreHasObject = obj.name !== "_" && _.has(core, obj.name);
|
||||
if (coreHasObject && _.has(core[obj.name], prop.name)) {
|
||||
this.stop();
|
||||
return t.memberExpression(file._coreId, node);
|
||||
if (!node.computed && coreHas(obj) && _.has(core[obj.name], prop.name)) {
|
||||
this.skip();
|
||||
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)
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var OBJECT_ASSIGN_MEMBER = t.memberExpression(t.identifier("Object"), t.identifier("assign"));
|
||||
|
||||
var isProtoKey = function (node) {
|
||||
return t.isLiteral(t.toComputedKey(node, node.key), { value: "__proto__" });
|
||||
};
|
||||
|
||||
var isProtoAssignmentExpression = function (node) {
|
||||
var left = node.left;
|
||||
return t.isMemberExpression(left) && t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" });
|
||||
};
|
||||
|
||||
var buildDefaultsCallExpression = function (expr, ref, file) {
|
||||
return t.expressionStatement(t.callExpression(file.addHelper("defaults"), [ref, expr.right]));
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
if (t.isExpressionStatement(parent)) return;
|
||||
if (!isProtoAssignmentExpression(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
var left = node.left.object;
|
||||
var temp = scope.generateTempBasedOnNode(node.left.object, file);
|
||||
|
||||
nodes.push(t.expressionStatement(t.assignmentExpression("=", temp, left)));
|
||||
nodes.push(buildDefaultsCallExpression(node, temp, file));
|
||||
if (temp) nodes.push(temp);
|
||||
|
||||
return t.toSequenceExpression(nodes);
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, file) {
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr, { operator: "=" })) return;
|
||||
|
||||
if (isProtoAssignmentExpression(expr)) {
|
||||
return buildDefaultsCallExpression(expr, expr.left.object, file);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
var proto;
|
||||
|
||||
for (var i in node.properties) {
|
||||
var prop = node.properties[i];
|
||||
|
||||
if (isProtoKey(prop)) {
|
||||
proto = prop.value;
|
||||
_.pull(node.properties, prop);
|
||||
}
|
||||
}
|
||||
|
||||
if (proto) {
|
||||
var args = [t.objectExpression([]), proto];
|
||||
if (node.properties.length) args.push(node);
|
||||
return t.callExpression(OBJECT_ASSIGN_MEMBER, args);
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -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 = scope.generateUidBasedOnNode(prop, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
@@ -19,22 +19,18 @@ var getPropRef = function (nodes, prop, file, scope) {
|
||||
};
|
||||
|
||||
var getObjRef = function (nodes, obj, file, scope) {
|
||||
if (t.isDynamic(obj)) {
|
||||
var temp = file.generateUidIdentifier("obj", scope);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, obj)
|
||||
]));
|
||||
return temp;
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
var temp = scope.generateUidBasedOnNode(obj, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, obj)
|
||||
]));
|
||||
return temp;
|
||||
};
|
||||
|
||||
var buildHasOwn = function (obj, prop, file) {
|
||||
return t.unaryExpression(
|
||||
"!",
|
||||
t.callExpression(
|
||||
t.memberExpression(file.addDeclaration("has-own"), t.identifier("call")),
|
||||
t.memberExpression(file.addHelper("has-own"), t.identifier("call")),
|
||||
[obj, prop]
|
||||
),
|
||||
true
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.BindMemberExpression = function (node, parent, file, scope) {
|
||||
var object = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
var temp;
|
||||
if (t.isDynamic(object)) {
|
||||
temp = object = scope.generateTemp(file);
|
||||
}
|
||||
var temp = scope.generateTempBasedOnNode(node.object, file);
|
||||
if (temp) object = temp;
|
||||
|
||||
var call = t.callExpression(
|
||||
t.memberExpression(t.memberExpression(object, prop), t.identifier("bind")),
|
||||
@@ -33,16 +30,12 @@ exports.BindFunctionExpression = function (node, parent, file, scope) {
|
||||
]));
|
||||
};
|
||||
|
||||
if (_.find(node.arguments, t.isDynamic)) {
|
||||
var temp = scope.generateTemp(file, "args");
|
||||
var temp = scope.generateTemp(file, "args");
|
||||
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
buildCall(node.arguments.map(function (node, i) {
|
||||
return t.memberExpression(temp, t.literal(i), true);
|
||||
}))
|
||||
]);
|
||||
} else {
|
||||
return buildCall(node.arguments);
|
||||
}
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
buildCall(node.arguments.map(function (node, i) {
|
||||
return t.memberExpression(temp, t.literal(i), true);
|
||||
}))
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property =
|
||||
exports.MethodDefinition = function (node) {
|
||||
exports.MethodDefinition = function (node, parent, file) {
|
||||
if (node.kind !== "memo") return;
|
||||
node.kind = "get";
|
||||
|
||||
@@ -21,10 +20,11 @@ exports.MethodDefinition = function (node) {
|
||||
if (t.isFunction(node)) return;
|
||||
|
||||
if (t.isReturnStatement(node) && node.argument) {
|
||||
node.argument = t.memberExpression(util.template("object-getter-memoization", {
|
||||
KEY: key,
|
||||
VALUE: node.argument
|
||||
}), key, true);
|
||||
node.argument = t.memberExpression(t.callExpression(file.addHelper("define-property"), [
|
||||
t.thisExpression(),
|
||||
key,
|
||||
node.argument
|
||||
]), key, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,12 +22,14 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var stopped = false;
|
||||
|
||||
for (var i in keys) {
|
||||
var key = keys[i];
|
||||
var nodes = parent[key];
|
||||
if (!nodes) continue;
|
||||
|
||||
var updated = false;
|
||||
var flatten = false;
|
||||
|
||||
var handle = function (obj, key) {
|
||||
var node = obj[key];
|
||||
@@ -50,7 +52,8 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
// replace the node
|
||||
node = obj[key] = result;
|
||||
updated = true;
|
||||
|
||||
if (isArray) flatten = true;
|
||||
|
||||
// we're replacing a statement or block node with an array of statements so we better
|
||||
// ensure that it's a block
|
||||
@@ -59,16 +62,20 @@ function traverse(parent, opts, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
var stopped = false;
|
||||
var skipped = false;
|
||||
var removed = false;
|
||||
|
||||
var context = {
|
||||
stop: function () {
|
||||
stopped = true;
|
||||
skipped = stopped = true;
|
||||
},
|
||||
|
||||
skip: function () {
|
||||
skipped = true;
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this.stop();
|
||||
this.skip();
|
||||
removed = true;
|
||||
}
|
||||
};
|
||||
@@ -84,11 +91,11 @@ function traverse(parent, opts, scope) {
|
||||
|
||||
if (removed) {
|
||||
obj[key] = null;
|
||||
updated = true;
|
||||
flatten = true;
|
||||
}
|
||||
|
||||
// stop iteration
|
||||
if (stopped) return;
|
||||
if (skipped) return;
|
||||
}
|
||||
|
||||
// traverse node
|
||||
@@ -103,13 +110,20 @@ function traverse(parent, opts, scope) {
|
||||
if (_.isArray(nodes)) {
|
||||
for (i in nodes) {
|
||||
handle(nodes, i);
|
||||
if (stopped) return;
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
if (flatten) {
|
||||
parent[key] = _.flatten(parent[key]);
|
||||
|
||||
if (key === "body") {
|
||||
// we can safely compact this
|
||||
parent[key] = _.compact(parent[key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handle(parent, key);
|
||||
if (stopped) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +170,7 @@ traverse.hasType = function (tree, type, blacklistTypes) {
|
||||
enter: function (node) {
|
||||
if (node.type === type) {
|
||||
has = true;
|
||||
this.stop();
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -31,6 +31,13 @@ Scope.add = function (node, references) {
|
||||
_.defaults(references, t.getIds(node, true));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {File} file
|
||||
* @param {String} [name="temp"]
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTemp = function (file, name) {
|
||||
var id = file.generateUidIdentifier(name || "temp", this);
|
||||
this.push({
|
||||
@@ -40,6 +47,83 @@ Scope.prototype.generateTemp = function (file, name) {
|
||||
return id;
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} parent
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidBasedOnNode = function (parent, file) {
|
||||
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, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {File} file
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTempBasedOnNode = function (node, file) {
|
||||
if (!t.isIdentifier(node) && !t.isMemberExpression(node)) {
|
||||
throw new TypeError("Invalid node type " + JSON.stringify(node.type) + " passed to Scope.prototype.generateTempBasedOnNode");
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node) && this.has(node.name, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var id = this.generateUidBasedOnNode(node, file);
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
Scope.prototype.getInfo = function () {
|
||||
var block = this.block;
|
||||
if (block._scopeInfo) return block._scopeInfo;
|
||||
@@ -93,7 +177,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 this.stop();
|
||||
if (t.isFunction(node)) return this.skip();
|
||||
|
||||
// function identifier doesn't belong to this scope
|
||||
if (block.id && node === block.id) return;
|
||||
@@ -123,6 +207,12 @@ Scope.prototype.getInfo = function () {
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} opts
|
||||
*/
|
||||
|
||||
Scope.prototype.push = function (opts) {
|
||||
var block = this.block;
|
||||
|
||||
@@ -143,33 +233,84 @@ Scope.prototype.push = function (opts) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
*/
|
||||
|
||||
Scope.prototype.add = function (node) {
|
||||
Scope.add(node, this.references);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.get = function (id, decl) {
|
||||
return id && (this.getOwn(id, decl) || this.parentGet(id, decl));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.getOwn = function (id, decl) {
|
||||
var refs = this.references;
|
||||
if (decl) refs = this.declarations;
|
||||
return _.has(refs, id) && refs[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.parentGet = function (id, decl) {
|
||||
return this.parent && this.parent.get(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.has = function (id, decl) {
|
||||
return (id && (this.hasOwn(id, decl) || this.parentHas(id, decl))) ||
|
||||
_.contains(Scope.defaultDeclarations, id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.hasOwn = function (id, decl) {
|
||||
return !!this.getOwn(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.parentHas = function (id, decl) {
|
||||
return this.parent && this.parent.has(id, decl);
|
||||
};
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
|
||||
@@ -64,15 +64,28 @@ _.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
|
||||
addAssert(type, is);
|
||||
});
|
||||
|
||||
//
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.isExpression = function (node) {
|
||||
return !t.isStatement(node);
|
||||
t.toComputedKey = function (node, key) {
|
||||
if (!node.computed) {
|
||||
if (t.isIdentifier(key)) key = t.literal(key.name);
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
addAssert("Expression", t.isExpression);
|
||||
|
||||
//
|
||||
/*
|
||||
* 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.isFalsyExpression = function (node) {
|
||||
if (t.isLiteral(node)) {
|
||||
@@ -83,7 +96,14 @@ t.isFalsyExpression = function (node) {
|
||||
return false;
|
||||
};
|
||||
|
||||
//
|
||||
/**
|
||||
* 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 = [];
|
||||
@@ -105,7 +125,11 @@ t.toSequenceExpression = function (nodes, scope) {
|
||||
}
|
||||
});
|
||||
|
||||
return t.sequenceExpression(exprs);
|
||||
if (exprs.length === 1) {
|
||||
return exprs[0];
|
||||
} else {
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -124,21 +148,43 @@ t.shallowEqual = function (actual, expected) {
|
||||
return same;
|
||||
};
|
||||
|
||||
//
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} member
|
||||
* @param {Object} append
|
||||
* @param {Boolean} [computed]
|
||||
* @returns {Object} member
|
||||
*/
|
||||
|
||||
t.isDynamic = function (node) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
return t.isDynamic(node.expression);
|
||||
} else if (t.isIdentifier(node) || t.isLiteral(node) || t.isThisExpression(node)) {
|
||||
return false;
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
return t.isDynamic(node.object) || t.isDynamic(node.property);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
t.appendToMemberExpression = function (member, append, computed) {
|
||||
member.object = t.memberExpression(member.object, member.property, member.computed);
|
||||
member.property = append;
|
||||
member.computed = !!computed;
|
||||
return member;
|
||||
};
|
||||
|
||||
// todo: https://github.com/eventualbuddha/ast-util/blob/9bf91c5ce8/lib/index.js#L454-L507
|
||||
/**
|
||||
* 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
|
||||
* @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;
|
||||
@@ -160,11 +206,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]+/, "");
|
||||
@@ -174,18 +238,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;
|
||||
@@ -219,6 +297,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;
|
||||
@@ -239,6 +325,15 @@ t.toBlock = function (node, parent) {
|
||||
return t.blockStatement(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} [map]
|
||||
* @param {Array} [ignoreTypes]
|
||||
* @returns {Array|Object}
|
||||
*/
|
||||
|
||||
t.getIds = function (node, map, ignoreTypes) {
|
||||
ignoreTypes = ignoreTypes || [];
|
||||
|
||||
@@ -289,27 +384,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;
|
||||
@@ -319,10 +456,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";
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.9",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -18,6 +18,10 @@
|
||||
"6to5-node": "./bin/6to5-node",
|
||||
"6to5-runtime": "./bin/6to5-runtime"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/6to5/index.js": "./lib/6to5/browser.js",
|
||||
"./lib/6to5/register.js": "./lib/6to5/register-browser.js"
|
||||
},
|
||||
"keywords": [
|
||||
"harmony",
|
||||
"classes",
|
||||
@@ -35,7 +39,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-1",
|
||||
"acorn-6to5": "0.11.1-7",
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
|
||||
@@ -13,10 +13,10 @@ suite("api", function () {
|
||||
assert.ok(!result.ast);
|
||||
});
|
||||
|
||||
test("addDeclaration unknown", function () {
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File;
|
||||
assert.throws(function () {
|
||||
file.addDeclaration("foob");
|
||||
file.addHelper("foob");
|
||||
}, /unknown declaration foob/);
|
||||
});
|
||||
});
|
||||
|
||||
19
test/browserify.js
Normal file
19
test/browserify.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var browserify = require("browserify");
|
||||
var assert = require("assert");
|
||||
var path = require("path");
|
||||
var vm = require("vm");
|
||||
|
||||
suite("browserify", function() {
|
||||
test("6to5/register may be used without breaking browserify", function(done) {
|
||||
var bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
|
||||
bundler.bundle(function(err, bundle) {
|
||||
if (err) return done(err);
|
||||
assert.ok(bundle.length, "bundle output code");
|
||||
|
||||
// ensure that the code runs without throwing an exception
|
||||
vm.runInNewContext(bundle, {});
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
3
test/fixtures/browserify/register.js
vendored
Normal file
3
test/fixtures/browserify/register.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
require("../../../register")({
|
||||
ignore: false
|
||||
});
|
||||
@@ -3,8 +3,9 @@ var test = {
|
||||
* Before bracket init
|
||||
*/
|
||||
["a"]: "1",
|
||||
[/*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"]: "2"
|
||||
[( /*
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"
|
||||
)]: "2"
|
||||
}, ok = 42;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
"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;
|
||||
})({});
|
||||
@@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function (_obj) {
|
||||
Object.defineProperties(_obj, {
|
||||
foo: {
|
||||
get: function () {
|
||||
return 5 + 5;
|
||||
},
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
|
||||
return _obj;
|
||||
})({});
|
||||
@@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var obj = (function (_obj) {
|
||||
Object.defineProperties(_obj, {
|
||||
foo: {
|
||||
set: function (value) {
|
||||
this._foo = value;
|
||||
},
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
|
||||
return _obj;
|
||||
})({});
|
||||
@@ -1,13 +1,13 @@
|
||||
module.exports = {
|
||||
init() {
|
||||
return new Promise((resolve, reject) => {
|
||||
MongoClient.connect(config.mongodb, (err, db) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.db = db;
|
||||
resolve(this);
|
||||
init: function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
MongoClient.connect(config.mongodb, (err, db) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.db = db;
|
||||
resolve(this);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,29 +13,37 @@ 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() {
|
||||
var _Foo$prototype$test, _Foo$prototype$test2;
|
||||
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(null, [this].concat(_slice.call(arguments)));
|
||||
_Foo.call.apply(null, [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 = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [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 () {
|
||||
var _Foo$prototype$test3, _Foo$prototype$test4;
|
||||
_Foo.prototype.test.call(this);
|
||||
(_Foo$prototype$test3 = _Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test4 = _Foo.prototype.test).call.apply(_Foo$prototype$test4, [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 () {
|
||||
var _Foo$foo, _Foo$foo2;
|
||||
_Foo.foo.call(this);
|
||||
(_Foo$foo = _Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$foo2 = _Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
|
||||
return Test;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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");
|
||||
|
||||
3
test/fixtures/transformation/es6-computed-property-names/ignore-symbol/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-computed-property-names/ignore-symbol/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var foo = {
|
||||
[Symbol.iterator]: "foobar"
|
||||
};
|
||||
8
test/fixtures/transformation/es6-computed-property-names/ignore-symbol/expected.js
vendored
Normal file
8
test/fixtures/transformation/es6-computed-property-names/ignore-symbol/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var foo = (function () {
|
||||
var _foo = {};
|
||||
|
||||
_foo[Symbol.iterator] = "foobar";
|
||||
return _foo;
|
||||
})();
|
||||
@@ -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";
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})({});
|
||||
})();
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
4
test/fixtures/transformation/es6-computed-property-names/two/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-computed-property-names/two/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var obj = {
|
||||
first: "first",
|
||||
["second"]: "second",
|
||||
};
|
||||
13
test/fixtures/transformation/es6-computed-property-names/two/expected.js
vendored
Normal file
13
test/fixtures/transformation/es6-computed-property-names/two/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var _defineProperty = function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
};
|
||||
|
||||
var obj = _defineProperty({
|
||||
first: "first" }, "second", "second");
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -15,11 +16,11 @@ var _slicedToArray = function (arr, i) {
|
||||
}
|
||||
};
|
||||
|
||||
var _ref = _slicedToArray(rect.topLeft, 2);
|
||||
var _rect$topLeft = _slicedToArray(rect.topLeft, 2);
|
||||
|
||||
var x1 = _ref[0];
|
||||
var y1 = _ref[1];
|
||||
var _ref2 = _slicedToArray(rect.bottomRight, 2);
|
||||
var x1 = _rect$topLeft[0];
|
||||
var y1 = _rect$topLeft[1];
|
||||
var _rect$bottomRight = _slicedToArray(rect.bottomRight, 2);
|
||||
|
||||
var x2 = _ref2[0];
|
||||
var y2 = _ref2[1];
|
||||
var x2 = _rect$bottomRight[0];
|
||||
var y2 = _rect$bottomRight[1];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -30,17 +31,17 @@ function unpackObject(_ref2) {
|
||||
|
||||
console.log(unpackObject({ title: "title", author: "author" }));
|
||||
|
||||
var unpackArray = function (_ref3, _ref5) {
|
||||
var _ref4 = _slicedToArray(_ref3, 3);
|
||||
var unpackArray = function (_ref3, _ref4) {
|
||||
var _ref3 = _slicedToArray(_ref3, 3);
|
||||
|
||||
var a = _ref4[0];
|
||||
var b = _ref4[1];
|
||||
var c = _ref4[2];
|
||||
var _ref6 = _slicedToArray(_ref5, 3);
|
||||
var a = _ref3[0];
|
||||
var b = _ref3[1];
|
||||
var c = _ref3[2];
|
||||
var _ref4 = _slicedToArray(_ref4, 3);
|
||||
|
||||
var x = _ref6[0];
|
||||
var y = _ref6[1];
|
||||
var z = _ref6[2];
|
||||
var x = _ref4[0];
|
||||
var y = _ref4[1];
|
||||
var z = _ref4[2];
|
||||
return a + b + c;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(["exports"], function (exports) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
define(["exports"], function (exports) {
|
||||
exports["default"] = foo;
|
||||
exports["default"] = 42;
|
||||
exports["default"] = {};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
(function (obj) {
|
||||
for (var i in obj) {
|
||||
exports[i] = obj[i];
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user