mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
Check for unused locals in commonjs modules (#19612)
This commit is contained in:
@@ -23158,7 +23158,7 @@ namespace ts {
|
||||
|
||||
checkDeferredNodes();
|
||||
|
||||
if (isExternalModule(node)) {
|
||||
if (isExternalOrCommonJsModule(node)) {
|
||||
registerForUnusedIdentifiersCheck(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/a.js(1,7): error TS6133: 'x' is declared but its value is never read.
|
||||
|
||||
|
||||
==== /a.js (1 errors) ====
|
||||
const x = 0;
|
||||
~
|
||||
!!! error TS6133: 'x' is declared but its value is never read.
|
||||
exports.y = 1;
|
||||
|
||||
9
tests/baselines/reference/commonJsUnusedLocals.symbols
Normal file
9
tests/baselines/reference/commonJsUnusedLocals.symbols
Normal file
@@ -0,0 +1,9 @@
|
||||
=== /a.js ===
|
||||
const x = 0;
|
||||
>x : Symbol(x, Decl(a.js, 0, 5))
|
||||
|
||||
exports.y = 1;
|
||||
>exports.y : Symbol(y, Decl(a.js, 0, 12))
|
||||
>exports : Symbol(y, Decl(a.js, 0, 12))
|
||||
>y : Symbol(y, Decl(a.js, 0, 12))
|
||||
|
||||
12
tests/baselines/reference/commonJsUnusedLocals.types
Normal file
12
tests/baselines/reference/commonJsUnusedLocals.types
Normal file
@@ -0,0 +1,12 @@
|
||||
=== /a.js ===
|
||||
const x = 0;
|
||||
>x : 0
|
||||
>0 : 0
|
||||
|
||||
exports.y = 1;
|
||||
>exports.y = 1 : 1
|
||||
>exports.y : number
|
||||
>exports : typeof "/a"
|
||||
>y : number
|
||||
>1 : 1
|
||||
|
||||
8
tests/cases/compiler/commonJsUnusedLocals.ts
Normal file
8
tests/cases/compiler/commonJsUnusedLocals.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// @noUnusedLocals: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @Filename: /a.js
|
||||
const x = 0;
|
||||
exports.y = 1;
|
||||
Reference in New Issue
Block a user