Skip to content

fix: #2206 indexing regexp #2263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
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 @@ -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) {
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 / /;