@analogjs/vite-plugin-angular 3.0.0-beta.6 → 3.0.0-beta.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +3 -3
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
  3. package/ngp/LICENSE +21 -0
  4. package/ngp/api.mjs +46806 -0
  5. package/ngp/build.json +4 -0
  6. package/ngp/ng_analyze.cjs +601 -0
  7. package/ngp/ng_analyze_bg.wasm +0 -0
  8. package/package.json +5 -2
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +4 -3
  11. package/src/index.js.map +1 -1
  12. package/src/lib/analog-plugin-interop.js +2 -3
  13. package/src/lib/angular-build-context.d.ts +215 -0
  14. package/src/lib/angular-build-context.js +360 -0
  15. package/src/lib/angular-build-context.js.map +1 -0
  16. package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
  17. package/src/lib/angular-build-optimizer-plugin.js +25 -11
  18. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  19. package/src/lib/angular-jit-plugin.d.ts +5 -3
  20. package/src/lib/angular-jit-plugin.js +16 -9
  21. package/src/lib/angular-jit-plugin.js.map +1 -1
  22. package/src/lib/angular-vite-plugin.d.ts +6 -109
  23. package/src/lib/angular-vite-plugin.js +9 -1251
  24. package/src/lib/angular-vite-plugin.js.map +1 -1
  25. package/src/lib/angular-vitest-plugin.d.ts +3 -2
  26. package/src/lib/angular-vitest-plugin.js +7 -5
  27. package/src/lib/angular-vitest-plugin.js.map +1 -1
  28. package/src/lib/companion-plugins.d.ts +7 -0
  29. package/src/lib/companion-plugins.js +37 -0
  30. package/src/lib/companion-plugins.js.map +1 -0
  31. package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
  32. package/src/lib/compilation-api/compilation-api-plugin.js +156 -285
  33. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  34. package/src/lib/compilation-api/index.js +1 -2
  35. package/src/lib/compiler/angular-version.js +0 -1
  36. package/src/lib/compiler/class-field-lowering.js +1 -2
  37. package/src/lib/compiler/compile.d.ts +1 -1
  38. package/src/lib/compiler/compile.js +224 -151
  39. package/src/lib/compiler/compile.js.map +1 -1
  40. package/src/lib/compiler/constants.js +1 -2
  41. package/src/lib/compiler/debug.js +1 -2
  42. package/src/lib/compiler/defer.d.ts +2 -3
  43. package/src/lib/compiler/defer.js +13 -16
  44. package/src/lib/compiler/defer.js.map +1 -1
  45. package/src/lib/compiler/dts-reader.d.ts +6 -1
  46. package/src/lib/compiler/dts-reader.js +20 -12
  47. package/src/lib/compiler/dts-reader.js.map +1 -1
  48. package/src/lib/compiler/hmr.d.ts +4 -0
  49. package/src/lib/compiler/hmr.js +8 -4
  50. package/src/lib/compiler/hmr.js.map +1 -1
  51. package/src/lib/compiler/index.d.ts +2 -2
  52. package/src/lib/compiler/index.js +6 -6
  53. package/src/lib/compiler/jit-metadata.js +1 -2
  54. package/src/lib/compiler/jit-transform.js +37 -15
  55. package/src/lib/compiler/jit-transform.js.map +1 -1
  56. package/src/lib/compiler/js-emitter.d.ts +0 -3
  57. package/src/lib/compiler/js-emitter.js +4 -23
  58. package/src/lib/compiler/js-emitter.js.map +1 -1
  59. package/src/lib/compiler/metadata.js +2 -3
  60. package/src/lib/compiler/registry.d.ts +7 -1
  61. package/src/lib/compiler/registry.js +24 -5
  62. package/src/lib/compiler/registry.js.map +1 -1
  63. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  64. package/src/lib/compiler/resource-inliner.js +11 -20
  65. package/src/lib/compiler/resource-inliner.js.map +1 -1
  66. package/src/lib/compiler/style-ast.d.ts +22 -1
  67. package/src/lib/compiler/style-ast.js +37 -20
  68. package/src/lib/compiler/style-ast.js.map +1 -1
  69. package/src/lib/compiler/type-elision.d.ts +4 -3
  70. package/src/lib/compiler/type-elision.js +11 -13
  71. package/src/lib/compiler/type-elision.js.map +1 -1
  72. package/src/lib/compiler/utils.d.ts +9 -7
  73. package/src/lib/compiler/utils.js +50 -11
  74. package/src/lib/compiler/utils.js.map +1 -1
  75. package/src/lib/compiler-plugin.js +1 -2
  76. package/src/lib/component-resolvers.js +1 -2
  77. package/src/lib/component-scanner.d.ts +74 -0
  78. package/src/lib/component-scanner.js +177 -0
  79. package/src/lib/component-scanner.js.map +1 -0
  80. package/src/lib/component-styles-plugin.d.ts +52 -0
  81. package/src/lib/component-styles-plugin.js +352 -0
  82. package/src/lib/component-styles-plugin.js.map +1 -0
  83. package/src/lib/compose-angular-plugins.d.ts +12 -0
  84. package/src/lib/compose-angular-plugins.js +30 -0
  85. package/src/lib/compose-angular-plugins.js.map +1 -0
  86. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  87. package/src/lib/dev-server-mode-plugin.js +22 -0
  88. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  89. package/src/lib/encapsulation-plugin.js +1 -2
  90. package/src/lib/fast-compile-api.d.ts +62 -0
  91. package/src/lib/fast-compile-api.js +11 -0
  92. package/src/lib/fast-compile-api.js.map +1 -0
  93. package/src/lib/fast-compile-plugin.d.ts +6 -1
  94. package/src/lib/fast-compile-plugin.js +169 -110
  95. package/src/lib/fast-compile-plugin.js.map +1 -1
  96. package/src/lib/host.d.ts +3 -0
  97. package/src/lib/host.js +5 -4
  98. package/src/lib/host.js.map +1 -1
  99. package/src/lib/hot-update-batch.js +1 -2
  100. package/src/lib/live-reload-plugin.d.ts +6 -3
  101. package/src/lib/live-reload-plugin.js +14 -8
  102. package/src/lib/live-reload-plugin.js.map +1 -1
  103. package/src/lib/ngp-compile-api.d.ts +55 -0
  104. package/src/lib/ngp-compile-api.js +11 -0
  105. package/src/lib/ngp-compile-api.js.map +1 -0
  106. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  107. package/src/lib/ngp-compile-plugin.js +672 -0
  108. package/src/lib/ngp-compile-plugin.js.map +1 -0
  109. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  110. package/src/lib/ngtsc-compile-plugin.js +776 -0
  111. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  112. package/src/lib/nx-folder-plugin.d.ts +6 -5
  113. package/src/lib/nx-folder-plugin.js +13 -9
  114. package/src/lib/nx-folder-plugin.js.map +1 -1
  115. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  116. package/src/lib/plugins/file-replacements.plugin.js +2 -2
  117. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  118. package/src/lib/router-plugin.d.ts +5 -1
  119. package/src/lib/router-plugin.js +14 -6
  120. package/src/lib/router-plugin.js.map +1 -1
  121. package/src/lib/style-preprocessor.js +1 -2
  122. package/src/lib/stylesheet-registry.js +1 -2
  123. package/src/lib/stylesheet-registry.js.map +1 -1
  124. package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
  125. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  126. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
  127. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  128. package/src/lib/utils/compilation-shared.js +3 -4
  129. package/src/lib/utils/css-extension-resolver.js +1 -2
  130. package/src/lib/utils/css-preprocessor-workers.js +1 -2
  131. package/src/lib/utils/debug-harness.js +1 -2
  132. package/src/lib/utils/debug-log-file.js +1 -2
  133. package/src/lib/utils/debug.js +1 -2
  134. package/src/lib/utils/devkit.js +2 -3
  135. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  136. package/src/lib/utils/hmr-component-updates.js +86 -0
  137. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  138. package/src/lib/utils/jit-inline-styles.js +1 -2
  139. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  140. package/src/lib/utils/lsp-type-checker.js +532 -0
  141. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  142. package/src/lib/utils/ngp-host-fs.d.ts +43 -0
  143. package/src/lib/utils/ngp-host-fs.js +128 -0
  144. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  145. package/src/lib/utils/plugin-config.d.ts +15 -8
  146. package/src/lib/utils/plugin-config.js +19 -7
  147. package/src/lib/utils/plugin-config.js.map +1 -1
  148. package/src/lib/utils/rolldown.js +1 -2
  149. package/src/lib/utils/safe-module-paths.js +1 -2
  150. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  151. package/src/lib/utils/stylesheet-warning.js +10 -0
  152. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  153. package/src/lib/utils/transform-cache.js +1 -2
  154. package/src/lib/utils/transform-cache.js.map +1 -1
  155. package/src/lib/utils/tsconfig-resolver.js +2 -3
  156. package/src/lib/utils/virtual-ids.js +1 -2
  157. package/src/lib/utils/virtual-resources.js +1 -2
  158. package/src/lib/utils/virtual-resources.js.map +1 -1
  159. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  160. package/src/lib/virtual-modules-plugin.js +70 -15
  161. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"defer.js","names":[],"sources":["../../../../src/lib/compiler/defer.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport * as o from '@angular/compiler';\nimport { ComponentRegistry } from './registry.js';\n\n/** Recursively collect all DeferredBlock nodes from a template AST. */\nexport function collectDeferBlocks(nodes: any[]): any[] {\n const result: any[] = [];\n function walk(node: any) {\n if (!node) return;\n if (node.constructor?.name === 'DeferredBlock') {\n result.push(node);\n }\n // Walk all possible child structures across block types:\n // Element/Template: children\n // IfBlock: branches (each has children)\n // ForLoopBlock: children, empty (has children)\n // SwitchBlock: groups (Angular v21+, each is a SwitchBlockCaseGroup with\n // children) or cases (Angular v18-v20, each has children)\n // DeferredBlock: children, placeholder/loading/error (each has children)\n if (Array.isArray(node.children)) node.children.forEach(walk);\n if (Array.isArray(node.branches)) node.branches.forEach(walk);\n if (Array.isArray(node.errorBlocks)) node.errorBlocks.forEach(walk);\n if (Array.isArray(node.groups)) node.groups.forEach(walk);\n if (Array.isArray(node.cases)) node.cases.forEach(walk);\n if (node.empty?.children) node.empty.children.forEach(walk);\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n }\n nodes.forEach(walk);\n return result;\n}\n\n/**\n * Collect element tag names from template AST nodes recursively.\n *\n * When `excludeDeferBlocks` is true, the deferred body of any DeferredBlock is\n * skipped — its children are treated as deferred, not eager. The fallback\n * subtrees (`@placeholder`, `@loading`, `@error`) are still walked: Angular\n * treats them as *eager* dependencies because the placeholder must render in\n * the main bundle before the defer trigger fires. A component shared between\n * the defer body and a fallback block must stay in static imports, otherwise\n * the fallback render breaks.\n */\nexport function collectElementNames(\n nodes: any[],\n excludeDeferBlocks = false,\n): Set<string> {\n const result = new Set<string>();\n function walk(node: any) {\n if (!node) return;\n if (excludeDeferBlocks && node.constructor?.name === 'DeferredBlock') {\n // Skip the deferred body but keep walking the fallback subtrees so\n // components referenced in `@placeholder` / `@loading` / `@error`\n // stay in the eager set.\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n return;\n }\n if (node.constructor?.name === 'Element') result.add(node.name);\n if (Array.isArray(node.children)) node.children.forEach(walk);\n if (Array.isArray(node.branches)) node.branches.forEach(walk);\n if (Array.isArray(node.errorBlocks)) node.errorBlocks.forEach(walk);\n if (Array.isArray(node.groups)) node.groups.forEach(walk);\n if (Array.isArray(node.cases)) node.cases.forEach(walk);\n if (node.empty?.children) node.empty.children.forEach(walk);\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n }\n nodes.forEach(walk);\n return result;\n}\n\n/** Information about how a class is imported. */\nexport interface ImportInfo {\n /** Module path from the import statement. */\n path: string;\n /** Whether the class was imported as a default import (`import X from`). */\n isDefault: boolean;\n /**\n * Original exported name on the source module's namespace. For\n * `import { HeavyWidget as Widget } from './heavy'`, the local\n * binding is `Widget` but the namespace exposes `HeavyWidget` —\n * `await import('./heavy')` returns `{ HeavyWidget }`, not\n * `{ Widget }`. Defer dependency emit must use the exported name,\n * not the local alias, or the lookup resolves to `undefined` at\n * runtime.\n */\n exportName: string;\n}\n\n/**\n * Build import info map: localName → { path, isDefault, exportName }\n * from source file imports. Tracks default vs named imports plus the\n * original exported name so the defer dependency generator can emit\n * `import('./p').then(m => m.default)` for default imports and\n * `import('./p').then(m => m.OriginalExportName)` for aliased named\n * imports.\n */\nexport function buildImportMap(sf: ts.SourceFile): Map<string, ImportInfo> {\n const result = new Map<string, ImportInfo>();\n for (const stmt of sf.statements) {\n if (!ts.isImportDeclaration(stmt) || !stmt.importClause) continue;\n const path = (stmt.moduleSpecifier as ts.StringLiteral).text;\n const clause = stmt.importClause;\n if (clause.name) {\n result.set(clause.name.text, {\n path,\n isDefault: true,\n exportName: 'default',\n });\n }\n if (clause.namedBindings && ts.isNamedImports(clause.namedBindings)) {\n for (const el of clause.namedBindings.elements) {\n // `import { Foo as Bar }` → propertyName is `Foo`, name is `Bar`.\n // `import { Foo }` → propertyName is undefined.\n const exportName = el.propertyName?.text ?? el.name.text;\n const info: ImportInfo = { path, isDefault: false, exportName };\n // Key the map by BOTH the local binding and the original export\n // name. The defer-dep lookup uses the className from the\n // registry — which is always the original class name from the\n // source file (`HeavyWidget`), not the consumer's local alias\n // (`Widget`). Without the export-name key, aliased imports\n // would silently produce no defer dependency at all.\n result.set(el.name.text, info);\n if (exportName !== el.name.text) {\n result.set(exportName, info);\n }\n }\n }\n }\n return result;\n}\n\n/**\n * Build defer block dependency map with dynamic import() expressions.\n *\n * For each defer block, identifies which imported components are only used\n * inside defer blocks (not in the eager template), and generates dynamic\n * import expressions for lazy loading.\n *\n * Returns:\n * - blocks: Map<DeferredBlock, Expression | null> for compileComponentFromMetadata\n * - deferredImports: Set<string> of class names that should be removed from static imports\n */\nexport function buildDeferDependencyMap(\n parsedTemplate: any,\n sourceFile: ts.SourceFile,\n registry: ComponentRegistry | undefined,\n localSelectors: Map<string, string>,\n): { blocks: Map<any, any>; deferredImports: Set<string> } {\n const deferBlocks = collectDeferBlocks(parsedTemplate.nodes);\n if (deferBlocks.length === 0) {\n return { blocks: new Map(), deferredImports: new Set() };\n }\n\n const deferElements = new Set<string>();\n for (const block of deferBlocks) {\n const elements = collectElementNames(block.children || []);\n for (const el of elements) deferElements.add(el);\n }\n // Eager elements = elements reachable without crossing into a DeferredBlock.\n // Pass `excludeDeferBlocks` so a defer block nested inside @switch / @if /\n // @for is not unfolded into the eager set. Without this, a component used\n // only inside such a nested defer would be misclassified as eager and lose\n // its lazy-load dependency function.\n const eagerElements = collectElementNames(parsedTemplate.nodes, true);\n\n // Build selector → className map from registry + local selectors\n const selectorToClass = new Map<string, string>();\n if (registry) {\n for (const [className, entry] of registry) {\n if (entry.selector) selectorToClass.set(entry.selector, className);\n }\n }\n for (const [className, selector] of localSelectors) {\n selectorToClass.set(selector, className);\n }\n\n // Build className → importPath map\n const importMap = buildImportMap(sourceFile);\n\n // Find defer-only component class names\n const deferredImports = new Set<string>();\n const deferOnlyElements = new Set<string>();\n for (const el of deferElements) {\n if (!eagerElements.has(el)) deferOnlyElements.add(el);\n }\n\n for (const el of deferOnlyElements) {\n const className = selectorToClass.get(el);\n if (className && importMap.has(className)) {\n deferredImports.add(className);\n }\n }\n\n // Build the blocks map with dependency functions\n const blocks = new Map<any, any>();\n for (const block of deferBlocks) {\n const blockElements = collectElementNames(block.children || []);\n const blockDeps: any[] = [];\n // Within a single block, dedupe by `${path}#${symbolName}` so two\n // refs to the same component don't generate two import expressions.\n const seenInBlock = new Set<string>();\n\n for (const el of blockElements) {\n const className = selectorToClass.get(el);\n if (!className || !deferredImports.has(className)) continue;\n const info = importMap.get(className)!;\n // Use the original exported name (tracked by buildImportMap) so\n // aliased imports like `import { HeavyWidget as Widget }` resolve\n // to `m.HeavyWidget` instead of `m.Widget` (which would be\n // `undefined` on the module namespace).\n const symbolName = info.exportName;\n const key = `${info.path}#${symbolName}`;\n if (seenInBlock.has(key)) continue;\n seenInBlock.add(key);\n // import('./path').then(m => m.ClassName) — or `m.default` for\n // default imports. Without the `.then(...)` resolver Angular's\n // runtime gets a module namespace and can't find the class.\n // `FnParam` and the `variable()` helper aren't on the top-level\n // namespace; they live in the `outputAst` sub-namespace.\n const ast: any = (o as any).outputAst;\n const mVar = ast.variable('m');\n const innerFn = ast.arrowFn(\n [new ast.FnParam('m', ast.DYNAMIC_TYPE)],\n new o.ReadPropExpr(mVar, symbolName),\n );\n const importExpr = new o.InvokeFunctionExpr(\n new o.ReadPropExpr(\n new o.DynamicImportExpr(new o.LiteralExpr(info.path)),\n 'then',\n ),\n [innerFn],\n );\n blockDeps.push(new o.ArrowFunctionExpr([], importExpr));\n }\n\n if (blockDeps.length > 0) {\n // () => [import('./a').then(m => m.A), import('./b').then(m => m.default)]\n blocks.set(\n block,\n new o.ArrowFunctionExpr([], new o.LiteralArrayExpr(blockDeps)),\n );\n } else {\n blocks.set(block, null);\n }\n }\n\n return { blocks, deferredImports };\n}\n"],"mappings":";;;;AAKA,SAAgB,mBAAmB,OAAqB;CACtD,MAAM,SAAgB,CAAC;CACvB,SAAS,KAAK,MAAW;EACvB,IAAI,CAAC,MAAM;EACX,IAAI,KAAK,aAAa,SAAS,iBAC7B,OAAO,KAAK,IAAI;EASlB,IAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG,KAAK,SAAS,QAAQ,IAAI;EAC5D,IAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG,KAAK,SAAS,QAAQ,IAAI;EAC5D,IAAI,MAAM,QAAQ,KAAK,WAAW,GAAG,KAAK,YAAY,QAAQ,IAAI;EAClE,IAAI,MAAM,QAAQ,KAAK,MAAM,GAAG,KAAK,OAAO,QAAQ,IAAI;EACxD,IAAI,MAAM,QAAQ,KAAK,KAAK,GAAG,KAAK,MAAM,QAAQ,I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AE,kBAAkB,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC,GACpD,MACF,GACA,CAAC,OAAO,CACV;GACA,UAAU,KAAK,IAAI,EAAE,kBAAkB,CAAC,GAAG,UAAU,CAAC;EACxD;EAEA,IAAI,UAAU,SAAS,GAErB,OAAO,IACL,OACA,IAAI,EAAE,kBAAkB,CAAC,GAAG,IAAI,EAAE,iBAAiB,SAAS,CAAC,CAC/D;OAEA,OAAO,IAAI,OAAO,IAAI;CAE1B;CAEA,OAAO;EAAE;EAAQ;CAAgB;AACnC"}
