Skip to content

Commit 4c35c59

Browse files
committed
JS: Implement path mapping from babel plugin
1 parent e45e16f commit 4c35c59

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Babel.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import javascript
6+
private import semmle.javascript.internal.paths.PathMapping
67

78
module Babel {
89
/**
@@ -202,4 +203,12 @@ module Babel {
202203
)
203204
}
204205
}
206+
207+
private class BabelPathMapping extends PathMapping, RootImportConfig {
208+
override File getAnAffectedFile() { result = this.getConfig().getAContainerInScope() }
209+
210+
override predicate hasPrefixPathMapping(string pattern, Container newContext, string newPath) {
211+
newPath = this.getRoot(pattern) and newContext = this.getFolder()
212+
}
213+
}
205214
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import f from '~/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
1+
import f from '~/a'; // $ importTarget=BabelRootImport/tst1/a.js
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import f from '~/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
1+
import f from '~/a'; // $ importTarget=BabelRootImport/tst1/a.js
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import g from '~/b.js'; // $ MISSING: importTarget=BabelRootImport/tst2/src/js/b.js
2-
import f from '#/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
1+
import g from '~/b.js'; // $ importTarget=BabelRootImport/tst2/src/js/b.js
2+
import f from '#/a'; // $ importTarget=BabelRootImport/tst1/a.js
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import greeting from '~/b.js'; // $ MISSING: importTarget=BabelRootImport/tst3/src/b.js
1+
import greeting from '~/b.js'; // $ importTarget=BabelRootImport/tst3/src/b.js
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import g from '~/b.js';
2-
import f from '#/a';
1+
import g from '~/b.js'; // $ importTarget=BabelRootImport/tst4/src/js/b.js
2+
import f from '#/a'; // $ importTarget=BabelRootImport/tst1/a.js

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
importTarget
2+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/index.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/a.js |
3+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/nested/tst.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/a.js |
4+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst2/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst2/src/js/b.js |
5+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst2/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/a.js |
6+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst3/index.js:1:1:1:30 | import ... /b.js'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst3/src/b.js |
7+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst4/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst4/src/js/b.js |
8+
| BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst4/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/BabelRootImport.testproj/srcBabelRootImport/tst1/a.js |
9+
| BabelRootImport/tst1/index.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/tst1/a.js |
10+
| BabelRootImport/tst1/nested/tst.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/tst1/a.js |
11+
| BabelRootImport/tst2/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/tst2/src/js/b.js |
12+
| BabelRootImport/tst2/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/tst1/a.js |
13+
| BabelRootImport/tst3/index.js:1:1:1:30 | import ... /b.js'; | BabelRootImport/tst3/src/b.js |
14+
| BabelRootImport/tst4/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/tst4/src/js/b.js |
15+
| BabelRootImport/tst4/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/tst1/a.js |
116
| BaseUrl/src/main.ts:2:1:2:26 | import ... /file"; | BaseUrl/base/lib/file.ts |
217
| BaseUrl/src/main.ts:3:1:3:29 | import ... le.ts"; | BaseUrl/base/lib/file.ts |
318
| BaseUrl/src/main.ts:4:1:4:29 | import ... le.js"; | BaseUrl/base/lib/file.ts |
@@ -105,3 +120,4 @@
105120
| import-packages.ts:28:1:28:24 | import ... older'; | MainIsFolder/src/index.ts |
106121
| import-packages.ts:29:1:29:33 | import ... older'; | MainIsFolder/src/index.ts |
107122
| import-packages.ts:31:1:31:27 | import ... nsSrc'; | DistContainsSrc/src/foo.ts |
123+
testFailures

0 commit comments

Comments
 (0)