-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no-unused-modules: support dynamic imports
All occurences of `import('...')` are treated as namespace imports (`import * as X from '...'`)
- Loading branch information
1 parent
40d1e67
commit cff6dbb
Showing
13 changed files
with
217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const importPath = './exports-for-dynamic-js'; | ||
class A { | ||
method() { | ||
const c = import(importPath) | ||
} | ||
} | ||
|
||
|
||
class B { | ||
method() { | ||
const c = import('i-do-not-exist') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class A { | ||
method() { | ||
const c = import('./exports-for-dynamic-js') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const a = 10; | ||
export const b = 20; | ||
export const c = 30; | ||
const d = 40; | ||
export default d; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const a = 10 | ||
export const b = 20 | ||
export const c = 30 | ||
const d = 40 | ||
export default d |
6 changes: 6 additions & 0 deletions
6
tests/files/no-unused-modules/typescript/dynamic-import-ts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class A { | ||
method() { | ||
const c = import('./exports-for-dynamic-ts') | ||
} | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
tests/files/no-unused-modules/typescript/exports-for-dynamic-ts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const ts_a = 10 | ||
export const ts_b = 20 | ||
export const ts_c = 30 | ||
const ts_d = 40 | ||
export default ts_d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
exports.__esModule = true | ||
|
||
exports.default = function visit(node, keys, visitorSpec) { | ||
if (!node || !keys) { | ||
return | ||
} | ||
const type = node.type | ||
if (typeof visitorSpec[type] === 'function') { | ||
visitorSpec[type](node) | ||
} | ||
const childFields = keys[type] | ||
if (!childFields) { | ||
return | ||
} | ||
for (const fieldName of childFields) { | ||
const field = node[fieldName] | ||
if (Array.isArray(field)) { | ||
for (const item of field) { | ||
visit(item, keys, visitorSpec) | ||
} | ||
} else { | ||
visit(field, keys, visitorSpec) | ||
} | ||
} | ||
if (typeof visitorSpec[`${type}:Exit`] === 'function') { | ||
visitorSpec[`${type}:Exit`](node) | ||
} | ||
} |