1
+ {"version":3,"file":"defer.js","names":[],"sources":["../../../../src/lib/compiler/defer.ts"],"sourcesContent":["import * as o from '@angular/compiler';\nimport { ComponentRegistry } from './registry.js';\n\n/** Recursively collect all DeferredBlock nodes from a template AST. */\nexport function collectDeferBlocks(nodes: any[]): any[] {\n const result: any[] = [];\n function walk(node: any) {\n if (!node) return;\n if (node.constructor?.name === 'DeferredBlock') {\n result.push(node);\n }\n // Walk all possible child structures across block types:\n // Element/Template: children\n // IfBlock: branches (each has children)\n // ForLoopBlock: children, empty (has children)\n // SwitchBlock: groups (Angular v21+, each is a SwitchBlockCaseGroup with\n // children) or cases (Angular v18-v20, each has children)\n // DeferredBlock: children, placeholder/loading/error (each has children)\n if (Array.isArray(node.children)) node.children.forEach(walk);\n if (Array.isArray(node.branches)) node.branches.forEach(walk);\n if (Array.isArray(node.errorBlocks)) node.errorBlocks.forEach(walk);\n if (Array.isArray(node.groups)) node.groups.forEach(walk);\n if (Array.isArray(node.cases)) node.cases.forEach(walk);\n if (node.empty?.children) node.empty.children.forEach(walk);\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n }\n nodes.forEach(walk);\n return result;\n}\n\n/**\n * Collect element tag names from template AST nodes recursively.\n *\n * When `excludeDeferBlocks` is true, the deferred body of any DeferredBlock is\n * skipped — its children are treated as deferred, not eager. The fallback\n * subtrees (`@placeholder`, `@loading`, `@error`) are still walked: Angular\n * treats them as *eager* dependencies because the placeholder must render in\n * the main bundle before the defer trigger fires. A component shared between\n * the defer body and a fallback block must stay in static imports, otherwise\n * the fallback render breaks.\n */\nexport function collectElementNames(\n nodes: any[],\n excludeDeferBlocks = false,\n): Set<string> {\n const result = new Set<string>();\n function walk(node: any) {\n if (!node) return;\n if (excludeDeferBlocks && node.constructor?.name === 'DeferredBlock') {\n // Skip the deferred body but keep walking the fallback subtrees so\n // components referenced in `@placeholder` / `@loading` / `@error`\n // stay in the eager set.\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n return;\n }\n if (node.constructor?.name === 'Element') result.add(node.name);\n if (Array.isArray(node.children)) node.children.forEach(walk);\n if (Array.isArray(node.branches)) node.branches.forEach(walk);\n if (Array.isArray(node.errorBlocks)) node.errorBlocks.forEach(walk);\n if (Array.isArray(node.groups)) node.groups.forEach(walk);\n if (Array.isArray(node.cases)) node.cases.forEach(walk);\n if (node.empty?.children) node.empty.children.forEach(walk);\n if (node.placeholder?.children) node.placeholder.children.forEach(walk);\n if (node.loading?.children) node.loading.children.forEach(walk);\n if (node.error?.children) node.error.children.forEach(walk);\n }\n nodes.forEach(walk);\n return result;\n}\n\n/** Information about how a class is imported. */\nexport interface ImportInfo {\n /** Module path from the import statement. */\n path: string;\n /** Whether the class was imported as a default import (`import X from`). */\n isDefault: boolean;\n /**\n * Original exported name on the source module's namespace. For\n * `import { HeavyWidget as Widget } from './heavy'`, the local\n * binding is `Widget` but the namespace exposes `HeavyWidget` —\n * `await import('./heavy')` returns `{ HeavyWidget }`, not\n * `{ Widget }`. Defer dependency emit must use the exported name,\n * not the local alias, or the lookup resolves to `undefined` at\n * runtime.\n */\n exportName: string;\n}\n\n/**\n * Build import info map: localName → { path, isDefault, exportName }\n * from source file imports. Tracks default vs named imports plus the\n * original exported name so the defer dependency generator can emit\n * `import('./p').then(m => m.default)` for default imports and\n * `import('./p').then(m => m.OriginalExportName)` for aliased named\n * imports.\n */\nexport function buildImportMap(program: any): Map<string, ImportInfo> {\n const result = new Map<string, ImportInfo>();\n for (const stmt of program.body) {\n if (stmt.type !== 'ImportDeclaration') continue;\n const path: string = stmt.source.value;\n for (const spec of stmt.specifiers) {\n if (spec.type === 'ImportDefaultSpecifier') {\n result.set(spec.local.name, {\n path,\n isDefault: true,\n exportName: 'default',\n });\n } else if (spec.type === 'ImportSpecifier') {\n // `import { Foo as Bar }` → imported is `Foo`, local is `Bar`.\n const exportName: string = spec.imported.name ?? spec.imported.value;\n const info: ImportInfo = { path, isDefault: false, exportName };\n // Key the map by BOTH the local binding and the original export\n // name. The defer-dep lookup uses the className from the\n // registry — which is always the original class name from the\n // source file (`HeavyWidget`), not the consumer's local alias\n // (`Widget`). Without the export-name key, aliased imports\n // would silently produce no defer dependency at all.\n result.set(spec.local.name, info);\n if (exportName !== spec.local.name) {\n result.set(exportName, info);\n }\n }\n }\n }\n return result;\n}\n\n/**\n * Build defer block dependency map with dynamic import() expressions.\n *\n * For each defer block, identifies which imported components are only used\n * inside defer blocks (not in the eager template), and generates dynamic\n * import expressions for lazy loading.\n *\n * Returns:\n * - blocks: Map<DeferredBlock, Expression | null> for compileComponentFromMetadata\n * - deferredImports: Set<string> of class names that should be removed from static imports\n */\nexport function buildDeferDependencyMap(\n parsedTemplate: any,\n program: any,\n registry: ComponentRegistry | undefined,\n localSelectors: Map<string, string>,\n): { blocks: Map<any, any>; deferredImports: Set<string> } {\n const deferBlocks = collectDeferBlocks(parsedTemplate.nodes);\n if (deferBlocks.length === 0) {\n return { blocks: new Map(), deferredImports: new Set() };\n }\n\n const deferElements = new Set<string>();\n for (const block of deferBlocks) {\n const elements = collectElementNames(block.children || []);\n for (const el of elements) deferElements.add(el);\n }\n // Eager elements = elements reachable without crossing into a DeferredBlock.\n // Pass `excludeDeferBlocks` so a defer block nested inside @switch / @if /\n // @for is not unfolded into the eager set. Without this, a component used\n // only inside such a nested defer would be misclassified as eager and lose\n // its lazy-load dependency function.\n const eagerElements = collectElementNames(parsedTemplate.nodes, true);\n\n // Build selector → className map from registry + local selectors\n const selectorToClass = new Map<string, string>();\n if (registry) {\n for (const [className, entry] of registry) {\n if (entry.selector) selectorToClass.set(entry.selector, className);\n }\n }\n for (const [className, selector] of localSelectors) {\n selectorToClass.set(selector, className);\n }\n\n // Build className → importPath map\n const importMap = buildImportMap(program);\n\n // Find defer-only component class names\n const deferredImports = new Set<string>();\n const deferOnlyElements = new Set<string>();\n for (const el of deferElements) {\n if (!eagerElements.has(el)) deferOnlyElements.add(el);\n }\n\n for (const el of deferOnlyElements) {\n const className = selectorToClass.get(el);\n if (className && importMap.has(className)) {\n deferredImports.add(className);\n }\n }\n\n // Build the blocks map with dependency functions\n const blocks = new Map<any, any>();\n for (const block of deferBlocks) {\n const blockElements = collectElementNames(block.children || []);\n const blockDeps: any[] = [];\n // Within a single block, dedupe by `${path}#${symbolName}` so two\n // refs to the same component don't generate two import expressions.\n const seenInBlock = new Set<string>();\n\n for (const el of blockElements) {\n const className = selectorToClass.get(el);\n if (!className || !deferredImports.has(className)) continue;\n const info = importMap.get(className)!;\n // Use the original exported name (tracked by buildImportMap) so\n // aliased imports like `import { HeavyWidget as Widget }` resolve\n // to `m.HeavyWidget` instead of `m.Widget` (which would be\n // `undefined` on the module namespace).\n const symbolName = info.exportName;\n const key = `${info.path}#${symbolName}`;\n if (seenInBlock.has(key)) continue;\n seenInBlock.add(key);\n // import('./path').then(m => m.ClassName) — or `m.default` for\n // default imports. Without the `.then(...)` resolver Angular's\n // runtime gets a module namespace and can't find the class.\n // `FnParam` and the `variable()` helper aren't on the top-level\n // namespace; they live in the `outputAst` sub-namespace.\n const ast: any = (o as any).outputAst;\n const mVar = ast.variable('m');\n const innerFn = ast.arrowFn(\n [new ast.FnParam('m', ast.DYNAMIC_TYPE)],\n new o.ReadPropExpr(mVar, symbolName),\n );\n const importExpr = new o.InvokeFunctionExpr(\n new o.ReadPropExpr(\n new o.DynamicImportExpr(new o.LiteralExpr(info.path)),\n 'then',\n ),\n [innerFn],\n );\n // Angular's dependency resolver returns the import promises themselves.\n // A function in the array would be taken for an already-loaded class.\n blockDeps.push(importExpr);\n }\n\n if (blockDeps.length > 0) {\n // () => [import('./a').then(m => m.A), import('./b').then(m => m.default)]\n blocks.set(\n block,\n new o.ArrowFunctionExpr([], new o.LiteralArrayExpr(blockDeps)),\n );\n } else {\n blocks.set(block, null);\n }\n }\n\n return { blocks, deferredImports };\n}\n"],"mappings":";;;AAIA,SAAgB,mBAAmB,OAAqB;CACtD,MAAM,SAAgB,CAAC;CACvB,SAAS,KAAK,MAAW;EACvB,IAAI,CAAC,MAAM;EACX,IAAI,KAAK,aAAa,SAAS,iBAC7B,OAAO,KAAK,IAAI;EASlB,IAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG,KAAK,SAAS,QAAQ,IAAI;EAC5D,IAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG,KAAK,SAAS,QAAQ,IAAI;EAC5D,IAAI,MAAM,QAAQ,KAAK,WAAW,GAAG,KAAK,YAAY,QAAQ,IAAI;EAClE,IAAI,MAAM,QAAQ,KAAK,MAAM,GAAG,KAAK,OAAO,QAAQ,IAAI;EACxD,IAAI,MAAM,QAAQ,KAAK,KAAK,GAAG,KAAK,MAAM,QAAQ,IAAI;EACtD,IAAI,KAAK,OAAO,UAAU,KAAK,MAAM,SAAS,QAAQ,IAAI;EAC1D,IAAI,KAAK,aAAa,UAAU,KAAK,YAAY,SAAS,QAAQ,IAAI;EACtE,IAAI,KAAK,SAAS,UAAU,KAAK,QAAQ,SAAS,QAAQ,IAAI;EAC9D,IAAI,KAAK,OAAO,UAAU,KAAK,MAAM,SAAS,QAAQ,IAAI;CAC5D;CACA,MAAM,QAAQ,IAAI;CAClB,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,oBACd,OACA,qBAAqB,OACR;CACb,MAAM,yBAAS,I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EACxC,IAAI,aAAa,UAAU,IAAI,SAAS,GACtC,gBAAgB,IAAI,SAAS;CAEjC;CAGA,MAAM,yBAAS,IAAI,IAAc;CACjC,KAAK,MAAM,SAAS,aAAa;EAC/B,MAAM,gBAAgB,oBAAoB,MAAM,YAAY,CAAC,CAAC;EAC9D,MAAM,YAAmB,CAAC;EAG1B,MAAM,8BAAc,IAAI,IAAY;EAEpC,KAAK,MAAM,MAAM,eAAe;GAC9B,MAAM,YAAY,gBAAgB,IAAI,EAAE;GACxC,IAAI,CAAC,aAAa,CAAC,gBAAgB,IAAI,SAAS,GAAG;GACnD,MAAM,OAAO,UAAU,IAAI,SAAS;GAKpC,MAAM,aAAa,KAAK;GACxB,MAAM,MAAM,GAAG,KAAK,KAAK,GAAG;GAC5B,IAAI,YAAY,IAAI,GAAG,GAAG;GAC1B,YAAY,IAAI,GAAG;GAMnB,MAAM,MAAY,EAAU;GAC5B,MAAM,OAAO,IAAI,SAAS,GAAG;GAC7B,MAAM,UAAU,IAAI,QAClB,CAAC,IAAI,IAAI,QAAQ,KAAK,IAAI,YAAY,CAAC,GACvC,IAAI,EAAE,aAAa,MAAM,UAAU,CACrC;GACA,MAAM,aAAa,IAAI,EAAE,mBACvB,IAAI,EAAE,aACJ,IAAI,EAAE,kBAAkB,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC,GACpD,MACF,GACA,CAAC,OAAO,CACV;GAGA,UAAU,KAAK,UAAU;EAC3B;EAEA,IAAI,UAAU,SAAS,GAErB,OAAO,IACL,OACA,IAAI,EAAE,kBAAkB,CAAC,GAAG,IAAI,EAAE,iBAAiB,SAAS,CAAC,CAC/D;OAEA,OAAO,IAAI,OAAO,IAAI;CAE1B;CAEA,OAAO;EAAE;EAAQ;CAAgB;AACnC"}
@@ -1,4 +1,4 @@
1
- import { parseSync } from "oxc-parser";
1
+ import type { parseSync } from "oxc-parser";
2
2
  import { RegistryEntry } from "./registry.js";
