Repository navigation
Commit 89dd9c6
* fix(metadata): give const enum ctor params `type: undefined`
ngtsc's typeToValue has no value for a const enum outside local
compilation, so full ɵsetClassMetadata and partial
ɵɵngDeclareClassMetadata write `type: undefined` for a constructor
parameter typed by one. oxc wrote the name, which for a
`declare const enum` threw a ReferenceError when JIT or TestBed read it.
- Same file: `const enum`, `declare const enum` and `ns.E` now give
`undefined`. A name a namespace, interface or `declare global` also
declares keeps the reference, and so does a class nested in a function
or block, since one file can't be sure what it means there.
- Imported: with `resolve_imported_values`, a named import the
cross-file analyzer finds to be a const enum (also through
`export { X } from` and `export *`) gives `undefined` and no `i1`
import. The file read becomes a watch dependency. Namespace imports,
packages, .d.ts-only modules and files with a bare namespace keep the
reference.
- Factories and DI tokens are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(metadata): say const enums now give `type: undefined`
The LocalDecls and local-reference comments still listed const enums as
emitted as written.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(ngmodule): leave directives and pipes out of the injector imports
In full and partial compilation ngtsc builds the ɵinj `imports` from what
each reference resolves to (NgModuleDecoratorHandler.resolve): it drops the
directives and pipes of `imports`, and the directives, components and pipes
of `exports`. Oxc copied ngtsc's local compilation and added both lists as
written. The runtime's walkProviderTree skips those entries, so dropping
them does not change which providers are registered.
An entry is dropped only when Oxc knows what it is:
- from this file: an `exports` entry that `declarations` also lists, a
class of the file with an Angular @directive or @pipe decorator (aliases
and namespace imports of the decorator count), and an exported @component
that `imports` or `declarations` also lists;
- with cross-file analysis (resolveImportedValues): imported classes,
`const` lists and package .d.ts types, read through the NgModule scope
code. A list is dropped only when all its classes drop, and an exported
component only when it is in the module's compilation scope.
Anything that does not resolve, an NgModule, a forRoot() call, and a
standalone component in `imports` stay. Classes nested in a function keep
their lists. The files read become watch dependencies like other
cross-file reads.
Not done: ngtsc also drops a standalone component from `imports` when it
brings in no providers, and rewrites a partly dropped list into the
references it keeps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(ngmodule): list the NgModule of ModuleWithProviders imports in partial declarations
In partial mode, ngtsc lists the NgModule each ModuleWithProviders entry
names in the `ɵɵngDeclareNgModule` imports (`resolveTypeList` with
`createModuleWithProvidersResolver`): `imports: [mwp, Holder.forRoot()]`
becomes `imports: [DepModule, DepModule]`. Oxc listed the class the method
is called on (`Holder`) and kept constants as is. When a JIT linker inlines
that list into `ɵɵdefineNgModule`, the runtime got a class that is no
module and a ModuleWithProviders object, which poisons the module scope.
Same file, always on: a static method of a class in this file is read in
ngtsc's order (a body that is a single `return { ngModule: T }` first,
then a `ModuleWithProviders<T>` return type), and top-level constants of
such calls or of `{ ngModule: T }` are followed. T must be a class declared
before the module, or a binding whose import is kept anyway; otherwise the
entry keeps its old output, since a type-only import is removed and a later
class would be read before it exists.
With cross-file analysis (`resolveImportedValues`), a method or constant of
another file is read through ng_module_scope.rs, and the module is named
through a namespace import (`i1.DepModule`), as ngtsc does.
Only the partial declaration changes: the result goes to a separate
`partial_imports` list, so the injector imports and the full-mode
`ɵɵsetNgModuleScope` keep the entries as written. Full output is the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(component): add the forbidOrphanComponents option
ngtsc's `forbidOrphanComponents` compiler option adds
`forbidOrphanRendering: true` to the `ɵsetClassDebugInfo` call of every
component, standalone or not. In dev mode with JIT support the runtime then
throws NG0981 when a non-standalone component is rendered before its NgModule
was loaded. oxc had no way to turn this on.
Add `forbid_orphan_components` to the Rust TransformOptions (default false),
`forbidOrphanComponents` to the napi TransformOptions, and a matching vite
plugin option. Full mode only: partial output has no class debug info, as in
ngtsc. The default output does not change.
Checked against ngtsc 22.2.3 on a file with a non-standalone component, a
standalone component, a directive and a pipe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(compiler): add enableTemplateSourceLocations and rootDirs options
Angular's `enableTemplateSourceLocations` option ends each view's create
block with one `ɵɵattachSourceLocations(path, [[slot, offset, line,
column], ...])` call. oxc had a port of the phase, but it ran whenever
advancedOptimizations was off, made one op per element with 1-based
lines and UTF-8 offsets, and reify threw the ops away.
Now it works like ngtsc full mode:
- off by default; when off the phase does no work and output is the same
- one call per view, at the end of the create block, not chained
- 0-based line and column and UTF-16 offsets, counted like Angular's lexer
cursor in the raw source: from the .ts file start for an inline literal
(escapes sit at their backslash), from the .html start for templateUrl,
and from the template start for any other inline value
- slots come from the element ops' own slots
- only for full compilation (the linker hard-codes it off) and Angular
19.1.0-next.3 or later (or no version given)
The path is project-relative, like ngtsc's getProjectRelativePath, using
a new `root_dirs` option. With no root dirs nothing is emitted (ngtsc
would fall back to rootDir or the working directory, which oxc does not
know). An inline literal whose raw text cannot be mapped (legacy octal
or `\u` surrogate escapes) also emits nothing.
With root dirs set, `ɵsetClassDebugInfo`'s `filePath` is also made
project-relative, and left out for a file outside every root, as
ngtsc's extractClassDebugInfo does. Without root dirs it stays the path
given. oxc never lowercases paths; ngtsc does on a case-insensitive
file system.
The napi TransformOptions gain the same two options
(`enableTemplateSourceLocations`, `rootDirs`).
Refs #623.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(vite): expose enableTemplateSourceLocations and rootDirs
The Vite plugin exposes both options. `rootDirs` defaults to Vite's
resolved `root`, so `ɵsetClassDebugInfo` `filePath` is now relative to
it, as in an ngtsc build, instead of the absolute module id.
The e2e compare runner passes the root dirs that match where ngtsc
compiles each fixture, so `filePath` now matches and the global
DEBUG_INFO_PATH known difference is gone (all 1174 fixtures pass).
Refs #623.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(e2e): list ɵinj's declared-exports filtering as a known difference
The compare oracle runs ngtsc in local mode, which keeps an exported
declaration in ɵinj. A full ngtsc build leaves it out, as Oxc now does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(metadata): count only exported namespace const enums
`NS.E` reads an exported member. A const enum one `namespace NS` block
keeps to itself hid an exported `class E` of another block, so the
class's ctor param lost its type (ngtsc keeps `type: NS.E`).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(ngmodule): keep an MWP entry whose module this file declares later
Another file's ModuleWithProviders<Later> could name a class declared
after the NgModule, and the partial ɵmod then read it before it was
initialized (TDZ ReferenceError). Apply the same-file check: such an
entry keeps today's name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(ngmodule): cover an exported component outside a readable scope
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(vite): default rootDirs to workspaceRoot, like ngtsc's cwd fallback
With Vite's root, a monorepo library outside the app lost filePath and
lineNumber in ɵsetClassDebugInfo. ngtsc falls back to the working
directory (the workspace root). Also list the new options in the README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(compiler): resolve a templateUrl of a bare file name against the working directory
A component file with no directory gave `/./x.html`, a path from the
root, so no source location was emitted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(vite): build the source-location test paths for the running OS
On Windows the plugin resolves `rootDirs` to `D:\proj\src`, which a
bare `/proj/...` module id never matches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(compiler): only unwrap forwardRef imported from @angular/core in cross-file lists
A local function named `forwardRef` may return any class, so a `const`
list built with it could be dropped from ɵinj with its providers. An
aliased `forwardRef` from @angular/core is now read too, as ngtsc does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(compiler): keep a ModuleWithProviders whose ngModule is a member of a parameter
`return { ngModule: modules.X }` reads the call's argument when
`modules` is a parameter, not a namespace import of the same name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(compiler): read a ModuleWithProviders method in ngtsc's order for NgModule scopes
The scope reader read the return type first and took a parameter or a
type parameter for the module. It now uses the reader the partial
imports use. With overloads, both read the first declaration, as ngtsc
does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(compiler): follow a returned call and read the return type when ngtsc can't evaluate a ModuleWithProviders body
ngtsc's evaluator looks only through parentheses, `as` and `!`, gives up
on an object literal with a getter or method, and evaluates a returned
`Class.method()` call. When the body gives no value, it reads the
`ModuleWithProviders<T>` return type. Both the partial imports and the
NgModule scope reader now do the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b179ed1 commit 89dd9c6
33 files changed
Lines changed: 4634 additions & 215 deletions
File tree
- crates/oxc_angular_compiler
- src
- class_metadata
- component
- cross_file_elision
- ir
- ng_module
- pipeline
- phases
- reify
- tests
- napi/angular-compiler
- e2e/compare
- fixtures
- src/compilers
- src
- test
- vite-plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
452 | 459 | | |
453 | 460 | | |
454 | 461 | | |
| |||
464 | 471 | | |
465 | 472 | | |
466 | 473 | | |
| 474 | + | |
467 | 475 | | |
468 | 476 | | |
469 | 477 | | |
| |||
951 | 959 | | |
952 | 960 | | |
953 | 961 | | |
954 | | - | |
955 | | - | |
956 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
957 | 965 | | |
958 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
959 | 974 | | |
960 | 975 | | |
961 | 976 | | |
962 | 977 | | |
963 | 978 | | |
964 | 979 | | |
965 | 980 | | |
| 981 | + | |
966 | 982 | | |
967 | 983 | | |
968 | 984 | | |
| |||
993 | 1009 | | |
994 | 1010 | | |
995 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
996 | 1017 | | |
997 | 1018 | | |
998 | 1019 | | |
| |||
1027 | 1048 | | |
1028 | 1049 | | |
1029 | 1050 | | |
1030 | | - | |
1031 | | - | |
| 1051 | + | |
| 1052 | + | |
1032 | 1053 | | |
1033 | | - | |
| 1054 | + | |
| 1055 | + | |
1034 | 1056 | | |
1035 | 1057 | | |
1036 | 1058 | | |
1037 | | - | |
| 1059 | + | |
1038 | 1060 | | |
1039 | 1061 | | |
1040 | 1062 | | |
| |||
1048 | 1070 | | |
1049 | 1071 | | |
1050 | 1072 | | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1051 | 1093 | | |
1052 | 1094 | | |
1053 | 1095 | | |
| |||
1137 | 1179 | | |
1138 | 1180 | | |
1139 | 1181 | | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
1144 | 1187 | | |
1145 | 1188 | | |
1146 | 1189 | | |
| |||
1156 | 1199 | | |
1157 | 1200 | | |
1158 | 1201 | | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
1159 | 1205 | | |
1160 | 1206 | | |
1161 | 1207 | | |
| |||
1242 | 1288 | | |
1243 | 1289 | | |
1244 | 1290 | | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1245 | 1294 | | |
1246 | 1295 | | |
1247 | 1296 | | |
| |||
1350 | 1399 | | |
1351 | 1400 | | |
1352 | 1401 | | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
1353 | 1405 | | |
1354 | 1406 | | |
1355 | 1407 | | |
| |||
1403 | 1455 | | |
1404 | 1456 | | |
1405 | 1457 | | |
1406 | | - | |
1407 | | - | |
1408 | | - | |
1409 | | - | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
1410 | 1463 | | |
1411 | 1464 | | |
| 1465 | + | |
| 1466 | + | |
1412 | 1467 | | |
1413 | 1468 | | |
| 1469 | + | |
1414 | 1470 | | |
1415 | 1471 | | |
1416 | 1472 | | |
1417 | 1473 | | |
1418 | 1474 | | |
1419 | 1475 | | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
1420 | 1488 | | |
1421 | 1489 | | |
1422 | 1490 | | |
1423 | 1491 | | |
1424 | 1492 | | |
1425 | 1493 | | |
1426 | 1494 | | |
1427 | | - | |
| 1495 | + | |
1428 | 1496 | | |
1429 | 1497 | | |
1430 | 1498 | | |
| |||
1434 | 1502 | | |
1435 | 1503 | | |
1436 | 1504 | | |
| 1505 | + | |
1437 | 1506 | | |
1438 | 1507 | | |
1439 | 1508 | | |
| |||
1460 | 1529 | | |
1461 | 1530 | | |
1462 | 1531 | | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
1463 | 1559 | | |
1464 | 1560 | | |
1465 | 1561 | | |
| |||
0 commit comments