Skip to content

Commit f845ac1

Browse files
authored
Merge pull request #18550 from asgerf/js/vue-ts-notsconfig
JS: Avoid inconsistent DB when embedded TS has no associated tsconfig.json
2 parents f183bc9 + 0b9187d commit f845ac1

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.LinkedHashSet;
99
import java.util.List;
10+
import java.util.Map;
1011
import java.util.Set;
1112
import java.util.regex.Pattern;
1213
import java.util.stream.Collectors;
@@ -41,7 +42,7 @@ public class Main {
4142
* A version identifier that should be updated every time the extractor changes in such a way that
4243
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4344
*/
44-
public static final String EXTRACTOR_VERSION = "2025-01-09";
45+
public static final String EXTRACTOR_VERSION = "2025-01-21";
4546

4647
public static final Pattern NEWLINE = Pattern.compile("\n");
4748

@@ -179,6 +180,12 @@ public void run(String[] args) {
179180
remainingTypescriptFiles.add(f);
180181
}
181182
}
183+
for (Map.Entry<Path, FileSnippet> entry : extractorState.getSnippets().entrySet()) {
184+
if (!extractedFiles.contains(entry.getKey().toFile())
185+
&& FileType.forFileExtension(entry.getKey().toFile()) == FileType.TYPESCRIPT) {
186+
remainingTypescriptFiles.add(entry.getKey().toFile());
187+
}
188+
}
182189
if (!remainingTypescriptFiles.isEmpty()) {
183190
tsParser.prepareFiles(remainingTypescriptFiles);
184191
for (File f : remainingTypescriptFiles) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a bug that would occur when TypeScript code was found in an HTML-like file, such as a `.vue` file,
5+
but where it could not be associated with any `tsconfig.json` file. Previously the embedded code was not
6+
extracted in this case, but should now be extracted properly.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<p v-html="input" />
3+
</template>
4+
<script setup lang="ts">
5+
console.log("hello");
6+
</script>
7+
<style></style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| embedded-typescript.vue:5:1:6:0 | <toplevel> |
2+
| test.js:1:1:2:0 | <toplevel> |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
query predicate toplevels(TopLevel top) { any() }

0 commit comments

Comments
 (0)