start concise methods
This commit is contained in:
committed by
Richard van Velzen
parent
2babe737e0
commit
0d8dea9538
@@ -473,6 +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, {
|
||||||
|
$documentation: "An ES6 concise method inside an object or class"
|
||||||
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Defun = DEFNODE("Defun", null, {
|
var AST_Defun = DEFNODE("Defun", null, {
|
||||||
$documentation: "A function definition"
|
$documentation: "A function definition"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|||||||
@@ -832,6 +832,9 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
if (needs_parens) { output.print(")") }
|
if (needs_parens) { output.print(")") }
|
||||||
});
|
});
|
||||||
|
DEFPRINT(AST_ConciseMethod, function(self, output){
|
||||||
|
self._do_print(output, true /* do not print "function" */);
|
||||||
|
});
|
||||||
|
|
||||||
/* -----[ exits ]----- */
|
/* -----[ exits ]----- */
|
||||||
AST_Exit.DEFMETHOD("_do_print", function(output, kind){
|
AST_Exit.DEFMETHOD("_do_print", function(output, kind){
|
||||||
|
|||||||
10
lib/parse.js
10
lib/parse.js
@@ -1446,6 +1446,16 @@ function parse($TEXT, options) {
|
|||||||
var type = start.type;
|
var type = start.type;
|
||||||
var name = as_property_name();
|
var name = as_property_name();
|
||||||
if (type == "name" && !is("punc", ":")) {
|
if (type == "name" && !is("punc", ":")) {
|
||||||
|
if (is("punc", "(")) {
|
||||||
|
a.push(new AST_ConciseMethod({
|
||||||
|
start : start,
|
||||||
|
name : new AST_Symbol({ name: name }), // TODO what symbol is this really?
|
||||||
|
argnames : params_or_seq_().as_params(croak),
|
||||||
|
body : _function_body(true),
|
||||||
|
end : prev()
|
||||||
|
}))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (name == "get") {
|
if (name == "get") {
|
||||||
a.push(new AST_ObjectGetter({
|
a.push(new AST_ObjectGetter({
|
||||||
start : start,
|
start : start,
|
||||||
|
|||||||
@@ -132,6 +132,22 @@ destructuring_arguments: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
concise_methods: {
|
||||||
|
input: {
|
||||||
|
x = {
|
||||||
|
foo(a, b) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y = {
|
||||||
|
foo([{a}]) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "x={foo(a,b){return x}};y={foo([{a}]){return a}};"
|
||||||
|
}
|
||||||
|
|
||||||
number_literals: {
|
number_literals: {
|
||||||
input: {
|
input: {
|
||||||
0b1001;
|
0b1001;
|
||||||
|
|||||||
Reference in New Issue
Block a user