refactor(compiler): make OutputAst
contain the moduleName, not the filePath (#16832).
The goal of this change is to simplify the emitters, as we will soon create a new one to emit TypeScript nodes directly.
This commit is contained in:

committed by
Chuck Jazdzewski

parent
3b28c75d1f
commit
6123b9c0c6
@ -9,117 +9,129 @@
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, QueryList, Renderer, SecurityContext, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵCodegenComponentFactoryResolver, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵand, ɵccf, ɵcmf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵmod, ɵmpd, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵreflector, ɵregisterModuleFactory, ɵted, ɵunv, ɵvid} from '@angular/core';
|
||||
|
||||
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
||||
import * as o from './output/output_ast';
|
||||
|
||||
const CORE = assetUrl('core');
|
||||
|
||||
export interface IdentifierSpec {
|
||||
name: string;
|
||||
moduleUrl: string;
|
||||
runtime: any;
|
||||
}
|
||||
|
||||
export class Identifiers {
|
||||
static ANALYZE_FOR_ENTRY_COMPONENTS: IdentifierSpec = {
|
||||
static ANALYZE_FOR_ENTRY_COMPONENTS: o.ExternalReference = {
|
||||
name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ANALYZE_FOR_ENTRY_COMPONENTS
|
||||
};
|
||||
static ElementRef: IdentifierSpec = {name: 'ElementRef', moduleUrl: CORE, runtime: ElementRef};
|
||||
static NgModuleRef: IdentifierSpec = {name: 'NgModuleRef', moduleUrl: CORE, runtime: NgModuleRef};
|
||||
static ElementRef:
|
||||
o.ExternalReference = {name: 'ElementRef', moduleName: CORE, runtime: ElementRef};
|
||||
static NgModuleRef:
|
||||
o.ExternalReference = {name: 'NgModuleRef', moduleName: CORE, runtime: NgModuleRef};
|
||||
static ViewContainerRef:
|
||||
IdentifierSpec = {name: 'ViewContainerRef', moduleUrl: CORE, runtime: ViewContainerRef};
|
||||
static ChangeDetectorRef:
|
||||
IdentifierSpec = {name: 'ChangeDetectorRef', moduleUrl: CORE, runtime: ChangeDetectorRef};
|
||||
static QueryList: IdentifierSpec = {name: 'QueryList', moduleUrl: CORE, runtime: QueryList};
|
||||
static TemplateRef: IdentifierSpec = {name: 'TemplateRef', moduleUrl: CORE, runtime: TemplateRef};
|
||||
static CodegenComponentFactoryResolver: IdentifierSpec = {
|
||||
o.ExternalReference = {name: 'ViewContainerRef', moduleName: CORE, runtime: ViewContainerRef};
|
||||
static ChangeDetectorRef: o.ExternalReference = {
|
||||
name: 'ChangeDetectorRef',
|
||||
moduleName: CORE,
|
||||
runtime: ChangeDetectorRef
|
||||
};
|
||||
static QueryList: o.ExternalReference = {name: 'QueryList', moduleName: CORE, runtime: QueryList};
|
||||
static TemplateRef:
|
||||
o.ExternalReference = {name: 'TemplateRef', moduleName: CORE, runtime: TemplateRef};
|
||||
static CodegenComponentFactoryResolver: o.ExternalReference = {
|
||||
name: 'ɵCodegenComponentFactoryResolver',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ɵCodegenComponentFactoryResolver
|
||||
};
|
||||
static ComponentFactoryResolver: IdentifierSpec = {
|
||||
static ComponentFactoryResolver: o.ExternalReference = {
|
||||
name: 'ComponentFactoryResolver',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ComponentFactoryResolver
|
||||
};
|
||||
static ComponentFactory:
|
||||
IdentifierSpec = {name: 'ComponentFactory', moduleUrl: CORE, runtime: ComponentFactory};
|
||||
o.ExternalReference = {name: 'ComponentFactory', moduleName: CORE, runtime: ComponentFactory};
|
||||
static ComponentRef:
|
||||
IdentifierSpec = {name: 'ComponentRef', moduleUrl: CORE, runtime: ComponentRef};
|
||||
o.ExternalReference = {name: 'ComponentRef', moduleName: CORE, runtime: ComponentRef};
|
||||
static NgModuleFactory:
|
||||
IdentifierSpec = {name: 'NgModuleFactory', moduleUrl: CORE, runtime: NgModuleFactory};
|
||||
static createModuleFactory: IdentifierSpec = {
|
||||
o.ExternalReference = {name: 'NgModuleFactory', moduleName: CORE, runtime: NgModuleFactory};
|
||||
static createModuleFactory: o.ExternalReference = {
|
||||
name: 'ɵcmf',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ɵcmf,
|
||||
};
|
||||
static moduleDef: IdentifierSpec = {
|
||||
static moduleDef: o.ExternalReference = {
|
||||
name: 'ɵmod',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ɵmod,
|
||||
};
|
||||
static moduleProviderDef: IdentifierSpec = {
|
||||
static moduleProviderDef: o.ExternalReference = {
|
||||
name: 'ɵmpd',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ɵmpd,
|
||||
};
|
||||
static RegisterModuleFactoryFn: IdentifierSpec = {
|
||||
static RegisterModuleFactoryFn: o.ExternalReference = {
|
||||
name: 'ɵregisterModuleFactory',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ɵregisterModuleFactory,
|
||||
};
|
||||
static Injector: IdentifierSpec = {name: 'Injector', moduleUrl: CORE, runtime: Injector};
|
||||
static ViewEncapsulation:
|
||||
IdentifierSpec = {name: 'ViewEncapsulation', moduleUrl: CORE, runtime: ViewEncapsulation};
|
||||
static ChangeDetectionStrategy: IdentifierSpec = {
|
||||
static Injector: o.ExternalReference = {name: 'Injector', moduleName: CORE, runtime: Injector};
|
||||
static ViewEncapsulation: o.ExternalReference = {
|
||||
name: 'ViewEncapsulation',
|
||||
moduleName: CORE,
|
||||
runtime: ViewEncapsulation
|
||||
};
|
||||
static ChangeDetectionStrategy: o.ExternalReference = {
|
||||
name: 'ChangeDetectionStrategy',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: ChangeDetectionStrategy
|
||||
};
|
||||
static SecurityContext: IdentifierSpec = {
|
||||
static SecurityContext: o.ExternalReference = {
|
||||
name: 'SecurityContext',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
runtime: SecurityContext,
|
||||
};
|
||||
static LOCALE_ID: IdentifierSpec = {name: 'LOCALE_ID', moduleUrl: CORE, runtime: LOCALE_ID};
|
||||
static TRANSLATIONS_FORMAT:
|
||||
IdentifierSpec = {name: 'TRANSLATIONS_FORMAT', moduleUrl: CORE, runtime: TRANSLATIONS_FORMAT};
|
||||
static inlineInterpolate:
|
||||
IdentifierSpec = {name: 'ɵinlineInterpolate', moduleUrl: CORE, runtime: ɵinlineInterpolate};
|
||||
static LOCALE_ID: o.ExternalReference = {name: 'LOCALE_ID', moduleName: CORE, runtime: LOCALE_ID};
|
||||
static TRANSLATIONS_FORMAT: o.ExternalReference = {
|
||||
name: 'TRANSLATIONS_FORMAT',
|
||||
moduleName: CORE,
|
||||
runtime: TRANSLATIONS_FORMAT
|
||||
};
|
||||
static inlineInterpolate: o.ExternalReference = {
|
||||
name: 'ɵinlineInterpolate',
|
||||
moduleName: CORE,
|
||||
runtime: ɵinlineInterpolate
|
||||
};
|
||||
static interpolate:
|
||||
IdentifierSpec = {name: 'ɵinterpolate', moduleUrl: CORE, runtime: ɵinterpolate};
|
||||
o.ExternalReference = {name: 'ɵinterpolate', moduleName: CORE, runtime: ɵinterpolate};
|
||||
static EMPTY_ARRAY:
|
||||
IdentifierSpec = {name: 'ɵEMPTY_ARRAY', moduleUrl: CORE, runtime: ɵEMPTY_ARRAY};
|
||||
static EMPTY_MAP: IdentifierSpec = {name: 'ɵEMPTY_MAP', moduleUrl: CORE, runtime: ɵEMPTY_MAP};
|
||||
static Renderer: IdentifierSpec = {name: 'Renderer', moduleUrl: CORE, runtime: Renderer};
|
||||
static viewDef: IdentifierSpec = {name: 'ɵvid', moduleUrl: CORE, runtime: ɵvid};
|
||||
static elementDef: IdentifierSpec = {name: 'ɵeld', moduleUrl: CORE, runtime: ɵeld};
|
||||
static anchorDef: IdentifierSpec = {name: 'ɵand', moduleUrl: CORE, runtime: ɵand};
|
||||
static textDef: IdentifierSpec = {name: 'ɵted', moduleUrl: CORE, runtime: ɵted};
|
||||
static directiveDef: IdentifierSpec = {name: 'ɵdid', moduleUrl: CORE, runtime: ɵdid};
|
||||
static providerDef: IdentifierSpec = {name: 'ɵprd', moduleUrl: CORE, runtime: ɵprd};
|
||||
static queryDef: IdentifierSpec = {name: 'ɵqud', moduleUrl: CORE, runtime: ɵqud};
|
||||
static pureArrayDef: IdentifierSpec = {name: 'ɵpad', moduleUrl: CORE, runtime: ɵpad};
|
||||
static pureObjectDef: IdentifierSpec = {name: 'ɵpod', moduleUrl: CORE, runtime: ɵpod};
|
||||
static purePipeDef: IdentifierSpec = {name: 'ɵppd', moduleUrl: CORE, runtime: ɵppd};
|
||||
static pipeDef: IdentifierSpec = {name: 'ɵpid', moduleUrl: CORE, runtime: ɵpid};
|
||||
static nodeValue: IdentifierSpec = {name: 'ɵnov', moduleUrl: CORE, runtime: ɵnov};
|
||||
static ngContentDef: IdentifierSpec = {name: 'ɵncd', moduleUrl: CORE, runtime: ɵncd};
|
||||
static unwrapValue: IdentifierSpec = {name: 'ɵunv', moduleUrl: CORE, runtime: ɵunv};
|
||||
static createRendererType2: IdentifierSpec = {name: 'ɵcrt', moduleUrl: CORE, runtime: ɵcrt};
|
||||
static RendererType2: IdentifierSpec = {
|
||||
o.ExternalReference = {name: 'ɵEMPTY_ARRAY', moduleName: CORE, runtime: ɵEMPTY_ARRAY};
|
||||
static EMPTY_MAP:
|
||||
o.ExternalReference = {name: 'ɵEMPTY_MAP', moduleName: CORE, runtime: ɵEMPTY_MAP};
|
||||
static Renderer: o.ExternalReference = {name: 'Renderer', moduleName: CORE, runtime: Renderer};
|
||||
static viewDef: o.ExternalReference = {name: 'ɵvid', moduleName: CORE, runtime: ɵvid};
|
||||
static elementDef: o.ExternalReference = {name: 'ɵeld', moduleName: CORE, runtime: ɵeld};
|
||||
static anchorDef: o.ExternalReference = {name: 'ɵand', moduleName: CORE, runtime: ɵand};
|
||||
static textDef: o.ExternalReference = {name: 'ɵted', moduleName: CORE, runtime: ɵted};
|
||||
static directiveDef: o.ExternalReference = {name: 'ɵdid', moduleName: CORE, runtime: ɵdid};
|
||||
static providerDef: o.ExternalReference = {name: 'ɵprd', moduleName: CORE, runtime: ɵprd};
|
||||
static queryDef: o.ExternalReference = {name: 'ɵqud', moduleName: CORE, runtime: ɵqud};
|
||||
static pureArrayDef: o.ExternalReference = {name: 'ɵpad', moduleName: CORE, runtime: ɵpad};
|
||||
static pureObjectDef: o.ExternalReference = {name: 'ɵpod', moduleName: CORE, runtime: ɵpod};
|
||||
static purePipeDef: o.ExternalReference = {name: 'ɵppd', moduleName: CORE, runtime: ɵppd};
|
||||
static pipeDef: o.ExternalReference = {name: 'ɵpid', moduleName: CORE, runtime: ɵpid};
|
||||
static nodeValue: o.ExternalReference = {name: 'ɵnov', moduleName: CORE, runtime: ɵnov};
|
||||
static ngContentDef: o.ExternalReference = {name: 'ɵncd', moduleName: CORE, runtime: ɵncd};
|
||||
static unwrapValue: o.ExternalReference = {name: 'ɵunv', moduleName: CORE, runtime: ɵunv};
|
||||
static createRendererType2: o.ExternalReference = {name: 'ɵcrt', moduleName: CORE, runtime: ɵcrt};
|
||||
static RendererType2: o.ExternalReference = {
|
||||
name: 'RendererType2',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
// type only
|
||||
runtime: null
|
||||
};
|
||||
static ViewDefinition: IdentifierSpec = {
|
||||
static ViewDefinition: o.ExternalReference = {
|
||||
name: 'ɵViewDefinition',
|
||||
moduleUrl: CORE,
|
||||
moduleName: CORE,
|
||||
// type only
|
||||
runtime: null
|
||||
};
|
||||
static createComponentFactory: IdentifierSpec = {name: 'ɵccf', moduleUrl: CORE, runtime: ɵccf};
|
||||
static createComponentFactory:
|
||||
o.ExternalReference = {name: 'ɵccf', moduleName: CORE, runtime: ɵccf};
|
||||
}
|
||||
|
||||
export function assetUrl(pkg: string, path: string | null = null, type: string = 'src'): string {
|
||||
@ -130,12 +142,12 @@ export function assetUrl(pkg: string, path: string | null = null, type: string =
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveIdentifier(identifier: IdentifierSpec) {
|
||||
export function resolveIdentifier(identifier: o.ExternalReference) {
|
||||
let name = identifier.name;
|
||||
return ɵreflector.resolveIdentifier(name, identifier.moduleUrl, null, identifier.runtime);
|
||||
return ɵreflector.resolveIdentifier(name !, identifier.moduleName !, null, identifier.runtime);
|
||||
}
|
||||
|
||||
export function createIdentifier(identifier: IdentifierSpec): CompileIdentifierMetadata {
|
||||
export function createIdentifier(identifier: o.ExternalReference): CompileIdentifierMetadata {
|
||||
return {reference: resolveIdentifier(identifier)};
|
||||
}
|
||||
|
||||
@ -143,12 +155,12 @@ export function identifierToken(identifier: CompileIdentifierMetadata): CompileT
|
||||
return {identifier: identifier};
|
||||
}
|
||||
|
||||
export function createIdentifierToken(identifier: IdentifierSpec): CompileTokenMetadata {
|
||||
export function createIdentifierToken(identifier: o.ExternalReference): CompileTokenMetadata {
|
||||
return identifierToken(createIdentifier(identifier));
|
||||
}
|
||||
|
||||
export function createEnumIdentifier(
|
||||
enumType: IdentifierSpec, name: string): CompileIdentifierMetadata {
|
||||
enumType: o.ExternalReference, name: string): CompileIdentifierMetadata {
|
||||
const resolvedEnum = ɵreflector.resolveEnum(resolveIdentifier(enumType), name);
|
||||
return {reference: resolvedEnum};
|
||||
}
|
||||
|
Reference in New Issue
Block a user