@analogjs/vite-plugin-angular 3.0.0-alpha.36 → 3.0.0-alpha.38
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/README.md +22 -0
- package/package.json +3 -4
- package/src/lib/angular-jit-plugin.js +3 -0
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +12 -7
- package/src/lib/angular-vite-plugin.js +7 -5
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +16 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +44 -0
- package/src/lib/compiler/compile.js +731 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +18 -0
- package/src/lib/compiler/constants.js +52 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +47 -0
- package/src/lib/compiler/defer.js +138 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +35 -0
- package/src/lib/compiler/dts-reader.js +365 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +7 -0
- package/src/lib/compiler/index.js +7 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +146 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +200 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +420 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +45 -0
- package/src/lib/compiler/metadata.js +633 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +49 -0
- package/src/lib/compiler/registry.js +164 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +21 -0
- package/src/lib/compiler/resource-inliner.js +152 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +8 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +26 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +10 -0
- package/src/lib/compiler/utils.js +35 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/{analog-compiler-plugin.d.ts → fast-compile-plugin.d.ts} +3 -3
- package/src/lib/{analog-compiler-plugin.js → fast-compile-plugin.js} +46 -33
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +16 -0
- package/src/lib/utils/virtual-resources.js +31 -2
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/analog-compiler-plugin.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","names":[],"sources":["../../../../src/lib/compiler/metadata.ts"],"sourcesContent":["import * as o from '@angular/compiler';\nimport { unwrapForwardRefOxc } from './utils.js';\nimport { SIGNAL_APIS } from './constants.js';\n\nfunction getCallApi(call: any): { api: string; required: boolean } | null {\n const callee = call.callee;\n if (!callee) return null;\n\n if (callee.type === 'Identifier') {\n return { api: callee.name, required: false };\n }\n\n if (\n (callee.type === 'StaticMemberExpression' ||\n callee.type === 'MemberExpression') &&\n callee.object?.type === 'Identifier' &&\n callee.property?.name === 'required'\n ) {\n return { api: callee.object.name, required: true };\n }\n\n return null;\n}\n\n/**\n * Extract the string value from an OXC string literal or template literal node.\n *\n * If `consts` is provided, interpolated template literals (e.g.\n * `\\`hello ${NAME}\\``) are resolved when every `${...}` expression is a bare\n * `Identifier` whose name is present in the map. This lets metadata fields\n * such as `template:` reference module-level string constants via JS\n * template-literal interpolation:\n *\n * const tw = `text-zinc-700 hover:text-zinc-900`;\n * @Component({ template: `<a class=\"${tw}\">x</a>` })\n *\n * Returns `null` if the node is not statically resolvable.\n */\nfunction stringValue(node: any, consts?: Map<string, string>): string | null {\n if (node?.type === 'StringLiteral') return node.value;\n if (node?.type === 'Literal' && typeof node.value === 'string')\n return node.value;\n if (node?.type === 'TemplateLiteral') {\n const quasis = node.quasis ?? [];\n const expressions = node.expressions ?? [];\n if (expressions.length === 0) {\n return quasis[0]?.value?.cooked ?? null;\n }\n if (!consts) return null;\n let result = '';\n for (let i = 0; i < quasis.length; i++) {\n const cooked = quasis[i]?.value?.cooked;\n if (cooked == null) return null;\n result += cooked;\n if (i < expressions.length) {\n const expr = expressions[i];\n if (expr?.type !== 'Identifier') return null;\n const resolved = consts.get(expr.name);\n if (resolved == null) return null;\n result += resolved;\n }\n }\n return result;\n }\n return null;\n}\n\n/** Check if an OXC node is a string-like literal. */\nfunction isStringLike(node: any, consts?: Map<string, string>): boolean {\n return stringValue(node, consts) !== null;\n}\n\n/**\n * Walk the top-level statements of an OXC program and collect a map of\n * statically-resolvable string-valued `const NAME = ...` declarations.\n *\n * Used so decorator metadata fields like `template:` can reference\n * module-level Tailwind class chains (or any other string constants) via\n * JS template-literal interpolation. Resolution is iterative: a const may\n * reference earlier-resolved consts via `${other}` interpolation.\n *\n * Only `const` declarations are considered. Non-string initializers,\n * function calls, member access, and any expression that cannot be reduced\n * to a string at parse time are ignored.\n */\nexport function collectStringConstants(oxcProgram: any): Map<string, string> {\n const rawDecls = new Map<string, any>();\n for (const stmt of oxcProgram?.body || []) {\n const decl =\n stmt.type === 'ExportNamedDeclaration' ? stmt.declaration : stmt;\n if (!decl || decl.type !== 'VariableDeclaration' || decl.kind !== 'const')\n continue;\n for (const d of decl.declarations || []) {\n if (d.id?.type === 'Identifier' && d.init) {\n rawDecls.set(d.id.name, d.init);\n }\n }\n }\n\n const resolved = new Map<string, string>();\n // Iterative fixpoint: each pass resolves consts whose dependencies are\n // already known. Bounded by the number of declarations to prevent cycles.\n for (let pass = 0; pass < rawDecls.size + 1; pass++) {\n let progress = false;\n for (const [name, init] of rawDecls) {\n if (resolved.has(name)) continue;\n const value = stringValue(init, resolved);\n if (value !== null) {\n resolved.set(name, value);\n progress = true;\n }\n }\n if (!progress) break;\n }\n return resolved;\n}\n\n/** Get the property key name from an OXC object property. */\nfunction propKeyName(prop: any): string | null {\n if (!prop.key) return null;\n return prop.key.name ?? prop.key.value ?? null;\n}\n\n/**\n * Extract decorator metadata from an OXC decorator AST node.\n * Parses @Component, @Directive, @Pipe, @Injectable, @NgModule arguments.\n *\n * `stringConsts`, when provided, lets string-typed metadata fields\n * (`template`, `selector`, `templateUrl`, `styles`, `styleUrl`, `styleUrls`,\n * `name`, `exportAs`, `providedIn`) resolve module-level string constants\n * referenced via template-literal interpolation, e.g.\n * `template: \\`<div class=\"${tw}\">x</div>\\``.\n */\nexport function extractMetadata(\n dec: any | undefined,\n sourceCode: string,\n stringConsts?: Map<string, string>,\n): any {\n if (!dec) return null;\n const call = dec.expression;\n if (!call || call.type !== 'CallExpression') return null;\n const arg = call.arguments?.[0];\n const meta: any = {\n hostRaw: {},\n inputs: {},\n outputs: {},\n standalone: true,\n imports: [],\n providers: null,\n viewProviders: null,\n animations: null,\n changeDetection: null,\n encapsulation: null,\n preserveWhitespaces: false,\n exportAs: null,\n selector: undefined,\n styles: [],\n templateUrl: null,\n styleUrls: [],\n };\n if (!arg || arg.type !== 'ObjectExpression') return meta;\n\n for (const p of arg.properties || []) {\n if (p.type !== 'ObjectProperty' && p.type !== 'Property') continue;\n const key = propKeyName(p);\n if (!key) continue;\n const valNode = p.value;\n const valText = sourceCode.slice(valNode.start, valNode.end);\n\n switch (key) {\n case 'host':\n if (valNode.type === 'ObjectExpression') {\n for (const hp of valNode.properties || []) {\n if (hp.type !== 'ObjectProperty' && hp.type !== 'Property')\n continue;\n const hKey = propKeyName(hp);\n if (!hKey) continue;\n // Prefer the parsed string value so embedded quotes (e.g. the\n // empty `\"\"` in `'expr ? \"\" : null'`) survive. Falling back to\n // the source slice for non-string values keeps prior behavior\n // for unusual host bindings (e.g. references to constants).\n const sv = stringValue(hp.value, stringConsts);\n const hVal =\n sv !== null\n ? sv\n : sourceCode\n .slice(hp.value.start, hp.value.end)\n .replace(/^['\"`]|['\"`]$/g, '');\n meta.hostRaw[hKey.replace(/^['\"`]|['\"`]$/g, '')] = hVal;\n }\n }\n break;\n case 'changeDetection':\n meta.changeDetection = valText.includes('OnPush') ? 0 : 1;\n break;\n case 'encapsulation':\n meta.encapsulation = valText.includes('None')\n ? 2\n : valText.includes('ShadowDom')\n ? 3\n : 0;\n break;\n case 'preserveWhitespaces':\n meta.preserveWhitespaces = valText === 'true';\n break;\n case 'pure':\n case 'standalone':\n meta[key] = valText !== 'false';\n break;\n case 'template':\n case 'selector':\n case 'name':\n case 'exportAs':\n case 'templateUrl':\n case 'providedIn': {\n const sv = stringValue(valNode, stringConsts);\n if (sv !== null) {\n meta[key] = sv;\n } else if (valNode.type === 'TemplateLiteral') {\n // Template literal with `${...}` interpolations that couldn't\n // all be resolved at parse time (e.g. they reference imports\n // or non-string values). The previous fallback stripped every\n // quote character from the source, which silently corrupted\n // templates such as `<a class=\"${cls} foo\">…</a>` into\n // `<a class=${cls} foo>…</a>` — making Angular's HTML parser\n // fail with confusing errors like `Opening tag \"a\" not\n // terminated`. Instead, walk the quasis and substitute each\n // unresolved interpolation with the empty string so the\n // surrounding HTML (including quoted attributes) is preserved.\n const quasis = valNode.quasis ?? [];\n const expressions = valNode.expressions ?? [];\n let result = '';\n for (let i = 0; i < quasis.length; i++) {\n result += quasis[i]?.value?.cooked ?? '';\n if (i < expressions.length) {\n const expr = expressions[i];\n if (expr?.type === 'Identifier') {\n const resolved = stringConsts?.get(expr.name);\n if (resolved != null) {\n result += resolved;\n continue;\n }\n }\n // Unresolvable — substitute empty string. This keeps the\n // surrounding HTML well-formed even if the resulting class\n // list is incomplete.\n }\n }\n meta[key] = result;\n } else {\n // Non-string, non-template-literal expression. Strip only the\n // outermost JS string delimiters, not every embedded quote.\n meta[key] = valText.replace(/^['\"`]|['\"`]$/g, '');\n }\n if (key === 'exportAs') meta.exportAs = [meta.exportAs];\n break;\n }\n case 'styleUrl': {\n const sv = stringValue(valNode, stringConsts);\n meta.styleUrls = [sv !== null ? sv : valText.replace(/['\"`]/g, '')];\n break;\n }\n case 'styleUrls':\n if (valNode.type === 'ArrayExpression') {\n meta.styleUrls = (valNode.elements || []).map((e: any) => {\n const sv = stringValue(e, stringConsts);\n return sv !== null\n ? sv\n : sourceCode.slice(e.start, e.end).replace(/['\"`]/g, '');\n });\n }\n break;\n case 'styles':\n if (valNode.type === 'ArrayExpression') {\n meta.styles = (valNode.elements || []).map((e: any) => {\n const sv = stringValue(e, stringConsts);\n return sv !== null\n ? sv\n : sourceCode.slice(e.start, e.end).replace(/['\"`]/g, '');\n });\n } else {\n const sv = stringValue(valNode, stringConsts);\n if (sv !== null) meta.styles = [sv];\n }\n break;\n case 'imports':\n case 'providers':\n case 'viewProviders':\n case 'animations':\n case 'rawImports':\n case 'declarations':\n case 'exports':\n case 'bootstrap':\n if (valNode.type === 'ArrayExpression') {\n meta[key] = (valNode.elements || []).map(\n (e: any) => new o.WrappedNodeExpr(unwrapForwardRefOxc(e)),\n );\n }\n break;\n // @Injectable provider configuration. Pass these through to\n // compileInjectable so the emitted `ɵprov` reflects the user's\n // intent. `useClass`/`useExisting`/`useValue` are\n // `MaybeForwardRefExpression` (`{ expression, forwardRef }`);\n // `useFactory` is a bare `Expression`.\n case 'useClass':\n case 'useExisting':\n case 'useValue': {\n const unwrapped = unwrapForwardRefOxc(valNode);\n const isForwardRef =\n valNode.type === 'CallExpression' && unwrapped !== valNode;\n meta[key] = {\n expression: new o.WrappedNodeExpr(unwrapped),\n forwardRef: isForwardRef ? 2 : 0,\n };\n break;\n }\n case 'useFactory':\n meta[key] = new o.WrappedNodeExpr(valNode);\n break;\n case 'hostDirectives':\n if (valNode.type === 'ArrayExpression') {\n meta.hostDirectives = (valNode.elements || [])\n .map((el: any) => {\n // Bare identifier: hostDirectives: [MatTooltip]\n if (el.type === 'Identifier' || el.type === 'CallExpression') {\n const unwrapped = unwrapForwardRefOxc(el);\n const ref = {\n value: new o.WrappedNodeExpr(unwrapped),\n type: new o.WrappedNodeExpr(unwrapped),\n };\n return {\n directive: ref,\n isForwardReference: el.type === 'CallExpression',\n inputs: null,\n outputs: null,\n };\n }\n // Object form: { directive: MatTooltip, inputs: [...], outputs: [...] }\n if (el.type === 'ObjectExpression') {\n let directiveNode: any = null;\n let isForwardRef = false;\n let inputs: Record<string, string> | null = null;\n let outputs: Record<string, string> | null = null;\n for (const prop of el.properties || []) {\n if (\n prop.type !== 'ObjectProperty' &&\n prop.type !== 'Property'\n )\n continue;\n const pName = propKeyName(prop);\n if (pName === 'directive') {\n directiveNode = unwrapForwardRefOxc(prop.value);\n isForwardRef =\n prop.value?.type === 'CallExpression' &&\n sourceCode\n .slice(prop.value.start, prop.value.end)\n .includes('forwardRef');\n } else if (\n pName === 'inputs' &&\n prop.value?.type === 'ArrayExpression'\n ) {\n inputs = {};\n for (const e of prop.value.elements || []) {\n const sv = stringValue(e);\n if (sv !== null) {\n const [source, alias = source] = sv\n .split(':')\n .map((part: string) => part.trim());\n if (source) inputs[source] = alias;\n }\n }\n } else if (\n pName === 'outputs' &&\n prop.value?.type === 'ArrayExpression'\n ) {\n outputs = {};\n for (const e of prop.value.elements || []) {\n const sv = stringValue(e);\n if (sv !== null) {\n const [source, alias = source] = sv\n .split(':')\n .map((part: string) => part.trim());\n if (source) outputs[source] = alias;\n }\n }\n }\n }\n if (directiveNode) {\n const ref = {\n value: new o.WrappedNodeExpr(directiveNode),\n type: new o.WrappedNodeExpr(directiveNode),\n };\n return {\n directive: ref,\n isForwardReference: isForwardRef,\n inputs,\n outputs,\n };\n }\n }\n return null;\n })\n .filter(Boolean);\n }\n break;\n default:\n meta[key] = valText.replace(/['\"`]/g, '');\n }\n }\n return meta;\n}\n\n/**\n * Detect signal-based APIs on class members: input(), model(), output(),\n * viewChild(), contentChild(), viewChildren(), contentChildren().\n */\nexport function detectSignals(classNode: any, sourceCode: string) {\n const inputs: any = {},\n outputs: any = {},\n viewQueries: any[] = [],\n contentQueries: any[] = [];\n\n const members: any[] = classNode.body?.body || [];\n\n for (const m of members) {\n if (\n m.type !== 'PropertyDefinition' ||\n !m.key?.name ||\n !m.value ||\n m.value.type !== 'CallExpression'\n )\n continue;\n\n const name: string = m.key.name;\n const signalCall = getCallApi(m.value);\n if (!signalCall) continue;\n\n const { api, required } = signalCall;\n if (!SIGNAL_APIS.has(api)) continue;\n\n const args: any[] = m.value.arguments || [];\n\n // 1. SIGNAL INPUTS (Standard & Required)\n if (api === 'input') {\n let transform: any = null;\n let alias: string | null = null;\n const optionsArg = required ? args[0] : args[1];\n if (optionsArg?.type === 'ObjectExpression') {\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = propKeyName(prop);\n if (k === 'transform') {\n transform = new o.WrappedNodeExpr(prop.value);\n } else if (k === 'alias') {\n const sv = stringValue(prop.value);\n if (sv !== null) alias = sv;\n }\n }\n }\n inputs[name] = {\n classPropertyName: name,\n // The binding (public) name is the alias if provided, otherwise\n // the class property name. Without honoring `alias`, host\n // directives that map by public name (e.g.\n // `inputs: ['aria-label']` against `ariaLabel = input(null, {\n // alias: 'aria-label' })`) fail at runtime with NG0311.\n bindingPropertyName: alias ?? name,\n isSignal: true,\n required,\n transform,\n };\n }\n\n // 2. MODEL SIGNALS (Writable Inputs)\n else if (api === 'model') {\n // model() supports the same options object as input(); honor `alias`\n // for the same reason (host-directive mappings use the public name).\n let alias: string | null = null;\n const optionsArg = required ? args[0] : args[1];\n if (optionsArg?.type === 'ObjectExpression') {\n for (const prop of optionsArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n if (propKeyName(prop) === 'alias') {\n const sv = stringValue(prop.value);\n if (sv !== null) alias = sv;\n }\n }\n }\n inputs[name] = {\n classPropertyName: name,\n bindingPropertyName: alias ?? name,\n isSignal: true,\n };\n // The compiled `outputs` field is `{ classPropertyName: bindingName }`.\n // Angular inverts this at runtime via\n // `parseAndConvertOutputsForDefinition`, producing the lookup map\n // `{ bindingName: classPropertyName }` used by `listenToOutput`.\n // For a `model()` signal, the class property is `name` and the\n // binding event is `${aliasOrName}Change`, and the model signal\n // itself is the subscribable, so `instance[name]` is what\n // `listenToOutput` needs to resolve.\n outputs[name] = (alias ?? name) + 'Change';\n }\n\n // 3. SIGNAL QUERIES (viewChild, contentChild)\n else if (\n api === 'viewChild' ||\n api === 'viewChildren' ||\n api === 'contentChild' ||\n api === 'contentChildren'\n ) {\n const isViewQuery = api === 'viewChild' || api === 'viewChildren';\n const isChildrenQuery =\n api === 'viewChildren' || api === 'contentChildren';\n\n const firstArg = args[0];\n const sv = stringValue(firstArg);\n\n // Parse the optional second-arg options object for `read` and\n // (content queries only) `descendants`. Without this, queries like\n // `viewChild('ref', { read: ElementRef })` and\n // `contentChildren(Foo, { descendants: false })` silently lose\n // their options at runtime.\n let read: any = null;\n // Defaults match Angular's signal-query API and the decorator\n // path (`isView || isFirst` in detectFieldDecorators):\n // viewChild → true (view queries always traverse)\n // viewChildren → true\n // contentChild → true (single-result content queries\n // traverse by default)\n // contentChildren → false (multi-result content queries are\n // shallow unless explicitly opted in)\n let descendants = isViewQuery || !isChildrenQuery;\n const optArg = args[1];\n if (optArg?.type === 'ObjectExpression') {\n for (const prop of optArg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = propKeyName(prop);\n if (k === 'read') {\n read = new o.WrappedNodeExpr(unwrapForwardRefOxc(prop.value));\n } else if (k === 'descendants') {\n const t = prop.value?.type;\n if (\n t === 'BooleanLiteral' ||\n (t === 'Literal' && typeof prop.value.value === 'boolean')\n ) {\n descendants = prop.value.value;\n }\n }\n }\n }\n\n const query = {\n propertyName: name,\n // Class predicates must be wrapped in an `R3QueryReference`\n // (`{ forwardRef, expression }`); Angular's `getQueryPredicate`\n // dispatches on `predicate.forwardRef` and reads\n // `predicate.expression`, so a bare `WrappedNodeExpr` is silently\n // dropped to `undefined` and emitted as `null`, leaving the query\n // with no target. `0 = ForwardRefHandling.None`.\n predicate:\n sv !== null\n ? [sv]\n : { forwardRef: 0, expression: new o.WrappedNodeExpr(firstArg) },\n first: !isChildrenQuery,\n descendants,\n read,\n static: false,\n emitFlags: 0,\n isSignal: true,\n };\n\n if (isViewQuery) viewQueries.push(query);\n else contentQueries.push(query);\n }\n\n // 4. STANDARD OUTPUTS (output() and outputFromObservable())\n else if (api === 'output' || api === 'outputFromObservable') {\n let alias = name;\n const optArg = args[0];\n if (optArg?.type === 'ObjectExpression') {\n for (const prop of optArg.properties || []) {\n if (\n (prop.type === 'ObjectProperty' || prop.type === 'Property') &&\n propKeyName(prop) === 'alias'\n ) {\n const sv = stringValue(prop.value);\n if (sv !== null) alias = sv;\n }\n }\n }\n outputs[name] = alias;\n }\n }\n\n return { inputs, outputs, viewQueries, contentQueries };\n}\n\n/**\n * Detect decorator-based field metadata: @Input, @Output, @ViewChild,\n * @ContentChild, @ViewChildren, @ContentChildren, @HostBinding, @HostListener.\n */\nexport function detectFieldDecorators(classNode: any, sourceCode: string) {\n const inputs: any = {};\n const outputs: any = {};\n const viewQueries: any[] = [];\n const contentQueries: any[] = [];\n const hostProperties: Record<string, string> = {};\n const hostListeners: Record<string, string> = {};\n\n const members: any[] = classNode.body?.body || [];\n\n for (const member of members) {\n const decorators: any[] = member.decorators || [];\n if (decorators.length === 0) continue;\n\n const memberName: string = member.key?.name || '';\n\n for (const dec of decorators) {\n const expr = dec.expression;\n if (!expr || expr.type !== 'CallExpression') continue;\n const decName: string | undefined = expr.callee?.name;\n if (!decName) continue;\n const args: any[] = expr.arguments || [];\n\n switch (decName) {\n case 'Input': {\n let bindingName = memberName;\n let required = false;\n let transformFunction: any = null;\n\n if (args.length > 0) {\n const arg = args[0];\n const sv = stringValue(arg);\n if (sv !== null) {\n bindingName = sv;\n } else if (arg.type === 'ObjectExpression') {\n for (const prop of arg.properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = propKeyName(prop);\n if (k === 'alias') {\n const asv = stringValue(prop.value);\n if (asv !== null) bindingName = asv;\n }\n if (k === 'required')\n required =\n sourceCode.slice(prop.value.start, prop.value.end) ===\n 'true';\n if (k === 'transform')\n transformFunction = new o.WrappedNodeExpr(prop.value);\n }\n }\n }\n\n inputs[memberName] = {\n classPropertyName: memberName,\n bindingPropertyName: bindingName,\n isSignal: false,\n required,\n transformFunction,\n };\n break;\n }\n\n case 'Output': {\n const sv = args.length > 0 ? stringValue(args[0]) : null;\n const alias = sv !== null ? sv : memberName;\n outputs[memberName] = alias;\n break;\n }\n\n case 'ViewChild':\n case 'ViewChildren':\n case 'ContentChild':\n case 'ContentChildren': {\n const isView = decName.startsWith('View');\n const isFirst = decName === 'ViewChild' || decName === 'ContentChild';\n\n // Default predicate when no argument is given is the member\n // name. Class predicates (the non-string case) must be wrapped\n // in an `R3QueryReference` (`{ forwardRef, expression }`) so\n // Angular's `getQueryPredicate` can dispatch on `forwardRef`\n // and read `.expression`. A bare `WrappedNodeExpr` is silently\n // dropped to undefined and emitted as `null`.\n let predicate: any = [memberName];\n if (args.length > 0) {\n const pred = args[0];\n const sv = stringValue(pred);\n if (sv !== null) {\n predicate = [sv];\n } else {\n predicate = {\n forwardRef: 0,\n expression: new o.WrappedNodeExpr(unwrapForwardRefOxc(pred)),\n };\n }\n }\n\n let read: any = null;\n let isStatic = false;\n let descendants = isView || isFirst;\n\n if (args.length > 1 && args[1]?.type === 'ObjectExpression') {\n for (const prop of args[1].properties || []) {\n if (prop.type !== 'ObjectProperty' && prop.type !== 'Property')\n continue;\n const k = propKeyName(prop);\n if (k === 'read') read = new o.WrappedNodeExpr(prop.value);\n if (k === 'static')\n isStatic =\n sourceCode.slice(prop.value.start, prop.value.end) === 'true';\n if (k === 'descendants')\n descendants =\n sourceCode.slice(prop.value.start, prop.value.end) === 'true';\n }\n }\n\n const query = {\n propertyName: memberName,\n predicate,\n first: isFirst,\n descendants,\n read,\n static: isStatic,\n emitFlags: 0,\n isSignal: false,\n };\n\n if (isView) viewQueries.push(query);\n else contentQueries.push(query);\n break;\n }\n\n case 'HostBinding': {\n const sv = args.length > 0 ? stringValue(args[0]) : null;\n const target = sv !== null ? sv : memberName;\n hostProperties[target] = memberName;\n break;\n }\n\n case 'HostListener': {\n const sv = args.length > 0 ? stringValue(args[0]) : null;\n if (sv !== null) {\n const event = sv;\n let handler = `${memberName}()`;\n if (args.length > 1 && args[1]?.type === 'ArrayExpression') {\n const handlerArgs = (args[1].elements || [])\n .map((e: any) => stringValue(e))\n .filter((v: string | null): v is string => v !== null)\n .join(', ');\n handler = `${memberName}(${handlerArgs})`;\n }\n hostListeners[event] = handler;\n }\n break;\n }\n }\n }\n }\n\n return {\n inputs,\n outputs,\n viewQueries,\n contentQueries,\n hostProperties,\n hostListeners,\n };\n}\n\n/**\n * Analyze constructor parameters for dependency injection.\n * Returns:\n * - R3DependencyMetadata[] for normal constructors\n * - null if class extends another without own constructor (use inherited factory)\n * - 'invalid' if any parameter has a type-only import token\n *\n * Accepts an OXC ClassDeclaration node and the original source string.\n */\nexport function extractConstructorDeps(\n classNode: any,\n sourceCode: string,\n typeOnlyImports: Set<string>,\n): any[] | 'invalid' | null {\n const heritage: any[] = classNode.superClass ? [classNode.superClass] : [];\n const hasSuper = heritage.length > 0;\n\n const members: any[] = classNode.body?.body || [];\n const ctor = members.find(\n (m: any) => m.type === 'MethodDefinition' && m.kind === 'constructor',\n );\n\n if (!ctor) {\n return hasSuper ? null : [];\n }\n\n const params: any[] = ctor.value?.params?.items || ctor.value?.params || [];\n const deps: any[] = [];\n let invalid = false;\n\n for (const param of params) {\n let token: string | null = null;\n let attributeNameType: any = null;\n let host = false,\n optional = false,\n self = false,\n skipSelf = false;\n\n // Handle TSParameterProperty (e.g., constructor(private foo: Bar))\n const actualParam =\n param.type === 'TSParameterProperty' ? param.parameter : param;\n const typeAnn =\n actualParam?.typeAnnotation?.typeAnnotation ??\n param?.typeAnnotation?.typeAnnotation;\n\n // Extract type annotation as token\n if (typeAnn) {\n if (typeAnn.type === 'TSTypeReference' && typeAnn.typeName) {\n token =\n typeAnn.typeName.name ??\n sourceCode.slice(typeAnn.typeName.start, typeAnn.typeName.end);\n } else if (typeAnn.type === 'TSUnionType') {\n // Filter out null/undefined/void arms — `T | null` and\n // `T | undefined` are common patterns that should resolve to T.\n // Anything else (multiple TypeReference arms, primitives, etc.)\n // is ambiguous and ngtsc rejects it. Mark as invalid so the\n // factory falls through to ɵɵinvalidFactory rather than\n // silently picking the first arm.\n const nonNullTypes = (typeAnn.types || []).filter((t: any) => {\n if (!t) return false;\n if (t.type === 'TSNullKeyword') return false;\n if (t.type === 'TSUndefinedKeyword') return false;\n if (t.type === 'TSVoidKeyword') return false;\n if (\n t.type === 'TSLiteralType' &&\n (t.literal?.type === 'NullLiteral' ||\n (t.literal?.type === 'Literal' && t.literal.value === null))\n ) {\n return false;\n }\n return true;\n });\n if (\n nonNullTypes.length === 1 &&\n nonNullTypes[0].type === 'TSTypeReference' &&\n nonNullTypes[0].typeName\n ) {\n const t = nonNullTypes[0];\n token =\n t.typeName.name ??\n sourceCode.slice(t.typeName.start, t.typeName.end);\n } else {\n // Ambiguous union — no suitable injection token.\n invalid = true;\n continue;\n }\n } else if (typeAnn.type === 'TSIntersectionType') {\n // Intersection types (`A & B`) have no single injection token.\n invalid = true;\n continue;\n }\n }\n\n // Process parameter decorators (may live on TSParameterProperty or inner param)\n const paramDecs: any[] = [\n ...(param.decorators || []),\n ...(param.type === 'TSParameterProperty' && actualParam?.decorators\n ? actualParam.decorators\n : []),\n ];\n for (const dec of paramDecs) {\n const expr = dec.expression;\n if (!expr || expr.type !== 'CallExpression') continue;\n const decName: string | undefined = expr.callee?.name;\n if (!decName) continue;\n const args: any[] = expr.arguments || [];\n\n switch (decName) {\n case 'Inject':\n if (args.length > 0) {\n const sv = stringValue(args[0]);\n if (sv !== null) {\n token = sv;\n } else {\n // Unwrap `@Inject(forwardRef(() => TOKEN))` so the\n // emitted token references TOKEN directly. Without this\n // the raw `forwardRef(() => TOKEN)` source slice would\n // appear in the factory output, producing broken code\n // that calls forwardRef at definition time.\n const unwrapped = unwrapForwardRefOxc(args[0]);\n token = sourceCode.slice(unwrapped.start, unwrapped.end);\n }\n }\n break;\n case 'Optional':\n optional = true;\n break;\n case 'Self':\n self = true;\n break;\n case 'SkipSelf':\n skipSelf = true;\n break;\n case 'Host':\n host = true;\n break;\n case 'Attribute':\n if (args.length > 0) {\n const sv = stringValue(args[0]);\n if (sv !== null) {\n attributeNameType = new o.LiteralExpr(sv);\n token = '';\n }\n }\n break;\n }\n }\n\n if (!token && !attributeNameType) {\n invalid = true;\n continue;\n }\n\n if (token && typeOnlyImports.has(token)) {\n invalid = true;\n continue;\n }\n\n deps.push({\n token: token ? new o.WrappedNodeExpr(token) : new o.LiteralExpr(null),\n attributeNameType,\n host,\n optional,\n self,\n skipSelf,\n });\n }\n\n return invalid ? 'invalid' : deps;\n}\n"],"mappings":";;;;AAIA,SAAS,WAAW,MAAsD;CACxE,MAAM,SAAS,KAAK;AACpB,KAAI,CAAC,OAAQ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
3
|
+
bindingPropertyName: string;
|
|
4
|
+
isSignal: boolean;
|
|
5
|
+
required: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* `true` when the input declares a `transform` function. The actual
|
|
8
|
+
* transform expression isn't usable cross-file, but downstream tools
|
|
9
|
+
* (template type checking, codegen widening) need to know whether
|
|
10
|
+
* one exists so they can broaden the accepted binding type.
|
|
11
|
+
*/
|
|
12
|
+
hasTransform?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface RegistryEntry {
|
|
15
|
+
/** CSS selector for components/directives, pipe name for pipes, class name for NgModules */
|
|
16
|
+
selector: string;
|
|
17
|
+
/** What kind of Angular declaration this is */
|
|
18
|
+
kind: "component" | "directive" | "pipe" | "ngmodule" | "tuple";
|
|
19
|
+
/** The pipe name (only for pipes) */
|
|
20
|
+
pipeName?: string;
|
|
21
|
+
/** Exported class names (only for NgModules) */
|
|
22
|
+
exports?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Member class names (only for `tuple` kind) — produced by top-level
|
|
25
|
+
* `export const X = [A, B, C] as const` style barrels common in
|
|
26
|
+
* helm/spartan-style libraries. The compiler expands these into the
|
|
27
|
+
* underlying directives when they appear in another component's
|
|
28
|
+
* `imports` array, mirroring how Angular's official compiler resolves
|
|
29
|
+
* static `imports` references at compile time.
|
|
30
|
+
*/
|
|
31
|
+
members?: string[];
|
|
32
|
+
/** The source file this declaration was found in */
|
|
33
|
+
fileName: string;
|
|
34
|
+
/** The class name */
|
|
35
|
+
className: string;
|
|
36
|
+
/** Input bindings (from signal APIs and @Input decorators) */
|
|
37
|
+
inputs?: Record<string, RegistryInput>;
|
|
38
|
+
/** Output bindings (from signal APIs and @Output decorators) */
|
|
39
|
+
outputs?: Record<string, string>;
|
|
40
|
+
/** The package this declaration was scanned from (e.g. "@angular/cdk") */
|
|
41
|
+
sourcePackage?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Maps class name → registry entry */
|
|
44
|
+
export type ComponentRegistry = Map<string, RegistryEntry>;
|
|
45
|
+
/**
|
|
46
|
+
* Lightweight scan of a TypeScript file to extract Angular decorator metadata
|
|
47
|
+
* without performing full compilation. Uses OXC's native Rust parser for speed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function scanFile(code: string, fileName: string): RegistryEntry[];
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { COMPILABLE_DECORATORS } from "./constants.js";
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
|
+
//#region packages/vite-plugin-angular/src/lib/compiler/registry.ts
|
|
4
|
+
var DECORATOR_RE = new RegExp(`@(${[...COMPILABLE_DECORATORS].join("|")})`);
|
|
5
|
+
/**
|
|
6
|
+
* Lightweight scan of a TypeScript file to extract Angular decorator metadata
|
|
7
|
+
* without performing full compilation. Uses OXC's native Rust parser for speed.
|
|
8
|
+
*/
|
|
9
|
+
function scanFile(code, fileName) {
|
|
10
|
+
const entries = [];
|
|
11
|
+
if (!DECORATOR_RE.test(code) && !/\bconst\s+\w+\s*=\s*\[/.test(code)) return entries;
|
|
12
|
+
const { program } = parseSync(fileName, code);
|
|
13
|
+
for (const node of program.body) {
|
|
14
|
+
const varDecl = node.type === "ExportNamedDeclaration" && node.declaration?.type === "VariableDeclaration" ? node.declaration : node.type === "VariableDeclaration" ? node : null;
|
|
15
|
+
if (!varDecl || varDecl.kind !== "const") continue;
|
|
16
|
+
for (const declarator of varDecl.declarations || []) {
|
|
17
|
+
if (declarator.id?.type !== "Identifier") continue;
|
|
18
|
+
let init = declarator.init;
|
|
19
|
+
if (init?.type === "TSAsExpression") init = init.expression;
|
|
20
|
+
if (init?.type !== "ArrayExpression") continue;
|
|
21
|
+
const members = [];
|
|
22
|
+
let allClassRefs = true;
|
|
23
|
+
for (const el of init.elements || []) {
|
|
24
|
+
if (el?.type !== "Identifier") {
|
|
25
|
+
allClassRefs = false;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
members.push(el.name);
|
|
29
|
+
}
|
|
30
|
+
if (!allClassRefs || members.length === 0) continue;
|
|
31
|
+
const tupleName = declarator.id.name;
|
|
32
|
+
entries.push({
|
|
33
|
+
selector: tupleName,
|
|
34
|
+
kind: "tuple",
|
|
35
|
+
members,
|
|
36
|
+
fileName,
|
|
37
|
+
className: tupleName
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const node of program.body) {
|
|
42
|
+
const decl = node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
43
|
+
if (!decl || decl.type !== "ClassDeclaration") continue;
|
|
44
|
+
if (!decl.id?.name) continue;
|
|
45
|
+
const className = decl.id.name;
|
|
46
|
+
const decorators = decl.decorators || [];
|
|
47
|
+
for (const dec of decorators) {
|
|
48
|
+
const expr = dec.expression;
|
|
49
|
+
if (!expr || expr.type !== "CallExpression") continue;
|
|
50
|
+
const decoratorName = expr.callee?.name;
|
|
51
|
+
if (!COMPILABLE_DECORATORS.has(decoratorName)) continue;
|
|
52
|
+
const arg = expr.arguments?.[0];
|
|
53
|
+
if (!arg || arg.type !== "ObjectExpression") continue;
|
|
54
|
+
let selector;
|
|
55
|
+
let pipeName;
|
|
56
|
+
let moduleExports;
|
|
57
|
+
for (const prop of arg.properties) {
|
|
58
|
+
if (prop.type !== "Property") continue;
|
|
59
|
+
const key = prop.key?.name || prop.key?.value;
|
|
60
|
+
const val = prop.value;
|
|
61
|
+
if (key === "selector" && val?.type === "Literal" && typeof val.value === "string") selector = val.value;
|
|
62
|
+
if (key === "name" && val?.type === "Literal" && typeof val.value === "string" && decoratorName === "Pipe") pipeName = val.value;
|
|
63
|
+
if (key === "exports" && val?.type === "ArrayExpression" && decoratorName === "NgModule") moduleExports = val.elements.filter((e) => e?.type === "Identifier").map((e) => e.name);
|
|
64
|
+
}
|
|
65
|
+
if (decoratorName === "NgModule") entries.push({
|
|
66
|
+
selector: className,
|
|
67
|
+
kind: "ngmodule",
|
|
68
|
+
exports: moduleExports || [],
|
|
69
|
+
fileName,
|
|
70
|
+
className
|
|
71
|
+
});
|
|
72
|
+
else if (decoratorName === "Pipe" && pipeName) entries.push({
|
|
73
|
+
selector: pipeName,
|
|
74
|
+
kind: "pipe",
|
|
75
|
+
pipeName,
|
|
76
|
+
fileName,
|
|
77
|
+
className
|
|
78
|
+
});
|
|
79
|
+
else if (selector) {
|
|
80
|
+
const inputs = {};
|
|
81
|
+
const outputs = {};
|
|
82
|
+
const members = decl.body?.body || [];
|
|
83
|
+
for (const member of members) {
|
|
84
|
+
if (member.type !== "PropertyDefinition" || !member.key?.name) continue;
|
|
85
|
+
const name = member.key.name;
|
|
86
|
+
const init = member.value;
|
|
87
|
+
if (init?.type === "CallExpression") {
|
|
88
|
+
const callee = init.callee;
|
|
89
|
+
let calleeName = "";
|
|
90
|
+
if (callee?.type === "Identifier") calleeName = callee.name;
|
|
91
|
+
else if (callee?.type === "StaticMemberExpression" || callee?.type === "MemberExpression") calleeName = (callee.object?.name || "") + "." + (callee.property?.name || "");
|
|
92
|
+
const aliasFromArg = (argIndex) => {
|
|
93
|
+
const optionsArg = init.arguments?.[argIndex];
|
|
94
|
+
if (optionsArg?.type !== "ObjectExpression") return null;
|
|
95
|
+
for (const prop of optionsArg.properties || []) {
|
|
96
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "Property") continue;
|
|
97
|
+
if ((prop.key?.name ?? prop.key?.value) !== "alias") continue;
|
|
98
|
+
const v = prop.value;
|
|
99
|
+
if (v?.type === "StringLiteral" || v?.type === "Literal" && typeof v.value === "string") return v.value;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
const hasTransformAtArg = (argIndex) => {
|
|
104
|
+
const optionsArg = init.arguments?.[argIndex];
|
|
105
|
+
if (optionsArg?.type !== "ObjectExpression") return false;
|
|
106
|
+
for (const prop of optionsArg.properties || []) {
|
|
107
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "Property") continue;
|
|
108
|
+
if ((prop.key?.name ?? prop.key?.value) === "transform") return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
};
|
|
112
|
+
const inputAliasIndex = calleeName === "input.required" || calleeName === "model.required" ? 0 : 1;
|
|
113
|
+
if (calleeName === "input" || calleeName === "input.required") {
|
|
114
|
+
const alias = aliasFromArg(inputAliasIndex);
|
|
115
|
+
const hasTransform = hasTransformAtArg(inputAliasIndex);
|
|
116
|
+
inputs[name] = {
|
|
117
|
+
classPropertyName: name,
|
|
118
|
+
bindingPropertyName: alias ?? name,
|
|
119
|
+
isSignal: true,
|
|
120
|
+
required: calleeName === "input.required",
|
|
121
|
+
...hasTransform ? { hasTransform: true } : {}
|
|
122
|
+
};
|
|
123
|
+
} else if (calleeName === "model" || calleeName === "model.required") {
|
|
124
|
+
const alias = aliasFromArg(inputAliasIndex);
|
|
125
|
+
inputs[name] = {
|
|
126
|
+
classPropertyName: name,
|
|
127
|
+
bindingPropertyName: alias ?? name,
|
|
128
|
+
isSignal: true,
|
|
129
|
+
required: calleeName === "model.required"
|
|
130
|
+
};
|
|
131
|
+
outputs[name] = (alias ?? name) + "Change";
|
|
132
|
+
} else if (calleeName === "output" || calleeName === "outputFromObservable") outputs[name] = aliasFromArg(calleeName === "outputFromObservable" ? 1 : 0) ?? name;
|
|
133
|
+
}
|
|
134
|
+
const memberDecorators = member.decorators || [];
|
|
135
|
+
for (const mdec of memberDecorators) {
|
|
136
|
+
const mexpr = mdec.expression;
|
|
137
|
+
if (!mexpr) continue;
|
|
138
|
+
const mdecName = mexpr.type === "CallExpression" ? mexpr.callee?.name : mexpr.type === "Identifier" ? mexpr.name : void 0;
|
|
139
|
+
if (mdecName === "Input") inputs[name] = {
|
|
140
|
+
classPropertyName: name,
|
|
141
|
+
bindingPropertyName: (mexpr.arguments?.[0]?.type === "Literal" ? mexpr.arguments[0].value : name) || name,
|
|
142
|
+
isSignal: false,
|
|
143
|
+
required: false
|
|
144
|
+
};
|
|
145
|
+
else if (mdecName === "Output") outputs[name] = (mexpr.arguments?.[0]?.type === "Literal" ? mexpr.arguments[0].value : name) || name;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
entries.push({
|
|
149
|
+
selector: selector.split(",")[0].trim(),
|
|
150
|
+
kind: decoratorName === "Component" ? "component" : "directive",
|
|
151
|
+
fileName,
|
|
152
|
+
className,
|
|
153
|
+
...Object.keys(inputs).length > 0 ? { inputs } : {},
|
|
154
|
+
...Object.keys(outputs).length > 0 ? { outputs } : {}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return entries;
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { scanFile };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../../../src/lib/compiler/registry.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\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 /**\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(code: string, fileName: string): 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 const { program } = parseSync(fileName, code);\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\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 (\n key === 'exports' &&\n val?.type === 'ArrayExpression' &&\n decoratorName === 'NgModule'\n ) {\n moduleExports = val.elements\n .filter((e: any) => e?.type === 'Identifier')\n .map((e: any) => e.name);\n }\n }\n\n if (decoratorName === 'NgModule') {\n entries.push({\n selector: className,\n kind: 'ngmodule',\n exports: moduleExports || [],\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"],"mappings":";;;AAkDA,IAAM,eAAe,IAAI,OAAO,KAAK,CAAC,GAAG,sBAAsB,CAAC,KAAK,IAAI,CAAC,GAAG;;;;;AAM7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,eAAe,YACf,eAAe,uBAOf,SAAQ,QAHM,aACZ,eAAe,yBAAyB,IAAI,EAC7C,IACwB;;KAK7B,MAAM,mBAA0B,OAAO,cAAc,EAAE;AACvD,UAAK,MAAM,QAAQ,kBAAkB;MACnC,MAAM,QAAQ,KAAK;AACnB,UAAI,CAAC,MAAO;MACZ,MAAM,WACJ,MAAM,SAAS,mBACX,MAAM,QAAQ,OACd,MAAM,SAAS,eACb,MAAM,OACN,KAAA;AACR,UAAI,aAAa,QAKf,QAAO,QAAQ;OACb,mBAAmB;OACnB,sBALA,MAAM,YAAY,IAAI,SAAS,YAC3B,MAAM,UAAU,GAAG,QACnB,SAG0B;OAC9B,UAAU;OACV,UAAU;OACX;eACQ,aAAa,SAKtB,SAAQ,SAHN,MAAM,YAAY,IAAI,SAAS,YAC3B,MAAM,UAAU,GAAG,QACnB,SACmB;;;AAK/B,YAAQ,KAAK;KACX,UAAU,SAAS,MAAM,IAAI,CAAC,GAAG,MAAM;KACvC,MAAM,kBAAkB,cAAc,cAAc;KACpD;KACA;KACA,GAAI,OAAO,KAAK,OAAO,CAAC,SAAS,IAAI,EAAE,QAAQ,GAAG,EAAE;KACpD,GAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,IAAI,EAAE,SAAS,GAAG,EAAE;KACvD,CAAC;;;;AAKR,QAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline external templateUrl and styleUrl/styleUrls into the source code
|
|
3
|
+
* using OXC parser for precise AST-based rewriting.
|
|
4
|
+
*
|
|
5
|
+
* Replaces:
|
|
6
|
+
* templateUrl: './file.html' → template: "...file contents..."
|
|
7
|
+
* styleUrl: './file.css' → styles: ["...file contents..."]
|
|
8
|
+
* styleUrls: ['./a.css'] → styles: ["...contents..."]
|
|
9
|
+
*
|
|
10
|
+
* When the decorator already has a `styles: [...]` array, inlined CSS is
|
|
11
|
+
* merged into that existing array instead of emitting a second `styles`
|
|
12
|
+
* property (which would be a duplicate object literal key).
|
|
13
|
+
*
|
|
14
|
+
* Returns the modified source code, or the original if no changes were needed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function inlineResourceUrls(code: string, fileName: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Extract inline style strings from Angular @Component decorator using OXC parser.
|
|
19
|
+
* Returns an array of style string values for preprocessing.
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractInlineStyles(code: string, fileName: string): string[];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { extractInlineStyles as extractInlineStyles$1 } from "./style-ast.js";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path$1 from "node:path";
|
|
4
|
+
import { parseSync } from "oxc-parser";
|
|
5
|
+
import MagicString from "magic-string";
|
|
6
|
+
//#region packages/vite-plugin-angular/src/lib/compiler/resource-inliner.ts
|
|
7
|
+
/**
|
|
8
|
+
* Inline external templateUrl and styleUrl/styleUrls into the source code
|
|
9
|
+
* using OXC parser for precise AST-based rewriting.
|
|
10
|
+
*
|
|
11
|
+
* Replaces:
|
|
12
|
+
* templateUrl: './file.html' → template: "...file contents..."
|
|
13
|
+
* styleUrl: './file.css' → styles: ["...file contents..."]
|
|
14
|
+
* styleUrls: ['./a.css'] → styles: ["...contents..."]
|
|
15
|
+
*
|
|
16
|
+
* When the decorator already has a `styles: [...]` array, inlined CSS is
|
|
17
|
+
* merged into that existing array instead of emitting a second `styles`
|
|
18
|
+
* property (which would be a duplicate object literal key).
|
|
19
|
+
*
|
|
20
|
+
* Returns the modified source code, or the original if no changes were needed.
|
|
21
|
+
*/
|
|
22
|
+
function inlineResourceUrls(code, fileName) {
|
|
23
|
+
if (!code.includes("templateUrl") && !code.includes("styleUrl")) return code;
|
|
24
|
+
const { program } = parseSync(fileName, code);
|
|
25
|
+
const ms = new MagicString(code);
|
|
26
|
+
let changed = false;
|
|
27
|
+
const dir = path$1.dirname(fileName);
|
|
28
|
+
for (const node of program.body) {
|
|
29
|
+
const decl = node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
30
|
+
if (!decl || decl.type !== "ClassDeclaration") continue;
|
|
31
|
+
for (const dec of decl.decorators || []) {
|
|
32
|
+
const expr = dec.expression;
|
|
33
|
+
if (!expr || expr.type !== "CallExpression") continue;
|
|
34
|
+
if (expr.callee?.name !== "Component") continue;
|
|
35
|
+
const arg = expr.arguments?.[0];
|
|
36
|
+
if (!arg || arg.type !== "ObjectExpression") continue;
|
|
37
|
+
let existingStylesArray = null;
|
|
38
|
+
for (const prop of arg.properties) {
|
|
39
|
+
if (prop.type !== "Property") continue;
|
|
40
|
+
if ((prop.key?.name ?? prop.key?.value) === "styles" && prop.value?.type === "ArrayExpression") {
|
|
41
|
+
existingStylesArray = prop.value;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const templateUrlRewrites = [];
|
|
46
|
+
const cssProps = [];
|
|
47
|
+
for (const prop of arg.properties) {
|
|
48
|
+
if (prop.type !== "Property") continue;
|
|
49
|
+
const key = prop.key?.name ?? prop.key?.value;
|
|
50
|
+
const val = prop.value;
|
|
51
|
+
if (key === "templateUrl" && val?.type === "Literal" && typeof val.value === "string") {
|
|
52
|
+
try {
|
|
53
|
+
const filePath = path$1.resolve(dir, val.value);
|
|
54
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
55
|
+
templateUrlRewrites.push({
|
|
56
|
+
prop,
|
|
57
|
+
content
|
|
58
|
+
});
|
|
59
|
+
} catch {}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (key === "styleUrl" && val?.type === "Literal" && typeof val.value === "string") {
|
|
63
|
+
try {
|
|
64
|
+
const filePath = path$1.resolve(dir, val.value);
|
|
65
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
66
|
+
cssProps.push({
|
|
67
|
+
prop,
|
|
68
|
+
contents: [content]
|
|
69
|
+
});
|
|
70
|
+
} catch {}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (key === "styleUrls" && val?.type === "ArrayExpression") {
|
|
74
|
+
const contents = [];
|
|
75
|
+
let allRead = true;
|
|
76
|
+
for (const el of val.elements) if (el?.type === "Literal" && typeof el.value === "string") try {
|
|
77
|
+
const filePath = path$1.resolve(dir, el.value);
|
|
78
|
+
contents.push(fs.readFileSync(filePath, "utf-8"));
|
|
79
|
+
} catch {
|
|
80
|
+
allRead = false;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (allRead && contents.length > 0) cssProps.push({
|
|
84
|
+
prop,
|
|
85
|
+
contents
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const { prop, content } of templateUrlRewrites) {
|
|
90
|
+
ms.overwrite(prop.start, prop.end, `template: ${JSON.stringify(content)}`);
|
|
91
|
+
changed = true;
|
|
92
|
+
}
|
|
93
|
+
if (cssProps.length > 0) {
|
|
94
|
+
const allContents = cssProps.flatMap((c) => c.contents);
|
|
95
|
+
if (existingStylesArray) {
|
|
96
|
+
const realElements = existingStylesArray.elements.filter((e) => e != null);
|
|
97
|
+
if (realElements.length > 0) {
|
|
98
|
+
const lastElement = realElements[realElements.length - 1];
|
|
99
|
+
const insertion = allContents.map((c) => `, ${JSON.stringify(c)}`).join("");
|
|
100
|
+
ms.appendRight(lastElement.end, insertion);
|
|
101
|
+
} else {
|
|
102
|
+
const insertion = allContents.map((c) => JSON.stringify(c)).join(", ");
|
|
103
|
+
ms.appendLeft(existingStylesArray.end - 1, insertion);
|
|
104
|
+
}
|
|
105
|
+
for (const { prop } of cssProps) removePropertyWithSeparator(ms, code, prop.start, prop.end);
|
|
106
|
+
} else {
|
|
107
|
+
const [first, ...rest] = cssProps;
|
|
108
|
+
ms.overwrite(first.prop.start, first.prop.end, `styles: [${allContents.map((c) => JSON.stringify(c)).join(", ")}]`);
|
|
109
|
+
for (const { prop } of rest) removePropertyWithSeparator(ms, code, prop.start, prop.end);
|
|
110
|
+
}
|
|
111
|
+
changed = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return changed ? ms.toString() : code;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Remove a property from an object literal while also eating one surrounding
|
|
119
|
+
* comma so the resulting object stays syntactically valid. Prefers the
|
|
120
|
+
* trailing comma; falls back to the leading comma when the property is the
|
|
121
|
+
* last entry in the object.
|
|
122
|
+
*/
|
|
123
|
+
function removePropertyWithSeparator(ms, code, propStart, propEnd) {
|
|
124
|
+
let i = propEnd;
|
|
125
|
+
while (i < code.length && isWhitespace(code[i])) i++;
|
|
126
|
+
if (code[i] === ",") {
|
|
127
|
+
ms.remove(propStart, i + 1);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let j = propStart - 1;
|
|
131
|
+
while (j >= 0 && isWhitespace(code[j])) j--;
|
|
132
|
+
if (code[j] === ",") {
|
|
133
|
+
ms.remove(j, propEnd);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
ms.remove(propStart, propEnd);
|
|
137
|
+
}
|
|
138
|
+
function isWhitespace(ch) {
|
|
139
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract inline style strings from Angular @Component decorator using OXC parser.
|
|
143
|
+
* Returns an array of style string values for preprocessing.
|
|
144
|
+
*/
|
|
145
|
+
function extractInlineStyles(code, fileName) {
|
|
146
|
+
if (!code.includes("styles")) return [];
|
|
147
|
+
return extractInlineStyles$1(code, fileName);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { extractInlineStyles, inlineResourceUrls };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=resource-inliner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-inliner.js","names":[],"sources":["../../../../src/lib/compiler/resource-inliner.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { parseSync } from 'oxc-parser';\nimport MagicString from 'magic-string';\nimport { extractInlineStyles as extractStylesFromAst } from './style-ast.js';\n\n/**\n * Inline external templateUrl and styleUrl/styleUrls into the source code\n * using OXC parser for precise AST-based rewriting.\n *\n * Replaces:\n * templateUrl: './file.html' → template: \"...file contents...\"\n * styleUrl: './file.css' → styles: [\"...file contents...\"]\n * styleUrls: ['./a.css'] → styles: [\"...contents...\"]\n *\n * When the decorator already has a `styles: [...]` array, inlined CSS is\n * merged into that existing array instead of emitting a second `styles`\n * property (which would be a duplicate object literal key).\n *\n * Returns the modified source code, or the original if no changes were needed.\n */\nexport function inlineResourceUrls(code: string, fileName: string): string {\n if (!code.includes('templateUrl') && !code.includes('styleUrl')) {\n return code;\n }\n\n const { program } = parseSync(fileName, code);\n const ms = new MagicString(code);\n let changed = false;\n const dir = path.dirname(fileName);\n\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 || decl.type !== 'ClassDeclaration') continue;\n\n for (const dec of decl.decorators || []) {\n const expr = dec.expression;\n if (!expr || expr.type !== 'CallExpression') continue;\n if (expr.callee?.name !== 'Component') continue;\n\n const arg = expr.arguments?.[0];\n if (!arg || arg.type !== 'ObjectExpression') continue;\n\n // First pass: locate an existing `styles: [...]` array in the same\n // decorator. Inlined CSS will be merged into it to avoid duplicate keys.\n let existingStylesArray: any = null;\n for (const prop of arg.properties) {\n if (prop.type !== 'Property') continue;\n const key: string = prop.key?.name ?? prop.key?.value;\n if (key === 'styles' && prop.value?.type === 'ArrayExpression') {\n existingStylesArray = prop.value;\n break;\n }\n }\n\n // Collect the props we want to rewrite. Contents from styleUrl /\n // styleUrls are accumulated so that multiple url-based props in one\n // decorator collapse into a single `styles` array write.\n const templateUrlRewrites: Array<{ prop: any; content: string }> = [];\n const cssProps: Array<{ prop: any; contents: 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 === 'templateUrl' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string'\n ) {\n try {\n const filePath = path.resolve(dir, val.value);\n const content = fs.readFileSync(filePath, 'utf-8');\n templateUrlRewrites.push({ prop, content });\n } catch {\n // Keep original if file can't be read\n }\n continue;\n }\n\n if (\n key === 'styleUrl' &&\n val?.type === 'Literal' &&\n typeof val.value === 'string'\n ) {\n try {\n const filePath = path.resolve(dir, val.value);\n const content = fs.readFileSync(filePath, 'utf-8');\n cssProps.push({ prop, contents: [content] });\n } catch {\n // Keep original if file can't be read\n }\n continue;\n }\n\n if (key === 'styleUrls' && val?.type === 'ArrayExpression') {\n const contents: string[] = [];\n let allRead = true;\n for (const el of val.elements) {\n if (el?.type === 'Literal' && typeof el.value === 'string') {\n try {\n const filePath = path.resolve(dir, el.value);\n contents.push(fs.readFileSync(filePath, 'utf-8'));\n } catch {\n allRead = false;\n break;\n }\n }\n }\n if (allRead && contents.length > 0) {\n cssProps.push({ prop, contents });\n }\n }\n }\n\n for (const { prop, content } of templateUrlRewrites) {\n ms.overwrite(\n prop.start,\n prop.end,\n `template: ${JSON.stringify(content)}`,\n );\n changed = true;\n }\n\n if (cssProps.length > 0) {\n const allContents = cssProps.flatMap((c) => c.contents);\n\n if (existingStylesArray) {\n // Filter out null holes in case the source already has a sparse array.\n const realElements = (existingStylesArray.elements as any[]).filter(\n (e) => e != null,\n );\n\n if (realElements.length > 0) {\n // Insert right after the last real element. This preserves any\n // trailing comma the source may have (e.g. Prettier output) and\n // avoids producing a sparse `[existing, , \"new\"]` element, which\n // would crash downstream decorator metadata extraction.\n const lastElement = realElements[realElements.length - 1];\n const insertion = allContents\n .map((c) => `, ${JSON.stringify(c)}`)\n .join('');\n ms.appendRight(lastElement.end, insertion);\n } else {\n // Empty array — drop the leading comma.\n const insertion = allContents\n .map((c) => JSON.stringify(c))\n .join(', ');\n ms.appendLeft(existingStylesArray.end - 1, insertion);\n }\n\n for (const { prop } of cssProps) {\n removePropertyWithSeparator(ms, code, prop.start, prop.end);\n }\n } else {\n // No existing `styles` array — rewrite the first styleUrl/styleUrls\n // prop with the merged contents and drop any additional ones so we\n // don't emit multiple `styles` properties.\n const [first, ...rest] = cssProps;\n ms.overwrite(\n first.prop.start,\n first.prop.end,\n `styles: [${allContents.map((c) => JSON.stringify(c)).join(', ')}]`,\n );\n for (const { prop } of rest) {\n removePropertyWithSeparator(ms, code, prop.start, prop.end);\n }\n }\n changed = true;\n }\n }\n }\n\n return changed ? ms.toString() : code;\n}\n\n/**\n * Remove a property from an object literal while also eating one surrounding\n * comma so the resulting object stays syntactically valid. Prefers the\n * trailing comma; falls back to the leading comma when the property is the\n * last entry in the object.\n */\nfunction removePropertyWithSeparator(\n ms: MagicString,\n code: string,\n propStart: number,\n propEnd: number,\n): void {\n let i = propEnd;\n while (i < code.length && isWhitespace(code[i])) i++;\n if (code[i] === ',') {\n ms.remove(propStart, i + 1);\n return;\n }\n let j = propStart - 1;\n while (j >= 0 && isWhitespace(code[j])) j--;\n if (code[j] === ',') {\n ms.remove(j, propEnd);\n return;\n }\n ms.remove(propStart, propEnd);\n}\n\nfunction isWhitespace(ch: string): boolean {\n return (\n ch === ' ' ||\n ch === '\\t' ||\n ch === '\\n' ||\n ch === '\\r' ||\n ch === '\\f' ||\n ch === '\\v'\n );\n}\n\n/**\n * Extract inline style strings from Angular @Component decorator using OXC parser.\n * Returns an array of style string values for preprocessing.\n */\nexport function extractInlineStyles(code: string, fileName: string): string[] {\n if (!code.includes('styles')) return [];\n return extractStylesFromAst(code, fileName);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBAAmB,MAAc,UAA0B;AACzE,KAAI,CAAC,KAAK,SAAS,cAAc,IAAI,CAAC,KAAK,SAAS,WAAW,CAC7D,QAAO;CAGT,MAAM,EAAE,YAAY,UAAU,UAAU,KAAK;CAC7C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AAM,KAAK,OACX,MAAM,KAAK,KACX,YAAY,YAAY,KAAK,MAAM,KAAK,UAAU,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,GAClE;AACD,UAAK,MAAM,EAAE,UAAU,KACrB,6BAA4B,IAAI,MAAM,KAAK,OAAO,KAAK,IAAI;;AAG/D,cAAU;;;;AAKhB,QAAO,UAAU,GAAG,UAAU,GAAG;;;;;;;;AASnC,SAAS,4BACP,IACA,MACA,WACA,SACM;CACN,IAAI,IAAI;AACR,QAAO,IAAI,KAAK,UAAU,aAAa,KAAK,GAAG,CAAE;AACjD,KAAI,KAAK,OAAO,KAAK;AACnB,KAAG,OAAO,WAAW,IAAI,EAAE;AAC3B;;CAEF,IAAI,IAAI,YAAY;AACpB,QAAO,KAAK,KAAK,aAAa,KAAK,GAAG,CAAE;AACxC,KAAI,KAAK,OAAO,KAAK;AACnB,KAAG,OAAO,GAAG,QAAQ;AACrB;;AAEF,IAAG,OAAO,WAAW,QAAQ;;AAG/B,SAAS,aAAa,IAAqB;AACzC,QACE,OAAO,OACP,OAAO,OACP,OAAO,QACP,OAAO,QACP,OAAO,QACP,OAAO;;;;;;AAQX,SAAgB,oBAAoB,MAAc,UAA4B;AAC5E,KAAI,CAAC,KAAK,SAAS,SAAS,CAAE,QAAO,EAAE;AACvC,QAAO,sBAAqB,MAAM,SAAS"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract styleUrl/styleUrls values from Angular @Component decorators.
|
|
3
|
+
*/
|
|
4
|
+
export declare function extractStyleUrls(code: string, fileName: string): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Extract inline style strings from Angular @Component decorators.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractInlineStyles(code: string, fileName: string): string[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/compiler/style-ast.ts
|
|
3
|
+
function getClassDeclaration(node) {
|
|
4
|
+
return node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
5
|
+
}
|
|
6
|
+
function getPropertyKey(prop) {
|
|
7
|
+
return prop.key?.name || prop.key?.value;
|
|
8
|
+
}
|
|
9
|
+
function getTemplateLiteralText(node) {
|
|
10
|
+
if (node?.type !== "TemplateLiteral" || node.quasis?.length !== 1) return;
|
|
11
|
+
return node.quasis[0].value.cooked || node.quasis[0].value.raw;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Extract inline style strings from Angular @Component decorators.
|
|
15
|
+
*/
|
|
16
|
+
function extractInlineStyles(code, fileName) {
|
|
17
|
+
const styles = [];
|
|
18
|
+
const { program } = parseSync(fileName, code);
|
|
19
|
+
for (const node of program.body) {
|
|
20
|
+
const decl = getClassDeclaration(node);
|
|
21
|
+
if (!decl || decl.type !== "ClassDeclaration") continue;
|
|
22
|
+
for (const dec of decl.decorators || []) {
|
|
23
|
+
const expr = dec.expression;
|
|
24
|
+
if (!expr || expr.type !== "CallExpression") continue;
|
|
25
|
+
if (expr.callee?.name !== "Component") continue;
|
|
26
|
+
const arg = expr.arguments?.[0];
|
|
27
|
+
if (!arg || arg.type !== "ObjectExpression") continue;
|
|
28
|
+
for (const prop of arg.properties) {
|
|
29
|
+
if (prop.type !== "Property") continue;
|
|
30
|
+
const key = getPropertyKey(prop);
|
|
31
|
+
const val = prop.value;
|
|
32
|
+
if (key !== "styles") continue;
|
|
33
|
+
if (val?.type === "ArrayExpression") for (const el of val.elements) {
|
|
34
|
+
if (el?.type === "Literal" && typeof el.value === "string") {
|
|
35
|
+
styles.push(el.value);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const templateText = getTemplateLiteralText(el);
|
|
39
|
+
if (templateText !== void 0) styles.push(templateText);
|
|
40
|
+
}
|
|
41
|
+
else if (val?.type === "Literal" && typeof val.value === "string") styles.push(val.value);
|
|
42
|
+
else {
|
|
43
|
+
const templateText = getTemplateLiteralText(val);
|
|
44
|
+
if (templateText !== void 0) styles.push(templateText);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return styles;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { extractInlineStyles };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=style-ast.js.map
|