feat(ivy): setup boilerplate for component indexing API (#30961)

Set up the skeleton for a compiler API that indexes components and their
templates on an independent indexing step.

Part of #30959

PR Close #30961
This commit is contained in:
Ayaz Hafiz 2019-06-10 09:19:35 -07:00 committed by Andrew Kushnir
parent a4601eca68
commit 4ad323a4d6
10 changed files with 120 additions and 0 deletions

View File

@ -29,6 +29,7 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/entry_point",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/incremental",
"//packages/compiler-cli/src/ngtsc/indexer",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/path",

View File

@ -0,0 +1,14 @@
load("//tools:defaults.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "indexer",
srcs = ["index.ts"] + glob([
"src/**/*.ts",
]),
deps = [
"//packages/compiler",
"@npm//typescript",
],
)

View File

@ -0,0 +1,10 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export * from './src/api';
export {IndexingContext} from './src/context';

View File

@ -0,0 +1,41 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ParseSourceFile, ParseSpan} from '@angular/compiler';
import * as ts from 'typescript';
/**
* Describes the kind of identifier found in a template.
*/
export enum IdentifierKind {
}
/**
* Describes a semantically-interesting identifier in a template, such as an interpolated variable
* or selector.
*/
export interface TemplateIdentifier {
name: string;
span: ParseSpan;
kind: IdentifierKind;
file: ParseSourceFile;
}
/**
* Describes an analyzed, indexed component and its template.
*/
export interface IndexedComponent {
name: string;
selector: string|null;
sourceFile: string;
content: string;
template: {
identifiers: Set<TemplateIdentifier>,
usedComponents: Set<ts.ClassDeclaration>,
};
}

View File

@ -0,0 +1,13 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* Stores analysis information about components in a compilation for and provides methods for
* querying information about components to be used in indexing.
*/
export class IndexingContext {}

View File

@ -0,0 +1,21 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript';
import {IndexedComponent} from './api';
import {IndexingContext} from './context';
/**
* Generates `IndexedComponent` entries from a `IndexingContext`, which has information
* about components discovered in the program registered in it.
*
* The context must be populated before `generateAnalysis` is called.
*/
export function generateAnalysis(context: IndexingContext): Map<ts.Declaration, IndexedComponent> {
throw new Error('Method not implemented.');
}

View File

@ -19,6 +19,7 @@ import {ErrorCode, ngErrorCode} from './diagnostics';
import {FlatIndexGenerator, ReferenceGraph, checkForPrivateExports, findFlatIndexEntryPoint} from './entry_point';
import {AbsoluteModuleStrategy, AliasGenerator, AliasStrategy, DefaultImportTracker, FileToModuleHost, FileToModuleStrategy, ImportRewriter, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NoopImportRewriter, R3SymbolsImportRewriter, Reference, ReferenceEmitter} from './imports';
import {IncrementalState} from './incremental';
import {IndexedComponent} from './indexer';
import {CompoundMetadataReader, CompoundMetadataRegistry, DtsMetadataReader, LocalMetadataRegistry, MetadataReader} from './metadata';
import {PartialEvaluator} from './partial_evaluator';
import {AbsoluteFsPath, LogicalFileSystem} from './path';
@ -264,6 +265,10 @@ export class NgtscProgram implements api.Program {
return this.routeAnalyzer !.listLazyRoutes(entryRoute);
}
getIndexedComponents(): Map<ts.Declaration, IndexedComponent> {
throw new Error('Method not implemented.');
}
getLibrarySummaries(): Map<string, api.LibrarySummary> {
throw new Error('Method not implemented.');
}

View File

@ -12,6 +12,7 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/incremental",
"//packages/compiler-cli/src/ngtsc/indexer",
"//packages/compiler-cli/src/ngtsc/perf",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/scope",

View File

@ -10,6 +10,7 @@ import {ConstantPool, Expression, Statement, Type} from '@angular/compiler';
import * as ts from 'typescript';
import {Reexport} from '../../imports';
import {IndexingContext} from '../../indexer';
import {ClassDeclaration, Decorator} from '../../reflection';
import {TypeCheckContext} from '../../typecheck';
@ -76,6 +77,13 @@ export interface DecoratorHandler<A, M> {
*/
analyze(node: ClassDeclaration, metadata: M): AnalysisOutput<A>;
/**
* Registers information about the decorator for the indexing phase in a
* `IndexingContext`, which stores information about components discovered in the
* program.
*/
index?(context: IndexingContext, node: ClassDeclaration, metadata: M): void;
/**
* Perform resolution on the given decorator along with the result of analysis.
*

View File

@ -12,6 +12,7 @@ import * as ts from 'typescript';
import {ErrorCode, FatalDiagnosticError} from '../../diagnostics';
import {ImportRewriter} from '../../imports';
import {IncrementalState} from '../../incremental';
import {IndexingContext} from '../../indexer';
import {PerfRecorder} from '../../perf';
import {ClassDeclaration, ReflectionHost, isNamedClassDeclaration, reflectNameOfDeclaration} from '../../reflection';
import {LocalModuleScopeRegistry} from '../../scope';
@ -250,6 +251,11 @@ export class IvyCompilation {
}
}
/**
* Feeds components discovered in the compilation to a context for indexing.
*/
index(context: IndexingContext) { throw new Error('Method not implemented.'); }
resolve(): void {
const resolveSpan = this.perf.start('resolve');
this.ivyClasses.forEach((ivyClass, node) => {