Skip to content

Commit c7f65e8

Browse files
YuichiNukiyamamhegazy
authored andcommitted
support groups property (microsoft#22176)
* support groups property * fix option unittests
1 parent 0a72568 commit c7f65e8

File tree

11 files changed

+193
-9
lines changed

11 files changed

+193
-9
lines changed

Gulpfile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const es2017LibrarySource = [
143143
const es2017LibrarySourceMap = es2017LibrarySource.map(source =>
144144
({ target: "lib." + source, sources: ["header.d.ts", source] }));
145145

146-
const es2018LibrarySource = [];
146+
const es2018LibrarySource = ["es2018.regexp.d.ts"];
147147
const es2018LibrarySourceMap = es2018LibrarySource.map(source =>
148148
({ target: "lib." + source, sources: ["header.d.ts", source] }));
149149

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
206206
return { target: "lib." + source, sources: ["header.d.ts", source] };
207207
});
208208

209-
var es2018LibrarySource = [];
209+
var es2018LibrarySource = ["es2018.regexp.d.ts"];
210210

211211
var es2018LibrarySourceMap = es2018LibrarySource.map(function (source) {
212212
return { target: "lib." + source, sources: ["header.d.ts", source] };

src/compiler/commandLineParser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ namespace ts {
151151
"es2017.string": "lib.es2017.string.d.ts",
152152
"es2017.intl": "lib.es2017.intl.d.ts",
153153
"es2017.typedarrays": "lib.es2017.typedarrays.d.ts",
154+
"es2018.regexp": "lib.es2018.regexp.d.ts",
154155
"esnext.array": "lib.esnext.array.d.ts",
155156
"esnext.asynciterable": "lib.esnext.asynciterable.d.ts",
156157
"esnext.promise": "lib.esnext.promise.d.ts",

src/harness/unittests/commandLineParsing.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
6161
{
6262
errors: [{
63-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
63+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
6464
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
6565
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
6666

@@ -263,7 +263,7 @@ namespace ts {
263263
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
264264
{
265265
errors: [{
266-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
266+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
267267
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
268268
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
269269

@@ -283,7 +283,7 @@ namespace ts {
283283
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
284284
{
285285
errors: [{
286-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
286+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
287287
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
288288
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
289289

src/harness/unittests/convertCompilerOptionsFromJson.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace ts {
266266
file: undefined,
267267
start: 0,
268268
length: 0,
269-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
269+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
270270
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
271271
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
272272
}]
@@ -297,7 +297,7 @@ namespace ts {
297297
file: undefined,
298298
start: 0,
299299
length: 0,
300-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
300+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
301301
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
302302
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
303303
}]
@@ -328,7 +328,7 @@ namespace ts {
328328
file: undefined,
329329
start: 0,
330330
length: 0,
331-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
331+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
332332
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
333333
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
334334
}]
@@ -359,7 +359,7 @@ namespace ts {
359359
file: undefined,
360360
start: 0,
361361
length: 0,
362-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
362+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable', 'esnext.promise'.",
363363
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
364364
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
365365
}]

src/lib/es2018.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/// <reference path="lib.es2017.d.ts" />
2+
/// <reference path="lib.es2018.regexp.d.ts" />

src/lib/es2018.regexp.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface RegExpMatchArray {
2+
groups?: {
3+
[key: string]: string
4+
}
5+
}
6+
7+
interface RegExpExecArray {
8+
groups?: {
9+
[key: string]: string
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [useRegexpGroups.ts]
2+
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
3+
let result = re.exec("2015-01-02");
4+
5+
let date = result[0];
6+
7+
let year1 = result.groups.year;
8+
let year2 = result[1];
9+
10+
let month1 = result.groups.month;
11+
let month2 = result[2];
12+
13+
let day1 = result.groups.day;
14+
let day2 = result[3];
15+
16+
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
17+
18+
//// [useRegexpGroups.js]
19+
var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
20+
var result = re.exec("2015-01-02");
21+
var date = result[0];
22+
var year1 = result.groups.year;
23+
var year2 = result[1];
24+
var month1 = result.groups.month;
25+
var month2 = result[2];
26+
var day1 = result.groups.day;
27+
var day2 = result[3];
28+
var foo = "foo".match(/(?<bar>foo)/).groups.foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/conformance/es2018/useRegexpGroups.ts ===
2+
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
3+
>re : Symbol(re, Decl(useRegexpGroups.ts, 0, 3))
4+
5+
let result = re.exec("2015-01-02");
6+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
7+
>re.exec : Symbol(RegExp.exec, Decl(lib.es5.d.ts, --, --))
8+
>re : Symbol(re, Decl(useRegexpGroups.ts, 0, 3))
9+
>exec : Symbol(RegExp.exec, Decl(lib.es5.d.ts, --, --))
10+
11+
let date = result[0];
12+
>date : Symbol(date, Decl(useRegexpGroups.ts, 3, 3))
13+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
14+
15+
let year1 = result.groups.year;
16+
>year1 : Symbol(year1, Decl(useRegexpGroups.ts, 5, 3))
17+
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
18+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
19+
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
20+
21+
let year2 = result[1];
22+
>year2 : Symbol(year2, Decl(useRegexpGroups.ts, 6, 3))
23+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
24+
25+
let month1 = result.groups.month;
26+
>month1 : Symbol(month1, Decl(useRegexpGroups.ts, 8, 3))
27+
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
28+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
29+
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
30+
31+
let month2 = result[2];
32+
>month2 : Symbol(month2, Decl(useRegexpGroups.ts, 9, 3))
33+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
34+
35+
let day1 = result.groups.day;
36+
>day1 : Symbol(day1, Decl(useRegexpGroups.ts, 11, 3))
37+
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
38+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
39+
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
40+
41+
let day2 = result[3];
42+
>day2 : Symbol(day2, Decl(useRegexpGroups.ts, 12, 3))
43+
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
44+
45+
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
46+
>foo : Symbol(foo, Decl(useRegexpGroups.ts, 14, 3))
47+
>"foo".match(/(?<bar>foo)/)!.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
48+
>"foo".match : Symbol(String.match, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
49+
>match : Symbol(String.match, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
50+
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
=== tests/cases/conformance/es2018/useRegexpGroups.ts ===
2+
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
3+
>re : RegExp
4+
>/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u : RegExp
5+
6+
let result = re.exec("2015-01-02");
7+
>result : RegExpExecArray
8+
>re.exec("2015-01-02") : RegExpExecArray
9+
>re.exec : (string: string) => RegExpExecArray
10+
>re : RegExp
11+
>exec : (string: string) => RegExpExecArray
12+
>"2015-01-02" : "2015-01-02"
13+
14+
let date = result[0];
15+
>date : string
16+
>result[0] : string
17+
>result : RegExpExecArray
18+
>0 : 0
19+
20+
let year1 = result.groups.year;
21+
>year1 : string
22+
>result.groups.year : string
23+
>result.groups : { [key: string]: string; }
24+
>result : RegExpExecArray
25+
>groups : { [key: string]: string; }
26+
>year : string
27+
28+
let year2 = result[1];
29+
>year2 : string
30+
>result[1] : string
31+
>result : RegExpExecArray
32+
>1 : 1
33+
34+
let month1 = result.groups.month;
35+
>month1 : string
36+
>result.groups.month : string
37+
>result.groups : { [key: string]: string; }
38+
>result : RegExpExecArray
39+
>groups : { [key: string]: string; }
40+
>month : string
41+
42+
let month2 = result[2];
43+
>month2 : string
44+
>result[2] : string
45+
>result : RegExpExecArray
46+
>2 : 2
47+
48+
let day1 = result.groups.day;
49+
>day1 : string
50+
>result.groups.day : string
51+
>result.groups : { [key: string]: string; }
52+
>result : RegExpExecArray
53+
>groups : { [key: string]: string; }
54+
>day : string
55+
56+
let day2 = result[3];
57+
>day2 : string
58+
>result[3] : string
59+
>result : RegExpExecArray
60+
>3 : 3
61+
62+
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
63+
>foo : string
64+
>"foo".match(/(?<bar>foo)/)!.groups.foo : string
65+
>"foo".match(/(?<bar>foo)/)!.groups : { [key: string]: string; }
66+
>"foo".match(/(?<bar>foo)/)! : RegExpMatchArray
67+
>"foo".match(/(?<bar>foo)/) : RegExpMatchArray
68+
>"foo".match : { (regexp: string | RegExp): RegExpMatchArray; (matcher: { [Symbol.match](string: string): RegExpMatchArray; }): RegExpMatchArray; }
69+
>"foo" : "foo"
70+
>match : { (regexp: string | RegExp): RegExpMatchArray; (matcher: { [Symbol.match](string: string): RegExpMatchArray; }): RegExpMatchArray; }
71+
>/(?<bar>foo)/ : RegExp
72+
>groups : { [key: string]: string; }
73+
>foo : string
74+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @target: es5
2+
// @lib: es6,es2018
3+
4+
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
5+
let result = re.exec("2015-01-02");
6+
7+
let date = result[0];
8+
9+
let year1 = result.groups.year;
10+
let year2 = result[1];
11+
12+
let month1 = result.groups.month;
13+
let month2 = result[2];
14+
15+
let day1 = result.groups.day;
16+
let day2 = result[3];
17+
18+
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;

0 commit comments

Comments
 (0)