Skip to content

Commit 845c066

Browse files
author
Andy
authored
Check for unused locals in commonjs modules (#19612)
1 parent bb7fb7d commit 845c066

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23158,7 +23158,7 @@ namespace ts {
2315823158

2315923159
checkDeferredNodes();
2316023160

23161-
if (isExternalModule(node)) {
23161+
if (isExternalOrCommonJsModule(node)) {
2316223162
registerForUnusedIdentifiersCheck(node);
2316323163
}
2316423164

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/a.js(1,7): error TS6133: 'x' is declared but its value is never read.
2+
3+
4+
==== /a.js (1 errors) ====
5+
const x = 0;
6+
~
7+
!!! error TS6133: 'x' is declared but its value is never read.
8+
exports.y = 1;
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== /a.js ===
2+
const x = 0;
3+
>x : Symbol(x, Decl(a.js, 0, 5))
4+
5+
exports.y = 1;
6+
>exports.y : Symbol(y, Decl(a.js, 0, 12))
7+
>exports : Symbol(y, Decl(a.js, 0, 12))
8+
>y : Symbol(y, Decl(a.js, 0, 12))
9+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.js ===
2+
const x = 0;
3+
>x : 0
4+
>0 : 0
5+
6+
exports.y = 1;
7+
>exports.y = 1 : 1
8+
>exports.y : number
9+
>exports : typeof "/a"
10+
>y : number
11+
>1 : 1
12+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @noUnusedLocals: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noEmit: true
5+
6+
// @Filename: /a.js
7+
const x = 0;
8+
exports.y = 1;

0 commit comments

Comments
 (0)