instance and static class method names

This commit is contained in:
Sebastian McKenzie
2015-01-15 02:24:23 +11:00
parent 6c5606b7e8
commit 44f06c0b4c
11 changed files with 46 additions and 24 deletions

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();
};
@@ -181,6 +193,8 @@ Class.prototype.pushMethod = function (node) {
var kind = node.kind;
if (kind === "") {
propertyMethodAssignment._namedMethod(node, this.file, this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes

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

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

@@ -32,14 +32,14 @@ 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)));

View File

@@ -23,7 +23,7 @@ var Test = (function (Foo) {
_inherits(Test, Foo);
Test.test = function () {
Test.test = function test() {
return Foo.wow.call(this);
};

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