File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,10 +142,15 @@ export class LuaTransformer {
142142
143143 if ( this . options . luaEntry ) {
144144 const requireCalls = this . options . luaEntry . map ( entry => {
145- const formattedEntryName = tsHelper . formatPathToLuaPath ( entry . replace ( / .t s $ / , "" ) ) ;
146- return tstl . createExpressionStatement (
147- this . createModuleRequire ( ts . createStringLiteral ( formattedEntryName ) , false )
148- ) ;
145+ const sourceFile = this . program . getSourceFile ( entry ) ;
146+ if ( sourceFile ) {
147+ const formattedEntryName = tsHelper . getExportPath ( sourceFile . fileName , this . options ) ;
148+ return tstl . createExpressionStatement (
149+ this . createModuleRequire ( ts . createStringLiteral ( formattedEntryName ) , false )
150+ ) ;
151+ } else {
152+ throw TSTLErrors . LuaEntryNotFound ( entry ) ;
153+ }
149154 } ) ;
150155 combinedStatements . push ( ...requireCalls ) ;
151156 }
Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ export const InvalidThrowExpression = (node: ts.Node) =>
6060export const ForbiddenStaticClassPropertyName = ( node : ts . Node , name : string ) =>
6161 new TranspileError ( `Cannot use "${ name } " as a static class property or method name.` , node ) ;
6262
63+ export const LuaEntryNotFound = ( entryName : string ) =>
64+ new TranspileError ( `Could not find luaEntry file '${ entryName } '.` , ts . createNode ( ts . SyntaxKind . Unknown ) ) ;
65+
6366export const MissingClassName = ( node : ts . Node ) => new TranspileError ( `Class declarations must have a name.` , node ) ;
6467
6568export const MissingForOfVariables = ( node : ts . Node ) =>
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import * as ts from "typescript";
22import { TranspileError } from "./TranspileError" ;
33
44export const transpileError = ( error : TranspileError ) : ts . Diagnostic => ( {
5- file : error . node . getSourceFile ( ) ,
6- start : error . node . getStart ( ) ,
7- length : error . node . getWidth ( ) ,
5+ file : error . node . kind === ts . SyntaxKind . Unknown ? undefined : error . node . getSourceFile ( ) ,
6+ start : error . node . kind === ts . SyntaxKind . Unknown ? undefined : error . node . getStart ( ) ,
7+ length : error . node . kind === ts . SyntaxKind . Unknown ? undefined : error . node . getWidth ( ) ,
88 category : ts . DiagnosticCategory . Error ,
99 code : 0 ,
1010 source : "typescript-to-lua" ,
Original file line number Diff line number Diff line change 11import * as util from "../util" ;
22import * as ts from "typescript" ;
3+ import * as TSTLErrors from "../../src/TSTLErrors" ;
34import { CompilerOptions } from "../../src/CompilerOptions" ;
45
56const exportValueSource = "export const value = true;" ;
@@ -115,4 +116,18 @@ describe("outFile", () => {
115116 . setOptions ( outFileOptionsWithEntry ( "main.ts" ) )
116117 . expectNoExecutionError ( ) ;
117118 } ) ;
119+
120+ test ( "luaEntry doesn't exist" , ( ) => {
121+ util . testBundle ``
122+ . setOptions ( outFileOptionsWithEntry ( "entry.ts" ) )
123+ . expectToHaveDiagnosticOfError ( TSTLErrors . LuaEntryNotFound ( "entry.ts" ) ) ;
124+ } ) ;
125+
126+ test ( "luaEntry resolved from path specified in tsconfig" , ( ) => {
127+ util . testBundle ``
128+ . addExtraFile ( "src/main.ts" , "" )
129+ . addExtraFile ( "src/module.ts" , "" )
130+ . setOptions ( { rootDir : "src" , ...outFileOptionsWithEntry ( "src/main.ts" ) } )
131+ . expectToHaveNoDiagnostics ( ) ;
132+ } ) ;
118133} ) ;
You can’t perform that action at this time.
0 commit comments