static properties
This commit is contained in:
15
lib/ast.js
15
lib/ast.js
@@ -473,7 +473,10 @@ var AST_Arrow = DEFNODE("Arrow", null, {
|
|||||||
$documentation: "An ES6 Arrow function ((a) => b)"
|
$documentation: "An ES6 Arrow function ((a) => b)"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_ConciseMethod = DEFNODE("ConciseMethod", null, {
|
var AST_ConciseMethod = DEFNODE("ConciseMethod", "static", {
|
||||||
|
$propdoc: {
|
||||||
|
static: "[boolean] whether this method is static (classes only)",
|
||||||
|
},
|
||||||
$documentation: "An ES6 concise method inside an object or class"
|
$documentation: "An ES6 concise method inside an object or class"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
@@ -947,11 +950,17 @@ var AST_ObjectSymbol = DEFNODE("ObjectSymbol", "symbol", {
|
|||||||
}
|
}
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
|
var AST_ObjectSetter = DEFNODE("ObjectSetter", "static", {
|
||||||
|
$propdoc: {
|
||||||
|
static: "[boolean] whether this is a static setter (classes only)"
|
||||||
|
},
|
||||||
$documentation: "An object setter property",
|
$documentation: "An object setter property",
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ObjectGetter = DEFNODE("ObjectGetter", null, {
|
var AST_ObjectGetter = DEFNODE("ObjectGetter", "static", {
|
||||||
|
$propdoc: {
|
||||||
|
static: "[boolean] whether this is a static getter (classes only)"
|
||||||
|
},
|
||||||
$documentation: "An object getter property",
|
$documentation: "An object getter property",
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
|
|||||||
@@ -775,9 +775,11 @@ function OutputStream(options) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
if (!nokeyword) {
|
if (!nokeyword) {
|
||||||
output.print("function");
|
output.print("function");
|
||||||
|
if (self.name) {
|
||||||
|
output.space();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (self.name) {
|
if (self.name) {
|
||||||
output.space();
|
|
||||||
self.name.print(output);
|
self.name.print(output);
|
||||||
}
|
}
|
||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
@@ -839,6 +841,10 @@ function OutputStream(options) {
|
|||||||
if (needs_parens) { output.print(")") }
|
if (needs_parens) { output.print(")") }
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ConciseMethod, function(self, output){
|
DEFPRINT(AST_ConciseMethod, function(self, output){
|
||||||
|
if (self.static) {
|
||||||
|
output.print("static");
|
||||||
|
output.space();
|
||||||
|
}
|
||||||
self._do_print(output, true /* do not print "function" */);
|
self._do_print(output, true /* do not print "function" */);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1238,12 +1244,20 @@ function OutputStream(options) {
|
|||||||
self.value.print(output);
|
self.value.print(output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ObjectSetter, function(self, output){
|
DEFPRINT(AST_ObjectSetter, function(self, output){
|
||||||
|
if (self.static) {
|
||||||
|
output.print("static");
|
||||||
|
output.space();
|
||||||
|
}
|
||||||
output.print("set");
|
output.print("set");
|
||||||
output.space();
|
output.space();
|
||||||
self.key.print(output);
|
self.key.print(output);
|
||||||
self.value._do_print(output, true);
|
self.value._do_print(output, true);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ObjectGetter, function(self, output){
|
DEFPRINT(AST_ObjectGetter, function(self, output){
|
||||||
|
if (self.static) {
|
||||||
|
output.print("static");
|
||||||
|
output.space();
|
||||||
|
}
|
||||||
output.print("get");
|
output.print("get");
|
||||||
output.space();
|
output.space();
|
||||||
self.key.print(output);
|
self.key.print(output);
|
||||||
|
|||||||
@@ -1533,9 +1533,16 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function concise_method_or_getset(name, start) {
|
function concise_method_or_getset(name, start) {
|
||||||
|
var is_static = false;
|
||||||
|
if (name === "static" && !is("punc", "(")) {
|
||||||
|
is_static = true;
|
||||||
|
name = S.token.value;
|
||||||
|
next();
|
||||||
|
}
|
||||||
if (is("punc", "(")) {
|
if (is("punc", "(")) {
|
||||||
return new AST_ConciseMethod({
|
return new AST_ConciseMethod({
|
||||||
start : start,
|
start : start,
|
||||||
|
static : is_static,
|
||||||
name : new AST_SymbolMethod({ name: name }),
|
name : new AST_SymbolMethod({ name: name }),
|
||||||
argnames : params_or_seq_().as_params(croak),
|
argnames : params_or_seq_().as_params(croak),
|
||||||
body : _function_body(true),
|
body : _function_body(true),
|
||||||
@@ -1545,6 +1552,7 @@ function parse($TEXT, options) {
|
|||||||
if (name == "get") {
|
if (name == "get") {
|
||||||
return new AST_ObjectGetter({
|
return new AST_ObjectGetter({
|
||||||
start : start,
|
start : start,
|
||||||
|
static: is_static,
|
||||||
key : as_atom_node(),
|
key : as_atom_node(),
|
||||||
value : function_(AST_Accessor),
|
value : function_(AST_Accessor),
|
||||||
end : prev()
|
end : prev()
|
||||||
@@ -1553,6 +1561,7 @@ function parse($TEXT, options) {
|
|||||||
if (name == "set") {
|
if (name == "set") {
|
||||||
return new AST_ObjectSetter({
|
return new AST_ObjectSetter({
|
||||||
start : start,
|
start : start,
|
||||||
|
static: is_static,
|
||||||
key : as_atom_node(),
|
key : as_atom_node(),
|
||||||
value : function_(AST_Accessor),
|
value : function_(AST_Accessor),
|
||||||
end : prev()
|
end : prev()
|
||||||
|
|||||||
@@ -200,6 +200,20 @@ classes: {
|
|||||||
expect_exact: "class SomeClass{constructor(){}foo(){}}class NoSemi{constructor(...args){}foo(){}}class ChildClass extends SomeClass{}var asExpression=class AsExpression{};var nameless=class{};"
|
expect_exact: "class SomeClass{constructor(){}foo(){}}class NoSemi{constructor(...args){}foo(){}}class ChildClass extends SomeClass{}var asExpression=class AsExpression{};var nameless=class{};"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class_statics: {
|
||||||
|
input: {
|
||||||
|
x = class {
|
||||||
|
static staticMethod() {}
|
||||||
|
static get foo() {}
|
||||||
|
static set bar() {}
|
||||||
|
static() { /* "static" can be a method name! */ }
|
||||||
|
get() { /* "get" can be a method name! */ }
|
||||||
|
set() { /* "set" can be a method name! */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "x=class{static staticMethod(){}static get foo(){}static set bar(){}static(){}get(){}set(){}};"
|
||||||
|
}
|
||||||
|
|
||||||
number_literals: {
|
number_literals: {
|
||||||
input: {
|
input: {
|
||||||
0b1001;
|
0b1001;
|
||||||
|
|||||||
Reference in New Issue
Block a user