instance and static class method names
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user