refactor(RegExpWrapper): remove the facade (#10512)

This commit is contained in:
Jason Choi
2016-08-05 09:50:49 -07:00
committed by Alex Rickabaugh
parent b4613ab2d2
commit 83e2d3d1cb
31 changed files with 112 additions and 194 deletions

View File

@ -8,7 +8,7 @@
import {StringMapWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {RegExpWrapper, StringWrapper, isBlank, isPresent} from '../../facade/lang';
import {StringWrapper, isBlank, isPresent} from '../../facade/lang';
import {RootUrl, Url, convertUrlParamsToArray} from '../../url_parser';
import {TouchMap, normalizeString} from '../../utils';
@ -60,7 +60,7 @@ class StaticPathSegment implements PathSegment {
* a matching `Instruction`.
*/
class DynamicPathSegment implements PathSegment {
static paramMatcher = /^:([^\/]+)$/g;
static paramMatcher = /^:([^\/]+)$/;
specificity = '1';
hash = ':';
constructor(public name: string) {}
@ -80,7 +80,7 @@ class DynamicPathSegment implements PathSegment {
* be provided to a matching `Instruction`.
*/
class StarPathSegment implements PathSegment {
static wildcardMatcher = /^\*([^\/]+)$/g;
static wildcardMatcher = /^\*([^\/]+)$/;
specificity = '0';
hash = '*';
constructor(public name: string) {}
@ -211,12 +211,11 @@ export class ParamRoutePath implements RoutePath {
var limit = segmentStrings.length - 1;
for (var i = 0; i <= limit; i++) {
var segment = segmentStrings[i], match: any /** TODO #9100 */;
var segment = segmentStrings[i], match: RegExpMatchArray;
if (isPresent(match = RegExpWrapper.firstMatch(DynamicPathSegment.paramMatcher, segment))) {
if (isPresent(match = segment.match(DynamicPathSegment.paramMatcher))) {
this._segments.push(new DynamicPathSegment(match[1]));
} else if (isPresent(
match = RegExpWrapper.firstMatch(StarPathSegment.wildcardMatcher, segment))) {
} else if (isPresent(match = segment.match(StarPathSegment.wildcardMatcher))) {
this._segments.push(new StarPathSegment(match[1]));
} else if (segment == '...') {
if (i < limit) {
@ -272,13 +271,13 @@ export class ParamRoutePath implements RoutePath {
throw new BaseException(
`Path "${path}" should not include "#". Use "HashLocationStrategy" instead.`);
}
var illegalCharacter = RegExpWrapper.firstMatch(ParamRoutePath.RESERVED_CHARS, path);
const illegalCharacter = path.match(ParamRoutePath.RESERVED_CHARS);
if (isPresent(illegalCharacter)) {
throw new BaseException(
`Path "${path}" contains "${illegalCharacter[0]}" which is not allowed in a route config.`);
}
}
static RESERVED_CHARS = RegExpWrapper.create('//|\\(|\\)|;|\\?|=');
static RESERVED_CHARS = new RegExp('//|\\(|\\)|;|\\?|=');
}
let REGEXP_PERCENT = /%/g;

View File

@ -8,7 +8,7 @@
import {BaseException} from '@angular/core';
import {RegExpMatcherWrapper, RegExpWrapper, isBlank} from '../../facade/lang';
import {isBlank} from '../../facade/lang';
import {Url} from '../../url_parser';
import {GeneratedUrl, MatchedUrl, RoutePath} from './route_path';
@ -20,10 +20,8 @@ function computeNumberOfRegexGroups(regex: string): number {
// cleverly compute regex groups by appending an alternative empty matching
// pattern and match against an empty string, the resulting match still
// receives all the other groups
var test_regex = RegExpWrapper.create(regex + '|');
var matcher = RegExpWrapper.matcher(test_regex, '');
var match = RegExpMatcherWrapper.next(matcher);
return match.length;
var testRegex = new RegExp(regex + '|');
return testRegex.exec('').length;
}
export class RegexRoutePath implements RoutePath {
@ -37,7 +35,7 @@ export class RegexRoutePath implements RoutePath {
private _reString: string, private _serializer: RegexSerializer,
private _groupNames?: Array<string>) {
this.hash = this._reString;
this._regex = RegExpWrapper.create(this._reString);
this._regex = new RegExp(this._reString);
if (this._groupNames != null) {
var groups = computeNumberOfRegexGroups(this._reString);
if (groups != _groupNames.length) {
@ -52,8 +50,7 @@ each matching group and a name for the complete match as its first element of re
matchUrl(url: Url): MatchedUrl {
var urlPath = url.toString();
var params: {[key: string]: string} = {};
var matcher = RegExpWrapper.matcher(this._regex, urlPath);
var match = RegExpMatcherWrapper.next(matcher);
var match = urlPath.match(this._regex);
if (isBlank(match)) {
return null;

View File

@ -8,7 +8,7 @@
import {StringMapWrapper} from '../src/facade/collection';
import {BaseException} from '../src/facade/exceptions';
import {RegExpWrapper, isBlank, isPresent} from '../src/facade/lang';
import {isBlank, isPresent} from '../src/facade/lang';
export function convertUrlParamsToArray(urlParams: {[key: string]: any}): string[] {
var paramsArray: any[] /** TODO #9100 */ = [];
@ -89,15 +89,15 @@ export function pathSegmentsToUrl(pathSegments: string[]): Url {
return url;
}
var SEGMENT_RE = RegExpWrapper.create('^[^\\/\\(\\)\\?;=&#]+');
const SEGMENT_RE = /^[^\/\(\)\?;=&#]+/;
function matchUrlSegment(str: string): string {
var match = RegExpWrapper.firstMatch(SEGMENT_RE, str);
return isPresent(match) ? match[0] : '';
const match = str.match(SEGMENT_RE);
return match !== null ? match[0] : '';
}
var QUERY_PARAM_VALUE_RE = RegExpWrapper.create('^[^\\(\\)\\?;&#]+');
const QUERY_PARAM_VALUE_RE = /^[^\(\)\?;&#]+/;
function matchUrlQueryParamValue(str: string): string {
var match = RegExpWrapper.firstMatch(QUERY_PARAM_VALUE_RE, str);
return isPresent(match) ? match[0] : '';
var match = str.match(QUERY_PARAM_VALUE_RE);
return match !== null ? match[0] : '';
}
export class UrlParser {