support groups property (#22176)

* support groups property

* fix option unittests
This commit is contained in:
Yuichi Nukiyama
2018-03-02 05:58:25 +09:00
committed by Mohamed Hegazy
parent 0a72568e59
commit c7f65e8725
11 changed files with 193 additions and 9 deletions

View File

@@ -143,7 +143,7 @@ const es2017LibrarySource = [
const es2017LibrarySourceMap = es2017LibrarySource.map(source =>
({ target: "lib." + source, sources: ["header.d.ts", source] }));
const es2018LibrarySource = [];
const es2018LibrarySource = ["es2018.regexp.d.ts"];
const es2018LibrarySourceMap = es2018LibrarySource.map(source =>
({ target: "lib." + source, sources: ["header.d.ts", source] }));

View File

@@ -206,7 +206,7 @@ var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };
});
var es2018LibrarySource = [];
var es2018LibrarySource = ["es2018.regexp.d.ts"];
var es2018LibrarySourceMap = es2018LibrarySource.map(function (source) {
return { target: "lib." + source, sources: ["header.d.ts", source] };

View File

@@ -151,6 +151,7 @@ namespace ts {
"es2017.string": "lib.es2017.string.d.ts",
"es2017.intl": "lib.es2017.intl.d.ts",
"es2017.typedarrays": "lib.es2017.typedarrays.d.ts",
"es2018.regexp": "lib.es2018.regexp.d.ts",
"esnext.array": "lib.esnext.array.d.ts",
"esnext.asynciterable": "lib.esnext.asynciterable.d.ts",
"esnext.promise": "lib.esnext.promise.d.ts",

View File

@@ -60,7 +60,7 @@ namespace ts {
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
{
errors: [{
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'.",
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'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
@@ -263,7 +263,7 @@ namespace ts {
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
{
errors: [{
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'.",
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'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
@@ -283,7 +283,7 @@ namespace ts {
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
{
errors: [{
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'.",
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'.",
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

View File

@@ -266,7 +266,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
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'.",
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'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -297,7 +297,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
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'.",
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'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -328,7 +328,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
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'.",
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'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -359,7 +359,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
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'.",
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'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]

1
src/lib/es2018.d.ts vendored
View File

@@ -1 +1,2 @@
/// <reference path="lib.es2017.d.ts" />
/// <reference path="lib.es2018.regexp.d.ts" />

11
src/lib/es2018.regexp.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
interface RegExpMatchArray {
groups?: {
[key: string]: string
}
}
interface RegExpExecArray {
groups?: {
[key: string]: string
}
}

View File

@@ -0,0 +1,28 @@
//// [useRegexpGroups.ts]
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
let result = re.exec("2015-01-02");
let date = result[0];
let year1 = result.groups.year;
let year2 = result[1];
let month1 = result.groups.month;
let month2 = result[2];
let day1 = result.groups.day;
let day2 = result[3];
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
//// [useRegexpGroups.js]
var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
var result = re.exec("2015-01-02");
var date = result[0];
var year1 = result.groups.year;
var year2 = result[1];
var month1 = result.groups.month;
var month2 = result[2];
var day1 = result.groups.day;
var day2 = result[3];
var foo = "foo".match(/(?<bar>foo)/).groups.foo;

View File

@@ -0,0 +1,51 @@
=== tests/cases/conformance/es2018/useRegexpGroups.ts ===
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
>re : Symbol(re, Decl(useRegexpGroups.ts, 0, 3))
let result = re.exec("2015-01-02");
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
>re.exec : Symbol(RegExp.exec, Decl(lib.es5.d.ts, --, --))
>re : Symbol(re, Decl(useRegexpGroups.ts, 0, 3))
>exec : Symbol(RegExp.exec, Decl(lib.es5.d.ts, --, --))
let date = result[0];
>date : Symbol(date, Decl(useRegexpGroups.ts, 3, 3))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
let year1 = result.groups.year;
>year1 : Symbol(year1, Decl(useRegexpGroups.ts, 5, 3))
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
let year2 = result[1];
>year2 : Symbol(year2, Decl(useRegexpGroups.ts, 6, 3))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
let month1 = result.groups.month;
>month1 : Symbol(month1, Decl(useRegexpGroups.ts, 8, 3))
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
let month2 = result[2];
>month2 : Symbol(month2, Decl(useRegexpGroups.ts, 9, 3))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
let day1 = result.groups.day;
>day1 : Symbol(day1, Decl(useRegexpGroups.ts, 11, 3))
>result.groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
>groups : Symbol(RegExpExecArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
let day2 = result[3];
>day2 : Symbol(day2, Decl(useRegexpGroups.ts, 12, 3))
>result : Symbol(result, Decl(useRegexpGroups.ts, 1, 3))
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
>foo : Symbol(foo, Decl(useRegexpGroups.ts, 14, 3))
>"foo".match(/(?<bar>foo)/)!.groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))
>"foo".match : Symbol(String.match, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>match : Symbol(String.match, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>groups : Symbol(RegExpMatchArray.groups, Decl(lib.es2018.regexp.d.ts, --, --))

View File

@@ -0,0 +1,74 @@
=== tests/cases/conformance/es2018/useRegexpGroups.ts ===
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
>re : RegExp
>/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u : RegExp
let result = re.exec("2015-01-02");
>result : RegExpExecArray
>re.exec("2015-01-02") : RegExpExecArray
>re.exec : (string: string) => RegExpExecArray
>re : RegExp
>exec : (string: string) => RegExpExecArray
>"2015-01-02" : "2015-01-02"
let date = result[0];
>date : string
>result[0] : string
>result : RegExpExecArray
>0 : 0
let year1 = result.groups.year;
>year1 : string
>result.groups.year : string
>result.groups : { [key: string]: string; }
>result : RegExpExecArray
>groups : { [key: string]: string; }
>year : string
let year2 = result[1];
>year2 : string
>result[1] : string
>result : RegExpExecArray
>1 : 1
let month1 = result.groups.month;
>month1 : string
>result.groups.month : string
>result.groups : { [key: string]: string; }
>result : RegExpExecArray
>groups : { [key: string]: string; }
>month : string
let month2 = result[2];
>month2 : string
>result[2] : string
>result : RegExpExecArray
>2 : 2
let day1 = result.groups.day;
>day1 : string
>result.groups.day : string
>result.groups : { [key: string]: string; }
>result : RegExpExecArray
>groups : { [key: string]: string; }
>day : string
let day2 = result[3];
>day2 : string
>result[3] : string
>result : RegExpExecArray
>3 : 3
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
>foo : string
>"foo".match(/(?<bar>foo)/)!.groups.foo : string
>"foo".match(/(?<bar>foo)/)!.groups : { [key: string]: string; }
>"foo".match(/(?<bar>foo)/)! : RegExpMatchArray
>"foo".match(/(?<bar>foo)/) : RegExpMatchArray
>"foo".match : { (regexp: string | RegExp): RegExpMatchArray; (matcher: { [Symbol.match](string: string): RegExpMatchArray; }): RegExpMatchArray; }
>"foo" : "foo"
>match : { (regexp: string | RegExp): RegExpMatchArray; (matcher: { [Symbol.match](string: string): RegExpMatchArray; }): RegExpMatchArray; }
>/(?<bar>foo)/ : RegExp
>groups : { [key: string]: string; }
>foo : string

View File

@@ -0,0 +1,18 @@
// @target: es5
// @lib: es6,es2018
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
let result = re.exec("2015-01-02");
let date = result[0];
let year1 = result.groups.year;
let year2 = result[1];
let month1 = result.groups.month;
let month2 = result[2];
let day1 = result.groups.day;
let day2 = result[3];
let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;