3
3
  /**
4
4
  * Scan a single .d.ts file and extract Angular directive/component/pipe
@@ -35,6 +35,11 @@ export declare function collectImportedPackages(code: string, fileName: string,
35
35
  */
36
36
  export declare function collectRelativeReExports(code: string, fileName: string, program?: ReturnType<typeof parseSync>["program"]): string[];
37
37
  /**
38
+ * Parse a source file with OXC and return every specifier it re-exports from
39
+ * (relative AND bare) via `export * from` or `export { … } from`.
40
+ */
41
+ export declare function collectReExports(code: string, fileName: string, program?: ReturnType<typeof parseSync>["program"]): string[];
42
+ /**
38
43
  * Parse a source file with OXC and return every module specifier it imports or
39
44
  * re-exports from (relative AND bare), including `import`, `export * from`, and
40
45
  * `export { … } from`. Used to walk the transitive import graph at startup so
@@ -1,7 +1,7 @@
1
+ import { parseOxc } from "./utils.js";
1
2
  import * as fs from "node:fs";
2
3
  import * as path$1 from "node:path";
3
- import { parseSync } from "oxc-parser";
4
- //#region packages/vite-plugin-angular/src/lib/compiler/dts-reader.ts
4
+ // packages/vite-plugin-angular/src/lib/compiler/dts-reader.ts
5
5
  /**
6
6
  * Scan a single .d.ts file and extract Angular directive/component/pipe
7
7
  * metadata from the static ɵdir / ɵcmp / ɵpipe type declarations.
@@ -13,7 +13,7 @@ import { parseSync } from "oxc-parser";
13
13
  */
