refactor(RegExp): use /.../ to create RegExp literal

fixes #2691
This commit is contained in:
Victor Berchet
2015-06-23 12:46:38 +02:00
parent 258da88765
commit 447926dc08
17 changed files with 62 additions and 84 deletions
@@ -23,11 +23,10 @@ import {
} from 'angular2/src/change_detection/parser/ast';
import {StringWrapper, RegExpWrapper, isPresent, isString} from 'angular2/src/facade/lang';
var quoteRegExp = RegExpWrapper.create('"');
import {StringWrapper, isPresent, isString} from 'angular2/src/facade/lang';
export class Unparser implements AstVisitor {
private static _quoteRegExp = /"/g;
private _expression: string;
unparse(ast: AST) {
@@ -151,7 +150,7 @@ export class Unparser implements AstVisitor {
visitLiteralPrimitive(ast: LiteralPrimitive) {
if (isString(ast.value)) {
this._expression += `"${StringWrapper.replaceAll(ast.value, quoteRegExp, '\"')}"`;
this._expression += `"${StringWrapper.replaceAll(ast.value, Unparser._quoteRegExp, '\"')}"`;
} else {
this._expression += `${ast.value}`;
}
+1 -1
View File
@@ -10,7 +10,7 @@ import {
export function main() {
describe('RegExp', () => {
it('should expose the index for each match', () => {
var re = RegExpWrapper.create('(!)');
var re = /(!)/g;
var matcher = RegExpWrapper.matcher(re, '0!23!567!!');
var indexes = [];
var m;
@@ -20,7 +20,7 @@ export function main() {
function s(css: string, contentAttr: string, hostAttr: string = '') {
var shadowCss = new ShadowCss();
var shim = shadowCss.shimCssText(css, contentAttr, hostAttr);
var nlRegexp = RegExpWrapper.create('\\n');
var nlRegexp = /\n/g;
return normalizeCSS(StringWrapper.replaceAll(shim, nlRegexp, ''));
}
@@ -61,8 +61,7 @@ export function main() {
isPresent(DOM.defaultDoc().body.style.animationName)) {
it('should handle keyframes rules', () => {
var css = '@keyframes foo {0% {transform: translate(-50%) scaleX(0);}}';
var passRe = RegExpWrapper.create(
'@keyframes foo {\\s*0% {\\s*transform:translate\\(-50%\\) scaleX\\(0\\);\\s*}\\s*}');
var passRe = /@keyframes foo {\s*0% {\s*transform:translate\(-50%\) scaleX\(0\);\s*}\s*}/g;
expect(RegExpWrapper.test(passRe, s(css, 'a'))).toEqual(true);
});
}
@@ -70,8 +69,8 @@ export function main() {
if (DOM.getUserAgent().indexOf('AppleWebKit') > -1) {
it('should handle -webkit-keyframes rules', () => {
var css = '@-webkit-keyframes foo {0% {-webkit-transform: translate(-50%) scaleX(0);}}';
var passRe = RegExpWrapper.create(
'@-webkit-keyframes foo {\\s*0% {\\s*(-webkit-)*transform:translate\\(-50%\\) scaleX\\(0\\);\\s*}}');
var passRe =
/@-webkit-keyframes foo {\s*0% {\s*(-webkit-)*transform:translate\(-50%\) scaleX\(0\);\s*}}/g;
expect(RegExpWrapper.test(passRe, s(css, 'a'))).toEqual(true);
});
}