From f105983efe970ba3f481e367f41675b493cf9046 Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Thu, 14 Apr 2022 22:59:40 +0900 Subject: [PATCH 1/7] fix: #2206 indexing regexp --- src/resolver.ts | 8 ++++++++ tests/compiler/indexing-regexp.json | 7 +++++++ tests/compiler/indexing-regexp.ts | 1 + 3 files changed, 16 insertions(+) create mode 100644 tests/compiler/indexing-regexp.json create mode 100644 tests/compiler/indexing-regexp.ts diff --git a/src/resolver.ts b/src/resolver.ts index db485a0973..a75888dd3a 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2249,6 +2249,14 @@ export class Resolver extends DiagnosticEmitter { } return null; } + case LiteralKind.REGEXP: { + this.error( + DiagnosticCode.Not_implemented_0, + node.range, + "Regular expressions" + ); + return null; + } } assert(false); return null; diff --git a/tests/compiler/indexing-regexp.json b/tests/compiler/indexing-regexp.json new file mode 100644 index 0000000000..5fc499d9a9 --- /dev/null +++ b/tests/compiler/indexing-regexp.json @@ -0,0 +1,7 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS100: Not implemented: Regular expressions" + ] +} diff --git a/tests/compiler/indexing-regexp.ts b/tests/compiler/indexing-regexp.ts new file mode 100644 index 0000000000..a0e1744c21 --- /dev/null +++ b/tests/compiler/indexing-regexp.ts @@ -0,0 +1 @@ +/ /[0] From 04e92b0747c64f55c5cdc2e1ae4563924a5c306f Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Thu, 14 Apr 2022 23:16:48 +0900 Subject: [PATCH 2/7] #2207 typeof regexp --- tests/compiler/typeof-regexp.json | 7 +++++++ tests/compiler/typeof-regexp.ts | 1 + 2 files changed, 8 insertions(+) create mode 100644 tests/compiler/typeof-regexp.json create mode 100644 tests/compiler/typeof-regexp.ts diff --git a/tests/compiler/typeof-regexp.json b/tests/compiler/typeof-regexp.json new file mode 100644 index 0000000000..5fc499d9a9 --- /dev/null +++ b/tests/compiler/typeof-regexp.json @@ -0,0 +1,7 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS100: Not implemented: Regular expressions" + ] +} diff --git a/tests/compiler/typeof-regexp.ts b/tests/compiler/typeof-regexp.ts new file mode 100644 index 0000000000..672da4a6bd --- /dev/null +++ b/tests/compiler/typeof-regexp.ts @@ -0,0 +1 @@ +typeof / / \ No newline at end of file From cca08ed7b893a1e187fa15779038f4188dabab03 Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Thu, 14 Apr 2022 23:35:33 +0900 Subject: [PATCH 3/7] add semicolon --- tests/compiler/indexes-itself.ts | 1 + tests/compiler/indexing-regexp.ts | 2 +- tests/compiler/typeof-regexp.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 tests/compiler/indexes-itself.ts diff --git a/tests/compiler/indexes-itself.ts b/tests/compiler/indexes-itself.ts new file mode 100644 index 0000000000..3844d0eded --- /dev/null +++ b/tests/compiler/indexes-itself.ts @@ -0,0 +1 @@ +let a = a[0]; diff --git a/tests/compiler/indexing-regexp.ts b/tests/compiler/indexing-regexp.ts index a0e1744c21..9f2e3cb3c7 100644 --- a/tests/compiler/indexing-regexp.ts +++ b/tests/compiler/indexing-regexp.ts @@ -1 +1 @@ -/ /[0] +/ /[0]; diff --git a/tests/compiler/typeof-regexp.ts b/tests/compiler/typeof-regexp.ts index 672da4a6bd..d4efeb76c4 100644 --- a/tests/compiler/typeof-regexp.ts +++ b/tests/compiler/typeof-regexp.ts @@ -1 +1 @@ -typeof / / \ No newline at end of file +typeof / /; From 08df9718f4e7f42a2d9792c1c69dc57f880f6161 Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Thu, 14 Apr 2022 23:40:32 +0900 Subject: [PATCH 4/7] rm unrelatd test --- tests/compiler/indexes-itself.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/compiler/indexes-itself.ts diff --git a/tests/compiler/indexes-itself.ts b/tests/compiler/indexes-itself.ts deleted file mode 100644 index 3844d0eded..0000000000 --- a/tests/compiler/indexes-itself.ts +++ /dev/null @@ -1 +0,0 @@ -let a = a[0]; From 19670ddc947fa895b79f16d1842f3d81330945e5 Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Sun, 17 Apr 2022 10:13:57 +0900 Subject: [PATCH 5/7] check reportMode --- src/resolver.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/resolver.ts b/src/resolver.ts index a75888dd3a..7450a440c2 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2250,11 +2250,14 @@ export class Resolver extends DiagnosticEmitter { return null; } case LiteralKind.REGEXP: { - this.error( - DiagnosticCode.Not_implemented_0, - node.range, - "Regular expressions" - ); + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Not_implemented_0, + node.range, + "Regular expressions" + ); + } + return null; return null; } } From 468619a2201128546852afd19761cba63cb8a7a6 Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Tue, 26 Apr 2022 12:11:31 +0900 Subject: [PATCH 6/7] Update src/resolver.ts Co-authored-by: dcode --- src/resolver.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/resolver.ts b/src/resolver.ts index 7450a440c2..dcc320a084 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2258,7 +2258,6 @@ export class Resolver extends DiagnosticEmitter { ); } return null; - return null; } } assert(false); From 44f7a304fdd5e4abab3417044e913a142f4b83eb Mon Sep 17 00:00:00 2001 From: ANDO Yasushi Date: Fri, 29 Apr 2022 22:49:09 +0900 Subject: [PATCH 7/7] resolve regexp literals to the RegExp type --- src/common.ts | 1 + src/program.ts | 8 ++++++++ src/resolver.ts | 13 +++---------- tests/compiler/indexing-regexp.json | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/common.ts b/src/common.ts index c48f5e7005..c5b4b50fba 100644 --- a/src/common.ts +++ b/src/common.ts @@ -207,6 +207,7 @@ export namespace CommonNames { export const I31ref = "I31ref"; export const Dataref = "Dataref"; export const String = "String"; + export const RegExp = "RegExp"; export const Object = "Object"; export const Array = "Array"; export const StaticArray = "StaticArray"; diff --git a/src/program.ts b/src/program.ts index 4e28ba2478..c290d43dc1 100644 --- a/src/program.ts +++ b/src/program.ts @@ -634,6 +634,14 @@ export class Program extends DiagnosticEmitter { } private _stringInstance: Class | null = null; + /** Gets the standard `RegExp` instance. */ + get regexpInstance(): Class { + var cached = this._regexpInstance; + if (!cached) this._regexpInstance = cached = this.requireClass(CommonNames.RegExp); + return cached; + } + private _regexpInstance: Class | null = null; + /** Gets the standard `Object` instance. */ get objectInstance(): Class { var cached = this._objectInstance; diff --git a/src/resolver.ts b/src/resolver.ts index dcc320a084..e81388c0e6 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2191,6 +2191,9 @@ export class Resolver extends DiagnosticEmitter { case LiteralKind.TEMPLATE: { return this.program.stringInstance; } + case LiteralKind.REGEXP: { + return this.program.regexpInstance; + } case LiteralKind.ARRAY: { let classReference = ctxType.getClass(); if (classReference && classReference.prototype == this.program.arrayPrototype) { @@ -2249,16 +2252,6 @@ export class Resolver extends DiagnosticEmitter { } return null; } - case LiteralKind.REGEXP: { - if (reportMode == ReportMode.REPORT) { - this.error( - DiagnosticCode.Not_implemented_0, - node.range, - "Regular expressions" - ); - } - return null; - } } assert(false); return null; diff --git a/tests/compiler/indexing-regexp.json b/tests/compiler/indexing-regexp.json index 5fc499d9a9..683cd4c33d 100644 --- a/tests/compiler/indexing-regexp.json +++ b/tests/compiler/indexing-regexp.json @@ -2,6 +2,6 @@ "asc_flags": [ ], "stderr": [ - "AS100: Not implemented: Regular expressions" + "TS2329: Index signature is missing in type '~lib/regexp/RegExp'" ] }