Compile import/export syntax in @babel/runtime-related modules.

Case in point: @babel/runtime/helpers/esm/typeof.js uses ECMAScript module
syntax (import, export), but must not be compiled with transforms like
@babel/plugin-transform-typeof-symbol, since it's part of the runtime
library depended upon by that transform.

This logic is an extreme implementation detail for sure, but at least
babel-compiler is the only code that needs to know about this complexity.
This commit is contained in:
Ben Newman
2019-06-19 11:06:12 -04:00
parent 26d4cb33c6
commit a4586e4332

View File

@@ -77,9 +77,10 @@ BCp.processOneFileForTarget = function (inputFile, source) {
! toBeAdded.bare &&
// If you need to exclude a specific file within an app from Babel
// compilation, give it the following file extension: .es5.js
! isInputFilePathExcluded(inputFilePath)) {
var extraFeatures = Object.assign({}, this.extraFeatures);
var arch = inputFile.getArch();
! excludedFileExtensionPattern.test(inputFilePath)) {
const extraFeatures = { ...this.extraFeatures };
const arch = inputFile.getArch();
if (arch.startsWith("os.")) {
// Start with a much simpler set of Babel presets and plugins if
@@ -96,6 +97,14 @@ BCp.processOneFileForTarget = function (inputFile, source) {
extraFeatures.jscript = true;
}
if (shouldCompileModulesOnly(inputFilePath)) {
// Modules like @babel/runtime/helpers/esm/typeof.js need to be
// compiled to support ECMAScript modules syntax, but should *not*
// be compiled in any other way (for more explanation, see my longer
// comment in shouldCompileModulesOnly).
extraFeatures.compileModulesOnly = true;
}
var babelOptions = Babel.getDefaultOptions(extraFeatures);
babelOptions.caller = { name: "meteor", arch };
@@ -165,11 +174,7 @@ BCp.processOneFileForTarget = function (inputFile, source) {
return toBeAdded;
};
function isInputFilePathExcluded(path) {
if (excludedFileExtensionPattern.test(path)) {
return true;
}
function shouldCompileModulesOnly(path) {
const parts = path.split("/");
const nmi = parts.lastIndexOf("node_modules");
if (nmi >= 0) {