@@ -162,14 +162,17 @@ function getCopyrightHeader() {
162162 * @param {string } entrypoint
163163 * @param {string } outfile
164164 * @param {boolean } exportIsTsObject True if this file exports the TS object and should have relevant code injected.
165+ * @param {boolean } performanceMatters True if this is a bundle where performance matters, so should be optimized at the cost of build time.
165166 */
166- function esbuildTask ( entrypoint , outfile , exportIsTsObject = false ) {
167+ function esbuildTask ( entrypoint , outfile , exportIsTsObject = false , performanceMatters = false ) {
168+ const preBabel = `${ outfile } .tmp.js` ;
169+
167170 /** @type {esbuild.BuildOptions } */
168171 const options = {
169172 entryPoints : [ entrypoint ] ,
170173 banner : { js : getCopyrightHeader ( ) } ,
171174 bundle : true ,
172- outfile,
175+ outfile : performanceMatters ? preBabel : outfile ,
173176 platform : "node" ,
174177 // TODO: also specify minimal browser targets
175178 target : "node10" , // Node 10 is the oldest benchmarker.
@@ -205,7 +208,13 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
205208 }
206209
207210 return {
208- build : ( ) => esbuild . build ( options ) ,
211+ build : async ( ) => {
212+ await esbuild . build ( options ) ;
213+ if ( performanceMatters ) {
214+ 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" ] ) ;
215+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
216+ }
217+ } ,
209218 clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
210219 watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
211220 } ;
@@ -233,7 +242,7 @@ cleanTasks.push(cleanDebugTools);
233242const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
234243
235244
236- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
245+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
237246
238247
239248const buildTsc = ( ) => {
@@ -260,7 +269,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
260269// Pre-build steps to use based on supplied options.
261270const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
262271
263- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
272+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
264273
265274// TODO(jakebailey): rename this; no longer "services".
266275const buildServices = ( ) => {
@@ -290,7 +299,7 @@ task("watch-services").flags = {
290299} ;
291300
292301
293- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
302+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
294303
295304const buildServer = ( ) => {
296305 if ( cmdLineOptions . bundle ) return esbuildServer . build ( ) ;
@@ -333,7 +342,7 @@ task("watch-min").flags = {
333342 " --built" : "Compile using the built version of the compiler."
334343} ;
335344
336- const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true ) ;
345+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
337346
338347const buildLssl = ( ) => {
339348 if ( cmdLineOptions . bundle ) return esbuildLssl . build ( ) ;
0 commit comments