diff --git a/src/imports.js b/src/imports.js index 36bdf23..e1db580 100644 --- a/src/imports.js +++ b/src/imports.js @@ -153,10 +153,13 @@ function getSourceWithControlCharacter(originalSource, item) { // Exclude "ImportDefaultSpecifier" – the "def" in `import def, {a, b}`. function getSpecifiers(importNode) { switch (importNode.type) { + case "ImportDeclaration": + return importNode.specifiers.filter((node) => isImportSpecifier(node)); case "TSImportEqualsDeclaration": return []; - default: // ImportDeclaration - return importNode.specifiers.filter((node) => isImportSpecifier(node)); + // istanbul ignore next + default: + throw new Error(`Unsupported import node type: ${importNode.type}`); } } @@ -179,9 +182,7 @@ function isImportSpecifier(node) { // And not: import type {} from "setup" function isSideEffectImport(importNode, sourceCode) { switch (importNode.type) { - case "TSImportEqualsDeclaration": - return false; - default: // ImportDeclaration + case "ImportDeclaration": return ( importNode.specifiers.length === 0 && (!importNode.importKind || @@ -191,5 +192,10 @@ function isSideEffectImport(importNode, sourceCode) { "{" ) ); + case "TSImportEqualsDeclaration": + return false; + // istanbul ignore next + default: + throw new Error(`Unsupported import node type: ${importNode.type}`); } } diff --git a/src/shared.js b/src/shared.js index 66409f3..9f8e0de 100644 --- a/src/shared.js +++ b/src/shared.js @@ -831,13 +831,18 @@ function getSource(sourceCode, node) { function getSourceTextAndKind(sourceCode, node) { switch (node.type) { + case "ImportDeclaration": + case "ExportNamedDeclaration": + case "ExportAllDeclaration": + return [node.source.value, getImportExportKind(node)]; case "TSImportEqualsDeclaration": return getSourceTextAndKindFromModuleReference( sourceCode, node.moduleReference ); - default: // ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration - return [node.source.value, getImportExportKind(node)]; + // istanbul ignore next + default: + throw new Error(`Unsupported import node type: ${node.type}`); } } @@ -873,19 +878,25 @@ function getSourceTextAndKindFromModuleReference(sourceCode, node) { getSourceTextFromTSQualifiedName(sourceCode, node), KIND_TS_IMPORT_ASSIGNMENT_NAMESPACE, ]; - default: // Identifier + case "Identifier": return [node.name, KIND_TS_IMPORT_ASSIGNMENT_NAMESPACE]; + // istanbul ignore next + default: + throw new Error(`Unsupported module reference node type: ${node.type}`); } } function getSourceTextFromTSQualifiedName(sourceCode, node) { switch (node.left.type) { + case "Identifier": + return `${node.left.name}.${node.right.name}`; case "TSQualifiedName": return `${getSourceTextFromTSQualifiedName(sourceCode, node.left)}.${ node.right.name }`; - default: // Identifier - return `${node.left.name}.${node.right.name}`; + // istanbul ignore next + default: + throw new Error(`Unsupported TS qualified name node type: ${node.type}`); } }