Implement new.target

This commit is contained in:
Fábio Santos
2015-11-21 14:48:23 +00:00
parent e076abdbf2
commit a800356ad0
4 changed files with 23 additions and 0 deletions

View File

@@ -1003,6 +1003,10 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
$documentation: "Base class for all symbols", $documentation: "Base class for all symbols",
}); });
var AST_NewTarget = DEFNODE("NewTarget", null, {
$documentation: "A reference to new.target"
});
var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, { var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
$documentation: "The name of a property accessor (setter/getter function)" $documentation: "The name of a property accessor (setter/getter function)"
}, AST_Symbol); }, AST_Symbol);

View File

@@ -1219,6 +1219,9 @@ function OutputStream(options) {
}); });
else output.print("{}"); else output.print("{}");
}); });
DEFPRINT(AST_NewTarget, function(self, output) {
output.print("new.target");
});
DEFPRINT(AST_ObjectKeyVal, function(self, output){ DEFPRINT(AST_ObjectKeyVal, function(self, output){
var key = self.key; var key = self.key;
var quote = self.quote; var quote = self.quote;

View File

@@ -1292,6 +1292,14 @@ function parse($TEXT, options) {
var new_ = function(allow_calls) { var new_ = function(allow_calls) {
var start = S.token; var start = S.token;
expect_token("operator", "new"); expect_token("operator", "new");
if (is("punc", ".")) {
next();
expect_token("name");
return subscripts(new AST_NewTarget({
start : start,
end : prev()
}), allow_calls);
}
var newexp = expr_atom(false), args; var newexp = expr_atom(false), args;
if (is("punc", "(")) { if (is("punc", "(")) {
next(); next();

View File

@@ -251,6 +251,14 @@ class_name_can_be_preserved: {
} }
} }
new_target: {
input: {
new.target;
new.target.name;
}
expect_exact: "new.target;new.target.name;"
}
number_literals: { number_literals: {
input: { input: {
0b1001; 0b1001;