JavaScript: Teach InvalidExport to never flag module.exports = exports = ... and similar.

This was previously flagged if `exports` wasn't used any further. While it's true that the assignment to `exports` is redundant in this case, the assignment is also flagged by DeadStorOfLocal, so there is no point in InvalidExport flagging it as well.
This commit is contained in:
Max Schaefer
2019-03-04 09:50:02 +00:00
parent c49c23068a
commit 3cabc12be3
8 changed files with 12 additions and 8 deletions

View File

@@ -41,12 +41,8 @@ from Assignment assgn, Variable exportsVar, DataFlow::Node exportsVal
where
exportsAssign(assgn, exportsVar, exportsVal) and
not exists(exportsVal.getAPredecessor()) and
not (
// this is OK if `exportsVal` flows into `module.exports`
moduleExportsAssign(_, exportsVal) and
// however, if there are no further uses of `exports` the assignment is useless anyway
strictcount(exportsVar.getAnAccess()) > 1
) and
// this is OK if `exportsVal` flows into `module.exports`
not moduleExportsAssign(_, exportsVal) and
// export assignments do work in closure modules
not assgn.getTopLevel() instanceof Closure::ClosureModule
select assgn, "Assigning to 'exports' does not export anything."