Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(compiler-cli): remove listLazyRoutes operation
Now that `Route.loadChildren` no longer accepts a string, there is no
need for tooling to find all string-based `loadChildren` to setup lazy
imports for them. As a result, the `listLazyRoutes` operation that
enumerates all string-based `loadChildren` occurrences is no longer
needed and is therefore removed from the compiler.

The `listLazyRoutes` API remains on the `Program` interface to avoid
breaking external tools that may be using this method, but those tools
should ultimately move away from using this API.
  • Loading branch information
JoostK authored and atscott committed Sep 29, 2021
commit 04fb36924f6c181a1161dfeb69f0c88046303c04
4 changes: 0 additions & 4 deletions goldens/circular-deps/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
"packages/compiler-cli/src/ngtsc/partial_evaluator/src/interface.ts",
"packages/compiler-cli/src/ngtsc/partial_evaluator/src/interpreter.ts"
],
[
"packages/compiler-cli/src/ngtsc/routing/src/analyzer.ts",
"packages/compiler-cli/src/ngtsc/routing/src/lazy.ts"
],
[
"packages/compiler-cli/src/ngtsc/scope/src/component_scope.ts",
"packages/compiler-cli/src/ngtsc/scope/src/local.ts"
Expand Down
87 changes: 0 additions & 87 deletions packages/compiler-cli/integrationtest/test/test_ngtools_api.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/compiler-cli/integrationtest/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
"src/module",
"src/bootstrap",
"test/all_spec",
"test/test_ngtools_api"
]
}
1 change: 0 additions & 1 deletion packages/compiler-cli/integrationtest/tsconfig-xi18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
"src/module",
"src/bootstrap",
"test/all_spec",
"test/test_ngtools_api"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ export class DecorationAnalyzer {
/* errorOnDuplicateProv */ false),
new NgModuleDecoratorHandler(
this.reflectionHost, this.evaluator, this.fullMetaReader, this.fullRegistry,
this.scopeRegistry, this.referencesRegistry, this.isCore, /* routeAnalyzer */ null,
this.refEmitter,
this.scopeRegistry, this.referencesRegistry, this.isCore, this.refEmitter,
/* factoryTracker */ null, !!this.compilerOptions.annotateForClosureCompiler,
this.injectableRegistry, NOOP_PERF_RECORDER),
];
Expand Down
1 change: 0 additions & 1 deletion packages/compiler-cli/src/ngtsc/annotations/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/perf",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/routing",
"//packages/compiler-cli/src/ngtsc/scope",
"//packages/compiler-cli/src/ngtsc/shims:api",
"//packages/compiler-cli/src/ngtsc/transform",
Expand Down
15 changes: 4 additions & 11 deletions packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {InjectableClassRegistry, MetadataReader, MetadataRegistry} from '../../m
import {PartialEvaluator, ResolvedValue} from '../../partial_evaluator';
import {PerfEvent, PerfRecorder} from '../../perf';
import {ClassDeclaration, Decorator, isNamedClassDeclaration, ReflectionHost, reflectObjectLiteral, typeNodeToValueExpr} from '../../reflection';
import {NgModuleRouteAnalyzer} from '../../routing';
import {LocalModuleScopeRegistry, ScopeData} from '../../scope';
import {FactoryTracker} from '../../shims/api';
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence, ResolveResult} from '../../transform';
Expand Down Expand Up @@ -129,8 +128,8 @@ export class NgModuleDecoratorHandler implements
private metaReader: MetadataReader, private metaRegistry: MetadataRegistry,
private scopeRegistry: LocalModuleScopeRegistry,
private referencesRegistry: ReferencesRegistry, private isCore: boolean,
private routeAnalyzer: NgModuleRouteAnalyzer|null, private refEmitter: ReferenceEmitter,
private factoryTracker: FactoryTracker|null, private annotateForClosureCompiler: boolean,
private refEmitter: ReferenceEmitter, private factoryTracker: FactoryTracker|null,
private annotateForClosureCompiler: boolean,
private injectableRegistry: InjectableClassRegistry, private perf: PerfRecorder,
private localeId?: string) {}

Expand Down Expand Up @@ -218,16 +217,14 @@ export class NgModuleDecoratorHandler implements
}

