Skip to content

Commit

Permalink
fix: skip type-import-style identifier in "declare module" (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
zertosh authored and gajus committed Apr 3, 2019
1 parent 6748dc5 commit 0f8a9b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rules/typeImportStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ const create = (context) => {
// Default to 'identifier'
const ignoreTypeDefault = context.options[1] &&
context.options[1].ignoreTypeDefault;
let isInsideDeclareModule = false;

return {
DeclareModule () {
isInsideDeclareModule = true;
},
'DeclareModule:exit' () {
isInsideDeclareModule = false;
},
ImportDeclaration (node) {
if (node.importKind !== 'type') {
return;
}

// type specifiers are not allowed inside module declarations:
// https://github.com/facebook/flow/issues/7609
if (isInsideDeclareModule) {
return;
}

if (
ignoreTypeDefault &&
node.specifiers[0] &&
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/assertions/typeImportStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default {
{
code: 'import type A from \'a\';',
options: ['identifier', {ignoreTypeDefault: true}]
},
{
code: 'declare module "m" { import type A from \'a\'; }',
options: ['identifier']
}
]
};
Expand Down

0 comments on commit 0f8a9b5

Please sign in to comment.