@analogjs/vite-plugin-angular 3.0.0-beta.3 → 3.0.0-beta.31
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/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46048 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +504 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +1 -1
- package/src/lib/angular-build-optimizer-plugin.js +6 -3
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +20 -5
- package/src/lib/angular-vite-plugin.js +30 -14
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.js +3 -0
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +158 -143
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +11 -13
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +6 -1
- package/src/lib/compiler/dts-reader.js +15 -9
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +7 -2
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +4 -4
- package/src/lib/compiler/jit-metadata.d.ts +3 -1
- package/src/lib/compiler/jit-metadata.js +10 -8
- package/src/lib/compiler/jit-metadata.js.map +1 -1
- package/src/lib/compiler/jit-transform.js +2 -2
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.d.ts +0 -3
- package/src/lib/compiler/js-emitter.js +3 -21
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/registry.d.ts +7 -1
- package/src/lib/compiler/registry.js +23 -3
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +8 -9
- package/src/lib/compiler/resource-inliner.js +10 -18
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +9 -1
- package/src/lib/compiler/style-ast.js +26 -5
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +4 -3
- package/src/lib/compiler/type-elision.js +10 -11
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.d.ts +14 -7
- package/src/lib/compiler/utils.js +38 -9
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/fast-compile-plugin.d.ts +3 -0
- package/src/lib/fast-compile-plugin.js +124 -38
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +2 -0
- package/src/lib/host.js +2 -0
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +4 -3
- package/src/lib/live-reload-plugin.js +4 -3
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/ngp-compile-plugin.d.ts +3 -0
- package/src/lib/ngp-compile-plugin.js +344 -0
- package/src/lib/ngp-compile-plugin.js.map +1 -0
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -1
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +87 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/lsp-type-checker.d.ts +55 -0
- package/src/lib/utils/lsp-type-checker.js +502 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +9 -0
- package/src/lib/utils/plugin-config.js +10 -1
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +8 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
1
|
import * as o from "@angular/compiler";
|
|
3
2
|
/** Emit Angular output AST expression directly to a JavaScript string. */
|
|
4
3
|
export declare function emitAngularExpr(expr: o.Expression): string;
|
|
5
4
|
/** Emit Angular output AST statement directly to a JavaScript string. */
|
|
6
5
|
export declare function emitAngularStmt(stmt: o.Statement): string;
|
|
7
|
-
/** Set the current source file for WrappedNodeExpr fallback printing. */
|
|
8
|
-
export declare function setEmitterSourceFile(sf: ts.SourceFile | undefined): void;
|
|
9
6
|
/** Set the current source code for OXC-based WrappedNodeExpr slice fallback. */
|
|
10
7
|
export declare function setEmitterSourceCode(code: string | undefined): void;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as o from "@angular/compiler";
|
|
2
|
-
import * as ts from "typescript";
|
|
3
2
|
//#region packages/vite-plugin-angular/src/lib/compiler/js-emitter.ts
|
|
4
|
-
/** Shared printer — only used as fallback for complex WrappedNodeExpr (e.g. decorator args). */
|
|
5
|
-
var sharedPrinter = ts.createPrinter({ removeComments: true });
|
|
6
|
-
var emptySourceFile = ts.createSourceFile("_.ts", "", ts.ScriptTarget.Latest, false);
|
|
7
3
|
var OP_DEFINITIONS = [
|
|
8
4
|
[
|
|
9
5
|
"Assign",
|
|
@@ -249,12 +245,9 @@ function escapeForLocalize(input) {
|
|
|
249
245
|
})}'`;
|
|
250
246
|
}
|
|
251
247
|
/**
|
|
252
|
-
* Emits Angular output AST directly to JavaScript strings
|
|
253
|
-
* ts.factory node creation and ts.Printer serialization (~4x faster).
|
|
248
|
+
* Emits Angular output AST directly to JavaScript strings.
|
|
254
249
|
*/
|
|
255
250
|
var JSEmitter = class JSEmitter {
|
|
256
|
-
/** Set by compile() so WrappedNodeExpr fallback can print with correct source context. */
|
|
257
|
-
static _currentSourceFile;
|
|
258
251
|
/** Set by compile() so OXC-based WrappedNodeExpr can slice original source. */
|
|
259
252
|
static _currentSourceCode;
|
|
260
253
|
emitExpr(e) {
|
|
@@ -277,14 +270,7 @@ var JSEmitter = class JSEmitter {
|
|
|
277
270
|
if (src) return src.slice(node.start, node.end);
|
|
278
271
|
return "null";
|
|
279
272
|
}
|
|
280
|
-
|
|
281
|
-
if (node.kind === ts.SyntaxKind.StringLiteral) return JSON.stringify(node.text);
|
|
282
|
-
if (node.kind === ts.SyntaxKind.NumericLiteral) return node.text;
|
|
283
|
-
if (node.kind === ts.SyntaxKind.TrueKeyword) return "true";
|
|
284
|
-
if (node.kind === ts.SyntaxKind.FalseKeyword) return "false";
|
|
285
|
-
if (node.kind === ts.SyntaxKind.NullKeyword) return "null";
|
|
286
|
-
if (node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral) return "`" + node.text + "`";
|
|
287
|
-
return sharedPrinter.printNode(ts.EmitHint.Unspecified, node, JSEmitter._currentSourceFile || emptySourceFile);
|
|
273
|
+
return "null";
|
|
288
274
|
}
|
|
289
275
|
visitExternalExpr(ast) {
|
|
290
276
|
const name = ast.value.name;
|
|
@@ -444,15 +430,11 @@ function emitAngularExpr(expr) {
|
|
|
444
430
|
function emitAngularStmt(stmt) {
|
|
445
431
|
return stmt.visitStatement(stringEmitter, null);
|
|
446
432
|
}
|
|
447
|
-
/** Set the current source file for WrappedNodeExpr fallback printing. */
|
|
448
|
-
function setEmitterSourceFile(sf) {
|
|
449
|
-
JSEmitter._currentSourceFile = sf;
|
|
450
|
-
}
|
|
451
433
|
/** Set the current source code for OXC-based WrappedNodeExpr slice fallback. */
|
|
452
434
|
function setEmitterSourceCode(code) {
|
|
453
435
|
JSEmitter._currentSourceCode = code;
|
|
454
436
|
}
|
|
455
437
|
//#endregion
|
|
456
|
-
export { emitAngularExpr, emitAngularStmt, setEmitterSourceCode
|
|
438
|
+
export { emitAngularExpr, emitAngularStmt, setEmitterSourceCode };
|
|
457
439
|
|
|
458
440
|
//# sourceMappingURL=js-emitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js-emitter.js","names":[],"sources":["../../../../src/lib/compiler/js-emitter.ts"],"sourcesContent":["import * as ts from 'typescript';\nimport * as o from '@angular/compiler';\n\n/** Shared printer — only used as fallback for complex WrappedNodeExpr (e.g. decorator args). */\nconst sharedPrinter = ts.createPrinter({ removeComments: true });\nconst emptySourceFile = ts.createSourceFile(\n '_.ts',\n '',\n ts.ScriptTarget.Latest,\n false,\n);\n\n// Operator metadata table — name, JS string, and precedence (higher = tighter\n// binding). Used to build version-aware lookup maps below.\n//\n// Why a runtime build instead of static `[o.BinaryOperator.Equals]: '=='`\n// literals: Angular's `BinaryOperator` enum gains members between major\n// versions (Assign and the 9 compound assignments were added in v21,\n// Exponentiation/In in v20, InstanceOf in v21). On older Angular versions\n// the missing members evaluate to `undefined` at module load time, and\n// every `[undefined]: '...'` entry collides on the single string key\n// `\"undefined\"` — last write wins. Pre-Phase-1, that gave the v19 install\n// `BINARY_OP_STR[\"undefined\"] === '??='`, so any expression with an\n// unknown operator emitted `??=` instead of failing loudly. Building the\n// table by iterating known names and skipping `undefined` values\n// eliminates the collision: members that don't exist on the installed\n// Angular are simply absent from the map.\n//\n// Precedence values match MDN's table, skipping levels not used by Angular\n// (bitwise XOR, shifts).\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence\nconst OP_DEFINITIONS: ReadonlyArray<\n readonly [name: string, str: string, precedence: number]\n> = [\n ['Assign', '=', 2],\n ['AdditionAssignment', '+=', 2],\n ['SubtractionAssignment', '-=', 2],\n ['MultiplicationAssignment', '*=', 2],\n ['DivisionAssignment', '/=', 2],\n ['RemainderAssignment', '%=', 2],\n ['ExponentiationAssignment', '**=', 2],\n ['AndAssignment', '&&=', 2],\n ['OrAssignment', '||=', 2],\n ['NullishCoalesceAssignment', '??=', 2],\n ['NullishCoalesce', '??', 4],\n ['Or', '||', 4],\n ['And', '&&', 5],\n ['BitwiseOr', '|', 6],\n ['BitwiseAnd', '&', 8],\n ['Equals', '==', 9],\n ['NotEquals', '!=', 9],\n ['Identical', '===', 9],\n ['NotIdentical', '!==', 9],\n ['Lower', '<', 10],\n ['LowerEquals', '<=', 10],\n ['Bigger', '>', 10],\n ['BiggerEquals', '>=', 10],\n ['In', 'in', 10],\n ['InstanceOf', 'instanceof', 10],\n ['Plus', '+', 12],\n ['Minus', '-', 12],\n ['Multiply', '*', 13],\n ['Divide', '/', 13],\n ['Modulo', '%', 13],\n ['Exponentiation', '**', 14],\n];\n\n/** Operator integer values that represent assignment forms (`=`, `+=`, etc.). */\nconst ASSIGNMENT_OP_NAMES: ReadonlySet<string> = new Set([\n 'Assign',\n 'AdditionAssignment',\n 'SubtractionAssignment',\n 'MultiplicationAssignment',\n 'DivisionAssignment',\n 'RemainderAssignment',\n 'ExponentiationAssignment',\n 'AndAssignment',\n 'OrAssignment',\n 'NullishCoalesceAssignment',\n]);\n\nconst BINARY_OP_STR = new Map<number, string>();\nconst BINARY_PRECEDENCE = new Map<number, number>();\nconst ASSIGNMENT_OP_VALUES = new Set<number>();\n\nfor (const [name, str, precedence] of OP_DEFINITIONS) {\n const value = (o.BinaryOperator as Record<string, unknown>)[name];\n if (typeof value !== 'number') continue;\n BINARY_OP_STR.set(value, str);\n BINARY_PRECEDENCE.set(value, precedence);\n if (ASSIGNMENT_OP_NAMES.has(name)) {\n ASSIGNMENT_OP_VALUES.add(value);\n }\n}\n\nconst UNARY_OP_STR = new Map<number, string>();\n\nfor (const [name, str] of [\n ['Plus', '+'],\n ['Minus', '-'],\n ['Increment', '++'],\n ['Decrement', '--'],\n] as const) {\n const value = (o.UnaryOperator as Record<string, unknown>)[name];\n if (typeof value !== 'number') continue;\n UNARY_OP_STR.set(value, str);\n}\n\n/** Returns true when `op` represents any kind of assignment (`=`, `+=`, etc.). */\nfunction isAssignmentOperator(op: o.BinaryOperator): boolean {\n return ASSIGNMENT_OP_VALUES.has(op);\n}\n\n/**\n * Determine whether a child expression needs parentheses when it appears\n * as an operand of `parentOp`.\n */\nfunction childNeedsParens(\n parentOp: o.BinaryOperator,\n child: o.Expression,\n isRhs: boolean,\n): boolean {\n if (!(child instanceof o.BinaryOperatorExpr)) return false;\n\n const childOp = child.operator;\n const parentPrec = BINARY_PRECEDENCE.get(parentOp);\n const childPrec = BINARY_PRECEDENCE.get(childOp);\n if (parentPrec === undefined || childPrec === undefined) return false;\n\n // ?? cannot appear with || or && without explicit grouping (JS spec)\n if (\n (parentOp === o.BinaryOperator.NullishCoalesce &&\n (childOp === o.BinaryOperator.And || childOp === o.BinaryOperator.Or)) ||\n (childOp === o.BinaryOperator.NullishCoalesce &&\n (parentOp === o.BinaryOperator.And || parentOp === o.BinaryOperator.Or))\n ) {\n return true;\n }\n\n // Child has strictly lower precedence\n if (childPrec < parentPrec) return true;\n\n // Same precedence — depends on associativity and position\n if (childPrec === parentPrec) {\n // ** is right-associative: LHS same-prec needs parens, RHS does not\n if (parentOp === o.BinaryOperator.Exponentiation) return !isRhs;\n // All other ops are left-associative: RHS same-prec needs parens\n return isRhs;\n }\n\n return false;\n}\n\n/**\n * Wrap a receiver expression in parens when emitting `<receiver>.name` or\n * `<receiver>.name(args)`. Two cases produce a JS parse error otherwise:\n *\n * 1. A `BinaryOperatorExpr` receiver: `a / 3600.toFixed(2)` parses as\n * `a / 3600.toFixed(2)` where `3600.toFixed` is read as the start of a\n * decimal literal followed by an identifier — an \"Invalid characters\n * after number\" error. Wrapping gives `(a / 3600).toFixed(2)`.\n * 2. A non-negative integer `LiteralExpr` receiver: `42.toFixed(2)` is\n * invalid for the same decimal-literal-ambiguity reason. Wrapping gives\n * `(42).toFixed(2)`. Negative numbers are already emitted as `(-42)` by\n * `visitLiteralExpr`. Floats (e.g. `4.5.toFixed`) and strings parse fine.\n *\n * Other expression kinds either already self-wrap (`ConditionalExpr`,\n * `UnaryOperatorExpr`) or are primary forms that don't need parens\n * (`ReadVarExpr`, `ReadPropExpr`, `InvokeFunctionExpr`, etc.).\n */\nfunction emitReceiverForMemberAccess(\n receiver: o.Expression,\n emitted: string,\n): string {\n if (receiver instanceof o.BinaryOperatorExpr) return '(' + emitted + ')';\n if (\n receiver instanceof o.LiteralExpr &&\n typeof receiver.value === 'number' &&\n receiver.value >= 0\n ) {\n return '(' + emitted + ')';\n }\n return emitted;\n}\n\n/** Polyfill for `__makeTemplateObject` used in downleveled `$localize` calls. */\nconst MAKE_TEMPLATE_OBJECT_POLYFILL =\n '(this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,\"raw\",{value:t}):e.raw=t,e})';\n\nconst SINGLE_QUOTE_ESCAPE_RE = /[\\\\'\\n\\r]/g;\n\n/** Escape a string for use as a single-quoted string literal. */\nfunction escapeForLocalize(input: string): string {\n const body = input.replace(SINGLE_QUOTE_ESCAPE_RE, (match) => {\n if (match === '\\n') return '\\\\n';\n if (match === '\\r') return '\\\\r';\n return `\\\\${match}`;\n });\n return `'${body}'`;\n}\n\n/**\n * Emits Angular output AST directly to JavaScript strings, bypassing\n * ts.factory node creation and ts.Printer serialization (~4x faster).\n */\nclass JSEmitter implements o.ExpressionVisitor, o.StatementVisitor {\n /** Set by compile() so WrappedNodeExpr fallback can print with correct source context. */\n static _currentSourceFile: ts.SourceFile | undefined;\n /** Set by compile() so OXC-based WrappedNodeExpr can slice original source. */\n static _currentSourceCode: string | undefined;\n\n private emitExpr(e: any): string {\n if (!e) return 'null';\n if (typeof e.visitExpression === 'function')\n return e.visitExpression(this, null);\n // Angular v21 LiteralMapPropertyAssignment: {key, value, quoted}\n if ('key' in e && 'value' in e) {\n const key = e.quoted ? JSON.stringify(e.key) : e.key;\n return key + ': ' + this.emitExpr(e.value);\n }\n return 'null';\n }\n visitWrappedNodeExpr(ast: o.WrappedNodeExpr<any>) {\n const node = ast.node;\n\n // Raw source text: already resolved to a string at wrap time\n if (typeof node === 'string') return node;\n\n // OXC AST nodes: identified by string `type` property + numeric start/end\n if (typeof node.type === 'string' && typeof node.start === 'number') {\n const src = JSEmitter._currentSourceCode;\n if (node.type === 'Identifier') return node.name;\n if (node.type === 'StringLiteral') return JSON.stringify(node.value);\n if (node.type === 'NumericLiteral') return String(node.value);\n if (node.type === 'BooleanLiteral') return node.value ? 'true' : 'false';\n if (node.type === 'NullLiteral') return 'null';\n if (node.type === 'TemplateLiteral' && !node.expressions?.length)\n return '`' + node.quasis[0].value.raw + '`';\n // Fallback: slice original source for complex OXC nodes\n if (src) return src.slice(node.start, node.end);\n return 'null';\n }\n\n // TypeScript AST nodes: identified by numeric `kind` property\n if (node.kind === ts.SyntaxKind.Identifier)\n return (node as ts.Identifier).escapedText as string;\n if (node.kind === ts.SyntaxKind.StringLiteral)\n return JSON.stringify((node as ts.StringLiteral).text);\n if (node.kind === ts.SyntaxKind.NumericLiteral)\n return (node as ts.NumericLiteral).text;\n if (node.kind === ts.SyntaxKind.TrueKeyword) return 'true';\n if (node.kind === ts.SyntaxKind.FalseKeyword) return 'false';\n if (node.kind === ts.SyntaxKind.NullKeyword) return 'null';\n if (node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral)\n return '`' + (node as ts.NoSubstitutionTemplateLiteral).text + '`';\n // Fallback for complex wrapped TS nodes (e.g. decorator arguments, array literals).\n // Use currentSourceFile when available for correct position-based printing.\n return sharedPrinter.printNode(\n ts.EmitHint.Unspecified,\n node,\n JSEmitter._currentSourceFile || emptySourceFile,\n );\n }\n visitExternalExpr(ast: o.ExternalExpr) {\n const name = ast.value.name;\n if (name === 'ngDevMode') return name;\n // When name is null/undefined, this is a bare module reference (e.g. ngImport: i0)\n if (!name) return 'i0';\n return 'i0.' + name;\n }\n visitLiteralExpr(ast: o.LiteralExpr) {\n const v = ast.value;\n if (typeof v === 'string') return JSON.stringify(v);\n if (typeof v === 'number') return v < 0 ? '(-' + -v + ')' : '' + v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (v === undefined) return 'void 0';\n return 'null';\n }\n visitLiteralArrayExpr(ast: o.LiteralArrayExpr) {\n return '[' + ast.entries.map((e) => this.emitExpr(e)).join(', ') + ']';\n }\n visitLiteralMapExpr(ast: o.LiteralMapExpr) {\n return '{' + ast.entries.map((e) => this.emitExpr(e)).join(', ') + '}';\n }\n visitInvokeFunctionExpr(ast: o.InvokeFunctionExpr) {\n const fn = ast.fn.visitExpression(this, null);\n const args = ast.args.map((a: any) => this.emitExpr(a)).join(', ');\n // Wrap arrow/function expressions in parens for valid IIFE syntax. A\n // `WrappedNodeExpr` callee is a raw user expression (e.g. an\n // `@Injectable({ useFactory: (a, b) => … })` arrow); without parens the\n // argument list binds to the arrow's *body* (`… => new X(a, b)(args)`)\n // instead of invoking the arrow. Parenthesizing any wrapped callee is\n // always semantically safe.\n const call = ast.isOptional ? '?.(' : '(';\n\n if (\n ast.fn instanceof o.ArrowFunctionExpr ||\n ast.fn instanceof o.FunctionExpr ||\n ast.fn instanceof o.WrappedNodeExpr\n ) {\n return '(' + fn + ')' + call + args + ')';\n }\n return fn + call + args + ')';\n }\n visitReadVarExpr(ast: o.ReadVarExpr) {\n if (ast.name === 'this') return 'this';\n if (ast.name === 'super') return 'super';\n return ast.name!;\n }\n visitReadPropExpr(ast: o.ReadPropExpr) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n (ast.isOptional ? '?.' : '.') +\n ast.name\n );\n }\n visitReadKeyExpr(ast: o.ReadKeyExpr) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n (ast.isOptional ? '?.[' : '[') +\n ast.index.visitExpression(this, null) +\n ']'\n );\n }\n visitConditionalExpr(ast: o.ConditionalExpr) {\n return (\n '(' +\n ast.condition.visitExpression(this, null) +\n ' ? ' +\n ast.trueCase.visitExpression(this, null) +\n ' : ' +\n ast.falseCase!.visitExpression(this, null) +\n ')'\n );\n }\n visitBinaryOperatorExpr(ast: o.BinaryOperatorExpr) {\n // `BINARY_OP_STR.get(...)` returns `undefined` when the operator value\n // doesn't exist in the installed Angular's `BinaryOperator` enum (the\n // enum is missing 13 members on v19, 11 on v20). Falling back to `'='`\n // would silently produce wrong code; instead, we throw so the error\n // surfaces in the DEBUG output and the calling test fails loudly.\n const op = BINARY_OP_STR.get(ast.operator);\n if (op === undefined) {\n throw new Error(\n `[fast-compile] Unsupported BinaryOperator value ${ast.operator} ` +\n `on @angular/compiler ${o.VERSION?.full ?? '(unknown version)'}`,\n );\n }\n\n const lhsRaw = ast.lhs.visitExpression(this, null);\n const rhsRaw = ast.rhs.visitExpression(this, null);\n\n const lhs = childNeedsParens(ast.operator, ast.lhs, false)\n ? '(' + lhsRaw + ')'\n : lhsRaw;\n const rhs = childNeedsParens(ast.operator, ast.rhs, true)\n ? '(' + rhsRaw + ')'\n : rhsRaw;\n\n const expr = lhs + ' ' + op + ' ' + rhs;\n\n // Wrap assignments in parens so they work correctly as ternary conditions:\n // (tmp = val) ? a : b vs tmp = val ? a : b\n //\n // `isAssignmentOperator` is built at module load time from the operator\n // names that actually exist on the installed Angular's enum. This\n // works whether `Assign` is present (v21+) or absent (v19/v20) — on\n // older versions the assignment branch is simply unreachable because\n // Angular's compiler never constructs an Assign-operator expression.\n if (isAssignmentOperator(ast.operator)) {\n return '(' + expr + ')';\n }\n return expr;\n }\n visitNotExpr(ast: o.NotExpr) {\n return '!(' + ast.condition.visitExpression(this, null) + ')';\n }\n visitFunctionExpr(ast: o.FunctionExpr) {\n return (\n '(' +\n ast.params.map((p: any) => p.name).join(', ') +\n ') => {' +\n ast.statements.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n }\n visitArrowFunctionExpr(ast: o.ArrowFunctionExpr) {\n const params = '(' + ast.params.map((p: any) => p.name).join(', ') + ')';\n if (Array.isArray(ast.body))\n return (\n params +\n ' => {' +\n ast.body.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n const bodyExpr = (ast.body as o.Expression).visitExpression(this, null);\n // Wrap object literals in parens so `() => {key: val}` isn't parsed\n // as a block with a labeled statement.\n if (ast.body instanceof o.LiteralMapExpr) {\n return params + ' => (' + bodyExpr + ')';\n }\n return params + ' => ' + bodyExpr;\n }\n // `Write*Expr` visitors must wrap the assignment in parentheses so that\n // it composes correctly when nested inside higher-precedence parents\n // (e.g. as the test of a `ConditionalExpr`). Without the wrapping,\n // tmp = ctx.data() ? 0 : -1\n // parses as `tmp = (ctx.data() ? 0 : -1)` because assignment binds\n // looser than the ternary, which silently assigns the wrong value to\n // `tmp`. Angular's own `AbstractEmitterVisitor.visitWriteVarExpr`\n // applies the same context-sensitive wrapping (it skips the parens\n // when the assignment is a top-level statement to avoid `(x = 1);`\n // noise; we always wrap for simplicity — the redundant parens at\n // statement level are harmless).\n //\n // This matters specifically on Angular v19/v20, where assignment is\n // represented in the IR via `WriteVarExpr` / `AssignTemporaryExpr →\n // WriteVarExpr`. On v21+ the same construct is represented via\n // `BinaryOperatorExpr(Assign, ...)`, which `visitBinaryOperatorExpr`\n // already wraps via `isAssignmentOperator`. Without these wrappers,\n // `@if (data(); as item)` and similar conditional alias forms emit\n // runtime-broken code on v19/v20.\n visitWriteVarExpr(ast: any) {\n return '(' + ast.name + ' = ' + ast.value.visitExpression(this, null) + ')';\n }\n visitWritePropExpr(ast: any) {\n return (\n '(' +\n ast.receiver.visitExpression(this, null) +\n '.' +\n ast.name +\n ' = ' +\n ast.value.visitExpression(this, null) +\n ')'\n );\n }\n visitWriteKeyExpr(ast: any) {\n return (\n '(' +\n ast.receiver.visitExpression(this, null) +\n '[' +\n ast.index.visitExpression(this, null) +\n '] = ' +\n ast.value.visitExpression(this, null) +\n ')'\n );\n }\n visitInvokeMethodExpr(ast: any) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n '.' +\n ast.name +\n '(' +\n ast.args.map((a: any) => this.emitExpr(a)).join(', ') +\n ')'\n );\n }\n visitTypeofExpr(ast: o.TypeofExpr) {\n return 'typeof ' + ast.expr.visitExpression(this, null);\n }\n visitUnaryOperatorExpr(ast: o.UnaryOperatorExpr) {\n const op = UNARY_OP_STR.get(ast.operator);\n if (op === undefined) {\n throw new Error(\n `[fast-compile] Unsupported UnaryOperator value ${ast.operator} ` +\n `on @angular/compiler ${o.VERSION?.full ?? '(unknown version)'}`,\n );\n }\n\n const operand = '(' + ast.expr.visitExpression(this, null) + ')';\n const isPostfix = 'isPrefix' in ast && ast.isPrefix === false;\n return '(' + (isPostfix ? operand + op : op + operand) + ')';\n }\n visitInstantiateExpr(ast: o.InstantiateExpr) {\n return (\n 'new (' +\n ast.classExpr.visitExpression(this, null) +\n ')(' +\n ast.args.map((a: any) => this.emitExpr(a)).join(', ') +\n ')'\n );\n }\n visitCommaExpr(ast: o.CommaExpr) {\n return ast.parts.map((p: any) => p.visitExpression(this, null)).join(', ');\n }\n visitParenthesizedExpr(ast: o.ParenthesizedExpr) {\n return '(' + ast.expr.visitExpression(this, null) + ')';\n }\n visitVoidExpr(ast: o.VoidExpr) {\n return 'void ' + ast.expr.visitExpression(this, null);\n }\n visitSpreadElementExpr(ast: o.SpreadElementExpr) {\n return '...' + (ast as any).expression.visitExpression(this, null);\n }\n visitDynamicImportExpr(ast: o.DynamicImportExpr) {\n return (\n 'import(' +\n (typeof ast.url === 'string'\n ? JSON.stringify(ast.url)\n : ast.url.visitExpression(this, null)) +\n ')'\n );\n }\n visitTemplateLiteralExpr(ast: o.TemplateLiteralExpr) {\n return (\n '`' +\n ast.elements[0].text +\n ast.expressions\n .map(\n (e: any, i: number) =>\n '${' +\n e.visitExpression(this, null) +\n '}' +\n ast.elements[i + 1].text,\n )\n .join('') +\n '`'\n );\n }\n visitTaggedTemplateLiteralExpr(ast: any) {\n const elements = ast.template.elements;\n const expressions = ast.template.expressions;\n const head = elements[0].text;\n const spans = expressions\n .map(\n (e: any, i: number) =>\n '${' + e.visitExpression(this, null) + '}' + elements[i + 1].text,\n )\n .join('');\n return ast.tag.visitExpression(this, null) + '`' + head + spans + '`';\n }\n visitLocalizedString(ast: o.LocalizedString) {\n // Emit the downleveled form:\n // $localize(makeTemplateObject(cooked, raw), expr1, expr2, ...)\n const parts: { cooked: string; raw: string }[] = [ast.serializeI18nHead()];\n for (let i = 1; i < ast.messageParts.length; i++) {\n parts.push(ast.serializeI18nTemplatePart(i));\n }\n const cooked = parts.map((p) => escapeForLocalize(p.cooked)).join(', ');\n const raw = parts.map((p) => escapeForLocalize(p.raw)).join(', ');\n const exprs = ast.expressions.map((e) => this.emitExpr(e));\n return (\n '$localize(' +\n MAKE_TEMPLATE_OBJECT_POLYFILL +\n '([' +\n cooked +\n '], [' +\n raw +\n '])' +\n (exprs.length > 0 ? ', ' + exprs.join(', ') : '') +\n ')'\n );\n }\n visitRegularExpressionLiteral(ast: any) {\n return '/' + (ast.body ?? ast.pattern) + '/' + ast.flags;\n }\n visitTemplateLiteralElementExpr(ast: o.TemplateLiteralElementExpr) {\n return JSON.stringify(ast.text);\n }\n // Statement visitors\n visitReturnStmt(stmt: o.ReturnStatement) {\n return 'return ' + stmt.value.visitExpression(this, null) + ';';\n }\n visitExpressionStmt(stmt: o.ExpressionStatement) {\n return stmt.expr.visitExpression(this, null) + ';';\n }\n visitIfStmt(stmt: o.IfStmt) {\n let s =\n 'if (' +\n stmt.condition.visitExpression(this, null) +\n ') {' +\n stmt.trueCase.map((s2: any) => s2.visitStatement(this, null)).join(' ') +\n '}';\n if (stmt.falseCase.length)\n s +=\n ' else {' +\n stmt.falseCase\n .map((s2: any) => s2.visitStatement(this, null))\n .join(' ') +\n '}';\n return s;\n }\n visitDeclareVarStmt(stmt: o.DeclareVarStmt) {\n const kw = stmt.hasModifier(o.StmtModifier.Final) ? 'const' : 'let';\n return (\n kw +\n ' ' +\n stmt.name +\n (stmt.value ? ' = ' + stmt.value.visitExpression(this, null) : '') +\n ';'\n );\n }\n visitDeclareFunctionStmt(stmt: o.DeclareFunctionStmt) {\n return (\n 'function ' +\n stmt.name +\n '(' +\n stmt.params.map((p: any) => p.name).join(', ') +\n ') {' +\n stmt.statements.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n }\n}\n\nconst stringEmitter = new JSEmitter();\n\n/** Emit Angular output AST expression directly to a JavaScript string. */\nexport function emitAngularExpr(expr: o.Expression): string {\n return expr.visitExpression(stringEmitter, null);\n}\n\n/** Emit Angular output AST statement directly to a JavaScript string. */\nexport function emitAngularStmt(stmt: o.Statement): string {\n return stmt.visitStatement(stringEmitter, null);\n}\n\n/** Set the current source file for WrappedNodeExpr fallback printing. */\nexport function setEmitterSourceFile(sf: ts.SourceFile | undefined): void {\n JSEmitter._currentSourceFile = sf;\n}\n\n/** Set the current source code for OXC-based WrappedNodeExpr slice fallback. */\nexport function setEmitterSourceCode(code: string | undefined): void {\n JSEmitter._currentSourceCode = code;\n}\n"],"mappings":";;;;AAIA,IAAM,gBAAgB,GAAG,cAAc,EAAE,gBAAgB,KAAK,CAAC;AAC/D,IAAM,kBAAkB,GAAG,iBACzB,QACA,IACA,GAAG,aAAa,QAChB,KACF;AAqBA,IAAM,iBAEF;CACF;EAAC;EAAU;EAAK;CAAC;CACjB;EAAC;EAAsB;EAAM;CAAC;CAC9B;EAAC;EAAyB;EAAM;CAAC;CACjC;EAAC;EAA4B;EAAM;CAAC;CACpC;EAAC;EAAsB;EAAM;CAAC;CAC9B;EAAC;EAAuB;EAAM;CAAC;CAC/B;EAAC;EAA4B;EAAO;CAAC;CACrC;EAAC;EAAiB;EAAO;CAAC;CAC1B;EAAC;EAAgB;EAAO;CAAC;CACzB;EAAC;EAA6B;EAAO;CAAC;CACtC;EAAC;EAAmB;EAAM;CAAC;CAC3B;EAAC;EAAM;EAAM;CAAC;CACd;EAAC;EAAO;EAAM;CAAC;CACf;EAAC;EAAa;EAAK;CAAC;CACpB;EAAC;EAAc;EAAK;CAAC;CACrB;EAAC;EAAU;EAAM;CAAC;CAClB;EAAC;EAAa;EAAM;CAAC;CACrB;EAAC;EAAa;EAAO;CAAC;CACtB;EAAC;EAAgB;EAAO;CAAC;CACzB;EAAC;EAAS;EAA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AK,QAAQ,QAAQ,KAAK,MAAM,gBAAgB,MAAM,IAAI,IAAI,MAC/D;CAEJ;CACA,yBAAyB,MAA6B;EACpD,OACE,cACA,KAAK,OACL,MACA,KAAK,OAAO,KAAK,MAAW,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI,IAC7C,QACA,KAAK,WAAW,KAAK,MAAW,EAAE,eAAe,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IACtE;CAEJ;AACF;AAEA,IAAM,gBAAgB,IAAI,UAAU;;AAGpC,SAAgB,gBAAgB,MAA4B;CAC1D,OAAO,KAAK,gBAAgB,eAAe,IAAI;AACjD;;AAGA,SAAgB,gBAAgB,MAA2B;CACzD,OAAO,KAAK,eAAe,eAAe,IAAI;AAChD;;AAGA,SAAgB,qBAAqB,IAAqC;CACxE,UAAU,qBAAqB;AACjC;;AAGA,SAAgB,qBAAqB,MAAgC;CACnE,UAAU,qBAAqB;AACjC"}
|
|
1
|
+
{"version":3,"file":"js-emitter.js","names":[],"sources":["../../../../src/lib/compiler/js-emitter.ts"],"sourcesContent":["import * as o from '@angular/compiler';\n\n// Operator metadata table — name, JS string, and precedence (higher = tighter\n// binding). Used to build version-aware lookup maps below.\n//\n// Why a runtime build instead of static `[o.BinaryOperator.Equals]: '=='`\n// literals: Angular's `BinaryOperator` enum gains members between major\n// versions (Assign and the 9 compound assignments were added in v21,\n// Exponentiation/In in v20, InstanceOf in v21). On older Angular versions\n// the missing members evaluate to `undefined` at module load time, and\n// every `[undefined]: '...'` entry collides on the single string key\n// `\"undefined\"` — last write wins. Pre-Phase-1, that gave the v19 install\n// `BINARY_OP_STR[\"undefined\"] === '??='`, so any expression with an\n// unknown operator emitted `??=` instead of failing loudly. Building the\n// table by iterating known names and skipping `undefined` values\n// eliminates the collision: members that don't exist on the installed\n// Angular are simply absent from the map.\n//\n// Precedence values match MDN's table, skipping levels not used by Angular\n// (bitwise XOR, shifts).\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence\nconst OP_DEFINITIONS: ReadonlyArray<\n readonly [name: string, str: string, precedence: number]\n> = [\n ['Assign', '=', 2],\n ['AdditionAssignment', '+=', 2],\n ['SubtractionAssignment', '-=', 2],\n ['MultiplicationAssignment', '*=', 2],\n ['DivisionAssignment', '/=', 2],\n ['RemainderAssignment', '%=', 2],\n ['ExponentiationAssignment', '**=', 2],\n ['AndAssignment', '&&=', 2],\n ['OrAssignment', '||=', 2],\n ['NullishCoalesceAssignment', '??=', 2],\n ['NullishCoalesce', '??', 4],\n ['Or', '||', 4],\n ['And', '&&', 5],\n ['BitwiseOr', '|', 6],\n ['BitwiseAnd', '&', 8],\n ['Equals', '==', 9],\n ['NotEquals', '!=', 9],\n ['Identical', '===', 9],\n ['NotIdentical', '!==', 9],\n ['Lower', '<', 10],\n ['LowerEquals', '<=', 10],\n ['Bigger', '>', 10],\n ['BiggerEquals', '>=', 10],\n ['In', 'in', 10],\n ['InstanceOf', 'instanceof', 10],\n ['Plus', '+', 12],\n ['Minus', '-', 12],\n ['Multiply', '*', 13],\n ['Divide', '/', 13],\n ['Modulo', '%', 13],\n ['Exponentiation', '**', 14],\n];\n\n/** Operator integer values that represent assignment forms (`=`, `+=`, etc.). */\nconst ASSIGNMENT_OP_NAMES: ReadonlySet<string> = new Set([\n 'Assign',\n 'AdditionAssignment',\n 'SubtractionAssignment',\n 'MultiplicationAssignment',\n 'DivisionAssignment',\n 'RemainderAssignment',\n 'ExponentiationAssignment',\n 'AndAssignment',\n 'OrAssignment',\n 'NullishCoalesceAssignment',\n]);\n\nconst BINARY_OP_STR = new Map<number, string>();\nconst BINARY_PRECEDENCE = new Map<number, number>();\nconst ASSIGNMENT_OP_VALUES = new Set<number>();\n\nfor (const [name, str, precedence] of OP_DEFINITIONS) {\n const value = (o.BinaryOperator as Record<string, unknown>)[name];\n if (typeof value !== 'number') continue;\n BINARY_OP_STR.set(value, str);\n BINARY_PRECEDENCE.set(value, precedence);\n if (ASSIGNMENT_OP_NAMES.has(name)) {\n ASSIGNMENT_OP_VALUES.add(value);\n }\n}\n\nconst UNARY_OP_STR = new Map<number, string>();\n\nfor (const [name, str] of [\n ['Plus', '+'],\n ['Minus', '-'],\n ['Increment', '++'],\n ['Decrement', '--'],\n] as const) {\n const value = (o.UnaryOperator as Record<string, unknown>)[name];\n if (typeof value !== 'number') continue;\n UNARY_OP_STR.set(value, str);\n}\n\n/** Returns true when `op` represents any kind of assignment (`=`, `+=`, etc.). */\nfunction isAssignmentOperator(op: o.BinaryOperator): boolean {\n return ASSIGNMENT_OP_VALUES.has(op);\n}\n\n/**\n * Determine whether a child expression needs parentheses when it appears\n * as an operand of `parentOp`.\n */\nfunction childNeedsParens(\n parentOp: o.BinaryOperator,\n child: o.Expression,\n isRhs: boolean,\n): boolean {\n if (!(child instanceof o.BinaryOperatorExpr)) return false;\n\n const childOp = child.operator;\n const parentPrec = BINARY_PRECEDENCE.get(parentOp);\n const childPrec = BINARY_PRECEDENCE.get(childOp);\n if (parentPrec === undefined || childPrec === undefined) return false;\n\n // ?? cannot appear with || or && without explicit grouping (JS spec)\n if (\n (parentOp === o.BinaryOperator.NullishCoalesce &&\n (childOp === o.BinaryOperator.And || childOp === o.BinaryOperator.Or)) ||\n (childOp === o.BinaryOperator.NullishCoalesce &&\n (parentOp === o.BinaryOperator.And || parentOp === o.BinaryOperator.Or))\n ) {\n return true;\n }\n\n // Child has strictly lower precedence\n if (childPrec < parentPrec) return true;\n\n // Same precedence — depends on associativity and position\n if (childPrec === parentPrec) {\n // ** is right-associative: LHS same-prec needs parens, RHS does not\n if (parentOp === o.BinaryOperator.Exponentiation) return !isRhs;\n // All other ops are left-associative: RHS same-prec needs parens\n return isRhs;\n }\n\n return false;\n}\n\n/**\n * Wrap a receiver expression in parens when emitting `<receiver>.name` or\n * `<receiver>.name(args)`. Two cases produce a JS parse error otherwise:\n *\n * 1. A `BinaryOperatorExpr` receiver: `a / 3600.toFixed(2)` parses as\n * `a / 3600.toFixed(2)` where `3600.toFixed` is read as the start of a\n * decimal literal followed by an identifier — an \"Invalid characters\n * after number\" error. Wrapping gives `(a / 3600).toFixed(2)`.\n * 2. A non-negative integer `LiteralExpr` receiver: `42.toFixed(2)` is\n * invalid for the same decimal-literal-ambiguity reason. Wrapping gives\n * `(42).toFixed(2)`. Negative numbers are already emitted as `(-42)` by\n * `visitLiteralExpr`. Floats (e.g. `4.5.toFixed`) and strings parse fine.\n *\n * Other expression kinds either already self-wrap (`ConditionalExpr`,\n * `UnaryOperatorExpr`) or are primary forms that don't need parens\n * (`ReadVarExpr`, `ReadPropExpr`, `InvokeFunctionExpr`, etc.).\n */\nfunction emitReceiverForMemberAccess(\n receiver: o.Expression,\n emitted: string,\n): string {\n if (receiver instanceof o.BinaryOperatorExpr) return '(' + emitted + ')';\n if (\n receiver instanceof o.LiteralExpr &&\n typeof receiver.value === 'number' &&\n receiver.value >= 0\n ) {\n return '(' + emitted + ')';\n }\n return emitted;\n}\n\n/** Polyfill for `__makeTemplateObject` used in downleveled `$localize` calls. */\nconst MAKE_TEMPLATE_OBJECT_POLYFILL =\n '(this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,\"raw\",{value:t}):e.raw=t,e})';\n\nconst SINGLE_QUOTE_ESCAPE_RE = /[\\\\'\\n\\r]/g;\n\n/** Escape a string for use as a single-quoted string literal. */\nfunction escapeForLocalize(input: string): string {\n const body = input.replace(SINGLE_QUOTE_ESCAPE_RE, (match) => {\n if (match === '\\n') return '\\\\n';\n if (match === '\\r') return '\\\\r';\n return `\\\\${match}`;\n });\n return `'${body}'`;\n}\n\n/**\n * Emits Angular output AST directly to JavaScript strings.\n */\nclass JSEmitter implements o.ExpressionVisitor, o.StatementVisitor {\n /** Set by compile() so OXC-based WrappedNodeExpr can slice original source. */\n static _currentSourceCode: string | undefined;\n\n private emitExpr(e: any): string {\n if (!e) return 'null';\n if (typeof e.visitExpression === 'function')\n return e.visitExpression(this, null);\n // Angular v21 LiteralMapPropertyAssignment: {key, value, quoted}\n if ('key' in e && 'value' in e) {\n const key = e.quoted ? JSON.stringify(e.key) : e.key;\n return key + ': ' + this.emitExpr(e.value);\n }\n return 'null';\n }\n visitWrappedNodeExpr(ast: o.WrappedNodeExpr<any>) {\n const node = ast.node;\n\n // Raw source text: already resolved to a string at wrap time\n if (typeof node === 'string') return node;\n\n // OXC AST nodes: identified by string `type` property + numeric start/end\n if (typeof node.type === 'string' && typeof node.start === 'number') {\n const src = JSEmitter._currentSourceCode;\n if (node.type === 'Identifier') return node.name;\n if (node.type === 'StringLiteral') return JSON.stringify(node.value);\n if (node.type === 'NumericLiteral') return String(node.value);\n if (node.type === 'BooleanLiteral') return node.value ? 'true' : 'false';\n if (node.type === 'NullLiteral') return 'null';\n if (node.type === 'TemplateLiteral' && !node.expressions?.length)\n return '`' + node.quasis[0].value.raw + '`';\n // Fallback: slice original source for complex OXC nodes\n if (src) return src.slice(node.start, node.end);\n return 'null';\n }\n\n return 'null';\n }\n visitExternalExpr(ast: o.ExternalExpr) {\n const name = ast.value.name;\n if (name === 'ngDevMode') return name;\n // When name is null/undefined, this is a bare module reference (e.g. ngImport: i0)\n if (!name) return 'i0';\n return 'i0.' + name;\n }\n visitLiteralExpr(ast: o.LiteralExpr) {\n const v = ast.value;\n if (typeof v === 'string') return JSON.stringify(v);\n if (typeof v === 'number') return v < 0 ? '(-' + -v + ')' : '' + v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (v === undefined) return 'void 0';\n return 'null';\n }\n visitLiteralArrayExpr(ast: o.LiteralArrayExpr) {\n return '[' + ast.entries.map((e) => this.emitExpr(e)).join(', ') + ']';\n }\n visitLiteralMapExpr(ast: o.LiteralMapExpr) {\n return '{' + ast.entries.map((e) => this.emitExpr(e)).join(', ') + '}';\n }\n visitInvokeFunctionExpr(ast: o.InvokeFunctionExpr) {\n const fn = ast.fn.visitExpression(this, null);\n const args = ast.args.map((a: any) => this.emitExpr(a)).join(', ');\n // Wrap arrow/function expressions in parens for valid IIFE syntax. A\n // `WrappedNodeExpr` callee is a raw user expression (e.g. an\n // `@Injectable({ useFactory: (a, b) => … })` arrow); without parens the\n // argument list binds to the arrow's *body* (`… => new X(a, b)(args)`)\n // instead of invoking the arrow. Parenthesizing any wrapped callee is\n // always semantically safe.\n const call = ast.isOptional ? '?.(' : '(';\n\n if (\n ast.fn instanceof o.ArrowFunctionExpr ||\n ast.fn instanceof o.FunctionExpr ||\n ast.fn instanceof o.WrappedNodeExpr\n ) {\n return '(' + fn + ')' + call + args + ')';\n }\n return fn + call + args + ')';\n }\n visitReadVarExpr(ast: o.ReadVarExpr) {\n if (ast.name === 'this') return 'this';\n if (ast.name === 'super') return 'super';\n return ast.name!;\n }\n visitReadPropExpr(ast: o.ReadPropExpr) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n (ast.isOptional ? '?.' : '.') +\n ast.name\n );\n }\n visitReadKeyExpr(ast: o.ReadKeyExpr) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n (ast.isOptional ? '?.[' : '[') +\n ast.index.visitExpression(this, null) +\n ']'\n );\n }\n visitConditionalExpr(ast: o.ConditionalExpr) {\n return (\n '(' +\n ast.condition.visitExpression(this, null) +\n ' ? ' +\n ast.trueCase.visitExpression(this, null) +\n ' : ' +\n ast.falseCase!.visitExpression(this, null) +\n ')'\n );\n }\n visitBinaryOperatorExpr(ast: o.BinaryOperatorExpr) {\n // `BINARY_OP_STR.get(...)` returns `undefined` when the operator value\n // doesn't exist in the installed Angular's `BinaryOperator` enum (the\n // enum is missing 13 members on v19, 11 on v20). Falling back to `'='`\n // would silently produce wrong code; instead, we throw so the error\n // surfaces in the DEBUG output and the calling test fails loudly.\n const op = BINARY_OP_STR.get(ast.operator);\n if (op === undefined) {\n throw new Error(\n `[fast-compile] Unsupported BinaryOperator value ${ast.operator} ` +\n `on @angular/compiler ${o.VERSION?.full ?? '(unknown version)'}`,\n );\n }\n\n const lhsRaw = ast.lhs.visitExpression(this, null);\n const rhsRaw = ast.rhs.visitExpression(this, null);\n\n const lhs = childNeedsParens(ast.operator, ast.lhs, false)\n ? '(' + lhsRaw + ')'\n : lhsRaw;\n const rhs = childNeedsParens(ast.operator, ast.rhs, true)\n ? '(' + rhsRaw + ')'\n : rhsRaw;\n\n const expr = lhs + ' ' + op + ' ' + rhs;\n\n // Wrap assignments in parens so they work correctly as ternary conditions:\n // (tmp = val) ? a : b vs tmp = val ? a : b\n //\n // `isAssignmentOperator` is built at module load time from the operator\n // names that actually exist on the installed Angular's enum. This\n // works whether `Assign` is present (v21+) or absent (v19/v20) — on\n // older versions the assignment branch is simply unreachable because\n // Angular's compiler never constructs an Assign-operator expression.\n if (isAssignmentOperator(ast.operator)) {\n return '(' + expr + ')';\n }\n return expr;\n }\n visitNotExpr(ast: o.NotExpr) {\n return '!(' + ast.condition.visitExpression(this, null) + ')';\n }\n visitFunctionExpr(ast: o.FunctionExpr) {\n return (\n '(' +\n ast.params.map((p: any) => p.name).join(', ') +\n ') => {' +\n ast.statements.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n }\n visitArrowFunctionExpr(ast: o.ArrowFunctionExpr) {\n const params = '(' + ast.params.map((p: any) => p.name).join(', ') + ')';\n if (Array.isArray(ast.body))\n return (\n params +\n ' => {' +\n ast.body.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n const bodyExpr = (ast.body as o.Expression).visitExpression(this, null);\n // Wrap object literals in parens so `() => {key: val}` isn't parsed\n // as a block with a labeled statement.\n if (ast.body instanceof o.LiteralMapExpr) {\n return params + ' => (' + bodyExpr + ')';\n }\n return params + ' => ' + bodyExpr;\n }\n // `Write*Expr` visitors must wrap the assignment in parentheses so that\n // it composes correctly when nested inside higher-precedence parents\n // (e.g. as the test of a `ConditionalExpr`). Without the wrapping,\n // tmp = ctx.data() ? 0 : -1\n // parses as `tmp = (ctx.data() ? 0 : -1)` because assignment binds\n // looser than the ternary, which silently assigns the wrong value to\n // `tmp`. Angular's own `AbstractEmitterVisitor.visitWriteVarExpr`\n // applies the same context-sensitive wrapping (it skips the parens\n // when the assignment is a top-level statement to avoid `(x = 1);`\n // noise; we always wrap for simplicity — the redundant parens at\n // statement level are harmless).\n //\n // This matters specifically on Angular v19/v20, where assignment is\n // represented in the IR via `WriteVarExpr` / `AssignTemporaryExpr →\n // WriteVarExpr`. On v21+ the same construct is represented via\n // `BinaryOperatorExpr(Assign, ...)`, which `visitBinaryOperatorExpr`\n // already wraps via `isAssignmentOperator`. Without these wrappers,\n // `@if (data(); as item)` and similar conditional alias forms emit\n // runtime-broken code on v19/v20.\n visitWriteVarExpr(ast: any) {\n return '(' + ast.name + ' = ' + ast.value.visitExpression(this, null) + ')';\n }\n visitWritePropExpr(ast: any) {\n return (\n '(' +\n ast.receiver.visitExpression(this, null) +\n '.' +\n ast.name +\n ' = ' +\n ast.value.visitExpression(this, null) +\n ')'\n );\n }\n visitWriteKeyExpr(ast: any) {\n return (\n '(' +\n ast.receiver.visitExpression(this, null) +\n '[' +\n ast.index.visitExpression(this, null) +\n '] = ' +\n ast.value.visitExpression(this, null) +\n ')'\n );\n }\n visitInvokeMethodExpr(ast: any) {\n const receiver = ast.receiver.visitExpression(this, null);\n return (\n emitReceiverForMemberAccess(ast.receiver, receiver) +\n '.' +\n ast.name +\n '(' +\n ast.args.map((a: any) => this.emitExpr(a)).join(', ') +\n ')'\n );\n }\n visitTypeofExpr(ast: o.TypeofExpr) {\n return 'typeof ' + ast.expr.visitExpression(this, null);\n }\n visitUnaryOperatorExpr(ast: o.UnaryOperatorExpr) {\n const op = UNARY_OP_STR.get(ast.operator);\n if (op === undefined) {\n throw new Error(\n `[fast-compile] Unsupported UnaryOperator value ${ast.operator} ` +\n `on @angular/compiler ${o.VERSION?.full ?? '(unknown version)'}`,\n );\n }\n\n const operand = '(' + ast.expr.visitExpression(this, null) + ')';\n const isPostfix = 'isPrefix' in ast && ast.isPrefix === false;\n return '(' + (isPostfix ? operand + op : op + operand) + ')';\n }\n visitInstantiateExpr(ast: o.InstantiateExpr) {\n return (\n 'new (' +\n ast.classExpr.visitExpression(this, null) +\n ')(' +\n ast.args.map((a: any) => this.emitExpr(a)).join(', ') +\n ')'\n );\n }\n visitCommaExpr(ast: o.CommaExpr) {\n return ast.parts.map((p: any) => p.visitExpression(this, null)).join(', ');\n }\n visitParenthesizedExpr(ast: o.ParenthesizedExpr) {\n return '(' + ast.expr.visitExpression(this, null) + ')';\n }\n visitVoidExpr(ast: o.VoidExpr) {\n return 'void ' + ast.expr.visitExpression(this, null);\n }\n visitSpreadElementExpr(ast: o.SpreadElementExpr) {\n return '...' + (ast as any).expression.visitExpression(this, null);\n }\n visitDynamicImportExpr(ast: o.DynamicImportExpr) {\n return (\n 'import(' +\n (typeof ast.url === 'string'\n ? JSON.stringify(ast.url)\n : ast.url.visitExpression(this, null)) +\n ')'\n );\n }\n visitTemplateLiteralExpr(ast: o.TemplateLiteralExpr) {\n return (\n '`' +\n ast.elements[0].text +\n ast.expressions\n .map(\n (e: any, i: number) =>\n '${' +\n e.visitExpression(this, null) +\n '}' +\n ast.elements[i + 1].text,\n )\n .join('') +\n '`'\n );\n }\n visitTaggedTemplateLiteralExpr(ast: any) {\n const elements = ast.template.elements;\n const expressions = ast.template.expressions;\n const head = elements[0].text;\n const spans = expressions\n .map(\n (e: any, i: number) =>\n '${' + e.visitExpression(this, null) + '}' + elements[i + 1].text,\n )\n .join('');\n return ast.tag.visitExpression(this, null) + '`' + head + spans + '`';\n }\n visitLocalizedString(ast: o.LocalizedString) {\n // Emit the downleveled form:\n // $localize(makeTemplateObject(cooked, raw), expr1, expr2, ...)\n const parts: { cooked: string; raw: string }[] = [ast.serializeI18nHead()];\n for (let i = 1; i < ast.messageParts.length; i++) {\n parts.push(ast.serializeI18nTemplatePart(i));\n }\n const cooked = parts.map((p) => escapeForLocalize(p.cooked)).join(', ');\n const raw = parts.map((p) => escapeForLocalize(p.raw)).join(', ');\n const exprs = ast.expressions.map((e) => this.emitExpr(e));\n return (\n '$localize(' +\n MAKE_TEMPLATE_OBJECT_POLYFILL +\n '([' +\n cooked +\n '], [' +\n raw +\n '])' +\n (exprs.length > 0 ? ', ' + exprs.join(', ') : '') +\n ')'\n );\n }\n visitRegularExpressionLiteral(ast: any) {\n return '/' + (ast.body ?? ast.pattern) + '/' + ast.flags;\n }\n visitTemplateLiteralElementExpr(ast: o.TemplateLiteralElementExpr) {\n return JSON.stringify(ast.text);\n }\n // Statement visitors\n visitReturnStmt(stmt: o.ReturnStatement) {\n return 'return ' + stmt.value.visitExpression(this, null) + ';';\n }\n visitExpressionStmt(stmt: o.ExpressionStatement) {\n return stmt.expr.visitExpression(this, null) + ';';\n }\n visitIfStmt(stmt: o.IfStmt) {\n let s =\n 'if (' +\n stmt.condition.visitExpression(this, null) +\n ') {' +\n stmt.trueCase.map((s2: any) => s2.visitStatement(this, null)).join(' ') +\n '}';\n if (stmt.falseCase.length)\n s +=\n ' else {' +\n stmt.falseCase\n .map((s2: any) => s2.visitStatement(this, null))\n .join(' ') +\n '}';\n return s;\n }\n visitDeclareVarStmt(stmt: o.DeclareVarStmt) {\n const kw = stmt.hasModifier(o.StmtModifier.Final) ? 'const' : 'let';\n return (\n kw +\n ' ' +\n stmt.name +\n (stmt.value ? ' = ' + stmt.value.visitExpression(this, null) : '') +\n ';'\n );\n }\n visitDeclareFunctionStmt(stmt: o.DeclareFunctionStmt) {\n return (\n 'function ' +\n stmt.name +\n '(' +\n stmt.params.map((p: any) => p.name).join(', ') +\n ') {' +\n stmt.statements.map((s: any) => s.visitStatement(this, null)).join(' ') +\n '}'\n );\n }\n}\n\nconst stringEmitter = new JSEmitter();\n\n/** Emit Angular output AST expression directly to a JavaScript string. */\nexport function emitAngularExpr(expr: o.Expression): string {\n return expr.visitExpression(stringEmitter, null);\n}\n\n/** Emit Angular output AST statement directly to a JavaScript string. */\nexport function emitAngularStmt(stmt: o.Statement): string {\n return stmt.visitStatement(stringEmitter, null);\n}\n\n/** Set the current source code for OXC-based WrappedNodeExpr slice fallback. */\nexport function setEmitterSourceCode(code: string | undefined): void {\n JSEmitter._currentSourceCode = code;\n}\n"],"mappings":";;AAqBA,IAAM,iBAEF;CACF;EAAC;EAAU;EAAK;CAAC;CACjB;EAAC;EAAsB;EAAM;CAAC;CAC9B;EAAC;EAAyB;EAAM;CAAC;CACjC;EAAC;EAA4B;EAAM;CAAC;CACpC;EAAC;EAAsB;EAAM;CAAC;CAC9B;EAAC;EAAuB;EAAM;CAAC;CAC/B;EAAC;EAA4B;EAAO;CAAC;CACrC;EAAC;EAAiB;EAAO;CAAC;CAC1B;EAAC;EAAgB;EAAO;CAAC;CACzB;EAAC;EAA6B;EAAO;CAAC;CACtC;EAAC;EAAmB;EAAM;CAAC;CAC3B;EAAC;EAAM;EAAM;CAAC;CACd;EAAC;EAAO;EAAM;CAAC;CACf;EAAC;EAAa;EAAK;CAAC;CACpB;EAAC;EAAc;EAAK;CAAC;CACrB;EAAC;EAAU;EAAM;CAAC;CAClB;EAAC;EAAa;EAAM;CAAC;CACrB;EAAC;EAAa;EAAO;CAAC;CACtB;EAAC;EAAgB;EAAO;CAAC;CACzB;EAAC;EAAS;EAAK;CAAE;CACjB;EAAC;EAAe;EAAM;CAAE;CACxB;EAAC;EAAU;EAAK;CAAE;CAClB;EAAC;EAAgB;EAAM;CAAE;CACzB;EAAC;EAAM;EAAM;CAAE;CACf;EAAC;EAAc;EAAc;CAAE;CAC/B;EAAC;EAAQ;EAAK;CAAE;CAChB;EAAC;EAAS;EAAK;CAAE;CACjB;EAAC;EAAY;EAAK;CAAE;CACpB;EAAC;EAAU;EAAK;CAAE;CAClB;EAAC;EAAU;EAAK;CAAE;CAClB;EAAC;EAAkB;EAAM;CAAE;AAC7B;;AAGA,IAAM,sCAA2C,IAAI,IAAI;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,IAAM,gCAAgB,IAA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,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IACtE;EACF,IAAI,KAAK,UAAU,QACjB,KACE,YACA,KAAK,UACF,KAAK,OAAY,GAAG,eAAe,MAAM,IAAI,CAAC,CAAC,CAC/C,KAAK,GAAG,IACX;EACJ,OAAO;CACT;CACA,oBAAoB,MAAwB;EAE1C,QADW,KAAK,YAAY,EAAE,aAAa,KAAK,IAAI,UAAU,SAG5D,MACA,KAAK,QACJ,KAAK,QAAQ,QAAQ,KAAK,MAAM,gBAAgB,MAAM,IAAI,IAAI,MAC/D;CAEJ;CACA,yBAAyB,MAA6B;EACpD,OACE,cACA,KAAK,OACL,MACA,KAAK,OAAO,KAAK,MAAW,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI,IAC7C,QACA,KAAK,WAAW,KAAK,MAAW,EAAE,eAAe,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IACtE;CAEJ;AACF;AAEA,IAAM,gBAAgB,IAAI,UAAU;;AAGpC,SAAgB,gBAAgB,MAA4B;CAC1D,OAAO,KAAK,gBAAgB,eAAe,IAAI;AACjD;;AAGA,SAAgB,gBAAgB,MAA2B;CACzD,OAAO,KAAK,eAAe,eAAe,IAAI;AAChD;;AAGA,SAAgB,qBAAqB,MAAgC;CACnE,UAAU,qBAAqB;AACjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseSync } from "oxc-parser";
|
|
1
|
+
import type { parseSync } from "oxc-parser";
|
|
2
2
|
export interface RegistryInput {
|
|
3
3
|
classPropertyName: string;
|
|
4
4
|
bindingPropertyName: string;
|
|
@@ -54,3 +54,9 @@ export type ComponentRegistry = Map<string, RegistryEntry>;
|
|
|
54
54
|
* without performing full compilation. Uses OXC's native Rust parser for speed.
|
|
55
55
|
*/
|
|
56
56
|
export declare function scanFile(code: string, fileName: string, program?: ReturnType<typeof parseSync>["program"]): RegistryEntry[];
|
|
57
|
+
/**
|
|
58
|
+
* Whether the file declares a `@Component({ standalone: false })`. Such a
|
|
59
|
+
* component's template scope comes from the NgModule that declares it, which
|
|
60
|
+
* can only be found by scanning the whole project.
|
|
61
|
+
*/
|
|
62
|
+
export declare function declaresNonStandaloneComponent(program: ReturnType<typeof parseSync>["program"]): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { COMPILABLE_DECORATORS } from "./constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { parseOxc } from "./utils.js";
|
|
3
3
|
//#region packages/vite-plugin-angular/src/lib/compiler/registry.ts
|
|
4
4
|
var DECORATOR_RE = new RegExp(`@(${[...COMPILABLE_DECORATORS].join("|")})`);
|
|
5
5
|
/**
|
|
@@ -9,7 +9,7 @@ var DECORATOR_RE = new RegExp(`@(${[...COMPILABLE_DECORATORS].join("|")})`);
|
|
|
9
9
|
function scanFile(code, fileName, program) {
|
|
10
10
|
const entries = [];
|
|
11
11
|
if (!DECORATOR_RE.test(code) && !/\bconst\s+\w+\s*=\s*\[/.test(code)) return entries;
|
|
12
|
-
program ??=
|
|
12
|
+
program ??= parseOxc(fileName, code).program;
|
|
13
13
|
for (const node of program.body) {
|
|
14
14
|
const varDecl = node.type === "ExportNamedDeclaration" && node.declaration?.type === "VariableDeclaration" ? node.declaration : node.type === "VariableDeclaration" ? node : null;
|
|
15
15
|
if (!varDecl || varDecl.kind !== "const") continue;
|
|
@@ -170,7 +170,27 @@ function scanFile(code, fileName, program) {
|
|
|
170
170
|
}
|
|
171
171
|
return entries;
|
|
172
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Whether the file declares a `@Component({ standalone: false })`. Such a
|
|
175
|
+
* component's template scope comes from the NgModule that declares it, which
|
|
176
|
+
* can only be found by scanning the whole project.
|
|
177
|
+
*/
|
|
178
|
+
function declaresNonStandaloneComponent(program) {
|
|
179
|
+
for (const node of program.body) {
|
|
180
|
+
const decl = node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
181
|
+
if (decl?.type !== "ClassDeclaration") continue;
|
|
182
|
+
for (const dec of decl.decorators || []) {
|
|
183
|
+
const expr = dec.expression;
|
|
184
|
+
if (expr?.type !== "CallExpression") continue;
|
|
185
|
+
if (expr.callee?.name !== "Component") continue;
|
|
186
|
+
const arg = expr.arguments?.[0];
|
|
187
|
+
if (arg?.type !== "ObjectExpression") continue;
|
|
188
|
+
for (const prop of arg.properties) if (prop.type === "Property" && (prop.key?.name || prop.key?.value) === "standalone" && prop.value?.type === "Literal" && prop.value.value === false) return true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
173
193
|
//#endregion
|
|
174
|
-
export { scanFile };
|
|
194
|
+
export { declaresNonStandaloneComponent, scanFile };
|
|
175
195
|
|
|
176
196
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +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 /** 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 ??= parseSync(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"],"mappings":";;;AAwDA,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,UAAU,UAAU,IAAI,CAAC,CAAC;CAStC,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,O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e,wBAOf,QAAQ,QAHM,aACZ,eAAe,yBAAyB,IAAI,CAE9B,KAAS;KAE7B;KAGA,MAAM,mBAA0B,OAAO,cAAc,CAAC;KACtD,KAAK,MAAM,QAAQ,kBAAkB;MACnC,MAAM,QAAQ,KAAK;MACnB,IAAI,CAAC,OAAO;MACZ,MAAM,WACJ,MAAM,SAAS,mBACX,MAAM,QAAQ,OACd,MAAM,SAAS,eACb,MAAM,OACN,KAAA;MACR,IAAI,aAAa,SAKf,OAAO,QAAQ;OACb,mBAAmB;OACnB,sBALA,MAAM,YAAY,EAAE,EAAE,SAAS,YAC3B,MAAM,UAAU,EAAE,CAAC,QACnB,SAG0B;OAC9B,UAAU;OACV,UAAU;MACZ;WACK,IAAI,aAAa,UAKtB,QAAQ,SAHN,MAAM,YAAY,EAAE,EAAE,SAAS,YAC3B,MAAM,UAAU,EAAE,CAAC,QACnB,SACmB;KAE7B;IACF;IAEA,QAAQ,KAAK;KACX,UAAU,SAAS,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;KACtC,MAAM,kBAAkB,cAAc,cAAc;KACpD;KACA;KACA,GAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;KACnD,GAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;IACvD,CAAC;GACH;EACF;CACF;CAEA,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}\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,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,MAA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|
+
import type { parseSync } from "oxc-parser";
|
|
2
2
|
export interface InlineResourceResult {
|
|
3
3
|
/** The modified source code, or the original if no changes were needed. */
|
|
4
4
|
code: string;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* truly-inline `styles: [...]` template strings).
|
|
6
|
+
* Absolute path of each inlined external style, keyed by its position in
|
|
7
|
+
* the flat per-file style list produced by {@link extractInlineStyles}. Lets
|
|
8
|
+
* the caller preprocess each external `styleUrl` as its own file (extension
|
|
9
|
+
* and relative imports), independent of the `inlineStylesExtension` option
|
|
10
|
+
* (which governs truly-inline `styles: [...]` template strings).
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
stylePaths: Map<number, string>;
|
|
14
13
|
/**
|
|
15
14
|
* Absolute paths of every external resource file successfully read and
|
|
16
15
|
* inlined. Callers record these so a later edit to the resource file can
|
|
@@ -32,7 +31,7 @@ export interface InlineResourceResult {
|
|
|
32
31
|
* merged into that existing array instead of emitting a second `styles`
|
|
33
32
|
* property (which would be a duplicate object literal key).
|
|
34
33
|
*
|
|
35
|
-
* Returns the modified source code plus the per-style-index
|
|
34
|
+
* Returns the modified source code plus the per-style-index path map
|
|
36
35
|
* (see {@link InlineResourceResult}).
|
|
37
36
|
*/
|
|
38
37
|
export declare function inlineResourceUrls(code: string, fileName: string): Promise<InlineResourceResult>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { parseOxc } from "./utils.js";
|
|
1
2
|
import { extractInlineStyles as extractInlineStyles$1 } from "./style-ast.js";
|
|
2
3
|
import * as fs from "node:fs";
|
|
3
4
|
import * as path$1 from "node:path";
|
|
4
|
-
import { parseSync } from "oxc-parser";
|
|
5
5
|
import MagicString from "magic-string";
|
|
6
6
|
//#region packages/vite-plugin-angular/src/lib/compiler/resource-inliner.ts
|
|
7
7
|
/** Whether a node is an inline style value (string literal or single-quasi template). */
|
|
@@ -28,17 +28,17 @@ function countInlineStyleLiterals(arrayExpr) {
|
|
|
28
28
|
* merged into that existing array instead of emitting a second `styles`
|
|
29
29
|
* property (which would be a duplicate object literal key).
|
|
30
30
|
*
|
|
31
|
-
* Returns the modified source code plus the per-style-index
|
|
31
|
+
* Returns the modified source code plus the per-style-index path map
|
|
32
32
|
* (see {@link InlineResourceResult}).
|
|
33
33
|
*/
|
|
34
34
|
async function inlineResourceUrls(code, fileName) {
|
|
35
|
-
const
|
|
35
|
+
const stylePaths = /* @__PURE__ */ new Map();
|
|
36
36
|
if (!code.includes("templateUrl") && !code.includes("styleUrl")) return {
|
|
37
37
|
code,
|
|
38
|
-
|
|
38
|
+
stylePaths,
|
|
39
39
|
resourceDependencies: []
|
|
40
40
|
};
|
|
41
|
-
const { program } =
|
|
41
|
+
const { program } = parseOxc(fileName, code);
|
|
42
42
|
const ms = new MagicString(code);
|
|
43
43
|
let changed = false;
|
|
44
44
|
const dir = path$1.dirname(fileName);
|
|
@@ -125,11 +125,10 @@ async function inlineResourceUrls(code, fileName) {
|
|
|
125
125
|
if (content !== void 0) cssProps.push({
|
|
126
126
|
prop: rp.prop,
|
|
127
127
|
contents: [content],
|
|
128
|
-
|
|
128
|
+
paths: [rp.resolvedPath]
|
|
129
129
|
});
|
|
130
130
|
} else {
|
|
131
131
|
const contents = [];
|
|
132
|
-
const extensions = [];
|
|
133
132
|
let allRead = true;
|
|
134
133
|
for (const p of rp.resolvedPaths) {
|
|
135
134
|
const content = fileContents.get(p);
|
|
@@ -138,12 +137,11 @@ async function inlineResourceUrls(code, fileName) {
|
|
|
138
137
|
break;
|
|
139
138
|
}
|
|
140
139
|
contents.push(content);
|
|
141
|
-
extensions.push(extensionOf(p));
|
|
142
140
|
}
|
|
143
141
|
if (allRead && contents.length > 0) cssProps.push({
|
|
144
142
|
prop: rp.prop,
|
|
145
143
|
contents,
|
|
146
|
-
|
|
144
|
+
paths: rp.resolvedPaths
|
|
147
145
|
});
|
|
148
146
|
}
|
|
149
147
|
for (const { prop, content } of templateUrlRewrites) {
|
|
@@ -152,7 +150,7 @@ async function inlineResourceUrls(code, fileName) {
|
|
|
152
150
|
}
|
|
153
151
|
if (cssProps.length > 0) {
|
|
154
152
|
const allContents = cssProps.flatMap((c) => c.contents);
|
|
155
|
-
const
|
|
153
|
+
const allPaths = cssProps.flatMap((c) => c.paths);
|
|
156
154
|
if (existingStylesArray) {
|
|
157
155
|
const realElements = existingStylesArray.elements.filter((e) => e != null);
|
|
158
156
|
if (realElements.length > 0) {
|
|
@@ -176,22 +174,16 @@ async function inlineResourceUrls(code, fileName) {
|
|
|
176
174
|
}
|
|
177
175
|
changed = true;
|
|
178
176
|
const externalBase = flatStyleBase + existingInlineCount;
|
|
179
|
-
|
|
180
|
-
if (ext) styleExtensions.set(externalBase + k, ext);
|
|
181
|
-
});
|
|
177
|
+
allPaths.forEach((p, k) => stylePaths.set(externalBase + k, p));
|
|
182
178
|
flatStyleBase = externalBase + allContents.length;
|
|
183
179
|
} else flatStyleBase += existingInlineCount;
|
|
184
180
|
}
|
|
185
181
|
return {
|
|
186
182
|
code: changed ? ms.toString() : code,
|
|
187
|
-
|
|
183
|
+
stylePaths,
|
|
188
184
|
resourceDependencies: [...pathsToRead].filter((p) => fileContents.get(p) !== void 0)
|
|
189
185
|
};
|
|
190
186
|
}
|
|
191
|
-
/** Lower-cased file extension without the leading dot (e.g. `scss`), or `''`. */
|
|
192
|
-
function extensionOf(filePath) {
|
|
193
|
-
return path$1.extname(filePath).slice(1).toLowerCase();
|
|
194
|
-
}
|
|
195
187
|
/**
|
|
196
188
|
* Remove a property from an object literal while also eating one surrounding
|
|
197
189
|
* comma so the resulting object stays syntactically valid. Prefers the
|