File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
2- "name" : " typescript-to-lua" ,
3- "version" : " 1.33.2" ,
2+ "name" : " its- typescript-to-lua" ,
3+ "version" : " 1.33.2-2 " ,
44 "description" : " A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!" ,
55 "repository" : " https://github.com/TypeScriptToLua/TypeScriptToLua" ,
66 "homepage" : " https://typescripttolua.github.io/" ,
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ export interface TypeScriptToLuaOptions {
4646 tstlVerbose ?: boolean ;
4747 lua51AllowTryCatchInAsyncAwait ?: boolean ;
4848 measurePerformance ?: boolean ;
49+ arrayIndexModification ?: ArrayIndexModification ;
4950}
5051
5152export type CompilerOptions = OmitIndexSignature < ts . CompilerOptions > &
@@ -76,9 +77,17 @@ export enum BuildMode {
7677 Library = "library" ,
7778}
7879
80+ export enum ArrayIndexModification {
81+ Never = "never" ,
82+ Always = "always" ,
83+ }
84+
7985export const isBundleEnabled = ( options : CompilerOptions ) =>
8086 options . luaBundle !== undefined && options . luaBundleEntry !== undefined ;
8187
88+ export const arrayIndexModificationEnabled = ( options : CompilerOptions ) =>
89+ options . arrayIndexModification !== ArrayIndexModification . Never ;
90+
8291export function validateOptions ( options : CompilerOptions ) : ts . Diagnostic [ ] {
8392 const diagnostics : ts . Diagnostic [ ] = [ ] ;
8493
Original file line number Diff line number Diff line change @@ -104,6 +104,11 @@ export const optionDeclarations: CommandLineOption[] = [
104104 description : "Measure performance of the tstl compiler." ,
105105 type : "boolean" ,
106106 } ,
107+ {
108+ name : "arrayIndexModification" ,
109+ description : "If array indexing operations should be modified (0 based to 1 based)." ,
110+ type : "string" ,
111+ } ,
107112] ;
108113
109114export function updateParsedConfigFile ( parsedConfigFile : ts . ParsedCommandLine ) : ParsedCommandLine {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525import { SyntaxKind } from "typescript" ;
2626import { getCustomNameFromSymbol } from "./identifier" ;
2727import { getSymbolExportScope , isSymbolExported } from "../utils/export" ;
28+ import { arrayIndexModificationEnabled } from "../../CompilerOptions" ;
2829
2930function addOneToArrayAccessArgument (
3031 context : TransformationContext ,
@@ -34,7 +35,10 @@ function addOneToArrayAccessArgument(
3435 const type = context . checker . getTypeAtLocation ( node . expression ) ;
3536 const argumentType = context . checker . getTypeAtLocation ( node . argumentExpression ) ;
3637 if ( isArrayType ( context , type ) && isNumberType ( context , argumentType ) ) {
37- return addToNumericExpression ( index , 1 ) ;
38+ const options = context . program . getCompilerOptions ( ) ;
39+ if ( arrayIndexModificationEnabled ( options ) ) {
40+ return addToNumericExpression ( index , 1 ) ;
41+ }
3842 }
3943 return index ;
4044}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { unsupportedProperty } from "../utils/diagnostics";
66import { isArrayType , isNumberType } from "../utils/typescript" ;
77import { addToNumericExpression } from "../utils/lua-ast" ;
88import { transformOptionalDeleteExpression } from "./optional-chaining" ;
9+ import { arrayIndexModificationEnabled } from "../../CompilerOptions" ;
910
1011export const transformDeleteExpression : FunctionVisitor < ts . DeleteExpression > = ( node , context ) => {
1112 if ( ts . isOptionalChain ( node . expression ) ) {
@@ -27,7 +28,10 @@ export const transformDeleteExpression: FunctionVisitor<ts.DeleteExpression> = (
2728 const argumentType = context . checker . getTypeAtLocation ( node . expression . argumentExpression ) ;
2829
2930 if ( isArrayType ( context , type ) && isNumberType ( context , argumentType ) ) {
30- propertyExpression = addToNumericExpression ( propertyExpression , 1 ) ;
31+ const options = context . program . getCompilerOptions ( ) ;
32+ if ( arrayIndexModificationEnabled ( options ) ) {
33+ propertyExpression = addToNumericExpression ( propertyExpression , 1 ) ;
34+ }
3135 }
3236 }
3337
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export abstract class TestBuilder {
165165 moduleResolution : ts . ModuleResolutionKind . Node10 ,
166166 resolveJsonModule : true ,
167167 sourceMap : true ,
168+ arrayIndexModification : tstl . ArrayIndexModification . Never ,
168169 } ;
169170 public setOptions ( options : tstl . CompilerOptions = { } ) : this {
170171 this . throwIfProgramExists ( "setOptions" ) ;
Original file line number Diff line number Diff line change 102102 "measurePerformance" : {
103103 "description" : " Measure and report performance of the tstl compiler." ,
104104 "type" : " boolean"
105+ },
106+ "arrayIndexModification" : {
107+ "description" : " If array indexing operations should be modified (0 based to 1 based)." ,
108+ "type" : " string" ,
109+ "enum" : [" never" , " always" ]
105110 }
106111 },
107112 "dependencies" : {
You can’t perform that action at this time.
0 commit comments