-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.d.ts
More file actions
904 lines (855 loc) · 27.3 KB
/
index.d.ts
File metadata and controls
904 lines (855 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/* auto-generated by NAPI-RS */
/* eslint-disable */
/** Angular version for version-conditional behavior. */
export interface AngularVersion {
/** Major version number (e.g., 19 for Angular 19.0.0). */
major: number
/** Minor version number (e.g., 0 for Angular 19.0.0). */
minor: number
/** Patch version number (e.g., 0 for Angular 19.0.0). */
patch: number
}
/** Result of class metadata compilation. */
export interface ClassMetadataNapiCompileResult {
/**
* The compiled setClassMetadata call as JavaScript code.
* Example: `(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵɵsetClassMetadata(...); })()`
*/
code: string
/** Compilation errors. */
errors: Array<OxcError>
}
/**
* Compile class metadata for an Angular decorated class (async).
*
* This is the async version of `compileClassMetadataSync`. Use this when
* compiling class metadata in a non-blocking context.
*/
export declare function compileClassMetadata(
source: string,
filePath: string,
className: string,
decoratorType: string,
): Promise<ClassMetadataNapiCompileResult>
/**
* Compile a factory function from the provided metadata (async).
*
* This generates a factory function that creates instances of the class
* with proper dependency injection. The output format depends on the
* deps_kind parameter.
*
* # Arguments
*
* * `input` - The factory metadata (name, target, deps)
*
* # Returns
*
* A `FactoryNapiCompileResult` containing the compiled code or errors.
*/
export declare function compileFactory(
input: FactoryCompileInput,
): Promise<FactoryNapiCompileResult>
/**
* Compile for HMR (async).
*
* This is the async version of `compileForHmrSync`.
*/
export declare function compileForHmr(
template: string,
componentName: string,
filePath: string,
styles?: Array<string> | undefined | null,
options?: TransformOptions | undefined | null,
): Promise<HmrCompileResult>
/**
* Transform a template and generate HMR module in one step.
*
* This is a convenience function that combines template compilation
* and HMR module generation.
*
* # Arguments
*
* * `template` - The template HTML string
* * `component_name` - The name of the component class
* * `file_path` - The path to the component file
* * `styles` - Optional array of CSS styles
*
* # Returns
*
* A tuple of (hmr_module_code, component_id) or errors.
*/
export declare function compileForHmrSync(
template: string,
componentName: string,
filePath: string,
styles?: Array<string> | undefined | null,
options?: TransformOptions | undefined | null,
): HmrCompileResult
/**
* Compile an Angular template to JavaScript (async).
*
* This is the async version of `compileTemplateSync`. Use this when
* compiling templates in a non-blocking context.
*/
export declare function compileTemplate(
template: string,
componentName: string,
filePath: string,
options?: TransformOptions | undefined | null,
): Promise<TemplateCompileResult>
/** Result of extracting Angular component definitions from compiled JavaScript. */
export interface ComponentExtractionResult {
/** Const declarations like `const _c0 = [...]`, `const _c1 = [...]`, etc. */
consts: Array<string>
/** Template functions like `function ClassName_Template(rf, ctx) {...}`. */
templateFunctions: Array<string>
/** Component definition like `ClassName.ɵcmp = defineComponent(...)`. */
componentDef?: string
/** Factory function like `ClassName.ɵfac = function(t) {...}`. */
factoryDef?: string
}
/** Host metadata extracted from a `@Component` decorator. */
export interface ComponentHostMetadata {
/** Host property bindings: [[key, value], ...]. */
properties: Array<Array<string>>
/** Host attribute bindings: [[key, value], ...]. */
attributes: Array<Array<string>>
/** Host event listeners: [[key, value], ...]. */
listeners: Array<Array<string>>
/** Static class attribute binding. */
classAttr?: string
/** Static style attribute binding. */
styleAttr?: string
}
/** Parts of a component ID. */
export interface ComponentIdParts {
/** The file path part of the component ID. */
filePath: string
/** The class name part of the component ID. */
className: string
}
/** URLs extracted from @Component decorators in a file. */
export interface ComponentUrls {
/** Template URLs from templateUrl properties. */
templateUrls: Array<string>
/** Style URLs from styleUrl and styleUrls properties. */
styleUrls: Array<string>
}
/**
* Decode a URL-encoded component ID.
*
* # Arguments
*
* * `encoded_id` - The URL-encoded component ID
*
* # Returns
*
* Decoded component ID.
*/
export declare function decodeComponentId(encodedId: string): string
/**
* Dependency metadata for factory injection.
*
* Describes a constructor parameter that needs to be injected.
*/
export interface DependencyMetadata {
/**
* The token expression as a JavaScript string (e.g., "SomeService", "SOME_TOKEN").
* If None, the dependency is invalid and will generate `invalidFactoryDep(index)`.
*/
token?: string
/**
* If this is an @Attribute injection, the literal attribute name type.
* Otherwise None for regular injection.
*/
attributeNameType?: string
/** Whether this dependency has an @Host qualifier. */
host?: boolean
/** Whether this dependency has an @Optional qualifier. */
optional?: boolean
/** Whether this dependency has an @Self qualifier. */
self?: boolean
/** Whether this dependency has an @SkipSelf qualifier. */
skipSelf?: boolean
}
/**
* A `.d.ts` type declaration for an Angular class.
*
* Contains the class name and the static member declarations
* that should be injected into the corresponding `.d.ts` class body.
*/
export interface DtsDeclaration {
/** The name of the class. */
className: string
/**
* The static member declarations to add to the class body in `.d.ts`.
* Newline-separated `static` property declarations.
*/
members: string
}
/**
* Encapsulate CSS styles for a component using attribute selectors.
*
* This implements Angular's ViewEncapsulation.Emulated behavior,
* scoping CSS styles to a component by adding attribute selectors.
*
* # Arguments
*
* * `css` - The CSS source code to encapsulate
* * `component_id` - The component's unique identifier (typically a hash)
*
* # Returns
*
* The CSS with all selectors scoped to the component.
*
* # Example
*
* Input:
* ```css
* .button { color: red; }
* ```
*
* Output (with component_id "abc123"):
* ```css
* .button[ng-cabc123] { color: red; }
* ```
*/
export declare function encapsulateStyle(css: string, componentId: string): string
/**
* URL-encode a component ID for use in import URLs.
*
* # Arguments
*
* * `component_id` - The component ID to encode
*
* # Returns
*
* URL-encoded component ID.
*/
export declare function encodeComponentId(componentId: string): string
/**
* Extract Angular component definitions from compiled JavaScript output using AST parsing.
*
* This function parses compiled Angular JavaScript and extracts specific elements
* for a given class name:
* - Const declarations matching `_c\d+` pattern
* - Template functions matching `{ClassName}_*_Template`
* - Component definition (`ClassName.ɵcmp = defineComponent(...)`)
* - Factory function (`ClassName.ɵfac = function(t) {...}`)
*
* # Arguments
*
* * `source` - The compiled JavaScript source code
* * `class_name` - The name of the component class to extract
*
* # Returns
*
* A `ComponentExtractionResult` containing all found elements.
*/
export declare function extractAngularComponentByAst(
source: string,
className: string,
): ComponentExtractionResult
/**
* Extract templateUrl and styleUrls from all @Component decorators in a file (async).
*
* This is the async version of `extractComponentUrlsSync`. Use this when
* extracting URLs in a non-blocking context.
*/
export declare function extractComponentUrls(
source: string,
filename: string,
): Promise<ComponentUrls>
/** Extracted component metadata from a `@Component` decorator. */
export interface ExtractedComponentMetadata {
/** The name of the component class. */
className: string
/** Span start of the class declaration. */
spanStart: number
/** Span end of the class declaration. */
spanEnd: number
/** The CSS selector. */
selector?: string
/** Inline template string. */
template?: string
/** URL to an external template file. */
templateUrl?: string
/** Inline styles array. */
styles: Array<string>
/** URLs to external stylesheet files. */
styleUrls: Array<string>
/** Whether this is a standalone component. */
standalone: boolean
/** View encapsulation mode: "Emulated" | "None" | "ShadowDom". */
encapsulation: string
/** Change detection strategy: "Default" | "OnPush". */
changeDetection: string
/** Host bindings and listeners. */
host?: ComponentHostMetadata
/** Component imports (for standalone components). */
imports: Array<string>
/** Exported names for template references. */
exportAs?: string
/** Whether to preserve whitespace in templates. */
preserveWhitespaces: boolean
/** Providers expression as emitted JavaScript (if present). */
providers?: string
/** View providers expression as emitted JavaScript (if present). */
viewProviders?: string
/** Animations expression as emitted JavaScript (if present). */
animations?: string
/** Schema identifiers. */
schemas: Array<string>
/** Host directives configuration. */
hostDirectives: Array<ExtractedHostDirective>
/** Inputs extracted from @Input decorators on class members. */
inputs?: Array<ExtractedInputMetadata>
/** Outputs extracted from @Output decorators on class members. */
outputs?: Array<ExtractedOutputMetadata>
/** Content queries extracted from @ContentChild/@ContentChildren decorators. */
queries?: Array<ExtractedQueryMetadata>
/** View queries extracted from @ViewChild/@ViewChildren decorators. */
viewQueries?: Array<ExtractedQueryMetadata>
}
/** Host directive metadata extracted from a `@Component` decorator. */
export interface ExtractedHostDirective {
/** The directive class name. */
directive: string
/** Input mappings: [[publicName, internalName], ...]. */
inputs: Array<Array<string>>
/** Output mappings: [[publicName, internalName], ...]. */
outputs: Array<Array<string>>
/** Whether this is a forward reference. */
isForwardReference: boolean
}
/** Extracted input metadata from an `@Input` decorator. */
export interface ExtractedInputMetadata {
/** The property name on the class. */
classPropertyName: string
/** The binding property name (can differ from class property name). */
bindingPropertyName: string
/** Whether this input is required. */
required: boolean
/** Whether this is a signal-based input. */
isSignal: boolean
/** Transform function expression as emitted JavaScript (if present). */
transform?: string
}
/** Extracted output metadata from an `@Output` decorator. */
export interface ExtractedOutputMetadata {
/** The property name on the class. */
classPropertyName: string
/** The binding property name (can differ from class property name). */
bindingPropertyName: string
}
/** Extracted pipe metadata from a `@Pipe` decorator. */
export interface ExtractedPipeMetadata {
/** The name of the pipe class. */
className: string
/** Span start of the class declaration. */
spanStart: number
/** Span end of the class declaration. */
spanEnd: number
/** The pipe name used in templates (from `@Pipe({name: '...'})`) */
pipeName?: string
/** Whether the pipe is pure (default: true). */
pure: boolean
/** Whether this is a standalone pipe. */
standalone: boolean
}
/** Extracted query metadata from `@ViewChild`, `@ViewChildren`, `@ContentChild`, or `@ContentChildren` decorators. */
export interface ExtractedQueryMetadata {
/** The property name on the class. */
propertyName: string
/** The query predicate (serialized as a string). */
predicate: string
/** Whether to include only direct children or all descendants. */
descendants?: boolean
/** Whether this query should collect only static results. */
static?: boolean
/** An expression representing a type to read from each matched node. */
read?: string
/** Whether this query returns only the first matching result (ViewChild/ContentChild vs ViewChildren/ContentChildren). */
first: boolean
}
/**
* Input for compiling a factory function.
*
* Factory functions are generated as part of directive, component, pipe,
* injectable, and NgModule compilation. This allows direct compilation
* of a factory function from metadata.
*/
export interface FactoryCompileInput {
/** The name of the class for which to generate the factory. */
name: string
/**
* The target type: "Component" | "Directive" | "Injectable" | "Pipe" | "NgModule".
* Defaults to "Injectable" if not specified.
*/
target?: string
/**
* The kind of dependencies: "Valid" | "Invalid" | "None".
* - "Valid": Normal dependencies that can be injected.
* - "Invalid": One or more dependencies couldn't be resolved (generates invalidFactory).
* - "None": No constructor, uses inherited factory pattern.
* Defaults to "Valid" if not specified.
*/
depsKind?: string
/**
* Dependencies to inject in the constructor.
* Only used when deps_kind is "Valid".
*/
deps?: Array<DependencyMetadata>
}
/** Result of compiling a factory function. */
export interface FactoryNapiCompileResult {
/**
* The compiled factory function as JavaScript code.
* Example: `function MyClass_Factory(__ngFactoryType__) { return new ... }`
*/
code: string
/** Compilation errors. */
errors: Array<OxcError>
}
/**
* Generate an HMR update module for a component.
*
* This generates a JavaScript module that can be dynamically imported
* during HMR to update a component's template and styles.
*
* # Arguments
*
* * `component_id` - The component ID (path@ClassName)
* * `template_js` - The compiled template function as JavaScript
* * `styles` - Optional array of CSS styles
*
* # Returns
*
* JavaScript code for the HMR update module.
*/
export declare function generateHmrModule(
componentId: string,
templateJs: string,
styles?: Array<string> | undefined | null,
declarationsJs?: string | undefined | null,
constsJs?: string | undefined | null,
): string
/**
* Generate a style update module for HMR.
*
* This generates a JavaScript module that exports updated styles
* for a component.
*
* # Arguments
*
* * `component_id` - The component ID (path@ClassName)
* * `styles` - Array of CSS styles
*
* # Returns
*
* JavaScript code for the style update module.
*/
export declare function generateStyleModule(componentId: string, styles: Array<string>): string
/** Result of compiling for HMR. */
export interface HmrCompileResult {
/** The complete HMR update module code. */
hmrModule: string
/** The component ID (path@ClassName). */
componentId: string
/** The compiled template function as JavaScript. */
templateJs: string
/** Compilation errors. */
errors: Array<OxcError>
}
/**
* Host bindings metadata for a component.
*
* Contains property bindings, attribute bindings, and event listeners
* extracted from the `host` property of a `@Component` decorator.
*/
export interface HostMetadataInput {
/**
* Host property bindings: `[[key, value], ...]`.
* Example: `[["[class.active]", "isActive"], ["[disabled]", "isDisabled"]]`
*/
properties?: Array<Array<string>>
/**
* Host attribute bindings: `[[key, value], ...]`.
* Example: `[["role", "button"], ["aria-label", "Submit"]]`
*/
attributes?: Array<Array<string>>
/**
* Host event listeners: `[[key, value], ...]`.
* Example: `[["(click)", "onClick()"], ["(keydown.enter)", "onEnter()"]]`
*/
listeners?: Array<Array<string>>
/** Special attribute for static class binding. */
classAttr?: string
/** Special attribute for static style binding. */
styleAttr?: string
}
/**
* Input for compiling an injector.
*
* Injectors are generated from `@NgModule` metadata, not from a decorator.
* This struct captures the metadata needed to compile an injector definition.
*/
export interface InjectorCompileInput {
/** The name of the injector (typically the NgModule class name). */
name: string
/**
* Optional serialized JavaScript expression for providers.
* Example: `"[MyService, { provide: TOKEN, useClass: MyImpl }]"`
*/
providers?: string
/**
* Optional array of import class names.
* Example: `["CommonModule", "FormsModule"]`
*/
imports?: Array<string>
}
/** Result of compiling an injector. */
export interface InjectorNapiCompileResult {
/**
* The compiled injector definition as JavaScript code.
* Example: `i0.ɵɵdefineInjector({ providers: [...], imports: [...] })`
*/
code: string
/** Compilation errors. */
errors: Array<OxcError>
}
/**
* Link Angular partial declarations in a JavaScript file (async).
*
* This is the async version of `linkAngularPackageSync`. Use this when
* linking packages in a non-blocking context.
*/
export declare function linkAngularPackage(code: string, filename: string): Promise<LinkResult>
/**
* Link Angular partial declarations in a JavaScript file (sync).
*
* Processes pre-compiled Angular library code containing `ɵɵngDeclare*` calls
* and converts them to their fully compiled equivalents (`ɵɵdefine*` calls).
*
* This is necessary for Angular libraries published with partial compilation
* (Angular 12+). Without linking, Angular falls back to JIT compilation
* which requires `@angular/compiler` at runtime.
*
* # Arguments
*
* * `code` - The JavaScript source code to link
* * `filename` - The filename (for source maps and error messages)
*
* # Returns
*
* A `LinkResult` containing the linked code. If no partial declarations
* were found, the original code is returned with `linked: false`.
*/
export declare function linkAngularPackageSync(code: string, filename: string): LinkResult
/** Result of linking Angular partial declarations. */
export interface LinkResult {
/** The linked code. */
code: string
/** Source map (if enabled). */
map?: string
/** Whether any declarations were linked. */
linked: boolean
}
/**
* Optimize an Angular package file for better tree-shaking (async).
*
* This is the async version of `optimizeAngularPackageSync`. Use this when
* optimizing packages in a non-blocking context.
*/
export declare function optimizeAngularPackage(
code: string,
filename: string,
options: OptimizeOptions,
): Promise<OptimizeResult>
/**
* Options for the Angular build optimizer.
*
* The optimizer applies transformations to pre-compiled Angular packages
* (from node_modules/@angular/*) to enable better tree-shaking.
*/
export interface OptimizeOptions {
/** Generate source maps. */
sourcemap?: boolean
/**
* Remove Angular metadata calls (`ɵsetClassMetadata`, etc.).
* Default: true
*/
elideMetadata?: boolean
/**
* Wrap Angular static members in pure IIFEs for tree-shaking.
* Default: true
*/
wrapStaticMembers?: boolean
/**
* Add `@__PURE__` annotations to top-level calls.
* Default: true
*/
markPure?: boolean
/**
* Optimize TypeScript enum patterns to IIFEs.
* Default: true
*/
adjustEnums?: boolean
}
/** Result of optimizing an Angular package file. */
export interface OptimizeResult {
/** The optimized code. */
code: string
/** Source map (if sourcemap option was enabled). */
map?: string
}
/**
* Parse a component ID into its parts.
*
* # Arguments
*
* * `component_id` - The component ID (path@ClassName)
*
* # Returns
*
* Object with `filePath` and `className` properties.
*/
export declare function parseComponentId(componentId: string): ComponentIdParts
/** Result of pipe compilation. */
export interface PipeCompileResult {
/** The compiled pipe definition as JavaScript code. */
code: string
/** Any errors that occurred during compilation. */
errors: Array<OxcError>
}
/**
* Pre-resolved external resources for file transformation.
*
* Note: NAPI-RS converts JavaScript plain objects (Record/object) to Rust HashMap,
* NOT JavaScript Map objects. Pass plain objects, not `new Map()`.
*/
export interface ResolvedResources {
/**
* Map from templateUrl path to resolved template content.
* Pass as a plain object: `{ './template.html': 'content' }`, not `new Map()`.
*/
templates: Record<string, string>
/**
* Map from styleUrl path to resolved (preprocessed) style content.
* Pass as a plain object: `{ './styles.scss': ['compiled css'] }`, not `new Map()`.
*/
styles: Record<string, string[]>
}
/** Result of compiling an Angular template. */
export interface TemplateCompileResult {
/** The compiled template function as JavaScript code. */
code: string
/** Source map (if sourcemap option was enabled). */
map?: string
/** Compilation errors. */
errors: Array<OxcError>
}
/**
* Top-level declarations extracted from a TypeScript file for HMR.
*
* These are the symbols that can be passed as local dependencies to
* the HMR update function.
*/
export interface TopLevelDeclarations {
/**
* Names of all top-level declarations in the file.
*
* Includes: classes, functions, const enums, variables, and imports.
* Excludes: type-only imports, interfaces, type aliases.
*/
names: Array<string>
}
/**
* Transform an Angular TypeScript file to JavaScript (async).
*
* This performs the complete transformation pipeline:
* 1. Parse the TypeScript file using oxc_parser
* 2. Find @Component decorated classes
* 3. Inline resolved templates and styles
* 4. Compile templates to Angular IR code
* 5. Generate JavaScript output using oxc_codegen
*
* # Arguments
*
* * `source` - The TypeScript source code
* * `filename` - The file path (for source maps and error messages)
* * `options` - Transformation options
* * `resolved_resources` - Optional pre-resolved external resources
*
* # Returns
*
* A `TransformResult` containing the transformed code, dependencies, and any errors.
*/
export declare function transformAngularFile(
source: string,
filename: string,
options: TransformOptions,
resolvedResources?: ResolvedResources | undefined | null,
): Promise<TransformResult>
export declare function transformAngularFileSync(
source: string,
filename: string,
options: TransformOptions,
resolvedResources?: ResolvedResources | undefined | null,
): TransformResult
/** Options for transforming an Angular component. */
export interface TransformOptions {
/** Generate source maps. */
sourcemap?: boolean
/** Enable JIT (Just-In-Time) compilation mode. */
jit?: boolean
/** Enable HMR (Hot Module Replacement) support. */
hmr?: boolean
/** Enable advanced optimizations. */
advancedOptimizations?: boolean
/**
* i18n message ID strategy.
*
* When true (default), uses external message IDs (MSG_EXTERNAL_abc123$$SUFFIX).
* When false, uses file-based naming (MSG_SUFFIX_0).
*/
i18NUseExternalIds?: boolean
/**
* Angular core version for version-conditional behavior.
*
* When set, used to determine defaults like:
* - `standalone`: defaults to `false` for v18 and earlier, `true` for v19+
*
* When not set, assumes latest Angular version (v19+ behavior).
*/
angularVersion?: AngularVersion
/** The CSS selector that identifies this component in a template. */
selector?: string
/**
* Whether this component is standalone.
* When not set, defaults based on Angular version (true for v19+, false for v18-).
*/
standalone?: boolean
/**
* View encapsulation mode: "Emulated" | "None" | "ShadowDom".
* Defaults to "Emulated" if not specified.
*/
encapsulation?: string
/**
* Change detection strategy: "Default" | "OnPush".
* Defaults to "Default" if not specified.
*/
changeDetection?: string
/**
* Whether to preserve whitespace in templates.
* Defaults to false if not specified.
*/
preserveWhitespaces?: boolean
/**
* Host bindings metadata for the component.
* Contains property bindings, attribute bindings, and event listeners.
*/
host?: HostMetadataInput
/**
* Enable cross-file import elision analysis.
*
* When true, resolves imports to source files to check if exports are type-only.
* This improves import elision accuracy for compare tests.
*
* **Note**: This is intended for compare tests only. In production, bundlers
* handle import elision during tree-shaking.
*/
crossFileElision?: boolean
/**
* Base directory for module resolution.
*
* Used when `cross_file_elision` is enabled to resolve relative imports.
*/
baseDir?: string
/**
* Path to tsconfig.json for path aliases.
*
* Used when `cross_file_elision` is enabled to resolve path aliases.
*/
tsconfigPath?: string
/**
* Emit setClassMetadata() calls for TestBed support.
*
* When true, generates `ɵɵsetClassMetadata()` calls wrapped in a dev-mode guard.
* This preserves original decorator information for TestBed's recompilation APIs.
*
* Default: false (metadata is dev-only and usually stripped in production)
*/
emitClassMetadata?: boolean
/**
* Minify final component styles before emitting them into `styles: [...]`.
*
* This runs after Angular style encapsulation, so it applies to the same
* final CSS strings that are embedded in generated component definitions.
*/
minifyComponentStyles?: boolean
/**
* Resolved import paths for host directives and other imports.
*
* Maps local identifier name (e.g., "AriaDisableDirective") to the resolved
* module path (e.g., "../a11y/aria-disable.directive").
*
* This is used to override barrel export paths with actual file paths.
* The build tool should resolve imports using TypeScript's module resolution
* and provide the actual file paths here.
*/
resolvedImports?: Map<string, string>
}
/** Result of transforming an Angular file. */
export interface TransformResult {
/** The transformed code. */
code: string
/** Source map (if sourcemap option was enabled). */
map?: string
/** Files this file depends on (for watch mode). */
dependencies: Array<string>
/** Template updates for HMR (component_id → compiled_template). */
templateUpdates: Map<string, string>
/** Style updates for HMR (component_id → styles). */
styleUpdates: Map<string, string[]>
/** Compilation errors. */
errors: Array<OxcError>
/** Compilation warnings. */
warnings: Array<OxcError>
/**
* `.d.ts` type declarations for Angular classes.
*
* Each entry contains the class name and the static member declarations
* that should be injected into the corresponding `.d.ts` class body.
* This enables library builds to include proper Ivy type declarations
* for template type-checking by consumers.
*
* The declarations use `i0` as the namespace alias for `@angular/core`.
* Consumers must ensure their `.d.ts` files include:
* `import * as i0 from "@angular/core";`
*/
dtsDeclarations: Array<DtsDeclaration>
}
export interface Comment {
type: 'Line' | 'Block'
value: string
start: number
end: number
}
export interface ErrorLabel {
message: string | null
start: number
end: number
}
export interface OxcError {
severity: Severity
message: string
labels: Array<ErrorLabel>
helpMessage: string | null
codeframe: string | null
}
export declare const enum Severity {
Error = 'Error',
Warning = 'Warning',
Advice = 'Advice',
}