Make distinction between * method and * operator

Also add quotes to properties when necessary,
this might be the case if the name isn't a valid
identifier
This commit is contained in:
Anthony Van de Gejuchte
2016-07-22 11:46:30 +02:00
parent 3f8fc3a316
commit 110a1ac885
4 changed files with 125 additions and 25 deletions

View File

@@ -888,7 +888,11 @@ function OutputStream(options) {
}
}
if (self.name instanceof AST_Symbol) {
self.name.print(output);
if (typeof self.name.name === "string" && !is_identifier_string(self.name.name)) {
output.print_string(self.name.name);
} else {
self.name.print(output);
}
} else if (nokeyword && self.name instanceof AST_Node) {
output.with_square(function() {
self.name.print(output); // Computed method name
@@ -1450,15 +1454,19 @@ function OutputStream(options) {
output.colon();
self.value.print(output);
});
DEFPRINT(AST_ObjectSetter, function(self, output){
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, self, output) {
if (self.static) {
output.print("static");
output.space();
}
output.print("set");
output.print(type);
output.space();
if (self.key instanceof AST_SymbolMethod) {
self.key.print(output);
if (typeof self.key.name === "string" && !is_identifier_string(self.key.name)) {
output.print_string(self.key.name);
} else {
self.key.print(output);
}
} else {
output.with_square(function() {
self.key.print(output);
@@ -1466,21 +1474,11 @@ function OutputStream(options) {
}
self.value._do_print(output, true);
});
DEFPRINT(AST_ObjectSetter, function(self, output){
self._print_getter_setter("set", self, output);
});
DEFPRINT(AST_ObjectGetter, function(self, output){
if (self.static) {
output.print("static");
output.space();
}
output.print("get");
output.space();
if (self.key instanceof AST_SymbolMethod) {
self.key.print(output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true);
self._print_getter_setter("get", self, output);
});
DEFPRINT(AST_ObjectComputedKeyVal, function(self, output) {
output.print("[");

View File

@@ -1747,7 +1747,7 @@ function parse($TEXT, options) {
a.push(concise);
continue;
}
} else if (start.value === "*") {
} else if (name === null) {
unexpected(prev());
}
@@ -1844,14 +1844,13 @@ function parse($TEXT, options) {
function concise_method_or_getset(name, start, is_class) {
var get_ast = function(name, token) {
if (typeof name === "string" || typeof name === "number") {
if (name === "*") {
unexpected(token);
}
return new AST_SymbolMethod({
start: token,
name: name,
end: prev()
});
} else if (name === null) {
unexpected();
}
return name;
}
@@ -1861,9 +1860,12 @@ function parse($TEXT, options) {
is_static = true;
name = as_property_name();
}
if (name === "*") {
if (name === null) {
is_generator = true;
name = as_property_name();
if (name === null) {
unexpected();
}
}
if (is("punc", "(")) {
name = get_ast(name, start);
@@ -2017,7 +2019,10 @@ function parse($TEXT, options) {
return ex;
} else unexpected(tmp);
case "operator":
if (["*", "delete", "in", "instanceof", "new", "typeof", "void"].indexOf(tmp.value) === -1) {
if (tmp.value === "*") {
return null;
}
if (["delete", "in", "instanceof", "new", "typeof", "void"].indexOf(tmp.value) === -1) {
unexpected(tmp);
}
case "name":