Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(RegExpWrapper): remove the facade #10512

Merged
merged 1 commit into from Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/@angular/common/src/pipes/number_pipe.ts
Expand Up @@ -9,12 +9,12 @@
import {Pipe, PipeTransform} from '@angular/core';

import {NumberFormatStyle, NumberFormatter} from '../facade/intl';
import {NumberWrapper, RegExpWrapper, Type, isBlank, isNumber, isPresent, isString} from '../facade/lang';
import {NumberWrapper, Type, isBlank, isNumber, isPresent, isString} from '../facade/lang';

import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';

var defaultLocale: string = 'en-US';
const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/g;
const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/;

function formatNumber(
pipe: Type, value: number | string, style: NumberFormatStyle, digits: string,
Expand All @@ -36,8 +36,8 @@ function formatNumber(
}

if (isPresent(digits)) {
var parts = RegExpWrapper.firstMatch(_NUMBER_FORMAT_REGEXP, digits);
if (!parts) {
var parts = digits.match(_NUMBER_FORMAT_REGEXP);
if (parts === null) {
throw new Error(`${digits} is not a valid digit info for number pipes`);
}
if (isPresent(parts[1])) { // min integer digits
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/common/src/pipes/replace_pipe.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {Pipe, PipeTransform} from '@angular/core';
import {RegExpWrapper, StringWrapper, isBlank, isFunction, isNumber, isString} from '../facade/lang';
import {StringWrapper, isBlank, isFunction, isNumber, isString} from '../facade/lang';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ReplacePipe implements PipeTransform {
}

if (isFunction(replacement)) {
const rgxPattern = isString(pattern) ? RegExpWrapper.create(pattern) : pattern;
const rgxPattern = isString(pattern) ? new RegExp(pattern, 'g') : pattern;

return StringWrapper.replaceAllMapped(
input, rgxPattern, <(m: string[]) => string>replacement);
Expand Down
6 changes: 3 additions & 3 deletions modules/@angular/common/test/pipes/replace_pipe_spec.ts
Expand Up @@ -9,7 +9,7 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal';

import {ReplacePipe} from '@angular/common';
import {RegExpWrapper, StringJoiner} from '../../src/facade/lang';
import {StringJoiner} from '../../src/facade/lang';

export function main() {
describe('ReplacePipe', () => {
Expand Down Expand Up @@ -45,9 +45,9 @@ export function main() {
it('should return a new string with the pattern replaced', () => {
var result1 = pipe.transform(str, 'Douglas', 'Hugh');

var result2 = pipe.transform(str, RegExpWrapper.create('a'), '_');
var result2 = pipe.transform(str, /a/g, '_');

var result3 = pipe.transform(str, RegExpWrapper.create('a', 'i'), '_');
var result3 = pipe.transform(str, /a/gi, '_');

var f = ((x: any) => { return 'Adams!'; });

Expand Down
8 changes: 4 additions & 4 deletions modules/@angular/compiler/src/animation/animation_parser.ts
Expand Up @@ -9,7 +9,7 @@
import {ANY_STATE, FILL_STYLE_FLAG} from '../../core_private';
import {CompileAnimationAnimateMetadata, CompileAnimationEntryMetadata, CompileAnimationGroupMetadata, CompileAnimationKeyframesSequenceMetadata, CompileAnimationMetadata, CompileAnimationSequenceMetadata, CompileAnimationStateDeclarationMetadata, CompileAnimationStateTransitionMetadata, CompileAnimationStyleMetadata, CompileAnimationWithStepsMetadata} from '../compile_metadata';
import {ListWrapper, StringMapWrapper} from '../facade/collection';
import {NumberWrapper, RegExpWrapper, isArray, isBlank, isPresent, isString, isStringMap} from '../facade/lang';
import {NumberWrapper, isArray, isBlank, isPresent, isString, isStringMap} from '../facade/lang';
import {Math} from '../facade/math';
import {ParseError} from '../parse_util';

Expand Down Expand Up @@ -465,13 +465,13 @@ function _fillAnimationAstStartingKeyframes(

function _parseTimeExpression(
exp: string | number, errors: AnimationParseError[]): _AnimationTimings {
var regex = /^([\.\d]+)(m?s)(?:\s+([\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?/gi;
var regex = /^([\.\d]+)(m?s)(?:\s+([\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?/i;
var duration: number;
var delay: number = 0;
var easing: string = null;
if (isString(exp)) {
var matches = RegExpWrapper.firstMatch(regex, <string>exp);
if (!isPresent(matches)) {
const matches = exp.match(regex);
if (matches === null) {
errors.push(new AnimationParseError(`The provided timing value "${exp}" is invalid.`));
return new _AnimationTimings(0, 0, null);
}
Expand Down
8 changes: 4 additions & 4 deletions modules/@angular/compiler/src/compile_metadata.ts
Expand Up @@ -11,7 +11,7 @@ import {ChangeDetectionStrategy, SchemaMetadata, ViewEncapsulation} from '@angul
import {LifecycleHooks, reflector} from '../core_private';
import {ListWrapper, StringMapWrapper} from './facade/collection';
import {BaseException, unimplemented} from './facade/exceptions';
import {RegExpWrapper, Type, isBlank, isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';
import {Type, isBlank, isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';

import {CssSelector} from './selector';
import {getUrlScheme} from './url_resolver';
Expand All @@ -23,7 +23,7 @@ import {sanitizeIdentifier, splitAtColon} from './util';
// group 1: "prop" from "[prop]"
// group 2: "event" from "(event)"
// group 3: "@trigger" from "@trigger"
const HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))|(\@[-\w]+)$/g;
const HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))|(\@[-\w]+)$/;
const UNDEFINED = new Object();

export abstract class CompileMetadataWithIdentifier {
Expand Down Expand Up @@ -434,8 +434,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
var hostAttributes: {[key: string]: string} = {};
if (isPresent(host)) {
StringMapWrapper.forEach(host, (value: string, key: string) => {
var matches = RegExpWrapper.firstMatch(HOST_REG_EXP, key);
if (isBlank(matches)) {
const matches = key.match(HOST_REG_EXP);
if (matches === null) {
hostAttributes[key] = value;
} else if (isPresent(matches[1])) {
hostProperties[matches[1]] = value;
Expand Down
6 changes: 3 additions & 3 deletions modules/@angular/compiler/src/expression_parser/parser.ts
Expand Up @@ -11,7 +11,7 @@ import {Injectable} from '@angular/core';
import * as chars from '../chars';
import {ListWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {RegExpWrapper, StringWrapper, escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {StringWrapper, escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../html_parser/interpolation_config';

import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
Expand All @@ -29,8 +29,8 @@ export class TemplateBindingParseResult {
}

function _createInterpolateRegExp(config: InterpolationConfig): RegExp {
const regexp = escapeRegExp(config.start) + '([\\s\\S]*?)' + escapeRegExp(config.end);
return RegExpWrapper.create(regexp, 'g');
const pattern = escapeRegExp(config.start) + '([\\s\\S]*?)' + escapeRegExp(config.end);
return new RegExp(pattern, 'g');
}

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/compiler/src/output/js_emitter.ts
Expand Up @@ -8,7 +8,7 @@

import {BaseException} from '@angular/core';

import {RegExpWrapper, StringWrapper, evalExpression, isBlank, isPresent, isString} from '../facade/lang';
import {StringWrapper, evalExpression, isBlank, isPresent, isString} from '../facade/lang';

import {EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
Expand Down
8 changes: 4 additions & 4 deletions modules/@angular/compiler/src/output/path_util.ts
Expand Up @@ -9,11 +9,11 @@
import {Injectable} from '@angular/core';

import {BaseException} from '../facade/exceptions';
import {Math, RegExpWrapper, isBlank, isPresent} from '../facade/lang';
import {Math, isBlank, isPresent} from '../facade/lang';


// asset:<package-name>/<realm>/<path-to-module>
var _ASSET_URL_RE = /asset:([^\/]+)\/([^\/]+)\/(.+)/g;
var _ASSET_URL_RE = /asset:([^\/]+)\/([^\/]+)\/(.+)/;

/**
* Interface that defines how import statements should be generated.
Expand All @@ -26,8 +26,8 @@ export abstract class ImportGenerator {

export class AssetUrl {
static parse(url: string, allowNonMatching: boolean = true): AssetUrl {
var match = RegExpWrapper.firstMatch(_ASSET_URL_RE, url);
if (isPresent(match)) {
const match = url.match(_ASSET_URL_RE);
if (match !== null) {
return new AssetUrl(match[1], match[2], match[3]);
}
if (allowNonMatching) {
Expand Down
21 changes: 11 additions & 10 deletions modules/@angular/compiler/src/selector.ts
Expand Up @@ -8,17 +8,18 @@

import {ListWrapper} from './facade/collection';
import {BaseException} from './facade/exceptions';
import {RegExpMatcherWrapper, RegExpWrapper, StringWrapper, isBlank, isPresent} from './facade/lang';
import {StringWrapper, isBlank, isPresent} from './facade/lang';

const _EMPTY_ATTR_VALUE = '';

const _SELECTOR_REGEXP = RegExpWrapper.create(
'(\\:not\\()|' + //":not("
'([-\\w]+)|' + // "tag"
'(?:\\.([-\\w]+))|' + // ".class"
'(?:\\[([-\\w*]+)(?:=([^\\]]*))?\\])|' + // "[name]", "[name=value]" or "[name*=value]"
'(\\))|' + // ")"
'(\\s*,\\s*)'); // ","
const _SELECTOR_REGEXP = new RegExp(
'(\\:not\\()|' + //":not("
'([-\\w]+)|' + // "tag"
'(?:\\.([-\\w]+))|' + // ".class"
'(?:\\[([-\\w*]+)(?:=([^\\]]*))?\\])|' + // "[name]", "[name=value]" or "[name*=value]"
'(\\))|' + // ")"
'(\\s*,\\s*)', // ","
'g');

/**
* A css selector contains an element name,
Expand All @@ -41,11 +42,11 @@ export class CssSelector {
res.push(cssSel);
};
var cssSelector = new CssSelector();
var matcher = RegExpWrapper.matcher(_SELECTOR_REGEXP, selector);
var match: string[];
var current = cssSelector;
var inNot = false;
while (isPresent(match = RegExpMatcherWrapper.next(matcher))) {
_SELECTOR_REGEXP.lastIndex = 0;
while (isPresent(match = _SELECTOR_REGEXP.exec(selector))) {
if (isPresent(match[1])) {
if (inNot) {
throw new BaseException('Nesting :not is not allowed in a selector');
Expand Down
25 changes: 12 additions & 13 deletions modules/@angular/compiler/src/shadow_css.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {ListWrapper} from './facade/collection';
import {RegExpMatcherWrapper, RegExpWrapper, StringWrapper, isBlank, isPresent} from './facade/lang';
import {StringWrapper, isBlank, isPresent} from './facade/lang';

/**
* This file is a port of shadowCSS from webcomponents.js to TypeScript.
Expand Down Expand Up @@ -244,9 +244,9 @@ export class ShadowCss {
**/
private _extractUnscopedRulesFromCssText(cssText: string): string {
// Difference with webcomponents.js: does not handle comments
var r = '', m: any /** TODO #9100 */;
var matcher = RegExpWrapper.matcher(_cssContentUnscopedRuleRe, cssText);
while (isPresent(m = RegExpMatcherWrapper.next(matcher))) {
var r = '', m: RegExpExecArray;
_cssContentUnscopedRuleRe.lastIndex = 0;
while ((m = _cssContentUnscopedRuleRe.exec(cssText)) !== null) {
var rule = m[0];
rule = StringWrapper.replace(rule, m[2], '');
rule = StringWrapper.replace(rule, m[1], m[3]);
Expand Down Expand Up @@ -362,15 +362,15 @@ export class ShadowCss {

private _selectorNeedsScoping(selector: string, scopeSelector: string): boolean {
var re = this._makeScopeMatcher(scopeSelector);
return !isPresent(RegExpWrapper.firstMatch(re, selector));
return !re.test(selector);
}

private _makeScopeMatcher(scopeSelector: string): RegExp {
var lre = /\[/g;
var rre = /\]/g;
scopeSelector = StringWrapper.replaceAll(scopeSelector, lre, '\\[');
scopeSelector = StringWrapper.replaceAll(scopeSelector, rre, '\\]');
return RegExpWrapper.create('^(' + scopeSelector + ')' + _selectorReSuffix, 'm');
return new RegExp('^(' + scopeSelector + ')' + _selectorReSuffix, 'm');
}

private _applySelectorScope(selector: string, scopeSelector: string, hostSelector: string):
Expand All @@ -382,7 +382,7 @@ export class ShadowCss {
// scope via name and [is=name]
private _applySimpleSelectorScope(selector: string, scopeSelector: string, hostSelector: string):
string {
if (isPresent(RegExpWrapper.firstMatch(_polyfillHostRe, selector))) {
if (_polyfillHostRe.test(selector)) {
var replaceBy = this.strictStyling ? `[${hostSelector}]` : scopeSelector;
selector = StringWrapper.replace(selector, _polyfillHostNoCombinator, replaceBy);
return StringWrapper.replaceAll(selector, _polyfillHostRe, replaceBy + ' ');
Expand All @@ -407,9 +407,8 @@ export class ShadowCss {
var t = StringWrapper.replaceAll(p.trim(), _polyfillHostRe, '');
if (t.length > 0 && !ListWrapper.contains(splits, t) &&
!StringWrapper.contains(t, attrName)) {
var re = /([^:]*)(:*)(.*)/g;
var m = RegExpWrapper.firstMatch(re, t);
if (isPresent(m)) {
const m = t.match(/([^:]*)(:*)(.*)/);
if (m !== null) {
p = m[1] + attrName + m[2] + m[3];
}
}
Expand Down Expand Up @@ -437,8 +436,8 @@ var _polyfillHostContext = '-shadowcsscontext';
var _parenSuffix = ')(?:\\((' +
'(?:\\([^)(]*\\)|[^)(]*)+?' +
')\\))?([^,{]*)';
var _cssColonHostRe = RegExpWrapper.create('(' + _polyfillHost + _parenSuffix, 'im');
var _cssColonHostContextRe = RegExpWrapper.create('(' + _polyfillHostContext + _parenSuffix, 'im');
var _cssColonHostRe = new RegExp('(' + _polyfillHost + _parenSuffix, 'gim');
var _cssColonHostContextRe = new RegExp('(' + _polyfillHostContext + _parenSuffix, 'gim');
var _polyfillHostNoCombinator = _polyfillHost + '-no-combinator';
var _shadowDOMSelectorsRe = [
/::shadow/g, /::content/g,
Expand All @@ -451,7 +450,7 @@ var _shadowDOMSelectorsRe = [
];
var _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)/g;
var _selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$';
var _polyfillHostRe = RegExpWrapper.create(_polyfillHost, 'im');
var _polyfillHostRe = new RegExp(_polyfillHost, 'im');
var _colonHostRe = /:host/gim;
var _colonHostContextRe = /:host-context/gim;

Expand Down
10 changes: 4 additions & 6 deletions modules/@angular/compiler/src/style_url_resolver.ts
Expand Up @@ -9,7 +9,7 @@
// Some of the code comes from WebComponents.JS
// https://github.com/webcomponents/webcomponentsjs/blob/master/src/HTMLImports/path.js

import {RegExpWrapper, StringWrapper, isBlank, isPresent} from './facade/lang';
import {StringWrapper, isBlank, isPresent} from './facade/lang';

import {UrlResolver} from './url_resolver';

Expand All @@ -19,8 +19,8 @@ export class StyleWithImports {

export function isStyleUrlResolvable(url: string): boolean {
if (isBlank(url) || url.length === 0 || url[0] == '/') return false;
var schemeMatch = RegExpWrapper.firstMatch(_urlWithSchemaRe, url);
return isBlank(schemeMatch) || schemeMatch[1] == 'package' || schemeMatch[1] == 'asset';
const schemeMatch = url.match(_urlWithSchemaRe);
return schemeMatch === null || schemeMatch[1] == 'package' || schemeMatch[1] == 'asset';
}

/**
Expand All @@ -43,6 +43,4 @@ export function extractStyleUrls(
}

var _cssImportRe = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
// TODO: can't use /^[^:/?#.]+:/g due to clang-format bug:
// https://github.com/angular/angular/issues/4596
var _urlWithSchemaRe = /^([a-zA-Z\-\+\.]+):/g;
var _urlWithSchemaRe = /^([^:/?#]+):/;
Expand Up @@ -10,7 +10,7 @@ import {Inject, Injectable, OpaqueToken, Optional, SchemaMetadata, SecurityConte
import {Console, MAX_INTERPOLATION_VALUES} from '../../core_private';

import {ListWrapper, StringMapWrapper, SetWrapper,} from '../facade/collection';
import {RegExpWrapper, isPresent, isBlank} from '../facade/lang';
import {isPresent, isBlank} from '../facade/lang';
import {BaseException} from '../facade/exceptions';
import {EmptyExpr, AST, Interpolation, ASTWithSource, TemplateBinding, RecursiveAstVisitor, BindingPipe, ParserError} from '../expression_parser/ast';
import {Parser} from '../expression_parser/parser';
Expand Down Expand Up @@ -42,7 +42,7 @@ import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer'
// Group 10 = identifier inside []
// Group 11 = identifier inside ()
const BIND_NAME_REGEXP =
/^(?:(?:(?:(bind-)|(var-)|(let-)|(ref-|#)|(on-)|(bindon-)|(animate-|@))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/g;
/^(?:(?:(?:(bind-)|(var-)|(let-)|(ref-|#)|(on-)|(bindon-)|(animate-|@))(.+))|\[\(([^\)]+)\)\]|\[([^\]]+)\]|\(([^\)]+)\))$/;

const TEMPLATE_ELEMENT = 'template';
const TEMPLATE_ATTR = 'template';
Expand Down Expand Up @@ -488,9 +488,9 @@ class TemplateParseVisitor implements html.Visitor {
targetRefs: ElementOrDirectiveRef[], targetVars: VariableAst[]): boolean {
const attrName = this._normalizeAttributeName(attr.name);
const attrValue = attr.value;
const bindParts = RegExpWrapper.firstMatch(BIND_NAME_REGEXP, attrName);
const bindParts = attrName.match(BIND_NAME_REGEXP);
let hasBinding = false;
if (isPresent(bindParts)) {
if (bindParts !== null) {
hasBinding = true;
if (isPresent(bindParts[1])) { // match: bind-prop
this._parsePropertyOrAnimation(
Expand Down
6 changes: 3 additions & 3 deletions modules/@angular/compiler/src/url_resolver.ts
Expand Up @@ -8,7 +8,7 @@

import {Inject, Injectable, PACKAGE_ROOT_URL} from '@angular/core';

import {StringWrapper, isPresent, isBlank, RegExpWrapper,} from './facade/lang';
import {StringWrapper, isBlank, isPresent} from './facade/lang';


const _ASSET_SCHEME = 'asset:';
Expand Down Expand Up @@ -211,7 +211,7 @@ function _buildFromEncodedParts(
* @type {!RegExp}
* @internal
*/
var _splitRe = RegExpWrapper.create(
var _splitRe = new RegExp(
'^' +
'(?:' +
'([^:/?#.]+)' + // scheme - ignore special characters
Expand Down Expand Up @@ -260,7 +260,7 @@ enum _ComponentIndex {
* arbitrary strings may still look like path names.
*/
function _split(uri: string): Array<string|any> {
return RegExpWrapper.firstMatch(_splitRe, uri);
return uri.match(_splitRe);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/compiler/test/shadow_css_spec.ts
Expand Up @@ -9,7 +9,7 @@
import {describe, beforeEach, it, expect, ddescribe, iit,} from '@angular/core/testing/testing_internal';
import {ShadowCss, processRules, CssRule} from '@angular/compiler/src/shadow_css';

import {RegExpWrapper, StringWrapper, isPresent} from '../src/facade/lang';
import {StringWrapper, isPresent} from '../src/facade/lang';
import {normalizeCSS} from '@angular/platform-browser/testing/browser_util';

export function main() {
Expand Down
2 changes: 1 addition & 1 deletion modules/@angular/facade/src/intl.ts
Expand Up @@ -198,7 +198,7 @@ function dateFormatter(format: string, date: Date, locale: string): string {
if (datePartsFormatterCache.has(format)) {
parts = datePartsFormatterCache.get(format);
} else {
var matchs = DATE_FORMATS_SPLIT.exec(format);
const matches = DATE_FORMATS_SPLIT.exec(format);

while (format) {
match = DATE_FORMATS_SPLIT.exec(format);
Expand Down