Merge pull request #763 from fabiosantoscode/feature/harmony-super

Feature/harmony super
This commit is contained in:
Richard van Velzen
2015-08-07 08:54:20 +02:00
5 changed files with 22 additions and 1 deletions

View File

@@ -967,6 +967,10 @@ var AST_This = DEFNODE("This", null, {
$documentation: "The `this` symbol", $documentation: "The `this` symbol",
}, AST_Symbol); }, AST_Symbol);
var AST_Super = DEFNODE("Super", null, {
$documentation: "The `super` symbol",
}, AST_Symbol);
var AST_Constant = DEFNODE("Constant", null, { var AST_Constant = DEFNODE("Constant", null, {
$documentation: "Base class for all constants", $documentation: "Base class for all constants",
getValue: function() { getValue: function() {

View File

@@ -1192,6 +1192,9 @@ function OutputStream(options) {
DEFPRINT(AST_This, function(self, output){ DEFPRINT(AST_This, function(self, output){
output.print("this"); output.print("this");
}); });
DEFPRINT(AST_Super, function(self, output){
output.print("super");
});
DEFPRINT(AST_Constant, function(self, output){ DEFPRINT(AST_Constant, function(self, output){
output.print(self.getValue()); output.print(self.getValue());
}); });

View File

@@ -1447,7 +1447,9 @@ function parse($TEXT, options) {
function _make_symbol(type) { function _make_symbol(type) {
var name = S.token.value; var name = S.token.value;
return new (name == "this" ? AST_This : type)({ return new (name == "this" ? AST_This :
name == "super" ? AST_Super :
type)({
name : String(name), name : String(name),
start : S.token, start : S.token,
end : S.token end : S.token
@@ -1586,6 +1588,7 @@ function parse($TEXT, options) {
function is_assignable(expr) { function is_assignable(expr) {
if (!options.strict) return true; if (!options.strict) return true;
if (expr instanceof AST_This) return false; if (expr instanceof AST_This) return false;
if (expr instanceof AST_Super) return false;
return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol); return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);
}; };

View File

@@ -472,6 +472,8 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
base54.consider("new"); base54.consider("new");
else if (node instanceof AST_This) else if (node instanceof AST_This)
base54.consider("this"); base54.consider("this");
else if (node instanceof AST_Super)
base54.consider("super");
else if (node instanceof AST_Try) else if (node instanceof AST_Try)
base54.consider("try"); base54.consider("try");
else if (node instanceof AST_Catch) else if (node instanceof AST_Catch)

9
test/compress/super.js Normal file
View File

@@ -0,0 +1,9 @@
super_can_be_parsed: {
input: {
super(1,2);
super.meth();
}
expect_exact: "super(1,2);super.meth();"
}