mancha
Version:
Javscript HTML rendering engine
119 lines • 2.42 kB
JavaScript
/*
* @license
* Portions Copyright (c) 2013, the Dart project authors.
*/
export class DefaultAstFactory {
empty() {
return { type: "Empty" };
}
// TODO(justinfagnani): just use a JS literal?
literal(value) {
return {
type: "Literal",
value,
};
}
id(value) {
return {
type: "ID",
value,
};
}
unary(operator, child) {
return {
type: "Unary",
operator,
child,
};
}
binary(left, operator, right) {
return {
type: "Binary",
operator,
left,
right,
};
}
getter(receiver, name, optional) {
return {
type: "Getter",
receiver,
name,
optional,
};
}
invoke(receiver, method, args, optional) {
// TODO(justinfagnani): do this assertion in the parser
if (args === undefined) {
throw new Error("args");
}
return {
type: "Invoke",
receiver,
method,
arguments: args,
optional,
};
}
paren(child) {
return {
type: "Paren",
child,
};
}
index(receiver, argument, optional) {
return {
type: "Index",
receiver,
argument,
optional,
};
}
ternary(condition, trueExpr, falseExpr) {
return {
type: "Ternary",
condition,
trueExpr,
falseExpr,
};
}
map(properties) {
return {
type: "Map",
properties,
};
}
list(items) {
return {
type: "List",
items,
};
}
property(key, value) {
return {
type: "Property",
key,
value,
};
}
arrowFunction(params, body) {
return {
type: "ArrowFunction",
params,
body,
};
}
spreadProperty(expression) {
return {
type: "SpreadProperty",
expression,
};
}
spreadElement(expression) {
return {
type: "SpreadElement",
expression,
};
}
}
//# sourceMappingURL=ast_factory.js.map