Skip to content

Commit a4563b1

Browse files
committed
Add write file and baseDir to transform
Also add error handling for transformers
1 parent 4a25bfa commit a4563b1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cli/asc.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ exports.main = function main(argv, options, callback) {
224224
}
225225
function applyTransform(name, ...args) {
226226
transforms.forEach(transform => {
227-
if (typeof transform[name] === "function") transform[name](...args);
227+
try {
228+
if (typeof transform[name] === "function") transform[name](...args);
229+
} catch (e) {
230+
callback(e);
231+
}
228232
});
229233
}
230234

@@ -426,7 +430,7 @@ exports.main = function main(argv, options, callback) {
426430
}
427431

428432
// Call afterParse transform hook
429-
applyTransform("afterParse", parser);
433+
applyTransform("afterParse", parser, writeFile, baseDir);
430434

431435
// Parse additional files, if any
432436
{

cli/transform.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import { Parser } from "../src/parser";
77

8+
declare function writeFile(name: string, contents: string | Uint8Array, baseDir: string): void;
89
export interface Transform {
910
/** Called when parsing is complete, before a program is instantiated from the AST. */
10-
afterParse(parser: Parser): void;
11+
afterParse(parser: Parser, writer?: typeof writeFile, baseDir?: string): void;
1112
}

0 commit comments

Comments
 (0)