Check for unused locals in commonjs modules (#19612)

This commit is contained in:
Andy
2017-11-03 17:46:19 -07:00
committed by GitHub
parent bb7fb7dda9
commit 845c066923
5 changed files with 39 additions and 1 deletions

View File

@@ -23158,7 +23158,7 @@ namespace ts {
checkDeferredNodes();
if (isExternalModule(node)) {
if (isExternalOrCommonJsModule(node)) {
registerForUnusedIdentifiersCheck(node);
}

View File

@@ -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;

View 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))

View 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

View File

@@ -0,0 +1,8 @@
// @noUnusedLocals: true
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js
const x = 0;
exports.y = 1;