Compare commits

...

9 Commits

Author SHA1 Message Date
Sebastian McKenzie
e01b7d288f v2.12.3 2015-01-15 02:29:44 +11:00
Sebastian McKenzie
98c0e185b8 add missing semicolon 2015-01-15 02:27:45 +11:00
Sebastian McKenzie
bf66d78210 add 2.12.3 changelog 2015-01-15 02:27:17 +11:00
Sebastian McKenzie
b60eca0a76 better typeof symbol transformer 2015-01-15 02:24:32 +11:00
Sebastian McKenzie
44f06c0b4c instance and static class method names 2015-01-15 02:24:23 +11:00
Sebastian McKenzie
6c5606b7e8 call transformer methods on traverse context 2015-01-15 02:24:05 +11:00
Sebastian McKenzie
07ddfbeb5d remove pointless prototypeProperties helper call 2015-01-15 01:20:06 +11:00
Sebastian McKenzie
87b890c172 fix parentheses deletion not support multilines - fixes #490 2015-01-15 01:14:49 +11:00
Sebastian McKenzie
245fcfe110 move mutator map checking to after loose test 2015-01-15 01:09:13 +11:00
17 changed files with 78 additions and 51 deletions

View File

@@ -11,6 +11,12 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 2.12.3
* **Spec Compliancy**
* Optional `typeof` transformer checks for `undefined` before passing it to the helper.
* Class methods are now named.
## 2.12.2
* **Internal**

View File

@@ -96,8 +96,8 @@ function replEval(code, context, filename, callback) {
var result;
try {
if (/^\((.*?)\n\)$/.test(code)) {
code = code.slice(1, -2); // remove "(" and "\n)"
if (code[0] === "(" && code[code.length - 1] === ")") {
code = code.slice(1, -1); // remove "(" and ")"
}
result = _eval(code, filename);

View File

@@ -65,7 +65,7 @@ Transformer.prototype.transform = function (file) {
if (exit) fn = fns.exit;
if (!fn) return;
return fn(node, parent, file, scope);
return fn.call(this, node, parent, file, scope);
};
};

View File

@@ -1,12 +1,24 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var propertyMethodAssignment = require("./es6-property-method-assignment");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
exports.ClassDeclaration = function (node, parent, file, scope) {
return new Class(node, file, scope, true).run();
};
exports.ClassExpression = function (node, parent, file, scope) {
if (!node.id) {
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
// var o = { foo: class {} };
node.id = parent.key;
}
if (t.isVariableDeclarator(parent)) {
node.id = parent.id;
}
}
return new Class(node, file, scope, false).run();
};
@@ -179,15 +191,10 @@ Class.prototype.pushMethod = function (node) {
var methodName = node.key;
var kind = node.kind;
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
if (kind === "") {
propertyMethodAssignment._namedMethod(node, this.file, this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes
@@ -204,6 +211,14 @@ Class.prototype.pushMethod = function (node) {
kind = "value";
}
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node);
};

View File

@@ -2,13 +2,9 @@ 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;
exports._namedMethod = function (node, file, scope) {
var key = t.toComputedKey(node, node.key);
if (!t.isLiteral(key)) return; // we can't set a function id with this
if (!t.isLiteral(key)) return node; // we can't set a function id with this
var id = t.toIdentifier(key.value);
key = t.identifier(id);
@@ -46,6 +42,14 @@ exports.Property = function (node, parent, file, scope) {
}
};
exports.Property = function (node, parent, file, scope) {
if (!node.method) return;
node.method = false;
exports._namedMethod(node, file, scope);
};
exports.ObjectExpression = function (node) {
var mutatorMap = {};
var hasAny = false;

View File

@@ -3,7 +3,19 @@ var t = require("../../types");
exports.optional = true;
exports.UnaryExpression = function (node, parent, file) {
this.skip();
if (node.operator === "typeof") {
return t.callExpression(file.addHelper("typeof"), [node.argument]);
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
if (t.isIdentifier(node.argument)) {
var undefLiteral = t.literal("undefined");
return t.conditionalExpression(
t.binaryExpression("===", t.unaryExpression("typeof", node.argument), undefLiteral),
undefLiteral,
call
);
} else {
return call;
}
}
};

View File

@@ -201,6 +201,10 @@ t.isReferenced = function (node, parent) {
if (_.contains(parent.params, node)) return false;
}
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
return false;
}
// we're a catch clause param
if (t.isCatchClause(parent) && parent.param === node) return false;

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.12.2",
"version": "2.12.3",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {

View File

@@ -1,11 +1,6 @@
"use strict";
var _slice = Array.prototype.slice;
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
@@ -37,21 +32,19 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
Test.prototype.test = function () {
Test.prototype.test = function test() {
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 () {
Test.foo = function foo() {
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)));
};
_prototypeProperties(Test, {}, {});
return Test;
})(Foo);

View File

@@ -1,10 +1,5 @@
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
@@ -28,11 +23,9 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
Test.test = function () {
Test.test = function test() {
return Foo.wow.call(this);
};
_prototypeProperties(Test, {});
return Test;
})(Foo);

View File

@@ -61,7 +61,7 @@ var Test = (function (Foo) {
_prototypeProperties(Test, {
foo: {
value: function () {
value: function foo() {
var _get4;
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
_get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments);
@@ -73,7 +73,7 @@ var Test = (function (Foo) {
}
}, {
test: {
value: function () {
value: function test() {
var _get5;
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments);

View File

@@ -52,7 +52,7 @@ var Test = (function (Foo) {
_prototypeProperties(Test, {
test: {
value: function () {
value: function test() {
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
},
writable: true,

View File

@@ -10,7 +10,7 @@ var Test = (function () {
_prototypeProperties(Test, null, {
test: {
value: function () {
value: function test() {
return 5 + 5;
},
writable: true,

View File

@@ -9,16 +9,16 @@ var BaseView = function BaseView() {
this.autoRender = true;
};
var BaseView = function () {
var BaseView = function BaseView() {
this.autoRender = true;
};
var BaseView = (function () {
var _class2 = function () {};
function BaseView() {}
_prototypeProperties(_class2, null, {
_prototypeProperties(BaseView, null, {
foo: {
value: function () {
value: function foo() {
this.autoRender = true;
},
writable: true,
@@ -27,5 +27,5 @@ var BaseView = (function () {
}
});
return _class2;
return BaseView;
})();

View File

@@ -10,7 +10,7 @@ var A = (function () {
_prototypeProperties(A, {
a: {
value: function () {},
value: function a() {},
writable: true,
enumerable: true,
configurable: true

View File

@@ -16,7 +16,7 @@ var H = (function () {
var J = new WeakMap(),
K = new WeakMap();
var I = new WeakMap();
var _class = function () {};
function H() {}
return _class;
return H;
})();

View File

@@ -5,4 +5,4 @@ var _typeof = function (obj) {
};
var s = Symbol("s");
assert.equal(_typeof(s), "symbol");
assert.equal(typeof s === "undefined" ? "undefined" : _typeof(s), "symbol");