testUnsupportedConstructsAreRejected

tcmts.core.test.hash.testUnsupportedConstructsAreRejected · #nxxhi6hx · term

Unsupported constructs are rejected with a reason.

import { analyzeFile } from "#codebase/tcmts/core/analyze";
import { dir, n } from "#codebase/tcmts/core/test/hash";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testUnsupportedConstructsAreRejected = () => {
  const file = path.join(dir, `bad${n++}.ts`);
  fs.writeFileSync(file, `var counter = 0`);
  const a = analyzeFile(file, { cacheDir: dir, resolveName: () => "" });
  assert.match(a.errors[0]!, /top-level `var`\/`using` is not supported/);
  // an ambient function would describe code tcm can't see
  const ambient = path.join(dir, `bad${n++}.ts`);
  fs.writeFileSync(ambient, `export {};\ndeclare function elsewhere(): void;\n`);
  assert.match(
    analyzeFile(ambient, { cacheDir: dir, resolveName: () => "" }).errors[0]!,
    /`declare` is not supported/,
  );
}

uses