Skip to content

Commit dbffdc0

Browse files
devversionthePunderWoman
authored andcommitted
fix(core): avoid duplicated code between entry-points (primary, testing, rxjs-interop) (#51500)
Fixes that there was code duplication between the primary entry-point, the testing entry-point and the rxjs-interop entry-point. This code duplication resulted in additional code size (really neglibible here because rxjs-interop did not duplicate large parts of core, and `testing` is not used in production). On the other hand though, the duplication resulted in a subtle JIT dependency tracking issue due to the `depsTracker` no longer being a singleton. This caused test failures as in: #51415. PR Close #51500
1 parent 9aa71cc commit dbffdc0

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

packages/core/rxjs-interop/src/to_signal.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertInInjectionContext, computed, DestroyRef, inject, Injector, signal, Signal, WritableSignal} from '@angular/core';
9+
import {assertInInjectionContext, computed, DestroyRef, inject, Injector, signal, Signal, untracked, WritableSignal, ɵRuntimeError, ɵRuntimeErrorCode} from '@angular/core';
1010
import {Observable, Subscribable} from 'rxjs';
1111

12-
import {RuntimeError, RuntimeErrorCode} from '../../src/errors';
13-
import {untracked} from '../../src/signals';
14-
1512
/**
1613
* Options for `toSignal`.
1714
*
@@ -186,8 +183,8 @@ export function toSignal<T, U = undefined>(
186183
});
187184

188185
if (ngDevMode && options?.requireSync && untracked(state).kind === StateKind.NoValue) {
189-
throw new RuntimeError(
190-
RuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
186+
throw new ɵRuntimeError(
187+
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
191188
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.');
192189
}
193190

@@ -206,8 +203,8 @@ export function toSignal<T, U = undefined>(
206203
case StateKind.NoValue:
207204
// This shouldn't really happen because the error is thrown on creation.
208205
// TODO(alxhub): use a RuntimeError when we finalize the error semantics
209-
throw new RuntimeError(
210-
RuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
206+
throw new ɵRuntimeError(
207+
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
211208
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.');
212209
}
213210
});

packages/core/src/core_private_export.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {getInjectableDef as ɵgetInjectableDef, ɵɵInjectableDeclaration, ɵɵI
1515
export {InternalEnvironmentProviders as ɵInternalEnvironmentProviders, isEnvironmentProviders as ɵisEnvironmentProviders} from './di/interface/provider';
1616
export {INJECTOR_SCOPE as ɵINJECTOR_SCOPE} from './di/scope';
1717
export {XSS_SECURITY_URL as ɵXSS_SECURITY_URL} from './error_details_base_url';
18-
export {formatRuntimeError as ɵformatRuntimeError, RuntimeError as ɵRuntimeError} from './errors';
18+
export {formatRuntimeError as ɵformatRuntimeError, RuntimeError as ɵRuntimeError, RuntimeErrorCode as ɵRuntimeErrorCode} from './errors';
1919
export {annotateForHydration as ɵannotateForHydration} from './hydration/annotate';
2020
export {withDomHydration as ɵwithDomHydration} from './hydration/api';
2121
export {IS_HYDRATION_DOM_REUSE_ENABLED as ɵIS_HYDRATION_DOM_REUSE_ENABLED} from './hydration/tokens';
@@ -24,7 +24,7 @@ export {CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleD
2424
export {DEFAULT_LOCALE_ID as ɵDEFAULT_LOCALE_ID} from './i18n/localization';
2525
export {InitialRenderPendingTasks as ɵInitialRenderPendingTasks} from './initial_render_pending_tasks';
2626
export {ComponentFactory as ɵComponentFactory} from './linker/component_factory';
27-
export {clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponentResourcesQueue, resolveComponentResources as ɵresolveComponentResources} from './metadata/resource_loading';
27+
export {clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution as ɵisComponentDefPendingResolution, resolveComponentResources as ɵresolveComponentResources, restoreComponentResolutionQueue as ɵrestoreComponentResolutionQueue} from './metadata/resource_loading';
2828
export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/reflection_capabilities';
2929
export {InjectorProfilerContext as ɵInjectorProfilerContext, setInjectorProfilerContext as ɵsetInjectorProfilerContext} from './render3/debug/injector_profiler';
3030
export {allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, BypassType as ɵBypassType, getSanitizationBypassType as ɵgetSanitizationBypassType, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue, unwrapSafeValue as ɵunwrapSafeValue} from './sanitization/bypass';

packages/core/src/core_render3_private_export.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,8 @@ export {
307307
noSideEffects as ɵnoSideEffects,
308308
} from './util/closure';
309309
export { AfterRenderEventManager as ɵAfterRenderEventManager } from './render3/after_render_hooks';
310+
export {depsTracker as ɵdepsTracker, USE_RUNTIME_DEPS_TRACKER_FOR_JIT as ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT} from './render3/deps_tracker/deps_tracker';
311+
export {generateStandaloneInDeclarationsError as ɵgenerateStandaloneInDeclarationsError} from './render3/jit/module';
312+
export {getAsyncClassMetadata as ɵgetAsyncClassMetadata} from './render3/metadata';
310313

311314
// clang-format on

packages/core/testing/src/test_bed.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
Type,
2828
ɵconvertToBitFlags as convertToBitFlags,
2929
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible,
30+
ɵgetAsyncClassMetadata as getAsyncClassMetadata,
3031
ɵgetUnknownElementStrictMode as getUnknownElementStrictMode,
3132
ɵgetUnknownPropertyStrictMode as getUnknownPropertyStrictMode,
3233
ɵRender3ComponentFactory as ComponentFactory,
@@ -35,13 +36,12 @@ import {
3536
ɵsetAllowDuplicateNgModuleIdsForTest as setAllowDuplicateNgModuleIdsForTest,
3637
ɵsetUnknownElementStrictMode as setUnknownElementStrictMode,
3738
ɵsetUnknownPropertyStrictMode as setUnknownPropertyStrictMode,
38-
ɵstringify as stringify
39-
} from '@angular/core';
40-
41-
import { getAsyncClassMetadata } from '../../src/render3/metadata';
39+
ɵstringify as stringify} from '@angular/core';
4240

4341
/* clang-format on */
4442

