Skip to content

Commit

Permalink
[Fix] TypeScript: named: avoid requiring typescript when not usin…
Browse files Browse the repository at this point in the history
…g TS

Fixes #1805.
  • Loading branch information
ljharb committed Jun 8, 2020
1 parent 2699251 commit 381b2b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ExportMap.js
Expand Up @@ -17,7 +17,7 @@ import { tsConfigLoader } from 'tsconfig-paths/lib/tsconfig-loader'

import includes from 'array-includes'

import {parseConfigFileTextToJson} from 'typescript'
let parseConfigFileTextToJson

const log = debug('eslint-plugin-import:ExportMap')

Expand Down Expand Up @@ -459,6 +459,10 @@ ExportMap.parse = function (path, content, context) {
try {
if (tsConfigInfo.tsConfigPath !== undefined) {
const jsonText = fs.readFileSync(tsConfigInfo.tsConfigPath).toString()
if (!parseConfigFileTextToJson) {
// this is because projects not using TypeScript won't have typescript installed
({parseConfigFileTextToJson} = require('typescript'))
}
const tsConfig = parseConfigFileTextToJson(tsConfigInfo.tsConfigPath, jsonText).config
return tsConfig.compilerOptions.esModuleInterop
}
Expand Down Expand Up @@ -552,7 +556,9 @@ ExportMap.parse = function (path, content, context) {
const isEsModuleInteropTrue = isEsModuleInterop()

const exports = ['TSExportAssignment']
isEsModuleInteropTrue && exports.push('TSNamespaceExportDeclaration')
if (isEsModuleInteropTrue) {
exports.push('TSNamespaceExportDeclaration')
}

// This doesn't declare anything, but changes what's being exported.
if (includes(exports, n.type)) {
Expand Down

0 comments on commit 381b2b5

Please sign in to comment.