Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: restore typescript 5.6 compatibility #301

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default function transformer(
...tsTransformPathsContext,
sourceFile,
isDeclarationFile: sourceFile.isDeclarationFile,
originalSourceFile: (<typeof ts>tsInstance).getOriginalSourceFile(sourceFile),
originalSourceFile: ts.getParseTreeNode(sourceFile, ts.isSourceFile) || sourceFile,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR description - both of these methods are not marked as @internal.

This is the exact implementation of getOriginalSourceFile: https://github.com/microsoft/TypeScript/blob/c8a7d589e647e19c94150d9892909f3aa93e48eb/src/compiler/utilities.ts#L5416-L5419

getVisitor() {
return nodeVisitor.bind(this);
},
Expand Down
4 changes: 4 additions & 0 deletions test/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import ts from "typescript";
import tsThree from "typescript-3";
import tsFourSeven from "typescript-4.7";
import tsFiveFive from "typescript-5.5";
import tsFiveSix from "typescript-5.6";
import path from "node:path";

export const tsModules = <const>[
["3.6.5", tsThree, "typescript-3"],
["4.7.4", tsFourSeven, "typescript-4.7"],
["5.5.4", tsFiveFive, "typescript-5.5"],
["5.6.3", tsFiveSix, "typescript-5.6"],
["Latest", ts, "typescript"],
Comment on lines +12 to 13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, 5.6.3 and latest are the same thing right now. However, I wanted to explicitly define 5.6.3 so we run tests against it. Then, when 5.7++ come out, we'll get test coverage.

];

Expand Down
4 changes: 3 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"ts-patch": "^3.2.1",
"tsp1": "npm:ts-patch@1.*.*",
"tsp2": "npm:ts-patch@2.*.*",
"typescript": "^5.5.4",
"typescript": "^5.6.3",
"typescript-3": "npm:typescript@3.6.5",
"typescript-4.7": "npm:typescript@4.7.4",
"typescript-5.5": "npm:typescript@5.5.4",
"typescript-5.6": "npm:typescript@5.6.3",
"typescript-transform-paths": "portal:../"
},
"workspaces": [
Expand Down
2 changes: 2 additions & 0 deletions test/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function patchTsModules() {

patchTypescript("typescript-3", patch1);
patchTypescript("typescript-4.7", patch2);
patchTypescript("typescript-5.5", patch);
patchTypescript("typescript-5.6", patch);
patchTypescript("typescript", patch);
}

Expand Down
10 changes: 8 additions & 2 deletions test/tests/extras.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ describe(`Extra Tests`, () => {
});

describe(`ts-node register script`, () => {
/** Yarn sometimes outputs bold text, which makes these tests flakey */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were failing for me when I ran them locally. The output of yarn seems to include control characters to bold the string null, which is why I'm stripping the string with this method.

 FAIL  tests/extras.test.ts (8.413 s)
  ● Extra Tests › Built Tests › ts-node register script › Works with --transpileOnly

    expect(received).toMatch(expected)

    Expected pattern: /^null($|\r?\n)/m
    Received string:  "null
    "

      37 |       test(`Works with --transpileOnly`, () => {
      38 |         const res = execSync("yarn g:ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
    > 39 |         expect(res).toMatch(/^null($|\r?\n)/m);
         |                     ^
      40 |       });
      41 |
      42 |       test(`Works with --typeCheck`, () => {

      at Object.<anonymous> (tests/extras.test.ts:39:21)

  ● Extra Tests › Built Tests › ts-node register script › Works with --typeCheck

    expect(received).toMatch(expected)

    Expected pattern: /^null($|\r?\n)/
    Received string:  "null
    "

      42 |       test(`Works with --typeCheck`, () => {
      43 |         const res = execSync("yarn g:ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
    > 44 |         expect(res).toMatch(/^null($|\r?\n)/);
         |                     ^
      45 |       });
      46 |     });
      47 |   });

      at Object.<anonymous> (tests/extras.test.ts:44:21)

function stripAnsi(str: string) {
// eslint-disable-next-line no-control-regex
return str.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "");
}

test(`Works with --transpileOnly`, () => {
const res = execSync("yarn g:ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
expect(res).toMatch(/^null($|\r?\n)/m);
expect(stripAnsi(res.trim())).toEqual("null");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of caring about the newline (which can be different between windows and mac), I just .trim() it.

});

test(`Works with --typeCheck`, () => {
const res = execSync("yarn g:ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
expect(res).toMatch(/^null($|\r?\n)/);
expect(stripAnsi(res.trim())).toEqual("null");
});
});
});
Expand Down
42 changes: 27 additions & 15 deletions test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8069,9 +8069,11 @@ __metadata:
ts-patch: "npm:^3.2.1"
tsp1: "npm:ts-patch@1.*.*"
tsp2: "npm:ts-patch@2.*.*"
typescript: "npm:^5.5.4"
typescript: "npm:^5.6.3"
typescript-3: "npm:typescript@3.6.5"
typescript-4.7: "npm:typescript@4.7.4"
typescript-5.5: "npm:typescript@5.5.4"
typescript-5.6: "npm:typescript@5.6.3"
typescript-transform-paths: "portal:../"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -9230,6 +9232,26 @@ __metadata:
languageName: node
linkType: hard

"typescript-5.5@npm:typescript@5.5.4":
version: 5.5.4
resolution: "typescript@npm:5.5.4"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/422be60f89e661eab29ac488c974b6cc0a660fb2228003b297c3d10c32c90f3bcffc1009b43876a082515a3c376b1eefcce823d6e78982e6878408b9a923199c
languageName: node
linkType: hard

"typescript-5.6@npm:typescript@5.6.3, typescript@npm:^5.6.3":
version: 5.6.3
resolution: "typescript@npm:5.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/44f61d3fb15c35359bc60399cb8127c30bae554cd555b8e2b46d68fa79d680354b83320ad419ff1b81a0bdf324197b29affe6cc28988cd6a74d4ac60c94f9799
languageName: node
linkType: hard

"typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A.":
version: 0.0.0-use.local
resolution: "typescript-transform-paths@portal:../::locator=root-workspace-0b6124%40workspace%3A."
Expand All @@ -9240,23 +9262,13 @@ __metadata:
languageName: node
linkType: soft

"typescript@npm:^5.5.4":
version: 5.5.4
resolution: "typescript@npm:5.5.4"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/422be60f89e661eab29ac488c974b6cc0a660fb2228003b297c3d10c32c90f3bcffc1009b43876a082515a3c376b1eefcce823d6e78982e6878408b9a923199c
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.5.4#optional!builtin<compat/typescript>":
version: 5.5.4
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=379a07"
"typescript@patch:typescript@npm%3A^5.6.3#optional!builtin<compat/typescript>":
version: 5.6.3
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=74658d"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/73409d7b9196a5a1217b3aaad929bf76294d3ce7d6e9766dd880ece296ee91cf7d7db6b16c6c6c630ee5096eccde726c0ef17c7dfa52b01a243e57ae1f09ef07
checksum: 10c0/ac8307bb06bbfd08ae7137da740769b7d8c3ee5943188743bb622c621f8ad61d244767480f90fbd840277fbf152d8932aa20c33f867dea1bb5e79b187ca1a92f
languageName: node
linkType: hard

Expand Down
Loading