@analogjs/vite-plugin-angular 3.0.0-alpha.5 → 3.0.0-alpha.50

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 (194) hide show
  1. package/README.md +30 -0
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
  3. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
  4. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
  5. package/migrations/migration.json +7 -1
  6. package/migrations/migrations.json +9 -0
  7. package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
  8. package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
  9. package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
  10. package/package.json +41 -12
  11. package/src/index.d.ts +3 -2
  12. package/src/index.js +6 -2
  13. package/src/index.js.map +1 -1
  14. package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
  15. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  16. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  17. package/src/lib/angular-jit-plugin.d.ts +3 -3
  18. package/src/lib/angular-jit-plugin.js +39 -37
  19. package/src/lib/angular-jit-plugin.js.map +1 -1
  20. package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
  21. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  22. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  23. package/src/lib/angular-vite-plugin.d.ts +180 -44
  24. package/src/lib/angular-vite-plugin.js +1233 -969
  25. package/src/lib/angular-vite-plugin.js.map +1 -1
  26. package/src/lib/angular-vitest-plugin.d.ts +19 -15
  27. package/src/lib/angular-vitest-plugin.js +99 -114
  28. package/src/lib/angular-vitest-plugin.js.map +1 -1
  29. package/src/lib/compilation-api/compilation-api-plugin.d.ts +29 -0
  30. package/src/lib/compilation-api/compilation-api-plugin.js +469 -0
  31. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -0
  32. package/src/lib/compilation-api/index.d.ts +1 -0
  33. package/src/lib/compilation-api/index.js +1 -0
  34. package/src/lib/compiler/angular-version.d.ts +19 -0
  35. package/src/lib/compiler/angular-version.js +16 -0
  36. package/src/lib/compiler/angular-version.js.map +1 -0
  37. package/src/lib/compiler/class-field-lowering.d.ts +23 -0
  38. package/src/lib/compiler/class-field-lowering.js +131 -0
  39. package/src/lib/compiler/class-field-lowering.js.map +1 -0
  40. package/src/lib/compiler/compile.d.ts +44 -0
  41. package/src/lib/compiler/compile.js +731 -0
  42. package/src/lib/compiler/compile.js.map +1 -0
  43. package/src/lib/compiler/constants.d.ts +18 -0
  44. package/src/lib/compiler/constants.js +52 -0
  45. package/src/lib/compiler/constants.js.map +1 -0
  46. package/src/lib/compiler/debug.d.ts +22 -0
  47. package/src/lib/compiler/debug.js +20 -0
  48. package/src/lib/compiler/debug.js.map +1 -0
  49. package/src/lib/compiler/defer.d.ts +57 -0
  50. package/src/lib/compiler/defer.js +154 -0
  51. package/src/lib/compiler/defer.js.map +1 -0
  52. package/src/lib/compiler/dts-reader.d.ts +35 -0
  53. package/src/lib/compiler/dts-reader.js +365 -0
  54. package/src/lib/compiler/dts-reader.js.map +1 -0
  55. package/src/lib/compiler/hmr.d.ts +16 -0
  56. package/src/lib/compiler/hmr.js +69 -0
  57. package/src/lib/compiler/hmr.js.map +1 -0
  58. package/src/lib/compiler/index.d.ts +7 -0
  59. package/src/lib/compiler/index.js +7 -0
  60. package/src/lib/compiler/jit-metadata.d.ts +14 -0
  61. package/src/lib/compiler/jit-metadata.js +146 -0
  62. package/src/lib/compiler/jit-metadata.js.map +1 -0
  63. package/src/lib/compiler/jit-transform.d.ts +24 -0
  64. package/src/lib/compiler/jit-transform.js +200 -0
  65. package/src/lib/compiler/jit-transform.js.map +1 -0
  66. package/src/lib/compiler/js-emitter.d.ts +10 -0
  67. package/src/lib/compiler/js-emitter.js +445 -0
  68. package/src/lib/compiler/js-emitter.js.map +1 -0
  69. package/src/lib/compiler/metadata.d.ts +45 -0
  70. package/src/lib/compiler/metadata.js +633 -0
  71. package/src/lib/compiler/metadata.js.map +1 -0
  72. package/src/lib/compiler/registry.d.ts +49 -0
  73. package/src/lib/compiler/registry.js +164 -0
  74. package/src/lib/compiler/registry.js.map +1 -0
  75. package/src/lib/compiler/resource-inliner.d.ts +21 -0
  76. package/src/lib/compiler/resource-inliner.js +152 -0
  77. package/src/lib/compiler/resource-inliner.js.map +1 -0
  78. package/src/lib/compiler/style-ast.d.ts +8 -0
  79. package/src/lib/compiler/style-ast.js +54 -0
  80. package/src/lib/compiler/style-ast.js.map +1 -0
  81. package/src/lib/compiler/styles.d.ts +13 -0
  82. package/src/lib/compiler/test-helpers.d.ts +7 -0
  83. package/src/lib/compiler/type-elision.d.ts +26 -0
  84. package/src/lib/compiler/type-elision.js +211 -0
  85. package/src/lib/compiler/type-elision.js.map +1 -0
  86. package/src/lib/compiler/utils.d.ts +10 -0
  87. package/src/lib/compiler/utils.js +35 -0
  88. package/src/lib/compiler/utils.js.map +1 -0
  89. package/src/lib/compiler-plugin.d.ts +11 -11
  90. package/src/lib/compiler-plugin.js +43 -44
  91. package/src/lib/compiler-plugin.js.map +1 -1
  92. package/src/lib/component-resolvers.d.ts +23 -5
  93. package/src/lib/component-resolvers.js +153 -63
  94. package/src/lib/component-resolvers.js.map +1 -1
  95. package/src/lib/encapsulation-plugin.d.ts +13 -0
  96. package/src/lib/encapsulation-plugin.js +48 -0
  97. package/src/lib/encapsulation-plugin.js.map +1 -0
  98. package/src/lib/fast-compile-plugin.d.ts +28 -0
  99. package/src/lib/fast-compile-plugin.js +289 -0
  100. package/src/lib/fast-compile-plugin.js.map +1 -0
  101. package/src/lib/host.d.ts +10 -8
  102. package/src/lib/host.js +113 -101
  103. package/src/lib/host.js.map +1 -1
  104. package/src/lib/live-reload-plugin.d.ts +5 -5
  105. package/src/lib/live-reload-plugin.js +61 -62
  106. package/src/lib/live-reload-plugin.js.map +1 -1
  107. package/src/lib/models.d.ts +9 -9
  108. package/src/lib/nx-folder-plugin.d.ts +5 -5
  109. package/src/lib/nx-folder-plugin.js +18 -16
  110. package/src/lib/nx-folder-plugin.js.map +1 -1
  111. package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
  112. package/src/lib/plugins/file-replacements.plugin.js +40 -62
  113. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  114. package/src/lib/router-plugin.d.ts +1 -1
  115. package/src/lib/router-plugin.js +23 -23
  116. package/src/lib/router-plugin.js.map +1 -1
  117. package/src/lib/style-pipeline.d.ts +15 -0
  118. package/src/lib/style-pipeline.js +31 -0
  119. package/src/lib/style-pipeline.js.map +1 -0
  120. package/src/lib/style-preprocessor.d.ts +35 -0
  121. package/src/lib/style-preprocessor.js +35 -0
  122. package/src/lib/style-preprocessor.js.map +1 -0
  123. package/src/lib/stylesheet-registry.d.ts +73 -0
  124. package/src/lib/stylesheet-registry.js +168 -0
  125. package/src/lib/stylesheet-registry.js.map +1 -0
  126. package/src/lib/tailwind-plugin.d.ts +34 -0
  127. package/src/lib/tailwind-plugin.js +116 -0
  128. package/src/lib/tailwind-plugin.js.map +1 -0
  129. package/src/lib/template-class-binding-guard-plugin.d.ts +30 -0
  130. package/src/lib/template-class-binding-guard-plugin.js +237 -0
  131. package/src/lib/template-class-binding-guard-plugin.js.map +1 -0
  132. package/src/lib/tools/package.json +2 -7
  133. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
  134. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  135. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
  136. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  137. package/src/lib/tools/src/index.js +0 -2
  138. package/src/lib/utils/compilation-shared.d.ts +58 -0
  139. package/src/lib/utils/compilation-shared.js +133 -0
  140. package/src/lib/utils/compilation-shared.js.map +1 -0
  141. package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
  142. package/src/lib/utils/debug-harness.d.ts +23 -0
  143. package/src/lib/utils/debug-harness.js +88 -0
  144. package/src/lib/utils/debug-harness.js.map +1 -0
  145. package/src/lib/utils/debug-log-file.d.ts +5 -0
  146. package/src/lib/utils/debug-log-file.js +56 -0
  147. package/src/lib/utils/debug-log-file.js.map +1 -0
  148. package/src/lib/utils/debug.d.ts +28 -0
  149. package/src/lib/utils/debug.js +39 -0
  150. package/src/lib/utils/debug.js.map +1 -0
  151. package/src/lib/utils/devkit.d.ts +6 -6
  152. package/src/lib/utils/devkit.js +34 -38
  153. package/src/lib/utils/devkit.js.map +1 -1
  154. package/src/lib/utils/hmr-candidates.d.ts +28 -28
  155. package/src/lib/utils/plugin-config.d.ts +37 -0
  156. package/src/lib/utils/plugin-config.js +71 -0
  157. package/src/lib/utils/plugin-config.js.map +1 -0
  158. package/src/lib/utils/rolldown.d.ts +2 -0
  159. package/src/lib/utils/rolldown.js +12 -0
  160. package/src/lib/utils/rolldown.js.map +1 -0
  161. package/src/lib/utils/safe-module-paths.d.ts +16 -0
  162. package/src/lib/utils/safe-module-paths.js +29 -0
  163. package/src/lib/utils/safe-module-paths.js.map +1 -0
  164. package/src/lib/utils/source-file-cache.d.ts +8 -15
  165. package/src/lib/utils/source-file-cache.js +35 -37
  166. package/src/lib/utils/source-file-cache.js.map +1 -1
  167. package/src/lib/utils/tailwind-reference.d.ts +12 -0
  168. package/src/lib/utils/tailwind-reference.js +99 -0
  169. package/src/lib/utils/tailwind-reference.js.map +1 -0
  170. package/src/lib/utils/tsconfig-resolver.d.ts +28 -0
  171. package/src/lib/utils/tsconfig-resolver.js +191 -0
  172. package/src/lib/utils/tsconfig-resolver.js.map +1 -0
  173. package/src/lib/utils/virtual-ids.d.ts +4 -0
  174. package/src/lib/utils/virtual-ids.js +23 -0
  175. package/src/lib/utils/virtual-ids.js.map +1 -0
  176. package/src/lib/utils/virtual-resources.d.ts +19 -0
  177. package/src/lib/utils/virtual-resources.js +38 -0
  178. package/src/lib/utils/virtual-resources.js.map +1 -0
  179. package/src/lib/virtual-modules-plugin.d.ts +5 -0
  180. package/src/lib/virtual-modules-plugin.js +23 -0
  181. package/src/lib/virtual-modules-plugin.js.map +1 -0
  182. package/src/test-setup.d.ts +2 -0
  183. package/setup-vitest.d.ts +0 -4
  184. package/setup-vitest.js +0 -215
  185. package/setup-vitest.js.map +0 -1
  186. package/src/lib/models.js +0 -1
  187. package/src/lib/models.js.map +0 -1
  188. package/src/lib/tools/README.md +0 -3
  189. package/src/lib/tools/src/index.d.ts +0 -0
  190. package/src/lib/tools/src/index.js.map +0 -1
  191. package/src/lib/utils/compiler-plugin-options.js +0 -1
  192. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  193. package/src/lib/utils/hmr-candidates.js +0 -272
  194. package/src/lib/utils/hmr-candidates.js.map +0 -1
