feat(change_detection): make INTERPOLATE_REGEXP customizable (#7417)
BREAKING CHANGES: `Parser` constructor required new parameter `config: CompilerConfig` as second argument.
This commit is contained in:
committed by
Miško Hevery
parent
9036f78b74
commit
c3fafa0651
@@ -41,6 +41,7 @@ function _createCompilerConfig() {
|
||||
*/
|
||||
export const COMPILER_PROVIDERS: Array<any | Type | {[k: string]: any} | any[]> =
|
||||
/*@ts2dart_const*/[
|
||||
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||
Lexer,
|
||||
Parser,
|
||||
HtmlParser,
|
||||
@@ -50,7 +51,6 @@ export const COMPILER_PROVIDERS: Array<any | Type | {[k: string]: any} | any[]>
|
||||
DEFAULT_PACKAGE_URL_PROVIDER,
|
||||
StyleCompiler,
|
||||
ViewCompiler,
|
||||
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||
RuntimeCompiler,
|
||||
/*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler},
|
||||
DomElementSchemaRegistry,
|
||||
|
||||
@@ -5,12 +5,17 @@ import {CompileIdentifierMetadata} from './compile_metadata';
|
||||
|
||||
export class CompilerConfig {
|
||||
public renderTypes: RenderTypes;
|
||||
public interpolateRegexp: RegExp;
|
||||
constructor(public genDebugInfo: boolean, public logBindingUpdate: boolean,
|
||||
public useJit: boolean, renderTypes: RenderTypes = null) {
|
||||
public useJit: boolean, renderTypes: RenderTypes = null, interpolateRegexp: RegExp = null) {
|
||||
if (isBlank(renderTypes)) {
|
||||
renderTypes = new DefaultRenderTypes();
|
||||
}
|
||||
this.renderTypes = renderTypes;
|
||||
if (isBlank(interpolateRegexp)) {
|
||||
interpolateRegexp = DEFAULT_INTERPOLATE_REGEXP;
|
||||
}
|
||||
this.interpolateRegexp = interpolateRegexp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,3 +41,8 @@ export class DefaultRenderTypes implements RenderTypes {
|
||||
renderNode = null;
|
||||
renderEvent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A regexp pattern used to interpolate in default.
|
||||
*/
|
||||
export var DEFAULT_INTERPOLATE_REGEXP = /\{\{([\s\S]*?)\}\}/g;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Injectable, Inject} from '@angular/core';
|
||||
import {isBlank, isPresent, StringWrapper} from '../../src/facade/lang';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {ListWrapper} from '../../src/facade/collection';
|
||||
@@ -46,11 +46,10 @@ import {
|
||||
AstVisitor,
|
||||
Quote
|
||||
} from './ast';
|
||||
import {CompilerConfig} from '../config';
|
||||
|
||||
|
||||
var _implicitReceiver = new ImplicitReceiver();
|
||||
// TODO(tbosch): Cannot make this const/final right now because of the transpiler...
|
||||
var INTERPOLATION_REGEXP = /\{\{([\s\S]*?)\}\}/g;
|
||||
|
||||
class ParseException extends BaseException {
|
||||
constructor(message: string, input: string, errLocation: string, ctxLocation?: any) {
|
||||
@@ -69,7 +68,9 @@ export class TemplateBindingParseResult {
|
||||
@Injectable()
|
||||
export class Parser {
|
||||
constructor(/** @internal */
|
||||
public _lexer: Lexer) {}
|
||||
public _lexer: Lexer,
|
||||
/** @internal */
|
||||
public _config: CompilerConfig) {}
|
||||
|
||||
parseAction(input: string, location: any): ASTWithSource {
|
||||
this._checkNoInterpolation(input, location);
|
||||
@@ -137,7 +138,7 @@ export class Parser {
|
||||
}
|
||||
|
||||
splitInterpolation(input: string, location: string): SplitInterpolation {
|
||||
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
|
||||
var parts = StringWrapper.split(input, this._config.interpolateRegexp);
|
||||
if (parts.length <= 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -187,7 +188,7 @@ export class Parser {
|
||||
}
|
||||
|
||||
private _checkNoInterpolation(input: string, location: any): void {
|
||||
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
|
||||
var parts = StringWrapper.split(input, this._config.interpolateRegexp);
|
||||
if (parts.length > 1) {
|
||||
throw new ParseException('Got interpolation ({{}}) where expression was expected', input,
|
||||
`at column ${this._findInterpolationErrorColumn(parts, 1)} in`,
|
||||
|
||||
Reference in New Issue
Block a user