Skip to content

Commit 381b2b5

Browse files
committed
[Fix] TypeScript: named: avoid requiring typescript when not using TS
Fixes #1805.
1 parent 2699251 commit 381b2b5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ExportMap.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { tsConfigLoader } from 'tsconfig-paths/lib/tsconfig-loader'
1717

1818
import includes from 'array-includes'
1919

20-
import {parseConfigFileTextToJson} from 'typescript'
20+
let parseConfigFileTextToJson
2121

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

@@ -459,6 +459,10 @@ ExportMap.parse = function (path, content, context) {
459459
try {
460460
if (tsConfigInfo.tsConfigPath !== undefined) {
461461
const jsonText = fs.readFileSync(tsConfigInfo.tsConfigPath).toString()
462+
if (!parseConfigFileTextToJson) {
463+
// this is because projects not using TypeScript won't have typescript installed
464+
({parseConfigFileTextToJson} = require('typescript'))
465+
}
462466
const tsConfig = parseConfigFileTextToJson(tsConfigInfo.tsConfigPath, jsonText).config
463467
return tsConfig.compilerOptions.esModuleInterop
464468
}
@@ -552,7 +556,9 @@ ExportMap.parse = function (path, content, context) {
552556
const isEsModuleInteropTrue = isEsModuleInterop()
553557

554558
const exports = ['TSExportAssignment']
555-
isEsModuleInteropTrue && exports.push('TSNamespaceExportDeclaration')
559+
if (isEsModuleInteropTrue) {
560+
exports.push('TSNamespaceExportDeclaration')
561+
}
556562

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

0 commit comments

Comments
 (0)