Skip to content

Commit 5b2769f

Browse files
demonhueAbhishekmrseanryan
authored
Handled the case when import statement contains '.ts' and '.tsx' extensions in path (#288)
Co-authored-by: Abhishek <[email protected]> Co-authored-by: Sean Ryan <[email protected]>
1 parent 4b37c10 commit 5b2769f

File tree

9 files changed

+30
-4
lines changed

9 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [9.0.6] - 26 Jun 2023
2+
3+
- Handled the case when import statement contains '.ts' and '.tsx' extensions in path
4+
15
## [9.0.5] - 24 Jun 2023
26

37
- Add --ignoreLocallyUsed flag which means that exports which are used in the same file they are defined in won't be reported as unused
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let a = 5;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import {a} from "./a.js";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const unused1 = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const unused2 = 1;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"target": "es5",
5+
"noEmit": true,
6+
"noImplicitAny": true,
7+
"strictNullChecks": true,
8+
"moduleResolution": "node",
9+
"paths": {
10+
"utils": ["utils/src"],
11+
"utils/*": ["utils/src/*"]
12+
},
13+
},
14+
"include": ["src/**/*.ts"],
15+
}

ispec/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function install_and_run_itest()
1818
{
1919
npm ci > /dev/null && run_itest
2020
}
21+
pushd ../example/import-with-ts-extension
22+
run_itest
23+
popd
2124

2225
pushd ../example/simple-zero-issues
2326
run_itest_expect_zero_issues

src/analyzer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
indexCandidateExtensions,
1010
indexCandidates,
1111
removeExportStarPrefix,
12-
removeFileExtensionToAllowForJs,
12+
removeFileExtensionToAllowForJsTsJsxTsx,
1313
} from './parser/util';
1414

1515
export { Analysis } from './types';
@@ -78,7 +78,7 @@ const getExportMap = (files: File[]): ExportMap => {
7878
const processImports = (file: File, exportMap: ExportMap): void => {
7979
Object.keys(file.imports).forEach((key) => {
8080
const importedFileExports =
81-
exportMap[removeFileExtensionToAllowForJs(key)] || null;
81+
exportMap[removeFileExtensionToAllowForJsTsJsxTsx(key)] || null;
8282

8383
let ex = importedFileExports?.exports || null;
8484

src/parser/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export const indexCandidateExtensions = [
2727
'.mjs',
2828
];
2929

30-
export function removeFileExtensionToAllowForJs(path: string): string {
30+
export function removeFileExtensionToAllowForJsTsJsxTsx(path: string): string {
3131
// ref: https://www.typescriptlang.org/docs/handbook/esm-node.html
32-
const extensionsToStrip = ['.js', '.cjs', '.mjs'];
32+
const extensionsToStrip = ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx'];
3333

3434
return stripExtensionsFromPath(extensionsToStrip, path);
3535
}

0 commit comments

Comments
 (0)