Compare commits

...

17 Commits

Author SHA1 Message Date
Sebastian McKenzie
b17bc95b4f v1.13.13 2014-11-25 19:49:51 +11:00
Sebastian McKenzie
a71f260377 add 1.13.13 changelog 2014-11-25 19:48:42 +11:00
Sebastian McKenzie
8cbc1f7f06 Merge pull request #218 from timoxley/no-no-timeouts
Remove --no-timeouts flag.
2014-11-25 19:47:54 +11:00
Sebastian McKenzie
34335018e9 v1.13.12 2014-11-25 19:03:48 +11:00
Sebastian McKenzie
136bddab33 temporarily disable es7-modules-system tests 2014-11-25 19:02:49 +11:00
Sebastian McKenzie
b2951c5462 remove SpreadProperty definition 2014-11-25 19:01:22 +11:00
Sebastian McKenzie
07de6f5f4a clean up Scope reference addition 2014-11-25 18:59:45 +11:00
Sebastian McKenzie
99ea00ca18 simplify generator context id 2014-11-25 18:59:36 +11:00
Sebastian McKenzie
ab5c6a38eb add VirtualPropertyExpression and SpreadProperty to ast-types 2014-11-25 18:59:26 +11:00
Sebastian McKenzie
52cee84625 add 1.13.12 changelog 2014-11-25 18:57:43 +11:00
Tim Oxley
20dc8b05c9 Remove --no-timeouts flag.
Not a valid flag, causes errors when trying to use debug modes.
2014-11-25 14:54:36 +08:00
Sebastian McKenzie
ba5992621d Merge branch 'guybedford-system' 2014-11-25 14:59:57 +11:00
Sebastian McKenzie
cdae98f653 Merge branch 'system' of github.com:guybedford/6to5 into guybedford-system 2014-11-25 14:59:47 +11:00
Sebastian McKenzie
81434bb557 add types.isDynamic so we can scan a node to see if it's ~safe~ to include it twice 2014-11-25 11:44:53 +11:00
Sebastian McKenzie
3af0fc6fb7 ignore XJSEmptyExpression - fixes #214 2014-11-25 11:44:35 +11:00
guybedford
3f60062ab6 system tests updates for live bindings and function hoisting 2014-11-24 16:05:54 +02:00
Sebastian McKenzie
76499bb26e update modules docs 2014-11-24 10:33:43 +11:00
37 changed files with 139 additions and 97 deletions

View File

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

View File

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

View File

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

View File

@@ -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");

View File

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

View File

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

View File

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

View File

@@ -132,6 +132,8 @@ exports.XJSElement = {
}
});
return;
} else if (t.isXJSEmptyExpression(child)) {
return;
}

View File

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

View File

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

View File

@@ -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": {

View File

@@ -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() {});
}
};
});

View 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 () {
}
};
});

View 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 () {
}
};
});

View File

@@ -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() {});
}
};
});

View File

@@ -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));
}
};
});

View File

@@ -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);
}

View File

@@ -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);
}
};
});

View File

@@ -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);
}
};
});

View File

@@ -82,6 +82,8 @@ suite("util", function () {
assert.equal(t.toIdentifier("swag-lord"), "swagLord");
});
test("isDynamic");
test("isReferenced");
test("removeProperties");