@@ -2,7 +2,6 @@ import * as ts from "typescript";
22import * as lua from "../../LuaAST" ;
33import { FunctionVisitor , Visitors } from "../context" ;
44import { validateAssignment } from "../utils/assignment-validation" ;
5- import { isInDestructingAssignment } from "../utils/typescript" ;
65
76const transformAssertionExpression : FunctionVisitor < ts . AssertionExpression > = ( expression , context ) => {
87 if ( ! ts . isConstTypeReference ( expression . type ) ) {
@@ -17,43 +16,15 @@ const transformAssertionExpression: FunctionVisitor<ts.AssertionExpression> = (e
1716 return context . transformExpression ( expression . expression ) ;
1817} ;
1918
20- function isWithinLiteralAssignmentStatement ( node : ts . Node ) : boolean {
21- if ( ! node . parent ) {
22- return false ;
23- }
24-
25- if (
26- ts . isArrayLiteralExpression ( node . parent ) ||
27- ts . isArrayBindingPattern ( node . parent ) ||
28- ts . isObjectLiteralExpression ( node . parent )
29- ) {
30- return isWithinLiteralAssignmentStatement ( node . parent ) ;
31- } else if ( isInDestructingAssignment ( node ) ) {
32- return true ;
33- } else if ( ts . isBinaryExpression ( node . parent ) && node . parent . operatorToken . kind === ts . SyntaxKind . EqualsToken ) {
34- return true ;
35- } else {
36- return false ;
37- }
38- }
39-
40- // TODO: Consider handling without a visitor since it depends on context too much
41- const transformOmittedExpression : FunctionVisitor < ts . OmittedExpression > = node => {
42- const isWithinBindingAssignmentStatement = isWithinLiteralAssignmentStatement ( node ) ;
43- return isWithinBindingAssignmentStatement ? lua . createAnonymousIdentifier ( ) : lua . createNilLiteral ( node ) ;
44- } ;
45-
4619export const todoMoveSomewhereVisitors : Visitors = {
47- [ ts . SyntaxKind . EmptyStatement ] : ( ) => undefined ,
48- [ ts . SyntaxKind . OmittedExpression ] : transformOmittedExpression ,
49-
5020 [ ts . SyntaxKind . TypeAliasDeclaration ] : ( ) => undefined ,
5121 [ ts . SyntaxKind . InterfaceDeclaration ] : ( ) => undefined ,
5222
5323 [ ts . SyntaxKind . NonNullExpression ] : ( node , context ) => context . transformExpression ( node . expression ) ,
5424 [ ts . SyntaxKind . AsExpression ] : transformAssertionExpression ,
5525 [ ts . SyntaxKind . TypeAssertionExpression ] : transformAssertionExpression ,
5626
27+ [ ts . SyntaxKind . EmptyStatement ] : ( ) => undefined ,
5728 [ ts . SyntaxKind . ParenthesizedExpression ] : ( node , context ) =>
5829 lua . createParenthesizedExpression ( context . transformExpression ( node . expression ) , node ) ,
5930} ;
0 commit comments