Skip to content

Commit 0c0073f

Browse files
authored
Merge pull request #2582 from asger-semmle/spurious-css-import
Approved by max-schaefer
2 parents 7e9b5b1 + 4772798 commit 0c0073f

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

javascript/ql/src/semmle/javascript/Modules.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ abstract class Module extends TopLevel {
8888
result = f.getJavaScriptFile(path.getBaseName())
8989
or
9090
// If a js file was not found look for a file that compiles to js
91+
path.getExtension() = ".js" and
9192
not exists(f.getJavaScriptFile(path.getBaseName())) and
9293
result = f.getJavaScriptFile(path.getStem())
9394
)

javascript/ql/src/semmle/javascript/Paths.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ abstract class PathString extends string {
128128
/** Gets the path of the parent folder of the folder or file this path refers to. */
129129
string getDirName() { result = this.regexpCapture(pathRegex(), 1) }
130130

131+
/**
132+
* Gets the extension of the folder or file this path refers to, that is, the suffix of the base name
133+
* starting at the last dot character, if there is one.
134+
*
135+
* Has no result if the base name does not contain a dot.
136+
*/
137+
string getExtension() { result = this.regexpCapture(pathRegex(), 4) }
138+
131139
/**
132140
* Gets the absolute path that the sub-path consisting of the first `n`
133141
* components of this path refers to when resolved relative to the
@@ -208,6 +216,14 @@ abstract class PathExpr extends PathExprBase {
208216
/** Gets the stem, that is, base name without extension, of the folder or file this path refers to. */
209217
string getStem() { result = getValue().(PathString).getStem() }
210218

219+
/**
220+
* Gets the extension of the folder or file this path refers to, that is, the suffix of the base name
221+
* starting at the last dot character, if there is one.
222+
*
223+
* Has no result if the base name does not contain a dot.
224+
*/
225+
string getExtension() { result = getValue().(PathString).getExtension() }
226+
211227
/**
212228
* Gets the file or folder that the first `n` components of this path refer to
213229
* when resolved relative to the root folder of the given `priority`.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import A from "./a.css";
2+
3+
A.bar();

javascript/ql/test/library-tests/Modules/tests.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_ImportSpecifiers
77
| g.ts:1:9:1:11 | foo | g.ts:1:9:1:11 | foo |
88
| import-in-mjs.mjs:1:8:1:24 | exported_from_mjs | import-in-mjs.mjs:1:8:1:24 | exported_from_mjs |
99
| import-ts-with-js-extension.ts:1:10:1:12 | foo | import-ts-with-js-extension.ts:1:10:1:12 | foo |
10+
| importcss.js:1:8:1:8 | A | importcss.js:1:8:1:8 | A |
1011
| m/c.js:1:8:1:13 | * as b | m/c.js:1:13:1:13 | b |
1112
| tst.html:5:10:5:10 | f | tst.html:5:10:5:10 | f |
1213
| unresolved.js:1:8:1:8 | f | unresolved.js:1:8:1:8 | f |
@@ -37,6 +38,7 @@ test_ImportDefaultSpecifiers
3738
| b.js:1:8:1:8 | f |
3839
| f.ts:1:8:1:8 | g |
3940
| import-in-mjs.mjs:1:8:1:24 | exported_from_mjs |
41+
| importcss.js:1:8:1:8 | A |
4042
| tst.html:5:10:5:10 | f |
4143
| unresolved.js:1:8:1:8 | f |
4244
test_getImportedName
@@ -47,6 +49,7 @@ test_getImportedName
4749
| g.ts:1:9:1:11 | foo | foo |
4850
| import-in-mjs.mjs:1:8:1:24 | exported_from_mjs | default |
4951
| import-ts-with-js-extension.ts:1:10:1:12 | foo | foo |
52+
| importcss.js:1:8:1:8 | A | default |
5053
| tst.html:5:10:5:10 | f | default |
5154
| unresolved.js:1:8:1:8 | f | default |
5255
test_ExportDeclarations
@@ -93,6 +96,7 @@ test_Imports
9396
| g.ts:1:1:1:23 | import ... m './f' | g.ts:1:19:1:23 | './f' | 1 |
9497
| import-in-mjs.mjs:1:1:1:46 | import ... n-mjs'; | import-in-mjs.mjs:1:31:1:45 | 'export-in-mjs' | 1 |
9598
| import-ts-with-js-extension.ts:1:1:1:29 | import ... /f.js"; | import-ts-with-js-extension.ts:1:21:1:28 | "./f.js" | 1 |
99+
| importcss.js:1:1:1:24 | import ... a.css"; | importcss.js:1:15:1:23 | "./a.css" | 1 |
96100
| m/c.js:1:1:1:26 | import ... '../b'; | m/c.js:1:20:1:25 | '../b' | 1 |
97101
| tst.html:5:3:5:20 | import f from 'a'; | tst.html:5:17:5:19 | 'a' | 1 |
98102
| unresolved.js:1:1:1:18 | import f from 'a'; | unresolved.js:1:15:1:17 | 'a' | 1 |

0 commit comments

Comments
 (0)