Fix quoting of properties

- Make AST_ConciseMethod child of AST_ObjectProperty.
- Fix some typos.
This commit is contained in:
Anthony Van de Gejuchte
2016-07-29 03:18:21 +02:00
committed by Richard van Velzen
parent 67461666dc
commit 1c15d0db45
7 changed files with 257 additions and 58 deletions

View File

@@ -1253,7 +1253,7 @@ function parse($TEXT, options) {
});
};
var function_ = function(ctor) {
var function_ = function(ctor, is_generator_property) {
var start = S.token
var in_statement = ctor === AST_Defun;
@@ -1267,7 +1267,7 @@ function parse($TEXT, options) {
unexpected();
var args = params_or_seq_().as_params(croak);
var body = _function_body(true, is_generator);
var body = _function_body(true, is_generator || is_generator_property);
return new ctor({
start : args.start,
end : body.end,
@@ -1744,7 +1744,7 @@ function parse($TEXT, options) {
start = S.token;
var type = start.type;
var name = as_property_name();
if (type != "string" && type != "num" && !is("punc", ":")) {
if (!is("punc", ":")) {
var concise = concise_method_or_getset(name, start);
if (concise) {
a.push(concise);
@@ -1757,8 +1757,10 @@ function parse($TEXT, options) {
if (type == "punc" && start.value == "[") {
expect(":");
a.push(new AST_ObjectComputedKeyVal({
start: start,
key: name,
value: expression(false)
value: expression(false),
end: prev()
}));
continue;
}
@@ -1859,12 +1861,15 @@ function parse($TEXT, options) {
}
var is_static = false;
var is_generator = false;
var property_token = start;
if (is_class && name === "static" && !is("punc", "(")) {
is_static = true;
property_token = S.token;
name = as_property_name();
}
if (name === null) {
is_generator = true;
property_token = S.token;
name = as_property_name();
if (name === null) {
unexpected();
@@ -1872,23 +1877,28 @@ function parse($TEXT, options) {
}
if (is("punc", "(")) {
name = get_ast(name, start);
return new AST_ConciseMethod({
is_generator: is_generator,
var node = new AST_ConciseMethod({
start : start,
static : is_static,
name : name,
argnames : params_or_seq_().as_params(croak),
body : _function_body(true, is_generator),
is_generator: is_generator,
key : name,
quote : name instanceof AST_SymbolMethod ?
property_token.quote : undefined,
value : function_(AST_Accessor, is_generator),
end : prev()
});
return node;
}
property_token = S.token;
if (name == "get") {
if (!is("punc") || is("punc", "[")) {
name = get_ast(as_property_name(), prev());
name = get_ast(as_property_name(), start);
return new AST_ObjectGetter({
start : start,
static: is_static,
key : name,
quote : name instanceof AST_SymbolMethod ?
property_token.quote : undefined,
value : function_(AST_Accessor),
end : prev()
});
@@ -1896,11 +1906,13 @@ function parse($TEXT, options) {
}
else if (name == "set") {
if (!is("punc") || is("punc", "[")) {
name = get_ast(as_property_name(), prev());
name = get_ast(as_property_name(), start);
return new AST_ObjectSetter({
start : start,
static: is_static,
key : name,
quote : name instanceof AST_SymbolMethod ?
property_token.quote : undefined,
value : function_(AST_Accessor),
end : prev()
});