Skip to content

Commit 5d1269d

Browse files
committed
Add babel for let/const lowering
This reverts commit 8623e3ee6936bf15418fc437b45d7621ca732296.
1 parent 822eb94 commit 5d1269d

File tree

3 files changed

+1287
-7
lines changed

3 files changed

+1287
-7
lines changed

Gulpfile.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 @@ 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: we could use ts.transpileModule for this, but running babel is faster to get this singular transform.
193+
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"]);
194+
await del([preBabel, `${preBabel}.map`]);
195+
}
196+
},
187197
clean: () => del([outfile, `${outfile}.map`]),
188198
watch: () => esbuild.build({ ...options, watch: true }),
189199
};
@@ -211,7 +221,7 @@ cleanTasks.push(cleanDebugTools);
211221
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools));
212222

213223

214-
const esbuildTsc = esbuildTask("./src/tsc/tsc.ts", "./built/local/tsc.js", /* exportIsTsObject */ true);
224+
const esbuildTsc = esbuildTask("./src/tsc/tsc.ts", "./built/local/tsc.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
215225

216226

217227
const buildTsc = () => {
@@ -238,7 +248,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
238248
// Pre-build steps to use based on supplied options.
239249
const preBuild = cmdLineOptions.lkg ? lkgPreBuild : localPreBuild;
240250

241-
const esbuildServices = esbuildTask("./src/typescript/typescript.ts", "./built/local/typescript.js", /* exportIsTsObject */ true);
251+
const esbuildServices = esbuildTask("./src/typescript/typescript.ts", "./built/local/typescript.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
242252

243253
// TODO(jakebailey): rename this; no longer "services".
244254
const buildServices = () => {
@@ -268,7 +278,7 @@ task("watch-services").flags = {
268278
};
269279

270280

271-
const esbuildServer = esbuildTask("./src/tsserver/server.ts", "./built/local/tsserver.js", /* exportIsTsObject */ true);
281+
const esbuildServer = esbuildTask("./src/tsserver/server.ts", "./built/local/tsserver.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
272282

273283
const buildServer = () => {
274284
if (cmdLineOptions.bundle) return esbuildServer.build();
@@ -311,7 +321,7 @@ task("watch-min").flags = {
311321
" --built": "Compile using the built version of the compiler."
312322
};
313323

314-
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true);
324+
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
315325

316326
const buildLssl = () => {
317327
if (cmdLineOptions.bundle) return esbuildLssl.build();

0 commit comments

Comments
 (0)