Skip to content

Commit

Permalink
pushed export keyword to inside of lexical_declaraction ast node
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Dec 9, 2024
1 parent a5ff43d commit 4a288bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
36 changes: 23 additions & 13 deletions src/expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,32 @@ function extract_lexical_declaration_bindings({
syntax_error(ls, `expected a variable declaration; found ${ls.t.tag}`);
}
}

function handle_let_or_const(loc: Loc) {
switch (loc.t.content) {
case "const":
case "let":
return go_right(
loc,
(loc) => get_vars(loc, lexical, context, counter),
(loc) => syntax_error(loc, "no bindings after keyword"),
);
default:
syntax_error(loc, "expected keyword const or let");
}
}

return go_down(
loc,
(loc) => {
if (loc.t.type === "atom") {
if (loc.t.tag === "other" && (loc.t.content === "const" || loc.t.content === "let")) {
return go_right(
loc,
(loc) => get_vars(loc, lexical, context, counter),
(loc) => syntax_error(loc, "no bindings after keyword"),
);
} else {
throw new Error(`HERE? ${loc.t.type}:${loc.t.tag}`);
}
} else {
syntax_error(loc, "expected keyword const or let");
switch (loc.t.content) {
case "const":
case "let":
return handle_let_or_const(loc);
case "export":
return go_right(loc, handle_let_or_const, syntax_error);
default:
syntax_error(loc, "expected keyword const or let");
}
},
syntax_error,
Expand Down Expand Up @@ -327,7 +338,6 @@ const list_handlers_table: { [tag in list_tag]: "descend" | "stop" | "todo" } =
ERROR: "stop",
lexical_declaration: "stop",
variable_declarator: "stop",
export_statement: "descend",
export_specifier: "todo",
export_clause: "todo",
export_declaration: "todo",
Expand Down
8 changes: 5 additions & 3 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ function absurdly(node: TS.Node, src: TS.SourceFile): AST {
ls[2].content === ";"
) {
return {
type: "list",
tag: "export_statement",
content: [ls[0].content[0], [ls[1], [ls[2], null]]],
...ls[1], // lexical_declaration
content: [
ls[0].content[0], // export keyword
llappend(ls[1].content, [ls[2], null]),
],
};
} else {
return { type: "list", tag: "ERROR", content };
Expand Down
1 change: 0 additions & 1 deletion src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type list_tag =
| "program"
| "lexical_declaration"
| "variable_declarator"
| "export_statement"
| "export_specifier"
| "export_declaration"
| "export_clause"
Expand Down

0 comments on commit 4a288bf

Please sign in to comment.