Starting ES6 classes

This commit is contained in:
Fábio Santos
2015-10-27 00:40:46 +00:00
parent 64e7a00399
commit 5f7cb6939c
4 changed files with 140 additions and 28 deletions

View File

@@ -502,6 +502,12 @@ 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;
@@ -1188,6 +1194,31 @@ function OutputStream(options) {
});
else output.print("{}");
});
DEFPRINT(AST_Class, function(self, output){
output.print("class");
output.space();
if (self.name) {
self.name.print(output);
output.space();
}
if (self.extends) {
output.print("extends");
output.space();
self.extends.print(output);
output.space();
}
if (self.properties.length > 0) output.with_block(function(){
self.properties.forEach(function(prop, i){
if (i) {
output.newline();
}
output.indent();
prop.print(output);
});
output.newline();
});
else output.print("{}");
});
DEFPRINT(AST_ObjectKeyVal, function(self, output){
var key = self.key;
var quote = self.quote;