From a5751003a7f29b45f81a96fa942541b288fe3eca Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sat, 9 Jun 2018 16:08:22 -0400 Subject: [PATCH] Use lazyFinalizer function when calling addJavaScript in BabelCompiler. --- packages/babel-compiler/babel-compiler.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/babel-compiler/babel-compiler.js b/packages/babel-compiler/babel-compiler.js index 7c9e5a7c8e..b3c91795bb 100644 --- a/packages/babel-compiler/babel-compiler.js +++ b/packages/babel-compiler/babel-compiler.js @@ -21,15 +21,29 @@ var hasOwn = Object.prototype.hasOwnProperty; var isMeteorPre144 = semver.lt(process.version, "4.8.1"); BCp.processFilesForTarget = function (inputFiles) { + var compiler = this; + // Reset this cache for each batch processed. this._babelrcCache = null; inputFiles.forEach(function (inputFile) { - var toBeAdded = this.processOneFileForTarget(inputFile); - if (toBeAdded) { - inputFile.addJavaScript(toBeAdded); + var fileOptions = inputFile.getFileOptions(); + + if (inputFile.supportsLazyCompilation) { + inputFile.addJavaScript({ + path: inputFile.getPathInPackage(), + hash: inputFile.getSourceHash(), + bare: !! fileOptions.bare + }, function () { + return compiler.processOneFileForTarget(inputFile); + }); + } else { + var toBeAdded = compiler.processOneFileForTarget(inputFile); + if (toBeAdded) { + inputFile.addJavaScript(toBeAdded); + } } - }, this); + }); }; // Returns an object suitable for passing to inputFile.addJavaScript, or