43+
44+
4545
import {ComponentFixture} from './component_fixture';
4646
import {MetadataOverride} from './metadata_override';
4747
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, ModuleTeardownOptions, TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, TestComponentRenderer, TestEnvironmentOptions, TestModuleMetadata, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from './test_bed_common';

packages/core/testing/src/test_bed_compiler.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
*/
88

99
import {ResourceLoader} from '@angular/compiler';
10-
import {ApplicationInitStatus, Compiler, COMPILER_OPTIONS, Component, Directive, Injector, InjectorType, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, provideZoneChangeDetection, resolveForwardRef, StaticProvider, Type, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵgetInjectableDef as getInjectableDef, ɵInternalEnvironmentProviders as InternalEnvironmentProviders, ɵisEnvironmentProviders as isEnvironmentProviders, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJ_DEF as NG_INJ_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDeclaration as InjectableDeclaration} from '@angular/core';
10+
import {ApplicationInitStatus, Compiler, COMPILER_OPTIONS, Component, Directive, Injector, InjectorType, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, provideZoneChangeDetection, resolveForwardRef, StaticProvider, Type, ɵclearResolutionOfComponentResourcesQueue, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵdepsTracker as depsTracker, ɵDirectiveDef as DirectiveDef, ɵgenerateStandaloneInDeclarationsError, ɵgetAsyncClassMetadata as getAsyncClassMetadata, ɵgetInjectableDef as getInjectableDef, ɵInternalEnvironmentProviders as InternalEnvironmentProviders, ɵisComponentDefPendingResolution, ɵisEnvironmentProviders as isEnvironmentProviders, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJ_DEF as NG_INJ_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵresolveComponentResources, ɵrestoreComponentResolutionQueue, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵUSE_RUNTIME_DEPS_TRACKER_FOR_JIT as USE_RUNTIME_DEPS_TRACKER_FOR_JIT, ɵɵInjectableDeclaration as InjectableDeclaration} from '@angular/core';
1111

