@@ -209,11 +209,7 @@ struct BridgeJSLink {
209209 }
210210
211211 private func generateVariableDeclarations ( ) -> [ String ] {
212- let hasAssociatedValueEnums = exportedSkeletons . contains { skeleton in
213- skeleton . enums . contains { $0 . enumType == . associatedValue }
214- }
215-
216- var declarations = [
212+ return [
217213 " let \( JSGlueVariableScope . reservedInstance ) ; " ,
218214 " let \( JSGlueVariableScope . reservedMemory ) ; " ,
219215 " let \( JSGlueVariableScope . reservedSetException ) ; " ,
@@ -237,25 +233,12 @@ struct BridgeJSLink {
237233 " let \( JSGlueVariableScope . reservedTmpParamF64s ) = []; " ,
238234 " let \( JSGlueVariableScope . reservedTmpRetPointers ) = []; " ,
239235 " let \( JSGlueVariableScope . reservedTmpParamPointers ) = []; " ,
236+ " const \( JSGlueVariableScope . reservedEnumHelpers ) = {}; " ,
237+ " const \( JSGlueVariableScope . reservedStructHelpers ) = {}; " ,
238+ " " ,
239+ " let _exports = null; " ,
240+ " let bjs = null; " ,
240241 ]
241-
242- let hasStructs = exportedSkeletons . contains { skeleton in
243- ! skeleton . structs . isEmpty
244- }
245-
246- if hasAssociatedValueEnums {
247- declarations . append ( " const enumHelpers = {}; " )
248- }
249-
250- if hasStructs {
251- declarations . append ( " const structHelpers = {}; " )
252- }
253-
254- declarations . append ( " " )
255- declarations . append ( " let _exports = null; " )
256- declarations . append ( " let bjs = null; " )
257-
258- return declarations
259242 }
260243
261244 /// Checks if a skeleton contains any closure types
@@ -1050,7 +1033,7 @@ struct BridgeJSLink {
10501033 printer . write (
10511034 " const \( enumDef . name ) Helpers = __bjs_create \( enumDef . valuesName ) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts ) , \( JSGlueVariableScope . reservedTmpParamF32s ) , \( JSGlueVariableScope . reservedTmpParamF64s ) , \( JSGlueVariableScope . reservedTextEncoder ) , \( JSGlueVariableScope . reservedSwift ) ); "
10521035 )
1053- printer . write ( " enumHelpers .\( enumDef . name ) = \( enumDef . name ) Helpers; " )
1036+ printer . write ( " \( JSGlueVariableScope . reservedEnumHelpers ) . \( enumDef . name ) = \( enumDef . name ) Helpers; " )
10541037 printer . nextLine ( )
10551038 }
10561039 }
@@ -1064,9 +1047,11 @@ struct BridgeJSLink {
10641047 for skeleton in exportedSkeletons {
10651048 for structDef in skeleton . structs {
10661049 printer . write (
1067- " const \( structDef . name ) Helpers = __bjs_create \( structDef . name ) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts ) , \( JSGlueVariableScope . reservedTmpParamF32s ) , \( JSGlueVariableScope . reservedTmpParamF64s ) , \( JSGlueVariableScope . reservedTmpParamPointers ) , \( JSGlueVariableScope . reservedTmpRetPointers ) , \( JSGlueVariableScope . reservedTextEncoder ) , \( JSGlueVariableScope . reservedSwift ) , enumHelpers); "
1050+ " const \( structDef . name ) Helpers = __bjs_create \( structDef . name ) Helpers()( \( JSGlueVariableScope . reservedTmpParamInts ) , \( JSGlueVariableScope . reservedTmpParamF32s ) , \( JSGlueVariableScope . reservedTmpParamF64s ) , \( JSGlueVariableScope . reservedTmpParamPointers ) , \( JSGlueVariableScope . reservedTmpRetPointers ) , \( JSGlueVariableScope . reservedTextEncoder ) , \( JSGlueVariableScope . reservedSwift ) , \( JSGlueVariableScope . reservedEnumHelpers ) ); "
1051+ )
1052+ printer . write (
1053+ " \( JSGlueVariableScope . reservedStructHelpers ) . \( structDef . name ) = \( structDef . name ) Helpers; "
10681054 )
1069- printer . write ( " structHelpers. \( structDef . name ) = \( structDef . name ) Helpers; " )
10701055 printer . nextLine ( )
10711056 }
10721057 }
0 commit comments