diff --git a/README.md b/README.md index 4309fc9..874e147 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ If you are looking for a Typescript REPL, or a way to _execute_ a full Typescrip [Become a sponsor/backer](https://github.com/wessberg/ts-evaluator?sponsor=1) and get your logo listed here. -| Bubbles | Christopher Blanchard | Ideal Postcodes | Xerox | Trent Raymond | scrubtheweb | Joel | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| [Bubbles](https://usebubbles.com)
Twitter: [@usebubbles](https://twitter.com/usebubbles) | [Christopher Blanchard](https://github.com/cblanc) | [Ideal Postcodes](https://github.com/ideal-postcodes) | [Xerox](https://www.xerox.com) | [Trent Raymond](https://changelog.me) | [scrubtheweb](https://scrubtheweb.com) | [Joel](https://github.com/hjoelh) | +| Bubbles | Xerox | Trent Raymond | scrubtheweb | Joel | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| [Bubbles](https://usebubbles.com)
Twitter: [@usebubbles](https://twitter.com/usebubbles) | [Xerox](https://www.xerox.com) | [Trent Raymond](https://changelog.me) | [scrubtheweb](https://scrubtheweb.com) | [Joel](https://github.com/hjoelh) | ### Patreon @@ -95,6 +95,7 @@ If you are looking for a Typescript REPL, or a way to _execute_ a full Typescrip - [Custom TypeScript version](#custom-typescript-version) - [Logging](#logging) - [Reporting](#reporting) + - [Module overrides](#module-overrides) - [Contributing](#contributing) - [Maintainers](#maintainers) - [FAQ](#faq) @@ -298,6 +299,23 @@ Here's an explainer of the different reporting hooks: - `reportIntermediateResults(entry: IIntermediateResultReportEntry) => void|(Promise)` - Will be invoked for each intermediate result that has been evaluated before producing a final result. This allows you to work programmatically with all expression values during code execution. - `reportErrors(entry: IErrorReportEntry) => void|(Promise)` - Will be invoked for each error that is thrown, both when evaluating a result, and for subsequent invocations on, for example, returned function instances. Holds a reference to the error, as well ast the AST node that threw or caused the Error. +### Module overrides + +Sometimes, evaluating identifiers require resolving identifiers across source files. When a typechecker is passed in, so long as the identifier is resolvable as part of the compilation unit, +this won't ever be an issue. However, when a type checker is not passed in, or in case you want to override the result of requiring an external module, you can use the `moduleOverrides` option. + +For example, you may want to pass in as shim for a built-in module. +To use it, pass a record where the keys are module specifiers and the value is what requiring that module should resolve to. For example: + +```ts +{ + fs: { + readFileSync: () => {}, + // ... + } +} +``` + ## Contributing diff --git a/package.json b/package.json index 27fbe1c..f51c876 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@types/semver": "^7.3.10", "@typescript-eslint/eslint-plugin": "^5.30.7", "@typescript-eslint/parser": "^5.30.7", - "@wessberg/ts-config": "^2.0.3", + "@wessberg/ts-config": "^2.0.4", "@wessberg/prettier-config": "^1.0.0", "rollup-plugin-ts": "3.0.2", "ava": "^3.15.0", @@ -62,7 +62,7 @@ "husky": "^8.0.1", "memfs": "^3.4.7", "np": "7.6.2", - "npm-check-updates": "^15.3.4", + "npm-check-updates": "^16.0.0", "pnpm": "^7.6.0", "prettier": "^2.7.1", "pretty-quick": "^3.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 159e1b1..74731a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,7 +8,7 @@ specifiers: '@typescript-eslint/eslint-plugin': ^5.30.7 '@typescript-eslint/parser': ^5.30.7 '@wessberg/prettier-config': ^1.0.0 - '@wessberg/ts-config': ^2.0.3 + '@wessberg/ts-config': ^2.0.4 ansi-colors: ^4.1.3 ava: ^3.15.0 crosspath: ^2.0.0 @@ -21,7 +21,7 @@ specifiers: jsdom: ^20.0.0 memfs: ^3.4.7 np: 7.6.2 - npm-check-updates: ^15.3.4 + npm-check-updates: ^16.0.0 object-path: ^0.11.8 pnpm: ^7.6.0 prettier: ^2.7.1 @@ -60,7 +60,7 @@ devDependencies: '@typescript-eslint/eslint-plugin': 5.30.7_6wltbjakwuqm7awqswigmiuhd4 '@typescript-eslint/parser': 5.30.7_he2ccbldppg44uulnyq4rwocfa '@wessberg/prettier-config': 1.0.0 - '@wessberg/ts-config': 2.0.3 + '@wessberg/ts-config': 2.0.4 ava: 3.15.0 crosspath: 2.0.0 eslint: 8.20.0 @@ -72,7 +72,7 @@ devDependencies: jsdom: 20.0.0 memfs: 3.4.7 np: 7.6.2 - npm-check-updates: 15.3.4 + npm-check-updates: 16.0.0 pnpm: 7.6.0 prettier: 2.7.1 pretty-quick: 3.1.3_prettier@2.7.1 @@ -620,8 +620,8 @@ packages: engines: {node: '>=8.0.0'} dev: true - /@wessberg/ts-config/2.0.3: - resolution: {integrity: sha512-j/ZQoPoB9mjdVsZduT74JzzKX13GqCDIdnXZUf3baegSzOHk4PdDNgefqTB1ozIWlJk0UFJBflBCVWDQ/98Dhw==} + /@wessberg/ts-config/2.0.4: + resolution: {integrity: sha512-Zi1mE/S9F1dJB1VX0o7YIt3TecM5j88vV+0AUlyGv6eWiqM+hSjHC5CbFMQ//aftIve6LJkMkqliii+3FlT94Q==} dev: true /JSONStream/1.3.5: @@ -1096,7 +1096,7 @@ packages: '@types/semver': 7.3.10 '@types/ua-parser-js': 0.7.36 browserslist: 4.20.2 - caniuse-lite: 1.0.30001368 + caniuse-lite: 1.0.30001369 isbot: 3.4.5 object-path: 0.11.8 semver: 7.3.7 @@ -1108,8 +1108,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001368 - electron-to-chromium: 1.4.198 + caniuse-lite: 1.0.30001369 + electron-to-chromium: 1.4.199 escalade: 3.1.1 node-releases: 2.0.6 picocolors: 1.0.0 @@ -1120,8 +1120,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001368 - electron-to-chromium: 1.4.198 + caniuse-lite: 1.0.30001369 + electron-to-chromium: 1.4.199 node-releases: 2.0.6 update-browserslist-db: 1.0.5_browserslist@4.21.2 dev: true @@ -1248,8 +1248,8 @@ packages: engines: {node: '>=14.16'} dev: true - /caniuse-lite/1.0.30001368: - resolution: {integrity: sha512-wgfRYa9DenEomLG/SdWgQxpIyvdtH3NW8Vq+tB6AwR9e56iOIcu1im5F/wNdDf04XlKHXqIx4N8Jo0PemeBenQ==} + /caniuse-lite/1.0.30001369: + resolution: {integrity: sha512-OY1SBHaodJc4wflDIKnlkdqWzJZd1Ls/2zbVJHBSv3AT7vgOJ58yAhd2CN4d57l2kPJrgMb7P9+N1Mhy4tNSQA==} dev: true /chalk/1.1.3: @@ -1953,8 +1953,8 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /electron-to-chromium/1.4.198: - resolution: {integrity: sha512-jwqQPdKGeAslcq8L+1SZZgL6uDiIDmTe9Gq4brsdWAH27y7MJ2g9Ue6MyST3ogmSM49EAQP7bype1V5hsuNrmQ==} + /electron-to-chromium/1.4.199: + resolution: {integrity: sha512-WIGME0Cs7oob3mxsJwHbeWkH0tYkIE/sjkJ8ML2BYmuRcjhRl/q5kVDXG7W9LOOKwzPU5M0LBlXRq9rlSgnNlg==} dev: true /elegant-spinner/1.0.1: @@ -4457,8 +4457,8 @@ packages: npm-normalize-package-bin: 1.0.1 dev: true - /npm-check-updates/15.3.4: - resolution: {integrity: sha512-YZDcw0DFn5ggl7b9znZ7N0i+Q1HVIxW+eZlV7XvR+RIs367H+ytKCB4slAU33Bg9IljY7uv3dsFjV2npOt3GyA==} + /npm-check-updates/16.0.0: + resolution: {integrity: sha512-l1PSWEQ51Zhq54LVMbvWcBDIKTqLLE0Bj40mP0z85mHR7wUJYRN1C+pndPu5qW3ay0h5466zZGc3E+o7wtJ2gA==} engines: {node: '>=14.14'} hasBin: true dependencies: diff --git a/src/interpreter/evaluate-options.ts b/src/interpreter/evaluate-options.ts index c85aabe..24fc652 100644 --- a/src/interpreter/evaluate-options.ts +++ b/src/interpreter/evaluate-options.ts @@ -12,4 +12,12 @@ export interface EvaluateOptions { logLevel?: LogLevelKind; policy?: Partial; reporting?: ReportingOptions; + + /** + * A record of implementations for module specifiers that will override whatever is resolvable via + * traditional require(...) evaluation. + * Useful when/if you want to shim other modules inside the compilation unit contex of the evaluation, + * much like local identifiers can be overridden with the `environment` option. + */ + moduleOverrides?: Record; } diff --git a/src/interpreter/evaluate.ts b/src/interpreter/evaluate.ts index 8c866e6..e5a5a6e 100644 --- a/src/interpreter/evaluate.ts +++ b/src/interpreter/evaluate.ts @@ -27,6 +27,7 @@ export function evaluate({ typeChecker, node, environment: {preset = "NODE", extra = {}} = {}, + moduleOverrides = {}, typescript = TSModule, logLevel = LogLevelKind.SILENT, policy: { @@ -100,6 +101,7 @@ export function evaluate({ typescript, logger, stack, + moduleOverrides, reporting: reporting, nextNode: nextNode => (currentNode = nextNode) }); diff --git a/src/interpreter/evaluator/evaluator-options.ts b/src/interpreter/evaluator/evaluator-options.ts index 46a0726..14eb5e0 100644 --- a/src/interpreter/evaluator/evaluator-options.ts +++ b/src/interpreter/evaluator/evaluator-options.ts @@ -15,6 +15,7 @@ export interface EvaluatorOptions> { environment: LexicalEnvironment; policy: EvaluatePolicySanitized; reporting: ReportingOptionsSanitized; + moduleOverrides?: Record; stack: Stack; statementTraversalStack: StatementTraversalStack; logger: Logger; diff --git a/src/interpreter/evaluator/node-evaluator/create-node-evaluator.ts b/src/interpreter/evaluator/node-evaluator/create-node-evaluator.ts index 5e9ceb7..9719da1 100644 --- a/src/interpreter/evaluator/node-evaluator/create-node-evaluator.ts +++ b/src/interpreter/evaluator/node-evaluator/create-node-evaluator.ts @@ -17,7 +17,7 @@ import {TS} from "../../../type/ts.js"; /** * Creates a Node Evaluator */ -export function createNodeEvaluator({typeChecker, typescript, policy, logger, stack, reporting, nextNode}: ICreateNodeEvaluatorOptions): NodeEvaluator { +export function createNodeEvaluator({typeChecker, typescript, policy, logger, stack, reporting, nextNode, moduleOverrides}: ICreateNodeEvaluatorOptions): NodeEvaluator { let ops = 0; const handleNewNode = (node: TS.Node, statementTraversalStack: StatementTraversalStack) => { @@ -101,7 +101,8 @@ export function createNodeEvaluator({typeChecker, typescript, policy, logger, st environment, stack, logger, - statementTraversalStack + statementTraversalStack, + moduleOverrides }; } diff --git a/src/interpreter/evaluator/node-evaluator/i-create-node-evaluator-options.ts b/src/interpreter/evaluator/node-evaluator/i-create-node-evaluator-options.ts index d6cf152..beb7dc7 100644 --- a/src/interpreter/evaluator/node-evaluator/i-create-node-evaluator-options.ts +++ b/src/interpreter/evaluator/node-evaluator/i-create-node-evaluator-options.ts @@ -9,6 +9,7 @@ export interface ICreateNodeEvaluatorOptions { typescript: typeof TS; policy: EvaluatePolicySanitized; reporting: ReportingOptionsSanitized; + moduleOverrides?: Record; logger: Logger; stack: Stack; nextNode(node: TS.Node): void; diff --git a/src/interpreter/util/module/get-implementation-for-declaration-within-declaration-file.ts b/src/interpreter/util/module/get-implementation-for-declaration-within-declaration-file.ts index 4a5d4c1..b87ba53 100644 --- a/src/interpreter/util/module/get-implementation-for-declaration-within-declaration-file.ts +++ b/src/interpreter/util/module/get-implementation-for-declaration-within-declaration-file.ts @@ -38,7 +38,7 @@ export function getImplementationForDeclarationWithinDeclarationFile(options: Ev try { // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires - const module = require(moduleDeclaration.name.text); + const module = options.moduleOverrides?.[moduleDeclaration.name.text] ?? require(moduleDeclaration.name.text); return typescript.isModuleDeclaration(node) ? module : module[name] ?? module; } catch (ex) { if (ex instanceof EvaluationError) throw ex; @@ -46,15 +46,14 @@ export function getImplementationForDeclarationWithinDeclarationFile(options: Ev } } - - export function getImplementationFromExternalFile(name: string, moduleSpecifier: string, options: EvaluatorOptions): Literal { +export function getImplementationFromExternalFile(name: string, moduleSpecifier: string, options: EvaluatorOptions): Literal { const {node} = options; const require = getFromLexicalEnvironment(node, options.environment, "require")!.literal as NodeRequire; try { // eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires - const module = require(moduleSpecifier); + const module = options.moduleOverrides?.[moduleSpecifier] ?? require(moduleSpecifier); return module[name] ?? module.default ?? module; } catch (ex) { if (ex instanceof EvaluationError) throw ex; diff --git a/test/array-binding-pattern/array-binding-pattern.test.ts b/test/array-binding-pattern/array-binding-pattern.test.ts index c28bda1..052b695 100644 --- a/test/array-binding-pattern/array-binding-pattern.test.ts +++ b/test/array-binding-pattern/array-binding-pattern.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ArrayBindingPatterns in VariableDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ArrayBindingPatterns in VariableDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -12,14 +12,14 @@ test("Can handle ArrayBindingPatterns in VariableDeclarations. #1", withTypeScri })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can handle ArrayBindingPatterns in VariableDeclarations. #2", withTypeScript, (t, {typescript}) => { +test("Can handle ArrayBindingPatterns in VariableDeclarations. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -29,14 +29,14 @@ test("Can handle ArrayBindingPatterns in VariableDeclarations. #2", withTypeScri })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can handle ArrayBindingPatterns in VariableDeclarations. #3", withTypeScript, (t, {typescript}) => { +test("Can handle ArrayBindingPatterns in VariableDeclarations. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -46,14 +46,14 @@ test("Can handle ArrayBindingPatterns in VariableDeclarations. #3", withTypeScri })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can handle ArrayBindingPatterns in ParameterDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ArrayBindingPatterns in ParameterDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -62,7 +62,7 @@ test("Can handle ArrayBindingPatterns in ParameterDeclarations. #1", withTypeScr })([1, {destructured: 2}, 3]); `, "(([, {destructured: alias}]) =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/array-literal-expression/array-literal-expression.test.ts b/test/array-literal-expression/array-literal-expression.test.ts index b03ab93..e8ea636 100644 --- a/test/array-literal-expression/array-literal-expression.test.ts +++ b/test/array-literal-expression/array-literal-expression.test.ts @@ -2,14 +2,14 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ArrayLiteralExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ArrayLiteralExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` (["foo", "bar"]) `, "([", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/assignments/assignments.test.ts b/test/assignments/assignments.test.ts index 9c72f43..906b4ca 100644 --- a/test/assignments/assignments.test.ts +++ b/test/assignments/assignments.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression for a function with variable assignments. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression for a function with variable assignments. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -15,7 +15,7 @@ test("Can evaluate a CallExpression for a function with variable assignments. #1 square(2); `, "square(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/await-expression/await-expression.test.ts b/test/await-expression/await-expression.test.ts index 6d8c32a..72e09bf 100644 --- a/test/await-expression/await-expression.test.ts +++ b/test/await-expression/await-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate an AwaitExpression #1", withTypeScript, async (t, {typescript}) => { +test("Can evaluate an AwaitExpression #1", withTypeScript, async (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -15,7 +15,7 @@ test("Can evaluate an AwaitExpression #1", withTypeScript, async (t, {typescript })(); `, "return await myAsyncFunction()", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/binary-expression/binary-expression.test.ts b/test/binary-expression/binary-expression.test.ts index 50d8b8e..f470e52 100644 --- a/test/binary-expression/binary-expression.test.ts +++ b/test/binary-expression/binary-expression.test.ts @@ -2,63 +2,63 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript, withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Can evaluate a simple arithmetic BinaryExpression #1", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`2 + 2`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #1", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`2 + 2`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a simple arithmetic BinaryExpression #2", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`2 - 2`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #2", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`2 - 2`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 0); }); -test("Can evaluate a simple arithmetic BinaryExpression #3", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`2 * 2`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #3", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`2 * 2`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a simple arithmetic BinaryExpression #4", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`2 / 2`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #4", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`2 / 2`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 1); }); -test("Can evaluate a simple arithmetic BinaryExpression #5", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`1 + 2 * 3`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #5", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`1 + 2 * 3`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 7); }); -test("Can evaluate a simple arithmetic BinaryExpression #6", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`(1 + 2) * 3`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression #6", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`(1 + 2) * 3`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 9); }); -test("Can evaluate a simple arithmetic BinaryExpression with type casts #1", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`((1) + 2) * 3`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression with type casts #1", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`((1) + 2) * 3`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 9); }); -test("Can evaluate a simple arithmetic BinaryExpression with type casts #2", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`((1 as number) + 2) * 3`, {typescript}); +test("Can evaluate a simple arithmetic BinaryExpression with type casts #2", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`((1 as number) + 2) * 3`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 9); }); -test("Can evaluate equality BinaryExpressions #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate equality BinaryExpressions #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -70,14 +70,14 @@ test("Can evaluate equality BinaryExpressions #1", withTypeScript, (t, {typescri })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, Number.MIN_VALUE); }); -test("Can evaluate BinaryExpressions with CommaTokens #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate BinaryExpressions with CommaTokens #1", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection UnnecessaryLocalVariableJS const {result} = executeProgram( // language=TypeScript @@ -90,14 +90,14 @@ test("Can evaluate BinaryExpressions with CommaTokens #1", withTypeScript, (t, { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -108,14 +108,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #1", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -127,14 +127,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #2", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "foo"); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -144,14 +144,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #3", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #4", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -161,14 +161,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #4", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #5", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #5", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -179,14 +179,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #5", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #6", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #6", withTypeScript, (t, {typescript, useTypeChecker}) => { /* eslint-disable no-useless-escape */ const {result} = executeProgram( // language=TypeScript @@ -198,14 +198,14 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #6", withTypeSc `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InstanceOf keyword #7", withTypeScript, (t, {typescript}) => { +test("Can evaluate a BinaryExpression with an InstanceOf keyword #7", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -218,36 +218,36 @@ test("Can evaluate a BinaryExpression with an InstanceOf keyword #7", withTypeSc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with a BigInt #1", withTypeScriptVersions(">=3.2"), (t, {typescript}) => { - const {result} = executeProgram(`123456789123456789123456789n + 123456789123456789123456789n`, {typescript}); +test("Can evaluate a BinaryExpression with a BigInt #1", withTypeScriptVersions(">=3.2"), (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`123456789123456789123456789n + 123456789123456789123456789n`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, BigInt("246913578246913578246913578")); }); -test("Can evaluate a BinaryExpression with an InKeyword #1", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`"foo" in {}`, {typescript}); +test("Can evaluate a BinaryExpression with an InKeyword #1", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`"foo" in {}`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, false); }); -test("Can evaluate a BinaryExpression with an InKeyword #2", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`"foo" in {foo: 123}`, {typescript}); +test("Can evaluate a BinaryExpression with an InKeyword #2", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`"foo" in {foo: 123}`, {typescript, useTypeChecker}); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can evaluate a BinaryExpression with an InKeyword #3", withTypeScript, (t, {typescript}) => { - const {result} = executeProgram(`"foo" in 42`, {typescript}); +test("Can evaluate a BinaryExpression with an InKeyword #3", withTypeScript, (t, {typescript, useTypeChecker}) => { + const {result} = executeProgram(`"foo" in 42`, {typescript, useTypeChecker}); if (result.success) t.fail("Expected the evaluation to fail"); else t.pass(); diff --git a/test/call-expression/call-bind-apply.test.ts b/test/call-expression/call-bind-apply.test.ts index 64d0139..e77c627 100644 --- a/test/call-expression/call-bind-apply.test.ts +++ b/test/call-expression/call-bind-apply.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression that is called with another 'this' value. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression that is called with another 'this' value. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -17,14 +17,14 @@ test("Can evaluate a CallExpression that is called with another 'this' value. #1 myFunc.call(myObj, 2); `, "myFunc.call(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a CallExpression that is called with another 'this' value. #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression that is called with another 'this' value. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -39,14 +39,14 @@ test("Can evaluate a CallExpression that is called with another 'this' value. #2 myFunc.bind(myObj, 2)(); `, "myFunc.bind(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a CallExpression that is called with another 'this' value. #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression that is called with another 'this' value. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -61,7 +61,7 @@ test("Can evaluate a CallExpression that is called with another 'this' value. #3 myFunc.apply(myObj, [2]); `, "myFunc.apply(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/class-declaration/class-declaration.test.ts b/test/class-declaration/class-declaration.test.ts index 3cfde5d..61e97e2 100644 --- a/test/class-declaration/class-declaration.test.ts +++ b/test/class-declaration/class-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript, withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Can handle ClassDeclarations and preserves their names. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassDeclarations and preserves their names. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -12,7 +12,7 @@ test("Can handle ClassDeclarations and preserves their names. #1", withTypeScrip (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -21,7 +21,7 @@ test("Can handle ClassDeclarations and preserves their names. #1", withTypeScrip } }); -test("Can handle ClassDeclarations that extends from other named classes. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassDeclarations that extends from other named classes. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -34,7 +34,7 @@ test("Can handle ClassDeclarations that extends from other named classes. #1", w (() => [A, B])(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -45,7 +45,7 @@ test("Can handle ClassDeclarations that extends from other named classes. #1", w } }); -test("Can handle ClassDeclarations that extends from Expressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassDeclarations that extends from Expressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -59,7 +59,7 @@ test("Can handle ClassDeclarations that extends from Expressions. #1", withTypeS (() => A)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -69,7 +69,7 @@ test("Can handle ClassDeclarations that extends from Expressions. #1", withTypeS } }); -test("Can handle ClassDeclarations and preserves their constructors. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassDeclarations and preserves their constructors. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -84,7 +84,7 @@ test("Can handle ClassDeclarations and preserves their constructors. #1", withTy (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -95,7 +95,7 @@ test("Can handle ClassDeclarations and preserves their constructors. #1", withTy } }); -test("Can handle ClassDeclarations and preserves their constructors. #2", withTypeScriptVersions(">=3.8"), (t, {typescript}) => { +test("Can handle ClassDeclarations and preserves their constructors. #2", withTypeScriptVersions(">=3.8"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -114,7 +114,7 @@ test("Can handle ClassDeclarations and preserves their constructors. #2", withTy (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -125,7 +125,7 @@ test("Can handle ClassDeclarations and preserves their constructors. #2", withTy } }); -test("Inherits PropertyDeclarations from super classes. #1", withTypeScript, (t, {typescript}) => { +test("Inherits PropertyDeclarations from super classes. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -140,7 +140,7 @@ test("Inherits PropertyDeclarations from super classes. #1", withTypeScript, (t, (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -151,7 +151,7 @@ test("Inherits PropertyDeclarations from super classes. #1", withTypeScript, (t, } }); -test("Inherits PropertyDeclarations from super classes. #2", withTypeScript, (t, {typescript}) => { +test("Inherits PropertyDeclarations from super classes. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -172,7 +172,7 @@ test("Inherits PropertyDeclarations from super classes. #2", withTypeScript, (t, (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -182,7 +182,7 @@ test("Inherits PropertyDeclarations from super classes. #2", withTypeScript, (t, } }); -test("Inherits PropertyDeclarations from super classes. #3", withTypeScript, (t, {typescript}) => { +test("Inherits PropertyDeclarations from super classes. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -209,7 +209,7 @@ test("Inherits PropertyDeclarations from super classes. #3", withTypeScript, (t, (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -220,7 +220,7 @@ test("Inherits PropertyDeclarations from super classes. #3", withTypeScript, (t, } }); -test("Can handle GetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle GetAccessorDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -234,7 +234,7 @@ test("Can handle GetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -245,7 +245,7 @@ test("Can handle GetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) } }); -test("Can handle SetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle SetAccessorDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -263,7 +263,7 @@ test("Can handle SetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -275,7 +275,7 @@ test("Can handle SetAccessorDeclarations. #1", withTypeScript, (t, {typescript}) } }); -test("Can handle instance properties set via Constructor arguments. #1", withTypeScript, (t, {typescript}) => { +test("Can handle instance properties set via Constructor arguments. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -286,7 +286,7 @@ test("Can handle instance properties set via Constructor arguments. #1", withTyp (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -295,4 +295,4 @@ test("Can handle instance properties set via Constructor arguments. #1", withTyp const instance = new (result.value as new () => {foo: number})(); t.deepEqual(instance.foo, 2); } -}); \ No newline at end of file +}); diff --git a/test/class-expression/class-expression.test.ts b/test/class-expression/class-expression.test.ts index 72a57e0..78aa18c 100644 --- a/test/class-expression/class-expression.test.ts +++ b/test/class-expression/class-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ClassExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -10,7 +10,7 @@ test("Can handle ClassExpressions. #1", withTypeScript, (t, {typescript}) => { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -19,7 +19,7 @@ test("Can handle ClassExpressions. #1", withTypeScript, (t, {typescript}) => { } }); -test("Can handle ClassExpressions that extends from other named classes. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ClassExpressions that extends from other named classes. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -29,7 +29,7 @@ test("Can handle ClassExpressions that extends from other named classes. #1", wi (() => [A, class extends A {}])(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/conditional-expression/conditional-expression.test.ts b/test/conditional-expression/conditional-expression.test.ts index 92a710e..e7bb8ed 100644 --- a/test/conditional-expression/conditional-expression.test.ts +++ b/test/conditional-expression/conditional-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ConditionalExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ConditionalExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -11,7 +11,7 @@ test("Can handle ConditionalExpressions. #1", withTypeScript, (t, {typescript}) (() => 2 + 2 === 5 ? true : false)() `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -20,7 +20,7 @@ test("Can handle ConditionalExpressions. #1", withTypeScript, (t, {typescript}) } }); -test("Can handle ConditionalExpressions. #2", withTypeScript, (t, {typescript}) => { +test("Can handle ConditionalExpressions. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -29,7 +29,7 @@ test("Can handle ConditionalExpressions. #2", withTypeScript, (t, {typescript}) (() => 2 + 2 === 4 ? true : false)() `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/decorator/decorator.test.ts b/test/decorator/decorator.test.ts index cfbf8fd..edfdacc 100644 --- a/test/decorator/decorator.test.ts +++ b/test/decorator/decorator.test.ts @@ -3,7 +3,7 @@ import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; import {IndexLiteral} from "../../src/interpreter/literal/literal.js"; -test("Can handle Class Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle Class Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -20,7 +20,7 @@ test("Can handle Class Decorators. #1", withTypeScript, (t, {typescript}) => { (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -30,7 +30,7 @@ test("Can handle Class Decorators. #1", withTypeScript, (t, {typescript}) => { } }); -test("Can handle multiple Class Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle multiple Class Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -54,7 +54,7 @@ test("Can handle multiple Class Decorators. #1", withTypeScript, (t, {typescript (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -65,7 +65,7 @@ test("Can handle multiple Class Decorators. #1", withTypeScript, (t, {typescript } }); -test("Can handle instance Method Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle instance Method Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -89,7 +89,7 @@ test("Can handle instance Method Decorators. #1", withTypeScript, (t, {typescrip (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -99,7 +99,7 @@ test("Can handle instance Method Decorators. #1", withTypeScript, (t, {typescrip } }); -test("Can handle static Method Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle static Method Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -123,7 +123,7 @@ test("Can handle static Method Decorators. #1", withTypeScript, (t, {typescript} (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -133,7 +133,7 @@ test("Can handle static Method Decorators. #1", withTypeScript, (t, {typescript} } }); -test("Can handle instance PropertyDeclaration Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle instance PropertyDeclaration Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -148,7 +148,7 @@ test("Can handle instance PropertyDeclaration Decorators. #1", withTypeScript, ( (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -158,7 +158,7 @@ test("Can handle instance PropertyDeclaration Decorators. #1", withTypeScript, ( } }); -test("Can handle static PropertyDeclaration Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle static PropertyDeclaration Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -173,7 +173,7 @@ test("Can handle static PropertyDeclaration Decorators. #1", withTypeScript, (t, (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -182,7 +182,7 @@ test("Can handle static PropertyDeclaration Decorators. #1", withTypeScript, (t, } }); -test("Can handle Parameter Decorators. #1", withTypeScript, (t, {typescript}) => { +test("Can handle Parameter Decorators. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -207,7 +207,7 @@ test("Can handle Parameter Decorators. #1", withTypeScript, (t, {typescript}) => (() => MyClass)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/enum-declaration/enum-declaration.test.ts b/test/enum-declaration/enum-declaration.test.ts index 6b2b55a..24d3830 100644 --- a/test/enum-declaration/enum-declaration.test.ts +++ b/test/enum-declaration/enum-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle EnumDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle EnumDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -15,7 +15,7 @@ test("Can handle EnumDeclarations. #1", withTypeScript, (t, {typescript}) => { (() => Foo)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -27,7 +27,7 @@ test("Can handle EnumDeclarations. #1", withTypeScript, (t, {typescript}) => { } }); -test("Can handle EnumDeclarations. #2", withTypeScript, (t, {typescript}) => { +test("Can handle EnumDeclarations. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -40,7 +40,7 @@ test("Can handle EnumDeclarations. #2", withTypeScript, (t, {typescript}) => { (() => Foo)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -52,7 +52,7 @@ test("Can handle EnumDeclarations. #2", withTypeScript, (t, {typescript}) => { } }); -test("Can handle EnumDeclarations. #3", withTypeScript, (t, {typescript}) => { +test("Can handle EnumDeclarations. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -65,7 +65,7 @@ test("Can handle EnumDeclarations. #3", withTypeScript, (t, {typescript}) => { (() => Foo)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -77,7 +77,7 @@ test("Can handle EnumDeclarations. #3", withTypeScript, (t, {typescript}) => { } }); -test("Can handle EnumDeclarations. #4", withTypeScript, (t, {typescript}) => { +test("Can handle EnumDeclarations. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -90,7 +90,7 @@ test("Can handle EnumDeclarations. #4", withTypeScript, (t, {typescript}) => { (() => Foo)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/environment/browser.test.ts b/test/environment/browser.test.ts index aafd2c7..cbe788c 100644 --- a/test/environment/browser.test.ts +++ b/test/environment/browser.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle a Browser environment. #1", withTypeScript, (t, {typescript}) => { +test("Can handle a Browser environment. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -14,6 +14,7 @@ test("Can handle a Browser environment. #1", withTypeScript, (t, {typescript}) = "(() =>", { typescript, + useTypeChecker, environment: { preset: "BROWSER" } @@ -26,7 +27,7 @@ test("Can handle a Browser environment. #1", withTypeScript, (t, {typescript}) = } }); -test("Can handle a Browser environment. #2", withTypeScript, (t, {typescript}) => { +test("Can handle a Browser environment. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -38,6 +39,7 @@ test("Can handle a Browser environment. #2", withTypeScript, (t, {typescript}) = "(() =>", { typescript, + useTypeChecker, environment: { preset: "BROWSER" } diff --git a/test/environment/node-cjs.test.ts b/test/environment/node-cjs.test.ts index 471430d..a5da251 100644 --- a/test/environment/node-cjs.test.ts +++ b/test/environment/node-cjs.test.ts @@ -3,7 +3,7 @@ import path from "crosspath"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS-based Node environment. #1", withTypeScript, (t, {typescript}) => { +test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS-based Node environment. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result, setup} = executeProgram( // language=TypeScript { @@ -17,6 +17,7 @@ test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS- { cwd: "/Users/someone/development/foo", typescript, + useTypeChecker, environment: { preset: "NODE" } @@ -29,7 +30,7 @@ test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS- } }); -test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS-based Node environment. #2", withTypeScript, (t, {typescript}) => { +test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS-based Node environment. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result, setup} = executeProgram( // language=TypeScript { @@ -43,6 +44,7 @@ test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS- { cwd: "/Users/someone/development/foo", typescript, + useTypeChecker, environment: { preset: "NODE_CJS" } @@ -55,7 +57,7 @@ test("Can handle the '__dirname' and '__filename' meta properties in a CommonJS- } }); -test("Can handle 'process.cwd()' in a CommonJS-based Node environment. #1", withTypeScript, (t, {typescript}) => { +test("Can handle 'process.cwd()' in a CommonJS-based Node environment. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -64,7 +66,7 @@ test("Can handle 'process.cwd()' in a CommonJS-based Node environment. #1", with })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/environment/node-esm.test.ts b/test/environment/node-esm.test.ts index c884cc1..6fc0c0b 100644 --- a/test/environment/node-esm.test.ts +++ b/test/environment/node-esm.test.ts @@ -3,7 +3,7 @@ import path from "crosspath"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle the import.meta.url meta property in an ESM-based Node environment. #1", withTypeScript, (t, {typescript}) => { +test("Can handle the import.meta.url meta property in an ESM-based Node environment. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result, setup} = executeProgram( // language=TypeScript { @@ -17,6 +17,7 @@ test("Can handle the import.meta.url meta property in an ESM-based Node environm { cwd: "/Users/someone/development/foo", typescript, + useTypeChecker, environment: { preset: "NODE_ESM" } @@ -27,4 +28,4 @@ test("Can handle the import.meta.url meta property in an ESM-based Node environm else { t.deepEqual(result.value, {filename: `file://${path.join(setup.fileStructure.dir.src, "bar.ts")}`}); } -}); \ No newline at end of file +}); diff --git a/test/for-in/for-in.test.ts b/test/for-in/for-in.test.ts index 8e84abc..4df44cb 100644 --- a/test/for-in/for-in.test.ts +++ b/test/for-in/for-in.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression with a ForInStatement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForInStatement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -18,7 +18,7 @@ test("Can evaluate a CallExpression with a ForInStatement. #1", withTypeScript, myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/for-of/for-of.test.ts b/test/for-of/for-of.test.ts index 6d4ce71..255ca43 100644 --- a/test/for-of/for-of.test.ts +++ b/test/for-of/for-of.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression with a ForOfStatement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForOfStatement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -17,14 +17,14 @@ test("Can evaluate a CallExpression with a ForOfStatement. #1", withTypeScript, myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 6); }); -test("Can evaluate a CallExpression with a ForOfStatement and a break statement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForOfStatement and a break statement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -40,14 +40,14 @@ test("Can evaluate a CallExpression with a ForOfStatement and a break statement. myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 3); }); -test("Can evaluate a CallExpression with a ForOfStatement and a continue statement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForOfStatement and a continue statement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -63,14 +63,14 @@ test("Can evaluate a CallExpression with a ForOfStatement and a continue stateme myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 5); }); -test("Can evaluate a CallExpression with a ForOfStatement and a return statement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForOfStatement and a return statement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -86,7 +86,7 @@ test("Can evaluate a CallExpression with a ForOfStatement and a return statement myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/for/for.test.ts b/test/for/for.test.ts index 18b5512..cc5ed58 100644 --- a/test/for/for.test.ts +++ b/test/for/for.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression with a ForStatement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForStatement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -18,14 +18,14 @@ test("Can evaluate a CallExpression with a ForStatement. #1", withTypeScript, (t myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 6); }); -test("Can evaluate a CallExpression with a ForStatement. #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForStatement. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -42,14 +42,14 @@ test("Can evaluate a CallExpression with a ForStatement. #2", withTypeScript, (t myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a CallExpression with a ForStatement. #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a ForStatement. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -66,7 +66,7 @@ test("Can evaluate a CallExpression with a ForStatement. #3", withTypeScript, (t myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/function-declaration/arithmetic.test.ts b/test/function-declaration/arithmetic.test.ts index f49ed92..03382b6 100644 --- a/test/function-declaration/arithmetic.test.ts +++ b/test/function-declaration/arithmetic.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a simple '(number, number) => number' function. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a simple '(number, number) => number' function. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -13,14 +13,14 @@ test("Can evaluate a simple '(number, number) => number' function. #1", withType add(1, 2); `, "add(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 3); }); -test("Can evaluate a simple '(number, number) => number' function. #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a simple '(number, number) => number' function. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -31,14 +31,14 @@ test("Can evaluate a simple '(number, number) => number' function. #2", withType minus(1, 2); `, "minus(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, -1); }); -test("Can evaluate a simple '(number, number) => number' function. #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate a simple '(number, number) => number' function. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -49,14 +49,14 @@ test("Can evaluate a simple '(number, number) => number' function. #3", withType multiply(1, 2); `, "multiply(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can evaluate a simple '(number, number) => number' function. #4", withTypeScript, (t, {typescript}) => { +test("Can evaluate a simple '(number, number) => number' function. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -67,14 +67,14 @@ test("Can evaluate a simple '(number, number) => number' function. #4", withType divide(1, 2); `, "divide(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 0.5); }); -test("Can evaluate a simple 'number => number' function. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a simple 'number => number' function. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -85,14 +85,14 @@ test("Can evaluate a simple 'number => number' function. #1", withTypeScript, (t square(2); `, "square(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can handle the 'arguments' identifier. #1", withTypeScript, (t, {typescript}) => { +test("Can handle the 'arguments' identifier. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -105,6 +105,7 @@ test("Can handle the 'arguments' identifier. #1", withTypeScript, (t, {typescrip "square(", { typescript, + useTypeChecker, policy: { console: true } diff --git a/test/function-declaration/recursion.test.ts b/test/function-declaration/recursion.test.ts index daffa2c..8f5152f 100644 --- a/test/function-declaration/recursion.test.ts +++ b/test/function-declaration/recursion.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression for a recursive function. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression for a recursive function. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -17,7 +17,7 @@ test("Can evaluate a CallExpression for a recursive function. #1", withTypeScrip fibonacci(5); `, "fibonacci(5", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/get-accessor-declaration/get-accessor-declaration.test.ts b/test/get-accessor-declaration/get-accessor-declaration.test.ts index 1e2f3b4..8f8bf55 100644 --- a/test/get-accessor-declaration/get-accessor-declaration.test.ts +++ b/test/get-accessor-declaration/get-accessor-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate and retrieve a GetAccessorDeclaration. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate and retrieve a GetAccessorDeclaration. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -13,7 +13,7 @@ test("Can evaluate and retrieve a GetAccessorDeclaration. #1", withTypeScript, ( } `, "get", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/hoisting/hoisting.test.ts b/test/hoisting/hoisting.test.ts index 0ac0d90..1c12a4d 100644 --- a/test/hoisting/hoisting.test.ts +++ b/test/hoisting/hoisting.test.ts @@ -4,7 +4,7 @@ import {withTypeScript} from "../setup/ts-macro.js"; import {UndefinedIdentifierError} from "../../src/interpreter/error/undefined-identifier-error/undefined-identifier-error.js"; import {NotCallableError} from "../../src/interpreter/error/not-callable-error/not-callable-error.js"; -test("Throws when attempting to reference an identifier that is still not defined within the current scope. #2", withTypeScript, (t, {typescript}) => { +test("Throws when attempting to reference an identifier that is still not defined within the current scope. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -15,7 +15,7 @@ test("Throws when attempting to reference an identifier that is still not define } `, "add(", - {typescript} + {typescript, useTypeChecker} ); if (result.success) t.fail(); @@ -25,7 +25,7 @@ test("Throws when attempting to reference an identifier that is still not define test( "Doesn't throw when attempting to reference an identifier that is declared after the reference, but is hoisted to the current scope. #1", withTypeScript, - (t, {typescript}) => { + (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -38,7 +38,7 @@ test( (() => myVar)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -51,7 +51,7 @@ test( test( "Throws when attempting to use the rvalue of a referenced identifier that is declared after the reference, but is hoisted to the current scope. #1", withTypeScript, - (t, {typescript}) => { + (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -64,7 +64,7 @@ test( (() => myVar(1, 2))(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (result.success) t.fail(); @@ -73,7 +73,7 @@ test( } ); -test("Respects block scoped variables declared with 'let'. #1", withTypeScript, (t, {typescript}) => { +test("Respects block scoped variables declared with 'let'. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -83,14 +83,14 @@ test("Respects block scoped variables declared with 'let'. #1", withTypeScript, (() => a)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (result.success) t.fail(); else t.true(result.reason instanceof UndefinedIdentifierError); }); -test("Respects block scoped variables declared with 'var'. #1", withTypeScript, (t, {typescript}) => { +test("Respects block scoped variables declared with 'var'. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -100,7 +100,7 @@ test("Respects block scoped variables declared with 'var'. #1", withTypeScript, (() => a)(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/import-declaration/import-declaration.test.ts b/test/import-declaration/import-declaration.test.ts index 8cccf2a..1a78a91 100644 --- a/test/import-declaration/import-declaration.test.ts +++ b/test/import-declaration/import-declaration.test.ts @@ -1,9 +1,10 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript, withTypeScriptVersions} from "../setup/ts-macro.js"; import path from "crosspath"; -test("Can resolve symbols via ImportDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ { @@ -27,14 +28,24 @@ test("Can resolve symbols via ImportDeclarations. #1", withTypeScript, (t, {type fileName: "b.ts", match: "(() =>" }, - {typescript} + { + typescript, + useTypeChecker, + ...(useTypeChecker + ? {} + : { + moduleOverrides: { + "./a": {foo: "bar"} + } + }) + } ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "bar2"); }); -test("Can resolve symbols via ImportDeclarations. #2", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ { @@ -65,14 +76,25 @@ test("Can resolve symbols via ImportDeclarations. #2", withTypeScript, (t, {type fileName: "c.ts", match: "(() =>" }, - {typescript} + { + typescript, + useTypeChecker, + ...(useTypeChecker + ? {} + : { + moduleOverrides: { + "./a": {foo: "bar"}, + "./b": {foo: "bar"} + } + }) + } ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "bar2"); }); -test("Can resolve symbols via ImportDeclarations. #3", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ { @@ -105,14 +127,25 @@ test("Can resolve symbols via ImportDeclarations. #3", withTypeScript, (t, {type fileName: "c.ts", match: "(() =>" }, - {typescript} + { + typescript, + useTypeChecker, + ...(useTypeChecker + ? {} + : { + moduleOverrides: { + "./a": {foo: "bar"}, + "./b": {foo: "bar"} + } + }) + } ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "bar2"); }); -test("Can resolve symbols via ImportDeclarations. #4", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ { @@ -145,14 +178,25 @@ test("Can resolve symbols via ImportDeclarations. #4", withTypeScript, (t, {type fileName: "c.ts", match: "(() =>" }, - {typescript} + { + typescript, + useTypeChecker, + ...(useTypeChecker + ? {} + : { + moduleOverrides: { + "./a": {foo: "bar"}, + "./b": {foo: "bar"} + } + }) + } ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "bar2"); }); -test("Can resolve symbols via ImportDeclarations for built-in node modules. #1", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations for built-in node modules. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ // language=TypeScript @@ -163,14 +207,14 @@ test("Can resolve symbols via ImportDeclarations for built-in node modules. #1", ` ], "foo", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "/foo"); }); -test("Can resolve symbols via ImportDeclarations for built-in node modules. #2", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations for built-in node modules. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ // language=TypeScript @@ -181,14 +225,14 @@ test("Can resolve symbols via ImportDeclarations for built-in node modules. #2", ` ], "foo", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "/foo"); }); -test("Can resolve symbols via ImportDeclarations for built-in node modules. #3", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations for built-in node modules. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ // language=TypeScript @@ -200,14 +244,14 @@ test("Can resolve symbols via ImportDeclarations for built-in node modules. #3", ` ], "foo", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "ts-evaluator"); }); -test("Can resolve symbols via ImportDeclarations for built-in node modules. #4", withTypeScriptVersions(">=3.1"), (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations for built-in node modules. #4", withTypeScriptVersions(">=3.1"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -223,14 +267,14 @@ test("Can resolve symbols via ImportDeclarations for built-in node modules. #4", })(); `, "(() => ", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, true); }); -test("Can resolve symbols via ImportDeclarations for built-in node modules. #5", withTypeScript, (t, {typescript}) => { +test("Can resolve symbols via ImportDeclarations for built-in node modules. #5", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( [ // language=TypeScript @@ -242,9 +286,9 @@ test("Can resolve symbols via ImportDeclarations for built-in node modules. #5", ` ], "foo", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "ts-evaluator"); -}); \ No newline at end of file +}); diff --git a/test/interface-declaration/interface-declaration.test.ts b/test/interface-declaration/interface-declaration.test.ts index 0a7d204..226c127 100644 --- a/test/interface-declaration/interface-declaration.test.ts +++ b/test/interface-declaration/interface-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Understands InterfaceDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Understands InterfaceDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -15,7 +15,7 @@ test("Understands InterfaceDeclarations. #1", withTypeScript, (t, {typescript}) })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/logical-assignment/logical-assignment.test.ts b/test/logical-assignment/logical-assignment.test.ts index 2f23400..a8bcafe 100644 --- a/test/logical-assignment/logical-assignment.test.ts +++ b/test/logical-assignment/logical-assignment.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Supports logical assignment. #1", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #1", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -13,7 +13,7 @@ test("Supports logical assignment. #1", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -22,7 +22,7 @@ test("Supports logical assignment. #1", withTypeScriptVersions(">=4.0"), (t, {ty } }); -test("Supports logical assignment. #2", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #2", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -33,7 +33,7 @@ test("Supports logical assignment. #2", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -42,7 +42,7 @@ test("Supports logical assignment. #2", withTypeScriptVersions(">=4.0"), (t, {ty } }); -test("Supports logical assignment. #3", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #3", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -54,7 +54,7 @@ test("Supports logical assignment. #3", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -63,7 +63,7 @@ test("Supports logical assignment. #3", withTypeScriptVersions(">=4.0"), (t, {ty } }); -test("Supports logical assignment. #4", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #4", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -75,7 +75,7 @@ test("Supports logical assignment. #4", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -84,7 +84,7 @@ test("Supports logical assignment. #4", withTypeScriptVersions(">=4.0"), (t, {ty } }); -test("Supports logical assignment. #5", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #5", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -96,7 +96,7 @@ test("Supports logical assignment. #5", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -105,7 +105,7 @@ test("Supports logical assignment. #5", withTypeScriptVersions(">=4.0"), (t, {ty } }); -test("Supports logical assignment. #6", withTypeScriptVersions(">=4.0"), (t, {typescript}) => { +test("Supports logical assignment. #6", withTypeScriptVersions(">=4.0"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -117,7 +117,7 @@ test("Supports logical assignment. #6", withTypeScriptVersions(">=4.0"), (t, {ty })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/method-declaration/method-declaration.test.ts b/test/method-declaration/method-declaration.test.ts index 66996f7..0cbcba3 100644 --- a/test/method-declaration/method-declaration.test.ts +++ b/test/method-declaration/method-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript, withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Can evaluate and retrieve a MethodDeclaration. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate and retrieve a MethodDeclaration. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -13,7 +13,7 @@ test("Can evaluate and retrieve a MethodDeclaration. #1", withTypeScript, (t, {t } `, "add (", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -22,7 +22,7 @@ test("Can evaluate and retrieve a MethodDeclaration. #1", withTypeScript, (t, {t } }); -test("Can evaluate and retrieve a private MethodDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript}) => { +test("Can evaluate and retrieve a private MethodDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -33,7 +33,7 @@ test("Can evaluate and retrieve a private MethodDeclaration. #1", withTypeScript } `, "#add (", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -42,7 +42,7 @@ test("Can evaluate and retrieve a private MethodDeclaration. #1", withTypeScript } }); -test("Can evaluate and retrieve the result of calling a private MethodDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript}) => { +test("Can evaluate and retrieve the result of calling a private MethodDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -59,7 +59,7 @@ test("Can evaluate and retrieve the result of calling a private MethodDeclaratio const result = foo.add(2, 2); `, "result", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -68,7 +68,7 @@ test("Can evaluate and retrieve the result of calling a private MethodDeclaratio } }); -test("Can evaluate and retrieve the result of calling a private MethodDeclaration. #2", withTypeScriptVersions(">=3.8"), (t, {typescript}) => { +test("Can evaluate and retrieve the result of calling a private MethodDeclaration. #2", withTypeScriptVersions(">=3.8"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -85,7 +85,7 @@ test("Can evaluate and retrieve the result of calling a private MethodDeclaratio const result = foo.addToSecretNumber(2); `, "result", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/new-target/new-target.test.ts b/test/new-target/new-target.test.ts index c52829b..60f6906 100644 --- a/test/new-target/new-target.test.ts +++ b/test/new-target/new-target.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle new.target syntax. #1", withTypeScript, (t, {typescript}) => { +test("Can handle new.target syntax. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( ` let result: boolean|undefined; @@ -16,7 +16,7 @@ test("Can handle new.target syntax. #1", withTypeScript, (t, {typescript}) => { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/nullish-coalescing/nullish-coalescing.test.ts b/test/nullish-coalescing/nullish-coalescing.test.ts index 425878c..8484868 100644 --- a/test/nullish-coalescing/nullish-coalescing.test.ts +++ b/test/nullish-coalescing/nullish-coalescing.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Supports nullish coalescing with null-like values. #1", withTypeScriptVersions(">=3.7"), (t, {typescript}) => { +test("Supports nullish coalescing with null-like values. #1", withTypeScriptVersions(">=3.7"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -10,7 +10,7 @@ test("Supports nullish coalescing with null-like values. #1", withTypeScriptVers const bar = foo ?? "bar"; `, `foo ?? "bar"`, - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/object-binding-pattern/object-binding-pattern.test.ts b/test/object-binding-pattern/object-binding-pattern.test.ts index eccb230..7fe8ba3 100644 --- a/test/object-binding-pattern/object-binding-pattern.test.ts +++ b/test/object-binding-pattern/object-binding-pattern.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ObjectBindingPatterns in VariableDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectBindingPatterns in VariableDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -12,14 +12,14 @@ test("Can handle ObjectBindingPatterns in VariableDeclarations. #1", withTypeScr })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 123); }); -test("Can handle ObjectBindingPatterns in VariableDeclarations. #2", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectBindingPatterns in VariableDeclarations. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -29,14 +29,14 @@ test("Can handle ObjectBindingPatterns in VariableDeclarations. #2", withTypeScr })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 245); }); -test("Can handle ObjectBindingPatterns in ParameterDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectBindingPatterns in ParameterDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -45,14 +45,14 @@ test("Can handle ObjectBindingPatterns in ParameterDeclarations. #1", withTypeSc })({foo: 2}); `, "(({foo}) =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can handle ObjectBindingPatterns in ParameterDeclarations. #2", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectBindingPatterns in ParameterDeclarations. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -61,7 +61,7 @@ test("Can handle ObjectBindingPatterns in ParameterDeclarations. #2", withTypeSc })({foo: 2}); `, "(({foo: alias}) =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/object-literal-expression/object-literal-expression.test.ts b/test/object-literal-expression/object-literal-expression.test.ts index 5e461c9..ebcd27e 100644 --- a/test/object-literal-expression/object-literal-expression.test.ts +++ b/test/object-literal-expression/object-literal-expression.test.ts @@ -1,9 +1,9 @@ import test from "ava"; -import { UndefinedIdentifierError } from "../../src/interpreter/error/undefined-identifier-error/undefined-identifier-error.js"; +import {UndefinedIdentifierError} from "../../src/interpreter/error/undefined-identifier-error/undefined-identifier-error.js"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle ObjectLiteralExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -16,7 +16,7 @@ test("Can handle ObjectLiteralExpressions. #1", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -25,7 +25,7 @@ test("Can handle ObjectLiteralExpressions. #1", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #2", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -38,7 +38,7 @@ test("Can handle ObjectLiteralExpressions. #2", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -47,7 +47,7 @@ test("Can handle ObjectLiteralExpressions. #2", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #3", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -62,7 +62,7 @@ test("Can handle ObjectLiteralExpressions. #3", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -71,7 +71,7 @@ test("Can handle ObjectLiteralExpressions. #3", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #4", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -82,7 +82,7 @@ test("Can handle ObjectLiteralExpressions. #4", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -91,7 +91,7 @@ test("Can handle ObjectLiteralExpressions. #4", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #5", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #5", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -102,7 +102,7 @@ test("Can handle ObjectLiteralExpressions. #5", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -111,7 +111,7 @@ test("Can handle ObjectLiteralExpressions. #5", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #6", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #6", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -122,7 +122,7 @@ test("Can handle ObjectLiteralExpressions. #6", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -131,7 +131,7 @@ test("Can handle ObjectLiteralExpressions. #6", withTypeScript, (t, {typescript} } }); -test("Can handle ObjectLiteralExpressions. #7", withTypeScript, (t, {typescript}) => { +test("Can handle ObjectLiteralExpressions. #7", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -141,11 +141,11 @@ test("Can handle ObjectLiteralExpressions. #7", withTypeScript, (t, {typescript} }) `, "({", - {typescript} + {typescript, useTypeChecker} ); if (result.success) t.fail(`Expected evaluation to throw`); else { - t.true(result.reason instanceof UndefinedIdentifierError) + t.true(result.reason instanceof UndefinedIdentifierError); } }); diff --git a/test/optional-chaining/optional-chaining.test.ts b/test/optional-chaining/optional-chaining.test.ts index 51d9fd3..af262e2 100644 --- a/test/optional-chaining/optional-chaining.test.ts +++ b/test/optional-chaining/optional-chaining.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Supports optional CallExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript}) => { +test("Supports optional CallExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -10,7 +10,7 @@ test("Supports optional CallExpressions. #1", withTypeScriptVersions(">=3.7"), ( const bar = foo.bar.baz?.(); `, "foo.bar.baz?.()", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -19,7 +19,7 @@ test("Supports optional CallExpressions. #1", withTypeScriptVersions(">=3.7"), ( } }); -test("Supports optional PropertyAccessExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript}) => { +test("Supports optional PropertyAccessExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -27,7 +27,7 @@ test("Supports optional PropertyAccessExpressions. #1", withTypeScriptVersions(" const bar = foo.bar?.baz; `, "foo.bar?.baz", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -36,7 +36,7 @@ test("Supports optional PropertyAccessExpressions. #1", withTypeScriptVersions(" } }); -test("Supports optional ElementAccessExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript}) => { +test("Supports optional ElementAccessExpressions. #1", withTypeScriptVersions(">=3.7"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -44,7 +44,7 @@ test("Supports optional ElementAccessExpressions. #1", withTypeScriptVersions("> const bar = foo.bar?.["baz"]; `, `foo.bar?.["baz"]`, - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/policy/policy.test.ts b/test/policy/policy.test.ts index d33c983..89842f7 100644 --- a/test/policy/policy.test.ts +++ b/test/policy/policy.test.ts @@ -7,7 +7,7 @@ import {NonDeterministicError} from "../../src/interpreter/error/policy-error/no import {NetworkError} from "../../src/interpreter/error/policy-error/network-error/network-error.js"; import {ProcessError} from "../../src/interpreter/error/policy-error/process-error/process-error.js"; -test("Throws on IO read if the policy requires it. #1", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -24,6 +24,7 @@ test("Throws on IO read if the policy requires it. #1", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -42,7 +43,7 @@ test("Throws on IO read if the policy requires it. #1", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on IO read if the policy requires it. #2", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -59,6 +60,7 @@ test("Throws on IO read if the policy requires it. #2", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -77,7 +79,7 @@ test("Throws on IO read if the policy requires it. #2", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on IO read if the policy requires it. #3", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -95,6 +97,7 @@ test("Throws on IO read if the policy requires it. #3", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -113,7 +116,7 @@ test("Throws on IO read if the policy requires it. #3", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on IO read if the policy requires it. #4", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -131,6 +134,7 @@ test("Throws on IO read if the policy requires it. #4", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -149,7 +153,7 @@ test("Throws on IO read if the policy requires it. #4", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on IO read if the policy requires it. #5", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #5", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -166,6 +170,7 @@ test("Throws on IO read if the policy requires it. #5", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -184,7 +189,7 @@ test("Throws on IO read if the policy requires it. #5", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on IO read if the policy requires it. #6", withTypeScript, (t, {typescript}) => { +test("Throws on IO read if the policy requires it. #6", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -201,6 +206,7 @@ test("Throws on IO read if the policy requires it. #6", withTypeScript, (t, {typ "(() => ", { typescript, + useTypeChecker, policy: { io: { read: false, @@ -219,7 +225,7 @@ test("Throws on IO read if the policy requires it. #6", withTypeScript, (t, {typ else t.deepEqual(result.value, true); }); -test("Throws on invoking Math.random() read if the policy is non-deterministic. #1", withTypeScript, (t, {typescript}) => { +test("Throws on invoking Math.random() read if the policy is non-deterministic. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -235,6 +241,7 @@ test("Throws on invoking Math.random() read if the policy is non-deterministic. "(() => ", { typescript, + useTypeChecker, policy: { deterministic: true }, @@ -250,7 +257,7 @@ test("Throws on invoking Math.random() read if the policy is non-deterministic. else t.deepEqual(result.value, true); }); -test("Doesn't throws on _getting_ Math.random, even if the policy is non-deterministic. #1", withTypeScript, (t, {typescript}) => { +test("Doesn't throws on _getting_ Math.random, even if the policy is non-deterministic. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -266,6 +273,7 @@ test("Doesn't throws on _getting_ Math.random, even if the policy is non-determi "(() => ", { typescript, + useTypeChecker, policy: { deterministic: true }, @@ -281,7 +289,7 @@ test("Doesn't throws on _getting_ Math.random, even if the policy is non-determi else t.deepEqual(result.value, true); }); -test("Throws on constructing new Date() without arguments if the policy is non-deterministic. #1", withTypeScript, (t, {typescript}) => { +test("Throws on constructing new Date() without arguments if the policy is non-deterministic. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -297,6 +305,7 @@ test("Throws on constructing new Date() without arguments if the policy is non-d "(() => ", { typescript, + useTypeChecker, policy: { deterministic: true }, @@ -312,7 +321,7 @@ test("Throws on constructing new Date() without arguments if the policy is non-d else t.deepEqual(result.value, true); }); -test("Doesn't throws on construction of a new Date with a specific date input, even if the policy is non-deterministic. #1", withTypeScript, (t, {typescript}) => { +test("Doesn't throws on construction of a new Date with a specific date input, even if the policy is non-deterministic. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -329,6 +338,7 @@ test("Doesn't throws on construction of a new Date with a specific date input, e "(() => ", { typescript, + useTypeChecker, policy: { deterministic: true }, @@ -344,7 +354,7 @@ test("Doesn't throws on construction of a new Date with a specific date input, e else t.deepEqual(result.value, true); }); -test("Throws on Network activity if the policy requires it. #1", withTypeScript, (t, {typescript}) => { +test("Throws on Network activity if the policy requires it. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -361,6 +371,7 @@ test("Throws on Network activity if the policy requires it. #1", withTypeScript, "(() => ", { typescript, + useTypeChecker, policy: { network: false }, @@ -376,7 +387,7 @@ test("Throws on Network activity if the policy requires it. #1", withTypeScript, else t.deepEqual(result.value, true); }); -test("Throws on Network activity if the policy requires it. #2", withTypeScript, (t, {typescript}) => { +test("Throws on Network activity if the policy requires it. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -393,6 +404,7 @@ test("Throws on Network activity if the policy requires it. #2", withTypeScript, "(() => ", { typescript, + useTypeChecker, policy: { network: false }, @@ -408,7 +420,7 @@ test("Throws on Network activity if the policy requires it. #2", withTypeScript, else t.deepEqual(result.value, true); }); -test("Throws on attempting to exit the Process if the policy requires it. #1", withTypeScript, (t, {typescript}) => { +test("Throws on attempting to exit the Process if the policy requires it. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -424,6 +436,7 @@ test("Throws on attempting to exit the Process if the policy requires it. #1", w "(() => ", { typescript, + useTypeChecker, policy: { process: false }, @@ -440,7 +453,7 @@ test("Throws on attempting to exit the Process if the policy requires it. #1", w else t.deepEqual(result.value, true); }); -test("Throws on attempting to spawn a child process if the policy requires it. #1", withTypeScript, (t, {typescript}) => { +test("Throws on attempting to spawn a child process if the policy requires it. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -457,6 +470,7 @@ test("Throws on attempting to spawn a child process if the policy requires it. # "(() => ", { typescript, + useTypeChecker, policy: { process: false }, diff --git a/test/postfix-unary-expression/postfix-unary-expression.test.ts b/test/postfix-unary-expression/postfix-unary-expression.test.ts index 30bb4c6..b53c853 100644 --- a/test/postfix-unary-expression/postfix-unary-expression.test.ts +++ b/test/postfix-unary-expression/postfix-unary-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle PostfixUnaryExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle PostfixUnaryExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { // noinspection BadExpressionStatementJS const {result} = executeProgram( // language=TypeScript @@ -16,7 +16,7 @@ test("Can handle PostfixUnaryExpressions. #1", withTypeScript, (t, {typescript}) (() => foo())(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/property-declaration/property-declaration.test.ts b/test/property-declaration/property-declaration.test.ts index f319f17..6d501e7 100644 --- a/test/property-declaration/property-declaration.test.ts +++ b/test/property-declaration/property-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript, withTypeScriptVersions} from "../setup/ts-macro.js"; -test("Can evaluate and retrieve a PropertyDeclaration. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate and retrieve a PropertyDeclaration. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -11,7 +11,7 @@ test("Can evaluate and retrieve a PropertyDeclaration. #1", withTypeScript, (t, } `, "someInstanceProp", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); @@ -20,7 +20,7 @@ test("Can evaluate and retrieve a PropertyDeclaration. #1", withTypeScript, (t, } }); -test("Can evaluate and retrieve a private PropertyDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript}) => { +test("Can evaluate and retrieve a private PropertyDeclaration. #1", withTypeScriptVersions(">=3.8"), (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -29,7 +29,7 @@ test("Can evaluate and retrieve a private PropertyDeclaration. #1", withTypeScri } `, "#someInstanceProp", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/setup/execute-program.ts b/test/setup/execute-program.ts index c21092a..dae94a8 100644 --- a/test/setup/execute-program.ts +++ b/test/setup/execute-program.ts @@ -69,7 +69,11 @@ export function executeProgram( result: evaluate({ ...context, node: entryNode, - typeChecker: program.getTypeChecker() + ...(context.useTypeChecker + ? { + typeChecker: program.getTypeChecker() + } + : {}) }) }; } diff --git a/test/setup/test-context.ts b/test/setup/test-context.ts index 4a8c8aa..c6169a0 100644 --- a/test/setup/test-context.ts +++ b/test/setup/test-context.ts @@ -5,11 +5,14 @@ import {LogLevelKind} from "../../src/interpreter/logger/log-level.js"; const _process = process; export interface TestContext extends PartialExcept, "typescript"> { cwd: string; + useTypeChecker: boolean; } export function createTestContext({ typescript, environment, + useTypeChecker = true, + moduleOverrides = {}, cwd = _process.cwd(), policy: { deterministic = true, @@ -33,7 +36,9 @@ export function createTestContext({ cwd, typescript, environment, + moduleOverrides, reporting, + useTypeChecker, policy: { maxOps, maxOpDuration, diff --git a/test/setup/ts-macro.ts b/test/setup/ts-macro.ts index 7c1c675..fe5f831 100644 --- a/test/setup/ts-macro.ts +++ b/test/setup/ts-macro.ts @@ -22,19 +22,20 @@ const pkg = getNearestPackageJson(); // ava macros export interface ExtendedImplementationArgumentOptions { + useTypeChecker: boolean; typescript: typeof TS; typescriptModuleSpecifier: string; } export type ExtendedImplementation = (t: ExecutionContext, options: ExtendedImplementationArgumentOptions) => void | Promise; -function makeTypeScriptMacro(version: string, specifier: string) { +function makeTypeScriptMacro(version: string, specifier: string, useTypeChecker: boolean) { const macro: Macro<[ExtendedImplementation]> = async (t, impl) => { let typescript = await import(specifier); if ("default" in typescript) { typescript = typescript.default; } - return impl(t, {typescript, typescriptModuleSpecifier: specifier}); + return impl(t, {useTypeChecker, typescript, typescriptModuleSpecifier: specifier}); }; - macro.title = (provided = "") => `${provided} (TypeScript v${version})`; + macro.title = (provided = "") => `${provided} (TypeScript v${version}) (typeChecker: ${useTypeChecker})`; return macro; } @@ -48,7 +49,7 @@ const {devDependencies} = pkg as {devDependencies: Record}; // Set of all TypeScript versions parsed from package.json const availableTsVersions = new Set(); // Map of TypeScript version to ava macro -const macros = new Map>(); +const macros = new Map, Macro<[ExtendedImplementation]>]>(); const tsRangeRegex = /(npm:typescript@)?[\^~]*(.+)$/; const filter = process.env.TS_VERSION; @@ -60,7 +61,10 @@ for (const [specifier, range] of Object.entries(devDependencies)) { if (context === "npm:typescript@" || specifier === "typescript") { availableTsVersions.add(version); if (filter === undefined || (filter.toUpperCase() === "CURRENT" && specifier === "typescript") || semver.satisfies(version, filter, {includePrerelease: true})) { - macros.set(version, makeTypeScriptMacro(version, specifier)); + macros.set(version, [ + makeTypeScriptMacro(version, specifier, true), + makeTypeScriptMacro(version, specifier, false) + ]); } } } @@ -73,7 +77,7 @@ Available TypeScript versions: ${[...availableTsVersions].join(", ")}`); } export function withTypeScriptVersions(extraFilter: string): OneOrMoreMacros<[ExtendedImplementation], unknown> { - const filteredMacros = [...macros.entries()].filter(([version]) => semver.satisfies(version, extraFilter, {includePrerelease: true})).map(([, macro]) => macro); + const filteredMacros = [...macros.entries()].filter(([version]) => semver.satisfies(version, extraFilter, {includePrerelease: true})).flatMap(([, macro]) => macro); if (filteredMacros.length === 0) { filteredMacros.push(noMatchingVersionMacro); diff --git a/test/spread-assignment/spread-assignment.test.ts b/test/spread-assignment/spread-assignment.test.ts index 8281b7b..c0a59d5 100644 --- a/test/spread-assignment/spread-assignment.test.ts +++ b/test/spread-assignment/spread-assignment.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle Spread assignments to objects. #1", withTypeScript, (t, {typescript}) => { +test("Can handle Spread assignments to objects. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -19,7 +19,7 @@ test("Can handle Spread assignments to objects. #1", withTypeScript, (t, {typesc })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/spread-element/spread-element.test.ts b/test/spread-element/spread-element.test.ts index c348da7..9a3ed2e 100644 --- a/test/spread-element/spread-element.test.ts +++ b/test/spread-element/spread-element.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can handle Spread Elements in arrays. #1", withTypeScript, (t, {typescript}) => { +test("Can handle Spread Elements in arrays. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -13,14 +13,14 @@ test("Can handle Spread Elements in arrays. #1", withTypeScript, (t, {typescript })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value as number[], [1, 2, 3]); }); -test("Can handle Spread Elements in CallExpressions. #1", withTypeScript, (t, {typescript}) => { +test("Can handle Spread Elements in CallExpressions. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -34,7 +34,7 @@ test("Can handle Spread Elements in CallExpressions. #1", withTypeScript, (t, {t })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/switch/switch.test.ts b/test/switch/switch.test.ts index 1e12d07..967f80c 100644 --- a/test/switch/switch.test.ts +++ b/test/switch/switch.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression with a SwitchStatement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -20,14 +20,14 @@ test("Can evaluate a CallExpression with a SwitchStatement. #1", withTypeScript, myFunc("a"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 0); }); -test("Can evaluate a CallExpression with a SwitchStatement. #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement. #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -45,14 +45,14 @@ test("Can evaluate a CallExpression with a SwitchStatement. #2", withTypeScript, myFunc("b"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 1); }); -test("Can evaluate a CallExpression with a SwitchStatement. #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement. #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -70,14 +70,14 @@ test("Can evaluate a CallExpression with a SwitchStatement. #3", withTypeScript, myFunc("c"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 2); }); -test("Can evaluate a CallExpression with a SwitchStatement. #4", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement. #4", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -97,14 +97,14 @@ test("Can evaluate a CallExpression with a SwitchStatement. #4", withTypeScript, myFunc("c"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 4); }); -test("Can evaluate a CallExpression with a SwitchStatement. #5", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement. #5", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -129,14 +129,14 @@ test("Can evaluate a CallExpression with a SwitchStatement. #5", withTypeScript, myFunc("a"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 0); }); -test("Can evaluate a CallExpression with a SwitchStatement with a fall-through. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a SwitchStatement with a fall-through. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -161,7 +161,7 @@ test("Can evaluate a CallExpression with a SwitchStatement with a fall-through. myFunc("b"); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/try-catch/try-catch.test.ts b/test/try-catch/try-catch.test.ts index 406e605..cf0cf50 100644 --- a/test/try-catch/try-catch.test.ts +++ b/test/try-catch/try-catch.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can capture errors that would otherwise throw with try-catch. #1", withTypeScript, (t, {typescript}) => { +test("Can capture errors that would otherwise throw with try-catch. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -17,7 +17,7 @@ test("Can capture errors that would otherwise throw with try-catch. #1", withTyp })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/type-alias-declaration/type-alias-declaration.test.ts b/test/type-alias-declaration/type-alias-declaration.test.ts index 61bb7b1..9db0742 100644 --- a/test/type-alias-declaration/type-alias-declaration.test.ts +++ b/test/type-alias-declaration/type-alias-declaration.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Understands TypeAliasDeclarations. #1", withTypeScript, (t, {typescript}) => { +test("Understands TypeAliasDeclarations. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -14,7 +14,7 @@ test("Understands TypeAliasDeclarations. #1", withTypeScript, (t, {typescript}) })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/type-of-expression/type-of-expression.test.ts b/test/type-of-expression/type-of-expression.test.ts index 217269a..8fff50c 100644 --- a/test/type-of-expression/type-of-expression.test.ts +++ b/test/type-of-expression/type-of-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a TypeOfExpression #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a TypeOfExpression #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -12,14 +12,14 @@ test("Can evaluate a TypeOfExpression #1", withTypeScript, (t, {typescript}) => })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, "bigint"); }); -test("Can evaluate a TypeOfExpression #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate a TypeOfExpression #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -30,7 +30,7 @@ test("Can evaluate a TypeOfExpression #2", withTypeScript, (t, {typescript}) => })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/void-expression/void-expression.test.ts b/test/void-expression/void-expression.test.ts index d80cb83..a9691d1 100644 --- a/test/void-expression/void-expression.test.ts +++ b/test/void-expression/void-expression.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate VoidExpressions #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate VoidExpressions #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -14,14 +14,14 @@ test("Can evaluate VoidExpressions #1", withTypeScript, (t, {typescript}) => { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, 1); }); -test("Can evaluate VoidExpressions #2", withTypeScript, (t, {typescript}) => { +test("Can evaluate VoidExpressions #2", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -32,14 +32,14 @@ test("Can evaluate VoidExpressions #2", withTypeScript, (t, {typescript}) => { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); else t.deepEqual(result.value, undefined); }); -test("Can evaluate VoidExpressions #3", withTypeScript, (t, {typescript}) => { +test("Can evaluate VoidExpressions #3", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -51,7 +51,7 @@ test("Can evaluate VoidExpressions #3", withTypeScript, (t, {typescript}) => { })(); `, "(() =>", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack); diff --git a/test/while/while.test.ts b/test/while/while.test.ts index cf71a18..ac24d7d 100644 --- a/test/while/while.test.ts +++ b/test/while/while.test.ts @@ -2,7 +2,7 @@ import test from "ava"; import {executeProgram} from "../setup/execute-program.js"; import {withTypeScript} from "../setup/ts-macro.js"; -test("Can evaluate a CallExpression with a WhileStatement. #1", withTypeScript, (t, {typescript}) => { +test("Can evaluate a CallExpression with a WhileStatement. #1", withTypeScript, (t, {typescript, useTypeChecker}) => { const {result} = executeProgram( // language=TypeScript ` @@ -16,7 +16,7 @@ test("Can evaluate a CallExpression with a WhileStatement. #1", withTypeScript, myFunc(); `, "myFunc(", - {typescript} + {typescript, useTypeChecker} ); if (!result.success) t.fail(result.reason.stack);