Skip to content

Commit ad477c7

Browse files
Merge pull request #2691 from Microsoft/isRegExpWeHardlyKnewYe
Remove 'Symbol.isRegExp' and introduce 'RegExp.prototype.flags'
2 parents 6cc1091 + 3d0655d commit ad477c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+156
-140
lines changed

src/lib/core.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ interface RegExp {
823823
*/
824824
test(string: string): boolean;
825825

826-
/** Returns a copy of the text of the regular expression pattern. Read-only. The rgExp argument is a Regular expression object. It can be a variable name or a literal. */
826+
/** Returns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal. */
827827
source: string;
828828

829829
/** Returns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only. */

src/lib/es6.d.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,21 @@ interface SymbolConstructor {
5050
*/
5151
isConcatSpreadable: symbol;
5252

53-
/**
54-
* A Boolean value that if true indicates that an object may be used as a regular expression.
55-
*/
56-
isRegExp: symbol;
57-
5853
/**
5954
* A method that returns the default iterator for an object.Called by the semantics of the
60-
* for-of statement.
55+
* for-of statement.
6156
*/
6257
iterator: symbol;
6358

6459
/**
6560
* A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
66-
* abstract operation.
61+
* abstract operation.
6762
*/
6863
toPrimitive: symbol;
6964

7065
/**
71-
* A String value that is used in the creation of the default string description of an object.
72-
* Called by the built- in method Object.prototype.toString.
66+
* A String value that is used in the creation of the default string description of an object.
67+
* Called by the built-in method Object.prototype.toString.
7368
*/
7469
toStringTag: symbol;
7570

@@ -111,7 +106,7 @@ interface ObjectConstructor {
111106
getOwnPropertySymbols(o: any): symbol[];
112107

113108
/**
114-
* Returns true if the values are the same value, false otherwise.
109+
* Returns true if the values are the same value, false otherwise.
115110
* @param value1 The first value.
116111
* @param value2 The second value.
117112
*/
@@ -598,8 +593,6 @@ interface Math {
598593
}
599594

600595
interface RegExp {
601-
[Symbol.isRegExp]: boolean;
602-
603596
/**
604597
* Matches a string with a regular expression, and returns an array containing the results of
605598
* that search.
@@ -631,6 +624,20 @@ interface RegExp {
631624
*/
632625
split(string: string, limit?: number): string[];
633626

627+
/**
628+
* Returns a string indicating the flags of the regular expression in question. This field is read-only.
629+
* The characters in this string are sequenced and concatenated in the following order:
630+
*
631+
* - "g" for global
632+
* - "i" for ignoreCase
633+
* - "m" for multiline
634+
* - "u" for unicode
635+
* - "y" for sticky
636+
*
637+
* If no flags are set, the value is the empty string.
638+
*/
639+
flags: string;
640+
634641
/**
635642
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
636643
* expression. Default is false. Read-only.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//// [parserSymbolProperty4.ts]
22
declare class C {
3-
[Symbol.isRegExp]: string;
3+
[Symbol.toPrimitive]: string;
44
}
55

66
//// [parserSymbolProperty4.js]

tests/baselines/reference/parserSymbolProperty4.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
declare class C {
33
>C : C
44

5-
[Symbol.isRegExp]: string;
6-
>Symbol.isRegExp : symbol
5+
[Symbol.toPrimitive]: string;
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99
}

tests/baselines/reference/parserSymbolProperty5.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//// [parserSymbolProperty5.ts]
22
class C {
3-
[Symbol.isRegExp]: string;
3+
[Symbol.toPrimitive]: string;
44
}
55

66
//// [parserSymbolProperty5.js]

tests/baselines/reference/parserSymbolProperty5.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
class C {
33
>C : C
44

5-
[Symbol.isRegExp]: string;
6-
>Symbol.isRegExp : symbol
5+
[Symbol.toPrimitive]: string;
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//// [symbolDeclarationEmit1.ts]
22
class C {
3-
[Symbol.isRegExp]: number;
3+
[Symbol.toPrimitive]: number;
44
}
55

66
//// [symbolDeclarationEmit1.js]
@@ -10,5 +10,5 @@ class C {
1010

1111
//// [symbolDeclarationEmit1.d.ts]
1212
declare class C {
13-
[Symbol.isRegExp]: number;
13+
[Symbol.toPrimitive]: number;
1414
}

tests/baselines/reference/symbolDeclarationEmit1.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
class C {
33
>C : C
44

5-
[Symbol.isRegExp]: number;
6-
>Symbol.isRegExp : symbol
5+
[Symbol.toPrimitive]: number;
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
//// [symbolDeclarationEmit11.ts]
22
class C {
33
static [Symbol.iterator] = 0;
4-
static [Symbol.toPrimitive]() { }
5-
static get [Symbol.isRegExp]() { return ""; }
6-
static set [Symbol.isRegExp](x) { }
4+
static [Symbol.isConcatSpreadable]() { }
5+
static get [Symbol.toPrimitive]() { return ""; }
6+
static set [Symbol.toPrimitive](x) { }
77
}
88

99
//// [symbolDeclarationEmit11.js]
1010
class C {
11-
static [Symbol.toPrimitive]() { }
12-
static get [Symbol.isRegExp]() { return ""; }
13-
static set [Symbol.isRegExp](x) { }
11+
static [Symbol.isConcatSpreadable]() { }
12+
static get [Symbol.toPrimitive]() { return ""; }
13+
static set [Symbol.toPrimitive](x) { }
1414
}
1515
C[Symbol.iterator] = 0;
1616

1717

1818
//// [symbolDeclarationEmit11.d.ts]
1919
declare class C {
2020
static [Symbol.iterator]: number;
21-
static [Symbol.toPrimitive](): void;
22-
static [Symbol.isRegExp]: string;
21+
static [Symbol.isConcatSpreadable](): void;
22+
static [Symbol.toPrimitive]: string;
2323
}

tests/baselines/reference/symbolDeclarationEmit11.types

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ class C {
77
>Symbol : SymbolConstructor
88
>iterator : symbol
99

10-
static [Symbol.toPrimitive]() { }
11-
>Symbol.toPrimitive : symbol
10+
static [Symbol.isConcatSpreadable]() { }
11+
>Symbol.isConcatSpreadable : symbol
1212
>Symbol : SymbolConstructor
13-
>toPrimitive : symbol
13+
>isConcatSpreadable : symbol
1414

15-
static get [Symbol.isRegExp]() { return ""; }
16-
>Symbol.isRegExp : symbol
15+
static get [Symbol.toPrimitive]() { return ""; }
16+
>Symbol.toPrimitive : symbol
1717
>Symbol : SymbolConstructor
18-
>isRegExp : symbol
18+
>toPrimitive : symbol
1919

20-
static set [Symbol.isRegExp](x) { }
21-
>Symbol.isRegExp : symbol
20+
static set [Symbol.toPrimitive](x) { }
21+
>Symbol.toPrimitive : symbol
2222
>Symbol : SymbolConstructor
23-
>isRegExp : symbol
23+
>toPrimitive : symbol
2424
>x : string
2525
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(4,28): error TS4031: Public property '[Symbol.iterator]' of exported class has or is using private name 'I'.
2+
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(5,9): error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
23
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(5,33): error TS4073: Parameter 'x' of public method from exported class has or is using private name 'I'.
34
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(6,40): error TS4055: Return type of public method from exported class has or is using private name 'I'.
4-
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(10,34): error TS4037: Parameter '[Symbol.isRegExp]' of public property setter from exported class has or is using private name 'I'.
5+
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(9,13): error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
6+
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(10,13): error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
7+
tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts(10,37): error TS4037: Parameter '[Symbol.toPrimitive]' of public property setter from exported class has or is using private name 'I'.
58

69

7-
==== tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts (4 errors) ====
10+
==== tests/cases/conformance/es6/Symbols/symbolDeclarationEmit12.ts (7 errors) ====
811
module M {
912
interface I { }
1013
export class C {
1114
[Symbol.iterator]: I;
1215
~
1316
!!! error TS4031: Public property '[Symbol.iterator]' of exported class has or is using private name 'I'.
1417
[Symbol.toPrimitive](x: I) { }
18+
~~~~~~~~~~~~~~~~~~~~
19+
!!! error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
1520
~
1621
!!! error TS4073: Parameter 'x' of public method from exported class has or is using private name 'I'.
1722
[Symbol.isConcatSpreadable](): I {
1823
~
1924
!!! error TS4055: Return type of public method from exported class has or is using private name 'I'.
2025
return undefined
2126
}
22-
get [Symbol.isRegExp]() { return undefined; }
23-
set [Symbol.isRegExp](x: I) { }
24-
~
25-
!!! error TS4037: Parameter '[Symbol.isRegExp]' of public property setter from exported class has or is using private name 'I'.
27+
get [Symbol.toPrimitive]() { return undefined; }
28+
~~~~~~~~~~~~~~~~~~~~
29+
!!! error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
30+
set [Symbol.toPrimitive](x: I) { }
31+
~~~~~~~~~~~~~~~~~~~~
32+
!!! error TS2300: Duplicate identifier '[Symbol.toPrimitive]'.
33+
~
34+
!!! error TS4037: Parameter '[Symbol.toPrimitive]' of public property setter from exported class has or is using private name 'I'.
2635
}
2736
}

tests/baselines/reference/symbolDeclarationEmit12.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module M {
77
[Symbol.isConcatSpreadable](): I {
88
return undefined
99
}
10-
get [Symbol.isRegExp]() { return undefined; }
11-
set [Symbol.isRegExp](x: I) { }
10+
get [Symbol.toPrimitive]() { return undefined; }
11+
set [Symbol.toPrimitive](x: I) { }
1212
}
1313
}
1414

@@ -20,8 +20,8 @@ var M;
2020
[Symbol.isConcatSpreadable]() {
2121
return undefined;
2222
}
23-
get [Symbol.isRegExp]() { return undefined; }
24-
set [Symbol.isRegExp](x) { }
23+
get [Symbol.toPrimitive]() { return undefined; }
24+
set [Symbol.toPrimitive](x) { }
2525
}
2626
M.C = C;
2727
})(M || (M = {}));
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//// [symbolDeclarationEmit13.ts]
22
class C {
3-
get [Symbol.isRegExp]() { return ""; }
3+
get [Symbol.toPrimitive]() { return ""; }
44
set [Symbol.toStringTag](x) { }
55
}
66

77
//// [symbolDeclarationEmit13.js]
88
class C {
9-
get [Symbol.isRegExp]() { return ""; }
9+
get [Symbol.toPrimitive]() { return ""; }
1010
set [Symbol.toStringTag](x) { }
1111
}
1212

1313

1414
//// [symbolDeclarationEmit13.d.ts]
1515
declare class C {
16-
[Symbol.isRegExp]: string;
16+
[Symbol.toPrimitive]: string;
1717
[Symbol.toStringTag]: any;
1818
}

tests/baselines/reference/symbolDeclarationEmit13.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
class C {
33
>C : C
44

5-
get [Symbol.isRegExp]() { return ""; }
6-
>Symbol.isRegExp : symbol
5+
get [Symbol.toPrimitive]() { return ""; }
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99

1010
set [Symbol.toStringTag](x) { }
1111
>Symbol.toStringTag : symbol
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//// [symbolDeclarationEmit14.ts]
22
class C {
3-
get [Symbol.isRegExp]() { return ""; }
3+
get [Symbol.toPrimitive]() { return ""; }
44
get [Symbol.toStringTag]() { return ""; }
55
}
66

77
//// [symbolDeclarationEmit14.js]
88
class C {
9-
get [Symbol.isRegExp]() { return ""; }
9+
get [Symbol.toPrimitive]() { return ""; }
1010
get [Symbol.toStringTag]() { return ""; }
1111
}
1212

1313

1414
//// [symbolDeclarationEmit14.d.ts]
1515
declare class C {
16-
[Symbol.isRegExp]: string;
16+
[Symbol.toPrimitive]: string;
1717
[Symbol.toStringTag]: string;
1818
}

tests/baselines/reference/symbolDeclarationEmit14.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
class C {
33
>C : C
44

5-
get [Symbol.isRegExp]() { return ""; }
6-
>Symbol.isRegExp : symbol
5+
get [Symbol.toPrimitive]() { return ""; }
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99

1010
get [Symbol.toStringTag]() { return ""; }
1111
>Symbol.toStringTag : symbol
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//// [symbolDeclarationEmit2.ts]
22
class C {
3-
[Symbol.isRegExp] = "";
3+
[Symbol.toPrimitive] = "";
44
}
55

66
//// [symbolDeclarationEmit2.js]
77
class C {
88
constructor() {
9-
this[Symbol.isRegExp] = "";
9+
this[Symbol.toPrimitive] = "";
1010
}
1111
}
1212

1313

1414
//// [symbolDeclarationEmit2.d.ts]
1515
declare class C {
16-
[Symbol.isRegExp]: string;
16+
[Symbol.toPrimitive]: string;
1717
}

tests/baselines/reference/symbolDeclarationEmit2.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
class C {
33
>C : C
44

5-
[Symbol.isRegExp] = "";
6-
>Symbol.isRegExp : symbol
5+
[Symbol.toPrimitive] = "";
6+
>Symbol.toPrimitive : symbol
77
>Symbol : SymbolConstructor
8-
>isRegExp : symbol
8+
>toPrimitive : symbol
99
}

0 commit comments

Comments
 (0)