refactor(static-module-record): Source type is invariant
MODIFY
packages/static-module-record/src/babelPlugin.js
packages/static-module-record/src/babelPlugin.js
@@ -40,6 +40,7 @@ const collectPatternIdentifiers = (path, pattern) => {
function makeModulePlugins(options) {
const {
+ sourceType,
exportAlls,
fixedExportMap,
imports,
@@ -48,6 +49,10 @@ function makeModulePlugins(options) {
liveExportMap,
} = options;
+ if (sourceType !== 'module') {
+ throw new Error(`Module sourceType must be 'module'`);
+ }
+
const updaterSources = Object.create(null);
/**
* Indicates that a name is declared at the top level and is never
@@ -560,7 +565,6 @@ function makeModulePlugins(options) {
},
});
- if (options.sourceType === 'module') {
// Add the module visitor.
switch (pass) {
case 0:
@@ -575,14 +579,9 @@ function makeModulePlugins(options) {
default:
throw TypeError(`Unrecognized module pass ${pass}`);
}
- }
- return { visitor };
};
- const rewriters = [rewriteModules(0)];
- if (options.sourceType === 'module') {
- rewriters.push(rewriteModules(1));
- }
+ const rewriters = [rewriteModules(0), rewriteModules(1)];
return rewriters;
}

refactor(static-module-record): Source type is invariant