diff --git a/.changeset/lovely-seahorses-remember.md b/.changeset/lovely-seahorses-remember.md new file mode 100644 index 0000000000..256b9553d9 --- /dev/null +++ b/.changeset/lovely-seahorses-remember.md @@ -0,0 +1,8 @@ +--- +"@marko/babel-utils": patch +"@marko/compiler": patch +"marko": patch +"@marko/translator-default": patch +--- + +Expose meta data about which child Marko templates were analyzed for a given compilation. diff --git a/packages/babel-utils/src/tags.js b/packages/babel-utils/src/tags.js index 229146ac7f..d367efd671 100644 --- a/packages/babel-utils/src/tags.js +++ b/packages/babel-utils/src/tags.js @@ -236,6 +236,14 @@ export function loadFileForTag(tag) { const filename = def && def.template; if (filename) { + const markoMeta = file.metadata.marko; + const { analyzedTags } = markoMeta; + if (analyzedTags) { + analyzedTags.push(filename); + } else { + markoMeta.analyzedTags = [filename]; + } + return file.___getMarkoFile( fs.readFileSync(filename).toString("utf-8"), createNewFileOpts(file.opts, filename), @@ -253,6 +261,14 @@ export function loadFileForImport(file, request) { relativeRequest[0] === "." ? resolve(file.opts.filename, "..", relativeRequest) : resolveFrom(dirname(file.opts.filename), relativeRequest); + const markoMeta = file.metadata.marko; + const { analyzedTags } = markoMeta; + if (analyzedTags) { + analyzedTags.push(filename); + } else { + markoMeta.analyzedTags = [filename]; + } + return file.___getMarkoFile( fs.readFileSync(filename).toString("utf-8"), createNewFileOpts(file.opts, filename), diff --git a/packages/compiler/index.d.ts b/packages/compiler/index.d.ts index d4224cc2bd..ebf8c301f1 100644 --- a/packages/compiler/index.d.ts +++ b/packages/compiler/index.d.ts @@ -26,6 +26,7 @@ export interface MarkoMeta { watchFiles: string[]; tags?: string[]; deps: Array; + analyzedTags?: [string, ...string[]]; diagnostics: Diagnostic[]; } diff --git a/packages/compiler/src/babel-plugin/index.js b/packages/compiler/src/babel-plugin/index.js index 7d35c7ddc5..8fc749f365 100644 --- a/packages/compiler/src/babel-plugin/index.js +++ b/packages/compiler/src/babel-plugin/index.js @@ -396,4 +396,7 @@ function isMarkoOutput(output) { function finalizeMeta(meta) { meta.watchFiles = [...new Set(meta.watchFiles)]; + if (meta.analyzedTags) { + meta.analyzedTags = [...new Set(meta.analyzedTags)]; + } }