Skip to content

Commit 8838b9f

Browse files
Brooooooklynclaude
andauthored
fix(partial): give NgModule components their scope (#655) (#665)
* fix(partial): give NgModule components their scope (#655) A partial declaration of a component an NgModule declares had no dependencies, so after linking it had no directives or pipes. The NgModule's file now calls ɵɵsetComponentScope for each component it declares, with the module's compilation scope read across files (source @NgModule decorators and .d.ts ɵmod types). A standalone component that imports an NgModule now lists the module's exported directives and pipes. Partial declarations also carry a real version (the target Angular version, else 22.2.3) instead of 0.0.0-PLACEHOLDER, which Angular's published linker reads as 0.0.0 and so turns off block syntax. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(partial): run NgModule scopes after the file, list each class once - Set component scopes at the end of the module's file with `() => [...]` lists, and skip a component whose file imports the module's file back. - A standalone component lists a class an imported NgModule exports once, by declaration, not by name. - Look up each `(file, name)` once per export search, so `export *` cycles end in linear time. - Import a workspace library class by path when its entry point doesn't export it. - Emit `isStandalone: true` for a linker before v19, which reads a missing field as `false`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(partial): find import cycles through barrels and namespace re-exports - Skip a component when the file its scope call imports it from loads the module file back, not only the file that declares it. - Follow `export * as ns from`, and not type-only imports and re-exports, when looking for a cycle. - List a module's classes as seen only once its list is kept: a module with a pipe of no static name no longer hides them from later ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(partial): read a module's later-declared exports through forwardRef A class an imported NgModule exports that the file declares after the standalone component is listed as `forwardRef(() => X)`, as ngtsc does, so creating the component's definition doesn't read it too early. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(partial): match the compiled file's path to the resolver's on Windows `canonicalize` gives the compiled file a `\\?\` path, which the resolver's paths don't have, so an import cycle back to it was never found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(partial): read imported scope classes in a cycle through forwardRef - A class an imported NgModule exports, whose file loads the standalone component's file back, is listed as `forwardRef(() => i1.X)`: the component's definition can be created before that file has run. - Name a class imported by path from an `.mts`/`.cts` file by the `.mjs` /`.cjs` file TypeScript writes for it. - Compare canonical paths when looking for a cycle: a path through a tsconfig alias can be spelled differently, as Windows short names are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b14c575 commit 8838b9f

36 files changed

Lines changed: 2794 additions & 172 deletions

‎crates/oxc_angular_compiler/src/component/cross_file_elision.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
3232
use super::defer_resolver::{ClassUse, decorated_class_selector};
3333
use crate::directive::{ImportValueResolver, StringConsts};
3434

35+
mod ng_module_scope;
36+
3537
/// `(file, exported_name, local_name, implicit_standalone)` -> how a
3638
/// template uses the class (see `Inner::selector_memo`).
3739
type SelectorMemo = FxHashMap<(String, String, String, bool), Option<ClassUse>>;
@@ -102,6 +104,8 @@ struct Inner {
102104
/// Handle to this state, for the resolvers of the files in `parsed`
103105
/// (`parse_file` only sees `&self`).
104106
this: Weak<Inner>,
107+
/// Memoized NgModule scope reads (see [`ng_module_scope`]).
108+
scope: ng_module_scope::ScopeState,
105109
}
106110

107111
/// A file parsed once per analyzer: its program, and the consts the
@@ -250,6 +254,7 @@ impl CrossFileAnalyzer {
250254
evaluating_values: RefCell::new(FxHashSet::default()),
251255
value_dependencies: RefCell::new(FxHashSet::default()),
252256
this: this.clone(),
257+
scope: ng_module_scope::ScopeState::default(),
253258
}),
254259
}
255260
}

0 commit comments

Comments
 (0)