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 db485a0973..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) { diff --git a/tests/compiler/indexing-regexp.json b/tests/compiler/indexing-regexp.json new file mode 100644 index 0000000000..683cd4c33d --- /dev/null +++ b/tests/compiler/indexing-regexp.json @@ -0,0 +1,7 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "TS2329: Index signature is missing in type '~lib/regexp/RegExp'" + ] +} diff --git a/tests/compiler/indexing-regexp.ts b/tests/compiler/indexing-regexp.ts new file mode 100644 index 0000000000..9f2e3cb3c7 --- /dev/null +++ b/tests/compiler/indexing-regexp.ts @@ -0,0 +1 @@ +/ /[0]; 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..d4efeb76c4 --- /dev/null +++ b/tests/compiler/typeof-regexp.ts @@ -0,0 +1 @@ +typeof / /;