@@ -140,14 +140,17 @@ function getCopyrightHeader() {
140140 * @param {string } entrypoint
141141 * @param {string } outfile
142142 * @param {boolean } exportIsTsObject True if this file exports the TS object and should have relevant code injected.
143+ * @param {boolean } performanceMatters True if this is a bundle where performance matters, so should be optimized at the cost of build time.
143144 */
144- function esbuildTask ( entrypoint , outfile , exportIsTsObject = false ) {
145+ function esbuildTask ( entrypoint , outfile , exportIsTsObject = false , performanceMatters = false ) {
146+ const preBabel = `${ outfile } .tmp.js` ;
147+
145148 /** @type {esbuild.BuildOptions } */
146149 const options = {
147150 entryPoints : [ entrypoint ] ,
148151 banner : { js : getCopyrightHeader ( ) } ,
149152 bundle : true ,
150- outfile,
153+ outfile : performanceMatters ? preBabel : outfile ,
151154 platform : "node" ,
152155 // TODO: also specify minimal browser targets
153156 target : "node10" , // Node 10 is the oldest benchmarker.
@@ -183,7 +186,15 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
183186 }
184187
185188 return {
186- build : ( ) => esbuild . build ( options ) ,
189+ build : async ( ) => {
190+ await esbuild . build ( options ) ;
191+ if ( performanceMatters ) {
192+ // TODO(jakebailey): we could use ts.transpileModule for this, but running babel is faster to get this singular transform.
193+ // If we did use ts.transpileModule, we'd need ts.ScriptTarget.ES5, which also will downlevel arrow functions, for-of, spread, etc.
194+ await exec ( process . execPath , [ "./node_modules/@babel/cli/bin/babel.js" , preBabel , "--out-file" , outfile , "--plugins" , "@babel/plugin-transform-block-scoping" , "--compact" , "false" , "--source-maps" ] ) ;
195+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
196+ }
197+ } ,
187198 clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
188199 watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
189200 } ;
@@ -211,7 +222,7 @@ cleanTasks.push(cleanDebugTools);
211222const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
212223
213224
214- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
225+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
215226
216227
217228const buildTsc = ( ) => {
@@ -238,7 +249,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
238249// Pre-build steps to use based on supplied options.
239250const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
240251
241- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
252+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
242253
243254// TODO(jakebailey): rename this; no longer "services".
244255const buildServices = ( ) => {
@@ -268,7 +279,7 @@ task("watch-services").flags = {
268279} ;
269280
270281
271- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
282+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
272283
273284const buildServer = ( ) => {
274285 if ( cmdLineOptions . bundle ) return esbuildServer . build ( ) ;
@@ -311,12 +322,7 @@ task("watch-min").flags = {
311322 " --built" : "Compile using the built version of the compiler."
312323} ;
313324
314- const buildLssl = ( ( ) => {
315- // TODO(jakebailey): fix this for modules
316- return cb => {
317- console . log ( "!!!TODO!!! buildLssl" ) ;
318- cb ( ) ;
319- } ;
325+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
320326
321327const buildLssl = ( ) => {
322328 if ( cmdLineOptions . bundle ) return esbuildLssl . build ( ) ;
0 commit comments