From bb6b3a773af0e2682689c738744226cf57d2340c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 20 Nov 2015 19:34:10 +0000 Subject: [PATCH] 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. --- lib/ast.js | 18 ++++++++++++++++-- lib/output.js | 6 ------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 9e2f3cee..b78a85b2 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -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: { diff --git a/lib/output.js b/lib/output.js index e744788f..d1ebdeee 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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;