Skip to content

Commit 64548d1

Browse files
committed
Document transform hook timing for parameter decorators
1 parent 932cb9e commit 64548d1

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

cli/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ export abstract class Transform {
276276
/** Called when parsing is complete, before a program is instantiated from the AST. */
277277
afterParse?(parser: Parser): void | Promise<void>;
278278

279-
/** Called after the program is instantiated. */
279+
/**
280+
* Called after the program is instantiated and before compilation-time validation runs.
281+
* This is the last hook where transforms can rewrite preserved AST-only syntax before it is rejected.
282+
*/
280283
afterInitialize?(program: Program): void | Promise<void>;
281284

282285
/** Called when compilation is complete, before the module is being validated. */

cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ export async function main(argv, options) {
718718
stats.initializeTime += stats.end(begin);
719719
}
720720

721-
// Call afterInitialize transform hook
721+
// Call afterInitialize transform hook, the last AST rewrite point before compilation-time validation.
722722
{
723723
let error = await applyTransform("afterInitialize", program);
724724
if (error) return prepareResult(error);

src/index-wasm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export function getDependee(program: Program, file: string): string | null {
347347

348348
// Compiler
349349

350-
/** Initializes the program pre-emptively for transform hooks. */
350+
/** Initializes the program pre-emptively so `afterInitialize` transforms can rewrite the AST before compilation. */
351351
export function initializeProgram(program: Program): void {
352352
program.initialize();
353353
}

tests/transform/cjs/remove-parameter-decorators.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Example transform proving that preserved parameter decorators can be stripped
2+
// during afterInitialize before compilation rejects them.
13
console.log("CommonJS parameter decorator removal transform loaded");
24

35
const NodeKind = {

tests/transform/remove-parameter-decorators.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Example transform proving that preserved parameter decorators can be stripped
2+
// during afterInitialize before compilation rejects them.
13
console.log("Parameter decorator removal transform loaded");
24

35
const NodeKind = {

0 commit comments

Comments
 (0)