refactor(compiler): move `static_reflector` into `@angular/compiler` and rename files
- `src/runtime_compiler.ts` -> `src/jit/compiler.ts` - `src/compiler.ts` -> `src/jit/compiler_factory.ts` - `src/offline_compiler` -> `src/aot/compiler.ts` Part of #12867
This commit is contained in:
parent
664a6273e1
commit
912ca44979
|
@ -50,6 +50,7 @@ module.exports = function(config) {
|
||||||
'dist/all/@angular/**/e2e_test/**',
|
'dist/all/@angular/**/e2e_test/**',
|
||||||
'dist/all/@angular/router/**',
|
'dist/all/@angular/router/**',
|
||||||
'dist/all/@angular/compiler-cli/**',
|
'dist/all/@angular/compiler-cli/**',
|
||||||
|
'dist/all/@angular/compiler/test/aot/**',
|
||||||
'dist/all/@angular/benchpress/**',
|
'dist/all/@angular/benchpress/**',
|
||||||
'dist/all/angular1_router.js',
|
'dist/all/angular1_router.js',
|
||||||
'dist/all/@angular/platform-browser/testing/e2e_util.js',
|
'dist/all/@angular/platform-browser/testing/e2e_util.js',
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler';
|
||||||
export {CodeGenerator} from './src/codegen';
|
export {CodeGenerator} from './src/codegen';
|
||||||
export {Extractor} from './src/extractor';
|
export {Extractor} from './src/extractor';
|
||||||
export {NodeReflectorHostContext, ReflectorHost, ReflectorHostContext} from './src/reflector_host';
|
export {NodeReflectorHostContext, ReflectorHost, ReflectorHostContext} from './src/reflector_host';
|
||||||
export {StaticReflector, StaticReflectorHost, StaticSymbol} from './src/static_reflector';
|
|
||||||
|
|
||||||
export * from '@angular/tsc-wrapped';
|
export * from '@angular/tsc-wrapped';
|
||||||
|
|
|
@ -20,8 +20,6 @@ import * as ts from 'typescript';
|
||||||
import {PathMappedReflectorHost} from './path_mapped_reflector_host';
|
import {PathMappedReflectorHost} from './path_mapped_reflector_host';
|
||||||
import {Console} from './private_import_core';
|
import {Console} from './private_import_core';
|
||||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
|
||||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector';
|
|
||||||
|
|
||||||
const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
|
const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
|
||||||
const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
|
const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
|
||||||
|
@ -38,8 +36,9 @@ const PREAMBLE = `/**
|
||||||
export class CodeGenerator {
|
export class CodeGenerator {
|
||||||
constructor(
|
constructor(
|
||||||
private options: AngularCompilerOptions, private program: ts.Program,
|
private options: AngularCompilerOptions, private program: ts.Program,
|
||||||
public host: ts.CompilerHost, private staticReflector: StaticReflector,
|
public host: ts.CompilerHost, private staticReflector: compiler.StaticReflector,
|
||||||
private compiler: compiler.OfflineCompiler, private reflectorHost: StaticReflectorHost) {}
|
private compiler: compiler.AotCompiler, private reflectorHost: compiler.StaticReflectorHost) {
|
||||||
|
}
|
||||||
|
|
||||||
// Write codegen in a directory structure matching the sources.
|
// Write codegen in a directory structure matching the sources.
|
||||||
private calculateEmitPath(filePath: string): string {
|
private calculateEmitPath(filePath: string): string {
|
||||||
|
@ -109,8 +108,8 @@ export class CodeGenerator {
|
||||||
new PathMappedReflectorHost(program, compilerHost, options, reflectorHostContext) :
|
new PathMappedReflectorHost(program, compilerHost, options, reflectorHostContext) :
|
||||||
new ReflectorHost(program, compilerHost, options, reflectorHostContext);
|
new ReflectorHost(program, compilerHost, options, reflectorHostContext);
|
||||||
}
|
}
|
||||||
const staticReflector = new StaticReflector(reflectorHost);
|
const staticReflector = new compiler.StaticReflector(reflectorHost);
|
||||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
compiler.StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||||
const htmlParser =
|
const htmlParser =
|
||||||
new compiler.I18NHtmlParser(new compiler.HtmlParser(), transContent, cliOptions.i18nFormat);
|
new compiler.I18NHtmlParser(new compiler.HtmlParser(), transContent, cliOptions.i18nFormat);
|
||||||
const config = new compiler.CompilerConfig({
|
const config = new compiler.CompilerConfig({
|
||||||
|
@ -131,7 +130,7 @@ export class CodeGenerator {
|
||||||
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
||||||
elementSchemaRegistry, normalizer, staticReflector);
|
elementSchemaRegistry, normalizer, staticReflector);
|
||||||
// TODO(vicb): do not pass cliOptions.i18nFormat here
|
// TODO(vicb): do not pass cliOptions.i18nFormat here
|
||||||
const offlineCompiler = new compiler.OfflineCompiler(
|
const aotCompiler = new compiler.AotCompiler(
|
||||||
resolver, tmplParser, new compiler.StyleCompiler(urlResolver),
|
resolver, tmplParser, new compiler.StyleCompiler(urlResolver),
|
||||||
new compiler.ViewCompiler(config, elementSchemaRegistry),
|
new compiler.ViewCompiler(config, elementSchemaRegistry),
|
||||||
new compiler.DirectiveWrapperCompiler(
|
new compiler.DirectiveWrapperCompiler(
|
||||||
|
@ -141,18 +140,19 @@ export class CodeGenerator {
|
||||||
new compiler.AnimationParser(elementSchemaRegistry));
|
new compiler.AnimationParser(elementSchemaRegistry));
|
||||||
|
|
||||||
return new CodeGenerator(
|
return new CodeGenerator(
|
||||||
options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);
|
options, program, compilerHost, staticReflector, aotCompiler, reflectorHost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractProgramSymbols(
|
export function extractProgramSymbols(
|
||||||
program: ts.Program, staticReflector: StaticReflector, reflectorHost: StaticReflectorHost,
|
program: ts.Program, staticReflector: compiler.StaticReflector,
|
||||||
options: AngularCompilerOptions): StaticSymbol[] {
|
reflectorHost: compiler.StaticReflectorHost,
|
||||||
|
options: AngularCompilerOptions): compiler.StaticSymbol[] {
|
||||||
// Compare with false since the default should be true
|
// Compare with false since the default should be true
|
||||||
const skipFileNames =
|
const skipFileNames =
|
||||||
options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES;
|
options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES;
|
||||||
|
|
||||||
const staticSymbols: StaticSymbol[] = [];
|
const staticSymbols: compiler.StaticSymbol[] = [];
|
||||||
|
|
||||||
program.getSourceFiles()
|
program.getSourceFiles()
|
||||||
.filter(sourceFile => !skipFileNames.test(sourceFile.fileName))
|
.filter(sourceFile => !skipFileNames.test(sourceFile.fileName))
|
||||||
|
|
|
@ -20,18 +20,16 @@ import * as ts from 'typescript';
|
||||||
|
|
||||||
import {extractProgramSymbols} from './codegen';
|
import {extractProgramSymbols} from './codegen';
|
||||||
import {ReflectorHost} from './reflector_host';
|
import {ReflectorHost} from './reflector_host';
|
||||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
|
||||||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
|
||||||
|
|
||||||
export class Extractor {
|
export class Extractor {
|
||||||
constructor(
|
constructor(
|
||||||
private options: tsc.AngularCompilerOptions, private program: ts.Program,
|
private options: tsc.AngularCompilerOptions, private program: ts.Program,
|
||||||
public host: ts.CompilerHost, private staticReflector: StaticReflector,
|
public host: ts.CompilerHost, private staticReflector: compiler.StaticReflector,
|
||||||
private messageBundle: compiler.MessageBundle, private reflectorHost: ReflectorHost,
|
private messageBundle: compiler.MessageBundle, private reflectorHost: ReflectorHost,
|
||||||
private metadataResolver: compiler.CompileMetadataResolver) {}
|
private metadataResolver: compiler.CompileMetadataResolver) {}
|
||||||
|
|
||||||
extract(): Promise<compiler.MessageBundle> {
|
extract(): Promise<compiler.MessageBundle> {
|
||||||
const programSymbols: StaticSymbol[] =
|
const programSymbols: compiler.StaticSymbol[] =
|
||||||
extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options);
|
extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options);
|
||||||
|
|
||||||
const {ngModules, files} = compiler.analyzeAndValidateNgModules(
|
const {ngModules, files} = compiler.analyzeAndValidateNgModules(
|
||||||
|
@ -72,8 +70,8 @@ export class Extractor {
|
||||||
|
|
||||||
const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver();
|
const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver();
|
||||||
if (!reflectorHost) reflectorHost = new ReflectorHost(program, compilerHost, options);
|
if (!reflectorHost) reflectorHost = new ReflectorHost(program, compilerHost, options);
|
||||||
const staticReflector = new StaticReflector(reflectorHost);
|
const staticReflector = new compiler.StaticReflector(reflectorHost);
|
||||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
compiler.StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||||
|
|
||||||
const config = new compiler.CompilerConfig({
|
const config = new compiler.CompilerConfig({
|
||||||
genDebugInfo: options.debug === true,
|
genDebugInfo: options.debug === true,
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {StaticSymbol} from '@angular/compiler';
|
||||||
import {AngularCompilerOptions, ModuleMetadata} from '@angular/tsc-wrapped';
|
import {AngularCompilerOptions, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||||
import {StaticSymbol} from './static_reflector';
|
|
||||||
|
|
||||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||||
const DTS = /\.d\.ts$/;
|
const DTS = /\.d\.ts$/;
|
||||||
|
|
|
@ -6,14 +6,12 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AssetUrl, ImportGenerator} from '@angular/compiler';
|
import {AssetUrl, ImportGenerator, StaticReflectorHost, StaticSymbol} from '@angular/compiler';
|
||||||
import {AngularCompilerOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
import {AngularCompilerOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {StaticReflectorHost, StaticSymbol} from './static_reflector';
|
|
||||||
|
|
||||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||||
const DTS = /\.d\.ts$/;
|
const DTS = /\.d\.ts$/;
|
||||||
const NODE_MODULES = '/node_modules/';
|
const NODE_MODULES = '/node_modules/';
|
||||||
|
|
|
@ -25,11 +25,14 @@ export * from './src/template_parser/template_ast';
|
||||||
export {TEMPLATE_TRANSFORMS} from './src/template_parser/template_parser';
|
export {TEMPLATE_TRANSFORMS} from './src/template_parser/template_parser';
|
||||||
export {CompilerConfig, RenderTypes} from './src/config';
|
export {CompilerConfig, RenderTypes} from './src/config';
|
||||||
export * from './src/compile_metadata';
|
export * from './src/compile_metadata';
|
||||||
export * from './src/offline_compiler';
|
export * from './src/aot/compiler';
|
||||||
export {RuntimeCompiler} from './src/runtime_compiler';
|
export * from './src/aot/static_reflector';
|
||||||
|
export * from './src/aot/static_reflection_capabilities';
|
||||||
|
export * from './src/aot/static_symbol';
|
||||||
|
export {JitCompiler} from './src/jit/compiler';
|
||||||
|
export * from './src/jit/compiler_factory';
|
||||||
export * from './src/url_resolver';
|
export * from './src/url_resolver';
|
||||||
export * from './src/resource_loader';
|
export * from './src/resource_loader';
|
||||||
export * from './src/compiler';
|
|
||||||
export {DirectiveResolver} from './src/directive_resolver';
|
export {DirectiveResolver} from './src/directive_resolver';
|
||||||
export {PipeResolver} from './src/pipe_resolver';
|
export {PipeResolver} from './src/pipe_resolver';
|
||||||
export {NgModuleResolver} from './src/ng_module_resolver';
|
export {NgModuleResolver} from './src/ng_module_resolver';
|
||||||
|
|
|
@ -8,20 +8,22 @@
|
||||||
|
|
||||||
import {SchemaMetadata} from '@angular/core';
|
import {SchemaMetadata} from '@angular/core';
|
||||||
|
|
||||||
import {AnimationCompiler} from './animation/animation_compiler';
|
import {AnimationCompiler} from '../animation/animation_compiler';
|
||||||
import {AnimationParser} from './animation/animation_parser';
|
import {AnimationParser} from '../animation/animation_parser';
|
||||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompileProviderMetadata, StaticSymbol, createHostComponentMeta} from './compile_metadata';
|
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompileProviderMetadata, createHostComponentMeta} from '../compile_metadata';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from '../directive_normalizer';
|
||||||
import {DirectiveWrapperCompileResult, DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
import {DirectiveWrapperCompileResult, DirectiveWrapperCompiler} from '../directive_wrapper_compiler';
|
||||||
import {ListWrapper} from './facade/collection';
|
import {ListWrapper} from '../facade/collection';
|
||||||
import {Identifiers, resolveIdentifier, resolveIdentifierToken} from './identifiers';
|
import {Identifiers, resolveIdentifier, resolveIdentifierToken} from '../identifiers';
|
||||||
import {CompileMetadataResolver} from './metadata_resolver';
|
import {CompileMetadataResolver} from '../metadata_resolver';
|
||||||
import {NgModuleCompiler} from './ng_module_compiler';
|
import {NgModuleCompiler} from '../ng_module_compiler';
|
||||||
import {OutputEmitter} from './output/abstract_emitter';
|
import {OutputEmitter} from '../output/abstract_emitter';
|
||||||
import * as o from './output/output_ast';
|
import * as o from '../output/output_ast';
|
||||||
import {CompiledStylesheet, StyleCompiler} from './style_compiler';
|
import {CompiledStylesheet, StyleCompiler} from '../style_compiler';
|
||||||
import {TemplateParser} from './template_parser/template_parser';
|
import {TemplateParser} from '../template_parser/template_parser';
|
||||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDependency, ViewCompileResult, ViewCompiler} from './view_compiler/view_compiler';
|
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDependency, ViewCompileResult, ViewCompiler} from '../view_compiler/view_compiler';
|
||||||
|
|
||||||
|
import {StaticSymbol} from './static_symbol';
|
||||||
|
|
||||||
export class SourceModule {
|
export class SourceModule {
|
||||||
constructor(public fileUrl: string, public moduleUrl: string, public source: string) {}
|
constructor(public fileUrl: string, public moduleUrl: string, public source: string) {}
|
||||||
|
@ -115,7 +117,7 @@ function _analyzeNgModules(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OfflineCompiler {
|
export class AotCompiler {
|
||||||
private _animationCompiler = new AnimationCompiler();
|
private _animationCompiler = new AnimationCompiler();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {GetterFn, MethodFn, ReflectionCapabilities, SetterFn, reflector} from './private_import_core';
|
import {GetterFn, MethodFn, ReflectionCapabilities, SetterFn, reflector} from '../private_import_core';
|
||||||
import {StaticReflector} from './static_reflector';
|
import {StaticReflector} from './static_reflector';
|
||||||
|
|
||||||
export class StaticAndDynamicReflectionCapabilities {
|
export class StaticAndDynamicReflectionCapabilities {
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
import {Attribute, Component, ContentChild, ContentChildren, Directive, Host, HostBinding, HostListener, Inject, Injectable, Input, NgModule, Optional, Output, Pipe, Self, SkipSelf, ViewChild, ViewChildren, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
import {Attribute, Component, ContentChild, ContentChildren, Directive, Host, HostBinding, HostListener, Inject, Injectable, Input, NgModule, Optional, Output, Pipe, Self, SkipSelf, ViewChild, ViewChildren, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||||
|
|
||||||
import {ReflectorReader} from './private_import_core';
|
import {ReflectorReader} from '../private_import_core';
|
||||||
|
|
||||||
|
import {StaticSymbol} from './static_symbol';
|
||||||
|
|
||||||
const SUPPORTED_SCHEMA_VERSION = 1;
|
const SUPPORTED_SCHEMA_VERSION = 1;
|
||||||
|
|
||||||
|
@ -48,15 +50,6 @@ export interface StaticReflectorHost {
|
||||||
getCanonicalFileName(fileName: string): string;
|
getCanonicalFileName(fileName: string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A token representing the a reference to a static type.
|
|
||||||
*
|
|
||||||
* This token is unique for a filePath and name and can be used as a hash table key.
|
|
||||||
*/
|
|
||||||
export class StaticSymbol {
|
|
||||||
constructor(public filePath: string, public name: string, public members?: string[]) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A static reflector implements enough of the Reflector API that is necessary to compile
|
* A static reflector implements enough of the Reflector API that is necessary to compile
|
||||||
* templates statically.
|
* templates statically.
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* @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 function isStaticSymbol(value: any): value is StaticSymbol {
|
||||||
|
return typeof value === 'object' && value !== null && value['name'] && value['filePath'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A token representing the a reference to a static type.
|
||||||
|
*
|
||||||
|
* This token is unique for a filePath and name and can be used as a hash table key.
|
||||||
|
*/
|
||||||
|
export class StaticSymbol {
|
||||||
|
constructor(public filePath: string, public name: string, public members?: string[]) {}
|
||||||
|
}
|
|
@ -718,15 +718,6 @@ function _normalizeArray(obj: any[]): any[] {
|
||||||
return obj || [];
|
return obj || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isStaticSymbol(value: any): value is StaticSymbol {
|
|
||||||
return typeof value === 'object' && value !== null && value['name'] && value['filePath'];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StaticSymbol {
|
|
||||||
name: string;
|
|
||||||
filePath: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ProviderMeta {
|
export class ProviderMeta {
|
||||||
token: any;
|
token: any;
|
||||||
useClass: Type<any>;
|
useClass: Type<any>;
|
||||||
|
|
|
@ -8,22 +8,22 @@
|
||||||
|
|
||||||
import {Compiler, ComponentFactory, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, SchemaMetadata, Type} from '@angular/core';
|
import {Compiler, ComponentFactory, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, SchemaMetadata, Type} from '@angular/core';
|
||||||
|
|
||||||
import {AnimationCompiler} from './animation/animation_compiler';
|
import {AnimationCompiler} from '../animation/animation_compiler';
|
||||||
import {AnimationParser} from './animation/animation_parser';
|
import {AnimationParser} from '../animation/animation_parser';
|
||||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from './compile_metadata';
|
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from '../compile_metadata';
|
||||||
import {CompilerConfig} from './config';
|
import {CompilerConfig} from '../config';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from '../directive_normalizer';
|
||||||
import {DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
import {DirectiveWrapperCompiler} from '../directive_wrapper_compiler';
|
||||||
import {stringify} from './facade/lang';
|
import {stringify} from '../facade/lang';
|
||||||
import {CompileMetadataResolver} from './metadata_resolver';
|
import {CompileMetadataResolver} from '../metadata_resolver';
|
||||||
import {NgModuleCompiler} from './ng_module_compiler';
|
import {NgModuleCompiler} from '../ng_module_compiler';
|
||||||
import * as ir from './output/output_ast';
|
import * as ir from '../output/output_ast';
|
||||||
import {interpretStatements} from './output/output_interpreter';
|
import {interpretStatements} from '../output/output_interpreter';
|
||||||
import {jitStatements} from './output/output_jit';
|
import {jitStatements} from '../output/output_jit';
|
||||||
import {CompiledStylesheet, StyleCompiler} from './style_compiler';
|
import {CompiledStylesheet, StyleCompiler} from '../style_compiler';
|
||||||
import {TemplateParser} from './template_parser/template_parser';
|
import {TemplateParser} from '../template_parser/template_parser';
|
||||||
import {SyncAsyncResult} from './util';
|
import {SyncAsyncResult} from '../util';
|
||||||
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDependency, ViewCompiler} from './view_compiler/view_compiler';
|
import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDependency, ViewCompiler} from '../view_compiler/view_compiler';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ import {ComponentFactoryDependency, DirectiveWrapperDependency, ViewClassDepende
|
||||||
* application to XSS risks. For more detail, see the [Security Guide](http://g.co/ng/security).
|
* application to XSS risks. For more detail, see the [Security Guide](http://g.co/ng/security).
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RuntimeCompiler implements Compiler {
|
export class JitCompiler implements Compiler {
|
||||||
private _compiledTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
private _compiledTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
||||||
private _compiledHostTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
private _compiledHostTemplateCache = new Map<Type<any>, CompiledTemplate>();
|
||||||
private _compiledDirectiveWrapperCache = new Map<Type<any>, Type<any>>();
|
private _compiledDirectiveWrapperCache = new Map<Type<any>, Type<any>>();
|
||||||
|
@ -385,10 +385,10 @@ function assertComponent(meta: CompileDirectiveMetadata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements `Compiler` by delegating to the RuntimeCompiler using a known module.
|
* Implements `Compiler` by delegating to the JitCompiler using a known module.
|
||||||
*/
|
*/
|
||||||
class ModuleBoundCompiler implements Compiler {
|
class ModuleBoundCompiler implements Compiler {
|
||||||
constructor(private _delegate: RuntimeCompiler, private _ngModule: Type<any>) {}
|
constructor(private _delegate: JitCompiler, private _ngModule: Type<any>) {}
|
||||||
|
|
||||||
get _injector(): Injector { return this._delegate.injector; }
|
get _injector(): Injector { return this._delegate.injector; }
|
||||||
|
|
|
@ -8,28 +8,29 @@
|
||||||
|
|
||||||
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Inject, Injectable, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Inject, Injectable, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||||
|
|
||||||
import {AnimationParser} from './animation/animation_parser';
|
import {AnimationParser} from '../animation/animation_parser';
|
||||||
import {CompilerConfig} from './config';
|
import {CompilerConfig} from '../config';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from '../directive_normalizer';
|
||||||
import {DirectiveResolver} from './directive_resolver';
|
import {DirectiveResolver} from '../directive_resolver';
|
||||||
import {DirectiveWrapperCompiler} from './directive_wrapper_compiler';
|
import {DirectiveWrapperCompiler} from '../directive_wrapper_compiler';
|
||||||
import {Lexer} from './expression_parser/lexer';
|
import {Lexer} from '../expression_parser/lexer';
|
||||||
import {Parser} from './expression_parser/parser';
|
import {Parser} from '../expression_parser/parser';
|
||||||
import * as i18n from './i18n/index';
|
import * as i18n from '../i18n/index';
|
||||||
import {CompileMetadataResolver} from './metadata_resolver';
|
import {CompileMetadataResolver} from '../metadata_resolver';
|
||||||
import {HtmlParser} from './ml_parser/html_parser';
|
import {HtmlParser} from '../ml_parser/html_parser';
|
||||||
import {NgModuleCompiler} from './ng_module_compiler';
|
import {NgModuleCompiler} from '../ng_module_compiler';
|
||||||
import {NgModuleResolver} from './ng_module_resolver';
|
import {NgModuleResolver} from '../ng_module_resolver';
|
||||||
import {PipeResolver} from './pipe_resolver';
|
import {PipeResolver} from '../pipe_resolver';
|
||||||
import {Console, ReflectionCapabilities, Reflector, ReflectorReader, reflector} from './private_import_core';
|
import {Console, ReflectionCapabilities, Reflector, ReflectorReader, reflector} from '../private_import_core';
|
||||||
import {ResourceLoader} from './resource_loader';
|
import {ResourceLoader} from '../resource_loader';
|
||||||
import {RuntimeCompiler} from './runtime_compiler';
|
import {DomElementSchemaRegistry} from '../schema/dom_element_schema_registry';
|
||||||
import {DomElementSchemaRegistry} from './schema/dom_element_schema_registry';
|
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
||||||
import {ElementSchemaRegistry} from './schema/element_schema_registry';
|
import {StyleCompiler} from '../style_compiler';
|
||||||
import {StyleCompiler} from './style_compiler';
|
import {TemplateParser} from '../template_parser/template_parser';
|
||||||
import {TemplateParser} from './template_parser/template_parser';
|
import {DEFAULT_PACKAGE_URL_PROVIDER, UrlResolver} from '../url_resolver';
|
||||||
import {DEFAULT_PACKAGE_URL_PROVIDER, UrlResolver} from './url_resolver';
|
import {ViewCompiler} from '../view_compiler/view_compiler';
|
||||||
import {ViewCompiler} from './view_compiler/view_compiler';
|
|
||||||
|
import {JitCompiler} from './compiler';
|
||||||
|
|
||||||
const _NO_RESOURCE_LOADER: ResourceLoader = {
|
const _NO_RESOURCE_LOADER: ResourceLoader = {
|
||||||
get(url: string): Promise<string>{
|
get(url: string): Promise<string>{
|
||||||
|
@ -38,7 +39,7 @@ const _NO_RESOURCE_LOADER: ResourceLoader = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of providers that provide `RuntimeCompiler` and its dependencies to use for
|
* A set of providers that provide `JitCompiler` and its dependencies to use for
|
||||||
* template compilation.
|
* template compilation.
|
||||||
*/
|
*/
|
||||||
export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> = [
|
export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> = [
|
||||||
|
@ -68,8 +69,8 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
||||||
NgModuleCompiler,
|
NgModuleCompiler,
|
||||||
DirectiveWrapperCompiler,
|
DirectiveWrapperCompiler,
|
||||||
{provide: CompilerConfig, useValue: new CompilerConfig()},
|
{provide: CompilerConfig, useValue: new CompilerConfig()},
|
||||||
RuntimeCompiler,
|
JitCompiler,
|
||||||
{provide: Compiler, useExisting: RuntimeCompiler},
|
{provide: Compiler, useExisting: JitCompiler},
|
||||||
DomElementSchemaRegistry,
|
DomElementSchemaRegistry,
|
||||||
{provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry},
|
{provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry},
|
||||||
UrlResolver,
|
UrlResolver,
|
||||||
|
@ -81,7 +82,7 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RuntimeCompilerFactory implements CompilerFactory {
|
export class JitCompilerFactory implements CompilerFactory {
|
||||||
private _defaultOptions: CompilerOptions[];
|
private _defaultOptions: CompilerOptions[];
|
||||||
constructor(@Inject(COMPILER_OPTIONS) defaultOptions: CompilerOptions[]) {
|
constructor(@Inject(COMPILER_OPTIONS) defaultOptions: CompilerOptions[]) {
|
||||||
this._defaultOptions = [<CompilerOptions>{
|
this._defaultOptions = [<CompilerOptions>{
|
||||||
|
@ -128,7 +129,7 @@ function _initReflector() {
|
||||||
*/
|
*/
|
||||||
export const platformCoreDynamic = createPlatformFactory(platformCore, 'coreDynamic', [
|
export const platformCoreDynamic = createPlatformFactory(platformCore, 'coreDynamic', [
|
||||||
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
|
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
|
||||||
{provide: CompilerFactory, useClass: RuntimeCompilerFactory},
|
{provide: CompilerFactory, useClass: JitCompilerFactory},
|
||||||
{provide: PLATFORM_INITIALIZER, useValue: _initReflector, multi: true},
|
{provide: PLATFORM_INITIALIZER, useValue: _initReflector, multi: true},
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, Attribute, ChangeDetectionStrategy, Component, Host, Inject, Injectable, ModuleWithProviders, Optional, Provider, Query, SchemaMetadata, Self, SkipSelf, Type, resolveForwardRef} from '@angular/core';
|
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, Attribute, ChangeDetectionStrategy, Component, Host, Inject, Injectable, ModuleWithProviders, Optional, Provider, Query, SchemaMetadata, Self, SkipSelf, Type, resolveForwardRef} from '@angular/core';
|
||||||
|
|
||||||
|
import {isStaticSymbol} from './aot/static_symbol';
|
||||||
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
||||||
import * as cpl from './compile_metadata';
|
import * as cpl from './compile_metadata';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from './directive_normalizer';
|
||||||
|
@ -921,16 +922,16 @@ function flattenAndDedupeArray(tree: any[]): Array<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidType(value: any): boolean {
|
function isValidType(value: any): boolean {
|
||||||
return cpl.isStaticSymbol(value) || (value instanceof Type);
|
return isStaticSymbol(value) || (value instanceof Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function staticTypeModuleUrl(value: any): string {
|
function staticTypeModuleUrl(value: any): string {
|
||||||
return cpl.isStaticSymbol(value) ? value.filePath : null;
|
return isStaticSymbol(value) ? value.filePath : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function componentModuleUrl(
|
function componentModuleUrl(
|
||||||
reflector: ReflectorReader, type: Type<any>, cmpMetadata: Component): string {
|
reflector: ReflectorReader, type: Type<any>, cmpMetadata: Component): string {
|
||||||
if (cpl.isStaticSymbol(type)) {
|
if (isStaticSymbol(type)) {
|
||||||
return staticTypeModuleUrl(type);
|
return staticTypeModuleUrl(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -956,7 +957,7 @@ function convertToCompileValue(
|
||||||
class _CompileValueConverter extends ValueTransformer {
|
class _CompileValueConverter extends ValueTransformer {
|
||||||
visitOther(value: any, targetIdentifiers: cpl.CompileIdentifierMetadata[]): any {
|
visitOther(value: any, targetIdentifiers: cpl.CompileIdentifierMetadata[]): any {
|
||||||
let identifier: cpl.CompileIdentifierMetadata;
|
let identifier: cpl.CompileIdentifierMetadata;
|
||||||
if (cpl.isStaticSymbol(value)) {
|
if (isStaticSymbol(value)) {
|
||||||
identifier = new cpl.CompileIdentifierMetadata(
|
identifier = new cpl.CompileIdentifierMetadata(
|
||||||
{name: value.name, moduleUrl: value.filePath, reference: value});
|
{name: value.name, moduleUrl: value.filePath, reference: value});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -73,3 +73,6 @@ export type ComponentStillLoadingError = typeof r._ComponentStillLoadingError;
|
||||||
export const ComponentStillLoadingError: typeof r.ComponentStillLoadingError =
|
export const ComponentStillLoadingError: typeof r.ComponentStillLoadingError =
|
||||||
r.ComponentStillLoadingError;
|
r.ComponentStillLoadingError;
|
||||||
export const AnimationTransition: typeof r.AnimationTransition = r.AnimationTransition;
|
export const AnimationTransition: typeof r.AnimationTransition = r.AnimationTransition;
|
||||||
|
export type SetterFn = typeof r._SetterFn;
|
||||||
|
export type GetterFn = typeof r._GetterFn;
|
||||||
|
export type MethodFn = typeof r._MethodFn;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
|
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler';
|
||||||
import {HostListener, Inject, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
import {HostListener, Inject, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||||
import {MetadataCollector} from '@angular/tsc-wrapped';
|
import {MetadataCollector} from '@angular/tsc-wrapped';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
|
@ -29,7 +29,7 @@ export * from './pipe_resolver_mock';
|
||||||
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModule, Component, Directive, Pipe, Type, PlatformRef} from '@angular/core';
|
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModule, Component, Directive, Pipe, Type, PlatformRef} from '@angular/core';
|
||||||
import {MetadataOverride} from '@angular/core/testing';
|
import {MetadataOverride} from '@angular/core/testing';
|
||||||
import {TestingCompilerFactory, TestingCompiler} from './private_import_core';
|
import {TestingCompilerFactory, TestingCompiler} from './private_import_core';
|
||||||
import {platformCoreDynamic, RuntimeCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler';
|
import {platformCoreDynamic, JitCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler';
|
||||||
import {MockDirectiveResolver} from './directive_resolver_mock';
|
import {MockDirectiveResolver} from './directive_resolver_mock';
|
||||||
import {MockNgModuleResolver} from './ng_module_resolver_mock';
|
import {MockNgModuleResolver} from './ng_module_resolver_mock';
|
||||||
import {MockPipeResolver} from './pipe_resolver_mock';
|
import {MockPipeResolver} from './pipe_resolver_mock';
|
||||||
|
@ -40,7 +40,7 @@ export class TestingCompilerFactoryImpl implements TestingCompilerFactory {
|
||||||
constructor(private _compilerFactory: CompilerFactory) {}
|
constructor(private _compilerFactory: CompilerFactory) {}
|
||||||
|
|
||||||
createTestingCompiler(options: CompilerOptions[]): TestingCompiler {
|
createTestingCompiler(options: CompilerOptions[]): TestingCompiler {
|
||||||
const compiler = <RuntimeCompiler>this._compilerFactory.createCompiler(options);
|
const compiler = <JitCompiler>this._compilerFactory.createCompiler(options);
|
||||||
return new TestingCompilerImpl(
|
return new TestingCompilerImpl(
|
||||||
compiler, compiler.injector.get(MockDirectiveResolver),
|
compiler, compiler.injector.get(MockDirectiveResolver),
|
||||||
compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
|
compiler.injector.get(MockPipeResolver), compiler.injector.get(MockNgModuleResolver));
|
||||||
|
@ -50,7 +50,7 @@ export class TestingCompilerFactoryImpl implements TestingCompilerFactory {
|
||||||
export class TestingCompilerImpl implements TestingCompiler {
|
export class TestingCompilerImpl implements TestingCompiler {
|
||||||
private _overrider = new MetadataOverrider();
|
private _overrider = new MetadataOverrider();
|
||||||
constructor(
|
constructor(
|
||||||
private _compiler: RuntimeCompiler, private _directiveResolver: MockDirectiveResolver,
|
private _compiler: JitCompiler, private _directiveResolver: MockDirectiveResolver,
|
||||||
private _pipeResolver: MockPipeResolver, private _moduleResolver: MockNgModuleResolver) {}
|
private _pipeResolver: MockPipeResolver, private _moduleResolver: MockNgModuleResolver) {}
|
||||||
get injector(): Injector { return this._compiler.injector; }
|
get injector(): Injector { return this._compiler.injector; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue