refactor(compiler): Change arguments of `CompilerConfig` to named arguments
BREAKIKNG CHANGE: `CompilerConfig` used to take positional arguments and now takes named arguments. Closes #9172
This commit is contained in:
parent
1745366530
commit
bc888bf3a1
|
@ -151,19 +151,25 @@ export class CodeGenerator {
|
|||
const staticReflector = new StaticReflector(reflectorHost);
|
||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||
const htmlParser = new HtmlParser();
|
||||
const config = new compiler.CompilerConfig(true, true, true);
|
||||
const config = new compiler.CompilerConfig({
|
||||
genDebugInfo: true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
logBindingUpdate: false,
|
||||
useJit: false,
|
||||
platformDirectives: [],
|
||||
platformPipes: []
|
||||
});
|
||||
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
||||
const parser = new Parser(new Lexer());
|
||||
const tmplParser = new TemplateParser(
|
||||
parser, new DomElementSchemaRegistry(), htmlParser,
|
||||
/*console*/ null, []);
|
||||
const offlineCompiler = new compiler.OfflineCompiler(
|
||||
normalizer, tmplParser, new StyleCompiler(urlResolver),
|
||||
new ViewCompiler(new compiler.CompilerConfig(true, true, true)),
|
||||
normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
|
||||
new TypeScriptEmitter(reflectorHost), xhr);
|
||||
const resolver = new CompileMetadataResolver(
|
||||
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
||||
new compiler.ViewResolver(staticReflector), null, null, staticReflector);
|
||||
new compiler.ViewResolver(staticReflector), config, staticReflector);
|
||||
|
||||
return new CodeGenerator(
|
||||
options, program, compilerHost, staticReflector, resolver, offlineCompiler, reflectorHost);
|
||||
|
|
|
@ -11,6 +11,7 @@ import * as ts from 'typescript';
|
|||
import * as tsc from '@angular/tsc-wrapped';
|
||||
import * as path from 'path';
|
||||
import * as compiler from '@angular/compiler';
|
||||
import {ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {StaticReflector} from './static_reflector';
|
||||
import {CompileMetadataResolver, HtmlParser, DirectiveNormalizer, Lexer, Parser, TemplateParser, DomElementSchemaRegistry, StyleCompiler, ViewCompiler, TypeScriptEmitter, MessageExtractor, removeDuplicates, ExtractionResult, Message, ParseError, serializeXmb,} from './compiler_private';
|
||||
|
@ -136,7 +137,14 @@ class Extractor {
|
|||
const staticReflector = new StaticReflector(reflectorHost);
|
||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||
const htmlParser = new HtmlParser();
|
||||
const config = new compiler.CompilerConfig(true, true, true);
|
||||
const config = new compiler.CompilerConfig({
|
||||
genDebugInfo: true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
logBindingUpdate: false,
|
||||
useJit: false,
|
||||
platformDirectives: [],
|
||||
platformPipes: []
|
||||
});
|
||||
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
||||
const parser = new Parser(new Lexer());
|
||||
const tmplParser = new TemplateParser(
|
||||
|
@ -147,7 +155,7 @@ class Extractor {
|
|||
new TypeScriptEmitter(reflectorHost), xhr);
|
||||
const resolver = new CompileMetadataResolver(
|
||||
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
|
||||
new compiler.ViewResolver(staticReflector), null, null, staticReflector);
|
||||
new compiler.ViewResolver(staticReflector), config, staticReflector);
|
||||
|
||||
// TODO(vicb): handle implicit
|
||||
const extractor = new MessageExtractor(htmlParser, parser, [], {});
|
||||
|
|
|
@ -31,10 +31,6 @@ import {ViewResolver} from './view_resolver';
|
|||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
|
||||
function _createCompilerConfig() {
|
||||
return new CompilerConfig(assertionsEnabled(), false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* A set of providers that provide `RuntimeCompiler` and its dependencies to use for
|
||||
* template compilation.
|
||||
|
@ -43,7 +39,7 @@ export const COMPILER_PROVIDERS: Array<any|Type|{[k: string]: any}|any[]> =
|
|||
/*@ts2dart_const*/[
|
||||
Lexer, Parser, HtmlParser, TemplateParser, DirectiveNormalizer, CompileMetadataResolver,
|
||||
DEFAULT_PACKAGE_URL_PROVIDER, StyleCompiler, ViewCompiler,
|
||||
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||
/*@ts2dart_Provider*/ {provide: CompilerConfig, useValue: new CompilerConfig()},
|
||||
RuntimeCompiler,
|
||||
/*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler},
|
||||
DomElementSchemaRegistry,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {unimplemented} from '../src/facade/exceptions';
|
||||
import {Type, isBlank} from '../src/facade/lang';
|
||||
import {Type, assertionsEnabled, isBlank} from '../src/facade/lang';
|
||||
|
||||
import {CompileIdentifierMetadata} from './compile_metadata';
|
||||
import {Identifiers} from './identifiers';
|
||||
|
@ -9,19 +9,31 @@ import {Identifiers} from './identifiers';
|
|||
export class CompilerConfig {
|
||||
public renderTypes: RenderTypes;
|
||||
public defaultEncapsulation: ViewEncapsulation;
|
||||
public genDebugInfo: boolean;
|
||||
public logBindingUpdate: boolean;
|
||||
public useJit: boolean;
|
||||
public platformDirectives: any[];
|
||||
public platformPipes: any[];
|
||||
|
||||
constructor(
|
||||
public genDebugInfo: boolean, public logBindingUpdate: boolean, public useJit: boolean,
|
||||
renderTypes: RenderTypes = null, defaultEncapsulation: ViewEncapsulation = null,
|
||||
public platformDirectives: any[] = [], public platformPipes: any[] = []) {
|
||||
if (isBlank(renderTypes)) {
|
||||
renderTypes = new DefaultRenderTypes();
|
||||
}
|
||||
{renderTypes = new DefaultRenderTypes(), defaultEncapsulation = ViewEncapsulation.Emulated,
|
||||
genDebugInfo = assertionsEnabled(), logBindingUpdate = assertionsEnabled(), useJit = true,
|
||||
platformDirectives = [], platformPipes = []}: {
|
||||
renderTypes?: RenderTypes,
|
||||
defaultEncapsulation?: ViewEncapsulation,
|
||||
genDebugInfo?: boolean,
|
||||
logBindingUpdate?: boolean,
|
||||
useJit?: boolean,
|
||||
platformDirectives?: any[],
|
||||
platformPipes?: any[]
|
||||
} = {}) {
|
||||
this.renderTypes = renderTypes;
|
||||
if (isBlank(defaultEncapsulation)) {
|
||||
defaultEncapsulation = ViewEncapsulation.Emulated;
|
||||
}
|
||||
this.defaultEncapsulation = defaultEncapsulation;
|
||||
this.genDebugInfo = genDebugInfo;
|
||||
this.logBindingUpdate = logBindingUpdate;
|
||||
this.useJit = useJit;
|
||||
this.platformDirectives = platformDirectives;
|
||||
this.platformPipes = platformPipes;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ export function main() {
|
|||
}));
|
||||
|
||||
describe('platform directives', () => {
|
||||
beforeEachProviders(
|
||||
() => [{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig(true, false, true, null, null, [ADirective])
|
||||
}]);
|
||||
beforeEachProviders(() => [{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig(
|
||||
{genDebugInfo: true, platformDirectives: [ADirective]})
|
||||
}]);
|
||||
|
||||
it('should include platform directives when available',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
|
|
|
@ -40,15 +40,13 @@ function _createOfflineCompiler(xhr: MockXHR, emitter: OutputEmitter): OfflineCo
|
|||
var urlResolver = createOfflineCompileUrlResolver();
|
||||
xhr.when(`${THIS_MODULE_PATH}/offline_compiler_compa.html`, 'Hello World {{user}}!');
|
||||
var htmlParser = new HtmlParser();
|
||||
var config = new CompilerConfig(true, true, true);
|
||||
var normalizer =
|
||||
new DirectiveNormalizer(xhr, urlResolver, htmlParser, new CompilerConfig(true, true, true));
|
||||
var config = new CompilerConfig({genDebugInfo: true, useJit: true});
|
||||
var normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
||||
return new OfflineCompiler(
|
||||
normalizer,
|
||||
new TemplateParser(
|
||||
new Parser(new Lexer()), new MockSchemaRegistry({}, {}), htmlParser, new Console(), []),
|
||||
new StyleCompiler(urlResolver), new ViewCompiler(new CompilerConfig(true, true, true)),
|
||||
emitter, xhr);
|
||||
new StyleCompiler(urlResolver), new ViewCompiler(config), emitter, xhr);
|
||||
}
|
||||
|
||||
export function compileComp(
|
||||
|
|
|
@ -15,25 +15,23 @@ import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe
|
|||
|
||||
export function main() {
|
||||
if (IS_DART) {
|
||||
declareTests();
|
||||
declareTests({useJit: false});
|
||||
} else {
|
||||
describe('jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||
declareTests();
|
||||
});
|
||||
describe('jit', () => { declareTests({useJit: true}); });
|
||||
|
||||
describe('no jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||
declareTests();
|
||||
});
|
||||
describe('no jit', () => { declareTests({useJit: false}); });
|
||||
}
|
||||
}
|
||||
|
||||
function declareTests() {
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
describe('animation tests', function() {
|
||||
beforeEachProviders(() => [{provide: AnimationDriver, useClass: MockAnimationDriver}]);
|
||||
beforeEachProviders(
|
||||
() =>
|
||||
[{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig({genDebugInfo: true, useJit: useJit})
|
||||
},
|
||||
{provide: AnimationDriver, useClass: MockAnimationDriver}]);
|
||||
|
||||
var makeAnimationCmp =
|
||||
(tcb: TestComponentBuilder, tpl: string,
|
||||
|
|
|
@ -34,26 +34,24 @@ const ANCHOR_ELEMENT = /*@ts2dart_const*/ new OpaqueToken('AnchorElement');
|
|||
|
||||
export function main() {
|
||||
if (IS_DART) {
|
||||
declareTests(false);
|
||||
declareTests({useJit: false});
|
||||
} else {
|
||||
describe('jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||
declareTests(true);
|
||||
});
|
||||
describe('jit', () => { declareTests({useJit: true}); });
|
||||
|
||||
describe('no jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||
declareTests(false);
|
||||
});
|
||||
describe('no jit', () => { declareTests({useJit: false}); });
|
||||
}
|
||||
}
|
||||
|
||||
function declareTests(isJit: boolean) {
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
describe('integration tests', function() {
|
||||
|
||||
beforeEachProviders(() => [{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
|
||||
beforeEachProviders(
|
||||
() =>
|
||||
[{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig({genDebugInfo: true, useJit: useJit})
|
||||
},
|
||||
{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
|
||||
|
||||
describe('react to record changes', function() {
|
||||
it('should consume text node changes',
|
||||
|
@ -1788,8 +1786,10 @@ function declareTests(isJit: boolean) {
|
|||
});
|
||||
|
||||
describe('logging property updates', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, true, isJit)}]);
|
||||
beforeEachProviders(() => [{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig({genDebugInfo: true, useJit: useJit})
|
||||
}]);
|
||||
|
||||
it('should reflect property values as attributes',
|
||||
inject(
|
||||
|
|
|
@ -10,23 +10,15 @@ import {CompilerConfig} from '@angular/compiler';
|
|||
|
||||
export function main() {
|
||||
if (IS_DART) {
|
||||
declareTests(false);
|
||||
declareTests({useJit: false});
|
||||
} else {
|
||||
describe('jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||
declareTests(true);
|
||||
});
|
||||
describe('jit', () => { declareTests({useJit: true}); });
|
||||
|
||||
describe('no jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||
declareTests(false);
|
||||
});
|
||||
describe('no jit', () => { declareTests({useJit: false}); });
|
||||
}
|
||||
}
|
||||
|
||||
function declareTests(isJit: boolean) {
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
// Place to put reproductions for regressions
|
||||
describe('regressions', () => {
|
||||
|
||||
|
@ -34,7 +26,8 @@ function declareTests(isJit: boolean) {
|
|||
beforeEachProviders(
|
||||
() => [{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig(true, false, isJit, null, null, [PlatformPipe])
|
||||
useValue: new CompilerConfig(
|
||||
{genDebugInfo: true, useJit: useJit, platformPipes: [PlatformPipe]})
|
||||
}]);
|
||||
|
||||
it('should overwrite them by custom pipes',
|
||||
|
|
|
@ -15,19 +15,11 @@ const ANCHOR_ELEMENT = /*@ts2dart_const*/ new OpaqueToken('AnchorElement');
|
|||
|
||||
export function main() {
|
||||
if (IS_DART) {
|
||||
declareTests(false);
|
||||
declareTests({useJit: false});
|
||||
} else {
|
||||
describe('jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
|
||||
declareTests(true);
|
||||
});
|
||||
describe('jit', () => { declareTests({useJit: true}); });
|
||||
|
||||
describe('no jit', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
|
||||
declareTests(false);
|
||||
});
|
||||
describe('no jit', () => { declareTests({useJit: false}); });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,10 +44,16 @@ function itAsync(
|
|||
}
|
||||
}
|
||||
|
||||
function declareTests(isJit: boolean) {
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
describe('security integration tests', function() {
|
||||
|
||||
beforeEachProviders(() => [{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
|
||||
beforeEachProviders(
|
||||
() =>
|
||||
[{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig({genDebugInfo: true, useJit: useJit})
|
||||
},
|
||||
{provide: ANCHOR_ELEMENT, useValue: el('<div></div>')}]);
|
||||
|
||||
let originalLog: (msg: any) => any;
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -63,14 +63,13 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
|||
Testability, EventManager, ELEMENT_PROBE_PROVIDERS
|
||||
];
|
||||
|
||||
function _createCompilerConfig() {
|
||||
return new CompilerConfig(
|
||||
assertionsEnabled(), false, true, null, null, COMMON_DIRECTIVES, COMMON_PIPES);
|
||||
}
|
||||
|
||||
export const BROWSER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
COMPILER_PROVIDERS,
|
||||
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||
{
|
||||
provide: CompilerConfig,
|
||||
useValue:
|
||||
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
|
||||
},
|
||||
{provide: XHR, useClass: XHRImpl},
|
||||
];
|
||||
|
||||
|
|
|
@ -45,14 +45,13 @@ export function workerAppPlatform(): PlatformRef {
|
|||
return assertPlatform(WORKER_APP_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
function _createCompilerConfig() {
|
||||
return new CompilerConfig(
|
||||
assertionsEnabled(), false, true, null, null, COMMON_DIRECTIVES, COMMON_PIPES);
|
||||
}
|
||||
|
||||
export const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
COMPILER_PROVIDERS,
|
||||
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||
{
|
||||
provide: CompilerConfig,
|
||||
useValue:
|
||||
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
|
||||
},
|
||||
{provide: XHR, useClass: XHRImpl},
|
||||
];
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ export function main() {
|
|||
var domRootRenderer = uiInjector.get(DomRootRenderer);
|
||||
workerRenderStore = new RenderStore();
|
||||
return [
|
||||
Serializer, {provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
|
||||
Serializer, {provide: CompilerConfig, useValue: new CompilerConfig({genDebugInfo: true})},
|
||||
{provide: RenderStore, useValue: workerRenderStore}, {
|
||||
provide: RootRenderer,
|
||||
useFactory: (workerSerializer: Serializer) => {
|
||||
|
|
|
@ -29,7 +29,7 @@ function _createBindings(): any[] {
|
|||
},
|
||||
// Use interpretative mode as Dart does not support JIT and
|
||||
// we want to be able to compare the numbers between JS and Dart
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig(false, false, false)}
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig({genDebugInfo: false, useJit: false, logBindingUpdate: false})}
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -169,9 +169,7 @@ const CORE = [
|
|||
'const AUTO_STYLE:any',
|
||||
'const PACKAGE_ROOT_URL:any',
|
||||
'const PLATFORM_COMMON_PROVIDERS:Array<any|Type|Provider|any[]>',
|
||||
'const PLATFORM_DIRECTIVES:OpaqueToken',
|
||||
'const PLATFORM_INITIALIZER:any',
|
||||
'const PLATFORM_PIPES:OpaqueToken',
|
||||
'ContentChildMetadata',
|
||||
'ContentChildMetadata.constructor(_selector:Type|string, {read=null}:{read?:any}={})',
|
||||
'ContentChildMetadataFactory',
|
||||
|
@ -1219,10 +1217,12 @@ const COMPILER = [
|
|||
'CompileQueryMetadata.selectors:Array<CompileTokenMetadata>',
|
||||
'CompileQueryMetadata.toJson():{[key:string]:any}',
|
||||
'CompilerConfig',
|
||||
'CompilerConfig.constructor(genDebugInfo:boolean, logBindingUpdate:boolean, useJit:boolean, renderTypes:RenderTypes=null, defaultEncapsulation:ViewEncapsulation=null)',
|
||||
'CompilerConfig.constructor({renderTypes=newDefaultRenderTypes(),defaultEncapsulation=ViewEncapsulation.Emulated,genDebugInfo=assertionsEnabled(),logBindingUpdate=assertionsEnabled(),useJit=true,platformDirectives=[],platformPipes=[]}:{renderTypes?:RenderTypes, defaultEncapsulation?:ViewEncapsulation, genDebugInfo?:boolean, logBindingUpdate?:boolean, useJit?:boolean, platformDirectives?:any[], platformPipes?:any[]}={})',
|
||||
'CompilerConfig.defaultEncapsulation:ViewEncapsulation',
|
||||
'CompilerConfig.genDebugInfo:boolean',
|
||||
'CompilerConfig.logBindingUpdate:boolean',
|
||||
'CompilerConfig.platformDirectives:any[]',
|
||||
'CompilerConfig.platformPipes:any[]',
|
||||
'CompilerConfig.renderTypes:RenderTypes',
|
||||
'CompilerConfig.useJit:boolean',
|
||||
'CompileTemplateMetadata',
|
||||
|
|
Loading…
Reference in New Issue