Skip to content

Commit a88fedb

Browse files
committed
Add babel for let/const lowering
This reverts commit 8623e3ee6936bf15418fc437b45d7621ca732296.
1 parent c388116 commit a88fedb

File tree

3 files changed

+1286
-7
lines changed

3 files changed

+1286
-7
lines changed

Gulpfile.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -206,7 +209,13 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
206209

207210
// TODO: these need to have better function names, for gulp.
208211
return {
209-
build: () => esbuild.build(options),
212+
build: async () => {
213+
await esbuild.build(options);
214+
if (performanceMatters) {
215+
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"]);
216+
await del([preBabel, `${preBabel}.map`]);
217+
}
218+
},
210219
clean: () => del([outfile, `${outfile}.map`]),
211220
watch: () => esbuild.build({ ...options, watch: true }),
212221
};
@@ -238,7 +247,7 @@ cleanTasks.push(cleanDebugTools);
238247
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools));
239248

240249

241-
const esbuildTsc = esbuildTask("./src/tsc/tsc.ts", "./built/local/tsc.js", /* exportIsTsObject */ true);
250+
const esbuildTsc = esbuildTask("./src/tsc/tsc.ts", "./built/local/tsc.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
242251

243252

244253
const buildTsc = () => cmdLineOptions.bundle ? esbuildTsc.build() : buildProject("src/tsc");
@@ -260,7 +269,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
260269
// Pre-build steps to use based on supplied options.
261270
const 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
const buildServices = () => cmdLineOptions.bundle ? esbuildServices.build() : buildProject("src/typescript");
266275

@@ -285,7 +294,7 @@ task("watch-services").flags = {
285294
};
286295

287296

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

290299
const buildServer = () => cmdLineOptions.bundle ? esbuildServer.build() : buildProject("src/tsserver");
291300
buildServer.displayName = "buildServer";
@@ -323,7 +332,7 @@ task("watch-min").flags = {
323332
" --built": "Compile using the built version of the compiler."
324333
};
325334

326-
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true);
335+
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
327336

328337
const buildLssl = () => cmdLineOptions.bundle ? esbuildLssl.build() : buildProject("src/tsserverlibrary");
329338
task("lssl", series(preBuild, buildLssl));

0 commit comments

Comments
 (0)