futurescript
Version:
A functional style, but highly readable language that compiles to JavaScript.
57 lines (50 loc) • 1.77 kB
JavaScript
import * as $lex from "./lex.mjs";
import * as $node from "./node.mjs";
import * as $base from "./expression-base.mjs";
import * as $pattern from "./pattern.mjs";
import * as $print from "./print.mjs";
import {JsBuilder as J} from "./js-builder.mjs";
export class AsExpression extends $base.Expression {
// `assignee` can be an assignee, or a `BracketAssignees` instance.
constructor(value, assignee) {
super();
this.value = value;
this.assignee = assignee;
}
static patternsAndCaptures() {
return [
[[$pattern.tokensExcept([$lex.Import]), $lex.As, $pattern.tokens], [0, 2]]
];
}
static applyMatch(match, lex) {
lex.part(match[1]).addStyle(16);
return new this(
this.build(lex.part(match[0])),
$node.buildAssignee(lex.part(match[1]), false, false)
);
}
bareCompile() {
return [$node.compileAssignee(this.assignee), "=", this.value.compile()];
}
}
export class IfvoidExpression extends $base.BinaryExpression {
bareCompile() {
this.getRoot().predefinedLib.ref = true;
return [
"(ref_" + $node.antiConflictString + "=", this.x.compile(), ")===undefined?",
this.y.compile(), ":ref_" + $node.antiConflictString
];
}
}
IfvoidExpression.sign = $lex.Ifvoid;
export class IfnullExpression extends $base.BinaryExpression {
bareCompile() {
this.getRoot().predefinedLib.ref = true;
return [
"(ref_" + $node.antiConflictString + "=", this.x.compile(), ")===undefined||ref_" +
$node.antiConflictString + "===null?",
this.y.compile(), ":ref_" + $node.antiConflictString
];
}
}
IfnullExpression.sign = $lex.Ifnull;