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:
Tobias Bosch 2016-06-13 10:06:40 -07:00
parent 1745366530
commit bc888bf3a1
15 changed files with 110 additions and 103 deletions

View File

@ -151,19 +151,25 @@ export class CodeGenerator {
const staticReflector = new StaticReflector(reflectorHost); const staticReflector = new StaticReflector(reflectorHost);
StaticAndDynamicReflectionCapabilities.install(staticReflector); StaticAndDynamicReflectionCapabilities.install(staticReflector);
const htmlParser = new HtmlParser(); 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 normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
const parser = new Parser(new Lexer()); const parser = new Parser(new Lexer());
const tmplParser = new TemplateParser( const tmplParser = new TemplateParser(
parser, new DomElementSchemaRegistry(), htmlParser, parser, new DomElementSchemaRegistry(), htmlParser,
/*console*/ null, []); /*console*/ null, []);
const offlineCompiler = new compiler.OfflineCompiler( const offlineCompiler = new compiler.OfflineCompiler(
normalizer, tmplParser, new StyleCompiler(urlResolver), normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
new ViewCompiler(new compiler.CompilerConfig(true, true, true)),
new TypeScriptEmitter(reflectorHost), xhr); new TypeScriptEmitter(reflectorHost), xhr);
const resolver = new CompileMetadataResolver( const resolver = new CompileMetadataResolver(
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector),
new compiler.ViewResolver(staticReflector), null, null, staticReflector); new compiler.ViewResolver(staticReflector), config, staticReflector);
return new CodeGenerator( return new CodeGenerator(
options, program, compilerHost, staticReflector, resolver, offlineCompiler, reflectorHost); options, program, compilerHost, staticReflector, resolver, offlineCompiler, reflectorHost);

View File