12-
import {clearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution, resolveComponentResources, restoreComponentResolutionQueue} from '../../src/metadata/resource_loading';
1312
import {ComponentDef, ComponentType} from '../../src/render3';
14-
import {depsTracker, USE_RUNTIME_DEPS_TRACKER_FOR_JIT} from '../../src/render3/deps_tracker/deps_tracker';
15-
import {generateStandaloneInDeclarationsError} from '../../src/render3/jit/module';
16-
import {getAsyncClassMetadata} from '../../src/render3/metadata';
1713

1814
import {MetadataOverride} from './metadata_override';
1915
import {ComponentResolver, DirectiveResolver, NgModuleResolver, PipeResolver, Resolver} from './resolvers';
@@ -35,7 +31,7 @@ function assertNoStandaloneComponents(
3531
if (!getAsyncClassMetadata(type)) {
3632
const component = resolver.resolve(type);
3733
if (component && component.standalone) {
38-
throw new Error(generateStandaloneInDeclarationsError(type, location));
34+
throw new Error(ɵgenerateStandaloneInDeclarationsError(type, location));
3935
}
4036
}
4137
});
@@ -236,7 +232,7 @@ export class TestBedCompiler {
236232
const metadata = this.resolvers.component.resolve(type)! as Component;
237233
return !!metadata.styleUrls && metadata.styleUrls.length > 0;
238234
};
239-
const overrideStyleUrls = !!def && !isComponentDefPendingResolution(type) && hasStyleUrls();
235+
const overrideStyleUrls = !!def && !ɵisComponentDefPendingResolution(type) && hasStyleUrls();
240236

241237
// In Ivy, compiling a component does not require knowing the module providing the
242238
// component's scope, so overrideTemplateUsingTestingModule can be implemented purely via
@@ -298,7 +294,7 @@ export class TestBedCompiler {
298294
}
299295
return Promise.resolve(resourceLoader.get(url));
300296
};
301-
await resolveComponentResources(resolver);
297+
await ɵresolveComponentResources(resolver);
302298
}
303299
}
304300

@@ -387,7 +383,7 @@ export class TestBedCompiler {
387383
`Please call \`await TestBed.compileComponents()\` before running this test.`);
388384
}
389385

390-
needsAsyncResources = needsAsyncResources || isComponentDefPendingResolution(declaration);
386+
needsAsyncResources = needsAsyncResources || ɵisComponentDefPendingResolution(declaration);
391387

392388
const metadata = this.resolvers.component.resolve(declaration);
393389
if (metadata === null) {
@@ -580,7 +576,7 @@ export class TestBedCompiler {
580576
// Check whether a give Type has respective NG def (ɵcmp) and compile if def is
581577
// missing. That might happen in case a class without any Angular decorators extends another
582578
// class where Component/Directive/Pipe decorator is defined.
583-
if (isComponentDefPendingResolution(type) || !type.hasOwnProperty(NG_COMP_DEF)) {
579+
if (ɵisComponentDefPendingResolution(type) || !type.hasOwnProperty(NG_COMP_DEF)) {
584580
this.pendingComponents.add(type);
585581
}
586582
this.seenComponents.add(type);
@@ -748,7 +744,7 @@ export class TestBedCompiler {
748744
if (this.originalComponentResolutionQueue === null) {
749745
this.originalComponentResolutionQueue = new Map();
750746
}
751-
clearResolutionOfComponentResourcesQueue().forEach(
747+
ɵclearResolutionOfComponentResourcesQueue().forEach(
752748
(value, key) => this.originalComponentResolutionQueue!.set(key, value));
753749
}
754750

@@ -759,7 +755,7 @@ export class TestBedCompiler {
759755
*/
760756
private restoreComponentResolutionQueue() {
761757
if (this.originalComponentResolutionQueue !== null) {
762-
restoreComponentResolutionQueue(this.originalComponentResolutionQueue);
758+
ɵrestoreComponentResolutionQueue(this.originalComponentResolutionQueue);
763759
this.originalComponentResolutionQueue = null;
764760
}
765761
}

0 commit comments

Comments
 (0)