Skip to content

Commit

Permalink
Fix merging parser plugins in babel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Sep 25, 2018
1 parent 6c8c231 commit 4023c84
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/transforms/babel/babel6.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ async function babel6(asset, options) {
ecmaVersion: Infinity,
strictMode: false,
sourceType: 'module',
locations: true,
plugins: ['exportExtensions', 'dynamicImport']
locations: true
});

// Passing a list of plugins as part of parserOpts seems to override any custom
// syntax plugins a user might have added (e.g. decorators). We add dynamicImport
// using a plugin instead.
config.plugins = (config.plugins || []).concat(dynamicImport);

let res = babel.transform(asset.contents, config);
if (res.ast) {
asset.ast = babel6toBabel7(res.ast);
asset.isAstDirty = true;
}
}

function dynamicImport() {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push('dynamicImport');
}
};
}

module.exports = babel6;

0 comments on commit 4023c84

Please sign in to comment.