Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1bdd804e2 | ||
|
|
10c051890b | ||
|
|
ac49d0a335 | ||
|
|
b56f1800e5 | ||
|
|
49ef92c586 | ||
|
|
542fe89123 | ||
|
|
5b118c0c3f | ||
|
|
8503916799 | ||
|
|
206c828a56 | ||
|
|
7a261a1db1 | ||
|
|
c9d9a085f1 | ||
|
|
6d1953d9c3 | ||
|
|
92621d71c7 | ||
|
|
dc01731c25 | ||
|
|
9fb8a80f60 | ||
|
|
85c2de57e4 | ||
|
|
58fac2e2be | ||
|
|
682806f1ca | ||
|
|
47c6f74251 | ||
|
|
37f360c72d | ||
|
|
e5a8c95b62 | ||
|
|
921d459f13 | ||
|
|
58898932e6 | ||
|
|
c7b45116c4 | ||
|
|
32ddd638ba | ||
|
|
0eb3cda2d4 | ||
|
|
2acb24d43d | ||
|
|
fdd1451d53 | ||
|
|
43e2f121a6 | ||
|
|
297e55ba63 | ||
|
|
38396dadd5 | ||
|
|
f75f045026 | ||
|
|
740193b1e2 | ||
|
|
b9fe1475c2 | ||
|
|
6065220f9b | ||
|
|
715884662e | ||
|
|
11780c28ff | ||
|
|
215c2da7cb | ||
|
|
c7c41d6548 | ||
|
|
695571b435 | ||
|
|
f845633cc1 | ||
|
|
72c9b1d6c9 | ||
|
|
edd3363e48 | ||
|
|
114b5ef9ec | ||
|
|
2f4e0c3361 | ||
|
|
3ee51dae1a | ||
|
|
20263c1151 | ||
|
|
eaac564f11 | ||
|
|
63a47ef7bb | ||
|
|
6963cc1e40 | ||
|
|
5eb2462e29 | ||
|
|
9e285cdc20 | ||
|
|
01ade47af9 | ||
|
|
b1fe449b0d | ||
|
|
2b458ec2d4 | ||
|
|
d5f47f4f4d | ||
|
|
d4deb18975 | ||
|
|
5a794db73b | ||
|
|
dc131f05a8 | ||
|
|
1d4f79790a | ||
|
|
6bcbaf6df1 | ||
|
|
bc199ef0c9 | ||
|
|
f5fed99c81 | ||
|
|
66a6d3cffe | ||
|
|
39227486a6 | ||
|
|
caafa31df1 | ||
|
|
4c41c904f5 | ||
|
|
0917a6a5b1 | ||
|
|
349eba33ce | ||
|
|
8ff21b407d | ||
|
|
751ea7a12c | ||
|
|
b30cd227cc | ||
|
|
18dc7b8143 | ||
|
|
1c628bbec1 | ||
|
|
d4c3dde02a |
44
CHANGELOG.md
44
CHANGELOG.md
@@ -1,3 +1,47 @@
|
||||
# 1.12.14
|
||||
|
||||
* Fix duplicate let scoping in functions.
|
||||
* Make JSX whitespace more React-compliant.
|
||||
* Add `_memberExpressionKeywords` transformer that turns keyword identifiers to computed literals.
|
||||
* Upgrade `regenerator-6to5`.
|
||||
|
||||
# 1.12.13
|
||||
|
||||
* Support duplicate constants within different block scopes.
|
||||
* Fix for-head duplication testing and replacement.
|
||||
* Support `raw` property on tagged template literals.
|
||||
|
||||
# 1.12.12
|
||||
|
||||
* Make scope tracker more reliable to handle all edgecases.
|
||||
|
||||
# 1.12.11
|
||||
|
||||
* Block scope classes.
|
||||
* Fix generation of integer `Literal`s in `MemberExpression`.
|
||||
|
||||
# 1.12.10
|
||||
|
||||
* Fix let scoping var hoisting.
|
||||
|
||||
# 1.12.9
|
||||
|
||||
* Escape unicode characters when generating string `Literal`s.
|
||||
* Fix semicolons being output for statements in `ExportDeclaration`.
|
||||
* Fix `WithStatement` missing parenthesis.
|
||||
|
||||
# 1.12.8
|
||||
|
||||
* Temporarily forbid `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
# 1.12.7
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
# 1.12.6
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
# 1.12.5
|
||||
|
||||
* Fix excessive whitespace trimming resulting in innaccurate sourcemap line.
|
||||
|
||||
31
CONTRIBUTING.md
Normal file
31
CONTRIBUTING.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Contributing
|
||||
|
||||
* **General**
|
||||
* No ES6 syntax features or methods, exclusively ES5.
|
||||
* Max of five arguments for functions
|
||||
* Max depth of four nested blocks
|
||||
* 2-spaced soft tabs
|
||||
* **Naming**
|
||||
* CamelCase all class names
|
||||
* camelBack all variable names
|
||||
* **Spacing**
|
||||
* 80 character line max
|
||||
* Spaces after all keywords
|
||||
* Spaces before all left curly braces
|
||||
* **Comments**
|
||||
* Use JSDoc-style comments for methods
|
||||
* Single-line comments for ambiguous code
|
||||
* **Quotes**
|
||||
* Always use double quotes
|
||||
* Only use single quotes when the string contains a double quote
|
||||
* **Declaration**
|
||||
* No unused variables
|
||||
* No pollution of global variables and prototypes
|
||||
|
||||
## Testing
|
||||
|
||||
$ make test
|
||||
|
||||
## Linting
|
||||
|
||||
$ make lint
|
||||
@@ -24,6 +24,6 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
**6to5** turns ES6 code into vanilla ES5, so you can use ES6 features **today.**
|
||||
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
|
||||
|
||||
For more information view the [documentation](https://6to5.github.io).
|
||||
|
||||
@@ -3,12 +3,6 @@
|
||||
A browser version of 6to5 is available from `browser.js` inside the 6to5
|
||||
directory in an npm release.
|
||||
|
||||
## API
|
||||
|
||||
```javascript
|
||||
to5.transform("class Test {}").code;
|
||||
```
|
||||
|
||||
## Scripts
|
||||
|
||||
While it's not recommended for serious use, when the browser version is included
|
||||
@@ -47,3 +41,21 @@ To test 6to5 in your browser run:
|
||||
$ make test-browser
|
||||
|
||||
And open `test/browser.html` in your browser if it doesn't open automatically.
|
||||
|
||||
## API
|
||||
|
||||
### to5.transform(code, [opts])
|
||||
|
||||
See [options](usage.md#options) for additional documentation.
|
||||
|
||||
```javascript
|
||||
to5.transform("class Test {}").code;
|
||||
```
|
||||
|
||||
### to5.run(code, [opts])
|
||||
|
||||
See [options](usage.md#options) for additional documentation.
|
||||
|
||||
```javascript
|
||||
to5.run("class Test {}");
|
||||
```
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# Caveats
|
||||
|
||||
## Async/Generators
|
||||
|
||||
The [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js)
|
||||
and an [ES6 polyfill](polyfill.md) are required in order for generators to work.
|
||||
|
||||
## Classes
|
||||
|
||||
Built-in classes such as `Date`, `Array` and `DOM` cannot be subclassed due to
|
||||
@@ -32,11 +37,6 @@ A polyfill is required for for-of functionality that implements `Symbol` and
|
||||
adds `prototype[Symbol.iterator]` behaviour to built-ins. Using the polyfills
|
||||
specified in [polyfill](polyfill.md) suffices.
|
||||
|
||||
## Generators
|
||||
|
||||
The [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js)
|
||||
and an [ES6 polyfill](polyfill.md) are required in order for generators to work.
|
||||
|
||||
## Spread
|
||||
|
||||
An [ES6 polyfill](polyfill.md) is required in order for spread to work. More
|
||||
|
||||
@@ -64,7 +64,7 @@ better suited if you'd like a full ES6 environment with polyfills and all.
|
||||
| Browser support | ✓ | ✓ | ✓ | | | |
|
||||
| Array comprehension | ✓ | ✓ | | | ✓ | |
|
||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Async functions | ✓ | | ✓ | | | |
|
||||
| Async functions | ✓ | ✓ | ✓ | | | |
|
||||
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Constants | ✓ | ✓ | | | ✓ | |
|
||||
|
||||
114
doc/features.md
114
doc/features.md
@@ -3,7 +3,32 @@
|
||||
## Array comprehension
|
||||
|
||||
```javascript
|
||||
[for (i of [1, 2, 3]) i * i]; // [1, 4, 9]
|
||||
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
|
||||
```
|
||||
|
||||
## Arrow functions
|
||||
|
||||
```javascript
|
||||
// Expression bodies
|
||||
var odds = evens.map(v => v + 1);
|
||||
var nums = evens.map((v, i) => v + i);
|
||||
|
||||
// Statement bodies
|
||||
nums.forEach(v => {
|
||||
if (v % 5 === 0)
|
||||
fives.push(v);
|
||||
});
|
||||
|
||||
// Lexical this
|
||||
var bob = {
|
||||
_name: "Bob",
|
||||
_friends: [],
|
||||
printFriends() {
|
||||
this._friends.forEach(f => {
|
||||
console.log(this._name + " knows " + f);
|
||||
});
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Async functions
|
||||
@@ -16,31 +41,27 @@ async function chainAnimationsAsync(elem, animations) {
|
||||
}
|
||||
```
|
||||
|
||||
## Arrow functions
|
||||
|
||||
```javascript
|
||||
arr.map(x => x * x);
|
||||
```
|
||||
|
||||
## Let scoping
|
||||
|
||||
```javascript
|
||||
for (let i in arr) {
|
||||
let v = arr[i];
|
||||
}
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
```javascript
|
||||
class Foo extends Bar {
|
||||
constructor() { }
|
||||
class SkinnedMesh extends THREE.Mesh {
|
||||
constructor(geometry, materials) {
|
||||
super(geometry, materials);
|
||||
|
||||
foo() { }
|
||||
this.idMatrix = SkinnedMesh.defaultMatrix();
|
||||
this.bones = [];
|
||||
this.boneMatrices = [];
|
||||
//...
|
||||
}
|
||||
|
||||
get bar() { }
|
||||
update(camera) {
|
||||
//...
|
||||
super.update();
|
||||
}
|
||||
|
||||
set bar() { }
|
||||
static defaultMatrix() {
|
||||
return new THREE.Matrix4();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -70,16 +91,35 @@ var MULTIPLIER; // error
|
||||
## Default parameters
|
||||
|
||||
```javascript
|
||||
function foo(bar = "foo") {
|
||||
return bar + "bar";
|
||||
function f(x, y = 12) {
|
||||
// y is 12 if not passed (or passed as undefined)
|
||||
return x + y;
|
||||
}
|
||||
f(3) == 15
|
||||
```
|
||||
|
||||
## Destructuring
|
||||
|
||||
```javascript
|
||||
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
|
||||
console.log(a + b + c); // hello, world
|
||||
// list matching
|
||||
var [a, , b] = [1,2,3];
|
||||
|
||||
// object matching
|
||||
var { op: a, lhs: { op: b }, rhs: c } = getASTNode();
|
||||
|
||||
// object matching shorthand
|
||||
// binds `op`, `lhs` and `rhs` in scope
|
||||
var { op, lhs, rhs } = getASTNode();
|
||||
|
||||
// Can be used in parameter position
|
||||
function g({ name: x }) {
|
||||
console.log(x);
|
||||
}
|
||||
g({ name: 5 });
|
||||
|
||||
// Fail-soft destructuring
|
||||
var [a] = [];
|
||||
a === undefined;
|
||||
```
|
||||
|
||||
## For-of
|
||||
@@ -100,6 +140,14 @@ for (var i of [1, 2, 3]) {
|
||||
```javascript
|
||||
```
|
||||
|
||||
## Let scoping
|
||||
|
||||
```javascript
|
||||
for (let i in arr) {
|
||||
let v = arr[i];
|
||||
}
|
||||
```
|
||||
|
||||
## Modules
|
||||
|
||||
```javascript
|
||||
@@ -141,23 +189,21 @@ function f(x, y) {
|
||||
## Rest parameters
|
||||
|
||||
```javascript
|
||||
function printList(name, ...items) {
|
||||
console.log("list %s has the following items", name);
|
||||
items.forEach(function (item) {
|
||||
console.log(item);
|
||||
});
|
||||
function f(x, ...y) {
|
||||
// y is an Array
|
||||
return x * y.length;
|
||||
}
|
||||
f(3, "hello", true) == 6
|
||||
```
|
||||
|
||||
## Spread
|
||||
|
||||
```javascript
|
||||
function add(x, y) {
|
||||
return x + y;
|
||||
function f(x, y, z) {
|
||||
return x + y + z;
|
||||
}
|
||||
|
||||
var numbers = [5, 10];
|
||||
add(...numbers); // 15
|
||||
// Pass each elem of array as argument
|
||||
f(...[1,2,3]) == 6
|
||||
```
|
||||
|
||||
## Template literals
|
||||
|
||||
20
doc/index.md
20
doc/index.md
@@ -1,4 +1,4 @@
|
||||
**6to5** turns ES6 code into vanilla ES5, so you can use ES6 features **today.**
|
||||
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
|
||||
|
||||
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
|
||||
- **Extensible** - with a large range of [plugins](plugins.md) and **browser support**.
|
||||
@@ -11,6 +11,24 @@ It's as easy as:
|
||||
|
||||
$ npm install -g 6to5
|
||||
|
||||
## Usage
|
||||
|
||||
Once you've installed 6to5, there are multiple paths you can take depending on
|
||||
how you want to use it.
|
||||
|
||||
6to5 will simply compile your ES6+ script to ES5 if you pass it as an argument
|
||||
to the command-line tool `6to5`:
|
||||
|
||||
$ 6to5 script.js
|
||||
|
||||
If you have a file written using ES6+ and you just want to run it, `6to5-node`
|
||||
has you covered:
|
||||
|
||||
$ 6to5-node script.js
|
||||
|
||||
And it doesn't end here! To see all the ways you can use 6to5, check out the
|
||||
[Usage](http://6to5.github.io/usage.html) page.
|
||||
|
||||
## [Features](features.md)
|
||||
|
||||
- [Array comprehension](features.md#array-comprehension)
|
||||
|
||||
14
doc/usage.md
14
doc/usage.md
@@ -50,16 +50,28 @@ Compile and run `test.js`.
|
||||
|
||||
```javascript
|
||||
var to5 = require("6to5");
|
||||
```
|
||||
|
||||
### to5.transform(code, [opts]);
|
||||
|
||||
```javascript
|
||||
var result = to5.transform("code();", options);
|
||||
result.code;
|
||||
result.map;
|
||||
result.ast;
|
||||
```
|
||||
|
||||
### to5.transformFileSync(filename, [opts])
|
||||
|
||||
```javascript
|
||||
to5.transformFileSync("filename.js", options).code;
|
||||
```
|
||||
|
||||
### to5.transformFile(filename, [opts], callback)
|
||||
|
||||
```javascript
|
||||
to5.transformFile("filename.js", options, function (err, result) {
|
||||
|
||||
result.code;
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -2,13 +2,6 @@ var transform = module.exports = require("./transformation/transform");
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
transform.eval = function (code, opts) {
|
||||
opts = opts || {};
|
||||
opts.filename = opts.filename || "eval";
|
||||
opts.sourceMap = "inline";
|
||||
return eval(transform(code, opts).code);
|
||||
};
|
||||
|
||||
transform.run = function (code, opts) {
|
||||
opts = opts || {};
|
||||
opts.sourceMap = "inline";
|
||||
|
||||
@@ -18,7 +18,8 @@ function File(opts) {
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = ["extends", "class-props", "slice", "apply-constructor"];
|
||||
File.declarations = ["extends", "class-props", "slice", "apply-constructor",
|
||||
"tagged-template-literal"];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
@@ -30,3 +30,11 @@ exports.ClassBody = function (node, print) {
|
||||
this.rightBrace();
|
||||
}
|
||||
};
|
||||
|
||||
exports.MethodDefinition = function (node, print) {
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
}
|
||||
|
||||
this._method(node, print);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var t = require("../../types");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.UnaryExpression = function (node, print) {
|
||||
var hasSpace = /[a-z]$/.test(node.operator);
|
||||
@@ -105,6 +106,11 @@ exports.MemberExpression = function (node, print) {
|
||||
print(node.property);
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(node.object) && util.isInteger(node.object.value)) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
}
|
||||
|
||||
@@ -74,5 +74,5 @@ exports.XJSClosingElement = function (node, print) {
|
||||
};
|
||||
|
||||
exports.XJSEmptyExpression = function () {
|
||||
this.push("null");
|
||||
|
||||
};
|
||||
|
||||
@@ -41,6 +41,8 @@ exports._method = function (node, print) {
|
||||
this.push(kind + " ");
|
||||
}
|
||||
|
||||
if (value.async) this.push("async ");
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(key);
|
||||
@@ -54,16 +56,9 @@ exports._method = function (node, print) {
|
||||
print(value.body);
|
||||
};
|
||||
|
||||
exports.MethodDefinition = function (node, print) {
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
}
|
||||
|
||||
this._method(node, print);
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
this.push("function");
|
||||
if (node.generator) this.push("*");
|
||||
this.space();
|
||||
@@ -74,6 +69,8 @@ exports.FunctionExpression = function (node, print) {
|
||||
};
|
||||
|
||||
exports.ArrowFunctionExpression = function (node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.params.length === 1 && !node.defaults.length && !node.rest && t.isIdentifier(node.params[0])) {
|
||||
print(node.params[0]);
|
||||
} else {
|
||||
|
||||
@@ -25,9 +25,10 @@ exports.ExportDeclaration = function (node, print) {
|
||||
|
||||
if (node.declaration) {
|
||||
print(node.declaration);
|
||||
if (t.isStatement(node.declaration)) return;
|
||||
} else {
|
||||
if (specifiers.length === 1 && t.isExportBatchSpecifier(specifiers[0])) {
|
||||
this.push("*");
|
||||
print(specifiers[0]);
|
||||
} else {
|
||||
this.push("{");
|
||||
if (specifiers.length) {
|
||||
|
||||
@@ -4,6 +4,7 @@ exports.WithStatement = function (node, print) {
|
||||
this.keyword("with");
|
||||
this.push("(");
|
||||
print(node.object);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
|
||||
@@ -134,15 +135,6 @@ exports.SwitchStatement = function (node, print) {
|
||||
this.push(") {");
|
||||
print.sequence(node.cases, { indent: true });
|
||||
this.push("}");
|
||||
|
||||
//if (node.cases.length) {
|
||||
// this.newline();
|
||||
// print.sequence(node.cases, { indent: true });
|
||||
// this.newline();
|
||||
// this.rightBrace();
|
||||
//} else {
|
||||
// this.push("}");
|
||||
//}
|
||||
};
|
||||
|
||||
exports.SwitchCase = function (node, print) {
|
||||
@@ -154,13 +146,8 @@ exports.SwitchCase = function (node, print) {
|
||||
this.push("default:");
|
||||
}
|
||||
|
||||
if (node.consequent.length === 1) {
|
||||
this.space();
|
||||
print(node.consequent[0]);
|
||||
} else if (node.consequent.length > 1) {
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
}
|
||||
this.space();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
};
|
||||
|
||||
exports.DebuggerStatement = function () {
|
||||
|
||||
@@ -74,13 +74,20 @@ exports.Literal = function (node) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "boolean" || type === "number" || type === "string") {
|
||||
if (type === "string") {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape unicode characters
|
||||
val = val.replace(/[\u007f-\uffff]/g, function(c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
} else if (type === "boolean" || type === "number") {
|
||||
this.push(JSON.stringify(val));
|
||||
} else if (node.regex) {
|
||||
this.push("/" + node.regex.pattern + "/" + node.regex.flags);
|
||||
} else if (val === null) {
|
||||
this.push("null");
|
||||
} else if (node.raw) {
|
||||
this.push(node.raw);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ module.exports = Node;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
var result;
|
||||
@@ -24,17 +24,14 @@ function Node(node, parent) {
|
||||
}
|
||||
|
||||
Node.prototype.isUserWhitespacable = function () {
|
||||
//var parent = this.parent;
|
||||
var parent = this.parent;
|
||||
var node = this.node;
|
||||
|
||||
if (t.isUserWhitespacable(node)) {
|
||||
if (t.isUserWhitespacable(node) ||
|
||||
t.isSequenceExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//if (t.isArrayExpression(parent)) {
|
||||
// return true;
|
||||
//}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (namespace) {
|
||||
namespace = t.identifier(namespace || "to5Runtime");
|
||||
namespace = t.identifier(t.toIdentifier(namespace || "to5Runtime"));
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
|
||||
4
lib/6to5/templates/tagged-template-literal.js
Normal file
4
lib/6to5/templates/tagged-template-literal.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function (strings, raw) {
|
||||
return Object.defineProperties(strings, { raw: { value: raw } });
|
||||
});
|
||||
|
||||
@@ -27,37 +27,38 @@ transform.moduleFormatters = {
|
||||
};
|
||||
|
||||
_.each({
|
||||
modules: require("./transformers/modules"),
|
||||
propertyNameShorthand: require("./transformers/property-name-shorthand"),
|
||||
constants: require("./transformers/constants"),
|
||||
arrayComprehension: require("./transformers/array-comprehension"),
|
||||
generatorComprehension: require("./transformers/generator-comprehension"),
|
||||
arrowFunctions: require("./transformers/arrow-functions"),
|
||||
classes: require("./transformers/classes"),
|
||||
modules: require("./transformers/modules"),
|
||||
propertyNameShorthand: require("./transformers/property-name-shorthand"),
|
||||
constants: require("./transformers/constants"),
|
||||
arrayComprehension: require("./transformers/array-comprehension"),
|
||||
generatorComprehension: require("./transformers/generator-comprehension"),
|
||||
arrowFunctions: require("./transformers/arrow-functions"),
|
||||
classes: require("./transformers/classes"),
|
||||
|
||||
_propertyLiterals: require("./transformers/_property-literals"),
|
||||
computedPropertyNames: require("./transformers/computed-property-names"),
|
||||
_propertyLiterals: require("./transformers/_property-literals"),
|
||||
computedPropertyNames: require("./transformers/computed-property-names"),
|
||||
|
||||
spread: require("./transformers/spread"),
|
||||
templateLiterals: require("./transformers/template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/property-method-assignment"),
|
||||
defaultParameters: require("./transformers/default-parameters"),
|
||||
restParameters: require("./transformers/rest-parameters"),
|
||||
destructuring: require("./transformers/destructuring"),
|
||||
letScoping: require("./transformers/let-scoping"),
|
||||
forOf: require("./transformers/for-of"),
|
||||
unicodeRegex: require("./transformers/unicode-regex"),
|
||||
spread: require("./transformers/spread"),
|
||||
templateLiterals: require("./transformers/template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/property-method-assignment"),
|
||||
defaultParameters: require("./transformers/default-parameters"),
|
||||
restParameters: require("./transformers/rest-parameters"),
|
||||
destructuring: require("./transformers/destructuring"),
|
||||
forOf: require("./transformers/for-of"),
|
||||
letScoping: require("./transformers/let-scoping"),
|
||||
unicodeRegex: require("./transformers/unicode-regex"),
|
||||
|
||||
react: require("./transformers/react"),
|
||||
react: require("./transformers/react"),
|
||||
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
generators: require("./transformers/generators"),
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
generators: require("./transformers/generators"),
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
|
||||
_moduleFormatter: require("./transformers/_module-formatter")
|
||||
_memberExpressionKeywords: require("./transformers/_member-expression-keywords"),
|
||||
_moduleFormatter: require("./transformers/_module-formatter")
|
||||
}, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
var esutils = require("esutils");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.MemberExpression = function (node) {
|
||||
var prop = node.property;
|
||||
if (t.isIdentifier(prop) && esutils.keyword.isKeywordES6(prop.name, true)) {
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
}
|
||||
};
|
||||
@@ -4,7 +4,7 @@ var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, file, scope) {
|
||||
return t.variableDeclaration("var", [
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, new Class(node, file, scope).run())
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -7,13 +7,14 @@ exports.BlockStatement =
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement =
|
||||
exports.ForStatement = function (node, parent, file) {
|
||||
var constants = [];
|
||||
var constants = {};
|
||||
|
||||
var check = function (node, names) {
|
||||
var check = function (node, names, parent) {
|
||||
_.each(names, function (name) {
|
||||
if (constants.indexOf(name) >= 0) {
|
||||
throw file.errorWithNode(node, name + " is read-only");
|
||||
}
|
||||
if (!_.has(constants, name)) return;
|
||||
if (parent && t.isBlockStatement(parent) && parent !== constants[name]) return;
|
||||
|
||||
throw file.errorWithNode(node, name + " is read-only");
|
||||
});
|
||||
};
|
||||
|
||||
@@ -21,12 +22,12 @@ exports.ForStatement = function (node, parent, file) {
|
||||
return t.getIds(node, false, ["MemberExpression"]);
|
||||
};
|
||||
|
||||
_.each(node.body, function (child) {
|
||||
_.each(node.body, function (child, parent) {
|
||||
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
|
||||
_.each(child.declarations, function (declar) {
|
||||
_.each(getIds(declar), function (name) {
|
||||
check(declar, [name]);
|
||||
constants.push(name);
|
||||
check(declar, [name], parent);
|
||||
constants[name] = parent;
|
||||
});
|
||||
|
||||
declar._ignoreConstant = true;
|
||||
@@ -37,13 +38,13 @@ exports.ForStatement = function (node, parent, file) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!constants.length) return;
|
||||
if (_.isEmpty(constants)) return;
|
||||
|
||||
traverse(node, function (child) {
|
||||
traverse(node, function (child, parent) {
|
||||
if (child._ignoreConstant) return;
|
||||
|
||||
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(child, getIds(child));
|
||||
if (t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(child, getIds(child), parent);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -146,6 +146,12 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
return nodes;
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file) {
|
||||
if (parent.type === "ExpressionStatement") return;
|
||||
if (!t.isPattern(node.left)) return;
|
||||
throw file.errorWithNode(node, "AssignmentExpression destructuring outside of a ExpressionStatement is forbidden due to current 6to5 limitations");
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@ exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
var left = node.left;
|
||||
var declar;
|
||||
|
||||
var stepKey = t.identifier(file.generateUid("step", scope));
|
||||
var stepValueId = t.memberExpression(stepKey, t.identifier("value"));
|
||||
var stepKey = t.identifier(file.generateUid("step", scope));
|
||||
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||
|
||||
if (t.isIdentifier(left)) {
|
||||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValueId));
|
||||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
|
||||
} else if (t.isVariableDeclaration(left)) {
|
||||
declar = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(left.declarations[0].id, stepValueId)
|
||||
t.variableDeclarator(left.declarations[0].id, stepValue)
|
||||
]);
|
||||
} else {
|
||||
return;
|
||||
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
|
||||
}
|
||||
|
||||
var node2 = util.template("for-of", {
|
||||
|
||||
@@ -74,7 +74,6 @@ function LetScoping(forParent, block, parent, file, scope) {
|
||||
|
||||
this.letReferences = {};
|
||||
this.body = [];
|
||||
this.info = this.getInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +86,10 @@ LetScoping.prototype.run = function () {
|
||||
if (block._letDone) return;
|
||||
block._letDone = true;
|
||||
|
||||
this.info = this.getInfo();
|
||||
|
||||
// this is a block within a `Function` so we can safely leave it be
|
||||
if (t.isFunction(this.parent)) return;
|
||||
if (t.isFunction(this.parent)) return this.noClosure();
|
||||
|
||||
// this block has no let references so let's clean up
|
||||
if (!this.info.keys.length) return this.noClosure();
|
||||
@@ -132,7 +133,7 @@ LetScoping.prototype.run = function () {
|
||||
|
||||
/**
|
||||
* There are no let references accessed within a closure so we can just traverse
|
||||
* through this block and replace all references that exist in a high scope to
|
||||
* through this block and replace all references that exist in a higher scope to
|
||||
* their uids.
|
||||
*/
|
||||
|
||||
@@ -145,11 +146,25 @@ LetScoping.prototype.noClosure = function () {
|
||||
|
||||
if (_.isEmpty(replacements)) return;
|
||||
|
||||
traverse(block, function (node, parent) {
|
||||
var replace = function (node, parent) {
|
||||
if (!t.isIdentifier(node)) return;
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
node.name = replacements[node.name] || node.name;
|
||||
});
|
||||
};
|
||||
|
||||
var traverseReplace = function (node, parent) {
|
||||
replace(node, parent);
|
||||
traverse(node, replace);
|
||||
};
|
||||
|
||||
var forParent = this.forParent;
|
||||
if (forParent) {
|
||||
traverseReplace(forParent.right, forParent);
|
||||
traverseReplace(forParent.test, forParent);
|
||||
traverseReplace(forParent.update, forParent);
|
||||
}
|
||||
|
||||
traverse(block, replace);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -181,10 +196,23 @@ LetScoping.prototype.getInfo = function () {
|
||||
keys: []
|
||||
};
|
||||
|
||||
var duplicates = function (id, key) {
|
||||
var has = scope.parentGet(key);
|
||||
|
||||
if (has && has !== id) {
|
||||
// there's a variable with this exact name in an upper scope so we need
|
||||
// to generate a new name
|
||||
opts.duplicates[key] = id.name = file.generateUid(key, scope);
|
||||
}
|
||||
};
|
||||
|
||||
_.each(opts.declarators, function (declar) {
|
||||
opts.declarators.push(declar);
|
||||
|
||||
var keys = t.getIds(declar);
|
||||
var keys = t.getIds(declar, true);
|
||||
_.each(keys, duplicates);
|
||||
keys = _.keys(keys);
|
||||
|
||||
opts.outsideKeys = opts.outsideKeys.concat(keys);
|
||||
opts.keys = opts.keys.concat(keys);
|
||||
});
|
||||
@@ -193,14 +221,7 @@ LetScoping.prototype.getInfo = function () {
|
||||
if (!isLet(declar)) return;
|
||||
|
||||
_.each(t.getIds(declar, true), function (id, key) {
|
||||
var has = scope.parentGet(key);
|
||||
|
||||
if (has && has !== id) {
|
||||
// there's a variable with this exact name in an upper scope so we need
|
||||
// to generate a new name
|
||||
opts.duplicates[key] = id.name = file.generateUid(key, scope);
|
||||
}
|
||||
|
||||
duplicates(id, key);
|
||||
opts.keys.push(key);
|
||||
});
|
||||
});
|
||||
@@ -211,7 +232,8 @@ LetScoping.prototype.getInfo = function () {
|
||||
/**
|
||||
* If we're inside of a `For*Statement` then traverse it and check if it has one
|
||||
* of the following node types `ReturnStatement`, `BreakStatement`,
|
||||
* `ContinueStatement` and replace it with a return value we can track later on.
|
||||
* `ContinueStatement` and replace it with a return value that we can track
|
||||
* later on.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
@@ -251,7 +273,7 @@ LetScoping.prototype.checkFor = function () {
|
||||
|
||||
/**
|
||||
* Hoist all var declarations in this block to before it so they retain scope
|
||||
* once we wrap everything is in a closure.
|
||||
* once we wrap everything in a closure.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.hoistVarDeclarations = function () {
|
||||
@@ -340,7 +362,7 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
LetScoping.prototype.buildPushDeclar = function (node) {
|
||||
LetScoping.prototype.pushDeclar = function (node) {
|
||||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
|
||||
return t.variableDeclarator(declar.id);
|
||||
})));
|
||||
|
||||
32
lib/6to5/transformation/transformers/react.js
vendored
32
lib/6to5/transformation/transformers/react.js
vendored
@@ -106,11 +106,35 @@ exports.XJSElement = {
|
||||
exit: function (node) {
|
||||
var callExpr = node.openingElement;
|
||||
|
||||
var childrenToRender = node.children.filter(function(child) {
|
||||
return !(t.isLiteral(child) && _.isString(child.value) && child.value.match(/^[ \t]*[\r\n][ \t\r\n]*$/));
|
||||
});
|
||||
_.each(node.children, function (child) {
|
||||
if (t.isLiteral(child)) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
|
||||
_.each(lines, function (line, i) {
|
||||
var isFirstLine = i === 0;
|
||||
var isLastLine = i === lines.length - 1;
|
||||
|
||||
// replace rendered whitespace tabs with spaces
|
||||
var trimmedLine = line.replace(/\t/g, ' ');
|
||||
|
||||
// trim whitespace touching a newline
|
||||
if (!isFirstLine) {
|
||||
trimmedLine = trimmedLine.replace(/^[ ]+/, '');
|
||||
}
|
||||
|
||||
// trim whitespace touching an endline
|
||||
if (!isLastLine) {
|
||||
trimmedLine = trimmedLine.replace(/[ ]+$/, '');
|
||||
}
|
||||
|
||||
if (trimmedLine) {
|
||||
callExpr.arguments.push(t.literal(trimmedLine));
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_.each(childrenToRender, function (child) {
|
||||
callExpr.arguments.push(child);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,14 +5,22 @@ var buildBinaryExpression = function (left, right) {
|
||||
return t.binaryExpression("+", left, right);
|
||||
};
|
||||
|
||||
exports.TaggedTemplateExpression = function (node) {
|
||||
exports.TaggedTemplateExpression = function (node, parent, file) {
|
||||
var args = [];
|
||||
var quasi = node.quasi;
|
||||
|
||||
var strings = quasi.quasis.map(function (elem) {
|
||||
return t.literal(elem.value.raw);
|
||||
var strings = [];
|
||||
var raw = [];
|
||||
|
||||
_.each(quasi.quasis, function (elem) {
|
||||
strings.push(t.literal(elem.value.cooked));
|
||||
raw.push(t.literal(elem.value.raw));
|
||||
});
|
||||
args.push(t.arrayExpression(strings));
|
||||
|
||||
args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [
|
||||
t.arrayExpression(strings),
|
||||
t.arrayExpression(raw)
|
||||
]));
|
||||
|
||||
_.each(quasi.expressions, function (expr) {
|
||||
args.push(expr);
|
||||
|
||||
@@ -4,6 +4,8 @@ var traverse = require("./index");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var FOR_KEYS = ["left", "init"];
|
||||
|
||||
function Scope(parent, block) {
|
||||
this.parent = parent;
|
||||
this.block = block;
|
||||
@@ -19,29 +21,59 @@ Scope.prototype.getIds = function () {
|
||||
var self = this;
|
||||
var ids = block._scopeIds = {};
|
||||
|
||||
if (t.isBlockStatement(block)) {
|
||||
_.each(block.body, function (node) {
|
||||
if (t.isVariableDeclaration(node) && node.kind !== "var") {
|
||||
self.add(node, ids);
|
||||
}
|
||||
});
|
||||
} else if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, function (node, parent) {
|
||||
if (parent !== block && t.isVariableDeclaration(node) && node.kind !== "var") {
|
||||
return;
|
||||
}
|
||||
// ForStatement - left, init
|
||||
|
||||
if (t.isDeclaration(node)) {
|
||||
self.add(node, ids);
|
||||
} else if (t.isFunction(node)) {
|
||||
return false;
|
||||
}
|
||||
if (t.isFor(block)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var node = block[key];
|
||||
if (t.isLet(node)) self.add(node, ids);
|
||||
});
|
||||
} else if (t.isCatchClause(block)) {
|
||||
|
||||
block = block.body;
|
||||
}
|
||||
|
||||
// Program, BlockStatement - let variables
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
_.each(block.body, function (node) {
|
||||
// check for non-var `VariableDeclaration`s
|
||||
if (t.isLet(node)) self.add(node, ids);
|
||||
});
|
||||
}
|
||||
|
||||
// CatchClause - param
|
||||
|
||||
if (t.isCatchClause(block)) {
|
||||
self.add(block.param, ids);
|
||||
}
|
||||
|
||||
// Program, Function - var variables
|
||||
|
||||
if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, function (node) {
|
||||
if (t.isFor(node)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var declar = node[key];
|
||||
if (t.isVar(declar)) self.add(declar, ids);
|
||||
});
|
||||
}
|
||||
|
||||
// this block is a function so we'll stop since none of the variables
|
||||
// declared within are accessible
|
||||
if (t.isFunction(node)) return false;
|
||||
|
||||
// we've ran into a declaration!
|
||||
// we'll let the BlockStatement scope deal with `let` declarations
|
||||
if (t.isDeclaration(node) && !t.isLet(node)) {
|
||||
self.add(node, ids);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function - params
|
||||
|
||||
if (t.isFunction(block)) {
|
||||
this.add(block.rest, ids);
|
||||
_.each(block.params, function (param) {
|
||||
self.add(param, ids);
|
||||
});
|
||||
@@ -51,6 +83,7 @@ Scope.prototype.getIds = function () {
|
||||
};
|
||||
|
||||
Scope.prototype.add = function (node, ids) {
|
||||
if (!node) return;
|
||||
_.merge(ids || this.ids, t.getIds(node, true));
|
||||
};
|
||||
|
||||
|
||||
@@ -35,12 +35,13 @@
|
||||
"ClassDeclaration": ["Statement", "Declaration", "Class"],
|
||||
"ClassExpression": ["Class"],
|
||||
|
||||
"ForOfStatement": ["Statement", "For"],
|
||||
"ForInStatement": ["Statement", "For"],
|
||||
"ForStatement": ["Statement", "For"],
|
||||
"ForOfStatement": ["Statement", "For", "Scope"],
|
||||
"ForInStatement": ["Statement", "For", "Scope"],
|
||||
"ForStatement": ["Statement", "For", "Scope"],
|
||||
|
||||
"ObjectPattern": ["Pattern"],
|
||||
"ArrayPattern": ["Pattern"],
|
||||
|
||||
"Property": ["UserWhitespacable"]
|
||||
"Property": ["UserWhitespacable"],
|
||||
"XJSElement": ["UserWhitespacable"]
|
||||
}
|
||||
|
||||
@@ -106,6 +106,10 @@ t.ensureBlock = function (node) {
|
||||
};
|
||||
|
||||
t.toStatement = function (node, ignore) {
|
||||
if (t.isStatement(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var mustHaveId = false;
|
||||
var newType;
|
||||
|
||||
@@ -115,8 +119,6 @@ t.toStatement = function (node, ignore) {
|
||||
} else if (t.isFunction(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "FunctionDeclaration";
|
||||
} else if (t.isStatement(node)) {
|
||||
newType = node.type;
|
||||
}
|
||||
|
||||
if (mustHaveId && !node.id) {
|
||||
@@ -183,6 +185,14 @@ t.getIds = function (node, map, ignoreTypes) {
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.isLet = function (node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
|
||||
};
|
||||
|
||||
t.isVar = function (node) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
AssignmentExpression: "left",
|
||||
ImportSpecifier: "id",
|
||||
|
||||
@@ -17,6 +17,10 @@ exports.canCompile = function (filename, altExts) {
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.isInteger = function (i) {
|
||||
return _.isNumber(i) && i % 1 === 0;
|
||||
};
|
||||
|
||||
exports.resolve = function (loc) {
|
||||
try {
|
||||
return require.resolve(loc);
|
||||
@@ -123,23 +127,17 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
|
||||
template = _.cloneDeep(template);
|
||||
|
||||
var inherits = false;
|
||||
if (nodes) {
|
||||
inherits = nodes.inherits;
|
||||
delete nodes.inherits;
|
||||
|
||||
if (!_.isEmpty(nodes)) {
|
||||
traverse(template, function (node) {
|
||||
if (t.isIdentifier(node) && _.has(nodes, node.name)) {
|
||||
var newNode = nodes[node.name];
|
||||
if (_.isString(newNode)) {
|
||||
node.name = newNode;
|
||||
} else {
|
||||
return newNode;
|
||||
}
|
||||
if (!_.isEmpty(nodes)) {
|
||||
traverse(template, function (node) {
|
||||
if (t.isIdentifier(node) && _.has(nodes, node.name)) {
|
||||
var newNode = nodes[node.name];
|
||||
if (_.isString(newNode)) {
|
||||
node.name = newNode;
|
||||
} else {
|
||||
return newNode;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var node = template.body[0];
|
||||
@@ -150,10 +148,6 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
if (t.isParenthesizedExpression(node)) node = node.expression;
|
||||
}
|
||||
|
||||
if (inherits) {
|
||||
node = t.inherits(node, inherits);
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.12.5",
|
||||
"version": "1.12.14",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -44,11 +44,11 @@
|
||||
"es6-symbol": "0.1.1",
|
||||
"regexpu": "0.3.0",
|
||||
"source-map": "0.1.40",
|
||||
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/75925940a7bb67d1ee8afec36b6d6eec072fb47c.tar.gz",
|
||||
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/a9c53518af063ffef410f826225f8ee250131932.tar.gz",
|
||||
"chokidar": "0.10.5",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.4",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/0384a0d51f630f66ed591769c1765581a17d2124.tar.gz",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/a6c34ba73e215bd16ee585f6794f6a6587820c58.tar.gz",
|
||||
"estraverse": "^1.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -36,8 +36,6 @@ exports.get = function (entryName) {
|
||||
if (fs.existsSync(suiteOptsLoc)) suite.options = require(suiteOptsLoc);
|
||||
|
||||
_.each(fs.readdirSync(suite.filename), function (taskName) {
|
||||
if (taskName[0] === ".") return;
|
||||
|
||||
var taskDir = suite.filename + "/" + taskName;
|
||||
if (fs.statSync(taskDir).isFile()) return;
|
||||
|
||||
@@ -59,6 +57,7 @@ exports.get = function (entryName) {
|
||||
|
||||
var test = {
|
||||
title: humanise(taskName),
|
||||
disabled: taskName[0] === ".",
|
||||
options: taskOpts,
|
||||
exec: {
|
||||
code: readFile(execLoc),
|
||||
|
||||
17
test/api.js
Normal file
17
test/api.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var assert = require("assert");
|
||||
var File = require("../lib/6to5/file");
|
||||
|
||||
suite("api", function () {
|
||||
test("{ code: false }", function () {
|
||||
var result = transform("foo('bar');", { code: false });
|
||||
assert.ok(!result.code);
|
||||
});
|
||||
|
||||
test("addDeclaration unknown", function () {
|
||||
var file = new File;
|
||||
assert.throws(function () {
|
||||
file.addDeclaration("foob");
|
||||
}, /unknown declaration foob/);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
var multiples = [for (num of nums) num * num];
|
||||
var multiples = [for (num of nums) for (num2 of nums) num * num];
|
||||
var multiples = [for (num of nums) if (num > 5) num * num];
|
||||
@@ -1,3 +0,0 @@
|
||||
var multiples = [for (num of nums) num * num];
|
||||
var multiples = [for (num of nums) for (num2 of nums) num * num];
|
||||
var multiples = [for (num of nums) if (num > 5) num * num];
|
||||
@@ -1 +0,0 @@
|
||||
var foo = [1, 2, 3];
|
||||
@@ -1 +0,0 @@
|
||||
var foo = [1, 2, 3];
|
||||
@@ -1,17 +0,0 @@
|
||||
var foo = `i
|
||||
am a multiline string`;
|
||||
|
||||
var foo = `i am also
|
||||
a multiline string
|
||||
foobar`;
|
||||
|
||||
var foo = `im a single line string`;
|
||||
|
||||
var foo = tagit`i
|
||||
am a multiline string`;
|
||||
|
||||
var foo = tagit`i am also
|
||||
a multiline string
|
||||
foobar`;
|
||||
|
||||
var foo = tagit`im a single line string`;
|
||||
@@ -1,17 +0,0 @@
|
||||
var foo = `i
|
||||
am a multiline string`;
|
||||
|
||||
var foo = `i am also
|
||||
a multiline string
|
||||
foobar`;
|
||||
|
||||
var foo = `im a single line string`;
|
||||
|
||||
var foo = tagit`i
|
||||
am a multiline string`;
|
||||
|
||||
var foo = tagit`i am also
|
||||
a multiline string
|
||||
foobar`;
|
||||
|
||||
var foo = tagit`im a single line string`;
|
||||
@@ -2,3 +2,5 @@
|
||||
/**/
|
||||
/*
|
||||
*/
|
||||
|
||||
test
|
||||
@@ -4,6 +4,6 @@ export { a as b, c as d } from "hello";
|
||||
export { a as b, c as d };
|
||||
export {};
|
||||
export default i = 20;
|
||||
export function test() {};
|
||||
export function test() {}
|
||||
export var i = 20;
|
||||
export let i = 42;
|
||||
|
||||
5
test/fixtures/generation/types/ArrayExpression-ArrayPattern/actual.js
vendored
Normal file
5
test/fixtures/generation/types/ArrayExpression-ArrayPattern/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[a, b, c];
|
||||
[[], [b, c], []];
|
||||
[a,, b,];
|
||||
[a,,,, b];
|
||||
[a, b,, c];
|
||||
5
test/fixtures/generation/types/ArrayExpression-ArrayPattern/expected.js
vendored
Normal file
5
test/fixtures/generation/types/ArrayExpression-ArrayPattern/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[a, b, c];
|
||||
[[], [b, c], []];
|
||||
[a,, b];
|
||||
[a,,,, b];
|
||||
[a, b,, c];
|
||||
4
test/fixtures/generation/types/ArrowFunctionExpression/actual.js
vendored
Normal file
4
test/fixtures/generation/types/ArrowFunctionExpression/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var foo = x => x * x;
|
||||
var foo = (a, b) => a * b;
|
||||
var foo = async x => x * x;
|
||||
var foo = async (a, b) => a * b;
|
||||
4
test/fixtures/generation/types/ArrowFunctionExpression/expected.js
vendored
Normal file
4
test/fixtures/generation/types/ArrowFunctionExpression/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var foo = x => x * x;
|
||||
var foo = (a, b) => a * b;
|
||||
var foo = async x => x * x;
|
||||
var foo = async (a, b) => a * b;
|
||||
@@ -0,0 +1,3 @@
|
||||
foo === bar;
|
||||
foo + bar;
|
||||
foo = bar;
|
||||
@@ -0,0 +1,3 @@
|
||||
foo === bar;
|
||||
foo + bar;
|
||||
foo = bar;
|
||||
7
test/fixtures/generation/types/AwaitExpression/actual.js
vendored
Normal file
7
test/fixtures/generation/types/AwaitExpression/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
async function foo() {
|
||||
await bar();
|
||||
}
|
||||
|
||||
async function bar() {
|
||||
await* foo();
|
||||
}
|
||||
7
test/fixtures/generation/types/AwaitExpression/expected.js
vendored
Normal file
7
test/fixtures/generation/types/AwaitExpression/expected.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
async function foo() {
|
||||
await bar();
|
||||
}
|
||||
|
||||
async function bar() {
|
||||
await* foo();
|
||||
}
|
||||
5
test/fixtures/generation/types/BlockStatement/actual.js
vendored
Normal file
5
test/fixtures/generation/types/BlockStatement/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{}
|
||||
|
||||
{
|
||||
foo();
|
||||
}
|
||||
5
test/fixtures/generation/types/BlockStatement/expected.js
vendored
Normal file
5
test/fixtures/generation/types/BlockStatement/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{}
|
||||
|
||||
{
|
||||
foo();
|
||||
}
|
||||
7
test/fixtures/generation/types/BreakStatement/actual.js
vendored
Normal file
7
test/fixtures/generation/types/BreakStatement/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
for (var i in foo) {
|
||||
break;
|
||||
}
|
||||
|
||||
foo: for (var i in foo) {
|
||||
break foo;
|
||||
}
|
||||
7
test/fixtures/generation/types/BreakStatement/expected.js
vendored
Normal file
7
test/fixtures/generation/types/BreakStatement/expected.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
for (var i in foo) {
|
||||
break;
|
||||
}
|
||||
|
||||
foo: for (var i in foo) {
|
||||
break foo;
|
||||
}
|
||||
5
test/fixtures/generation/types/CallExpression/actual.js
vendored
Normal file
5
test/fixtures/generation/types/CallExpression/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
foo();
|
||||
foo("foo");
|
||||
foo("foo", "bar");
|
||||
foo(bar());
|
||||
foo(bar("test"));
|
||||
5
test/fixtures/generation/types/CallExpression/expected.js
vendored
Normal file
5
test/fixtures/generation/types/CallExpression/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
foo();
|
||||
foo("foo");
|
||||
foo("foo", "bar");
|
||||
foo(bar());
|
||||
foo(bar("test"));
|
||||
13
test/fixtures/generation/types/ClassBody-MethodDefinition/actual.js
vendored
Normal file
13
test/fixtures/generation/types/ClassBody-MethodDefinition/actual.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
class Foo {
|
||||
async foo() {}
|
||||
foo() {}
|
||||
["foo"]() {}
|
||||
get foo() {}
|
||||
set foo() {}
|
||||
|
||||
static async foo() {}
|
||||
static foo() {}
|
||||
static ["foo"]() {}
|
||||
static get foo() {}
|
||||
static set foo() {}
|
||||
}
|
||||
13
test/fixtures/generation/types/ClassBody-MethodDefinition/expected.js
vendored
Normal file
13
test/fixtures/generation/types/ClassBody-MethodDefinition/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
class Foo {
|
||||
async foo() {}
|
||||
foo() {}
|
||||
["foo"]() {}
|
||||
get foo() {}
|
||||
set foo() {}
|
||||
|
||||
static async foo() {}
|
||||
static foo() {}
|
||||
static ["foo"]() {}
|
||||
static get foo() {}
|
||||
static set foo() {}
|
||||
}
|
||||
2
test/fixtures/generation/types/ClassDeclaration/actual.js
vendored
Normal file
2
test/fixtures/generation/types/ClassDeclaration/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var foo = class Foo {};
|
||||
var foo = class Foo extends Bar {};
|
||||
2
test/fixtures/generation/types/ClassDeclaration/expected.js
vendored
Normal file
2
test/fixtures/generation/types/ClassDeclaration/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var foo = class Foo {};
|
||||
var foo = class Foo extends Bar {};
|
||||
2
test/fixtures/generation/types/ClassExpression/actual.js
vendored
Normal file
2
test/fixtures/generation/types/ClassExpression/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
class Foo {}
|
||||
class Foo extends Bar {}
|
||||
2
test/fixtures/generation/types/ClassExpression/expected.js
vendored
Normal file
2
test/fixtures/generation/types/ClassExpression/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
class Foo {}
|
||||
class Foo extends Bar {}
|
||||
9
test/fixtures/generation/types/ComprehensionBlock-ComprehensionExpression/actual.js
vendored
Normal file
9
test/fixtures/generation/types/ComprehensionBlock-ComprehensionExpression/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[for (x of nums) x * x];
|
||||
[for (x of nums) if (x > 2) x * x];
|
||||
[for (nums of nums2) for (x of nums) x * x];
|
||||
[for (nums of nums2) for (x of nums) if (x > 2) x * x];
|
||||
|
||||
(for (x of nums) x * x);
|
||||
(for (x of nums) if (x > 2) x * x);
|
||||
(for (nums of nums2) for (x of nums) x * x);
|
||||
(for (nums of nums2) for (x of nums) if (x > 2) x * x);
|
||||
9
test/fixtures/generation/types/ComprehensionBlock-ComprehensionExpression/expected.js
vendored
Normal file
9
test/fixtures/generation/types/ComprehensionBlock-ComprehensionExpression/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[for (x of nums) x * x];
|
||||
[for (x of nums) if (x > 2) x * x];
|
||||
[for (nums of nums2) for (x of nums) x * x];
|
||||
[for (nums of nums2) for (x of nums) if (x > 2) x * x];
|
||||
|
||||
(for (x of nums) x * x);
|
||||
(for (x of nums) if (x > 2) x * x);
|
||||
(for (nums of nums2) for (x of nums) x * x);
|
||||
(for (nums of nums2) for (x of nums) if (x > 2) x * x);
|
||||
1
test/fixtures/generation/types/ConditionalExpression/actual.js
vendored
Normal file
1
test/fixtures/generation/types/ConditionalExpression/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo ? foo : bar;
|
||||
1
test/fixtures/generation/types/ConditionalExpression/expected.js
vendored
Normal file
1
test/fixtures/generation/types/ConditionalExpression/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo ? foo : bar;
|
||||
7
test/fixtures/generation/types/ContinueStatement/actual.js
vendored
Normal file
7
test/fixtures/generation/types/ContinueStatement/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
for (var i in foo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foo: for (var i in foo) {
|
||||
continue foo;
|
||||
}
|
||||
7
test/fixtures/generation/types/ContinueStatement/expected.js
vendored
Normal file
7
test/fixtures/generation/types/ContinueStatement/expected.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
for (var i in foo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foo: for (var i in foo) {
|
||||
continue foo;
|
||||
}
|
||||
1
test/fixtures/generation/types/DebuggerStatement/actual.js
vendored
Normal file
1
test/fixtures/generation/types/DebuggerStatement/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
debugger;
|
||||
1
test/fixtures/generation/types/DebuggerStatement/expected.js
vendored
Normal file
1
test/fixtures/generation/types/DebuggerStatement/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
debugger;
|
||||
5
test/fixtures/generation/types/DoWhileStatement/actual.js
vendored
Normal file
5
test/fixtures/generation/types/DoWhileStatement/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
do {
|
||||
test();
|
||||
} while (true);
|
||||
|
||||
do {} while (true);
|
||||
5
test/fixtures/generation/types/DoWhileStatement/expected.js
vendored
Normal file
5
test/fixtures/generation/types/DoWhileStatement/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
do {
|
||||
test();
|
||||
} while (true);
|
||||
|
||||
do {} while (true);
|
||||
1
test/fixtures/generation/types/EmptyStatement/actual.js
vendored
Normal file
1
test/fixtures/generation/types/EmptyStatement/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
1
test/fixtures/generation/types/EmptyStatement/expected.js
vendored
Normal file
1
test/fixtures/generation/types/EmptyStatement/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
27
test/fixtures/generation/types/ExportDeclaration-ExportSpecifier-ExportBatchSpecifier/actual.js
vendored
Normal file
27
test/fixtures/generation/types/ExportDeclaration-ExportSpecifier-ExportBatchSpecifier/actual.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export default 42;
|
||||
export default {};
|
||||
export default [];
|
||||
export default foo;
|
||||
export default function () {};
|
||||
export default class {};
|
||||
export default function foo() {};
|
||||
export default class Foo {};
|
||||
export * from "foo";
|
||||
export { foo } from "foo";
|
||||
export { foo, bar } from "foo";
|
||||
export { foo as bar } from "foo";
|
||||
export { foo as default } from "foo";
|
||||
export { foo as default, bar } from "foo";
|
||||
export { foo };
|
||||
export { foo, bar };
|
||||
export { foo as bar };
|
||||
export { foo as default };
|
||||
export { foo as default, bar };
|
||||
export var foo = 1;
|
||||
export var foo2 = function () {};
|
||||
export var foo3;
|
||||
export let foo4 = 2;
|
||||
export let foo5;
|
||||
export const foo6 = 3;
|
||||
export function foo7() {}
|
||||
export class foo8 {}
|
||||
@@ -0,0 +1,27 @@
|
||||
export default 42;
|
||||
export default {};
|
||||
export default [];
|
||||
export default foo;
|
||||
export default function () {};
|
||||
export default class {};
|
||||
export default function foo() {};
|
||||
export default class Foo {};
|
||||
export * from "foo";
|
||||
export { foo } from "foo";
|
||||
export { foo, bar } from "foo";
|
||||
export { foo as bar } from "foo";
|
||||
export { foo as default } from "foo";
|
||||
export { foo as default, bar } from "foo";
|
||||
export { foo };
|
||||
export { foo, bar };
|
||||
export { foo as bar };
|
||||
export { foo as default };
|
||||
export { foo as default, bar };
|
||||
export var foo = 1;
|
||||
export var foo2 = function () {};
|
||||
export var foo3;
|
||||
export let foo4 = 2;
|
||||
export let foo5;
|
||||
export const foo6 = 3;
|
||||
export function foo7() {}
|
||||
export class foo8 {}
|
||||
5
test/fixtures/generation/types/ForInStatement/actual.js
vendored
Normal file
5
test/fixtures/generation/types/ForInStatement/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
for (var i in nums) {}
|
||||
|
||||
for (var i in nums) {
|
||||
nums[i] = nums[i] * nums[i];
|
||||
}
|
||||
5
test/fixtures/generation/types/ForInStatement/expected.js
vendored
Normal file
5
test/fixtures/generation/types/ForInStatement/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
for (var i in nums) {}
|
||||
|
||||
for (var i in nums) {
|
||||
nums[i] = nums[i] * nums[i];
|
||||
}
|
||||
5
test/fixtures/generation/types/ForOfStatement/actual.js
vendored
Normal file
5
test/fixtures/generation/types/ForOfStatement/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
for (var x of nums) {}
|
||||
|
||||
for (var x of nums) {
|
||||
console.log(x * x);
|
||||
}
|
||||
5
test/fixtures/generation/types/ForOfStatement/expected.js
vendored
Normal file
5
test/fixtures/generation/types/ForOfStatement/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
for (var x of nums) {}
|
||||
|
||||
for (var x of nums) {
|
||||
console.log(x * x);
|
||||
}
|
||||
3
test/fixtures/generation/types/ForStatement/actual.js
vendored
Normal file
3
test/fixtures/generation/types/ForStatement/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var i = 0;;) {}
|
||||
for (var i = 0; i < 5;) {}
|
||||
for (var i = 0; i < 5; i++) {}
|
||||
3
test/fixtures/generation/types/ForStatement/expected.js
vendored
Normal file
3
test/fixtures/generation/types/ForStatement/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var i = 0;;) {}
|
||||
for (var i = 0; i < 5;) {}
|
||||
for (var i = 0; i < 5; i++) {}
|
||||
23
test/fixtures/generation/types/FunctionDeclaration-FunctionExpression/actual.js
vendored
Normal file
23
test/fixtures/generation/types/FunctionDeclaration-FunctionExpression/actual.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function foo(bar = "bar") {}
|
||||
|
||||
function foo(bar = "bar", ...items) {}
|
||||
|
||||
function foo(...items) {}
|
||||
|
||||
function* foo() {}
|
||||
|
||||
function foo() {}
|
||||
|
||||
async function foo() {}
|
||||
|
||||
var foo = function* foo() {};
|
||||
|
||||
var foo = function foo() {};
|
||||
|
||||
var foo = async function foo() {};
|
||||
|
||||
var foo = function* () {};
|
||||
|
||||
var foo = function () {};
|
||||
|
||||
var foo = async function () {};
|
||||
23
test/fixtures/generation/types/FunctionDeclaration-FunctionExpression/expected.js
vendored
Normal file
23
test/fixtures/generation/types/FunctionDeclaration-FunctionExpression/expected.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function foo(bar = "bar") {}
|
||||
|
||||
function foo(bar = "bar", ...items) {}
|
||||
|
||||
function foo(...items) {}
|
||||
|
||||
function* foo() {}
|
||||
|
||||
function foo() {}
|
||||
|
||||
async function foo() {}
|
||||
|
||||
var foo = function* foo() {};
|
||||
|
||||
var foo = function foo() {};
|
||||
|
||||
var foo = async function foo() {};
|
||||
|
||||
var foo = function* () {};
|
||||
|
||||
var foo = function () {};
|
||||
|
||||
var foo = async function () {};
|
||||
2
test/fixtures/generation/types/Identifier/actual.js
vendored
Normal file
2
test/fixtures/generation/types/Identifier/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
foo;
|
||||
undefined;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user