File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // 1. find to ExportsModuleDeclaration(`Object.defineProperty(exports, "__esModule", {value: true});`)
2+ // 2. find to ExportsAssignmentExpression(`exports.default`, `exports.foo` etc)
3+ // 3. add `module.exports` if exists only `exports.default` assignment
4+ // The above works after executing `preset-env`(transform-es2015-modules-*) in `Plugin.post`
5+
16module . exports = ( { template, types} ) => {
27 let pluginOptions
3- const visitor = {
8+ const ExportsModuleDeclarationVisitor = {
49 CallExpression : {
510 exit ( path ) {
6- // Not `Object.defineProperty`, skip
7- if ( ! path . get ( 'callee.object' ) . node ) {
8- return
9- }
10-
1111 if ( isExportsModuleDeclaration ( path ) ) {
1212 const finder = new ExportFinder ( path )
1313
@@ -33,12 +33,17 @@ module.exports = ({template, types}) => {
3333 }
3434 } ,
3535 post ( fileMap ) {
36- fileMap . path . traverse ( visitor )
36+ fileMap . path . traverse ( ExportsModuleDeclarationVisitor )
3737 }
3838 }
3939}
4040
4141function isExportsModuleDeclaration ( path ) {
42+ // Not `Object.defineProperty`, skip
43+ if ( ! path . get ( 'callee.object' ) . node ) {
44+ return false
45+ }
46+
4247 const callee = `${ path . get ( 'callee.object.name' ) . node } .${ path . get ( 'callee.property.name' ) . node } `
4348 const args = path . get ( 'arguments' ) . map ( path => {
4449 if ( path . isStringLiteral ( ) ) {
You can’t perform that action at this time.
0 commit comments