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:
Suguru Inatomi
2016-05-27 05:08:39 +09:00
committed by Miško Hevery
parent 9036f78b74
commit c3fafa0651
10 changed files with 43 additions and 18 deletions

View File

@ -2,11 +2,12 @@ import {ddescribe, describe, it, xit, iit, expect, beforeEach} from '@angular/co
import {isBlank, isPresent} from '../../src/facade/lang';
import {Parser} from '@angular/compiler/src/expression_parser/parser';
import {Unparser} from './unparser';
import {CompilerConfig} from '@angular/compiler';
import {Lexer} from '@angular/compiler/src/expression_parser/lexer';
import {BindingPipe, LiteralPrimitive, AST} from '@angular/compiler/src/expression_parser/ast';
export function main() {
function createParser() { return new Parser(new Lexer()); }
function createParser() { return new Parser(new Lexer(), new CompilerConfig(true, true, true)); }
function parseAction(text, location = null): any {
return createParser().parseAction(text, location);
@ -453,6 +454,14 @@ export function main() {
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", () => {
it('should ignore comments in interpolation expressions',
() => { checkInterpolation('{{a //comment}}', '{{ a }}'); });

View File

@ -1,6 +1,7 @@
import {describe, expect, it, iit, ddescribe} from "@angular/core/testing/testing_internal";
import {I18nHtmlParser} from "@angular/compiler/src/i18n/i18n_html_parser";
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 {Lexer} from "@angular/compiler/src/expression_parser/lexer";
import {StringMapWrapper} from "../../src/facade/collection";
@ -14,7 +15,7 @@ export function main() {
describe('I18nHtmlParser', () => {
function parse(template: string, messages: {[key: string]: string}, implicitTags: string[] = [],
implicitAttrs: {[k: string]: string[]} = {}): HtmlParseTreeResult {
var parser = new Parser(new Lexer());
var parser = new Parser(new Lexer(), new CompilerConfig(true, true, true));
let htmlParser = new HtmlParser();
let msgs = '';

View File

@ -11,6 +11,7 @@ import {
} from '@angular/core/testing/testing_internal';
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 {Message} from '@angular/compiler/src/i18n/message';
import {Parser} from '@angular/compiler/src/expression_parser/parser';
@ -22,7 +23,7 @@ export function main() {
beforeEach(() => {
let htmlParser = new HtmlParser();
var parser = new Parser(new Lexer());
var parser = new Parser(new Lexer(), new CompilerConfig(true, true, true));
extractor = new MessageExtractor(htmlParser, parser, ['i18n-tag'], {'i18n-el': ['trans']});
});

View File

@ -50,10 +50,11 @@ function _createOfflineCompiler(xhr: MockXHR, emitter: OutputEmitter): OfflineCo
xhr.when(`${THIS_MODULE_PATH}/offline_compiler_compa.html`, 'Hello World {{user}}!');
var htmlParser = new HtmlParser();
var normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser);
var config = new CompilerConfig(true, true, true);
return new OfflineCompiler(
normalizer, new TemplateParser(new Parser(new Lexer()), new MockSchemaRegistry({}, {}),
normalizer, new TemplateParser(new Parser(new Lexer(), config), new MockSchemaRegistry({}, {}),
htmlParser, new Console(), []),
new StyleCompiler(urlResolver), new ViewCompiler(new CompilerConfig(true, true, true)),
new StyleCompiler(urlResolver), new ViewCompiler(config),
emitter, xhr);
}
@ -79,4 +80,4 @@ export class SimpleJsImportGenerator implements ImportGenerator {
return importedUrlStr;
}
}
}
}