diff --git a/package.json b/package.json index 28e45eeb56..5d77bf8080 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,8 @@ "minimatch": "^3.0.4", "object.values": "^1.1.0", "read-pkg-up": "^2.0.0", - "resolve": "^1.12.0" + "resolve": "^1.12.0", + "tsconfig-paths": "^3.9.0" }, "nyc": { "require": [ diff --git a/src/ExportMap.js b/src/ExportMap.js index 525f64a48a..0ccdb4ec5d 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -13,6 +13,8 @@ import isIgnored, { hasValidExtension } from 'eslint-module-utils/ignore' import { hashObject } from 'eslint-module-utils/hash' import * as unambiguous from 'eslint-module-utils/unambiguous' +import { loadConfig } from 'tsconfig-paths' + const log = debug('eslint-plugin-import:ExportMap') const exportCache = new Map() @@ -445,6 +447,14 @@ ExportMap.parse = function (path, content, context) { const source = makeSourceCode(content, ast) + function isEsModuleInterop() { + const configLoaderResult = loadConfig(context.parserOptions.tsconfigRootDir || process.cwd()) + if (configLoaderResult === 'success') { + return configLoaderResult.esModuleInterop + } + return false + } + ast.body.forEach(function (n) { if (n.type === 'ExportDefaultDeclaration') { @@ -530,6 +540,9 @@ ExportMap.parse = function (path, content, context) { // This doesn't declare anything, but changes what's being exported. if (n.type === 'TSExportAssignment') { + if (isEsModuleInterop()) { + m.namespace.set('default', {}) + } const moduleDecls = ast.body.filter((bodyNode) => bodyNode.type === 'TSModuleDeclaration' && bodyNode.id.name === n.expression.name )