let importRefs: Reference<ClassDeclaration>[] = [];
let rawImports: ts.Expression|null = null;
if (ngModule.has('imports')) {
rawImports = ngModule.get('imports')!;
const rawImports = ngModule.get('imports')!;
const importsMeta = this.evaluator.evaluate(rawImports, moduleResolvers);
importRefs = this.resolveTypeList(rawImports, importsMeta, name, 'imports');
}
let exportRefs: Reference<ClassDeclaration>[] = [];
let rawExports: ts.Expression|null = null;
if (ngModule.has('exports')) {
rawExports = ngModule.get('exports')!;
const rawExports = ngModule.get('exports')!;
const exportsMeta = this.evaluator.evaluate(rawExports, moduleResolvers);
exportRefs = this.resolveTypeList(rawExports, exportsMeta, name, 'exports');
this.referencesRegistry.add(node, ...exportRefs);
Expand Down Expand Up @@ -331,10 +328,6 @@ export class NgModuleDecoratorHandler implements
injectorImports.push(new WrappedNodeExpr(ngModule.get('imports')!));
}

if (this.routeAnalyzer !== null) {
this.routeAnalyzer.add(node.getSourceFile(), name, rawImports, rawExports, rawProviders);
}

const injectorMetadata: R3InjectorMetadata = {
name,
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ runInEachFileSystem(() => {

const handler = new NgModuleDecoratorHandler(
reflectionHost, evaluator, metaReader, metaRegistry, scopeRegistry, referencesRegistry,
/* isCore */ false, /* routeAnalyzer */ null, refEmitter, /* factoryTracker */ null,
/* isCore */ false, refEmitter, /* factoryTracker */ null,
/* annotateForClosureCompiler */ false, injectableRegistry, NOOP_PERF_RECORDER);
const TestModule =
getDeclaration(program, _('/entry.ts'), 'TestModule', isNamedClassDeclaration);
Expand Down
1 change: 0 additions & 1 deletion packages/compiler-cli/src/ngtsc/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/program_driver",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/resource",
"//packages/compiler-cli/src/ngtsc/routing",
"//packages/compiler-cli/src/ngtsc/scope",
"//packages/compiler-cli/src/ngtsc/shims",
"//packages/compiler-cli/src/ngtsc/shims:api",
Expand Down
6 changes: 0 additions & 6 deletions packages/compiler-cli/src/ngtsc/core/api/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,3 @@ export interface TransformResourceResult {
*/
export interface ExtendedTsCompilerHost extends ts.CompilerHost, Partial<ResourceHost>,
Partial<UnifiedModulesHost> {}

export interface LazyRoute {
route: string;
module: {name: string, filePath: string};
referencedModule: {name: string, filePath: string};
}
54 changes: 4 additions & 50 deletions packages/compiler-cli/src/ngtsc/core/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {ActivePerfRecorder, DelegatingPerfRecorder, PerfCheckpoint, PerfEvent, P
import {FileUpdate, ProgramDriver, UpdateMode} from '../../program_driver';
import {DeclarationNode, isNamedClassDeclaration, TypeScriptReflectionHost} from '../../reflection';
import {AdapterResourceLoader} from '../../resource';
import {entryPointKeyFor, NgModuleRouteAnalyzer} from '../../routing';
import {ComponentScopeReader, LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver, TypeCheckScopeRegistry} from '../../scope';
import {generatedFactoryTransform} from '../../shims';
import {ivySwitchTransform} from '../../switch';
Expand All @@ -34,9 +33,9 @@ import {ExtendedTemplateCheckerImpl} from '../../typecheck/extended';
import {ExtendedTemplateChecker, TemplateCheck} from '../../typecheck/extended/api';
import {InvalidBananaInBoxCheck} from '../../typecheck/extended/checks/invalid_banana_in_box';
import {NullishCoalescingNotNullableCheck} from '../../typecheck/extended/checks/nullish_coalescing_not_nullable';
import {getSourceFileOrNull, isDtsPath, resolveModuleName, toUnredirectedSourceFile} from '../../util/src/typescript';
import {getSourceFileOrNull, isDtsPath, toUnredirectedSourceFile} from '../../util/src/typescript';
import {Xi18nContext} from '../../xi18n';
import {LazyRoute, NgCompilerAdapter, NgCompilerOptions} from '../api';
import {NgCompilerAdapter, NgCompilerOptions} from '../api';

/**
* State information about a compilation which is only generated once some data is requested from
Expand All @@ -50,7 +49,6 @@ interface LazyCompilationState {
scopeRegistry: LocalModuleScopeRegistry;
typeCheckScopeRegistry: TypeCheckScopeRegistry;
exportReferenceGraph: ReferenceGraph|null;
routeAnalyzer: NgModuleRouteAnalyzer;
dtsTransforms: DtsTransformRegistry;
aliasingHost: AliasingHost|null;
refEmitter: ReferenceEmitter;
Expand Down Expand Up @@ -607,47 +605,6 @@ export class NgCompiler {
});
}

/**
* List lazy routes detected during analysis.
*
* This can be called for one specific route, or to retrieve all top-level routes.
*/
listLazyRoutes(entryRoute?: string): LazyRoute[] {
if (entryRoute) {
// htts://github.com/angular/angular/blob/50732e156/packages/compiler-cli/src/transformers/compiler_host.ts#L175-L188).
//
// `@angular/cli` will always call this API with an absolute path, so the resolution step is
// not necessary, but keeping it backwards compatible in case someone else is using the API.

// Relative entry paths are disallowed.
if (entryRoute.startsWith('.')) {
throw new Error(`Failed to list lazy routes: Resolution of relative paths (${
entryRoute}) is not supported.`);
}

// Non-relative entry paths fall into one of the following categories:
// - Absolute system paths (e.g. `/foo/bar/my-project/my-module`), which are unaffected by the
// logic below.
// - Paths to enternal modules (e.g. `some-lib`).
// - Paths mapped to directories in `tsconfig.json` (e.g. `shared/my-module`).
// (See https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping.)
//
// In all cases above, the `containingFile` argument is ignored, so we can just take the first
// of the root files.
const containingFile = this.inputProgram.getRootFileNames()[0];
const [entryPath, moduleName] = entryRoute.split('#');
const resolvedModule =
resolveModuleName(entryPath, containingFile, this.options, this.adapter, null);

if (resolvedModule) {
entryRoute = entryPointKeyFor(resolvedModule.resolvedFileName, moduleName);
}
}

const compilation = this.ensureAnalyzed();
return compilation.routeAnalyzer.listLazyRoutes(entryRoute);
}

/**
* Fetch transformers and other information which is necessary for a consumer to `emit` the
* program with Angular-added definitions.
Expand Down Expand Up @@ -1037,8 +994,6 @@ export class NgCompiler {
referencesRegistry = new NoopReferencesRegistry();
}

const routeAnalyzer = new NgModuleRouteAnalyzer(this.moduleResolver, evaluator);

const dtsTransforms = new DtsTransformRegistry();

const isCore = isAngularCorePackage(this.inputProgram);
Expand Down Expand Up @@ -1088,8 +1043,8 @@ export class NgCompiler {
this.delegatingPerfRecorder),
new NgModuleDecoratorHandler(
reflector, evaluator, metaReader, metaRegistry, scopeRegistry, referencesRegistry, isCore,
routeAnalyzer, refEmitter, this.adapter.factoryTracker, this.closureCompilerEnabled,
injectableRegistry, this.delegatingPerfRecorder, this.options.i18nInLocale),
refEmitter, this.adapter.factoryTracker, this.closureCompilerEnabled, injectableRegistry,
this.delegatingPerfRecorder, this.options.i18nInLocale),
];

const traitCompiler = new TraitCompiler(
Expand Down Expand Up @@ -1124,7 +1079,6 @@ export class NgCompiler {
scopeRegistry,
dtsTransforms,
exportReferenceGraph,
routeAnalyzer,
metaReader,
typeCheckScopeRegistry,
aliasingHost,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/ngtsc/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class NgtscProgram implements api.Program {
}

listLazyRoutes(entryRoute?: string|undefined): api.LazyRoute[] {
return this.compiler.listLazyRoutes(entryRoute);
return [];
}

private emitXi18n(): void {
Expand Down
18 changes: 0 additions & 18 deletions packages/compiler-cli/src/ngtsc/routing/BUILD.bazel

This file was deleted.

12 changes: 0 additions & 12 deletions packages/compiler-cli/src/ngtsc/routing/index.ts

This file was deleted.

Loading