|
| 1 | +/** |
| 2 | + * Provides classes for working with file system libraries. |
| 3 | + */ |
| 4 | + |
| 5 | +import javascript |
| 6 | + |
| 7 | +/** |
| 8 | + * A file name from the `walk-sync` library. |
| 9 | + */ |
| 10 | +private class WalkSyncFileNameSource extends FileNameSource { |
| 11 | + |
| 12 | + WalkSyncFileNameSource() { |
| 13 | + // `require('walkSync')()` |
| 14 | + this = DataFlow::moduleImport("walkSync").getACall() |
| 15 | + } |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * A file name or an array of file names from the `walk` library. |
| 21 | + */ |
| 22 | +private class WalkFileNameSource extends FileNameSource { |
| 23 | + |
| 24 | + WalkFileNameSource() { |
| 25 | + // `stats.name` in `require('walk').walk(_).on(_, (_, stats) => stats.name)` |
| 26 | + exists (DataFlow::FunctionNode callback | |
| 27 | + callback = DataFlow::moduleMember("walk", "walk").getACall().getAMethodCall("on").getCallback(1) | |
| 28 | + this = callback.getParameter(1).getAPropertyRead("name") |
| 29 | + ) |
| 30 | + } |
| 31 | + |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + * A file name or an array of file names from the `glob` library. |
| 36 | + */ |
| 37 | +private class GlobFileNameSource extends FileNameSource { |
| 38 | + |
| 39 | + GlobFileNameSource() { |
| 40 | + exists (string moduleName | |
| 41 | + moduleName = "glob" | |
| 42 | + // `require('glob').sync(_)` |
| 43 | + this = DataFlow::moduleMember(moduleName, "sync").getACall() |
| 44 | + or |
| 45 | + // `name` in `require('glob')(_, (e, name) => ...)` |
| 46 | + this = DataFlow::moduleImport(moduleName).getACall().getCallback([1..2]).getParameter(1) |
| 47 | + or |
| 48 | + exists (DataFlow::NewNode instance | |
| 49 | + instance = DataFlow::moduleMember(moduleName, "Glob").getAnInstantiation() | |
| 50 | + // `name` in `new require('glob').Glob(_, (e, name) => ...)` |
| 51 | + this = instance.getCallback([1..2]).getParameter(1) or |
| 52 | + // `new require('glob').Glob(_).found` |
| 53 | + this = instance.getAPropertyRead("found") |
| 54 | + ) |
| 55 | + ) |
| 56 | + } |
| 57 | + |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * A file name or an array of file names from the `globby` library. |
| 62 | + */ |
| 63 | +private class GlobbyFileNameSource extends FileNameSource { |
| 64 | + |
| 65 | + GlobbyFileNameSource() { |
| 66 | + exists (string moduleName | |
| 67 | + moduleName = "globby" | |
| 68 | + // `require('globby').sync(_)` |
| 69 | + this = DataFlow::moduleMember(moduleName, "sync").getACall() |
| 70 | + or |
| 71 | + // `files` in `require('globby')(_).then(files => ...)` |
| 72 | + this = DataFlow::moduleImport(moduleName).getACall().getAMethodCall("then").getCallback(0).getParameter(0) |
| 73 | + ) |
| 74 | + } |
| 75 | + |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * A file name or an array of file names from the `fast-glob` library. |
| 80 | + */ |
| 81 | +private class FastGlobFileNameSource extends FileNameSource { |
| 82 | + |
| 83 | + FastGlobFileNameSource() { |
| 84 | + exists (string moduleName | |
| 85 | + moduleName = "fast-glob" | |
| 86 | + // `require('fast-glob').sync(_)` |
| 87 | + this = DataFlow::moduleMember(moduleName, "sync").getACall() |
| 88 | + or |
| 89 | + exists (DataFlow::SourceNode f | |
| 90 | + f = DataFlow::moduleImport(moduleName) |
| 91 | + or |
| 92 | + f = DataFlow::moduleMember(moduleName, "async") | |
| 93 | + // `files` in `require('fast-glob')(_).then(files => ...)` and |
| 94 | + // `files` in `require('fast-glob').async(_).then(files => ...)` |
| 95 | + this = f.getACall().getAMethodCall("then").getCallback(0).getParameter(0) |
| 96 | + ) |
| 97 | + or |
| 98 | + // `file` in `require('fast-glob').stream(_).on(_, file => ...)` |
| 99 | + this = DataFlow::moduleMember(moduleName, "stream").getACall().getAMethodCall("on").getCallback(1).getParameter(0) |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments