Skip to content

Commit 43c65e0

Browse files
author
Esben Sparre Andreasen
committed
JS: classify bundle files based on multiple license comments
1 parent 10329fa commit 43c65e0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

javascript/ql/src/semmle/javascript/frameworks/Bundling.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,20 @@ Comment getExclamationPointCommentInRun(ExclamationPointComment head) {
213213
* Holds if this is a bundle containing multiple licenses.
214214
*/
215215
predicate isMultiLicenseBundle(TopLevel tl) {
216+
// case: comments preserved by minifiers
216217
count(ExclamationPointComment head |
217218
head.getTopLevel() = tl and
218219
exists(ExclamationPointComment licenseIndicator |
219220
licenseIndicator = getExclamationPointCommentInRun(head) and
220221
licenseIndicator.getLine(_).regexpMatch("(?i).*\\b(copyright|license|\\d+\\.\\d+)\\b.*")
221222
)
222223
) > 1
224+
or
225+
// case: ordinary block comments with "@license" lines
226+
count(BlockComment head |
227+
head.getTopLevel() = tl and
228+
head.getLine(_).regexpMatch("(?i) *\\* @license .*")
229+
) > 1
223230
}
224231

225232
/**

javascript/ql/test/query-tests/filters/ClassifyFiles/ClassifyFiles.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| jsx.js:0:0:0:0 | jsx.js | generated |
1212
| multi-part-bundle.html:0:0:0:0 | multi-part-bundle.html | generated |
1313
| multi-part-bundle.js:0:0:0:0 | multi-part-bundle.js | generated |
14+
| multiple-licenses-2.js:0:0:0:0 | multiple-licenses-2.js | generated |
1415
| multiple-licenses.js:0:0:0:0 | multiple-licenses.js | generated |
1516
| opal-test.js:0:0:0:0 | opal-test.js | generated |
1617
| peg-js.js:0:0:0:0 | peg-js.js | generated |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* @copyright (c) ...
3+
* @copyright (c) ...
4+
* @license ...
5+
*/
6+
7+
/**
8+
* @copyright ...
9+
* @license ...
10+
*/

0 commit comments

Comments
 (0)