Skip to content

Commit

Permalink
Add ConditionalExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
qti3e committed Aug 13, 2019
1 parent a8276a5 commit 488073f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 1 addition & 3 deletions jsc/src/play.ts
Expand Up @@ -11,9 +11,7 @@ import { dump } from "./dump";

function main() {
const source = `
do {
x++;
} while (true);
const x = true ? 1 : 0;
`;

const context = new Compiler();
Expand Down
13 changes: 12 additions & 1 deletion jsc/src/visitor.ts
Expand Up @@ -427,7 +427,14 @@ export function visit(writer: Writer, node: estree.Node): void {
break;
}

case "EmptyStatement": {
case "ConditionalExpression": {
visit(writer, node.test);
const jmp = writer.jmp(ByteCode.JmpFalsePop);
visit(writer, node.consequent);
const jmp2 = writer.jmp(ByteCode.Jmp);
jmp.next();
visit(writer, node.alternate);
jmp2.next();
break;
}

Expand All @@ -440,6 +447,10 @@ export function visit(writer: Writer, node: estree.Node): void {
break;
}

case "EmptyStatement": {
break;
}

default:
// TODO(qti3e)
writer.write(ByteCode.TODO);
Expand Down

0 comments on commit 488073f

Please sign in to comment.