Skip to content

Commit

Permalink
feat: TypeScript 5.6 supported
Browse files Browse the repository at this point in the history
  • Loading branch information
acutmore committed Sep 11, 2024
1 parent 9d6af45 commit c914165
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"types": "./out/index.d.ts",
"dependencies": {
"typescript": "5.1.6 - 5.5.x"
"typescript": "5.1.6 - 5.6.x"
},
"imports": {
"#r": "./loader/register.js",
Expand Down
30 changes: 11 additions & 19 deletions tests/ecosystem/ecosystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "node:test";
import { test, type TestContext } from "node:test";
import assert from "node:assert";
import * as fs from "node:fs";
import { join } from "node:path";
Expand Down Expand Up @@ -26,12 +26,11 @@ const skipList = new Set([
"constructorOverloads9.ts",
// esbuild can't parse: "ERROR: Cannot continue to label "target1"
"continueTarget3.ts",
// Prettier can't yet parse: `import {"0n" as foo}`
"bigintArbirtraryIdentifier.ts",
]);

/**
* @param {string} filename
*/
function validFileName(filename) {
function validFileName(filename: string) {
if (!filename.endsWith(".ts")) {
return false;
}
Expand All @@ -54,29 +53,25 @@ for (const filename of fs.readdirSync(typescriptCompilerCasesDir, {
return;
}
const path = join(typescriptCompilerCasesDir, filename);
await sameEmit(fs.readFileSync(path, "utf-8"), t);
await sameEmit(fs.readFileSync(path, "utf-8"), t, filename);
});
if (i++ % 100 === 0) {
await new Promise((r) => setTimeout(r));
}
}

/**
* @param {string} source
* @param {import("node:test").TestContext} t
*/
async function sameEmit(source, t, multipart = false) {
async function sameEmit(source: string, t: TestContext, filename: string, multipart = false) {
if (!multipart && source.match(/\/\/ ?@filename:/i)) {
const parts = source.split(/(?=\/\/ ?@filename:)/gi).filter((v) => v.trim());
for (const section of parts) {
const match = section.match(/@filename:(.+)/);
if (!match) continue;
const filename = match[/* capture-group: */ 1];
if (!validFileName(filename)) {
const virtualFilename = match[/* capture-group: */ 1].trim();
if (!validFileName(virtualFilename)) {
continue;
}
await t.test(`multipart: ${filename}`, async (t) => {
await sameEmit(section, t, /* multipart: */ true);
await t.test(`multipart: ${filename}/${virtualFilename}`, async (t) => {
await sameEmit(section, t, filename, /* multipart: */ true);
});
}
return;
Expand Down Expand Up @@ -136,10 +131,7 @@ function tidyLines(input) {
.filter((line) => line);
}

/**
* @param {string} input
*/
async function normalizeJS(input) {
async function normalizeJS(input: string) {
let minified;

try {
Expand Down
4 changes: 4 additions & 0 deletions tests/fixture/cases/modules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**/import type T from "node:assert";
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `import type`

import { "🙂" as C2 } from "./modules";

type I = any;
class C {}
C === C2;

/**/export type { I };
// ^^^^^^^^^^^^^^^^^^ `export type`
Expand All @@ -17,6 +20,7 @@ export {
C,
type T,
// ^^^^^^
C as "🙂"
}

/**/export type T2 = 1;
Expand Down
4 changes: 3 additions & 1 deletion tests/fixture/cases/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"compilerOptions": {
"target": "esnext",
"moduleDetection": "force"
"module": "esnext",
"moduleDetection": "force",
"allowSyntheticDefaultImports": true
}
}
6 changes: 5 additions & 1 deletion tests/fixture/output/modules.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c914165

Please sign in to comment.