Make AST_Class inherit AST_Scope instead of AST_Object
This is one of those days I'd love to use multiple inheritance. An AST_Class has lots of common with AST_Object, but unfortunately `instanceof AST_Scope` is used very, very much, and a class has its name inside its own special pocket scope. This compels me to make AST_Class inherit Scope instead. It looks like, although there is much in common with AST_Object, `instanceof AST_Object` seldom are made, perhaps because it is less often necessary to traverse an object than a scope.
This commit is contained in:
18
lib/ast.js
18
lib/ast.js
@@ -964,13 +964,27 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "static", {
|
|||||||
$documentation: "An object getter property",
|
$documentation: "An object getter property",
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_Class = DEFNODE("Class", "name extends", {
|
var AST_Class = DEFNODE("Class", "name extends properties", {
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
name: "[AST_SymbolClassName?] optional class name.",
|
name: "[AST_SymbolClassName?] optional class name.",
|
||||||
extends: "[AST_Node]? optional parent class",
|
extends: "[AST_Node]? optional parent class",
|
||||||
|
properties: "[AST_ObjectProperty*] array of properties"
|
||||||
},
|
},
|
||||||
$documentation: "An ES6 class",
|
$documentation: "An ES6 class",
|
||||||
}, AST_Object);
|
_walk: function(visitor) {
|
||||||
|
return visitor._visit(this, function(){
|
||||||
|
if (this.name) {
|
||||||
|
this.name._walk(visitor);
|
||||||
|
}
|
||||||
|
if (this.extends) {
|
||||||
|
this.extends._walk(visitor);
|
||||||
|
}
|
||||||
|
this.properties.forEach(function(prop){
|
||||||
|
prop._walk(visitor);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}, AST_Scope);
|
||||||
|
|
||||||
var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
|
var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
|
|||||||
@@ -502,12 +502,6 @@ function OutputStream(options) {
|
|||||||
return first_in_statement(output);
|
return first_in_statement(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Not a class, though. It can be alone in a statement although
|
|
||||||
// it extends from AST_Object.
|
|
||||||
PARENS(AST_Class, function() {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
PARENS([ AST_Unary, AST_Undefined ], function(output){
|
PARENS([ AST_Unary, AST_Undefined ], function(output){
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_PropAccess && p.expression === this;
|
return p instanceof AST_PropAccess && p.expression === this;
|
||||||
|
|||||||
Reference in New Issue
Block a user