( workspace: Workspace, logger: ILogger | undefined, request: CompileNativeRequestBody, )
| 115 | } |
| 116 | |
| 117 | export async function compileNative( |
| 118 | workspace: Workspace, |
| 119 | logger: ILogger | undefined, |
| 120 | request: CompileNativeRequestBody, |
| 121 | ): Promise<CompileNativeResponseBody> { |
| 122 | const filesToOpen: string[] = []; |
| 123 | |
| 124 | for (const inputFile of request.inputFiles) { |
| 125 | let relativePath: string; |
| 126 | if (request.registerInputFiles) { |
| 127 | const stripIndex = inputFile.indexOf(request.stripIncludePrefix); |
| 128 | if (stripIndex < 0) { |
| 129 | throw new Error(`Invalid strip include prefix '${request.stripIncludePrefix}' for file path ${inputFile}`); |
| 130 | } |
| 131 | relativePath = inputFile.substring(stripIndex + request.stripIncludePrefix.length + 1); |
| 132 | |
| 133 | workspace.registerDiskFile(relativePath, inputFile); |
| 134 | } else { |
| 135 | relativePath = inputFile; |
| 136 | } |
| 137 | |
| 138 | if ( |
| 139 | (inputFile.endsWith('.ts') && !inputFile.endsWith('.d.ts')) || |
| 140 | inputFile.endsWith('.tsx') || |
| 141 | inputFile.endsWith('.js') |
| 142 | ) { |
| 143 | filesToOpen.push(relativePath); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (!workspace.initialized) { |
| 148 | await workspace.initialize(); |
| 149 | } |
| 150 | |
| 151 | const openedFiles = await Promise.all(filesToOpen.map((file) => workspace.openFile(file))); |
| 152 | const allIRs: NativeCompilerIR.Base[] = []; |
| 153 | const shouldCheckSyntax = !!request.registerInputFiles; |
| 154 | |
| 155 | const options = { |
| 156 | optimizeSlots: true, |
| 157 | optimizeVarRefs: true, |
| 158 | |
| 159 | // smaller code size and faster |
| 160 | optimizeNullChecks: true, |
| 161 | mergeSetProperties: true, |
| 162 | foldConstants: true, |
| 163 | optimizeVarRefLoads: true, |
| 164 | optimizeAssignments: true, |
| 165 | inlinePropertyCache: true, |
| 166 | enableIntrinsics: true, // unsafe, replace some builtin functions with intrinsics |
| 167 | |
| 168 | mergeReleases: false, // smaller code size, very slightly slower |
| 169 | autoRelease: false, // smaller code size, slightly slower |
| 170 | noinlineRetainRelease: false, // smaller code size, slower |
| 171 | }; |
| 172 | let fileIndex = 0; |
| 173 | for (const openedFile of openedFiles) { |
| 174 | const relativePath = filesToOpen[fileIndex]; |
no test coverage detected