Skip to content

Commit

Permalink
fix: Add missing resolve of RegExp literals (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
technohippy committed Jul 23, 2022
1 parent 92ea1c4 commit 3a5b51d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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";
Expand Down
8 changes: 8 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,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) {
Expand Down
7 changes: 7 additions & 0 deletions tests/compiler/indexing-regexp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"asc_flags": [
],
"stderr": [
"TS2329: Index signature is missing in type '~lib/regexp/RegExp'"
]
}
1 change: 1 addition & 0 deletions tests/compiler/indexing-regexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ /[0];
7 changes: 7 additions & 0 deletions tests/compiler/typeof-regexp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"asc_flags": [
],
"stderr": [
"AS100: Not implemented: Regular expressions"
]
}
1 change: 1 addition & 0 deletions tests/compiler/typeof-regexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typeof / /;

0 comments on commit 3a5b51d

Please sign in to comment.