@@ -0,0 +1,731 @@
1
+ import { ANGULAR_DECORATORS, FIELD_DECORATORS } from "./constants.js";
2
+ import { findAllClasses } from "./utils.js";
3
+ import { detectTypeOnlyImportNames, elideTypeOnlyImportsMagicString } from "./type-elision.js";
4
+ import { emitAngularExpr, emitAngularStmt, setEmitterSourceCode, setEmitterSourceFile } from "./js-emitter.js";
5
+ import { lowerClassFields } from "./class-field-lowering.js";
6
+ import { collectStringConstants, detectFieldDecorators, detectSignals, extractConstructorDeps, extractMetadata } from "./metadata.js";
7
+ import { buildDeferDependencyMap } from "./defer.js";
8
+ import { debugCompile } from "./debug.js";
9
+ import { ANGULAR_MAJOR } from "./angular-version.js";
10
+ import * as fs from "node:fs";
11
+ import * as path$1 from "node:path";
12
+ import { parseSync } from "oxc-parser";
13
+ import * as ts from "typescript";
14
+ import * as o from "@angular/compiler";
15
+ import { ConstantPool, FactoryTarget, ParseLocation, ParseSourceFile, ParseSourceSpan, R3NgModuleMetadataKind, R3SelectorScopeMode, compileClassMetadata, compileComponentFromMetadata, compileDeclareClassMetadata, compileDeclareComponentFromMetadata, compileDeclareDirectiveFromMetadata, compileDeclareFactoryFunction, compileDeclareInjectableFromMetadata, compileDeclareInjectorFromMetadata, compileDeclareNgModuleFromMetadata, compileDeclarePipeFromMetadata, compileDirectiveFromMetadata, compileFactoryFunction, compileInjector, compileNgModule, compilePipeFromMetadata, makeBindingParser, parseHostBindings, parseTemplate } from "@angular/compiler";
16
+ import MagicString from "magic-string";
17
+ //#region packages/vite-plugin-angular/src/lib/compiler/compile.ts
18
+ function hasExportModifier(node) {
19
+ return ts.canHaveModifiers(node) && ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) === true;
20
+ }
21
+ /**
22
+ * Collect identifier names referenced in eagerly-evaluated code only.
23
+ * Skips function/arrow/class bodies so that lazy references
24
+ * (e.g. `const TOKEN = () => LaterClass`) are not treated as dependencies.
25
+ */
26
+ function collectIdentifiers(node) {
27
+ const ids = /* @__PURE__ */ new Set();
28
+ function walk(n) {
29
+ if (ts.isIdentifier(n)) ids.add(n.text);
30
+ if (ts.isFunctionLike(n) || ts.isClassLike(n)) return;
31
+ ts.forEachChild(n, walk);
32
+ }
33
+ ts.forEachChild(node, walk);
34
+ return ids;
35
+ }
36
+ /** Extract the names defined by a top-level statement. */
37
+ function getDefinedNames(stmt) {
38
+ if (ts.isVariableStatement(stmt)) {
39
+ const names = [];
40
+ for (const decl of stmt.declarationList.declarations) collectBindingNames(decl.name, names);
41
+ return names;
42
+ }
43
+ if (ts.isFunctionDeclaration(stmt) && stmt.name) return [stmt.name.text];
44
+ if (ts.isClassDeclaration(stmt) && stmt.name) return [stmt.name.text];
45
+ return [];
46
+ }
47
+ /** Recursively collect all bound identifiers from a binding name/pattern. */
48
+ function collectBindingNames(name, out) {
49
+ if (ts.isIdentifier(name)) out.push(name.text);
50
+ else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
51
+ for (const el of name.elements) if (!ts.isOmittedExpression(el)) collectBindingNames(el.name, out);
52
+ }
53
+ }
54
+ function compile(sourceCode, fileName, optionsOrRegistry) {
55
+ const opts = optionsOrRegistry instanceof Map ? { registry: optionsOrRegistry } : optionsOrRegistry || {};
56
+ const registry = opts.registry;
57
+ const resolvedStyles = opts.resolvedStyles;
58
+ const resolvedInlineStyles = opts.resolvedInlineStyles;
59
+ const useDefineForClassFields = opts.useDefineForClassFields ?? false;
60
+ const isPartial = opts.compilationMode === "partial";
61
+ const startTimeMs = debugCompile.enabled ? performance.now() : 0;
62
+ debugCompile("compile %s (mode=%s, registry=%d entries)", fileName, isPartial ? "partial" : "full", registry?.size ?? 0);
63
+ const origSourceFile = ts.createSourceFile(fileName, sourceCode, ts.ScriptTarget.Latest, true);
64
+ const { program: oxcProgram } = parseSync(fileName, sourceCode);
65
+ const oxcClassMap = /* @__PURE__ */ new Map();
66
+ for (const stmt of oxcProgram.body) {
67
+ const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
68
+ if (decl && (decl.type === "ClassDeclaration" || decl.type === "ClassExpression") && decl.id?.name) oxcClassMap.set(decl.id.name, decl);
69
+ }
70
+ const stringConsts = collectStringConstants(oxcProgram);
71
+ const constantPool = new ConstantPool();
72
+ const resourceDependencies = [];
73
+ const parseLoc = new ParseLocation(new ParseSourceFile(sourceCode, fileName), 0, 0, 0);
74
+ const typeSourceSpan = new ParseSourceSpan(parseLoc, parseLoc);
75
+ const typeOnlyImports = detectTypeOnlyImportNames(sourceCode);
76
+ const importSpecifierByName = /* @__PURE__ */ new Map();
77
+ const importedNames = /* @__PURE__ */ new Set();
78
+ for (const stmt of origSourceFile.statements) {
79
+ if (!ts.isImportDeclaration(stmt) || !stmt.importClause?.namedBindings || !ts.isNamedImports(stmt.importClause.namedBindings)) continue;
80
+ const moduleSpecifier = stmt.moduleSpecifier.text;
81
+ const isDeclarationTypeOnly = stmt.importClause.isTypeOnly;
82
+ for (const element of stmt.importClause.namedBindings.elements) {
83
+ const localName = element.name.text;
84
+ importedNames.add(localName);
85
+ importSpecifierByName.set(localName, moduleSpecifier);
86
+ if (isDeclarationTypeOnly || element.isTypeOnly) typeOnlyImports.add(localName);
87
+ }
88
+ }
89
+ const sourceFile = injectAngularImport(origSourceFile);
90
+ const localSelectors = /* @__PURE__ */ new Map();
91
+ if (!registry) for (const [clsName, oxcNode] of oxcClassMap) {
92
+ const decs = oxcNode.decorators || [];
93
+ if (decs.length > 0) {
94
+ const meta = extractMetadata(decs[0], sourceCode, stringConsts);
95
+ if (meta?.selector) localSelectors.set(clsName, meta.selector.split(",")[0].trim());
96
+ }
97
+ }
98
+ const bindingParser = isPartial ? void 0 : makeBindingParser();
99
+ setEmitterSourceFile(origSourceFile);
100
+ setEmitterSourceCode(sourceCode);
101
+ const classResults = [];
102
+ const hoistedHelpers = [];
103
+ const syntheticImports = /* @__PURE__ */ new Map();
104
+ for (const node of findAllClasses(origSourceFile)) {
105
+ const decorators = ts.getDecorators(node);
106
+ if (!decorators || decorators.length === 0) continue;
107
+ const className = node.name?.text;
108
+ if (!className) continue;
109
+ const angularDecorators = decorators.filter((dec) => {
110
+ if (!ts.isCallExpression(dec.expression)) return false;
111
+ const name = dec.expression.expression.getText(origSourceFile);
112
+ return ANGULAR_DECORATORS.has(name);
113
+ });
114
+ if (angularDecorators.length === 0) continue;
115
+ const ivyCode = [];
116
+ let targetType = FactoryTarget.Injectable;
117
+ const resolvedResources = /* @__PURE__ */ new Map();
118
+ const classRef = {
119
+ value: new o.WrappedNodeExpr(className),
120
+ type: new o.WrappedNodeExpr(className)
121
+ };
122
+ const extendsClause = node.heritageClauses?.find((h) => h.token === ts.SyntaxKind.ExtendsKeyword);
123
+ const usesInheritance = !!extendsClause && extendsClause.types.length > 0;
124
+ const oxcNode = oxcClassMap.get(className);
125
+ let classCompileError = null;
126
+ angularDecorators.forEach((dec) => {
127
+ const decoratorName = dec.expression.expression.getText(origSourceFile);
128
+ const oxcDec = oxcNode?.decorators?.find((d) => {
129
+ const expr = d.expression;
130
+ return expr?.type === "CallExpression" && expr.callee?.name === decoratorName;
131
+ });
132
+ const meta = extractMetadata(oxcDec, sourceCode, stringConsts);
133
+ const sigs = oxcNode ? detectSignals(oxcNode, sourceCode) : {
134
+ inputs: {},
135
+ outputs: {},
136
+ viewQueries: [],
137
+ contentQueries: []
138
+ };
139
+ const fields = oxcNode ? detectFieldDecorators(oxcNode, sourceCode) : {
140
+ inputs: {},
141
+ outputs: {},
142
+ viewQueries: [],
143
+ contentQueries: [],
144
+ hostProperties: {},
145
+ hostListeners: {}
146
+ };
147
+ const hostBindings = parseHostBindings(meta.hostRaw || {});
148
+ const hostMetadata = {
149
+ attributes: hostBindings.attributes,
150
+ listeners: {
151
+ ...hostBindings.listeners,
152
+ ...fields.hostListeners
153
+ },
154
+ properties: {
155
+ ...hostBindings.properties,
156
+ ...fields.hostProperties
157
+ },
158
+ specialAttributes: hostBindings.specialAttributes
159
+ };
160
+ switch (decoratorName) {
161
+ case "Component": {
162
+ targetType = FactoryTarget.Component;
163
+ if (!meta.selector) meta.selector = `ng-component-${className.toLowerCase()}`;
164
+ const declarations = [];
165
+ const seenDeclarationNames = /* @__PURE__ */ new Set();
166
+ const collectExpandedImports = (depClassName, visited) => {
167
+ if (visited.has(depClassName)) return [];
168
+ visited.add(depClassName);
169
+ const entry = registry?.get(depClassName);
170
+ if (!entry) return [depClassName];
171
+ if (entry.kind === "ngmodule" && entry.exports) {
172
+ const out = [];
173
+ for (const name of entry.exports) out.push(...collectExpandedImports(name, visited));
174
+ return out;
175
+ }
176
+ if (entry.kind === "tuple" && entry.members) {
177
+ const out = [];
178
+ for (const name of entry.members) out.push(...collectExpandedImports(name, visited));
179
+ return out;
180
+ }
181
+ return [depClassName];
182
+ };
183
+ for (const dep of Array.isArray(meta.imports) ? meta.imports : []) {
184
+ const depNode = dep.node;
185
+ const depClassName = typeof depNode === "string" ? depNode : depNode?.name ?? depNode?.type === "Identifier" ? depNode.name : sourceCode.slice(depNode?.start ?? 0, depNode?.end ?? 0);
186
+ const registryEntry = registry?.get(depClassName);
187
+ if (registryEntry?.kind === "tuple" && registryEntry.members) {
188
+ const expanded = collectExpandedImports(depClassName, /* @__PURE__ */ new Set());
189
+ const tupleSpecifier = importSpecifierByName.get(depClassName);
190
+ for (const memberName of expanded) {
191
+ const memberEntry = registry?.get(memberName);
192
+ if (!memberEntry || memberEntry.kind === "tuple") continue;
193
+ const memberRef = new o.WrappedNodeExpr(memberName);
194
+ if (memberEntry.sourcePackage || tupleSpecifier) {
195
+ if (!importedNames.has(memberName)) syntheticImports.set(memberName, memberEntry.sourcePackage || tupleSpecifier);
196
+ }
197
+ const kind = memberEntry.kind === "pipe" ? 1 : 0;
198
+ const memberDecl = {
199
+ type: memberRef,
200
+ selector: memberEntry.selector,
201
+ kind,
202
+ ...kind === 1 ? { name: memberEntry.pipeName } : {}
203
+ };
204
+ if (memberEntry.inputs) memberDecl.inputs = Object.values(memberEntry.inputs).map((i) => i.bindingPropertyName);
205
+ if (memberEntry.outputs) memberDecl.outputs = Object.values(memberEntry.outputs);
206
+ if (!seenDeclarationNames.has(memberName)) {
207
+ seenDeclarationNames.add(memberName);
208
+ declarations.push(memberDecl);
209
+ }
210
+ }
211
+ continue;
212
+ }
213
+ if (registryEntry?.kind === "ngmodule" && registryEntry.exports) {
214
+ const moduleSpecifier = importSpecifierByName.get(depClassName);
215
+ const allExports = [];
216
+ const expandModule = (moduleName, visited = /* @__PURE__ */ new Set()) => {
217
+ if (visited.has(moduleName)) return;
218
+ visited.add(moduleName);
219
+ const mod = registry?.get(moduleName);
220
+ if (!mod?.exports) return;
221
+ for (const name of mod.exports) {
222
+ const entry = registry?.get(name);
223
+ if (!entry) continue;
224
+ if (entry.kind === "ngmodule") expandModule(name, visited);
225
+ else allExports.push(name);
226
+ }
227
+ };
228
+ expandModule(depClassName);
229
+ for (const exportedName of allExports) {
230
+ const exportedEntry = registry?.get(exportedName);
231
+ if (exportedEntry) {
232
+ const kind = exportedEntry.kind === "pipe" ? 1 : 0;
233
+ const exportedRef = new o.WrappedNodeExpr(exportedName);
234
+ if (exportedEntry.sourcePackage || moduleSpecifier) syntheticImports.set(exportedName, exportedEntry.sourcePackage || moduleSpecifier);
235
+ const decl = {
236
+ type: exportedRef,
237
+ selector: exportedEntry.selector,
238
+ kind,
239
+ ...kind === 1 ? { name: exportedEntry.pipeName } : {}
240
+ };
241
+ if (exportedEntry.inputs) decl.inputs = Object.values(exportedEntry.inputs).map((i) => i.bindingPropertyName);
242
+ if (exportedEntry.outputs) decl.outputs = Object.values(exportedEntry.outputs);
243
+ if (!seenDeclarationNames.has(exportedName)) {
244
+ seenDeclarationNames.add(exportedName);
245
+ declarations.push(decl);
246
+ }
247
+ }
248
+ }
249
+ continue;
250
+ }
251
+ const selector = registryEntry?.selector ?? localSelectors.get(depClassName);
252
+ const kind = registryEntry?.kind === "pipe" ? 1 : 0;
253
+ const decl = {
254
+ type: dep,
255
+ selector: selector || `_unresolved-${depClassName}`,
256
+ kind,
257
+ ...kind === 1 ? { name: registryEntry?.pipeName } : {}
258
+ };
259
+ if (registryEntry?.inputs) decl.inputs = Object.values(registryEntry.inputs).map((i) => i.bindingPropertyName);
260
+ if (registryEntry?.outputs) decl.outputs = Object.values(registryEntry.outputs);
261
+ if (!seenDeclarationNames.has(depClassName)) {
262
+ seenDeclarationNames.add(depClassName);
263
+ declarations.push(decl);
264
+ }
265
+ }
266
+ if (!isPartial && !seenDeclarationNames.has(className)) {
267
+ const selfInputs = Object.entries(sigs.inputs).map(([, v]) => v.bindingPropertyName);
268
+ const selfOutputs = Object.values({
269
+ ...meta.outputs,
270
+ ...fields.outputs,
271
+ ...sigs.outputs
272
+ });
273
+ seenDeclarationNames.add(className);
274
+ declarations.push({
275
+ type: classRef.value,
276
+ selector: meta.selector,
277
+ kind: 0,
278
+ ...selfInputs.length > 0 ? { inputs: selfInputs } : {},
279
+ ...selfOutputs.length > 0 ? { outputs: selfOutputs } : {}
280
+ });
281
+ }
282
+ let templateContent = meta.template || "";
283
+ if (!templateContent && meta.templateUrl) try {
284
+ const templatePath = path$1.resolve(path$1.dirname(fileName), meta.templateUrl);
285
+ templateContent = fs.readFileSync(templatePath, "utf-8");
286
+ resourceDependencies.push(templatePath);
287
+ } catch {
288
+ console.warn(`[fast-compile] Could not read template file "${meta.templateUrl}" for ${className}`);
289
+ }
290
+ if (Array.isArray(meta.styleUrls)) for (const url of meta.styleUrls) try {
291
+ const stylePath = path$1.resolve(path$1.dirname(fileName), url);
292
+ const styleContent = resolvedStyles?.get(stylePath) ?? fs.readFileSync(stylePath, "utf-8");
293
+ meta.styles.push(styleContent);
294
+ resourceDependencies.push(stylePath);
295
+ } catch {
296
+ console.warn(`[fast-compile] Could not read style file "${url}" for ${className}`);
297
+ }
298
+ if (resolvedInlineStyles) {
299
+ for (const [idx, css] of resolvedInlineStyles) if (idx < meta.styles.length) meta.styles[idx] = css;
300
+ }
301
+ resolvedResources.set(dec, {
302
+ template: templateContent || void 0,
303
+ styles: meta.styles?.length > 0 ? [...meta.styles] : void 0
304
+ });
305
+ const parsedTemplate = parseTemplate(templateContent, fileName, {
306
+ preserveWhitespaces: meta.preserveWhitespaces,
307
+ enableI18nLegacyMessageIdFormat: opts.enableI18nLegacyMessageIdFormat ?? true,
308
+ i18nNormalizeLineEndingsInICUs: opts.i18nNormalizeLineEndingsInICUs ?? true
309
+ });
310
+ const ivyInputs = {};
311
+ if (Array.isArray(meta.inputs)) meta.inputs.forEach((i) => ivyInputs[i] = i);
312
+ else if (meta.inputs) Object.assign(ivyInputs, meta.inputs);
313
+ Object.assign(ivyInputs, fields.inputs);
314
+ for (const [key, val] of Object.entries(sigs.inputs)) {
315
+ const sigDesc = val;
316
+ ivyInputs[key] = {
317
+ classPropertyName: key,
318
+ bindingPropertyName: sigDesc.bindingPropertyName ?? key,
319
+ isSignal: true,
320
+ required: sigDesc.required || false,
321
+ transformFunction: sigDesc.transform || null
322
+ };
323
+ }
324
+ const templateErrors = parsedTemplate.errors ?? [];
325
+ if (templateErrors.length > 0) {
326
+ const firstError = templateErrors[0];
327
+ classCompileError = /* @__PURE__ */ new Error(`[fast-compile] Template parse error in ${fileName} (${className}): ${firstError.msg}`);
328
+ return;
329
+ }
330
+ const componentMeta = {
331
+ ...meta,
332
+ name: className,
333
+ type: classRef,
334
+ typeSourceSpan,
335
+ declarations,
336
+ template: {
337
+ nodes: parsedTemplate.nodes,
338
+ ngContentSelectors: parsedTemplate.ngContentSelectors,
339
+ preserveWhitespaces: parsedTemplate.preserveWhitespaces
340
+ },
341
+ styles: [...meta.styles || [], ...parsedTemplate.styles || []],
342
+ inputs: ivyInputs,
343
+ outputs: {
344
+ ...meta.outputs,
345
+ ...fields.outputs,
346
+ ...sigs.outputs
347
+ },
348
+ viewQueries: [...fields.viewQueries, ...sigs.viewQueries],
349
+ queries: [...fields.contentQueries, ...sigs.contentQueries],
350
+ host: hostMetadata,
351
+ changeDetection: meta.changeDetection ?? (isPartial ? null : 1),
352
+ encapsulation: meta.encapsulation ?? 0,
353
+ exportAs: meta.exportAs,
354
+ providers: meta.providers?.length ? new o.LiteralArrayExpr(meta.providers) : null,
355
+ viewProviders: meta.viewProviders?.length ? new o.LiteralArrayExpr(meta.viewProviders) : null,
356
+ animations: meta.animations?.length ? new o.LiteralArrayExpr(meta.animations) : null,
357
+ isStandalone: meta.standalone,
358
+ imports: meta.imports,
359
+ lifecycle: { usesOnChanges: false },
360
+ interpolation: o.DEFAULT_INTERPOLATION_CONFIG ?? {
361
+ start: "{{",
362
+ end: "}}"
363
+ },
364
+ usesInheritance,
365
+ defer: {
366
+ mode: 0,
367
+ blocks: buildDeferDependencyMap(parsedTemplate, sourceFile, registry, localSelectors).blocks
368
+ },
369
+ declarationListEmitMode: 1,
370
+ i18nUseExternalIds: opts.i18nUseExternalIds ?? false,
371
+ relativeContextFilePath: fileName,
372
+ controlCreate: null
373
+ };
374
+ if (ANGULAR_MAJOR < 18) {
375
+ componentMeta.deferBlocks = /* @__PURE__ */ new Map();
376
+ componentMeta.deferrableTypes = /* @__PURE__ */ new Map();
377
+ componentMeta.deferBlockDepsEmitMode = 0;
378
+ }
379
+ if (ANGULAR_MAJOR >= 20) componentMeta.hasDirectiveDependencies = declarations.length > 0 || Array.isArray(meta.imports) && meta.imports.length > 0;
380
+ if (isPartial) {
381
+ componentMeta.declarations = declarations.map((d) => ({
382
+ ...d,
383
+ inputs: d.inputs ?? null,
384
+ outputs: d.outputs ?? null,
385
+ exportAs: d.exportAs ?? null,
386
+ isComponent: d.isComponent ?? false
387
+ }));
388
+ const cmp = compileDeclareComponentFromMetadata(componentMeta, parsedTemplate, {
389
+ content: templateContent,
390
+ sourceUrl: fileName,
391
+ isInline: !meta.templateUrl,
392
+ inlineTemplateLiteralExpression: null
393
+ });
394
+ ivyCode.push(`static ɵcmp = /*@__PURE__*/ ${emitAngularExpr(cmp.expression)}`);
395
+ for (const stmt of cmp.statements ?? []) hoistedHelpers.push(emitAngularStmt(stmt));
396
+ } else {
397
+ const cmp = compileComponentFromMetadata(componentMeta, constantPool, bindingParser);
398
+ ivyCode.push(`static ɵcmp = /*@__PURE__*/ ${emitAngularExpr(cmp.expression)}`);
399
+ for (const stmt of cmp.statements ?? []) hoistedHelpers.push(emitAngularStmt(stmt));
400
+ }
401
+ break;
402
+ }
403
+ case "Directive": {
404
+ targetType = FactoryTarget.Directive;
405
+ const dirInputs = {};
406
+ if (Array.isArray(meta.inputs)) meta.inputs.forEach((i) => dirInputs[i] = i);
407
+ else if (meta.inputs) Object.assign(dirInputs, meta.inputs);
408
+ Object.assign(dirInputs, fields.inputs);
409
+ for (const [key, val] of Object.entries(sigs.inputs)) {
410
+ const sigDesc = val;
411
+ dirInputs[key] = {
412
+ classPropertyName: key,
413
+ bindingPropertyName: sigDesc.bindingPropertyName ?? key,
414
+ isSignal: true,
415
+ required: sigDesc.required || false,
416
+ transformFunction: sigDesc.transform || null
417
+ };
418
+ }
419
+ const directiveMeta = {
420
+ ...meta,
421
+ selector: meta.selector ?? null,
422
+ name: className,
423
+ type: classRef,
424
+ typeSourceSpan,
425
+ host: hostMetadata,
426
+ inputs: dirInputs,
427
+ outputs: {
428
+ ...meta.outputs,
429
+ ...fields.outputs,
430
+ ...sigs.outputs
431
+ },
432
+ viewQueries: [...fields.viewQueries, ...sigs.viewQueries],
433
+ queries: [...fields.contentQueries, ...sigs.contentQueries],
434
+ providers: meta.providers?.length ? new o.LiteralArrayExpr(meta.providers) : null,
435
+ exportAs: meta.exportAs,
436
+ isStandalone: meta.standalone,
437
+ lifecycle: { usesOnChanges: false },
438
+ usesInheritance,
439
+ controlCreate: null
440
+ };
441
+ if (isPartial) {
442
+ const dir = compileDeclareDirectiveFromMetadata(directiveMeta);
443
+ ivyCode.push(`static ɵdir = /*@__PURE__*/ ${emitAngularExpr(dir.expression)}`);
444
+ } else {
445
+ const dir = compileDirectiveFromMetadata(directiveMeta, constantPool, bindingParser);
446
+ ivyCode.push(`static ɵdir = /*@__PURE__*/ ${emitAngularExpr(dir.expression)}`);
447
+ }
448
+ break;
449
+ }
450
+ case "Pipe": {
451
+ targetType = FactoryTarget.Pipe;
452
+ const pipeMeta = {
453
+ ...meta,
454
+ name: className,
455
+ pipeName: meta.name,
456
+ type: classRef,
457
+ isStandalone: meta.standalone,
458
+ pure: meta.pure ?? true
459
+ };
460
+ if (isPartial) {
461
+ const pipe = compileDeclarePipeFromMetadata(pipeMeta);
462
+ ivyCode.push(`static ɵpipe = /*@__PURE__*/ ${emitAngularExpr(pipe.expression)}`);
463
+ } else {
464
+ const pipe = compilePipeFromMetadata(pipeMeta);
465
+ ivyCode.push(`static ɵpipe = /*@__PURE__*/ ${emitAngularExpr(pipe.expression)}`);
466
+ }
467
+ break;
468
+ }
469
+ case "Injectable": {
470
+ targetType = FactoryTarget.Injectable;
471
+ const injectableMeta = {
472
+ name: className,
473
+ type: classRef,
474
+ typeArgumentCount: 0,
475
+ providedIn: {
476
+ expression: new o.LiteralExpr(meta.providedIn || "root"),
477
+ forwardRef: 0
478
+ }
479
+ };
480
+ if (meta.useClass) injectableMeta.useClass = meta.useClass;
481
+ if (meta.useFactory) injectableMeta.useFactory = meta.useFactory;
482
+ if (meta.useExisting) injectableMeta.useExisting = meta.useExisting;
483
+ if (meta.useValue) injectableMeta.useValue = meta.useValue;
484
+ if (isPartial) {
485
+ const inj = compileDeclareInjectableFromMetadata(injectableMeta);
486
+ ivyCode.push(`static ɵprov = /*@__PURE__*/ ${emitAngularExpr(inj.expression)}`);
487
+ } else {
488
+ const inj = o.compileInjectable(injectableMeta, true);
489
+ ivyCode.push(`static ɵprov = /*@__PURE__*/ ${emitAngularExpr(inj.expression)}`);
490
+ }
491
+ break;
492
+ }
493
+ case "NgModule": {
494
+ targetType = FactoryTarget.NgModule;
495
+ const ngModuleImports = Array.isArray(meta.imports) ? meta.imports : [];
496
+ const ngModuleDeclarations = Array.isArray(meta.declarations) ? meta.declarations : [];
497
+ const ngModuleExports = Array.isArray(meta.exports) ? meta.exports : [];
498
+ const ngModuleBootstrap = Array.isArray(meta.bootstrap) ? meta.bootstrap : [];
499
+ const ngModuleMeta = {
500
+ kind: R3NgModuleMetadataKind.Global,
501
+ type: classRef,
502
+ bootstrap: ngModuleBootstrap.map((e) => ({
503
+ value: e,
504
+ type: e
505
+ })),
506
+ declarations: ngModuleDeclarations.map((e) => ({
507
+ value: e,
508
+ type: e
509
+ })),
510
+ publicDeclarationTypes: null,
511
+ imports: ngModuleImports.map((e) => ({
512
+ value: e,
513
+ type: e
514
+ })),
515
+ includeImportTypes: true,
516
+ exports: ngModuleExports.map((e) => ({
517
+ value: e,
518
+ type: e
519
+ })),
520
+ selectorScopeMode: R3SelectorScopeMode.Inline,
521
+ containsForwardDecls: false,
522
+ schemas: [],
523
+ id: null
524
+ };
525
+ const injectorMeta = {
526
+ name: className,
527
+ type: classRef,
528
+ providers: meta.providers ? new o.LiteralArrayExpr(meta.providers) : null,
529
+ imports: ngModuleImports.map((e) => e)
530
+ };
531
+ if (isPartial) {
532
+ const ngMod = compileDeclareNgModuleFromMetadata(ngModuleMeta);
533
+ ivyCode.push(`static ɵmod = /*@__PURE__*/ ${emitAngularExpr(ngMod.expression)}`);
534
+ const injector = compileDeclareInjectorFromMetadata(injectorMeta);
535
+ ivyCode.push(`static ɵinj = /*@__PURE__*/ ${emitAngularExpr(injector.expression)}`);
536
+ } else {
537
+ const ngMod = compileNgModule(ngModuleMeta);
538
+ ivyCode.push(`static ɵmod = /*@__PURE__*/ ${emitAngularExpr(ngMod.expression)}`);
539
+ const injector = compileInjector(injectorMeta);
540
+ ivyCode.push(`static ɵinj = /*@__PURE__*/ ${emitAngularExpr(injector.expression)}`);
541
+ }
542
+ break;
543
+ }
544
+ }
545
+ });
546
+ if (classCompileError) throw classCompileError;
547
+ const deps = oxcNode ? extractConstructorDeps(oxcNode, sourceCode, typeOnlyImports) : [];
548
+ if (deps === null) {
549
+ const baseVar = `ɵ${className}_BaseFactory`;
550
+ ivyCode.unshift(`static ɵfac = /*@__PURE__*/ (() => { let ${baseVar}; return function ${className}_Factory(__ngFactoryType__) { return (${baseVar} || (${baseVar} = i0.ɵɵgetInheritedFactory(${className})))(__ngFactoryType__ || ${className}); }; })()`);
551
+ } else if (deps === "invalid") ivyCode.unshift(`static ɵfac = function ${className}_Factory(__ngFactoryType__) { i0.ɵɵinvalidFactory(); }`);
552
+ else {
553
+ const factoryMeta = {
554
+ name: className,
555
+ type: classRef,
556
+ typeArgumentCount: 0,
557
+ deps,
558
+ target: targetType
559
+ };
560
+ if (isPartial) {
561
+ const fac = compileDeclareFactoryFunction(factoryMeta);
562
+ ivyCode.unshift(`static ɵfac = /*@__PURE__*/ ${emitAngularExpr(fac.expression)}`);
563
+ } else {
564
+ const fac = compileFactoryFunction(factoryMeta);
565
+ ivyCode.unshift(`static ɵfac = /*@__PURE__*/ ${emitAngularExpr(fac.expression)}`);
566
+ }
567
+ }
568
+ angularDecorators.forEach((dec) => {
569
+ const call = dec.expression;
570
+ const decName = call.expression.getText(origSourceFile);
571
+ const decArgsNode = call.arguments[0];
572
+ const resources = resolvedResources.get(dec);
573
+ let metadataArgsExpr = null;
574
+ if (decArgsNode) if (resources && ts.isObjectLiteralExpression(decArgsNode)) {
575
+ const rewrittenProps = [];
576
+ let needsTransform = false;
577
+ for (const prop of decArgsNode.properties) {
578
+ if (!ts.isPropertyAssignment(prop)) {
579
+ rewrittenProps.push(prop.getText(origSourceFile));
580
+ continue;
581
+ }
582
+ const propName = prop.name?.getText(origSourceFile);
583
+ if (propName === "templateUrl" && resources.template) {
584
+ rewrittenProps.push(`template: ${JSON.stringify(resources.template)}`);
585
+ needsTransform = true;
586
+ } else if ((propName === "styleUrl" || propName === "styleUrls") && resources.styles?.length) {
587
+ rewrittenProps.push(`styles: [${resources.styles.map((s) => JSON.stringify(s)).join(", ")}]`);
588
+ needsTransform = true;
589
+ } else rewrittenProps.push(prop.getText(origSourceFile));
590
+ }
591
+ metadataArgsExpr = needsTransform ? `{${rewrittenProps.join(", ")}}` : decArgsNode.getText(origSourceFile);
592
+ } else metadataArgsExpr = decArgsNode.getText(origSourceFile);
593
+ try {
594
+ const classMetaInput = {
595
+ type: new o.WrappedNodeExpr(ts.factory.createIdentifier(className)),
596
+ decorators: new o.LiteralArrayExpr([new o.LiteralMapExpr([{
597
+ key: "type",
598
+ value: new o.WrappedNodeExpr(decName),
599
+ quoted: false
600
+ }, ...metadataArgsExpr ? [{
601
+ key: "args",
602
+ value: new o.LiteralArrayExpr([new o.WrappedNodeExpr(metadataArgsExpr)]),
603
+ quoted: false
604
+ }] : []])]),
605
+ ctorParameters: null,
606
+ propDecorators: null
607
+ };
608
+ const classMetadataExpr = isPartial ? compileDeclareClassMetadata(classMetaInput) : compileClassMetadata(classMetaInput);
609
+ constantPool.statements.push(new o.ExpressionStatement(classMetadataExpr));
610
+ } catch (e) {
611
+ if (debugCompile.enabled) debugCompile("compileClassMetadata failed for %s in %s: %s", className, fileName, e?.message);
612
+ }
613
+ });
614
+ const memberDecorators = [];
615
+ for (const member of node.members) {
616
+ const mDecorators = ts.getDecorators(member);
617
+ if (!mDecorators) continue;
618
+ for (const dec of mDecorators) {
619
+ if (!ts.isCallExpression(dec.expression)) continue;
620
+ const decName = dec.expression.expression.getText(origSourceFile);
621
+ if (FIELD_DECORATORS.has(decName)) memberDecorators.push(dec);
622
+ }
623
+ }
624
+ classResults.push({
625
+ ivyCode,
626
+ decorators: [...angularDecorators, ...memberDecorators],
627
+ classEnd: node.getEnd()
628
+ });
629
+ }
630
+ const ms = new MagicString(sourceCode, { filename: fileName });
631
+ if (!sourceCode.includes("import * as i0 from")) ms.prepend("import * as i0 from \"@angular/core\";\n");
632
+ for (const [name, specifier] of syntheticImports) if (!importedNames.has(name)) {
633
+ ms.prepend(`import { ${name} } from "${specifier}";\n`);
634
+ importedNames.add(name);
635
+ }
636
+ if (classResults.length > 0) {
637
+ let firstClassPos = Infinity;
638
+ const nonHoistableNames = /* @__PURE__ */ new Set();
639
+ for (const stmt of origSourceFile.statements) if (ts.isClassDeclaration(stmt)) {
640
+ firstClassPos = stmt.getStart(origSourceFile);
641
+ if (stmt.name) nonHoistableNames.add(stmt.name.text);
642
+ break;
643
+ }
644
+ for (const stmt of origSourceFile.statements) {
645
+ if (stmt.getStart(origSourceFile) <= firstClassPos) continue;
646
+ if (ts.isClassDeclaration(stmt) && stmt.name) nonHoistableNames.add(stmt.name.text);
647
+ if (ts.isEnumDeclaration(stmt)) nonHoistableNames.add(stmt.name.text);
648
+ if (ts.isVariableStatement(stmt) && hasExportModifier(stmt)) for (const decl of stmt.declarationList.declarations) {
649
+ const names = [];
650
+ collectBindingNames(decl.name, names);
651
+ for (const n of names) nonHoistableNames.add(n);
652
+ }
653
+ if (ts.isFunctionDeclaration(stmt) && hasExportModifier(stmt) && stmt.name) nonHoistableNames.add(stmt.name.text);
654
+ }
655
+ for (const stmt of origSourceFile.statements) {
656
+ const stmtStart = stmt.getStart(origSourceFile);
657
+ if (stmtStart <= firstClassPos) continue;
658
+ if (!(ts.isVariableStatement(stmt) && !hasExportModifier(stmt) || ts.isFunctionDeclaration(stmt) && !hasExportModifier(stmt))) continue;
659
+ const referencedIds = collectIdentifiers(stmt);
660
+ let referencesNonHoistable = false;
661
+ for (const id of referencedIds) if (nonHoistableNames.has(id)) {
662
+ referencesNonHoistable = true;
663
+ break;
664
+ }
665
+ if (referencesNonHoistable) for (const name of getDefinedNames(stmt)) nonHoistableNames.add(name);
666
+ else {
667
+ const text = stmt.getText(origSourceFile);
668
+ ms.remove(stmtStart, stmt.getEnd());
669
+ ms.appendLeft(firstClassPos, text + "\n");
670
+ }
671
+ }
672
+ }
673
+ for (const cr of classResults) {
674
+ for (const dec of cr.decorators) {
675
+ const start = dec.getStart(origSourceFile);
676
+ let trimEnd = dec.getEnd();
677
+ while (trimEnd < sourceCode.length && (sourceCode[trimEnd] === " " || sourceCode[trimEnd] === "\n" || sourceCode[trimEnd] === "\r")) trimEnd++;
678
+ ms.remove(start, trimEnd);
679
+ }
680
+ if (cr.ivyCode.length > 0) {
681
+ const memberCode = cr.ivyCode.map((c) => " " + c + ";").join("\n");
682
+ ms.appendLeft(cr.classEnd - 1, "\n" + memberCode + "\n");
683
+ }
684
+ }
685
+ const helpers = [];
686
+ const sideEffects = [];
687
+ helpers.push(...hoistedHelpers);
688
+ for (const s of constantPool.statements) {
689
+ const code = emitAngularStmt(s);
690
+ if (s instanceof o.ExpressionStatement && s.expr instanceof o.InvokeFunctionExpr) sideEffects.push(`/*@__PURE__*/ ${code}`);
691
+ else helpers.push(code);
692
+ }
693
+ if (helpers.length > 0) {
694
+ const willElide = detectTypeOnlyImportNames(ms.toString());
695
+ let insertPos = 0;
696
+ for (const stmt of origSourceFile.statements) if (ts.isImportDeclaration(stmt)) {
697
+ if (willElide.size > 0 && stmt.importClause) {
698
+ const clause = stmt.importClause;
699
+ const namedBindings = clause.namedBindings && ts.isNamedImports(clause.namedBindings) ? clause.namedBindings.elements : void 0;
700
+ const defaultName = clause.name;
701
+ if ((!defaultName || willElide.has(defaultName.text)) && (!namedBindings || namedBindings.every((el) => el.isTypeOnly || willElide.has(el.name.text)))) continue;
702
+ }
703
+ insertPos = stmt.getEnd();
704
+ } else if (ts.isVariableStatement(stmt) && !stmt.getText(origSourceFile).includes("class")) insertPos = stmt.getEnd();
705
+ else if (!ts.isExportAssignment(stmt)) break;
706
+ if (insertPos === 0) ms.appendLeft(0, helpers.join("\n") + "\n");
707
+ else ms.appendRight(insertPos, "\n" + helpers.join("\n") + "\n");
708
+ }
709
+ if (sideEffects.length > 0) ms.append("\n\n" + sideEffects.join("\n"));
710
+ if (!useDefineForClassFields) lowerClassFields(ms, sourceCode, oxcProgram);
711
+ elideTypeOnlyImportsMagicString(ms);
712
+ const map = ms.generateMap({
713
+ source: fileName,
714
+ file: fileName + ".js",
715
+ includeContent: true,
716
+ hires: "boundary"
717
+ });
718
+ if (debugCompile.enabled) debugCompile("compile %s done (%dms, %d classes, %d resource deps)", fileName, Math.round(performance.now() - startTimeMs), classResults.length, resourceDependencies.length);
719
+ return {
720
+ code: ms.toString(),
721
+ map,
722
+ resourceDependencies
723
+ };
724
+ }
725
+ function injectAngularImport(sf) {
726
+ return ts.factory.updateSourceFile(sf, [ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamespaceImport(ts.factory.createIdentifier("i0"))), ts.factory.createStringLiteral("@angular/core")), ...sf.statements]);
727
+ }
728
+ //#endregion
729
+ export { compile };
730
+
731
+ //# sourceMappingURL=compile.js.map