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:
Fábio Santos
2015-11-20 19:34:10 +00:00
parent 364d20f8fb
commit bb6b3a773a
2 changed files with 16 additions and 8 deletions

View File

@@ -964,13 +964,27 @@ var AST_ObjectGetter = DEFNODE("ObjectGetter", "static", {
$documentation: "An object getter property",
}, AST_ObjectProperty);
var AST_Class = DEFNODE("Class", "name extends", {
var AST_Class = DEFNODE("Class", "name extends properties", {
$propdoc: {
name: "[AST_SymbolClassName?] optional class name.",
extends: "[AST_Node]? optional parent class",
properties: "[AST_ObjectProperty*] array of properties"
},
$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", {
$propdoc: {

View File

@@ -502,12 +502,6 @@ function OutputStream(options) {
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){
var p = output.parent();
return p instanceof AST_PropAccess && p.expression === this;