14
14
  function scanDtsFile(code, fileName) {
15
15
  if (!code.includes("DirectiveDeclaration") && !code.includes("ComponentDeclaration") && !code.includes("PipeDeclaration") && !code.includes("NgModuleDeclaration")) return [];
16
- const { program } = parseSync(fileName, code);
16
+ const { program } = parseOxc(fileName, code);
17
17
  const entries = [];
18
18
  visitStatements(program.body, fileName, entries);
19
19
  return entries;
@@ -105,7 +105,7 @@ function collectExportedClassesFromDts(filePath, importPath, map, visited = /* @
105
105
  }
106
106
  let program;
107
107
  try {
108
- program = parseSync(filePath, code).program;
108
+ program = parseOxc(filePath, code).program;
109
109
  } catch {
110
110
  return;
111
111
  }
@@ -172,7 +172,7 @@ function subEntryFromFilePath(packageName, pkgDir, filePath) {
172
172
  */
173
173
  function collectImportedPackages(code, fileName, program) {
174
174
  const packages = /* @__PURE__ */ new Set();
175
- program ??= parseSync(fileName, code).program;
175
+ program ??= parseOxc(fileName, code).program;
176
176
  for (const stmt of program.body) {
177
177
  if (stmt.type !== "ImportDeclaration") continue;
178
178
  const specifier = stmt.source?.value;
@@ -192,8 +192,15 @@ function collectImportedPackages(code, fileName, program) {
192
192
  * directive classes land in the registry before any consumer is compiled.
193
193
  */
194
194
  function collectRelativeReExports(code, fileName, program) {
195
+ return collectReExports(code, fileName, program).filter((specifier) => specifier.startsWith("."));
196
+ }
197
+ /**
198
+ * Parse a source file with OXC and return every specifier it re-exports from
199
+ * (relative AND bare) via `export * from` or `export { … } from`.
200
+ */
201
+ function collectReExports(code, fileName, program) {
195
202
  if (!program) try {
196
- program = parseSync(fileName, code).program;
203
+ program = parseOxc(fileName, code).program;
197
204
  } catch {
198
205
  return [];
199
206
  }
@@ -201,8 +208,7 @@ function collectRelativeReExports(code, fileName, program) {
201
208
  for (const stmt of program.body || []) {
202
209
  if (stmt.type !== "ExportAllDeclaration" && stmt.type !== "ExportNamedDeclaration") continue;
203
210
  const specifier = stmt.source?.value;
204
- if (!specifier || !specifier.startsWith(".")) continue;
205
- result.push(specifier);
211
+ if (specifier && !isTypeOnly(stmt)) result.push(specifier);
206
212
  }
207
213
  return result;
208
214
  }
@@ -216,17 +222,20 @@ function collectRelativeReExports(code, fileName, program) {
216
222
  */
217
223
  function collectAllImports(code, fileName, program) {
218
224
  if (!program) try {
219
- program = parseSync(fileName, code).program;
225
+ program = parseOxc(fileName, code).program;
220
226
  } catch {
221
227
  return [];
222
228
  }
223
229
  const result = [];
224
230
  for (const stmt of program.body || []) if (stmt.type === "ImportDeclaration" || stmt.type === "ExportAllDeclaration" || stmt.type === "ExportNamedDeclaration") {
225
231
  const specifier = stmt.source?.value;
226
- if (specifier) result.push(specifier);
232
+ if (specifier && !isTypeOnly(stmt)) result.push(specifier);
227
233
  }
228
234
  return result;
229
235
  }
236
+ function isTypeOnly(stmt) {
237
+ return stmt.importKind === "type" || stmt.exportKind === "type";
238
+ }
230
239
  function visitStatements(stmts, fileName, entries) {
231
240
  for (const stmt of stmts) {
232
241
  const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
@@ -389,7 +398,6 @@ function collectDtsFiles(dir) {
389
398
  }
390
399
  return results;
391
400
  }
392
- //#endregion
393
- export { collectAllImports, collectImportedPackages, collectRelativeReExports, scanDtsFile, scanPackageDts };
401
+ export { collectAllImports, collectImportedPackages, collectReExports, collectRelativeReExports, scanDtsFile, scanPackageDts };
394
402
 
395
403
  //# sourceMappingURL=dts-reader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dts-reader.js","names":[],"sources":["../../../../src/lib/compiler/dts-reader.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { RegistryEntry, RegistryInput } from './registry.js';\n\n/**\n * Scan a single .d.ts file and extract Angular directive/component/pipe\n * metadata from the static ɵdir / ɵcmp / ɵpipe type declarations.\n *\n * This mirrors what ngtsc's DtsMetadataReader does: it reads the type\n * parameters of ɵɵDirectiveDeclaration / ɵɵComponentDeclaration /\n * ɵɵPipeDeclaration to discover selectors, inputs, and outputs for\n * pre-compiled Angular packages.\n */\nexport function scanDtsFile(code: string, fileName: string): RegistryEntry[] {\n // Fast pre-filter — skip files that can't contain Angular declarations\n if (\n !code.includes('DirectiveDeclaration') &&\n !code.includes('ComponentDeclaration') &&\n !code.includes('PipeDeclaration') &&\n !code.includes('NgModuleDeclaration')\n )\n return [];\n\n const { program } = parseSync(fileName, code);\n const entries: RegistryEntry[] = [];\n\n visitStatements(program.body, fileName, entries);\n return entries;\n}\n\n/**\n * Resolve a package's directory in node_modules, scan all its .d.ts files,\n * and return RegistryEntry[] for every Angular declaration found.\n *\n * @param packageName e.g. \"@angular/router\"\n * @param basePath project root (where node_modules lives)\n */\nexport function scanPackageDts(\n packageName: string,\n basePath: string,\n visited?: Set<string>,\n): RegistryEntry[] {\n // Walk up from basePath to find the nearest node_modules containing the package.\n // This handles monorepos where node_modules is at the workspace root,\n // not in the project subdirectory.\n let pkgDir = '';\n let searchBase = basePath;\n while (searchBase !== path.dirname(searchBase)) {\n const candidate = path.join(searchBase, 'node_modules', packageName);\n if (fs.existsSync(candidate)) {\n pkgDir = candidate;\n break;\n }\n searchBase = path.dirname(searchBase);\n }\n if (!pkgDir) return [];\n\n // Build a map from className → correct import path using package.json exports.\n // This handles packages with sub-entry points (e.g. @angular/material/tabs)\n // where re-exported classes must be imported from their origin entry point.\n const classToImportPath = buildClassToImportMap(packageName, pkgDir);\n\n // Check for a \"types\" directory first (Angular packages use this),\n // then fall back to the package root.\n const typesDir = path.join(pkgDir, 'types');\n const searchDir = fs.existsSync(typesDir) ? typesDir : pkgDir;\n\n const dtsFiles = collectDtsFiles(searchDir);\n const entries: RegistryEntry[] = [];\n // Packages re-exported by this package's NgModule declarations. A library\n // NgModule can re-export another package's module (e.g. BrowserModule exports\n // CommonModule), so those packages must be scanned too or their directives\n // (NgIf, NgForOf, …) never reach the registry.\n const referencedPackages = new Set<string>();\n\n for (const file of dtsFiles) {\n try {\n const code = fs.readFileSync(file, 'utf-8');\n const fileEntries = scanDtsFile(code, file);\n for (const entry of fileEntries) {\n entry.sourcePackage =\n classToImportPath.get(entry.className) ||\n subEntryFromFilePath(packageName, pkgDir, file) ||\n packageName;\n }\n entries.push(...fileEntries);\n // Only follow cross-package imports of declaration files that actually\n // contain an NgModule — those are the ones whose exports can pull in\n // another package's directives/pipes. This keeps the walk bounded.\n if (visited && fileEntries.some((e) => e.kind === 'ngmodule')) {\n for (const p of collectImportedPackages(code, file)) {\n referencedPackages.add(p);\n }\n }\n } catch {\n // Skip unreadable files\n }\n }\n\n if (visited) {\n for (const p of referencedPackages) {\n if (p === packageName || visited.has(p)) continue;\n visited.add(p);\n try {\n entries.push(...scanPackageDts(p, basePath, visited));\n } catch {\n // Package may not have .d.ts or not be Angular\n }\n }\n }\n\n return entries;\n}\n\n/**\n * Read package.json exports to build a map from class name to the correct\n * sub-entry import path (e.g. \"MatTabNav\" → \"@angular/material/tabs\").\n *\n * For each sub-entry that has a \"types\" field, the corresponding .d.ts file\n * is read to collect declared class names and re-exported names.\n */\nfunction buildClassToImportMap(\n packageName: string,\n pkgDir: string,\n): Map<string, string> {\n const map = new Map<string, string>();\n try {\n const pkgJson = JSON.parse(\n fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf-8'),\n );\n if (!pkgJson.exports) return map;\n\n for (const [key, value] of Object.entries(pkgJson.exports) as [\n string,\n any,\n ][]) {\n if (key !== '.' && !key.startsWith('./')) continue;\n // Resolve types from the export entry. Some packages declare\n // `types` only at the package root (top-level package.json `types`\n // field) rather than per-export, so fall back to that for `.`.\n let typesFile: string | undefined =\n typeof value === 'object' && value !== null && value.types;\n if (!typesFile && key === '.' && typeof pkgJson.types === 'string') {\n typesFile = pkgJson.types;\n }\n if (!typesFile) continue;\n\n // Root entry (`.`) maps classes to the bare package name; sub-entries\n // (`./tabs`) map to `${packageName}/tabs`. Mapping root-exported\n // classes prevents `subEntryFromFilePath` from deriving an invalid\n // subpath like `ngx-scrollbar/lib` for files that physically live in\n // a `lib/` subdirectory but are only re-exported from the root entry.\n const importPath =\n key === '.' ? packageName : packageName + '/' + key.slice(2);\n const fullTypesPath = path.resolve(pkgDir, typesFile);\n if (!fs.existsSync(fullTypesPath)) continue;\n\n collectExportedClassesFromDts(fullTypesPath, importPath, map);\n }\n } catch {\n // No package.json or no exports — fall back to packageName\n }\n return map;\n}\n\n/**\n * Read a `.d.ts` entry file and add every class it exports to `map`,\n * following `export * from './rel'` chains so re-exported classes from\n * physically nested files (e.g. `lib/foo.d.ts`) are still mapped to the\n * exporting entry's import path.\n *\n * Without this, packages whose root `index.d.ts` is just a barrel of\n * `export * from './lib/...'` would never get their classes mapped, and the\n * `subEntryFromFilePath` fallback would derive an invalid `${pkg}/lib`\n * import for files living under `lib/`.\n */\nfunction collectExportedClassesFromDts(\n filePath: string,\n importPath: string,\n map: Map<string, string>,\n visited: Set<string> = new Set(),\n): void {\n if (visited.has(filePath)) return;\n visited.add(filePath);\n let code: string;\n try {\n code = fs.readFileSync(filePath, 'utf-8');\n } catch {\n return;\n }\n\n let program: any;\n try {\n program = parseSync(filePath, code).program;\n } catch {\n return;\n }\n\n const dir = path.dirname(filePath);\n for (const stmt of program.body || []) {\n // `declare class Foo` (top-level)\n if (stmt.type === 'ClassDeclaration' && stmt.id?.name) {\n map.set(stmt.id.name, importPath);\n continue;\n }\n\n // `export declare class Foo` / `export class Foo` /\n // `export { A, B as C } from '...'` / `export { A, B }`\n if (stmt.type === 'ExportNamedDeclaration') {\n if (\n stmt.declaration?.type === 'ClassDeclaration' &&\n stmt.declaration.id?.name\n ) {\n map.set(stmt.declaration.id.name, importPath);\n }\n for (const spec of stmt.specifiers || []) {\n // ExportSpecifier: { local, exported }\n const exportedNode = spec.exported;\n const exportedName =\n exportedNode?.type === 'Identifier'\n ? exportedNode.name\n : exportedNode?.type === 'Literal'\n ? exportedNode.value\n : undefined;\n if (typeof exportedName === 'string') {\n map.set(exportedName, importPath);\n }\n }\n continue;\n }\n\n // `export * from './rel'` and `export * as Ns from './rel'`\n if (stmt.type === 'ExportAllDeclaration') {\n const rel: string | undefined = stmt.source?.value;\n if (!rel || !rel.startsWith('.')) continue;\n // TypeScript preserves the original specifier text in emitted\n // `.d.ts` files, so NodeNext-style packages keep their `.js`\n // (or `.mjs`) extensions in re-exports — but the actual\n // declaration is at `foo.d.ts` / `foo/index.d.ts`. Strip the\n // ESM extension before probing.\n const normalizedRel = rel.replace(/\\.(?:js|mjs)$/u, '');\n const candidates = [\n path.resolve(dir, normalizedRel + '.d.ts'),\n path.resolve(dir, normalizedRel, 'index.d.ts'),\n ];\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n collectExportedClassesFromDts(candidate, importPath, map, visited);\n break;\n }\n }\n continue;\n }\n }\n}\n\n/**\n * Derive a sub-entry import path from a .d.ts file's location relative to the\n * package root. This handles older Angular packages that keep .d.ts files in\n * subdirectories (e.g. `@angular/material/tabs/index.d.ts`) instead of a\n * top-level `types/` folder.\n *\n * Returns `undefined` when no sub-entry can be determined (e.g. file is at the\n * package root, inside `types/`, or in a non-entry directory).\n */\nfunction subEntryFromFilePath(\n packageName: string,\n pkgDir: string,\n filePath: string,\n): string | undefined {\n const NON_ENTRY_DIRS = new Set([\n 'types',\n 'fesm2022',\n 'fesm2020',\n 'fesm2015',\n 'esm2022',\n 'esm2020',\n 'esm2015',\n 'bundles',\n 'schematics',\n 'node_modules',\n ]);\n const rel = path.relative(pkgDir, filePath);\n const segments = rel.split(path.sep);\n // File directly in pkgDir (no subdirectory) → no sub-entry\n if (segments.length < 2) return undefined;\n const firstDir = segments[0];\n // Skip internal/build directories and chunk files\n if (NON_ENTRY_DIRS.has(firstDir) || firstDir.startsWith('_'))\n return undefined;\n return packageName + '/' + firstDir;\n}\n\n/**\n * Parse a source file with OXC and return the set of bare-specifier package\n * names it imports (e.g. \"@angular/router\", \"rxjs\"). Relative imports are\n * skipped.\n */\nexport function collectImportedPackages(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): Set<string> {\n const packages = new Set<string>();\n program ??= parseSync(fileName, code).program;\n\n for (const stmt of program.body) {\n if (stmt.type !== 'ImportDeclaration') continue;\n const specifier: string = stmt.source?.value;\n if (!specifier || specifier.startsWith('.')) continue;\n\n const parts = specifier.split('/');\n packages.add(\n specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0],\n );\n }\n\n return packages;\n}\n\n/**\n * Parse a source file with OXC and return the relative-path specifiers it\n * re-exports via `export * from './x'`, `export * as Ns from './x'`, or\n * `export { … } from './x'`. Bare-specifier re-exports are skipped.\n *\n * Used by the analog Vite plugin to walk library entry barrels at startup\n * (e.g. `helm/select/src/index.ts` → `./lib/hlm-select`) so the underlying\n * directive classes land in the registry before any consumer is compiled.\n */\nexport function collectRelativeReExports(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): string[] {\n if (!program) {\n try {\n program = parseSync(fileName, code).program;\n } catch {\n return [];\n }\n }\n const result: string[] = [];\n for (const stmt of program.body || []) {\n if (\n stmt.type !== 'ExportAllDeclaration' &&\n stmt.type !== 'ExportNamedDeclaration'\n ) {\n continue;\n }\n // ExportNamedDeclaration without `source` is `export { x }` (no\n // re-export), which we don't care about here.\n const specifier: string | undefined = stmt.source?.value;\n if (!specifier || !specifier.startsWith('.')) continue;\n result.push(specifier);\n }\n return result;\n}\n\n/**\n * Parse a source file with OXC and return every module specifier it imports or\n * re-exports from (relative AND bare), including `import`, `export * from`, and\n * `export { … } from`. Used to walk the transitive import graph at startup so\n * the registry contains components/directives/pipes/modules from files not\n * directly listed in tsconfig `files`/`include` (transitively-imported app\n * sources) or behind wildcard `paths` (workspace libraries).\n */\nexport function collectAllImports(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): string[] {\n if (!program) {\n try {\n program = parseSync(fileName, code).program;\n } catch {\n return [];\n }\n }\n const result: string[] = [];\n for (const stmt of program.body || []) {\n if (\n stmt.type === 'ImportDeclaration' ||\n stmt.type === 'ExportAllDeclaration' ||\n stmt.type === 'ExportNamedDeclaration'\n ) {\n const specifier: string | undefined = stmt.source?.value;\n if (specifier) result.push(specifier);\n }\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction visitStatements(\n stmts: any[],\n fileName: string,\n entries: RegistryEntry[],\n) {\n for (const stmt of stmts) {\n // Unwrap exports: `export declare class ...` / `export default class ...`\n const decl =\n stmt.type === 'ExportNamedDeclaration' ||\n stmt.type === 'ExportDefaultDeclaration'\n ? stmt.declaration\n : stmt;\n\n if (!decl) continue;\n\n // Recurse into `declare module \"...\" { ... }` blocks\n if (decl.type === 'TSModuleDeclaration' && decl.body?.body) {\n visitStatements(decl.body.body, fileName, entries);\n continue;\n }\n\n if (decl.type !== 'ClassDeclaration' || !decl.id?.name) continue;\n const className: string = decl.id.name;\n const members: any[] = decl.body?.body || [];\n\n for (const member of members) {\n if (member.type !== 'PropertyDefinition' || !member.static) continue;\n const propName: string | undefined = member.key?.name;\n\n // Read the type annotation: e.g. `i0.ɵɵDirectiveDeclaration<...>`\n const typeRef = member.typeAnnotation?.typeAnnotation;\n if (!typeRef || typeRef.type !== 'TSTypeReference') continue;\n\n const typeName = qualifiedName(typeRef.typeName);\n const typeParams: any[] | undefined = typeRef.typeArguments?.params;\n\n if (\n (propName === 'ɵdir' || propName === 'ɵcmp') &&\n (typeName.includes('DirectiveDeclaration') ||\n typeName.includes('ComponentDeclaration')) &&\n typeParams &&\n typeParams.length >= 5\n ) {\n const selector = literalString(typeParams[1]);\n if (!selector) continue;\n\n const inputs = extractInputs(typeParams[3]);\n const outputs = extractOutputs(typeParams[4]);\n\n entries.push({\n selector: selector.split(',')[0].trim(),\n kind: propName === 'ɵcmp' ? 'component' : 'directive',\n fileName,\n className,\n ...(Object.keys(inputs).length > 0 ? { inputs } : {}),\n ...(Object.keys(outputs).length > 0 ? { outputs } : {}),\n });\n } else if (\n propName === 'ɵpipe' &&\n typeName.includes('PipeDeclaration') &&\n typeParams &&\n typeParams.length >= 2\n ) {\n const pipeName = literalString(typeParams[1]);\n if (!pipeName) continue;\n\n entries.push({\n selector: pipeName,\n kind: 'pipe',\n pipeName,\n fileName,\n className,\n });\n } else if (\n propName === 'ɵmod' &&\n typeName.includes('NgModuleDeclaration') &&\n typeParams &&\n typeParams.length >= 4\n ) {\n // ɵɵNgModuleDeclaration<Module, Declarations, Imports, Exports>\n // Extract exported class names from the 4th type param (index 3).\n const exportsParam = typeParams[3];\n const exportedNames: string[] = [];\n if (exportsParam?.type === 'TSTupleType' && exportsParam.elementTypes) {\n for (const el of exportsParam.elementTypes) {\n if (\n el.type === 'TSTypeQuery' &&\n el.exprName?.type === 'Identifier'\n ) {\n exportedNames.push(el.exprName.name);\n } else if (\n el.type === 'TSTypeQuery' &&\n el.exprName?.type === 'TSQualifiedName'\n ) {\n // e.g. typeof i2.BidiModule → extract \"BidiModule\"\n const right = el.exprName.right;\n if (right?.type === 'Identifier') {\n exportedNames.push(right.name);\n }\n }\n }\n }\n entries.push({\n selector: className,\n kind: 'ngmodule',\n exports: exportedNames,\n fileName,\n className,\n });\n }\n }\n }\n}\n\n/**\n * Extract inputs from the type-argument at position [3].\n *\n * Handles two formats:\n * v16+: { \"prop\": { \"alias\": \"binding\"; \"required\": false; \"isSignal\"?: true } }\n * pre-v16: { \"prop\": \"binding\" }\n */\nfunction extractInputs(node: any): Record<string, RegistryInput> {\n const inputs: Record<string, RegistryInput> = {};\n if (node?.type !== 'TSTypeLiteral') return inputs;\n\n for (const member of node.members) {\n if (member.type !== 'TSPropertySignature') continue;\n const propName = keyName(member.key);\n const innerType = member.typeAnnotation?.typeAnnotation;\n if (!propName || !innerType) continue;\n\n if (innerType.type === 'TSTypeLiteral') {\n // v16+ object format\n let alias = propName;\n let required = false;\n let isSignal = false;\n\n for (const inner of innerType.members) {\n if (inner.type !== 'TSPropertySignature') continue;\n const key = keyName(inner.key);\n const val = inner.typeAnnotation?.typeAnnotation;\n if (!key || !val) continue;\n\n if (key === 'alias') {\n alias = literalString(val) ?? propName;\n } else if (key === 'required') {\n required = literalBoolean(val) === true;\n } else if (key === 'isSignal') {\n isSignal = literalBoolean(val) === true;\n }\n }\n\n inputs[propName] = {\n classPropertyName: propName,\n bindingPropertyName: alias,\n isSignal,\n required,\n };\n } else {\n // pre-v16 string format\n const alias = literalString(innerType);\n if (alias) {\n inputs[propName] = {\n classPropertyName: propName,\n bindingPropertyName: alias,\n isSignal: false,\n required: false,\n };\n }\n }\n }\n\n return inputs;\n}\n\n/**\n * Extract outputs from the type-argument at position [4].\n * Format: { \"propName\": \"eventName\" }\n */\nfunction extractOutputs(node: any): Record<string, string> {\n const outputs: Record<string, string> = {};\n if (node?.type !== 'TSTypeLiteral') return outputs;\n\n for (const member of node.members) {\n if (member.type !== 'TSPropertySignature') continue;\n const propName = keyName(member.key);\n const val = member.typeAnnotation?.typeAnnotation;\n if (!propName || !val) continue;\n\n const value = literalString(val);\n if (value) outputs[propName] = value;\n }\n\n return outputs;\n}\n\n/** Get the string name from a property key (Identifier or Literal). */\nfunction keyName(key: any): string | undefined {\n if (!key) return undefined;\n if (key.type === 'Identifier') return key.name;\n if (key.type === 'Literal' && typeof key.value === 'string') return key.value;\n return undefined;\n}\n\n/** Build a dotted name from an Identifier or TSQualifiedName. */\nfunction qualifiedName(node: any): string {\n if (!node) return '';\n if (node.type === 'Identifier') return node.name;\n if (node.type === 'TSQualifiedName')\n return qualifiedName(node.left) + '.' + qualifiedName(node.right);\n return '';\n}\n\n/** Extract a string value from a TSLiteralType node. */\nfunction literalString(node: any): string | undefined {\n if (\n node?.type === 'TSLiteralType' &&\n node.literal?.type === 'Literal' &&\n typeof node.literal.value === 'string'\n ) {\n return node.literal.value;\n }\n return undefined;\n}\n\n/** Extract a boolean value from a TSLiteralType node. */\nfunction literalBoolean(node: any): boolean | undefined {\n if (\n node?.type === 'TSLiteralType' &&\n node.literal?.type === 'Literal' &&\n typeof node.literal.value === 'boolean'\n ) {\n return node.literal.value;\n }\n return undefined;\n}\n\n/** Recursively collect all .d.ts files under a directory. */\nfunction collectDtsFiles(dir: string): string[] {\n const results: string[] = [];\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return results;\n }\n\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory() && entry.name !== 'node_modules') {\n results.push(...collectDtsFiles(full));\n } else if (entry.isFile() && entry.name.endsWith('.d.ts')) {\n results.push(full);\n }\n }\n\n return results;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,YAAY,MAAc,UAAmC;CAE3E,IACE,CAAC,KAAK,SAAS,sBAAsB,KACrC,CAAC,KAAK,SAAS,sBAAsB,KACrC,CAAC,KAAK,SAAS,iBAAiB,KAChC,CAAC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,SAAS,eAAe,MAAgC;CACtD,IACE,MAAM,SAAS,mBACf,KAAK,SAAS,SAAS,aACvB,OAAO,KAAK,QAAQ,UAAU,WAE9B,OAAO,KAAK,QAAQ;AAGxB;;AAGA,SAAS,gBAAgB,KAAuB;CAC9C,MAAM,UAAoB,CAAC;CAC3B,IAAI;CACJ,IAAI;EACF,UAAU,GAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC;CACvD,QAAQ;EACN,OAAO;CACT;CAEA,KAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,OAAO,OAAK,KAAK,KAAK,MAAM,IAAI;EACtC,IAAI,MAAM,YAAY,KAAK,MAAM,SAAS,gBACxC,QAAQ,KAAK,GAAG,gBAAgB,IAAI,CAAC;OAChC,IAAI,MAAM,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO,GACtD,QAAQ,KAAK,IAAI;CAErB;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"dts-reader.js","names":["path"],"sources":["../../../../src/lib/compiler/dts-reader.ts"],"sourcesContent":["import type { parseSync } from 'oxc-parser';\nimport { parseOxc } from './utils.js';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { RegistryEntry, RegistryInput } from './registry.js';\n\n/**\n * Scan a single .d.ts file and extract Angular directive/component/pipe\n * metadata from the static ɵdir / ɵcmp / ɵpipe type declarations.\n *\n * This mirrors what ngtsc's DtsMetadataReader does: it reads the type\n * parameters of ɵɵDirectiveDeclaration / ɵɵComponentDeclaration /\n * ɵɵPipeDeclaration to discover selectors, inputs, and outputs for\n * pre-compiled Angular packages.\n */\nexport function scanDtsFile(code: string, fileName: string): RegistryEntry[] {\n // Fast pre-filter — skip files that can't contain Angular declarations\n if (\n !code.includes('DirectiveDeclaration') &&\n !code.includes('ComponentDeclaration') &&\n !code.includes('PipeDeclaration') &&\n !code.includes('NgModuleDeclaration')\n )\n return [];\n\n const { program } = parseOxc(fileName, code);\n const entries: RegistryEntry[] = [];\n\n visitStatements(program.body, fileName, entries);\n return entries;\n}\n\n/**\n * Resolve a package's directory in node_modules, scan all its .d.ts files,\n * and return RegistryEntry[] for every Angular declaration found.\n *\n * @param packageName e.g. \"@angular/router\"\n * @param basePath project root (where node_modules lives)\n */\nexport function scanPackageDts(\n packageName: string,\n basePath: string,\n visited?: Set<string>,\n): RegistryEntry[] {\n // Walk up from basePath to find the nearest node_modules containing the package.\n // This handles monorepos where node_modules is at the workspace root,\n // not in the project subdirectory.\n let pkgDir = '';\n let searchBase = basePath;\n while (searchBase !== path.dirname(searchBase)) {\n const candidate = path.join(searchBase, 'node_modules', packageName);\n if (fs.existsSync(candidate)) {\n pkgDir = candidate;\n break;\n }\n searchBase = path.dirname(searchBase);\n }\n if (!pkgDir) return [];\n\n // Build a map from className → correct import path using package.json exports.\n // This handles packages with sub-entry points (e.g. @angular/material/tabs)\n // where re-exported classes must be imported from their origin entry point.\n const classToImportPath = buildClassToImportMap(packageName, pkgDir);\n\n // Check for a \"types\" directory first (Angular packages use this),\n // then fall back to the package root.\n const typesDir = path.join(pkgDir, 'types');\n const searchDir = fs.existsSync(typesDir) ? typesDir : pkgDir;\n\n const dtsFiles = collectDtsFiles(searchDir);\n const entries: RegistryEntry[] = [];\n // Packages re-exported by this package's NgModule declarations. A library\n // NgModule can re-export another package's module (e.g. BrowserModule exports\n // CommonModule), so those packages must be scanned too or their directives\n // (NgIf, NgForOf, …) never reach the registry.\n const referencedPackages = new Set<string>();\n\n for (const file of dtsFiles) {\n try {\n const code = fs.readFileSync(file, 'utf-8');\n const fileEntries = scanDtsFile(code, file);\n for (const entry of fileEntries) {\n entry.sourcePackage =\n classToImportPath.get(entry.className) ||\n subEntryFromFilePath(packageName, pkgDir, file) ||\n packageName;\n }\n entries.push(...fileEntries);\n // Only follow cross-package imports of declaration files that actually\n // contain an NgModule — those are the ones whose exports can pull in\n // another package's directives/pipes. This keeps the walk bounded.\n if (visited && fileEntries.some((e) => e.kind === 'ngmodule')) {\n for (const p of collectImportedPackages(code, file)) {\n referencedPackages.add(p);\n }\n }\n } catch {\n // Skip unreadable files\n }\n }\n\n if (visited) {\n for (const p of referencedPackages) {\n if (p === packageName || visited.has(p)) continue;\n visited.add(p);\n try {\n entries.push(...scanPackageDts(p, basePath, visited));\n } catch {\n // Package may not have .d.ts or not be Angular\n }\n }\n }\n\n return entries;\n}\n\n/**\n * Read package.json exports to build a map from class name to the correct\n * sub-entry import path (e.g. \"MatTabNav\" → \"@angular/material/tabs\").\n *\n * For each sub-entry that has a \"types\" field, the corresponding .d.ts file\n * is read to collect declared class names and re-exported names.\n */\nfunction buildClassToImportMap(\n packageName: string,\n pkgDir: string,\n): Map<string, string> {\n const map = new Map<string, string>();\n try {\n const pkgJson = JSON.parse(\n fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf-8'),\n );\n if (!pkgJson.exports) return map;\n\n for (const [key, value] of Object.entries(pkgJson.exports) as [\n string,\n any,\n ][]) {\n if (key !== '.' && !key.startsWith('./')) continue;\n // Resolve types from the export entry. Some packages declare\n // `types` only at the package root (top-level package.json `types`\n // field) rather than per-export, so fall back to that for `.`.\n let typesFile: string | undefined =\n typeof value === 'object' && value !== null && value.types;\n if (!typesFile && key === '.' && typeof pkgJson.types === 'string') {\n typesFile = pkgJson.types;\n }\n if (!typesFile) continue;\n\n // Root entry (`.`) maps classes to the bare package name; sub-entries\n // (`./tabs`) map to `${packageName}/tabs`. Mapping root-exported\n // classes prevents `subEntryFromFilePath` from deriving an invalid\n // subpath like `ngx-scrollbar/lib` for files that physically live in\n // a `lib/` subdirectory but are only re-exported from the root entry.\n const importPath =\n key === '.' ? packageName : packageName + '/' + key.slice(2);\n const fullTypesPath = path.resolve(pkgDir, typesFile);\n if (!fs.existsSync(fullTypesPath)) continue;\n\n collectExportedClassesFromDts(fullTypesPath, importPath, map);\n }\n } catch {\n // No package.json or no exports — fall back to packageName\n }\n return map;\n}\n\n/**\n * Read a `.d.ts` entry file and add every class it exports to `map`,\n * following `export * from './rel'` chains so re-exported classes from\n * physically nested files (e.g. `lib/foo.d.ts`) are still mapped to the\n * exporting entry's import path.\n *\n * Without this, packages whose root `index.d.ts` is just a barrel of\n * `export * from './lib/...'` would never get their classes mapped, and the\n * `subEntryFromFilePath` fallback would derive an invalid `${pkg}/lib`\n * import for files living under `lib/`.\n */\nfunction collectExportedClassesFromDts(\n filePath: string,\n importPath: string,\n map: Map<string, string>,\n visited: Set<string> = new Set(),\n): void {\n if (visited.has(filePath)) return;\n visited.add(filePath);\n let code: string;\n try {\n code = fs.readFileSync(filePath, 'utf-8');\n } catch {\n return;\n }\n\n let program: any;\n try {\n program = parseOxc(filePath, code).program;\n } catch {\n return;\n }\n\n const dir = path.dirname(filePath);\n for (const stmt of program.body || []) {\n // `declare class Foo` (top-level)\n if (stmt.type === 'ClassDeclaration' && stmt.id?.name) {\n map.set(stmt.id.name, importPath);\n continue;\n }\n\n // `export declare class Foo` / `export class Foo` /\n // `export { A, B as C } from '...'` / `export { A, B }`\n if (stmt.type === 'ExportNamedDeclaration') {\n if (\n stmt.declaration?.type === 'ClassDeclaration' &&\n stmt.declaration.id?.name\n ) {\n map.set(stmt.declaration.id.name, importPath);\n }\n for (const spec of stmt.specifiers || []) {\n // ExportSpecifier: { local, exported }\n const exportedNode = spec.exported;\n const exportedName =\n exportedNode?.type === 'Identifier'\n ? exportedNode.name\n : exportedNode?.type === 'Literal'\n ? exportedNode.value\n : undefined;\n if (typeof exportedName === 'string') {\n map.set(exportedName, importPath);\n }\n }\n continue;\n }\n\n // `export * from './rel'` and `export * as Ns from './rel'`\n if (stmt.type === 'ExportAllDeclaration') {\n const rel: string | undefined = stmt.source?.value;\n if (!rel || !rel.startsWith('.')) continue;\n // TypeScript preserves the original specifier text in emitted\n // `.d.ts` files, so NodeNext-style packages keep their `.js`\n // (or `.mjs`) extensions in re-exports — but the actual\n // declaration is at `foo.d.ts` / `foo/index.d.ts`. Strip the\n // ESM extension before probing.\n const normalizedRel = rel.replace(/\\.(?:js|mjs)$/u, '');\n const candidates = [\n path.resolve(dir, normalizedRel + '.d.ts'),\n path.resolve(dir, normalizedRel, 'index.d.ts'),\n ];\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n collectExportedClassesFromDts(candidate, importPath, map, visited);\n break;\n }\n }\n continue;\n }\n }\n}\n\n/**\n * Derive a sub-entry import path from a .d.ts file's location relative to the\n * package root. This handles older Angular packages that keep .d.ts files in\n * subdirectories (e.g. `@angular/material/tabs/index.d.ts`) instead of a\n * top-level `types/` folder.\n *\n * Returns `undefined` when no sub-entry can be determined (e.g. file is at the\n * package root, inside `types/`, or in a non-entry directory).\n */\nfunction subEntryFromFilePath(\n packageName: string,\n pkgDir: string,\n filePath: string,\n): string | undefined {\n const NON_ENTRY_DIRS = new Set([\n 'types',\n 'fesm2022',\n 'fesm2020',\n 'fesm2015',\n 'esm2022',\n 'esm2020',\n 'esm2015',\n 'bundles',\n 'schematics',\n 'node_modules',\n ]);\n const rel = path.relative(pkgDir, filePath);\n const segments = rel.split(path.sep);\n // File directly in pkgDir (no subdirectory) → no sub-entry\n if (segments.length < 2) return undefined;\n const firstDir = segments[0];\n // Skip internal/build directories and chunk files\n if (NON_ENTRY_DIRS.has(firstDir) || firstDir.startsWith('_'))\n return undefined;\n return packageName + '/' + firstDir;\n}\n\n/**\n * Parse a source file with OXC and return the set of bare-specifier package\n * names it imports (e.g. \"@angular/router\", \"rxjs\"). Relative imports are\n * skipped.\n */\nexport function collectImportedPackages(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): Set<string> {\n const packages = new Set<string>();\n program ??= parseOxc(fileName, code).program;\n\n for (const stmt of program.body) {\n if (stmt.type !== 'ImportDeclaration') continue;\n const specifier: string = stmt.source?.value;\n if (!specifier || specifier.startsWith('.')) continue;\n\n const parts = specifier.split('/');\n packages.add(\n specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0],\n );\n }\n\n return packages;\n}\n\n/**\n * Parse a source file with OXC and return the relative-path specifiers it\n * re-exports via `export * from './x'`, `export * as Ns from './x'`, or\n * `export { … } from './x'`. Bare-specifier re-exports are skipped.\n *\n * Used by the analog Vite plugin to walk library entry barrels at startup\n * (e.g. `helm/select/src/index.ts` → `./lib/hlm-select`) so the underlying\n * directive classes land in the registry before any consumer is compiled.\n */\nexport function collectRelativeReExports(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): string[] {\n return collectReExports(code, fileName, program).filter((specifier) =>\n specifier.startsWith('.'),\n );\n}\n\n/**\n * Parse a source file with OXC and return every specifier it re-exports from\n * (relative AND bare) via `export * from` or `export { … } from`.\n */\nexport function collectReExports(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): string[] {\n if (!program) {\n try {\n program = parseOxc(fileName, code).program;\n } catch {\n return [];\n }\n }\n const result: string[] = [];\n for (const stmt of program.body || []) {\n if (\n stmt.type !== 'ExportAllDeclaration' &&\n stmt.type !== 'ExportNamedDeclaration'\n ) {\n continue;\n }\n // ExportNamedDeclaration without `source` is `export { x }` (no\n // re-export), which we don't care about here.\n const specifier: string | undefined = stmt.source?.value;\n if (specifier && !isTypeOnly(stmt)) result.push(specifier);\n }\n return result;\n}\n\n/**\n * Parse a source file with OXC and return every module specifier it imports or\n * re-exports from (relative AND bare), including `import`, `export * from`, and\n * `export { … } from`. Used to walk the transitive import graph at startup so\n * the registry contains components/directives/pipes/modules from files not\n * directly listed in tsconfig `files`/`include` (transitively-imported app\n * sources) or behind wildcard `paths` (workspace libraries).\n */\nexport function collectAllImports(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): string[] {\n if (!program) {\n try {\n program = parseOxc(fileName, code).program;\n } catch {\n return [];\n }\n }\n const result: string[] = [];\n for (const stmt of program.body || []) {\n if (\n stmt.type === 'ImportDeclaration' ||\n stmt.type === 'ExportAllDeclaration' ||\n stmt.type === 'ExportNamedDeclaration'\n ) {\n const specifier: string | undefined = stmt.source?.value;\n if (specifier && !isTypeOnly(stmt)) result.push(specifier);\n }\n }\n return result;\n}\n\nfunction isTypeOnly(stmt: any): boolean {\n return stmt.importKind === 'type' || stmt.exportKind === 'type';\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction visitStatements(\n stmts: any[],\n fileName: string,\n entries: RegistryEntry[],\n) {\n for (const stmt of stmts) {\n // Unwrap exports: `export declare class ...` / `export default class ...`\n const decl =\n stmt.type === 'ExportNamedDeclaration' ||\n stmt.type === 'ExportDefaultDeclaration'\n ? stmt.declaration\n : stmt;\n\n if (!decl) continue;\n\n // Recurse into `declare module \"...\" { ... }` blocks\n if (decl.type === 'TSModuleDeclaration' && decl.body?.body) {\n visitStatements(decl.body.body, fileName, entries);\n continue;\n }\n\n if (decl.type !== 'ClassDeclaration' || !decl.id?.name) continue;\n const className: string = decl.id.name;\n const members: any[] = decl.body?.body || [];\n\n for (const member of members) {\n if (member.type !== 'PropertyDefinition' || !member.static) continue;\n const propName: string | undefined = member.key?.name;\n\n // Read the type annotation: e.g. `i0.ɵɵDirectiveDeclaration<...>`\n const typeRef = member.typeAnnotation?.typeAnnotation;\n if (!typeRef || typeRef.type !== 'TSTypeReference') continue;\n\n const typeName = qualifiedName(typeRef.typeName);\n const typeParams: any[] | undefined = typeRef.typeArguments?.params;\n\n if (\n (propName === 'ɵdir' || propName === 'ɵcmp') &&\n (typeName.includes('DirectiveDeclaration') ||\n typeName.includes('ComponentDeclaration')) &&\n typeParams &&\n typeParams.length >= 5\n ) {\n const selector = literalString(typeParams[1]);\n if (!selector) continue;\n\n const inputs = extractInputs(typeParams[3]);\n const outputs = extractOutputs(typeParams[4]);\n\n entries.push({\n selector: selector.split(',')[0].trim(),\n kind: propName === 'ɵcmp' ? 'component' : 'directive',\n fileName,\n className,\n ...(Object.keys(inputs).length > 0 ? { inputs } : {}),\n ...(Object.keys(outputs).length > 0 ? { outputs } : {}),\n });\n } else if (\n propName === 'ɵpipe' &&\n typeName.includes('PipeDeclaration') &&\n typeParams &&\n typeParams.length >= 2\n ) {\n const pipeName = literalString(typeParams[1]);\n if (!pipeName) continue;\n\n entries.push({\n selector: pipeName,\n kind: 'pipe',\n pipeName,\n fileName,\n className,\n });\n } else if (\n propName === 'ɵmod' &&\n typeName.includes('NgModuleDeclaration') &&\n typeParams &&\n typeParams.length >= 4\n ) {\n // ɵɵNgModuleDeclaration<Module, Declarations, Imports, Exports>\n // Extract exported class names from the 4th type param (index 3).\n const exportsParam = typeParams[3];\n const exportedNames: string[] = [];\n if (exportsParam?.type === 'TSTupleType' && exportsParam.elementTypes) {\n for (const el of exportsParam.elementTypes) {\n if (\n el.type === 'TSTypeQuery' &&\n el.exprName?.type === 'Identifier'\n ) {\n exportedNames.push(el.exprName.name);\n } else if (\n el.type === 'TSTypeQuery' &&\n el.exprName?.type === 'TSQualifiedName'\n ) {\n // e.g. typeof i2.BidiModule → extract \"BidiModule\"\n const right = el.exprName.right;\n if (right?.type === 'Identifier') {\n exportedNames.push(right.name);\n }\n }\n }\n }\n entries.push({\n selector: className,\n kind: 'ngmodule',\n exports: exportedNames,\n fileName,\n className,\n });\n }\n }\n }\n}\n\n/**\n * Extract inputs from the type-argument at position [3].\n *\n * Handles two formats:\n * v16+: { \"prop\": { \"alias\": \"binding\"; \"required\": false; \"isSignal\"?: true } }\n * pre-v16: { \"prop\": \"binding\" }\n */\nfunction extractInputs(node: any): Record<string, RegistryInput> {\n const inputs: Record<string, RegistryInput> = {};\n if (node?.type !== 'TSTypeLiteral') return inputs;\n\n for (const member of node.members) {\n if (member.type !== 'TSPropertySignature') continue;\n const propName = keyName(member.key);\n const innerType = member.typeAnnotation?.typeAnnotation;\n if (!propName || !innerType) continue;\n\n if (innerType.type === 'TSTypeLiteral') {\n // v16+ object format\n let alias = propName;\n let required = false;\n let isSignal = false;\n\n for (const inner of innerType.members) {\n if (inner.type !== 'TSPropertySignature') continue;\n const key = keyName(inner.key);\n const val = inner.typeAnnotation?.typeAnnotation;\n if (!key || !val) continue;\n\n if (key === 'alias') {\n alias = literalString(val) ?? propName;\n } else if (key === 'required') {\n required = literalBoolean(val) === true;\n } else if (key === 'isSignal') {\n isSignal = literalBoolean(val) === true;\n }\n }\n\n inputs[propName] = {\n classPropertyName: propName,\n bindingPropertyName: alias,\n isSignal,\n required,\n };\n } else {\n // pre-v16 string format\n const alias = literalString(innerType);\n if (alias) {\n inputs[propName] = {\n classPropertyName: propName,\n bindingPropertyName: alias,\n isSignal: false,\n required: false,\n };\n }\n }\n }\n\n return inputs;\n}\n\n/**\n * Extract outputs from the type-argument at position [4].\n * Format: { \"propName\": \"eventName\" }\n */\nfunction extractOutputs(node: any): Record<string, string> {\n const outputs: Record<string, string> = {};\n if (node?.type !== 'TSTypeLiteral') return outputs;\n\n for (const member of node.members) {\n if (member.type !== 'TSPropertySignature') continue;\n const propName = keyName(member.key);\n const val = member.typeAnnotation?.typeAnnotation;\n if (!propName || !val) continue;\n\n const value = literalString(val);\n if (value) outputs[propName] = value;\n }\n\n return outputs;\n}\n\n/** Get the string name from a property key (Identifier or Literal). */\nfunction keyName(key: any): string | undefined {\n if (!key) return undefined;\n if (key.type === 'Identifier') return key.name;\n if (key.type === 'Literal' && typeof key.value === 'string') return key.value;\n return undefined;\n}\n\n/** Build a dotted name from an Identifier or TSQualifiedName. */\nfunction qualifiedName(node: any): string {\n if (!node) return '';\n if (node.type === 'Identifier') return node.name;\n if (node.type === 'TSQualifiedName')\n return qualifiedName(node.left) + '.' + qualifiedName(node.right);\n return '';\n}\n\n/** Extract a string value from a TSLiteralType node. */\nfunction literalString(node: any): string | undefined {\n if (\n node?.type === 'TSLiteralType' &&\n node.literal?.type === 'Literal' &&\n typeof node.literal.value === 'string'\n ) {\n return node.literal.value;\n }\n return undefined;\n}\n\n/** Extract a boolean value from a TSLiteralType node. */\nfunction literalBoolean(node: any): boolean | undefined {\n if (\n node?.type === 'TSLiteralType' &&\n node.literal?.type === 'Literal' &&\n typeof node.literal.value === 'boolean'\n ) {\n return node.literal.value;\n }\n return undefined;\n}\n\n/** Recursively collect all .d.ts files under a directory. */\nfunction collectDtsFiles(dir: string): string[] {\n const results: string[] = [];\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return results;\n }\n\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory() && entry.name !== 'node_modules') {\n results.push(...collectDtsFiles(full));\n } else if (entry.isFile() && entry.name.endsWith('.d.ts')) {\n results.push(full);\n }\n }\n\n return results;\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,YAAY,MAAc,UAAmC;CAE3E,IACE,CAAC,KAAK,SAAS,sBAAsB,KACrC,CAAC,KAAK,SAAS,sBAAsB,KACrC,CAAC,KAAK,SAAS,iBAAiB,KAChC,CAAC,KAAK,SAAS,qBAAqB,GAEpC,OAAO,CAAC;CAEV,MAAM,EAAE,YAAY,SAAS,UAAU,IAAI;CAC3C,MAAM,UAA2B,CAAC;CAElC,gBAAgB,QAAQ,MAAM,UAAU,OAAO;CAC/C,OAAO;AACT;;;;;;;;AASA,SAAgB,eACd,aACA,UACA,SACiB;CAIjB,IAAI,SAAS;CACb,IAAI,aAAa;CACjB,OAAO,eAAeA,OAAK,QAAQ,UAAU,GAAG;EAC9C,MAAM,YAAYA,OAAK,KAAK,YAAY,gBAAgB,WAAW;EACnE,IAAI,GAAG,WAAW,SAAS,GAAG;GAC5B,SAAS;GACT;EACF;EACA,aAAaA,OAAK,QAAQ,UAAU;CACtC;CACA,IAAI,CAAC,QAAQ,OAAO,CAAC;CAKrB,MAAM,oBAAoB,sBAAsB,aAAa,MAAM;CAInE,MAAM,WAAWA,OAAK,KAAK,QAAQ,OAAO;CAG1C,MAAM,WAAW,gBAFC,GAAG,WAAW,QAAQ,IAAI,WAAW,MAEb;CAC1C,MAAM,UAA2B,CAAC;CAKlC,MAAM,qCAAqB,IAAI,IAAY;CAE3C,KAAK,MAAM,QAAQ,UACjB,IAAI;EACF,MAAM,OAAO,GAAG,aAAa,MAAM,O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AK,IAAI;CAErB;CAEA,OAAO;AACT"}
@@ -12,5 +12,9 @@ import type { RegistryEntry } from "./registry.js";
12
12
  *
13
13
  * For directives and pipes, ɵɵreplaceMetadata does not support them, so
14
14
  * we fall back to a full page reload via import.meta.hot.invalidate().
15
+ *
16
+ * Every update re-executes the module and defines new classes, but Angular
17
+ * keeps rendering the classes from the first load. Those are kept in
18
+ * `import.meta.hot.data` so each update patches them, not the previous copy.
15
19
  */
16
20
  export declare function generateHmrCode(declarations: RegistryEntry[], localDepClassNames?: string[]): string;
@@ -1,4 +1,4 @@
1
- //#region packages/vite-plugin-angular/src/lib/compiler/hmr.ts
1
+ // packages/vite-plugin-angular/src/lib/compiler/hmr.ts
2
2
  /**
3
3
  * Generate HMR code using Angular's ɵɵreplaceMetadata for components,
4
4
  * and simple field-swap + invalidation for directives/pipes.
@@ -12,6 +12,10 @@
12
12
  *
13
13
  * For directives and pipes, ɵɵreplaceMetadata does not support them, so
14
14
  * we fall back to a full page reload via import.meta.hot.invalidate().
15
+ *
16
+ * Every update re-executes the module and defines new classes, but Angular
17
+ * keeps rendering the classes from the first load. Those are kept in
18
+ * `import.meta.hot.data` so each update patches them, not the previous copy.
15
19
  */
16
20
  function generateHmrCode(declarations, localDepClassNames = []) {
17
21
  const components = declarations.filter((d) => d.kind === "component");
@@ -26,7 +30,7 @@ export function ɵhmr_${c.className}(type) {
26
30
  const replaceBlocks = components.map((c) => `
27
31
  try {
28
32
  i0.ɵɵreplaceMetadata(
29
- ${c.className},
33
+ ɵhmrTypes.${c.className},
30
34
  newModule.ɵhmr_${c.className},
31
35
  { i0 },
32
36
  ${localDepsArray},
@@ -39,7 +43,7 @@ export function ɵhmr_${c.className}(type) {
39
43
  }`).join("\n");
40
44
  const swapBlocks = nonComponents.map((c) => `
41
45
  try {
42
- newModule.ɵhmr_${c.className}(${c.className});
46
+ newModule.ɵhmr_${c.className}(ɵhmrTypes.${c.className});
43
47
  swapped = true;
44
48
  } catch(e) {}`).join("\n");
45
49
  let acceptBody = `
@@ -59,11 +63,11 @@ export function ɵhmr_${c.className}(type) {
59
63
  }`;
60
64
  return `\n${applyFns}
61
65
  if (import.meta.hot) {
66
+ const ɵhmrTypes = (import.meta.hot.data.ɵhmrTypes ??= {});${declarations.map((c) => `\n ɵhmrTypes.${c.className} ??= ${c.className};`).join("")}
62
67
  import.meta.hot.accept((newModule) => {${acceptBody}
63
68
  });
64
69
  }`;
65
70
  }
66
- //#endregion
67
71
  export { generateHmrCode };
68
72
 
69
73
  //# sourceMappingURL=hmr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hmr.js","names":[],"sources":["../../../../src/lib/compiler/hmr.ts"],"sourcesContent":["import type { RegistryEntry } from './registry.js';\n\n/**\n * Generate HMR code using Angular's ɵɵreplaceMetadata for components,\n * and simple field-swap + invalidation for directives/pipes.\n *\n * The applyMetadata callback dynamically copies all ɵ-prefixed static\n * fields (ɵcmp, ɵfac, ɵdir, ɵpipe, etc.) from the newly compiled class\n * to the old class reference that Angular's runtime is tracking.\n *\n * For components, ɵɵreplaceMetadata then merges the old/new definitions\n * and recreates matching LViews in the component tree.\n *\n * For directives and pipes, ɵɵreplaceMetadata does not support them, so\n * we fall back to a full page reload via import.meta.hot.invalidate().\n */\nexport function generateHmrCode(\n declarations: RegistryEntry[],\n localDepClassNames: string[] = [],\n): string {\n const components = declarations.filter((d) => d.kind === 'component');\n const nonComponents = declarations.filter((d) => d.kind !== 'component');\n\n // Export applyMetadata functions so the accept callback can access them.\n // Dynamically copy all ɵ-prefixed static fields to handle ɵcmp, ɵfac,\n // ɵdir, ɵpipe, ɵmod, ɵinj, ɵprov, and any future Ivy fields.\n const applyFns = declarations\n .map(\n (c) => `\nexport function ɵhmr_${c.className}(type) {\n for (const key of Object.getOwnPropertyNames(${c.className})) {\n if (key.startsWith('ɵ')) type[key] = ${c.className}[key];\n }\n}`,\n )\n .join('\\n');\n\n // Components: use ɵɵreplaceMetadata for full LView recreation\n const localDepsArray =\n localDepClassNames.length > 0 ? `[${localDepClassNames.join(', ')}]` : '[]';\n\n const replaceBlocks = components\n .map(\n (c) => `\n try {\n i0.ɵɵreplaceMetadata(\n ${c.className},\n newModule.ɵhmr_${c.className},\n { i0 },\n ${localDepsArray},\n import.meta,\n \"${c.className}\"\n );\n replaced = true;\n } catch(e) {\n // ɵɵreplaceMetadata failed — will fall back to page reload\n }`,\n )\n .join('\\n');\n\n // Directives/pipes: swap static fields and invalidate\n const swapBlocks = nonComponents\n .map(\n (c) => `\n try {\n newModule.ɵhmr_${c.className}(${c.className});\n swapped = true;\n } catch(e) {}`,\n )\n .join('\\n');\n\n let acceptBody = `\n if (!newModule) return;`;\n\n if (components.length > 0) {\n acceptBody += `\n let replaced = false;${replaceBlocks}\n if (!replaced) {\n import.meta.hot.invalidate('Component HMR failed, reloading');\n return;\n }`;\n }\n\n if (nonComponents.length > 0) {\n acceptBody += `\n let swapped = false;${swapBlocks}\n if (swapped) {\n // Directive/pipe definitions updated — full reload needed for Angular\n // to pick up the new behavior since ɵɵreplaceMetadata only supports components.\n import.meta.hot.invalidate('Directive/pipe changed, reloading');\n }`;\n }\n\n return `\\n${applyFns}\nif (import.meta.hot) {\n import.meta.hot.accept((newModule) => {${acceptBody}\n });\n}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,gBACd,cACA,qBAA+B,CAAC,GACxB;CACR,MAAM,aAAa,aAAa,QAAQ,MAAM,EAAE,SAAS,WAAW;CACpE,MAAM,gBAAgB,aAAa,QAAQ,MAAM,EAAE,SAAS,WAAW;CAKvE,MAAM,WAAW,aACd,KACE,MAAM;uBACU,EAAE,UAAU;iDACc,EAAE,UAAU;2CAClB,EAAE,UAAU;;EAGnD,CAAC,CACA,KAAK,IAAI;CAGZ,MAAM,iBACJ,mBAAmB,SAAS,IAAI,IAAI,mBAAmB,KAAK,IAAI,EAAE,KAAK;CAEzE,MAAM,gBAAgB,WACnB,KACE,MAAM;;;YAGD,EAAE,UAAU;2BACG,EAAE,UAAU;;YAE3B,eAAe;;aAEd,EAAE,UAAU;;;;;QAMrB,CAAC,CACA,KAAK,IAAI;CAGZ,MAAM,aAAa,cAChB,KACE,MAAM;;yBAEY,EAAE,UAAU,GAAG,EAAE,UAAU;;oBAGhD,CAAC,CACA,KAAK,IAAI;CAEZ,IAAI,aAAa;;CAGjB,IAAI,WAAW,SAAS,GACtB,cAAc;2BACS,cAAc;;;;;CAOvC,IAAI,cAAc,SAAS,GACzB,cAAc;0BACQ,WAAW;;;;;;CAQnC,OAAO,KAAK,SAAS;;2CAEoB,WAAW;;;AAGtD"}
1
+ {"version":3,"file":"hmr.js","names":[],"sources":["../../../../src/lib/compiler/hmr.ts"],"sourcesContent":["import type { RegistryEntry } from './registry.js';\n\n/**\n * Generate HMR code using Angular's ɵɵreplaceMetadata for components,\n * and simple field-swap + invalidation for directives/pipes.\n *\n * The applyMetadata callback dynamically copies all ɵ-prefixed static\n * fields (ɵcmp, ɵfac, ɵdir, ɵpipe, etc.) from the newly compiled class\n * to the old class reference that Angular's runtime is tracking.\n *\n * For components, ɵɵreplaceMetadata then merges the old/new definitions\n * and recreates matching LViews in the component tree.\n *\n * For directives and pipes, ɵɵreplaceMetadata does not support them, so\n * we fall back to a full page reload via import.meta.hot.invalidate().\n *\n * Every update re-executes the module and defines new classes, but Angular\n * keeps rendering the classes from the first load. Those are kept in\n * `import.meta.hot.data` so each update patches them, not the previous copy.\n */\nexport function generateHmrCode(\n declarations: RegistryEntry[],\n localDepClassNames: string[] = [],\n): string {\n const components = declarations.filter((d) => d.kind === 'component');\n const nonComponents = declarations.filter((d) => d.kind !== 'component');\n\n // Export applyMetadata functions so the accept callback can access them.\n // Dynamically copy all ɵ-prefixed static fields to handle ɵcmp, ɵfac,\n // ɵdir, ɵpipe, ɵmod, ɵinj, ɵprov, and any future Ivy fields.\n const applyFns = declarations\n .map(\n (c) => `\nexport function ɵhmr_${c.className}(type) {\n for (const key of Object.getOwnPropertyNames(${c.className})) {\n if (key.startsWith('ɵ')) type[key] = ${c.className}[key];\n }\n}`,\n )\n .join('\\n');\n\n // Components: use ɵɵreplaceMetadata for full LView recreation\n const localDepsArray =\n localDepClassNames.length > 0 ? `[${localDepClassNames.join(', ')}]` : '[]';\n\n const replaceBlocks = components\n .map(\n (c) => `\n try {\n i0.ɵɵreplaceMetadata(\n ɵhmrTypes.${c.className},\n newModule.ɵhmr_${c.className},\n { i0 },\n ${localDepsArray},\n import.meta,\n \"${c.className}\"\n );\n replaced = true;\n } catch(e) {\n // ɵɵreplaceMetadata failed — will fall back to page reload\n }`,\n )\n .join('\\n');\n\n // Directives/pipes: swap static fields and invalidate\n const swapBlocks = nonComponents\n .map(\n (c) => `\n try {\n newModule.ɵhmr_${c.className}(ɵhmrTypes.${c.className});\n swapped = true;\n } catch(e) {}`,\n )\n .join('\\n');\n\n let acceptBody = `\n if (!newModule) return;`;\n\n if (components.length > 0) {\n acceptBody += `\n let replaced = false;${replaceBlocks}\n if (!replaced) {\n import.meta.hot.invalidate('Component HMR failed, reloading');\n return;\n }`;\n }\n\n if (nonComponents.length > 0) {\n acceptBody += `\n let swapped = false;${swapBlocks}\n if (swapped) {\n // Directive/pipe definitions updated — full reload needed for Angular\n // to pick up the new behavior since ɵɵreplaceMetadata only supports components.\n import.meta.hot.invalidate('Directive/pipe changed, reloading');\n }`;\n }\n\n const keepTypes = declarations\n .map((c) => `\\n ɵhmrTypes.${c.className} ??= ${c.className};`)\n .join('');\n\n return `\\n${applyFns}\nif (import.meta.hot) {\n const ɵhmrTypes = (import.meta.hot.data.ɵhmrTypes ??= {});${keepTypes}\n import.meta.hot.accept((newModule) => {${acceptBody}\n });\n}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,gBACd,cACA,qBAA+B,CAAC,GACxB;CACR,MAAM,aAAa,aAAa,QAAQ,MAAM,EAAE,SAAS,WAAW;CACpE,MAAM,gBAAgB,aAAa,QAAQ,MAAM,EAAE,SAAS,WAAW;CAKvE,MAAM,WAAW,aACd,KACE,MAAM;uBACU,EAAE,UAAU;iDACc,EAAE,UAAU;2CAClB,EAAE,UAAU;;EAGnD,CAAC,CACA,KAAK,IAAI;CAGZ,MAAM,iBACJ,mBAAmB,SAAS,IAAI,IAAI,mBAAmB,KAAK,IAAI,EAAE,KAAK;CAEzE,MAAM,gBAAgB,WACnB,KACE,MAAM;;;sBAGS,EAAE,UAAU;2BACP,EAAE,UAAU;;YAE3B,eAAe;;aAEd,EAAE,UAAU;;;;;QAMrB,CAAC,CACA,KAAK,IAAI;CAGZ,MAAM,aAAa,cAChB,KACE,MAAM;;yBAEY,EAAE,UAAU,aAAa,EAAE,UAAU;;oBAG1D,CAAC,CACA,KAAK,IAAI;CAEZ,IAAI,aAAa;;CAGjB,IAAI,WAAW,SAAS,GACtB,cAAc;2BACS,cAAc;;;;;CAOvC,IAAI,cAAc,SAAS,GACzB,cAAc;0BACQ,WAAW;;;;;;CAYnC,OAAO,KAAK,SAAS;;8DAJH,aACf,KAAK,MAAM,iBAAiB,EAAE,UAAU,OAAO,EAAE,UAAU,EAAE,CAAC,CAC9D,KAAK,EAIoD,EAAU;2CAC7B,WAAW;;;AAGtD"}
@@ -1,7 +1,7 @@
1
1
  export { compile, type CompileResult, type CompileOptions } from "./compile.js";
2
2
  export { ANGULAR_DECORATORS, ANGULAR_DECORATOR_CALL_RE } from "./constants.js";
3
- export { scanFile, type RegistryEntry, type ComponentRegistry } from "./registry.js";
4
- export { scanDtsFile, scanPackageDts, collectImportedPackages, collectRelativeReExports, collectAllImports } from "./dts-reader.js";
3
+ export { scanFile, declaresNonStandaloneComponent, type RegistryEntry, type ComponentRegistry } from "./registry.js";
4
+ export { scanDtsFile, scanPackageDts, collectImportedPackages, collectRelativeReExports, collectReExports, collectAllImports } from "./dts-reader.js";
5
5
  export { jitTransform, type JitTransformResult } from "./jit-transform.js";
6
6
  export { generateHmrCode } from "./hmr.js";
7
7
  export { inlineResourceUrls, extractInlineStyles } from "./resource-inliner.js";
@@ -1,9 +1,9 @@
1
- import { ANGULAR_DECORATOR_CALL_RE } from "./constants.js";
2
- import { debugCompile, debugRegistry } from "./debug.js";
3
1
  import { compile } from "./compile.js";
4
- import { scanFile } from "./registry.js";
5
- import { collectAllImports, collectImportedPackages, collectRelativeReExports, scanPackageDts } from "./dts-reader.js";
2
+ import { ANGULAR_DECORATOR_CALL_RE } from "./constants.js";
3
+ import { declaresNonStandaloneComponent, scanFile } from "./registry.js";
4
+ import { collectAllImports, collectImportedPackages, collectReExports, collectRelativeReExports, scanPackageDts } from "./dts-reader.js";
6
5
  import { jitTransform } from "./jit-transform.js";
7
- import { generateHmrCode } from "./hmr.js";
8
6
  import { extractInlineStyles, inlineResourceUrls } from "./resource-inliner.js";
9
- export { ANGULAR_DECORATOR_CALL_RE, collectAllImports, collectImportedPackages, collectRelativeReExports, compile, debugCompile, debugRegistry, extractInlineStyles, generateHmrCode, inlineResourceUrls, jitTransform, scanFile, scanPackageDts };
7
+ import { generateHmrCode } from "./hmr.js";
8
+ import { debugRegistry } from "./debug.js";
9
+ export { ANGULAR_DECORATOR_CALL_RE, collectAllImports, collectImportedPackages, collectReExports, collectRelativeReExports, compile, debugRegistry, declaresNonStandaloneComponent, extractInlineStyles, generateHmrCode, inlineResourceUrls, jitTransform, scanFile, scanPackageDts };
@@ -1,5 +1,5 @@
1
1
  import { FIELD_DECORATORS } from "./constants.js";
2
- //#region packages/vite-plugin-angular/src/lib/compiler/jit-metadata.ts
2
+ // packages/vite-plugin-angular/src/lib/compiler/jit-metadata.ts
3
3
  /**
4
4
  * JIT metadata helpers — OXC AST edition.
5
5
  *
@@ -169,7 +169,6 @@ function buildPropDecorators(classNode, sourceCode, coreNamespace = "") {
169
169
  if (entries.length === 0) return null;
170
170
  return `{${entries.map(([key, decs]) => `${key}: [${decs.join(", ")}]`).join(", ")}}`;
171
171
  }
172
- //#endregion
173
172
  export { buildCtorParameters, buildPropDecorators, findConstructor };
174
173
 
175
174
  //# sourceMappingURL=jit-metadata.js.map
@@ -1,9 +1,9 @@
1
- import { ANGULAR_DECORATORS, FIELD_DECORATORS } from "./constants.js";
1
+ import { parseOxc } from "./utils.js";
2
2
  import { detectTypeOnlyImportNames } from "./type-elision.js";
3
3
  import { buildCtorParameters, buildPropDecorators, findConstructor } from "./jit-metadata.js";
4
- import { parseSync } from "oxc-parser";
4
+ import { ANGULAR_DECORATORS, FIELD_DECORATORS } from "./constants.js";
5
5
  import MagicString from "magic-string";
6
- //#region packages/vite-plugin-angular/src/lib/compiler/jit-transform.ts
6
+ // packages/vite-plugin-angular/src/lib/compiler/jit-transform.ts
7
7
  /**
8
8
  * Recursively find all ClassDeclaration nodes in an OXC AST.
9
9
  * Handles top-level, exported, and nested classes (e.g. inside function scopes).
@@ -23,20 +23,37 @@ function findAllClasses(node) {
23
23
  return result;
24
24
  }
25
25
  /**
26
- * `@Injectable` and `@Service` stay on the class — their decorator functions
27
- * self-register ɵprov/ɵfac at class definition time and there is no JIT
28
- * compile entry point to call instead.
26
+ * `@Injectable` and `@Service` have no JIT compile entry point: their
27
+ * decorator functions self-register ɵprov/ɵfac when applied to the class.
29
28
  */
30
29
  function isSelfRegisteringDecorator(dec) {
31
30
  const name = dec.expression?.callee?.name;
32
31
  return name === "Injectable" || name === "Service";
33
32
  }
33
+ /**
34
+ * Whether jitTransform removes every class decorator. A decorator left for
35
+ * the TypeScript strip would run at class definition, ahead of a
36
+ * self-registering decorator applied after the class, reversing legacy order.
37
+ */
38
+ function removesEveryClassDecorator(decorators) {
39
+ return decorators.every((dec) => ANGULAR_DECORATORS.has(dec.expression?.callee?.name));
40
+ }
34
41
  /** Remove a decorator along with its trailing whitespace. */
35
42
  function removeDecorator(ms, sourceCode, dec) {
36
43
  let trimEnd = dec.end;
37
44
  while (trimEnd < sourceCode.length && /\s/.test(sourceCode[trimEnd])) trimEnd++;
38
45
  ms.remove(dec.start, trimEnd);
39
46
  }
47
+ /**
48
+ * Remove a self-registering decorator and return the statement that applies
49
+ * it to the class, as a legacy decorator runs. The output then needs no
50
+ * decorator lowering, which the TypeScript strip only does when tsconfig
51
+ * sets `experimentalDecorators`.
52
+ */
53
+ function applySelfRegisteringDecorator(ms, sourceCode, className, dec) {
54
+ removeDecorator(ms, sourceCode, dec);
55
+ return `${sourceCode.slice(dec.expression.start, dec.expression.end)}(${className});`;
56
+ }
40
57
  var DI_PARAM_DECORATORS = /* @__PURE__ */ new Set([
41
58
  "Inject",
42
59
  "Optional",
@@ -60,10 +77,8 @@ function ctorParamDecorators(classNode) {
60
77
  * provider option replaces the constructor, or when a non-DI parameter
61
78
  * decorator must keep running as written.
62
79
  */
63
- function needsInjectableCtorParameters(node, decorators) {
64
- const dec = decorators.find(isSelfRegisteringDecorator);
65
- const options = dec?.expression.arguments?.[0];
66
- return !!dec && node.type === "ClassDeclaration" && !options?.properties?.some((p) => PROVIDER_KEYS.has(p.key?.name)) && ctorParamDecorators(node).every((d) => DI_PARAM_DECORATORS.has(d.expression?.callee?.name));
80
+ function needsInjectableCtorParameters(node, dec) {
81
+ return !(dec.expression.arguments?.[0])?.properties?.some((p) => PROVIDER_KEYS.has(p.key?.name)) && ctorParamDecorators(node).every((d) => DI_PARAM_DECORATORS.has(d.expression?.callee?.name));
67
82
  }
68
83
  /**
69
84
  * JIT transform for Angular files.
@@ -85,7 +100,7 @@ function needsInjectableCtorParameters(node, decorators) {
85
100
  * faster parsing and source-position slicing instead of getText() calls.
86
101
  */
87
102
  function jitTransform(sourceCode, fileName) {
88
- const { program } = parseSync(fileName, sourceCode);
103
+ const { program } = parseOxc(fileName, sourceCode);
89
104
  const ms = new MagicString(sourceCode, { filename: fileName });
90
105
  const typeOnlyImports = detectTypeOnlyImportNames(sourceCode, program);
91
106
  let hasAngularClass = false;
@@ -105,13 +120,20 @@ function jitTransform(sourceCode, fileName) {
105
120
  });
106
121
  const className = node.id?.name;
107
122
  if (!className) continue;
123
+ const selfRegistering = node.type === "ClassDeclaration" ? decorators.find(isSelfRegisteringDecorator) : void 0;
124
+ const appliesSelfRegistering = !!selfRegistering && removesEveryClassDecorator(decorators);
108
125
  if (angularDecs.length === 0) {
109
- const ctorParams = needsInjectableCtorParameters(node, decorators) && buildCtorParameters(node, sourceCode, typeOnlyImports);
126
+ if (!selfRegistering) continue;
127
+ const statements = [];
128
+ const ctorParams = needsInjectableCtorParameters(node, selfRegistering) && buildCtorParameters(node, sourceCode, typeOnlyImports);
110
129
  if (ctorParams) {
111
- hasAngularClass = true;
112
130
  for (const dec of ctorParamDecorators(node)) removeDecorator(ms, sourceCode, dec);
113
- ms.appendLeft(node.end, `\n${className}.ctorParameters = () => [${ctorParams}];\n`);
131
+ statements.push(`${className}.ctorParameters = () => [${ctorParams}];`);
114
132
  }
133
+ if (appliesSelfRegistering) statements.push(applySelfRegisteringDecorator(ms, sourceCode, className, selfRegistering));
134
+ if (statements.length === 0) continue;
135
+ hasAngularClass = true;
136
+ ms.appendLeft(node.end, `\n${statements.join("\n")}\n`);
115
137
  continue;
116
138
  }
117
139
  hasAngularClass = true;
@@ -194,6 +216,7 @@ function jitTransform(sourceCode, fileName) {
194
216
  const members = node.body?.body || [];
195
217
  for (const member of members) for (const dec of member.decorators || []) removeDecorator(ms, sourceCode, dec);
196
218
  for (const dec of ctorParamDecorators(node)) removeDecorator(ms, sourceCode, dec);
219
+ if (appliesSelfRegistering) classStatements.push(applySelfRegisteringDecorator(ms, sourceCode, className, selfRegistering));
197
220
  if (classStatements.length > 0) {
198
221
  allEmittedStatements.push(...classStatements);
199
222
  ms.appendLeft(node.end, "\n" + classStatements.join("\n") + "\n");
@@ -224,7 +247,6 @@ function jitTransform(sourceCode, fileName) {
224
247
  map
225
248
  };
226
249
  }
227
- //#endregion
228
250
  export { jitTransform };
229
251
 
230
252
  //# sourceMappingURL=jit-transform.js.map