Skip to content

Commit 3a5b51d

Browse files
authoredJul 23, 2022
fix: Add missing resolve of RegExp literals (#2263)
1 parent 92ea1c4 commit 3a5b51d

File tree

7 files changed

+28
-0
lines changed

7 files changed

+28
-0
lines changed
 

‎src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export namespace CommonNames {
210210
export const I31ref = "I31ref";
211211
export const Dataref = "Dataref";
212212
export const String = "String";
213+
export const RegExp = "RegExp";
213214
export const Object = "Object";
214215
export const Array = "Array";
215216
export const StaticArray = "StaticArray";

‎src/program.ts

+8
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,14 @@ export class Program extends DiagnosticEmitter {
634634
}
635635
private _stringInstance: Class | null = null;
636636

637+
/** Gets the standard `RegExp` instance. */
638+
get regexpInstance(): Class {
639+
var cached = this._regexpInstance;
640+
if (!cached) this._regexpInstance = cached = this.requireClass(CommonNames.RegExp);
641+
return cached;
642+
}
643+
private _regexpInstance: Class | null = null;
644+
637645
/** Gets the standard `Object` instance. */
638646
get objectInstance(): Class {
639647
var cached = this._objectInstance;

‎src/resolver.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,9 @@ export class Resolver extends DiagnosticEmitter {
22312231
case LiteralKind.TEMPLATE: {
22322232
return this.program.stringInstance;
22332233
}
2234+
case LiteralKind.REGEXP: {
2235+
return this.program.regexpInstance;
2236+
}
22342237
case LiteralKind.ARRAY: {
22352238
let classReference = ctxType.getClass();
22362239
if (classReference && classReference.prototype == this.program.arrayPrototype) {

‎tests/compiler/indexing-regexp.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"asc_flags": [
3+
],
4+
"stderr": [
5+
"TS2329: Index signature is missing in type '~lib/regexp/RegExp'"
6+
]
7+
}

‎tests/compiler/indexing-regexp.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ /[0];

‎tests/compiler/typeof-regexp.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"asc_flags": [
3+
],
4+
"stderr": [
5+
"AS100: Not implemented: Regular expressions"
6+
]
7+
}

‎tests/compiler/typeof-regexp.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typeof / /;

0 commit comments

Comments
 (0)
Please sign in to comment.