@@ -2,11 +2,10 @@ import * as ts from "typescript";
22import * as lua from "../../LuaAST" ;
33import { assert } from "../../utils" ;
44import { FunctionVisitor } from "../context" ;
5- import { notAllowedTopLevelAwait } from "../utils/diagnostics" ;
65import { createExportsIdentifier } from "../utils/lua-ast" ;
76import { getUsedLuaLibFeatures } from "../utils/lualib" ;
87import { performHoisting , popScope , pushScope , ScopeType } from "../utils/scope" ;
9- import { hasExportEquals , traverseWithoutCrossingFunction } from "../utils/typescript" ;
8+ import { hasExportEquals } from "../utils/typescript" ;
109
1110export const transformSourceFileNode : FunctionVisitor < ts . SourceFile > = ( node , context ) => {
1211 let statements : lua . Statement [ ] = [ ] ;
@@ -25,11 +24,6 @@ export const transformSourceFileNode: FunctionVisitor<ts.SourceFile> = (node, co
2524 } else {
2625 pushScope ( context , ScopeType . File ) ;
2726
28- // await cannot be used outside of async functions due to it using yield which needs to be inside a coroutine
29- for ( const topLevelAwait of node . statements . filter ( isTopLevelAwait ) ) {
30- context . diagnostics . push ( notAllowedTopLevelAwait ( topLevelAwait ) ) ;
31- }
32-
3327 statements = performHoisting ( context , context . transformStatements ( node . statements ) ) ;
3428 popScope ( context ) ;
3529
@@ -50,14 +44,3 @@ export const transformSourceFileNode: FunctionVisitor<ts.SourceFile> = (node, co
5044 const trivia = node . getFullText ( ) . match ( / ^ # ! .* \r ? \n / ) ?. [ 0 ] ?? "" ;
5145 return lua . createFile ( statements , getUsedLuaLibFeatures ( context ) , trivia , node ) ;
5246} ;
53-
54- function isTopLevelAwait ( statement : ts . Statement ) {
55- // Check if expression contains an await child, without going into function declarations
56- let containsAwait = false ;
57- traverseWithoutCrossingFunction ( statement , node => {
58- if ( ts . isAwaitExpression ( node ) ) {
59- containsAwait = true ;
60- }
61- } ) ;
62- return containsAwait ;
63- }
0 commit comments