@@ -9,8 +9,11 @@ module.exports = ({template, types}) => {
99 AssignmentExpression ( path ) {
1010 const name = `${ path . get ( 'left.object.name' ) . node } .${ path . get ( `left.property.name` ) . node } `
1111 if ( name === 'exports.default' ) {
12- const finder = new ExportFinder ( path )
13- if ( ! finder . isOnlyDefaultExport ( ) ) {
12+ const finder = new ExportsFinder ( path )
13+ if ( ! finder . isOnlyExportsDefault ( ) ) {
14+ return
15+ }
16+ if ( finder . isAmd ( ) ) {
1417 return
1518 }
1619 const rootPath = finder . getRootPath ( )
@@ -37,17 +40,17 @@ module.exports = ({template, types}) => {
3740 }
3841}
3942
40- class ExportFinder {
41- constructor ( path ) {
42- this . path = path
43+ class ExportsFinder {
44+ constructor ( exportsDefaultPath ) {
45+ this . path = exportsDefaultPath
4346 this . hasExportsDefault = false
4447 this . hasExportsNamed = false
4548 this . hasModuleExports = false
4649 }
4750 getRootPath ( ) {
4851 return this . path . parentPath . parentPath
4952 }
50- isOnlyDefaultExport ( ) {
53+ isOnlyExportsDefault ( ) {
5154 this . getRootPath ( ) . get ( 'body' ) . forEach ( ( path ) => {
5255 if ( path . isVariableDeclaration ( ) ) {
5356 this . findExport ( path . get ( 'declarations.0' ) , 'init' )
@@ -79,4 +82,20 @@ class ExportFinder {
7982 }
8083 return null
8184 }
85+ isAmd ( ) {
86+ const rootPath = this . getRootPath ( )
87+ const hasntAmdRoot = ! ( rootPath . parentPath && rootPath . parentPath . parentPath )
88+ if ( hasntAmdRoot ) {
89+ return false
90+ }
91+
92+ const amdRoot = rootPath . parentPath . parentPath
93+ if ( ! amdRoot . isCallExpression ( ) ) {
94+ return false
95+ }
96+ if ( amdRoot . get ( 'callee.name' ) . node === 'define' ) {
97+ return true
98+ }
99+ return false
100+ }
82101}
0 commit comments