Skip to content

Commit a349301

Browse files
committed
fix: support TypeScriptToLua v0.35.0
1 parent eb8340b commit a349301

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"resolve-from": "^5.0.0",
4040
"resolve-global": "^1.0.0",
4141
"tslib": "^2.0.0",
42-
"typescript-to-lua": "^0.34.0"
42+
"typescript-to-lua": "^0.35.0"
4343
},
4444
"devDependencies": {
4545
"@ark120202/eslint-config": "^2.3.0",

src/index.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import mockRequire from 'mock-require';
22
import path from 'path';
33
import resolveFrom from 'resolve-from';
44
import resolveGlobal from 'resolve-global';
5-
import { ParsedCommandLine } from 'typescript-to-lua';
6-
import * as tsserverlibrary from 'typescript/lib/tsserverlibrary';
5+
import type * as tstl from 'typescript-to-lua';
6+
import type * as tsserverlibrary from 'typescript/lib/tsserverlibrary';
77

88
const pluginMarker = Symbol('pluginMarker');
99
class TSTLPlugin {
@@ -18,7 +18,7 @@ class TSTLPlugin {
1818
this.project.log(`[typescript-tstl-plugin] ${this.project.getProjectName()}: ${message}`);
1919
}
2020

21-
private parsedCommandLine?: ParsedCommandLine;
21+
private parsedCommandLine?: tstl.ParsedCommandLine;
2222
public update() {
2323
this.log('Updating project');
2424
if (!(this.project instanceof this.ts.server.ConfiguredProject)) return;
@@ -90,8 +90,26 @@ class TSTLPlugin {
9090
programOptions.emitDeclarationOnly = false;
9191

9292
try {
93-
const { diagnostics } = this.tstl.transpile({ program, sourceFiles: [sourceFile] });
94-
return diagnostics;
93+
let diagnostics: tsserverlibrary.Diagnostic[] | undefined;
94+
95+
// >=0.35.0
96+
if (this.tstl.getProgramTranspileResult !== undefined) {
97+
({ diagnostics } = this.tstl.getProgramTranspileResult(this.serverHost, () => {}, {
98+
program,
99+
sourceFiles: [sourceFile],
100+
}));
101+
}
102+
103+
// >=0.19.0
104+
if (this.tstl.transpile !== undefined) {
105+
({ diagnostics } = this.tstl.transpile({ program, sourceFiles: [sourceFile] }));
106+
}
107+
108+
if (diagnostics === undefined) {
109+
throw new Error(`Unsupported TypeScriptToLua version: ${this.tstl.version}`);
110+
}
111+
112+
return diagnostics.map(diag => ({ ...diag, code: undefined! }));
95113
} catch (error) {
96114
this.log(`Error during transpilation: ${error.stack}`);
97115
}

src/tstl.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-unnecessary-qualifier */
2+
import * as tstl from 'typescript-to-lua';
3+
4+
declare module 'typescript-to-lua' {
5+
export const transpile: ((options: tstl.TranspileOptions) => tstl.TranspileResult) | undefined;
6+
}

test-workspace/yarn.lock

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ normalize-path@^2.1.1:
3434
dependencies:
3535
remove-trailing-separator "^1.0.1"
3636

37+
path-parse@^1.0.6:
38+
version "1.0.6"
39+
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
40+
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
41+
3742
remove-trailing-separator@^1.0.1:
3843
version "1.1.0"
3944
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
@@ -51,15 +56,26 @@ resolve-global@^1.0.0:
5156
dependencies:
5257
global-dirs "^0.1.1"
5358

59+
resolve@^1.15.1:
60+
version "1.17.0"
61+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
62+
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
63+
dependencies:
64+
path-parse "^1.0.6"
65+
5466
source-map@^0.7.3:
5567
version "0.7.3"
5668
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
5769
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
5870

59-
tslib@^1.9.3:
60-
version "1.9.3"
61-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
62-
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==
71+
tslib@^2.0.0:
72+
version "2.0.0"
73+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.0.tgz#18d13fc2dce04051e20f074cc8387fd8089ce4f3"
74+
integrity sha512-lTqkx847PI7xEDYJntxZH89L2/aXInsyF2luSafe/+0fHOMjlBNXdH6th7f70qxLDhul7KZK0zC8V5ZIyHl0/g==
75+
76+
typescript-to-lua@^0.35.0:
77+
version "0.0.0"
78+
uid ""
6379

6480
"typescript-to-lua@link:../node_modules/typescript-to-lua":
6581
version "0.0.0"
@@ -69,7 +85,7 @@ tslib@^1.9.3:
6985
version "0.0.0"
7086
uid ""
7187

72-
typescript@^3.4.5:
73-
version "3.4.5"
74-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
75-
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
88+
typescript@^3.9.2:
89+
version "3.9.6"
90+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
91+
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,10 +1898,10 @@ type-fest@^0.8.1:
18981898
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
18991899
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
19001900

1901-
typescript-to-lua@^0.34.0:
1902-
version "0.34.0"
1903-
resolved "https://registry.yarnpkg.com/typescript-to-lua/-/typescript-to-lua-0.34.0.tgz#bd9cba84ce3fd8f44b13f17c7bd39ef2f3bf08db"
1904-
integrity sha512-00Sh6Pv90r664dEp1svHbML1A6/d8+SDdzeDFS3K6vFi9xht8ZGAxy8QRePK25/pclj9EV3caKYxb2x2mKv/PA==
1901+
typescript-to-lua@^0.35.0:
1902+
version "0.35.0"
1903+
resolved "https://registry.yarnpkg.com/typescript-to-lua/-/typescript-to-lua-0.35.0.tgz#abe468401ff7679abbd267c4faecfeef81bf0857"
1904+
integrity sha512-r79LfK1nWauFO4SR7q7pMCYjwW412Z17yx1WKp00SnVmYNwbm4fB/TsJuZe5jLtpZxAuGG8nVqtJEAsU5d1Bhg==
19051905
dependencies:
19061906
resolve "^1.15.1"
19071907
source-map "^0.7.3"

0 commit comments

Comments
 (0)