JS: Implement babel-plugin-root-import as a PathMapping

This commit is contained in:
Asger F
2025-04-28 13:35:23 +02:00
parent e4420f63fb
commit d724874969
7 changed files with 23 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
*/
import javascript
private import semmle.javascript.internal.paths.PathMapping
module Babel {
/**
@@ -202,4 +203,12 @@ module Babel {
)
}
}
private class BabelPathMapping extends PathMapping, RootImportConfig {
override File getAnAffectedFile() { result = this.getConfig().getAContainerInScope() }
override predicate hasPrefixPathMapping(string pattern, Container newContext, string newPath) {
newPath = this.getRoot(pattern) and newContext = this.getFolder()
}
}
}

View File

@@ -1 +1 @@
import f from '~/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
import f from '~/a'; // $ importTarget=BabelRootImport/tst1/a.js

View File

@@ -1 +1 @@
import f from '~/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
import f from '~/a'; // $ importTarget=BabelRootImport/tst1/a.js

View File

@@ -1,2 +1,2 @@
import g from '~/b.js'; // $ MISSING: importTarget=BabelRootImport/tst2/src/js/b.js
import f from '#/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
import g from '~/b.js'; // $ importTarget=BabelRootImport/tst2/src/js/b.js
import f from '#/a'; // $ importTarget=BabelRootImport/tst1/a.js

View File

@@ -1 +1 @@
import greeting from '~/b.js'; // $ MISSING: importTarget=BabelRootImport/tst3/src/b.js
import greeting from '~/b.js'; // $ importTarget=BabelRootImport/tst3/src/b.js

View File

@@ -1,2 +1,2 @@
import g from '~/b.js'; // $ MISSING: importTarget=BabelRootImport/tst4/src/js/b.js
import f from '#/a'; // $ MISSING: importTarget=BabelRootImport/tst1/a.js
import g from '~/b.js'; // $ importTarget=BabelRootImport/tst4/src/js/b.js
import f from '#/a'; // $ importTarget=BabelRootImport/tst1/a.js

View File

@@ -1,3 +1,10 @@
| BabelRootImport/tst1/index.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/tst1/a.js |
| BabelRootImport/tst1/nested/tst.js:1:1:1:20 | import f from '~/a'; | BabelRootImport/tst1/a.js |
| BabelRootImport/tst2/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/tst2/src/js/b.js |
| BabelRootImport/tst2/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/tst1/a.js |
| BabelRootImport/tst3/index.js:1:1:1:30 | import ... /b.js'; | BabelRootImport/tst3/src/b.js |
| BabelRootImport/tst4/index.js:1:1:1:23 | import ... /b.js'; | BabelRootImport/tst4/src/js/b.js |
| BabelRootImport/tst4/index.js:2:1:2:20 | import f from '#/a'; | BabelRootImport/tst1/a.js |
| BaseUrl/src/main.ts:2:1:2:26 | import ... /file"; | BaseUrl/base/lib/file.ts |
| BaseUrl/src/main.ts:3:1:3:29 | import ... le.ts"; | BaseUrl/base/lib/file.ts |
| BaseUrl/src/main.ts:4:1:4:29 | import ... le.js"; | BaseUrl/base/lib/file.ts |