Skip to content

Commit a11f683

Browse files
committed
chore(ts): Don't mask the Regexp builtin.
Doing so makes it impossible to compile with TypeScript, since it conflicts with the shape of the Regexp global var defined in the standard lib.
1 parent b65b145 commit a11f683

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

modules/angular2/src/facade/lang.es6

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,20 @@ export class StringWrapper {
6767
return s.charCodeAt(index);
6868
}
6969

70-
static split(s:string, regExp:RegExp) {
71-
return s.split(regExp.multiple);
70+
static split(s:string, regExp) {
71+
return s.split(regExp);
7272
}
7373

7474
static equals(s:string, s2:string):boolean {
7575
return s === s2;
7676
}
7777

78-
static replace(s:string, from , replace:string): string {
79-
if (typeof(from) === "string") {
80-
return s.replace(from, replace);
81-
} else {
82-
return s.replace(from.single, replace);
83-
}
78+
static replace(s:string, from: string, replace:string): string {
79+
return s.replace(from, replace);
8480
}
8581

8682
static replaceAll(s:string, from:RegExp, replace:string):string {
87-
return s.replace(from.multiple, replace);
83+
return s.replace(from, replace);
8884
}
8985

9086
static startsWith(s:string, start:string) {
@@ -96,7 +92,7 @@ export class StringWrapper {
9692
}
9793

9894
static replaceAllMapped(s:string, from:RegExp, cb:Function): string {
99-
return s.replace(from.multiple, function(...matches) {
95+
return s.replace(from, function(...matches) {
10096
// Remove offset & string from the result array
10197
matches.splice(-2, 2);
10298
// The callback receives match, p1, ..., pn
@@ -188,36 +184,25 @@ export class NumberWrapper {
188184
}
189185
}
190186

191-
export var RegExp;
192-
if (assertionsEnabled_) {
193-
RegExp = assert.define('RegExp', function(obj) {
194-
assert(obj).is(assert.structure({
195-
single: _global.RegExp,
196-
multiple: _global.RegExp
197-
}));
198-
});
199-
} else {
200-
RegExp = {};
201-
}
187+
export var RegExp = _global.RegExp;
202188

203189
export class RegExpWrapper {
204190
static create(regExpStr, flags:string = ''):RegExp {
205191
flags = flags.replace(/g/g, '');
206-
return {
207-
multiple: new _global.RegExp(regExpStr, flags + 'g'),
208-
single: new _global.RegExp(regExpStr, flags)
209-
};
192+
return new _global.RegExp(regExpStr, flags + 'g');
210193
}
211194
static firstMatch(regExp, input) {
212-
return input.match(regExp.single);
195+
// Reset multimatch regex state
196+
regExp.lastIndex = 0;
197+
return regExp.exec(input);
213198
}
214199
static matcher(regExp, input) {
215200
// Reset regex state for the case
216201
// someone did not loop over all matches
217202
// last time.
218-
regExp.multiple.lastIndex = 0;
203+
regExp.lastIndex = 0;
219204
return {
220-
re: regExp.multiple,
205+
re: regExp,
221206
input: input
222207
};
223208
}
@@ -241,7 +226,7 @@ export var BaseException = Error;
241226
// JS has NaN !== NaN
242227
export function looseIdentical(a, b):boolean {
243228
return a === b ||
244-
typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
229+
typeof a === "number" && typeof b === "number" && isNaN(a) && isNaN(b);
245230
}
246231

247232
// JS considers NaN is the same as NaN for map Key (while NaN !== NaN otherwise)

0 commit comments

Comments
 (0)