JS: classify generated data files

This commit is contained in:
Esben Sparre Andreasen
2018-08-27 15:06:00 +02:00
parent 61bd003cf9
commit 02d56306c9
4 changed files with 2424 additions and 1 deletions

View File

@@ -99,6 +99,21 @@ private predicate hasManyInvocations(TopLevel tl) {
)
}
/**
* Holds if `f` is side effect free, and full of primitive literals, which is often a sign of generated data code.
*/
private predicate isData(File f) {
// heuristic: `f` has more than 1000 primitive literal expressions ...
count(SyntacticConstants::PrimitiveLiteralConstant e | e.getFile() = f) > 1000 and
// ... but no expressions with side effects ...
not exists (Expr e |
e.getFile() = f and
e.isImpure() and
// ... except for variable initializers
not e instanceof VariableDeclarator
)
}
/**
* Holds if `tl` looks like it contains generated code.
*/
@@ -108,7 +123,8 @@ predicate isGenerated(TopLevel tl) {
tl instanceof GWTGeneratedTopLevel or
tl instanceof DartGeneratedTopLevel or
exists (GeneratedCodeMarkerComment gcmc | tl = gcmc.getTopLevel()) or
hasManyInvocations(tl)
hasManyInvocations(tl) or
isData(tl.getFile())
}
/**

View File

@@ -1,5 +1,7 @@
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |
| bundle-directive.js:0:0:0:0 | bundle-directive.js | generated |
| data.js:0:0:0:0 | data.js | generated |
| exported-data.js:0:0:0:0 | exported-data.js | generated |
| jison-lex.js:0:0:0:0 | jison-lex.js | generated |
| jison.js:0:0:0:0 | jison.js | generated |
| jquery-datatables.js:0:0:0:0 | jquery-datatables.js | library |

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff