@@ -2,8 +2,8 @@ import mockRequire from 'mock-require';
22import path from 'path' ;
33import resolveFrom from 'resolve-from' ;
44import 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
88const pluginMarker = Symbol ( 'pluginMarker' ) ;
99class 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 }
0 commit comments