@ -11,6 +11,7 @@ import * as ts from 'typescript';
import * as tsc from '@angular/tsc-wrapped'; import * as tsc from '@angular/tsc-wrapped';
import * as path from 'path'; import * as path from 'path';
import * as compiler from '@angular/compiler'; import * as compiler from '@angular/compiler';
import {ViewEncapsulation} from '@angular/core';
import {StaticReflector} from './static_reflector'; 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'; 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); const staticReflector = new StaticReflector(reflectorHost);
StaticAndDynamicReflectionCapabilities.install(staticReflector); StaticAndDynamicReflectionCapabilities.install(staticReflector);
const htmlParser = new HtmlParser(); 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 normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
const parser = new Parser(new Lexer()); const parser = new Parser(new Lexer());
const tmplParser = new TemplateParser( const tmplParser = new TemplateParser(
@ -147,7 +155,7 @@ class Extractor {
new TypeScriptEmitter(reflectorHost), xhr); new TypeScriptEmitter(reflectorHost), xhr);
const resolver = new CompileMetadataResolver( const resolver = new CompileMetadataResolver(
new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), 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 // TODO(vicb): handle implicit
const extractor = new MessageExtractor(htmlParser, parser, [], {}); const extractor = new MessageExtractor(htmlParser, parser, [], {});

View File

@ -31,10 +31,6 @@ import {ViewResolver} from './view_resolver';
import {DirectiveResolver} from './directive_resolver'; import {DirectiveResolver} from './directive_resolver';
import {PipeResolver} from './pipe_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 * A set of providers that provide `RuntimeCompiler` and its dependencies to use for
* template compilation. * template compilation.
@ -43,7 +39,7 @@ export const COMPILER_PROVIDERS: Array<any|Type|{[k: string]: any}|any[]> =
/*@ts2dart_const*/[ /*@ts2dart_const*/[
Lexer, Parser, HtmlParser, TemplateParser, DirectiveNormalizer, CompileMetadataResolver, Lexer, Parser, HtmlParser, TemplateParser, DirectiveNormalizer, CompileMetadataResolver,
DEFAULT_PACKAGE_URL_PROVIDER, StyleCompiler, ViewCompiler, DEFAULT_PACKAGE_URL_PROVIDER, StyleCompiler, ViewCompiler,
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []}, /*@ts2dart_Provider*/ {provide: CompilerConfig, useValue: new CompilerConfig()},
RuntimeCompiler, RuntimeCompiler,
/*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler}, /*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler},
DomElementSchemaRegistry, DomElementSchemaRegistry,

View File

@ -1,7 +1,7 @@
import {ViewEncapsulation} from '@angular/core'; import {ViewEncapsulation} from '@angular/core';
import {unimplemented} from '../src/facade/exceptions'; 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 {CompileIdentifierMetadata} from './compile_metadata';
import {Identifiers} from './identifiers'; import {Identifiers} from './identifiers';
@ -9,19 +9,31 @@ import {Identifiers} from './identifiers';
export class CompilerConfig { export class CompilerConfig {
public renderTypes: RenderTypes; public renderTypes: RenderTypes;
public defaultEncapsulation: ViewEncapsulation; public defaultEncapsulation: ViewEncapsulation;
public genDebugInfo: boolean;
public logBindingUpdate: boolean;
public useJit: boolean;
public platformDirectives: any[];
public platformPipes: any[];
constructor( constructor(
public genDebugInfo: boolean, public logBindingUpdate: boolean, public useJit: boolean, {renderTypes = new DefaultRenderTypes(), defaultEncapsulation = ViewEncapsulation.Emulated,
renderTypes: RenderTypes = null, defaultEncapsulation: ViewEncapsulation = null, genDebugInfo = assertionsEnabled(), logBindingUpdate = assertionsEnabled(), useJit = true,
public platformDirectives: any[] = [], public platformPipes: any[] = []) { platformDirectives = [], platformPipes = []}: {
if (isBlank(renderTypes)) { renderTypes?: RenderTypes,
renderTypes = new DefaultRenderTypes(); defaultEncapsulation?: ViewEncapsulation,
} genDebugInfo?: boolean,
logBindingUpdate?: boolean,
useJit?: boolean,
platformDirectives?: any[],
platformPipes?: any[]
} = {}) {
this.renderTypes = renderTypes; this.renderTypes = renderTypes;
if (isBlank(defaultEncapsulation)) {
defaultEncapsulation = ViewEncapsulation.Emulated;
}
this.defaultEncapsulation = defaultEncapsulation; this.defaultEncapsulation = defaultEncapsulation;
this.genDebugInfo = genDebugInfo;
this.logBindingUpdate = logBindingUpdate;
this.useJit = useJit;
this.platformDirectives = platformDirectives;
this.platformPipes = platformPipes;
} }
} }

View File

@ -72,11 +72,11 @@ export function main() {
})); }));
describe('platform directives', () => { describe('platform directives', () => {
beforeEachProviders( beforeEachProviders(() => [{
() => [{ provide: CompilerConfig,
provide: CompilerConfig, useValue: new CompilerConfig(
useValue: new CompilerConfig(true, false, true, null, null, [ADirective]) {genDebugInfo: true, platformDirectives: [ADirective]})
}]); }]);
it('should include platform directives when available', it('should include platform directives when available',
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => { inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {

View File

@ -40,15 +40,13 @@ function _createOfflineCompiler(xhr: MockXHR, emitter: OutputEmitter): OfflineCo
var urlResolver = createOfflineCompileUrlResolver(); var urlResolver = createOfflineCompileUrlResolver();
xhr.when(`${THIS_MODULE_PATH}/offline_compiler_compa.html`, 'Hello World {{user}}!'); xhr.when(`${THIS_MODULE_PATH}/offline_compiler_compa.html`, 'Hello World {{user}}!');
var htmlParser = new HtmlParser(); var htmlParser = new HtmlParser();
var config = new CompilerConfig(true, true, true); var config = new CompilerConfig({genDebugInfo: true, useJit: true});
var normalizer = var normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
new DirectiveNormalizer(xhr, urlResolver, htmlParser, new CompilerConfig(true, true, true));
return new OfflineCompiler( return new OfflineCompiler(
normalizer, normalizer,
new TemplateParser( new TemplateParser(
new Parser(new Lexer()), new MockSchemaRegistry({}, {}), htmlParser, new Console(), []), new Parser(new Lexer()), new MockSchemaRegistry({}, {}), htmlParser, new Console(), []),
new StyleCompiler(urlResolver), new ViewCompiler(new CompilerConfig(true, true, true)), new StyleCompiler(urlResolver), new ViewCompiler(config), emitter, xhr);
emitter, xhr);
} }
export function compileComp( export function compileComp(

View File

@ -15,25 +15,23 @@ import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe
export function main() { export function main() {
if (IS_DART) { if (IS_DART) {
declareTests(); declareTests({useJit: false});
} else { } else {
describe('jit', () => { describe('jit', () => { declareTests({useJit: true}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests();
});
describe('no jit', () => { describe('no jit', () => { declareTests({useJit: false}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests();
});
} }
} }
function declareTests() { function declareTests({useJit}: {useJit: boolean}) {
describe('animation tests', function() { 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 = var makeAnimationCmp =
(tcb: TestComponentBuilder, tpl: string, (tcb: TestComponentBuilder, tpl: string,

View File

@ -34,26 +34,24 @@ const ANCHOR_ELEMENT = /*@ts2dart_const*/ new OpaqueToken('AnchorElement');
export function main() { export function main() {
if (IS_DART) { if (IS_DART) {
declareTests(false); declareTests({useJit: false});
} else { } else {
describe('jit', () => { describe('jit', () => { declareTests({useJit: true}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => { describe('no jit', () => { declareTests({useJit: false}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
} }
} }
function declareTests(isJit: boolean) { function declareTests({useJit}: {useJit: boolean}) {
describe('integration tests', function() { 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() { describe('react to record changes', function() {
it('should consume text node changes', it('should consume text node changes',
@ -1788,8 +1786,10 @@ function declareTests(isJit: boolean) {
}); });
describe('logging property updates', () => { describe('logging property updates', () => {
beforeEachProviders( beforeEachProviders(() => [{
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, true, isJit)}]); provide: CompilerConfig,
useValue: new CompilerConfig({genDebugInfo: true, useJit: useJit})
}]);
it('should reflect property values as attributes', it('should reflect property values as attributes',
inject( inject(

View File

@ -10,23 +10,15 @@ import {CompilerConfig} from '@angular/compiler';
export function main() { export function main() {
if (IS_DART) { if (IS_DART) {
declareTests(false); declareTests({useJit: false});
} else { } else {
describe('jit', () => { describe('jit', () => { declareTests({useJit: true}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => { describe('no jit', () => { declareTests({useJit: false}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
} }
} }
function declareTests(isJit: boolean) { function declareTests({useJit}: {useJit: boolean}) {
// Place to put reproductions for regressions // Place to put reproductions for regressions
describe('regressions', () => { describe('regressions', () => {
@ -34,7 +26,8 @@ function declareTests(isJit: boolean) {
beforeEachProviders( beforeEachProviders(
() => [{ () => [{
provide: CompilerConfig, 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', it('should overwrite them by custom pipes',

View File

@ -15,19 +15,11 @@ const ANCHOR_ELEMENT = /*@ts2dart_const*/ new OpaqueToken('AnchorElement');
export function main() { export function main() {
if (IS_DART) { if (IS_DART) {
declareTests(false); declareTests({useJit: false});
} else { } else {
describe('jit', () => { describe('jit', () => { declareTests({useJit: true}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, true)}]);
declareTests(true);
});
describe('no jit', () => { describe('no jit', () => { declareTests({useJit: false}); });
beforeEachProviders(
() => [{provide: CompilerConfig, useValue: new CompilerConfig(true, false, false)}]);
declareTests(false);
});
} }
} }
@ -52,10 +44,16 @@ function itAsync(
} }
} }
function declareTests(isJit: boolean) { function declareTests({useJit}: {useJit: boolean}) {
describe('security integration tests', function() { 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; let originalLog: (msg: any) => any;
beforeEach(() => { beforeEach(() => {

View File

@ -63,14 +63,13 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
Testability, EventManager, ELEMENT_PROBE_PROVIDERS 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[]*/> = [ export const BROWSER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
COMPILER_PROVIDERS, COMPILER_PROVIDERS,
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []}, {
provide: CompilerConfig,
useValue:
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
},
{provide: XHR, useClass: XHRImpl}, {provide: XHR, useClass: XHRImpl},
]; ];

View File

@ -45,14 +45,13 @@ export function workerAppPlatform(): PlatformRef {
return assertPlatform(WORKER_APP_PLATFORM_MARKER); return assertPlatform(WORKER_APP_PLATFORM_MARKER);
} }
function _createCompilerConfig() { const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
return new CompilerConfig(
assertionsEnabled(), false, true, null, null, COMMON_DIRECTIVES, COMMON_PIPES);
}
export const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
COMPILER_PROVIDERS, COMPILER_PROVIDERS,
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []}, {
provide: CompilerConfig,
useValue:
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
},
{provide: XHR, useClass: XHRImpl}, {provide: XHR, useClass: XHRImpl},
]; ];

View File

@ -70,7 +70,7 @@ export function main() {
var domRootRenderer = uiInjector.get(DomRootRenderer); var domRootRenderer = uiInjector.get(DomRootRenderer);
workerRenderStore = new RenderStore(); workerRenderStore = new RenderStore();
return [ return [
Serializer, {provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)}, Serializer, {provide: CompilerConfig, useValue: new CompilerConfig({genDebugInfo: true})},
{provide: RenderStore, useValue: workerRenderStore}, { {provide: RenderStore, useValue: workerRenderStore}, {
provide: RootRenderer, provide: RootRenderer,
useFactory: (workerSerializer: Serializer) => { useFactory: (workerSerializer: Serializer) => {

View File

@ -29,7 +29,7 @@ function _createBindings(): any[] {
}, },
// Use interpretative mode as Dart does not support JIT and // Use interpretative mode as Dart does not support JIT and
// we want to be able to compare the numbers between JS and Dart // 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})}
]; ];
} }

View File

@ -169,9 +169,7 @@ const CORE = [
'const AUTO_STYLE:any', 'const AUTO_STYLE:any',
'const PACKAGE_ROOT_URL:any', 'const PACKAGE_ROOT_URL:any',
'const PLATFORM_COMMON_PROVIDERS:Array<any|Type|Provider|any[]>', 'const PLATFORM_COMMON_PROVIDERS:Array<any|Type|Provider|any[]>',
'const PLATFORM_DIRECTIVES:OpaqueToken',
'const PLATFORM_INITIALIZER:any', 'const PLATFORM_INITIALIZER:any',
'const PLATFORM_PIPES:OpaqueToken',
'ContentChildMetadata', 'ContentChildMetadata',
'ContentChildMetadata.constructor(_selector:Type|string, {read=null}:{read?:any}={})', 'ContentChildMetadata.constructor(_selector:Type|string, {read=null}:{read?:any}={})',
'ContentChildMetadataFactory', 'ContentChildMetadataFactory',
@ -1219,10 +1217,12 @@ const COMPILER = [
'CompileQueryMetadata.selectors:Array<CompileTokenMetadata>', 'CompileQueryMetadata.selectors:Array<CompileTokenMetadata>',
'CompileQueryMetadata.toJson():{[key:string]:any}', 'CompileQueryMetadata.toJson():{[key:string]:any}',
'CompilerConfig', '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.defaultEncapsulation:ViewEncapsulation',
'CompilerConfig.genDebugInfo:boolean', 'CompilerConfig.genDebugInfo:boolean',
'CompilerConfig.logBindingUpdate:boolean', 'CompilerConfig.logBindingUpdate:boolean',
'CompilerConfig.platformDirectives:any[]',
'CompilerConfig.platformPipes:any[]',
'CompilerConfig.renderTypes:RenderTypes', 'CompilerConfig.renderTypes:RenderTypes',
'CompilerConfig.useJit:boolean', 'CompilerConfig.useJit:boolean',
'CompileTemplateMetadata', 'CompileTemplateMetadata',