@analogjs/vite-plugin-angular 3.0.0-beta.62 → 3.0.0-beta.63
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.
- package/package.json +1 -1
- package/src/lib/compiler/registry.d.ts +2 -0
- package/src/lib/compiler/registry.js +12 -3
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/component-scanner.d.ts +29 -2
- package/src/lib/component-scanner.js +172 -18
- package/src/lib/component-scanner.js.map +1 -1
- package/src/lib/fast-compile-api.d.ts +1 -1
- package/src/lib/fast-compile-api.js.map +1 -1
- package/src/lib/fast-compile-plugin.js +58 -12
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/ngp-compile-api.d.ts +1 -1
- package/src/lib/ngp-compile-api.js.map +1 -1
- package/src/lib/ngp-compile-plugin.js +4 -1
- package/src/lib/ngp-compile-plugin.js.map +1 -1
package/package.json
CHANGED
|
@@ -46,6 +46,8 @@ export interface RegistryEntry {
|
|
|
46
46
|
outputs?: Record<string, string>;
|
|
47
47
|
/** The package this declaration was scanned from (e.g. "@angular/cdk") */
|
|
48
48
|
sourcePackage?: string;
|
|
49
|
+
/** Whether this declaration is the file's default export */
|
|
50
|
+
isDefaultExport?: boolean;
|
|
49
51
|
}
|
|
50
52
|
/** Maps class name → registry entry */
|
|
51
53
|
export type ComponentRegistry = Map<string, RegistryEntry>;
|
|
@@ -38,11 +38,17 @@ function scanFile(code, fileName, program) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
let defaultExportedName;
|
|
42
|
+
for (const node of program.body) if (node.type === "ExportDefaultDeclaration" && node.declaration?.type === "Identifier") defaultExportedName = node.declaration.name;
|
|
43
|
+
else if (node.type === "ExportNamedDeclaration" && !node.source) {
|
|
44
|
+
for (const spec of node.specifiers || []) if ((spec.exported?.type === "Identifier" ? spec.exported.name : spec.exported?.value) === "default" && spec.local?.type === "Identifier") defaultExportedName = spec.local.name;
|
|
45
|
+
}
|
|
41
46
|
for (const node of program.body) {
|
|
42
47
|
const decl = node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
43
48
|
if (!decl || decl.type !== "ClassDeclaration") continue;
|
|
44
49
|
if (!decl.id?.name) continue;
|
|
45
50
|
const className = decl.id.name;
|
|
51
|
+
const isDefaultExport = node.type === "ExportDefaultDeclaration" || className === defaultExportedName;
|
|
46
52
|
const decorators = decl.decorators || [];
|
|
47
53
|
for (const dec of decorators) {
|
|
48
54
|
const expr = dec.expression;
|
|
@@ -79,14 +85,16 @@ function scanFile(code, fileName, program) {
|
|
|
79
85
|
declarations: moduleDeclarations || [],
|
|
80
86
|
imports: moduleImports || [],
|
|
81
87
|
fileName,
|
|
82
|
-
className
|
|
88
|
+
className,
|
|
89
|
+
...isDefaultExport ? { isDefaultExport: true } : {}
|
|
83
90
|
});
|
|
84
91
|
else if (decoratorName === "Pipe" && pipeName) entries.push({
|
|
85
92
|
selector: pipeName,
|
|
86
93
|
kind: "pipe",
|
|
87
94
|
pipeName,
|
|
88
95
|
fileName,
|
|
89
|
-
className
|
|
96
|
+
className,
|
|
97
|
+
...isDefaultExport ? { isDefaultExport: true } : {}
|
|
90
98
|
});
|
|
91
99
|
else if (selector) {
|
|
92
100
|
const inputs = {};
|
|
@@ -163,7 +171,8 @@ function scanFile(code, fileName, program) {
|
|
|
163
171
|
fileName,
|
|
164
172
|
className,
|
|
165
173
|
...Object.keys(inputs).length > 0 ? { inputs } : {},
|
|
166
|
-
...Object.keys(outputs).length > 0 ? { outputs } : {}
|
|
174
|
+
...Object.keys(outputs).length > 0 ? { outputs } : {},
|
|
175
|
+
...isDefaultExport ? { isDefaultExport: true } : {}
|
|
167
176
|
});
|
|
168
177
|
}
|
|
169
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":[],"sources":["../../../../src/lib/compiler/registry.ts"],"sourcesContent":["import type { parseSync } from 'oxc-parser';\nimport { parseOxc } from './utils.js';\nimport { COMPILABLE_DECORATORS } from './constants.js';\n\nexport interface RegistryInput {\n classPropertyName: string;\n bindingPropertyName: string;\n isSignal: boolean;\n required: boolean;\n /**\n * `true` when the input declares a `transform` function. The actual\n * transform expression isn't usable cross-file, but downstream tools\n * (template type checking, codegen widening) need to know whether\n * one exists so they can broaden the accepted binding type.\n */\n hasTransform?: boolean;\n}\n\nexport interface RegistryEntry {\n /** CSS selector for components/directives, pipe name for pipes, class name for NgModules */\n selector: string;\n /** What kind of Angular declaration this is */\n kind: 'component' | 'directive' | 'pipe' | 'ngmodule' | 'tuple';\n /** The pipe name (only for pipes) */\n pipeName?: string;\n /** Exported class names (only for NgModules) */\n exports?: string[];\n /** Declared class names (only for NgModules) — used to wire non-standalone\n * component scope from the declaring module. */\n declarations?: string[];\n /** Imported module/class names (only for NgModules) — expanded transitively\n * to compute the directive/pipe scope of declared components. */\n imports?: string[];\n /**\n * Member class names (only for `tuple` kind) — produced by top-level\n * `export const X = [A, B, C] as const` style barrels common in\n * helm/spartan-style libraries. The compiler expands these into the\n * underlying directives when they appear in another component's\n * `imports` array, mirroring how Angular's official compiler resolves\n * static `imports` references at compile time.\n */\n members?: string[];\n /** The source file this declaration was found in */\n fileName: string;\n /** The class name */\n className: string;\n /** Input bindings (from signal APIs and @Input decorators) */\n inputs?: Record<string, RegistryInput>;\n /** Output bindings (from signal APIs and @Output decorators) */\n outputs?: Record<string, string>;\n /** The package this declaration was scanned from (e.g. \"@angular/cdk\") */\n sourcePackage?: string;\n}\n\n/** Maps class name → registry entry */\nexport type ComponentRegistry = Map<string, RegistryEntry>;\n\nconst DECORATOR_RE = new RegExp(`@(${[...COMPILABLE_DECORATORS].join('|')})`);\n\n/**\n * Lightweight scan of a TypeScript file to extract Angular decorator metadata\n * without performing full compilation. Uses OXC's native Rust parser for speed.\n */\nexport function scanFile(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): RegistryEntry[] {\n const entries: RegistryEntry[] = [];\n\n // Fast regex pre-filter — skip files with neither Angular decorators\n // nor a top-level `const X = [...]` that might be a directive tuple\n // barrel re-export.\n if (!DECORATOR_RE.test(code) && !/\\bconst\\s+\\w+\\s*=\\s*\\[/.test(code)) {\n return entries;\n }\n\n program ??= parseOxc(fileName, code).program;\n\n // First pass: collect tuple barrels — top-level `const X = [A, B, C]`\n // (with or without `export`/`as const`) where every element is a bare\n // class identifier. These are how spartan-style libraries expose a\n // group of directives behind a single import (e.g. `HlmSelectImports`).\n // Without registering them, the fast-compile path treats the bare\n // identifier as an unknown directive and Angular's runtime never\n // matches the underlying classes.\n for (const node of program.body) {\n const varDecl =\n node.type === 'ExportNamedDeclaration' &&\n (node as any).declaration?.type === 'VariableDeclaration'\n ? (node as any).declaration\n : node.type === 'VariableDeclaration'\n ? node\n : null;\n if (!varDecl || varDecl.kind !== 'const') continue;\n for (const declarator of varDecl.declarations || []) {\n if (declarator.id?.type !== 'Identifier') continue;\n // Unwrap `arr as const` → ArrayExpression\n let init = declarator.init;\n if (init?.type === 'TSAsExpression') init = init.expression;\n if (init?.type !== 'ArrayExpression') continue;\n const members: string[] = [];\n let allClassRefs = true;\n for (const el of init.elements || []) {\n if (el?.type !== 'Identifier') {\n allClassRefs = false;\n break;\n }\n members.push(el.name);\n }\n if (!allClassRefs || members.length === 0) continue;\n const tupleName: string = declarator.id.name;\n entries.push({\n selector: tupleName,\n kind: 'tuple',\n members,\n fileName,\n className: tupleName,\n });\n }\n }\n\n for (const node of program.body) {\n // Handle `class Foo {}`, `export class Foo {}`, and `export default class Foo {}`\n const decl =\n node.type === 'ExportNamedDeclaration' ||\n node.type === 'ExportDefaultDeclaration'\n ? (node as any).declaration\n : node;\n if (!decl || decl.type !== 'ClassDeclaration') continue;\n // Skip anonymous default exports (no name to register)\n if (!decl.id?.name) continue;\n\n const className: string = decl.id.name;\n const decorators: any[] = decl.decorators || [];\n\n for (const dec of decorators) {\n const expr = dec.expression;\n if (!expr || expr.type !== 'CallExpression') continue;\n\n const decoratorName: string = expr.callee?.name;\n if (!COMPILABLE_DECORATORS.has(decoratorName)) continue;\n\n const arg = expr.arguments?.[0];\n if (!arg || arg.type !== 'ObjectExpression') continue;\n\n let selector: string | undefined;\n let pipeName: string | undefined;\n let moduleExports: string[] | undefined;\n let moduleDeclarations: string[] | undefined;\n let moduleImports: string[] | undefined;\n\n // Class names from an NgModule metadata array: bare `Identifier`s and the\n // module out of `Module.forRoot(...)`/`forChild(...)` ModuleWithProviders.\n const classNamesFrom = (val: any): string[] =>\n (val?.elements ?? [])\n .map((e: any) => {\n if (e?.type === 'Identifier') return e.name;\n if (\n e?.type === 'CallExpression' &&\n // OXC emits `StaticMemberExpression`; the ESTree shape some\n // versions produce uses `MemberExpression`. Accept both (matches\n // the other member-expression checks in this file).\n (e.callee?.type === 'StaticMemberExpression' ||\n e.callee?.type === 'MemberExpression') &&\n e.callee.object?.type === 'Identifier'\n ) {\n return e.callee.object.name;\n }\n return undefined;\n })\n .filter((n: unknown): n is string => typeof n === 'string');\n\n for (const prop of arg.properties) {\n if (prop.type !== 'Property') continue;\n const key: string = prop.key?.name || prop.key?.value;\n const val = prop.value;\n\n if (\n key === 'selector' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string'\n ) {\n selector = val.value;\n }\n if (\n key === 'name' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string' &&\n decoratorName === 'Pipe'\n ) {\n pipeName = val.value;\n }\n if (val?.type === 'ArrayExpression' && decoratorName === 'NgModule') {\n if (key === 'exports') moduleExports = classNamesFrom(val);\n else if (key === 'declarations')\n moduleDeclarations = classNamesFrom(val);\n else if (key === 'imports') moduleImports = classNamesFrom(val);\n }\n }\n\n if (decoratorName === 'NgModule') {\n entries.push({\n selector: className,\n kind: 'ngmodule',\n exports: moduleExports || [],\n declarations: moduleDeclarations || [],\n imports: moduleImports || [],\n fileName,\n className,\n });\n } else if (decoratorName === 'Pipe' && pipeName) {\n entries.push({\n selector: pipeName,\n kind: 'pipe',\n pipeName,\n fileName,\n className,\n });\n } else if (selector) {\n // Extract inputs/outputs from class members\n const inputs: Record<string, RegistryInput> = {};\n const outputs: Record<string, string> = {};\n const members: any[] = decl.body?.body || [];\n\n for (const member of members) {\n if (member.type !== 'PropertyDefinition' || !member.key?.name)\n continue;\n const name: string = member.key.name;\n const init = member.value;\n\n // Signal APIs: input(), input.required(), model(), output()\n if (init?.type === 'CallExpression') {\n const callee = init.callee;\n let calleeName = '';\n if (callee?.type === 'Identifier') {\n calleeName = callee.name;\n } else if (\n callee?.type === 'StaticMemberExpression' ||\n callee?.type === 'MemberExpression'\n ) {\n calleeName =\n (callee.object?.name || '') +\n '.' +\n (callee.property?.name || '');\n }\n\n // Extract `alias` from an options object at the given\n // argument index. Used for input/model (options at index 1,\n // or 0 for the `.required` variants) and for output (options\n // at index 0). Without this, host-directive mappings that\n // reference the public name (e.g. `inputs: ['aria-label']`,\n // `outputs: ['publicEvent']`) fail to resolve.\n const aliasFromArg = (argIndex: number): string | null => {\n const optionsArg = init.arguments?.[argIndex];\n if (optionsArg?.type !== 'ObjectExpression') return null;\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = prop.key?.name ?? prop.key?.value;\n if (k !== 'alias') continue;\n const v = prop.value;\n if (\n v?.type === 'StringLiteral' ||\n (v?.type === 'Literal' && typeof v.value === 'string')\n ) {\n return v.value;\n }\n }\n return null;\n };\n // Detect a `transform: ...` entry in the input options object\n // so cross-file consumers know the binding type is widened.\n const hasTransformAtArg = (argIndex: number): boolean => {\n const optionsArg = init.arguments?.[argIndex];\n if (optionsArg?.type !== 'ObjectExpression') return false;\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = prop.key?.name ?? prop.key?.value;\n if (k === 'transform') return true;\n }\n return false;\n };\n const inputAliasIndex =\n calleeName === 'input.required' || calleeName === 'model.required'\n ? 0\n : 1;\n\n if (calleeName === 'input' || calleeName === 'input.required') {\n const alias = aliasFromArg(inputAliasIndex);\n const hasTransform = hasTransformAtArg(inputAliasIndex);\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias ?? name,\n isSignal: true,\n required: calleeName === 'input.required',\n ...(hasTransform ? { hasTransform: true } : {}),\n };\n } else if (\n calleeName === 'model' ||\n calleeName === 'model.required'\n ) {\n const alias = aliasFromArg(inputAliasIndex);\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias ?? name,\n isSignal: true,\n required: calleeName === 'model.required',\n };\n // outputs map is `{ classPropertyName: bindingName }` —\n // for a model, the class property is `name` and the\n // binding name is `${aliasOrName}Change`.\n outputs[name] = (alias ?? name) + 'Change';\n } else if (\n calleeName === 'output' ||\n calleeName === 'outputFromObservable'\n ) {\n // output() options at arg[0]; outputFromObservable(source,\n // opts?) options at arg[1].\n const alias = aliasFromArg(\n calleeName === 'outputFromObservable' ? 1 : 0,\n );\n outputs[name] = alias ?? name;\n }\n }\n\n // Decorator-based: @Input(), @Output()\n const memberDecorators: any[] = member.decorators || [];\n for (const mdec of memberDecorators) {\n const mexpr = mdec.expression;\n if (!mexpr) continue;\n const mdecName =\n mexpr.type === 'CallExpression'\n ? mexpr.callee?.name\n : mexpr.type === 'Identifier'\n ? mexpr.name\n : undefined;\n if (mdecName === 'Input') {\n const alias =\n mexpr.arguments?.[0]?.type === 'Literal'\n ? mexpr.arguments[0].value\n : name;\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias || name,\n isSignal: false,\n required: false,\n };\n } else if (mdecName === 'Output') {\n const alias =\n mexpr.arguments?.[0]?.type === 'Literal'\n ? mexpr.arguments[0].value\n : name;\n outputs[name] = alias || name;\n }\n }\n }\n\n entries.push({\n selector: selector.split(',')[0].trim(),\n kind: decoratorName === 'Component' ? 'component' : 'directive',\n fileName,\n className,\n ...(Object.keys(inputs).length > 0 ? { inputs } : {}),\n ...(Object.keys(outputs).length > 0 ? { outputs } : {}),\n });\n }\n }\n }\n\n return entries;\n}\n\n/**\n * Whether the file declares a `@Component({ standalone: false })`. Such a\n * component's template scope comes from the NgModule that declares it, which\n * can only be found by scanning the whole project.\n */\nexport function declaresNonStandaloneComponent(\n program: ReturnType<typeof parseSync>['program'],\n): boolean {\n for (const node of program.body) {\n const decl =\n node.type === 'ExportNamedDeclaration' ||\n node.type === 'ExportDefaultDeclaration'\n ? (node as any).declaration\n : node;\n if (decl?.type !== 'ClassDeclaration') continue;\n for (const dec of decl.decorators || []) {\n const expr = dec.expression;\n if (expr?.type !== 'CallExpression') continue;\n if (expr.callee?.name !== 'Component') continue;\n const arg = expr.arguments?.[0];\n if (arg?.type !== 'ObjectExpression') continue;\n for (const prop of arg.properties) {\n if (\n prop.type === 'Property' &&\n (prop.key?.name || prop.key?.value) === 'standalone' &&\n prop.value?.type === 'Literal' &&\n prop.value.value === false\n ) {\n return true;\n }\n }\n }\n }\n return false;\n}\n"],"mappings":";;;AAyDA,IAAM,eAAe,IAAI,OAAO,KAAK,CAAC,GAAG,qBAAqB,CAAC,CAAC,KAAK,GAAG,EAAE,EAAE;;;;;AAM5E,SAAgB,SACd,MACA,UACA,SACiB;CACjB,MAAM,UAA2B,CAAC;CAKlC,IAAI,CAAC,aAAa,KAAK,IAAI,KAAK,CAAC,yBAAyB,KAAK,IAAI,GACjE,OAAO;CAGT,YAAY,SAAS,UAAU,IAAI,CAAC,CAAC;CASrC,KAAK,MAAM,QAAQ,QAAQ,MAAM;EAC/B,MAAM,UACJ,KAAK,SAAS,4BACb,KAAa,aAAa,SAAS,wBAC/B,KAAa,cACd,KAAK,SAAS,wBACZ,OACA;EACR,IAAI,CAAC,WAAW,QAAQ,SAAS,SAAS;EAC1C,KAAK,MAAM,cAAc,QAAQ,gBAAgB,CAAC,GAAG;GACnD,IAAI,WAAW,IAAI,SAAS,cAAc;GAE1C,IAAI,OAAO,WAAW;GACtB,IAAI,MAAM,SAAS,kBAAkB,OAAO,KAAK;GACjD,IAAI,MAAM,SAAS,m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AK,MAAM,QAAQ,IAAI,YACrB,IACE,KAAK,SAAS,eACb,KAAK,KAAK,QAAQ,KAAK,KAAK,WAAW,gBACxC,KAAK,OAAO,SAAS,aACrB,KAAK,MAAM,UAAU,OAErB,OAAO;EAGb;CACF;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../../../src/lib/compiler/registry.ts"],"sourcesContent":["import type { parseSync } from 'oxc-parser';\nimport { parseOxc } from './utils.js';\nimport { COMPILABLE_DECORATORS } from './constants.js';\n\nexport interface RegistryInput {\n classPropertyName: string;\n bindingPropertyName: string;\n isSignal: boolean;\n required: boolean;\n /**\n * `true` when the input declares a `transform` function. The actual\n * transform expression isn't usable cross-file, but downstream tools\n * (template type checking, codegen widening) need to know whether\n * one exists so they can broaden the accepted binding type.\n */\n hasTransform?: boolean;\n}\n\nexport interface RegistryEntry {\n /** CSS selector for components/directives, pipe name for pipes, class name for NgModules */\n selector: string;\n /** What kind of Angular declaration this is */\n kind: 'component' | 'directive' | 'pipe' | 'ngmodule' | 'tuple';\n /** The pipe name (only for pipes) */\n pipeName?: string;\n /** Exported class names (only for NgModules) */\n exports?: string[];\n /** Declared class names (only for NgModules) — used to wire non-standalone\n * component scope from the declaring module. */\n declarations?: string[];\n /** Imported module/class names (only for NgModules) — expanded transitively\n * to compute the directive/pipe scope of declared components. */\n imports?: string[];\n /**\n * Member class names (only for `tuple` kind) — produced by top-level\n * `export const X = [A, B, C] as const` style barrels common in\n * helm/spartan-style libraries. The compiler expands these into the\n * underlying directives when they appear in another component's\n * `imports` array, mirroring how Angular's official compiler resolves\n * static `imports` references at compile time.\n */\n members?: string[];\n /** The source file this declaration was found in */\n fileName: string;\n /** The class name */\n className: string;\n /** Input bindings (from signal APIs and @Input decorators) */\n inputs?: Record<string, RegistryInput>;\n /** Output bindings (from signal APIs and @Output decorators) */\n outputs?: Record<string, string>;\n /** The package this declaration was scanned from (e.g. \"@angular/cdk\") */\n sourcePackage?: string;\n /** Whether this declaration is the file's default export */\n isDefaultExport?: boolean;\n}\n\n/** Maps class name → registry entry */\nexport type ComponentRegistry = Map<string, RegistryEntry>;\n\nconst DECORATOR_RE = new RegExp(`@(${[...COMPILABLE_DECORATORS].join('|')})`);\n\n/**\n * Lightweight scan of a TypeScript file to extract Angular decorator metadata\n * without performing full compilation. Uses OXC's native Rust parser for speed.\n */\nexport function scanFile(\n code: string,\n fileName: string,\n program?: ReturnType<typeof parseSync>['program'],\n): RegistryEntry[] {\n const entries: RegistryEntry[] = [];\n\n // Fast regex pre-filter — skip files with neither Angular decorators\n // nor a top-level `const X = [...]` that might be a directive tuple\n // barrel re-export.\n if (!DECORATOR_RE.test(code) && !/\\bconst\\s+\\w+\\s*=\\s*\\[/.test(code)) {\n return entries;\n }\n\n program ??= parseOxc(fileName, code).program;\n\n // First pass: collect tuple barrels — top-level `const X = [A, B, C]`\n // (with or without `export`/`as const`) where every element is a bare\n // class identifier. These are how spartan-style libraries expose a\n // group of directives behind a single import (e.g. `HlmSelectImports`).\n // Without registering them, the fast-compile path treats the bare\n // identifier as an unknown directive and Angular's runtime never\n // matches the underlying classes.\n for (const node of program.body) {\n const varDecl =\n node.type === 'ExportNamedDeclaration' &&\n (node as any).declaration?.type === 'VariableDeclaration'\n ? (node as any).declaration\n : node.type === 'VariableDeclaration'\n ? node\n : null;\n if (!varDecl || varDecl.kind !== 'const') continue;\n for (const declarator of varDecl.declarations || []) {\n if (declarator.id?.type !== 'Identifier') continue;\n // Unwrap `arr as const` → ArrayExpression\n let init = declarator.init;\n if (init?.type === 'TSAsExpression') init = init.expression;\n if (init?.type !== 'ArrayExpression') continue;\n const members: string[] = [];\n let allClassRefs = true;\n for (const el of init.elements || []) {\n if (el?.type !== 'Identifier') {\n allClassRefs = false;\n break;\n }\n members.push(el.name);\n }\n if (!allClassRefs || members.length === 0) continue;\n const tupleName: string = declarator.id.name;\n entries.push({\n selector: tupleName,\n kind: 'tuple',\n members,\n fileName,\n className: tupleName,\n });\n }\n }\n\n // Collect the local identifier name of a separate `export default Foo` or\n // `export { Foo as default }` so classes declared earlier are marked too.\n let defaultExportedName: string | undefined;\n for (const node of program.body) {\n if (\n node.type === 'ExportDefaultDeclaration' &&\n (node as any).declaration?.type === 'Identifier'\n ) {\n defaultExportedName = (node as any).declaration.name;\n } else if (\n node.type === 'ExportNamedDeclaration' &&\n !(node as any).source\n ) {\n for (const spec of (node as any).specifiers || []) {\n const exported =\n spec.exported?.type === 'Identifier'\n ? spec.exported.name\n : spec.exported?.value;\n if (exported === 'default' && spec.local?.type === 'Identifier') {\n defaultExportedName = spec.local.name;\n }\n }\n }\n }\n\n for (const node of program.body) {\n // Handle `class Foo {}`, `export class Foo {}`, and `export default class Foo {}`\n const decl =\n node.type === 'ExportNamedDeclaration' ||\n node.type === 'ExportDefaultDeclaration'\n ? (node as any).declaration\n : node;\n if (!decl || decl.type !== 'ClassDeclaration') continue;\n // Skip anonymous default exports (no name to register)\n if (!decl.id?.name) continue;\n\n const className: string = decl.id.name;\n const isDefaultExport =\n node.type === 'ExportDefaultDeclaration' ||\n className === defaultExportedName;\n const decorators: any[] = decl.decorators || [];\n\n for (const dec of decorators) {\n const expr = dec.expression;\n if (!expr || expr.type !== 'CallExpression') continue;\n\n const decoratorName: string = expr.callee?.name;\n if (!COMPILABLE_DECORATORS.has(decoratorName)) continue;\n\n const arg = expr.arguments?.[0];\n if (!arg || arg.type !== 'ObjectExpression') continue;\n\n let selector: string | undefined;\n let pipeName: string | undefined;\n let moduleExports: string[] | undefined;\n let moduleDeclarations: string[] | undefined;\n let moduleImports: string[] | undefined;\n\n // Class names from an NgModule metadata array: bare `Identifier`s and the\n // module out of `Module.forRoot(...)`/`forChild(...)` ModuleWithProviders.\n const classNamesFrom = (val: any): string[] =>\n (val?.elements ?? [])\n .map((e: any) => {\n if (e?.type === 'Identifier') return e.name;\n if (\n e?.type === 'CallExpression' &&\n // OXC emits `StaticMemberExpression`; the ESTree shape some\n // versions produce uses `MemberExpression`. Accept both (matches\n // the other member-expression checks in this file).\n (e.callee?.type === 'StaticMemberExpression' ||\n e.callee?.type === 'MemberExpression') &&\n e.callee.object?.type === 'Identifier'\n ) {\n return e.callee.object.name;\n }\n return undefined;\n })\n .filter((n: unknown): n is string => typeof n === 'string');\n\n for (const prop of arg.properties) {\n if (prop.type !== 'Property') continue;\n const key: string = prop.key?.name || prop.key?.value;\n const val = prop.value;\n\n if (\n key === 'selector' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string'\n ) {\n selector = val.value;\n }\n if (\n key === 'name' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string' &&\n decoratorName === 'Pipe'\n ) {\n pipeName = val.value;\n }\n if (val?.type === 'ArrayExpression' && decoratorName === 'NgModule') {\n if (key === 'exports') moduleExports = classNamesFrom(val);\n else if (key === 'declarations')\n moduleDeclarations = classNamesFrom(val);\n else if (key === 'imports') moduleImports = classNamesFrom(val);\n }\n }\n\n if (decoratorName === 'NgModule') {\n entries.push({\n selector: className,\n kind: 'ngmodule',\n exports: moduleExports || [],\n declarations: moduleDeclarations || [],\n imports: moduleImports || [],\n fileName,\n className,\n ...(isDefaultExport ? { isDefaultExport: true } : {}),\n });\n } else if (decoratorName === 'Pipe' && pipeName) {\n entries.push({\n selector: pipeName,\n kind: 'pipe',\n pipeName,\n fileName,\n className,\n ...(isDefaultExport ? { isDefaultExport: true } : {}),\n });\n } else if (selector) {\n // Extract inputs/outputs from class members\n const inputs: Record<string, RegistryInput> = {};\n const outputs: Record<string, string> = {};\n const members: any[] = decl.body?.body || [];\n\n for (const member of members) {\n if (member.type !== 'PropertyDefinition' || !member.key?.name)\n continue;\n const name: string = member.key.name;\n const init = member.value;\n\n // Signal APIs: input(), input.required(), model(), output()\n if (init?.type === 'CallExpression') {\n const callee = init.callee;\n let calleeName = '';\n if (callee?.type === 'Identifier') {\n calleeName = callee.name;\n } else if (\n callee?.type === 'StaticMemberExpression' ||\n callee?.type === 'MemberExpression'\n ) {\n calleeName =\n (callee.object?.name || '') +\n '.' +\n (callee.property?.name || '');\n }\n\n // Extract `alias` from an options object at the given\n // argument index. Used for input/model (options at index 1,\n // or 0 for the `.required` variants) and for output (options\n // at index 0). Without this, host-directive mappings that\n // reference the public name (e.g. `inputs: ['aria-label']`,\n // `outputs: ['publicEvent']`) fail to resolve.\n const aliasFromArg = (argIndex: number): string | null => {\n const optionsArg = init.arguments?.[argIndex];\n if (optionsArg?.type !== 'ObjectExpression') return null;\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = prop.key?.name ?? prop.key?.value;\n if (k !== 'alias') continue;\n const v = prop.value;\n if (\n v?.type === 'StringLiteral' ||\n (v?.type === 'Literal' && typeof v.value === 'string')\n ) {\n return v.value;\n }\n }\n return null;\n };\n // Detect a `transform: ...` entry in the input options object\n // so cross-file consumers know the binding type is widened.\n const hasTransformAtArg = (argIndex: number): boolean => {\n const optionsArg = init.arguments?.[argIndex];\n if (optionsArg?.type !== 'ObjectExpression') return false;\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = prop.key?.name ?? prop.key?.value;\n if (k === 'transform') return true;\n }\n return false;\n };\n const inputAliasIndex =\n calleeName === 'input.required' || calleeName === 'model.required'\n ? 0\n : 1;\n\n if (calleeName === 'input' || calleeName === 'input.required') {\n const alias = aliasFromArg(inputAliasIndex);\n const hasTransform = hasTransformAtArg(inputAliasIndex);\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias ?? name,\n isSignal: true,\n required: calleeName === 'input.required',\n ...(hasTransform ? { hasTransform: true } : {}),\n };\n } else if (\n calleeName === 'model' ||\n calleeName === 'model.required'\n ) {\n const alias = aliasFromArg(inputAliasIndex);\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias ?? name,\n isSignal: true,\n required: calleeName === 'model.required',\n };\n // outputs map is `{ classPropertyName: bindingName }` —\n // for a model, the class property is `name` and the\n // binding name is `${aliasOrName}Change`.\n outputs[name] = (alias ?? name) + 'Change';\n } else if (\n calleeName === 'output' ||\n calleeName === 'outputFromObservable'\n ) {\n // output() options at arg[0]; outputFromObservable(source,\n // opts?) options at arg[1].\n const alias = aliasFromArg(\n calleeName === 'outputFromObservable' ? 1 : 0,\n );\n outputs[name] = alias ?? name;\n }\n }\n\n // Decorator-based: @Input(), @Output()\n const memberDecorators: any[] = member.decorators || [];\n for (const mdec of memberDecorators) {\n const mexpr = mdec.expression;\n if (!mexpr) continue;\n const mdecName =\n mexpr.type === 'CallExpression'\n ? mexpr.callee?.name\n : mexpr.type === 'Identifier'\n ? mexpr.name\n : undefined;\n if (mdecName === 'Input') {\n const alias =\n mexpr.arguments?.[0]?.type === 'Literal'\n ? mexpr.arguments[0].value\n : name;\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias || name,\n isSignal: false,\n required: false,\n };\n } else if (mdecName === 'Output') {\n const alias =\n mexpr.arguments?.[0]?.type === 'Literal'\n ? mexpr.arguments[0].value\n : name;\n outputs[name] = alias || name;\n }\n }\n }\n\n entries.push({\n selector: selector.split(',')[0].trim(),\n kind: decoratorName === 'Component' ? 'component' : 'directive',\n fileName,\n className,\n ...(Object.keys(inputs).length > 0 ? { inputs } : {}),\n ...(Object.keys(outputs).length > 0 ? { outputs } : {}),\n ...(isDefaultExport ? { isDefaultExport: true } : {}),\n });\n }\n }\n }\n\n return entries;\n}\n\n/**\n * Whether the file declares a `@Component({ standalone: false })`. Such a\n * component's template scope comes from the NgModule that declares it, which\n * can only be found by scanning the whole project.\n */\nexport function declaresNonStandaloneComponent(\n program: ReturnType<typeof parseSync>['program'],\n): boolean {\n for (const node of program.body) {\n const decl =\n node.type === 'ExportNamedDeclaration' ||\n node.type === 'ExportDefaultDeclaration'\n ? (node as any).declaration\n : node;\n if (decl?.type !== 'ClassDeclaration') continue;\n for (const dec of decl.decorators || []) {\n const expr = dec.expression;\n if (expr?.type !== 'CallExpression') continue;\n if (expr.callee?.name !== 'Component') continue;\n const arg = expr.arguments?.[0];\n if (arg?.type !== 'ObjectExpression') continue;\n for (const prop of arg.properties) {\n if (\n prop.type === 'Property' &&\n (prop.key?.name || prop.key?.value) === 'standalone' &&\n prop.value?.type === 'Literal' &&\n prop.value.value === false\n ) {\n return true;\n }\n }\n }\n }\n return false;\n}\n"],"mappings":";;;AA2DA,IAAM,eAAe,IAAI,OAAO,KAAK,CAAC,GAAG,qBAAqB,CAAC,CAAC,KAAK,GAAG,EAAE,EAAE;;;;;AAM5E,SAAgB,SACd,MACA,UACA,SACiB;CACjB,MAAM,UAA2B,CAAC;CAKlC,IAAI,CAAC,aAAa,KAAK,IAAI,KAAK,CAAC,yBAAyB,KAAK,IAAI,GACjE,OAAO;CAGT,YAAY,SAAS,UAAU,IAAI,CAAC,CAAC;CASrC,KAAK,MAAM,QAAQ,QAAQ,MAAM;EAC/B,MAAM,UACJ,KAAK,SAAS,4BACb,KAAa,aAAa,SAAS,wBAC/B,KAAa,cACd,KAAK,SAAS,wBACZ,OACA;EACR,IAAI,CAAC,WAAW,QAAQ,SAAS,SAAS;EAC1C,KAAK,MAAM,cAAc,QAAQ,gBAAgB,CAAC,GAAG;GACnD,IAAI,WAAW,IAAI,SAAS,cAAc;GAE1C,IAAI,OAAO,WAAW;GACtB,IAAI,MAAM,SAAS,kBAAkB,OAAO,KAAK;GACjD,IAAI,MAAM,SAAS,mBAAmB;GACtC,MAAM,UAAoB,CAAC;GAC3B,IAAI,eAAe;GACnB,KAAK,MAAM,MAAM,KAAK,YAAY,CAAC,GAAG;IACpC,IAAI,IAAI,SAAS,cAAc;KAC7B,eAAe;KACf;IACF;IACA,QAAQ,KAAK,GAAG,IAAI;GACtB;GACA,IAAI,CAAC,gBAAgB,QAAQ,WAAW,GAAG;GAC3C,MAAM,YAAoB,WAAW,GAAG;GACxC,QAAQ,KAAK;IACX,UAAU;IACV,MAAM;IACN;IACA;IACA,WAAW;GACb,CAAC;EACH;CACF;CAIA,IAAI;CACJ,KAAK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ACvC,MAAM,OAAO,IAAI;GACjB,IAAI,MAAM,SAAS,kBAAkB;GACrC,IAAI,KAAK,QAAQ,SAAS,aAAa;GACvC,MAAM,MAAM,KAAK,YAAY;GAC7B,IAAI,KAAK,SAAS,oBAAoB;GACtC,KAAK,MAAM,QAAQ,IAAI,YACrB,IACE,KAAK,SAAS,eACb,KAAK,KAAK,QAAQ,KAAK,KAAK,WAAW,gBACxC,KAAK,OAAO,SAAS,aACrB,KAAK,MAAM,UAAU,OAErB,OAAO;EAGb;CACF;CACA,OAAO;AACT"}
|
|
@@ -5,6 +5,11 @@ import type { FastCompileResolve, FastCompileSourceFormat } from "./fast-compile
|
|
|
5
5
|
type OxcProgram = ReturnType<typeof parseSync>["program"];
|
|
6
6
|
/** Resolves an import to a source file to scan, or `null` to skip it. */
|
|
7
7
|
export type ResolveImport = (spec: string, importer: string) => Promise<string | null>;
|
|
8
|
+
/** Optional import site context for module-scoped selector lookup. */
|
|
9
|
+
export interface SelectorLookupContext {
|
|
10
|
+
moduleSpecifier?: string;
|
|
11
|
+
containingFile?: string;
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* Angular classes scanned from source files and package `.d.ts` declarations,
|
|
10
15
|
* so source formats can look up the selectors of the components they import
|
|
@@ -18,6 +23,12 @@ export declare class ComponentScanner {
|
|
|
18
23
|
readonly lazyScans: Map<string, Promise<Set<string>>>;
|
|
19
24
|
/** Modules compiled against each scanned file. */
|
|
20
25
|
readonly importersByFile: Map<string, Set<string>>;
|
|
26
|
+
/** Entries declared in each scanned source file, keyed by normalized path. */
|
|
27
|
+
private readonly entriesByFile;
|
|
28
|
+
/** Direct resolved target file per importer and module specifier. */
|
|
29
|
+
private readonly resolvedImports;
|
|
30
|
+
/** Export aliases and re-export bindings per scanned file, keyed by normalized path. */
|
|
31
|
+
private readonly reExportsByFile;
|
|
21
32
|
private readonly sourceFormats;
|
|
22
33
|
private root;
|
|
23
34
|
/** Where package declarations are looked up from. */
|
|
@@ -52,16 +63,32 @@ export declare class ComponentScanner {
|
|
|
52
63
|
*/
|
|
53
64
|
resolveImportSpecifiers(specs: string[], id: string, resolveImport: ResolveImport): Promise<void>;
|
|
54
65
|
/**
|
|
66
|
+
* Resolves the registry entry for an imported or global Angular declaration.
|
|
67
|
+
* When `context` gives the importing file and module specifier, exported
|
|
68
|
+
* bindings on the resolved module (including barrel re-exports) are followed
|
|
69
|
+
* before falling back to the global registry.
|
|
70
|
+
*/
|
|
71
|
+
lookupEntry(className: string, external?: readonly ComponentRegistryEntries[], context?: SelectorLookupContext): RegistryEntry | undefined;
|
|
72
|
+
/**
|
|
55
73
|
* The element selector of a component or directive class. `external` are
|
|
56
|
-
* registries contributed through `analog.setup()`.
|
|
74
|
+
* registries contributed through `analog.setup()`. When `context` gives the
|
|
75
|
+
* importing file and module specifier, declarations scanned from that module
|
|
76
|
+
* (and its re-exports) are checked before falling back to the global registry.
|
|
57
77
|
*/
|
|
58
|
-
lookupSelector(className: string, external?: readonly ComponentRegistryEntries[]): string | null;
|
|
78
|
+
lookupSelector(className: string, external?: readonly ComponentRegistryEntries[], context?: SelectorLookupContext): string | null;
|
|
59
79
|
/** The files scanned for `importer`. */
|
|
60
80
|
dependenciesOf(importer: string): string[];
|
|
61
81
|
entriesOf(file: string): RegistryEntry[];
|
|
82
|
+
/**
|
|
83
|
+
* Records the entries scanned from a source file in both per-file storage
|
|
84
|
+
* and the global registry.
|
|
85
|
+
*/
|
|
86
|
+
recordFileEntries(file: string, entries: RegistryEntry[], overwrite?: boolean): void;
|
|
62
87
|
/** Drops what was scanned from `file`, so the next scan reads it again. */
|
|
63
88
|
invalidate(file: string): void;
|
|
64
89
|
private addEntry;
|
|
90
|
+
private resolveExportedEntry;
|
|
91
|
+
private removeFromRegistryIfOwned;
|
|
65
92
|
private scanOnDemand;
|
|
66
93
|
/**
|
|
67
94
|
* Scan a file and everything it re-exports, resolving specifiers through
|
|
@@ -19,6 +19,12 @@ var ComponentScanner = class {
|
|
|
19
19
|
lazyScans = /* @__PURE__ */ new Map();
|
|
20
20
|
/** Modules compiled against each scanned file. */
|
|
21
21
|
importersByFile = /* @__PURE__ */ new Map();
|
|
22
|
+
/** Entries declared in each scanned source file, keyed by normalized path. */
|
|
23
|
+
entriesByFile = /* @__PURE__ */ new Map();
|
|
24
|
+
/** Direct resolved target file per importer and module specifier. */
|
|
25
|
+
resolvedImports = /* @__PURE__ */ new Map();
|
|
26
|
+
/** Export aliases and re-export bindings per scanned file, keyed by normalized path. */
|
|
27
|
+
reExportsByFile = /* @__PURE__ */ new Map();
|
|
22
28
|
sourceFormats = [];
|
|
23
29
|
root = "";
|
|
24
30
|
/** Where package declarations are looked up from. */
|
|
@@ -31,6 +37,9 @@ var ComponentScanner = class {
|
|
|
31
37
|
this.scannedDtsPackages.clear();
|
|
32
38
|
this.lazyScans.clear();
|
|
33
39
|
this.importersByFile.clear();
|
|
40
|
+
this.entriesByFile.clear();
|
|
41
|
+
this.resolvedImports.clear();
|
|
42
|
+
this.reExportsByFile.clear();
|
|
34
43
|
}
|
|
35
44
|
registerSourceFormat(format) {
|
|
36
45
|
if (!this.sourceFormats.includes(format)) this.sourceFormats.push(format);
|
|
@@ -95,10 +104,22 @@ var ComponentScanner = class {
|
|
|
95
104
|
* records `id` as their importer.
|
|
96
105
|
*/
|
|
97
106
|
async resolveImportSpecifiers(specs, id, resolveImport) {
|
|
107
|
+
const importerKey = normalizePath(id);
|
|
98
108
|
await Promise.all(specs.map(async (spec) => {
|
|
99
109
|
const file = await resolveImport(spec, id);
|
|
100
|
-
if (!file)
|
|
101
|
-
|
|
110
|
+
if (!file) {
|
|
111
|
+
this.resolvedImports.get(importerKey)?.delete(spec);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const normalizedFile = normalizePath(file);
|
|
115
|
+
const scannedFiles = await this.scanOnDemand(normalizedFile, resolveImport);
|
|
116
|
+
let bySpec = this.resolvedImports.get(importerKey);
|
|
117
|
+
if (!bySpec) {
|
|
118
|
+
bySpec = /* @__PURE__ */ new Map();
|
|
119
|
+
this.resolvedImports.set(importerKey, bySpec);
|
|
120
|
+
}
|
|
121
|
+
bySpec.set(spec, normalizedFile);
|
|
122
|
+
for (const scanned of scannedFiles) {
|
|
102
123
|
let importers = this.importersByFile.get(scanned);
|
|
103
124
|
if (!importers) {
|
|
104
125
|
importers = /* @__PURE__ */ new Set();
|
|
@@ -109,12 +130,30 @@ var ComponentScanner = class {
|
|
|
109
130
|
}));
|
|
110
131
|
}
|
|
111
132
|
/**
|
|
133
|
+
* Resolves the registry entry for an imported or global Angular declaration.
|
|
134
|
+
* When `context` gives the importing file and module specifier, exported
|
|
135
|
+
* bindings on the resolved module (including barrel re-exports) are followed
|
|
136
|
+
* before falling back to the global registry.
|
|
137
|
+
*/
|
|
138
|
+
lookupEntry(className, external = [], context) {
|
|
139
|
+
if (context?.moduleSpecifier && context.containingFile) {
|
|
140
|
+
const targetFile = this.resolvedImports.get(normalizePath(context.containingFile))?.get(context.moduleSpecifier);
|
|
141
|
+
if (targetFile) {
|
|
142
|
+
const match = this.resolveExportedEntry(targetFile, className, /* @__PURE__ */ new Set());
|
|
143
|
+
if (match) return match;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return this.registry.get(className) ?? external.map((r) => r.get(className)).find((e) => e !== void 0);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
112
149
|
* The element selector of a component or directive class. `external` are
|
|
113
|
-
* registries contributed through `analog.setup()`.
|
|
150
|
+
* registries contributed through `analog.setup()`. When `context` gives the
|
|
151
|
+
* importing file and module specifier, declarations scanned from that module
|
|
152
|
+
* (and its re-exports) are checked before falling back to the global registry.
|
|
114
153
|
*/
|
|
115
|
-
lookupSelector(className, external = []) {
|
|
116
|
-
const entry = this.
|
|
117
|
-
if (!entry || entry
|
|
154
|
+
lookupSelector(className, external = [], context) {
|
|
155
|
+
const entry = this.lookupEntry(className, external, context);
|
|
156
|
+
if (!entry || !isSelectableEntry(entry)) return null;
|
|
118
157
|
return entry.selector;
|
|
119
158
|
}
|
|
120
159
|
/** The files scanned for `importer`. */
|
|
@@ -122,16 +161,75 @@ var ComponentScanner = class {
|
|
|
122
161
|
return [...this.importersByFile].filter(([, importers]) => importers.has(importer)).map(([file]) => file);
|
|
123
162
|
}
|
|
124
163
|
entriesOf(file) {
|
|
125
|
-
return
|
|
164
|
+
return this.entriesByFile.get(normalizePath(file)) ?? [];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Records the entries scanned from a source file in both per-file storage
|
|
168
|
+
* and the global registry.
|
|
169
|
+
*/
|
|
170
|
+
recordFileEntries(file, entries, overwrite = false) {
|
|
171
|
+
const key = normalizePath(file);
|
|
172
|
+
const previous = this.entriesByFile.get(key);
|
|
173
|
+
if (entries.length > 0) this.entriesByFile.set(key, entries);
|
|
174
|
+
else this.entriesByFile.delete(key);
|
|
175
|
+
if (previous) {
|
|
176
|
+
const nextNames = new Set(entries.map((e) => e.className));
|
|
177
|
+
for (const old of previous) if (!nextNames.has(old.className)) this.removeFromRegistryIfOwned(old.className, key);
|
|
178
|
+
}
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
const current = this.registry.get(entry.className);
|
|
181
|
+
if (overwrite || !current || normalizePath(current.fileName) === key) this.registry.set(entry.className, entry);
|
|
182
|
+
}
|
|
126
183
|
}
|
|
127
184
|
/** Drops what was scanned from `file`, so the next scan reads it again. */
|
|
128
185
|
invalidate(file) {
|
|
129
|
-
|
|
186
|
+
const key = normalizePath(file);
|
|
187
|
+
const oldEntries = this.entriesByFile.get(key) ?? [];
|
|
188
|
+
this.entriesByFile.delete(key);
|
|
189
|
+
for (const entry of oldEntries) this.removeFromRegistryIfOwned(entry.className, key);
|
|
190
|
+
this.resolvedImports.delete(key);
|
|
191
|
+
this.reExportsByFile.delete(key);
|
|
130
192
|
this.lazyScans.clear();
|
|
131
193
|
}
|
|
132
194
|
addEntry(entry) {
|
|
133
195
|
if (!this.registry.has(entry.className)) this.registry.set(entry.className, entry);
|
|
134
196
|
}
|
|
197
|
+
resolveExportedEntry(file, exportName, visited) {
|
|
198
|
+
const visitKey = `${file}\0${exportName}`;
|
|
199
|
+
if (visited.has(visitKey)) return;
|
|
200
|
+
visited.add(visitKey);
|
|
201
|
+
const exportMap = this.reExportsByFile.get(file);
|
|
202
|
+
const namedReExport = exportMap?.namedReExports.get(exportName);
|
|
203
|
+
if (namedReExport) return this.resolveExportedEntry(namedReExport.file, namedReExport.importedName, visited);
|
|
204
|
+
const entries = this.entriesByFile.get(file);
|
|
205
|
+
if (entries) {
|
|
206
|
+
if (exportName === "default") {
|
|
207
|
+
const localDefault = exportMap?.localAliases.get("default");
|
|
208
|
+
const match = entries.find((entry) => entry.isDefaultExport === true || localDefault !== void 0 && entry.className === localDefault);
|
|
209
|
+
if (match) return match;
|
|
210
|
+
} else {
|
|
211
|
+
const localName = exportMap?.localAliases.get(exportName) ?? exportName;
|
|
212
|
+
const match = entries.find((entry) => entry.className === localName);
|
|
213
|
+
if (match) return match;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (exportName !== "default" && exportMap) for (const starFile of exportMap.starReExports) {
|
|
217
|
+
const match = this.resolveExportedEntry(starFile, exportName, visited);
|
|
218
|
+
if (match) return match;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
removeFromRegistryIfOwned(className, ownerKey) {
|
|
222
|
+
const current = this.registry.get(className);
|
|
223
|
+
if (!current || normalizePath(current.fileName) !== ownerKey) return;
|
|
224
|
+
this.registry.delete(className);
|
|
225
|
+
for (const entries of this.entriesByFile.values()) {
|
|
226
|
+
const replacement = entries.find((e) => e.className === className);
|
|
227
|
+
if (replacement) {
|
|
228
|
+
this.registry.set(className, replacement);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
135
233
|
scanOnDemand(file, resolveImport) {
|
|
136
234
|
let scan = this.lazyScans.get(file);
|
|
137
235
|
if (!scan) {
|
|
@@ -149,29 +247,85 @@ var ComponentScanner = class {
|
|
|
149
247
|
async scanWithReExports(file, resolveImport) {
|
|
150
248
|
const visited = /* @__PURE__ */ new Set();
|
|
151
249
|
const visit = async (current) => {
|
|
152
|
-
|
|
153
|
-
visited.
|
|
250
|
+
const currentKey = normalizePath(current);
|
|
251
|
+
if (visited.has(currentKey)) return;
|
|
252
|
+
visited.add(currentKey);
|
|
154
253
|
let code;
|
|
155
254
|
let program;
|
|
156
255
|
try {
|
|
157
|
-
code = await this.readScanSource(
|
|
158
|
-
program = parseOxc(
|
|
256
|
+
code = await this.readScanSource(currentKey);
|
|
257
|
+
program = parseOxc(currentKey, code).program;
|
|
159
258
|
} catch {
|
|
160
259
|
return;
|
|
161
260
|
}
|
|
162
|
-
const entries = scanFile(code,
|
|
163
|
-
|
|
164
|
-
this.ensureDtsRegistryForSource(code,
|
|
165
|
-
const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code,
|
|
261
|
+
const entries = scanFile(code, currentKey, program);
|
|
262
|
+
this.recordFileEntries(currentKey, entries);
|
|
263
|
+
this.ensureDtsRegistryForSource(code, currentKey, program);
|
|
264
|
+
const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, currentKey, program) : collectReExports(code, currentKey, program);
|
|
265
|
+
const resolvedBySpec = /* @__PURE__ */ new Map();
|
|
166
266
|
for (const spec of specifiers) {
|
|
167
|
-
|
|
168
|
-
|
|
267
|
+
if (resolvedBySpec.has(spec)) continue;
|
|
268
|
+
const dep = await resolveImport(spec, currentKey);
|
|
269
|
+
if (dep) resolvedBySpec.set(spec, normalizePath(dep));
|
|
169
270
|
}
|
|
271
|
+
const exportMap = collectFileExportMap(program, resolvedBySpec);
|
|
272
|
+
if (exportMap) this.reExportsByFile.set(currentKey, exportMap);
|
|
273
|
+
else this.reExportsByFile.delete(currentKey);
|
|
274
|
+
for (const dep of resolvedBySpec.values()) await visit(dep);
|
|
170
275
|
};
|
|
171
276
|
await visit(file);
|
|
172
277
|
return visited;
|
|
173
278
|
}
|
|
174
279
|
};
|
|
280
|
+
function isSelectableEntry(entry) {
|
|
281
|
+
return entry.kind === "component" || entry.kind === "directive";
|
|
282
|
+
}
|
|
283
|
+
function moduleExportName(node) {
|
|
284
|
+
if (!node) return void 0;
|
|
285
|
+
if (node.type === "Identifier") return node.name;
|
|
286
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
287
|
+
}
|
|
288
|
+
function collectFileExportMap(program, resolvedBySpec) {
|
|
289
|
+
const localAliases = /* @__PURE__ */ new Map();
|
|
290
|
+
const namedReExports = /* @__PURE__ */ new Map();
|
|
291
|
+
const starReExports = [];
|
|
292
|
+
for (const stmt of program.body || []) {
|
|
293
|
+
if (stmt.exportKind === "type") continue;
|
|
294
|
+
if (stmt.type === "ExportNamedDeclaration") {
|
|
295
|
+
const source = stmt.source?.value;
|
|
296
|
+
if (!source) for (const spec of stmt.specifiers || []) {
|
|
297
|
+
if (spec.exportKind === "type") continue;
|
|
298
|
+
const localName = moduleExportName(spec.local);
|
|
299
|
+
const exportedName = moduleExportName(spec.exported);
|
|
300
|
+
if (localName && exportedName && localName !== exportedName) localAliases.set(exportedName, localName);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const targetFile = resolvedBySpec.get(source);
|
|
304
|
+
if (!targetFile) continue;
|
|
305
|
+
for (const spec of stmt.specifiers || []) {
|
|
306
|
+
if (spec.exportKind === "type") continue;
|
|
307
|
+
const importedName = moduleExportName(spec.local);
|
|
308
|
+
const exportedName = moduleExportName(spec.exported);
|
|
309
|
+
if (importedName && exportedName) namedReExports.set(exportedName, {
|
|
310
|
+
file: targetFile,
|
|
311
|
+
importedName
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} else if (stmt.type === "ExportAllDeclaration") {
|
|
316
|
+
if (stmt.exported) continue;
|
|
317
|
+
const source = stmt.source?.value;
|
|
318
|
+
const targetFile = source ? resolvedBySpec.get(source) : void 0;
|
|
319
|
+
if (targetFile && !starReExports.includes(targetFile)) starReExports.push(targetFile);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (localAliases.size === 0 && namedReExports.size === 0 && starReExports.length === 0) return null;
|
|
323
|
+
return {
|
|
324
|
+
localAliases,
|
|
325
|
+
namedReExports,
|
|
326
|
+
starReExports
|
|
327
|
+
};
|
|
328
|
+
}
|
|
175
329
|
export { ComponentScanner };
|
|
176
330
|
|
|
177
331
|
//# sourceMappingURL=component-scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-scanner.js","names":["fsPromises"],"sources":["../../../src/lib/component-scanner.ts"],"sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport type { parseSync } from 'oxc-parser';\nimport { normalizePath } from 'vite';\n\nimport type { ComponentRegistryEntries } from './analog-plugin-interop.js';\nimport {\n collectAllImports,\n collectImportedPackages,\n collectReExports,\n scanFile,\n scanPackageDts,\n type ComponentRegistry,\n type RegistryEntry,\n} from './compiler/index.js';\nimport { parseOxc } from './compiler/utils.js';\nimport type {\n FastCompileResolve,\n FastCompileSourceFormat,\n} from './fast-compile-api.js';\nimport { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from './utils/plugin-config.js';\n\ntype OxcProgram = ReturnType<typeof parseSync>['program'];\n\n/** Resolves an import to a source file to scan, or `null` to skip it. */\nexport type ResolveImport = (\n spec: string,\n importer: string,\n) => Promise<string | null>;\n\n/**\n * Angular classes scanned from source files and package `.d.ts` declarations,\n * so source formats can look up the selectors of the components they import\n * before any compiler sees their modules. Shared by the fast compile and NGP\n * plugins.\n */\nexport class ComponentScanner {\n readonly registry: ComponentRegistry = new Map();\n readonly scannedDtsPackages: Set<string> = new Set();\n /** Files scanned on demand, mapped to the barrel chain each pulled in. */\n readonly lazyScans: Map<string, Promise<Set<string>>> = new Map();\n /** Modules compiled against each scanned file. */\n readonly importersByFile: Map<string, Set<string>> = new Map();\n private readonly sourceFormats: FastCompileSourceFormat[] = [];\n private root = '';\n\n /** Where package declarations are looked up from. */\n get projectRoot(): string {\n return this.root;\n }\n\n reset(projectRoot: string): void {\n this.root = projectRoot;\n this.registry.clear();\n this.scannedDtsPackages.clear();\n this.lazyScans.clear();\n this.importersByFile.clear();\n }\n\n registerSourceFormat(format: FastCompileSourceFormat): void {\n if (!this.sourceFormats.includes(format)) {\n this.sourceFormats.push(format);\n }\n }\n\n sourceFormatOf(file: string): FastCompileSourceFormat | undefined {\n const path = file.split('?')[0];\n return this.sourceFormats.find((format) => format.test(path));\n }\n\n /** Whether `file` is TypeScript or a module of a registered source format. */\n isCompiledSource(file: string): boolean {\n return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== undefined;\n }\n\n /**\n * Reads a source file for scanning. Modules of a registered source format\n * are converted to TypeScript first so the scanner sees their classes.\n */\n async readScanSource(file: string): Promise<string> {\n const code = await fsPromises.readFile(file, 'utf-8');\n const format = this.sourceFormatOf(file);\n return format ? format.toScanSource(code, file) : code;\n }\n\n /**\n * Adapts a Vite-style resolver to the scanner's: only source files this\n * scanner reads, outside `node_modules` (package declarations come from the\n * `.d.ts` scanner instead).\n */\n toResolveImport(resolve: FastCompileResolve): ResolveImport {\n return async (spec, importer) => {\n const resolved = await resolve(spec, importer);\n if (!resolved || resolved.external) return null;\n const file = normalizePath(resolved.id.split('?')[0]);\n return this.isCompiledSource(file) &&\n !EXCLUDED_TS_EXT_REGEX.test(file) &&\n !file.includes('/node_modules/')\n ? file\n : null;\n };\n }\n\n /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */\n ensureDtsRegistryForPackages(packages: Iterable<string>): void {\n for (const pkg of packages) {\n if (this.scannedDtsPackages.has(pkg)) continue;\n this.scannedDtsPackages.add(pkg);\n try {\n const dtsEntries = scanPackageDts(\n pkg,\n // Before a tsconfig resolves, look up packages from the working directory.\n this.root || process.cwd(),\n this.scannedDtsPackages,\n );\n for (const entry of dtsEntries) {\n this.addEntry(entry);\n }\n } catch {\n // Package may not have .d.ts files or may not be Angular\n }\n }\n }\n\n ensureDtsRegistryForSource(\n code: string,\n id: string,\n program?: OxcProgram,\n ): void {\n this.ensureDtsRegistryForPackages(\n collectImportedPackages(code, id, program),\n );\n }\n\n /**\n * Scans the modules behind `specifiers`, imported by `importer`: packages\n * from their `.d.ts` declarations, everything else from source.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n this.ensureDtsRegistryForPackages(\n specifiers\n .filter((spec) => !spec.startsWith('.') && !spec.startsWith('/'))\n .map((spec) => {\n const parts = spec.split('/');\n return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];\n }),\n );\n return this.resolveImportSpecifiers(\n specifiers,\n importer,\n this.toResolveImport(resolve),\n );\n }\n\n /**\n * Scans the files behind `specs`, imported by `id`, into the registry and\n * records `id` as their importer.\n */\n async resolveImportSpecifiers(\n specs: string[],\n id: string,\n resolveImport: ResolveImport,\n ): Promise<void> {\n await Promise.all(\n specs.map(async (spec) => {\n const file = await resolveImport(spec, id);\n if (!file) return;\n for (const scanned of await this.scanOnDemand(file, resolveImport)) {\n let importers = this.importersByFile.get(scanned);\n if (!importers) {\n importers = new Set();\n this.importersByFile.set(scanned, importers);\n }\n importers.add(id);\n }\n }),\n );\n }\n\n /**\n * The element selector of a component or directive class. `external` are\n * registries contributed through `analog.setup()`.\n */\n lookupSelector(\n className: string,\n external: readonly ComponentRegistryEntries[] = [],\n ): string | null {\n const entry =\n this.registry.get(className) ??\n external.map((r) => r.get(className)).find((e) => e !== undefined);\n if (!entry || (entry.kind !== 'component' && entry.kind !== 'directive')) {\n return null;\n }\n return entry.selector;\n }\n\n /** The files scanned for `importer`. */\n dependenciesOf(importer: string): string[] {\n return [...this.importersByFile]\n .filter(([, importers]) => importers.has(importer))\n .map(([file]) => file);\n }\n\n entriesOf(file: string): RegistryEntry[] {\n return [...this.registry.values()].filter((e) => e.fileName === file);\n }\n\n /** Drops what was scanned from `file`, so the next scan reads it again. */\n invalidate(file: string): void {\n for (const entry of this.entriesOf(file)) {\n this.registry.delete(entry.className);\n }\n this.lazyScans.clear();\n }\n\n private addEntry(entry: RegistryEntry): void {\n if (!this.registry.has(entry.className)) {\n this.registry.set(entry.className, entry);\n }\n }\n\n private scanOnDemand(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n let scan = this.lazyScans.get(file);\n if (!scan) {\n scan = this.scanWithReExports(file, resolveImport);\n this.lazyScans.set(file, scan);\n }\n return scan;\n }\n\n /**\n * Scan a file and everything it re-exports, resolving specifiers through\n * Vite so path aliases work. Tuple barrels and NgModules can list classes\n * their file imports without re-exporting, so their imports are followed\n * too. Returns every file scanned.\n */\n private async scanWithReExports(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n const visited = new Set<string>();\n const visit = async (current: string): Promise<void> => {\n if (visited.has(current)) return;\n visited.add(current);\n let code: string;\n let program: OxcProgram;\n try {\n code = await this.readScanSource(current);\n program = parseOxc(current, code).program;\n } catch {\n return;\n }\n const entries = scanFile(code, current, program);\n for (const entry of entries) {\n this.addEntry(entry);\n }\n this.ensureDtsRegistryForSource(code, current, program);\n const followsImports = entries.some(\n (e) => e.kind === 'tuple' || e.kind === 'ngmodule',\n );\n const specifiers = followsImports\n ? collectAllImports(code, current, program)\n : collectReExports(code, current, program);\n for (const spec of specifiers) {\n const dep = await resolveImport(spec, current);\n if (dep) await visit(dep);\n }\n };\n await visit(file);\n return visited;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,IAAa,mBAAb,MAA8B;CAC5B,2BAAuC,IAAI,IAAI;CAC/C,qCAA2C,IAAI,IAAI;;CAEnD,4BAAwD,IAAI,IAAI;;CAEhE,kCAAqD,IAAI,IAAI;CAC7D,gBAA4D,CAAC;CAC7D,OAAe;;CAGf,IAAI,cAAsB;EACxB,OAAO,KAAK;CACd;CAEA,MAAM,aAA2B;EAC/B,KAAK,OAAO;EACZ,KAAK,SAAS,MAAM;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,MAAM,MAAM,GAAG;GAC1B;EACF;EACA,MAAM,MAAM,IAAI;EAChB,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"component-scanner.js","names":["fsPromises"],"sources":["../../../src/lib/component-scanner.ts"],"sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport type { parseSync } from 'oxc-parser';\nimport { normalizePath } from 'vite';\n\nimport type { ComponentRegistryEntries } from './analog-plugin-interop.js';\nimport {\n collectAllImports,\n collectImportedPackages,\n collectReExports,\n scanFile,\n scanPackageDts,\n type ComponentRegistry,\n type RegistryEntry,\n} from './compiler/index.js';\nimport { parseOxc } from './compiler/utils.js';\nimport type {\n FastCompileResolve,\n FastCompileSourceFormat,\n} from './fast-compile-api.js';\nimport { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from './utils/plugin-config.js';\n\ntype OxcProgram = ReturnType<typeof parseSync>['program'];\n\n/** Resolves an import to a source file to scan, or `null` to skip it. */\nexport type ResolveImport = (\n spec: string,\n importer: string,\n) => Promise<string | null>;\n\n/** Optional import site context for module-scoped selector lookup. */\nexport interface SelectorLookupContext {\n moduleSpecifier?: string;\n containingFile?: string;\n}\n\ninterface ReExportTarget {\n file: string;\n importedName: string;\n}\n\ninterface FileExportMap {\n /** `export { LocalName as ExportedName }` for declarations in this file. */\n localAliases: Map<string, string>;\n /** `export { ImportedName as ExportedName } from './target'`. */\n namedReExports: Map<string, ReExportTarget>;\n /** `export * from './target'` (excluding `export * as ns from`). */\n starReExports: string[];\n}\n\n/**\n * Angular classes scanned from source files and package `.d.ts` declarations,\n * so source formats can look up the selectors of the components they import\n * before any compiler sees their modules. Shared by the fast compile and NGP\n * plugins.\n */\nexport class ComponentScanner {\n readonly registry: ComponentRegistry = new Map();\n readonly scannedDtsPackages: Set<string> = new Set();\n /** Files scanned on demand, mapped to the barrel chain each pulled in. */\n readonly lazyScans: Map<string, Promise<Set<string>>> = new Map();\n /** Modules compiled against each scanned file. */\n readonly importersByFile: Map<string, Set<string>> = new Map();\n /** Entries declared in each scanned source file, keyed by normalized path. */\n private readonly entriesByFile: Map<string, RegistryEntry[]> = new Map();\n /** Direct resolved target file per importer and module specifier. */\n private readonly resolvedImports: Map<string, Map<string, string>> =\n new Map();\n /** Export aliases and re-export bindings per scanned file, keyed by normalized path. */\n private readonly reExportsByFile: Map<string, FileExportMap> = new Map();\n private readonly sourceFormats: FastCompileSourceFormat[] = [];\n private root = '';\n\n /** Where package declarations are looked up from. */\n get projectRoot(): string {\n return this.root;\n }\n\n reset(projectRoot: string): void {\n this.root = projectRoot;\n this.registry.clear();\n this.scannedDtsPackages.clear();\n this.lazyScans.clear();\n this.importersByFile.clear();\n this.entriesByFile.clear();\n this.resolvedImports.clear();\n this.reExportsByFile.clear();\n }\n\n registerSourceFormat(format: FastCompileSourceFormat): void {\n if (!this.sourceFormats.includes(format)) {\n this.sourceFormats.push(format);\n }\n }\n\n sourceFormatOf(file: string): FastCompileSourceFormat | undefined {\n const path = file.split('?')[0];\n return this.sourceFormats.find((format) => format.test(path));\n }\n\n /** Whether `file` is TypeScript or a module of a registered source format. */\n isCompiledSource(file: string): boolean {\n return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== undefined;\n }\n\n /**\n * Reads a source file for scanning. Modules of a registered source format\n * are converted to TypeScript first so the scanner sees their classes.\n */\n async readScanSource(file: string): Promise<string> {\n const code = await fsPromises.readFile(file, 'utf-8');\n const format = this.sourceFormatOf(file);\n return format ? format.toScanSource(code, file) : code;\n }\n\n /**\n * Adapts a Vite-style resolver to the scanner's: only source files this\n * scanner reads, outside `node_modules` (package declarations come from the\n * `.d.ts` scanner instead).\n */\n toResolveImport(resolve: FastCompileResolve): ResolveImport {\n return async (spec, importer) => {\n const resolved = await resolve(spec, importer);\n if (!resolved || resolved.external) return null;\n const file = normalizePath(resolved.id.split('?')[0]);\n return this.isCompiledSource(file) &&\n !EXCLUDED_TS_EXT_REGEX.test(file) &&\n !file.includes('/node_modules/')\n ? file\n : null;\n };\n }\n\n /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */\n ensureDtsRegistryForPackages(packages: Iterable<string>): void {\n for (const pkg of packages) {\n if (this.scannedDtsPackages.has(pkg)) continue;\n this.scannedDtsPackages.add(pkg);\n try {\n const dtsEntries = scanPackageDts(\n pkg,\n // Before a tsconfig resolves, look up packages from the working directory.\n this.root || process.cwd(),\n this.scannedDtsPackages,\n );\n for (const entry of dtsEntries) {\n this.addEntry(entry);\n }\n } catch {\n // Package may not have .d.ts files or may not be Angular\n }\n }\n }\n\n ensureDtsRegistryForSource(\n code: string,\n id: string,\n program?: OxcProgram,\n ): void {\n this.ensureDtsRegistryForPackages(\n collectImportedPackages(code, id, program),\n );\n }\n\n /**\n * Scans the modules behind `specifiers`, imported by `importer`: packages\n * from their `.d.ts` declarations, everything else from source.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n this.ensureDtsRegistryForPackages(\n specifiers\n .filter((spec) => !spec.startsWith('.') && !spec.startsWith('/'))\n .map((spec) => {\n const parts = spec.split('/');\n return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];\n }),\n );\n return this.resolveImportSpecifiers(\n specifiers,\n importer,\n this.toResolveImport(resolve),\n );\n }\n\n /**\n * Scans the files behind `specs`, imported by `id`, into the registry and\n * records `id` as their importer.\n */\n async resolveImportSpecifiers(\n specs: string[],\n id: string,\n resolveImport: ResolveImport,\n ): Promise<void> {\n const importerKey = normalizePath(id);\n await Promise.all(\n specs.map(async (spec) => {\n const file = await resolveImport(spec, id);\n if (!file) {\n this.resolvedImports.get(importerKey)?.delete(spec);\n return;\n }\n const normalizedFile = normalizePath(file);\n const scannedFiles = await this.scanOnDemand(\n normalizedFile,\n resolveImport,\n );\n let bySpec = this.resolvedImports.get(importerKey);\n if (!bySpec) {\n bySpec = new Map();\n this.resolvedImports.set(importerKey, bySpec);\n }\n bySpec.set(spec, normalizedFile);\n for (const scanned of scannedFiles) {\n let importers = this.importersByFile.get(scanned);\n if (!importers) {\n importers = new Set();\n this.importersByFile.set(scanned, importers);\n }\n importers.add(id);\n }\n }),\n );\n }\n\n /**\n * Resolves the registry entry for an imported or global Angular declaration.\n * When `context` gives the importing file and module specifier, exported\n * bindings on the resolved module (including barrel re-exports) are followed\n * before falling back to the global registry.\n */\n lookupEntry(\n className: string,\n external: readonly ComponentRegistryEntries[] = [],\n context?: SelectorLookupContext,\n ): RegistryEntry | undefined {\n if (context?.moduleSpecifier && context.containingFile) {\n const targetFile = this.resolvedImports\n .get(normalizePath(context.containingFile))\n ?.get(context.moduleSpecifier);\n if (targetFile) {\n const match = this.resolveExportedEntry(\n targetFile,\n className,\n new Set(),\n );\n if (match) {\n return match;\n }\n }\n }\n\n return (\n this.registry.get(className) ??\n external.map((r) => r.get(className)).find((e) => e !== undefined)\n );\n }\n\n /**\n * The element selector of a component or directive class. `external` are\n * registries contributed through `analog.setup()`. When `context` gives the\n * importing file and module specifier, declarations scanned from that module\n * (and its re-exports) are checked before falling back to the global registry.\n */\n lookupSelector(\n className: string,\n external: readonly ComponentRegistryEntries[] = [],\n context?: SelectorLookupContext,\n ): string | null {\n const entry = this.lookupEntry(className, external, context);\n if (!entry || !isSelectableEntry(entry)) {\n return null;\n }\n return entry.selector;\n }\n\n /** The files scanned for `importer`. */\n dependenciesOf(importer: string): string[] {\n return [...this.importersByFile]\n .filter(([, importers]) => importers.has(importer))\n .map(([file]) => file);\n }\n\n entriesOf(file: string): RegistryEntry[] {\n return this.entriesByFile.get(normalizePath(file)) ?? [];\n }\n\n /**\n * Records the entries scanned from a source file in both per-file storage\n * and the global registry.\n */\n recordFileEntries(\n file: string,\n entries: RegistryEntry[],\n overwrite = false,\n ): void {\n const key = normalizePath(file);\n const previous = this.entriesByFile.get(key);\n if (entries.length > 0) {\n this.entriesByFile.set(key, entries);\n } else {\n this.entriesByFile.delete(key);\n }\n if (previous) {\n const nextNames = new Set(entries.map((e) => e.className));\n for (const old of previous) {\n if (!nextNames.has(old.className)) {\n this.removeFromRegistryIfOwned(old.className, key);\n }\n }\n }\n for (const entry of entries) {\n const current = this.registry.get(entry.className);\n if (overwrite || !current || normalizePath(current.fileName) === key) {\n this.registry.set(entry.className, entry);\n }\n }\n }\n\n /** Drops what was scanned from `file`, so the next scan reads it again. */\n invalidate(file: string): void {\n const key = normalizePath(file);\n const oldEntries = this.entriesByFile.get(key) ?? [];\n this.entriesByFile.delete(key);\n for (const entry of oldEntries) {\n this.removeFromRegistryIfOwned(entry.className, key);\n }\n this.resolvedImports.delete(key);\n this.reExportsByFile.delete(key);\n this.lazyScans.clear();\n }\n\n private addEntry(entry: RegistryEntry): void {\n if (!this.registry.has(entry.className)) {\n this.registry.set(entry.className, entry);\n }\n }\n\n private resolveExportedEntry(\n file: string,\n exportName: string,\n visited: Set<string>,\n ): RegistryEntry | undefined {\n const visitKey = `${file}\\0${exportName}`;\n if (visited.has(visitKey)) {\n return undefined;\n }\n visited.add(visitKey);\n\n const exportMap = this.reExportsByFile.get(file);\n const namedReExport = exportMap?.namedReExports.get(exportName);\n if (namedReExport) {\n return this.resolveExportedEntry(\n namedReExport.file,\n namedReExport.importedName,\n visited,\n );\n }\n\n const entries = this.entriesByFile.get(file);\n if (entries) {\n if (exportName === 'default') {\n const localDefault = exportMap?.localAliases.get('default');\n const match = entries.find(\n (entry) =>\n entry.isDefaultExport === true ||\n (localDefault !== undefined && entry.className === localDefault),\n );\n if (match) {\n return match;\n }\n } else {\n const localName = exportMap?.localAliases.get(exportName) ?? exportName;\n const match = entries.find((entry) => entry.className === localName);\n if (match) {\n return match;\n }\n }\n }\n\n if (exportName !== 'default' && exportMap) {\n for (const starFile of exportMap.starReExports) {\n const match = this.resolveExportedEntry(starFile, exportName, visited);\n if (match) {\n return match;\n }\n }\n }\n\n return undefined;\n }\n\n private removeFromRegistryIfOwned(className: string, ownerKey: string): void {\n const current = this.registry.get(className);\n if (!current || normalizePath(current.fileName) !== ownerKey) {\n return;\n }\n this.registry.delete(className);\n for (const entries of this.entriesByFile.values()) {\n const replacement = entries.find((e) => e.className === className);\n if (replacement) {\n this.registry.set(className, replacement);\n break;\n }\n }\n }\n\n private scanOnDemand(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n let scan = this.lazyScans.get(file);\n if (!scan) {\n scan = this.scanWithReExports(file, resolveImport);\n this.lazyScans.set(file, scan);\n }\n return scan;\n }\n\n /**\n * Scan a file and everything it re-exports, resolving specifiers through\n * Vite so path aliases work. Tuple barrels and NgModules can list classes\n * their file imports without re-exporting, so their imports are followed\n * too. Returns every file scanned.\n */\n private async scanWithReExports(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n const visited = new Set<string>();\n const visit = async (current: string): Promise<void> => {\n const currentKey = normalizePath(current);\n if (visited.has(currentKey)) return;\n visited.add(currentKey);\n let code: string;\n let program: OxcProgram;\n try {\n code = await this.readScanSource(currentKey);\n program = parseOxc(currentKey, code).program;\n } catch {\n return;\n }\n const entries = scanFile(code, currentKey, program);\n this.recordFileEntries(currentKey, entries);\n this.ensureDtsRegistryForSource(code, currentKey, program);\n const followsImports = entries.some(\n (e) => e.kind === 'tuple' || e.kind === 'ngmodule',\n );\n const specifiers = followsImports\n ? collectAllImports(code, currentKey, program)\n : collectReExports(code, currentKey, program);\n\n const resolvedBySpec = new Map<string, string>();\n for (const spec of specifiers) {\n if (resolvedBySpec.has(spec)) continue;\n const dep = await resolveImport(spec, currentKey);\n if (dep) resolvedBySpec.set(spec, normalizePath(dep));\n }\n\n const exportMap = collectFileExportMap(program, resolvedBySpec);\n if (exportMap) {\n this.reExportsByFile.set(currentKey, exportMap);\n } else {\n this.reExportsByFile.delete(currentKey);\n }\n\n for (const dep of resolvedBySpec.values()) {\n await visit(dep);\n }\n };\n await visit(file);\n return visited;\n }\n}\n\nfunction isSelectableEntry(entry: RegistryEntry): boolean {\n return entry.kind === 'component' || entry.kind === 'directive';\n}\n\nfunction moduleExportName(node: any): string | undefined {\n if (!node) return undefined;\n if (node.type === 'Identifier') return node.name;\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n return undefined;\n}\n\nfunction collectFileExportMap(\n program: OxcProgram,\n resolvedBySpec: Map<string, string>,\n): FileExportMap | null {\n const localAliases = new Map<string, string>();\n const namedReExports = new Map<string, ReExportTarget>();\n const starReExports: string[] = [];\n\n for (const stmt of program.body || []) {\n if ((stmt as any).exportKind === 'type') continue;\n if (stmt.type === 'ExportNamedDeclaration') {\n const source: string | undefined = stmt.source?.value;\n if (!source) {\n for (const spec of (stmt as any).specifiers || []) {\n if (spec.exportKind === 'type') continue;\n const localName = moduleExportName(spec.local);\n const exportedName = moduleExportName(spec.exported);\n if (localName && exportedName && localName !== exportedName) {\n localAliases.set(exportedName, localName);\n }\n }\n } else {\n const targetFile = resolvedBySpec.get(source);\n if (!targetFile) continue;\n for (const spec of (stmt as any).specifiers || []) {\n if (spec.exportKind === 'type') continue;\n const importedName = moduleExportName(spec.local);\n const exportedName = moduleExportName(spec.exported);\n if (importedName && exportedName) {\n namedReExports.set(exportedName, {\n file: targetFile,\n importedName,\n });\n }\n }\n }\n } else if (stmt.type === 'ExportAllDeclaration') {\n if ((stmt as any).exported) continue;\n const source: string | undefined = stmt.source?.value;\n const targetFile = source ? resolvedBySpec.get(source) : undefined;\n if (targetFile && !starReExports.includes(targetFile)) {\n starReExports.push(targetFile);\n }\n }\n }\n\n if (\n localAliases.size === 0 &&\n namedReExports.size === 0 &&\n starReExports.length === 0\n ) {\n return null;\n }\n return { localAliases, namedReExports, starReExports };\n}\n"],"mappings":";;;;;;;;;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAC5B,2BAAuC,IAAI,IAAI;CAC/C,qCAA2C,IAAI,IAAI;;CAEnD,4BAAwD,IAAI,IAAI;;CAEhE,kCAAqD,IAAI,IAAI;;CAE7D,gCAA+D,IAAI,IAAI;;CAEvE,kCACE,IAAI,IAAI;;CAEV,kCAA+D,IAAI,IAAI;CACvE,gBAA4D,CAAC;CAC7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a,cAAc,CAAC,GAAG;IACjD,IAAI,KAAK,eAAe,QAAQ;IAChC,MAAM,YAAY,iBAAiB,KAAK,KAAK;IAC7C,MAAM,eAAe,iBAAiB,KAAK,QAAQ;IACnD,IAAI,aAAa,gBAAgB,cAAc,cAC7C,aAAa,IAAI,cAAc,SAAS;GAE5C;QACK;IACL,MAAM,aAAa,eAAe,IAAI,MAAM;IAC5C,IAAI,CAAC,YAAY;IACjB,KAAK,MAAM,QAAS,KAAa,cAAc,CAAC,GAAG;KACjD,IAAI,KAAK,eAAe,QAAQ;KAChC,MAAM,eAAe,iBAAiB,KAAK,KAAK;KAChD,MAAM,eAAe,iBAAiB,KAAK,QAAQ;KACnD,IAAI,gBAAgB,cAClB,eAAe,IAAI,cAAc;MAC/B,MAAM;MACN;KACF,CAAC;IAEL;GACF;EACF,OAAO,IAAI,KAAK,SAAS,wBAAwB;GAC/C,IAAK,KAAa,UAAU;GAC5B,MAAM,SAA6B,KAAK,QAAQ;GAChD,MAAM,aAAa,SAAS,eAAe,IAAI,MAAM,IAAI,KAAA;GACzD,IAAI,cAAc,CAAC,cAAc,SAAS,UAAU,GAClD,cAAc,KAAK,UAAU;EAEjC;CACF;CAEA,IACE,aAAa,SAAS,KACtB,eAAe,SAAS,KACxB,cAAc,WAAW,GAEzB,OAAO;CAET,OAAO;EAAE;EAAc;EAAgB;CAAc;AACvD"}
|
|
@@ -49,7 +49,7 @@ export interface FastCompileApi {
|
|
|
49
49
|
*/
|
|
50
50
|
scanImports(specifiers: string[], importer: string, resolve: FastCompileResolve): Promise<void>;
|
|
51
51
|
/** The element selector of a component or directive class, if known. */
|
|
52
|
-
resolveSelector(className: string): string | null;
|
|
52
|
+
resolveSelector(className: string, moduleSpecifier?: string, containingFile?: string): string | null;
|
|
53
53
|
/** Compiles TypeScript produced for module `id`. */
|
|
54
54
|
compile(code: string, id: string, options: FastCompileOptions): Promise<{
|
|
55
55
|
code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fast-compile-api.js","names":[],"sources":["../../../src/lib/fast-compile-api.ts"],"sourcesContent":["/**\n * The fast compile path's plugin API, for Vite plugins that compile other\n * source formats into Angular components (for example `.tsrx` modules).\n *\n * Such a plugin finds the fast compile plugin by its `api.fastCompile`\n * property, lowers its modules to TypeScript, and hands the result to\n * `compile()`.\n */\n\n/** Resolves an import the way Vite's `this.resolve` does. */\nexport type FastCompileResolve = (\n specifier: string,\n importer: string,\n) => Promise<{\n id: string;\n external?: boolean | 'absolute' | 'relative';\n} | null>;\n\n/** A source format whose modules compile to Angular components. */\nexport interface FastCompileSourceFormat {\n /** Short name used in diagnostics, for example `'tsrx'`. */\n name: string;\n /** Whether a module path (without query) belongs to this format. */\n test(path: string): boolean;\n /**\n * TypeScript for registry scanning. It must declare the same Angular\n * classes, selectors, inputs and outputs as the compiled module; template\n * details may be placeholders.\n */\n toScanSource(code: string, path: string): Promise<string> | string;\n}\n\n/** A source map, as a JSON string or an object. */\nexport type SourceMapInput = string | { [key: string]: unknown };\n\nexport interface FastCompileOptions {\n /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */\n resolve: FastCompileResolve;\n /**\n * Maps the compiled output's source map (which points at `code`) back to\n * the module's original source.\n */\n mapToSource?(map: SourceMapInput): { [key: string]: unknown };\n}\n\nexport interface FastCompileApi {\n /** Registers a source format so registry scans and HMR understand its modules. */\n registerSourceFormat(format: FastCompileSourceFormat): void;\n /**\n * Scans the modules behind `specifiers`, imported by `importer`, into the\n * component registry so `resolveSelector` knows their selectors. Relative\n * imports are scanned from source; packages from their `.d.ts` declarations.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void>;\n /** The element selector of a component or directive class, if known. */\n resolveSelector(className: string): string | null;\n /** Compiles TypeScript produced for module `id`. */\n compile(\n code: string,\n id: string,\n options: FastCompileOptions,\n ): Promise<{ code: string; map: SourceMapInput | null } | undefined>;\n}\n\n/** Finds the fast compile plugin's API among resolved Vite plugins. */\nexport function findFastCompileApi(\n plugins: readonly { api?: unknown }[],\n): FastCompileApi | undefined {\n for (const plugin of plugins) {\n const api = plugin.api as { fastCompile?: FastCompileApi } | undefined;\n if (api?.fastCompile) {\n return api.fastCompile;\n }\n }\n return undefined;\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"fast-compile-api.js","names":[],"sources":["../../../src/lib/fast-compile-api.ts"],"sourcesContent":["/**\n * The fast compile path's plugin API, for Vite plugins that compile other\n * source formats into Angular components (for example `.tsrx` modules).\n *\n * Such a plugin finds the fast compile plugin by its `api.fastCompile`\n * property, lowers its modules to TypeScript, and hands the result to\n * `compile()`.\n */\n\n/** Resolves an import the way Vite's `this.resolve` does. */\nexport type FastCompileResolve = (\n specifier: string,\n importer: string,\n) => Promise<{\n id: string;\n external?: boolean | 'absolute' | 'relative';\n} | null>;\n\n/** A source format whose modules compile to Angular components. */\nexport interface FastCompileSourceFormat {\n /** Short name used in diagnostics, for example `'tsrx'`. */\n name: string;\n /** Whether a module path (without query) belongs to this format. */\n test(path: string): boolean;\n /**\n * TypeScript for registry scanning. It must declare the same Angular\n * classes, selectors, inputs and outputs as the compiled module; template\n * details may be placeholders.\n */\n toScanSource(code: string, path: string): Promise<string> | string;\n}\n\n/** A source map, as a JSON string or an object. */\nexport type SourceMapInput = string | { [key: string]: unknown };\n\nexport interface FastCompileOptions {\n /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */\n resolve: FastCompileResolve;\n /**\n * Maps the compiled output's source map (which points at `code`) back to\n * the module's original source.\n */\n mapToSource?(map: SourceMapInput): { [key: string]: unknown };\n}\n\nexport interface FastCompileApi {\n /** Registers a source format so registry scans and HMR understand its modules. */\n registerSourceFormat(format: FastCompileSourceFormat): void;\n /**\n * Scans the modules behind `specifiers`, imported by `importer`, into the\n * component registry so `resolveSelector` knows their selectors. Relative\n * imports are scanned from source; packages from their `.d.ts` declarations.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void>;\n /** The element selector of a component or directive class, if known. */\n resolveSelector(\n className: string,\n moduleSpecifier?: string,\n containingFile?: string,\n ): string | null;\n /** Compiles TypeScript produced for module `id`. */\n compile(\n code: string,\n id: string,\n options: FastCompileOptions,\n ): Promise<{ code: string; map: SourceMapInput | null } | undefined>;\n}\n\n/** Finds the fast compile plugin's API among resolved Vite plugins. */\nexport function findFastCompileApi(\n plugins: readonly { api?: unknown }[],\n): FastCompileApi | undefined {\n for (const plugin of plugins) {\n const api = plugin.api as { fastCompile?: FastCompileApi } | undefined;\n if (api?.fastCompile) {\n return api.fastCompile;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAyEA,SAAgB,mBACd,SAC4B;CAC5B,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,MAAM,OAAO;EACnB,IAAI,KAAK,aACP,OAAO,IAAI;CAEf;AAEF"}
|