Skip to content

Commit

Permalink
feature(import/default): support default export in TSExportAssignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok committed Mar 19, 2020
1 parent 1a3a128 commit 0b93f55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
13 changes: 13 additions & 0 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 0b93f55

Please sign in to comment.