Skip to content

Commit

Permalink
[Fix] no-unused-modules: fix crash due to export *
Browse files Browse the repository at this point in the history
  • Loading branch information
Taranys authored and ljharb committed Oct 8, 2019
1 parent 112a0bf commit fcaca07
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/rules/no-unused-modules.js
Expand Up @@ -87,8 +87,13 @@ const prepareImportsAndExports = (srcFiles, context) => {

// dependencies === export * from
const currentExportAll = new Set()
dependencies.forEach(value => {
currentExportAll.add(value().path)
dependencies.forEach(getDependency => {
const dependency = getDependency()
if (dependency === null) {
return
}

currentExportAll.add(dependency.path)
})
exportAll.set(file, currentExportAll)

Expand Down
7 changes: 7 additions & 0 deletions tests/files/no-unused-modules/cjs.js
@@ -0,0 +1,7 @@
// Simple import extracted from 'redux-starter-kit' compiled file

function isPlain(val) {
return true;
}

exports.isPlain = isPlain;
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/filte-r.js
@@ -0,0 +1 @@
export * from './cjs'
16 changes: 16 additions & 0 deletions tests/src/rules/no-unused-modules.js
Expand Up @@ -453,6 +453,11 @@ describe('test behaviour for new file', () => {
test({ options: unusedExportsOptions,
code: `export * from '${testFilePath('./no-unused-modules/file-added-0.js')}'`,
filename: testFilePath('./no-unused-modules/file-0.js')}),
// Test export * from 'external-compiled-library'
test({ options: unusedExportsOptions,
code: `export * from 'external-compiled-library'`,
filename: testFilePath('./no-unused-modules/file-r.js'),
}),
],
invalid: [
test({ options: unusedExportsOptions,
Expand Down Expand Up @@ -638,3 +643,14 @@ describe('do not report unused export for files mentioned in package.json', () =
],
})
})

describe('Avoid errors if re-export all from umd compiled library', () => {
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `export * from '${testFilePath('./no-unused-modules/bin.js')}'`,
filename: testFilePath('./no-unused-modules/main/index.js')}),
],
invalid: [],
})
})

0 comments on commit fcaca07

Please sign in to comment.