Revert "feat(change_detection): make INTERPOLATE_REGEXP customizable (#7417)"
This reverts commit c3fafa0651
.
The symbols should be configured at the component level and not be global to the compiler.
This commit is contained in:
parent
04220be8fd
commit
1a386a58c8
|
@ -41,7 +41,6 @@ function _createCompilerConfig() {
|
||||||
*/
|
*/
|
||||||
export const COMPILER_PROVIDERS: Array<any | Type | {[k: string]: any} | any[]> =
|
export const COMPILER_PROVIDERS: Array<any | Type | {[k: string]: any} | any[]> =
|
||||||
/*@ts2dart_const*/[
|
/*@ts2dart_const*/[
|
||||||
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
|
||||||
Lexer,
|
Lexer,
|
||||||
Parser,
|
Parser,
|
||||||
HtmlParser,
|
HtmlParser,
|
||||||
|
@ -51,6 +50,7 @@ export const COMPILER_PROVIDERS: Array<any | Type | {[k: string]: any} | any[]>
|
||||||
DEFAULT_PACKAGE_URL_PROVIDER,
|
DEFAULT_PACKAGE_URL_PROVIDER,
|
||||||
StyleCompiler,
|
StyleCompiler,
|
||||||
ViewCompiler,
|
ViewCompiler,
|
||||||
|
/*@ts2dart_Provider*/ {provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
|
||||||
RuntimeCompiler,
|
RuntimeCompiler,
|
||||||
/*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler},
|
/*@ts2dart_Provider*/ {provide: ComponentResolver, useExisting: RuntimeCompiler},
|
||||||
DomElementSchemaRegistry,
|
DomElementSchemaRegistry,
|
||||||
|
|
|
@ -6,20 +6,15 @@ import {ViewEncapsulation} from '@angular/core';
|
||||||
|
|
||||||
export class CompilerConfig {
|
export class CompilerConfig {
|
||||||
public renderTypes: RenderTypes;
|
public renderTypes: RenderTypes;
|
||||||
public interpolateRegexp: RegExp;
|
|
||||||
public defaultEncapsulation: ViewEncapsulation;
|
public defaultEncapsulation: ViewEncapsulation;
|
||||||
|
|
||||||
constructor(public genDebugInfo: boolean, public logBindingUpdate: boolean,
|
constructor(public genDebugInfo: boolean, public logBindingUpdate: boolean,
|
||||||
public useJit: boolean, renderTypes: RenderTypes = null,
|
public useJit: boolean, renderTypes: RenderTypes = null,
|
||||||
interpolateRegexp: RegExp = null, defaultEncapsulation: ViewEncapsulation = null) {
|
defaultEncapsulation: ViewEncapsulation = null) {
|
||||||
if (isBlank(renderTypes)) {
|
if (isBlank(renderTypes)) {
|
||||||
renderTypes = new DefaultRenderTypes();
|
renderTypes = new DefaultRenderTypes();
|
||||||
}
|
}
|
||||||
this.renderTypes = renderTypes;
|
this.renderTypes = renderTypes;
|
||||||
if (isBlank(interpolateRegexp)) {
|
|
||||||
interpolateRegexp = DEFAULT_INTERPOLATE_REGEXP;
|
|
||||||
}
|
|
||||||
this.interpolateRegexp = interpolateRegexp;
|
|
||||||
if (isBlank(defaultEncapsulation)) {
|
if (isBlank(defaultEncapsulation)) {
|
||||||
defaultEncapsulation = ViewEncapsulation.Emulated;
|
defaultEncapsulation = ViewEncapsulation.Emulated;
|
||||||
}
|
}
|
||||||
|
@ -49,8 +44,3 @@ export class DefaultRenderTypes implements RenderTypes {
|
||||||
renderNode = null;
|
renderNode = null;
|
||||||
renderEvent = 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, Inject} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {isBlank, isPresent, StringWrapper} from '../../src/facade/lang';
|
import {isBlank, isPresent, StringWrapper} from '../../src/facade/lang';
|
||||||
import {BaseException} from '../../src/facade/exceptions';
|
import {BaseException} from '../../src/facade/exceptions';
|
||||||
import {ListWrapper} from '../../src/facade/collection';
|
import {ListWrapper} from '../../src/facade/collection';
|
||||||
|
@ -46,10 +46,11 @@ import {
|
||||||
AstVisitor,
|
AstVisitor,
|
||||||
Quote
|
Quote
|
||||||
} from './ast';
|
} from './ast';
|
||||||
import {CompilerConfig} from '../config';
|
|
||||||
|
|
||||||
|
|
||||||
var _implicitReceiver = new ImplicitReceiver();
|
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 {
|
class ParseException extends BaseException {
|
||||||
constructor(message: string, input: string, errLocation: string, ctxLocation?: any) {
|
constructor(message: string, input: string, errLocation: string, ctxLocation?: any) {
|
||||||
|
@ -68,9 +69,7 @@ export class TemplateBindingParseResult {
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Parser {
|
export class Parser {
|
||||||
constructor(/** @internal */
|
constructor(/** @internal */
|
||||||
public _lexer: Lexer,
|
public _lexer: Lexer) {}
|
||||||
/** @internal */
|
|
||||||
public _config: CompilerConfig) {}
|
|
||||||
|
|
||||||
parseAction(input: string, location: any): ASTWithSource {
|
parseAction(input: string, location: any): ASTWithSource {
|
||||||
this._checkNoInterpolation(input, location);
|
this._checkNoInterpolation(input, location);
|
||||||
|
@ -138,7 +137,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
splitInterpolation(input: string, location: string): SplitInterpolation {
|
splitInterpolation(input: string, location: string): SplitInterpolation {
|
||||||
var parts = StringWrapper.split(input, this._config.interpolateRegexp);
|
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
|
||||||
if (parts.length <= 1) {
|
if (parts.length <= 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +187,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _checkNoInterpolation(input: string, location: any): void {
|
private _checkNoInterpolation(input: string, location: any): void {
|
||||||
var parts = StringWrapper.split(input, this._config.interpolateRegexp);
|
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
throw new ParseException('Got interpolation ({{}}) where expression was expected', input,
|
throw new ParseException('Got interpolation ({{}}) where expression was expected', input,
|
||||||
`at column ${this._findInterpolationErrorColumn(parts, 1)} in`,
|
`at column ${this._findInterpolationErrorColumn(parts, 1)} in`,
|
||||||
|
|
|
@ -2,12 +2,11 @@ import {ddescribe, describe, it, xit, iit, expect, beforeEach} from '@angular/co
|
||||||
import {isBlank, isPresent} from '../../src/facade/lang';
|
import {isBlank, isPresent} from '../../src/facade/lang';
|
||||||
import {Parser} from '@angular/compiler/src/expression_parser/parser';
|
import {Parser} from '@angular/compiler/src/expression_parser/parser';
|
||||||
import {Unparser} from './unparser';
|
import {Unparser} from './unparser';
|
||||||
import {CompilerConfig} from '@angular/compiler';
|
|
||||||
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
|
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
|
||||||
import {BindingPipe, LiteralPrimitive, AST} from '@angular/compiler/src/expression_parser/ast';
|
import {BindingPipe, LiteralPrimitive, AST} from '@angular/compiler/src/expression_parser/ast';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
function createParser() { return new Parser(new Lexer(), new CompilerConfig(true, true, true)); }
|
function createParser() { return new Parser(new Lexer()); }
|
||||||
|
|
||||||
function parseAction(text, location = null): any {
|
function parseAction(text, location = null): any {
|
||||||
return createParser().parseAction(text, location);
|
return createParser().parseAction(text, location);
|
||||||
|
@ -454,14 +453,6 @@ export function main() {
|
||||||
checkInterpolation(`{{ 'foo' +\n 'bar' +\r 'baz' }}`, `{{ "foo" + "bar" + "baz" }}`);
|
checkInterpolation(`{{ 'foo' +\n 'bar' +\r 'baz' }}`, `{{ "foo" + "bar" + "baz" }}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support custom interpolation regexp', () => {
|
|
||||||
var customParser = new Parser(new Lexer(), new CompilerConfig(true, true, true, null, /<<([\s\S]*?)>>/g));
|
|
||||||
var ast = (customParser.parseInterpolation('<< a >>', null) as any).ast;
|
|
||||||
expect(ast.strings).toEqual(['', '']);
|
|
||||||
expect(ast.expressions.length).toEqual(1);
|
|
||||||
expect(ast.expressions[0].name).toEqual('a');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("comments", () => {
|
describe("comments", () => {
|
||||||
it('should ignore comments in interpolation expressions',
|
it('should ignore comments in interpolation expressions',
|
||||||
() => { checkInterpolation('{{a //comment}}', '{{ a }}'); });
|
() => { checkInterpolation('{{a //comment}}', '{{ a }}'); });
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {describe, expect, it, iit, ddescribe} from "@angular/core/testing/testing_internal";
|
import {describe, expect, it, iit, ddescribe} from "@angular/core/testing/testing_internal";
|
||||||
import {I18nHtmlParser} from "@angular/compiler/src/i18n/i18n_html_parser";
|
import {I18nHtmlParser} from "@angular/compiler/src/i18n/i18n_html_parser";
|
||||||
import {Message, id} from "@angular/compiler/src/i18n/message";
|
import {Message, id} from "@angular/compiler/src/i18n/message";
|
||||||
import {CompilerConfig} from "@angular/compiler/src/config";
|
|
||||||
import {Parser} from "@angular/compiler/src/expression_parser/parser";
|
import {Parser} from "@angular/compiler/src/expression_parser/parser";
|
||||||
import {Lexer} from "@angular/compiler/src/expression_parser/lexer";
|
import {Lexer} from "@angular/compiler/src/expression_parser/lexer";
|
||||||
import {StringMapWrapper} from "../../src/facade/collection";
|
import {StringMapWrapper} from "../../src/facade/collection";
|
||||||
|
@ -15,7 +14,7 @@ export function main() {
|
||||||
describe('I18nHtmlParser', () => {
|
describe('I18nHtmlParser', () => {
|
||||||
function parse(template: string, messages: {[key: string]: string}, implicitTags: string[] = [],
|
function parse(template: string, messages: {[key: string]: string}, implicitTags: string[] = [],
|
||||||
implicitAttrs: {[k: string]: string[]} = {}): HtmlParseTreeResult {
|
implicitAttrs: {[k: string]: string[]} = {}): HtmlParseTreeResult {
|
||||||
var parser = new Parser(new Lexer(), new CompilerConfig(true, true, true));
|
var parser = new Parser(new Lexer());
|
||||||
let htmlParser = new HtmlParser();
|
let htmlParser = new HtmlParser();
|
||||||
|
|
||||||
let msgs = '';
|
let msgs = '';
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {
|
||||||
} from '@angular/core/testing/testing_internal';
|
} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {HtmlParser} from '@angular/compiler/src/html_parser';
|
import {HtmlParser} from '@angular/compiler/src/html_parser';
|
||||||
import {CompilerConfig} from '@angular/compiler/src/config';
|
|
||||||
import {MessageExtractor, removeDuplicates} from '@angular/compiler/src/i18n/message_extractor';
|
import {MessageExtractor, removeDuplicates} from '@angular/compiler/src/i18n/message_extractor';
|
||||||
import {Message} from '@angular/compiler/src/i18n/message';
|
import {Message} from '@angular/compiler/src/i18n/message';
|
||||||
import {Parser} from '@angular/compiler/src/expression_parser/parser';
|
import {Parser} from '@angular/compiler/src/expression_parser/parser';
|
||||||
|
@ -23,7 +22,7 @@ export function main() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
let htmlParser = new HtmlParser();
|
let htmlParser = new HtmlParser();
|
||||||
var parser = new Parser(new Lexer(), new CompilerConfig(true, true, true));
|
var parser = new Parser(new Lexer());
|
||||||
extractor = new MessageExtractor(htmlParser, parser, ['i18n-tag'], {'i18n-el': ['trans']});
|
extractor = new MessageExtractor(htmlParser, parser, ['i18n-tag'], {'i18n-el': ['trans']});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,11 @@ function _createOfflineCompiler(xhr: MockXHR, emitter: OutputEmitter): OfflineCo
|
||||||
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(true, true, true);
|
||||||
var normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
var normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, new CompilerConfig(true, true, true));
|
||||||
return new OfflineCompiler(
|
return new OfflineCompiler(
|
||||||
normalizer, new TemplateParser(new Parser(new Lexer(), config), new MockSchemaRegistry({}, {}),
|
normalizer, new TemplateParser(new Parser(new Lexer()), new MockSchemaRegistry({}, {}),
|
||||||
htmlParser, new Console(), []),
|
htmlParser, new Console(), []),
|
||||||
new StyleCompiler(urlResolver), new ViewCompiler(config),
|
new StyleCompiler(urlResolver), new ViewCompiler(new CompilerConfig(true, true, true)),
|
||||||
emitter, xhr);
|
emitter, xhr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,4 +80,4 @@ export class SimpleJsImportGenerator implements ImportGenerator {
|
||||||
return importedUrlStr;
|
return importedUrlStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -160,12 +160,12 @@ export class CodeGenerator {
|
||||||
const htmlParser = new HtmlParser();
|
const htmlParser = new HtmlParser();
|
||||||
const config = new compiler.CompilerConfig(true, true, true);
|
const config = new compiler.CompilerConfig(true, true, true);
|
||||||
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
|
||||||
const parser = new Parser(new Lexer(), config);
|
const parser = new Parser(new Lexer());
|
||||||
const tmplParser = new TemplateParser(parser, new DomElementSchemaRegistry(), htmlParser,
|
const tmplParser = new TemplateParser(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),
|
||||||
|
|
|
@ -24,7 +24,7 @@ OfflineCompiler createTemplateCompiler(AssetReader reader,
|
||||||
var _urlResolver = createOfflineCompileUrlResolver();
|
var _urlResolver = createOfflineCompileUrlResolver();
|
||||||
|
|
||||||
// TODO(yjbanov): add router AST transformer when ready
|
// TODO(yjbanov): add router AST transformer when ready
|
||||||
var parser = new ng.Parser(new ng.Lexer(), compilerConfig);
|
var parser = new ng.Parser(new ng.Lexer());
|
||||||
var _htmlParser = _createHtmlParser(translations, parser);
|
var _htmlParser = _createHtmlParser(translations, parser);
|
||||||
|
|
||||||
var templateParser = new TemplateParser(
|
var templateParser = new TemplateParser(
|
||||||
|
|
|
@ -1246,10 +1246,9 @@ const COMPILER = [
|
||||||
'CompileTypeMetadata.type:CompileTypeMetadata',
|
'CompileTypeMetadata.type:CompileTypeMetadata',
|
||||||
'CompileTypeMetadata.value:any',
|
'CompileTypeMetadata.value:any',
|
||||||
'CompilerConfig',
|
'CompilerConfig',
|
||||||
'CompilerConfig.constructor(genDebugInfo:boolean, logBindingUpdate:boolean, useJit:boolean, renderTypes:RenderTypes=null, interpolateRegexp:RegExp=null, defaultEncapsulation:ViewEncapsulation=null)',
|
'CompilerConfig.constructor(genDebugInfo:boolean, logBindingUpdate:boolean, useJit:boolean, renderTypes:RenderTypes=null, defaultEncapsulation:ViewEncapsulation=null)',
|
||||||
'CompilerConfig.defaultEncapsulation:ViewEncapsulation',
|
'CompilerConfig.defaultEncapsulation:ViewEncapsulation',
|
||||||
'CompilerConfig.genDebugInfo:boolean',
|
'CompilerConfig.genDebugInfo:boolean',
|
||||||
'CompilerConfig.interpolateRegexp:RegExp',
|
|
||||||
'CompilerConfig.logBindingUpdate:boolean',
|
'CompilerConfig.logBindingUpdate:boolean',
|
||||||
'CompilerConfig.renderTypes:RenderTypes',
|
'CompilerConfig.renderTypes:RenderTypes',
|
||||||
'CompilerConfig.useJit:boolean',
|
'CompilerConfig.useJit:boolean',
|
||||||
|
|
Loading…
Reference in New Issue