@@ -10,26 +10,11 @@ import { isValidLuaIdentifier } from "../utils/safe-names";
1010import { isExpressionWithEvaluationEffect } from "../utils/typescript" ;
1111import { transformElementAccessArgument } from "./access" ;
1212import { isMultiReturnCall , shouldMultiReturnCallBeWrapped } from "./language-extensions/multi" ;
13- import { isOperatorMapping , transformOperatorMappingExpression } from "./language-extensions/operators" ;
14- import {
15- isTableDeleteCall ,
16- isTableGetCall ,
17- isTableHasCall ,
18- isTableSetCall ,
19- transformTableDeleteExpression ,
20- transformTableGetExpression ,
21- transformTableHasExpression ,
22- transformTableSetExpression ,
23- } from "./language-extensions/table" ;
24- import {
25- annotationRemoved ,
26- invalidTableDeleteExpression ,
27- invalidTableSetExpression ,
28- unsupportedBuiltinOptionalCall ,
29- } from "../utils/diagnostics" ;
13+ import { annotationRemoved } from "../utils/diagnostics" ;
3014import { moveToPrecedingTemp , transformExpressionList } from "./expression-list" ;
3115import { transformInPrecedingStatementScope } from "../utils/preceding-statements" ;
32- import { transformOptionalChain , getOptionalContinuationData } from "./optional-chaining" ;
16+ import { getOptionalContinuationData , transformOptionalChain } from "./optional-chaining" ;
17+ import { transformLanguageExtensionCallExpression } from "./language-extensions" ;
3318
3419export type PropertyCallExpression = ts . CallExpression & { expression : ts . PropertyAccessExpression } ;
3520
@@ -234,52 +219,16 @@ export const transformCallExpression: FunctionVisitor<ts.CallExpression> = (node
234219 : undefined ;
235220 const wrapResultInTable = isMultiReturnCall ( context , node ) && shouldMultiReturnCallBeWrapped ( context , node ) ;
236221
237- const builtinResult = transformBuiltinCallExpression ( context , node , optionalContinuation !== undefined ) ;
238- if ( builtinResult ) {
239- if ( optionalContinuation ) {
240- context . diagnostics . push ( unsupportedBuiltinOptionalCall ( node ) ) ;
241- }
242- return wrapResultInTable ? wrapInTable ( builtinResult ) : builtinResult ;
243- }
244-
245222 if ( isTupleReturnCall ( context , node ) ) {
246223 context . diagnostics . push ( annotationRemoved ( node , AnnotationKind . TupleReturn ) ) ;
247224 }
248225
249- if ( isOperatorMapping ( context , node ) ) {
250- if ( optionalContinuation ) {
251- context . diagnostics . push ( unsupportedBuiltinOptionalCall ( node ) ) ;
252- return lua . createNilLiteral ( ) ;
253- }
254- return transformOperatorMappingExpression ( context , node ) ;
255- }
256-
257- if ( isTableDeleteCall ( context , node ) ) {
258- context . diagnostics . push ( invalidTableDeleteExpression ( node ) ) ;
259- context . addPrecedingStatements ( transformTableDeleteExpression ( context , node ) ) ;
260- return lua . createNilLiteral ( ) ;
261- }
262-
263- if ( isTableGetCall ( context , node ) ) {
264- if ( optionalContinuation ) {
265- context . diagnostics . push ( unsupportedBuiltinOptionalCall ( node ) ) ;
266- return lua . createNilLiteral ( ) ;
267- }
268- return transformTableGetExpression ( context , node ) ;
269- }
270-
271- if ( isTableHasCall ( context , node ) ) {
272- if ( optionalContinuation ) {
273- context . diagnostics . push ( unsupportedBuiltinOptionalCall ( node ) ) ;
274- return lua . createNilLiteral ( ) ;
275- }
276- return transformTableHasExpression ( context , node ) ;
277- }
278-
279- if ( isTableSetCall ( context , node ) ) {
280- context . diagnostics . push ( invalidTableSetExpression ( node ) ) ;
281- context . addPrecedingStatements ( transformTableSetExpression ( context , node ) ) ;
282- return lua . createNilLiteral ( ) ;
226+ const builtinOrExtensionResult =
227+ transformBuiltinCallExpression ( context , node , optionalContinuation !== undefined ) ??
228+ transformLanguageExtensionCallExpression ( context , node , optionalContinuation !== undefined ) ;
229+ if ( builtinOrExtensionResult ) {
230+ // unsupportedOptionalCall diagnostic already present
231+ return wrapResultInTable ? wrapInTable ( builtinOrExtensionResult ) : builtinOrExtensionResult ;
283232 }
284233
285234 if ( ts . isPropertyAccessExpression ( node . expression ) ) {
0 commit comments