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
+1 -5
View File
@@ -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,
+22 -10
View File
@@ -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(