Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b17bc95b4f | ||
|
|
a71f260377 | ||
|
|
8cbc1f7f06 | ||
|
|
34335018e9 | ||
|
|
136bddab33 | ||
|
|
b2951c5462 | ||
|
|
07de6f5f4a | ||
|
|
99ea00ca18 | ||
|
|
ab5c6a38eb | ||
|
|
52cee84625 | ||
|
|
20dc8b05c9 | ||
|
|
ba5992621d | ||
|
|
cdae98f653 | ||
|
|
81434bb557 | ||
|
|
3af0fc6fb7 | ||
|
|
3f60062ab6 | ||
|
|
76499bb26e |
@@ -1,3 +1,11 @@
|
||||
# 1.13.13
|
||||
|
||||
* Fix `--debug` in `bin/6to5-node`. Thanks [@timoxley](https://github.com/timoxley).
|
||||
|
||||
# 1.13.12
|
||||
|
||||
* Ignore `XJSEmptyExpression`s in `react` transformer output.
|
||||
|
||||
# 1.13.11
|
||||
|
||||
* Fix `util.regexify` on falsy values.
|
||||
|
||||
@@ -14,13 +14,11 @@ process.argv.slice(2).forEach(function(arg){
|
||||
switch (flag) {
|
||||
case "-d":
|
||||
args.unshift("--debug");
|
||||
args.push("--no-timeouts");
|
||||
break;
|
||||
case "debug":
|
||||
case "--debug":
|
||||
case "--debug-brk":
|
||||
args.unshift(arg);
|
||||
args.push("--no-timeouts");
|
||||
break;
|
||||
case "-gc":
|
||||
case "--expose-gc":
|
||||
|
||||
@@ -15,6 +15,13 @@ to5.transform('import "foo";', { modules: "common" });
|
||||
|
||||
## Formats
|
||||
|
||||
* [AMD](#amd)
|
||||
* [Common (Default)](#common-default)
|
||||
* [Common](#common)
|
||||
* [Ignore](#ignore)
|
||||
* [System](#system)
|
||||
* [UMD](#umd)
|
||||
|
||||
### Common (Default)
|
||||
|
||||
**In**
|
||||
@@ -198,7 +205,7 @@ function bar() {
|
||||
}
|
||||
```
|
||||
|
||||
### Register
|
||||
### System
|
||||
|
||||
**In**
|
||||
|
||||
@@ -213,7 +220,7 @@ export function bar() {
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
System.register("bar", ["foo"], function ($__export) {
|
||||
System.register("bar", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "bar";
|
||||
@@ -227,12 +234,10 @@ System.register("bar", ["foo"], function ($__export) {
|
||||
foo = m.default;
|
||||
}],
|
||||
execute: function () {
|
||||
$__export("bar", bar);
|
||||
_export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Custom
|
||||
|
||||
@@ -3,6 +3,7 @@ var _ = require("lodash");
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
var or = types.Type.or;
|
||||
|
||||
// Program wrapper
|
||||
def("File")
|
||||
@@ -16,12 +17,19 @@ def("ParenthesizedExpression")
|
||||
.build("expression")
|
||||
.field("expression", def("Expression"));
|
||||
|
||||
// Same as ImportNamespaceSpecifier but `id` is `name`
|
||||
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
|
||||
def("ImportBatchSpecifier")
|
||||
.bases("Specifier")
|
||||
.build("name")
|
||||
.field("name", def("Identifier"));
|
||||
|
||||
// Abstract references
|
||||
def("VirtualPropertyExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "property")
|
||||
.field("object", def("Expression"))
|
||||
.field("property", or(def("Identifier"), def("Expression")));
|
||||
|
||||
types.finalize();
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
|
||||
@@ -83,7 +83,6 @@ SystemFormatter.prototype.transform = function (ast) {
|
||||
program.body = [t.expressionStatement(runner)];
|
||||
};
|
||||
|
||||
|
||||
SystemFormatter.prototype._buildSetters = function () {
|
||||
// generate setters array expression elements
|
||||
return _.map(this.importedModule, function (specs) {
|
||||
|
||||
@@ -56,7 +56,7 @@ var visitor = function (path, file) {
|
||||
);
|
||||
|
||||
var innerFnId = t.identifier(node.id.name + "$");
|
||||
var contextId = file.generateUidIdentifier("context$", scope);
|
||||
var contextId = file.generateUidIdentifier("context", scope);
|
||||
var vars = hoist(path);
|
||||
|
||||
var emitter = new Emitter(contextId);
|
||||
|
||||
@@ -29,7 +29,7 @@ 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.isIdentifier(value)) {
|
||||
if (t.isDynamic(value)) {
|
||||
var tempName = file.generateUid("temp");
|
||||
temp = value = t.identifier(tempName);
|
||||
scope.push(tempName, temp);
|
||||
@@ -70,7 +70,7 @@ exports.CallExpression = function (node, parent, file, scope) {
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp;
|
||||
if (!t.isIdentifier(callee.object)) {
|
||||
if (t.isDynamic(callee.object)) {
|
||||
// we need to save `callee.object` so we can call it again
|
||||
var tempName = file.generateUid("temp");
|
||||
temp = t.identifier(tempName);
|
||||
|
||||
@@ -132,6 +132,8 @@ exports.XJSElement = {
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
} else if (t.isXJSEmptyExpression(child)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,19 @@ function Scope(block, parent) {
|
||||
this.references = this.getReferences();
|
||||
}
|
||||
|
||||
Scope.add = function (node, references) {
|
||||
if (!node) return;
|
||||
_.merge(references, t.getIds(node, true));
|
||||
};
|
||||
|
||||
Scope.prototype.getReferences = function () {
|
||||
var block = this.block;
|
||||
if (block._scopeReferences) return block._scopeReferences;
|
||||
|
||||
var self = this;
|
||||
var references = block._scopeReferences = {};
|
||||
|
||||
var add = function (node) {
|
||||
self.add(node, references);
|
||||
Scope.add(node, references);
|
||||
};
|
||||
|
||||
// ForStatement - left, init
|
||||
@@ -116,9 +120,8 @@ Scope.prototype.push = function (name, id, init) {
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.add = function (node, references) {
|
||||
if (!node) return;
|
||||
_.merge(references || this.references, t.getIds(node, true));
|
||||
Scope.prototype.add = function (node) {
|
||||
Scope.add(node, this.references);
|
||||
};
|
||||
|
||||
Scope.prototype.get = function (id) {
|
||||
|
||||
@@ -87,6 +87,16 @@ t.shallowEqual = function (actual, expected) {
|
||||
|
||||
//
|
||||
|
||||
t.isDynamic = function (node) {
|
||||
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.isReferenced = function (node, parent) {
|
||||
// we're a property key so we aren't referenced
|
||||
if (t.isProperty(parent) && parent.key === node) return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.13.11",
|
||||
"version": "1.13.13",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
|
||||
@@ -4,10 +4,10 @@ System.register("actual", [], function (_export) {
|
||||
var __moduleName = "actual";
|
||||
|
||||
function _anonymous() {}
|
||||
var _anonymous2 = function _anonymous2() {};
|
||||
var _anonymous2;
|
||||
|
||||
function foo() {}
|
||||
var Foo = function Foo() {};
|
||||
var Foo;
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
@@ -22,11 +22,11 @@ System.register("actual", [], function (_export) {
|
||||
|
||||
_export("default", _anonymous);
|
||||
|
||||
_export("default", _anonymous2);
|
||||
_export("default", _anonymous2 = function _anonymous2() {});
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("default", Foo);
|
||||
_export("default", Foo = function Foo() {});
|
||||
}
|
||||
};
|
||||
});
|
||||
34
test/fixtures/transformation/.es6-modules-system/exports-from/expected.js
vendored
Normal file
34
test/fixtures/transformation/.es6-modules-system/exports-from/expected.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
System.register("actual", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var _localExports = ['foo', 'bar', 'default'];
|
||||
|
||||
return {
|
||||
setters: [
|
||||
function(m) {
|
||||
_export("foo", m.foo);
|
||||
|
||||
_export("foo", m.foo);
|
||||
|
||||
_export("bar", m.bar);
|
||||
|
||||
_export("bar", m.foo);
|
||||
|
||||
_export("default", m.foo);
|
||||
|
||||
_export("default", m.foo);
|
||||
|
||||
_export("bar", m.bar);
|
||||
|
||||
for (var p in m) {
|
||||
if (_localExports.indexOf(i) == -1)
|
||||
_export(p, m[p]);
|
||||
}
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
}
|
||||
};
|
||||
});
|
||||
26
test/fixtures/transformation/.es6-modules-system/exports-named/expected.js
vendored
Normal file
26
test/fixtures/transformation/.es6-modules-system/exports-named/expected.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [
|
||||
function(m) {
|
||||
_export("foo", m.foo);
|
||||
|
||||
_export("foo", m.foo);
|
||||
|
||||
_export("bar", m.bar);
|
||||
|
||||
_export("bar", m.foo);
|
||||
|
||||
_export("default", m.foo);
|
||||
|
||||
_export("default", m.foo);
|
||||
|
||||
_export("bar", m.bar);
|
||||
}],
|
||||
execute: function () {
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -3,33 +3,35 @@ System.register("actual", [], function (_export) {
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo = 1;
|
||||
var foo2 = function () {};
|
||||
var foo;
|
||||
var foo2;
|
||||
var foo3;
|
||||
var foo4 = 2;
|
||||
var foo4;
|
||||
var foo5;
|
||||
var foo6 = 3;
|
||||
var foo6;
|
||||
function foo7() {}
|
||||
var foo8 = function foo8() {};
|
||||
_export("foo7", foo7);
|
||||
|
||||
var foo8;
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("foo", foo);
|
||||
_export("foo", foo = 1);
|
||||
|
||||
_export("foo2", foo2);
|
||||
_export("foo2", foo2 = function () {});
|
||||
|
||||
_export("foo3", foo3);
|
||||
|
||||
_export("foo4", foo4);
|
||||
_export("foo4", foo4 = 2);
|
||||
|
||||
_export("foo5", foo5);
|
||||
|
||||
_export("foo6", foo6);
|
||||
_export("foo6", foo6 = 3);
|
||||
|
||||
_export("foo7", foo7);
|
||||
|
||||
_export("foo8", foo8);
|
||||
_export("foo8", foo8 = function foo8() {});
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -7,19 +7,19 @@ System.register("actual", ["./evens"], function (_export) {
|
||||
function nextOdd(n) {
|
||||
return isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(isEven);return {
|
||||
var isOdd;
|
||||
return {
|
||||
setters: [function (m) {
|
||||
isEven = m.isEven;
|
||||
}],
|
||||
execute: function () {
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
_export("isOdd", isOdd);
|
||||
_export("isOdd", isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(isEven));
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -4,7 +4,7 @@ System.register("actual", ["foo", "foo-bar", "./directory/foo-bar"], function (_
|
||||
var __moduleName = "actual";
|
||||
|
||||
var foo, bar;
|
||||
var test = 5;
|
||||
var test;
|
||||
|
||||
return {
|
||||
setters: [function (m) {
|
||||
@@ -16,7 +16,7 @@ System.register("actual", ["foo", "foo-bar", "./directory/foo-bar"], function (_
|
||||
execute: function () {
|
||||
_export("test", test);
|
||||
|
||||
_export("test", test);
|
||||
_export("test", test = 5);
|
||||
|
||||
_export("default", test);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
var exports = _export;
|
||||
(function (obj) {
|
||||
for (var i in obj) {
|
||||
exports[i] = obj[i];
|
||||
}
|
||||
})(foo);
|
||||
|
||||
_export("foo", foo.foo);
|
||||
|
||||
_export("foo", foo.foo);
|
||||
|
||||
_export("bar", foo.bar);
|
||||
|
||||
_export("bar", foo.foo);
|
||||
|
||||
_export("default", foo.foo);
|
||||
|
||||
_export("default", foo.foo);
|
||||
|
||||
_export("bar", foo.bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
System.register("actual", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "actual";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("foo", foo);
|
||||
|
||||
_export("foo", foo);
|
||||
|
||||
_export("bar", bar);
|
||||
|
||||
_export("bar", foo);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("default", foo);
|
||||
|
||||
_export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -82,6 +82,8 @@ suite("util", function () {
|
||||
assert.equal(t.toIdentifier("swag-lord"), "swagLord");
|
||||
});
|
||||
|
||||
test("isDynamic");
|
||||
|
||||
test("isReferenced");
|
||||
|
||||
test("removeProperties");
|
||||
|
||||
Reference in New Issue
Block a user