Skip to content

Commit

Permalink
Merge pull request #18550 from asgerf/js/vue-ts-notsconfig
Browse files Browse the repository at this point in the history
JS: Avoid inconsistent DB when embedded TS has no associated tsconfig.json
  • Loading branch information
asgerf authored Jan 22, 2025
2 parents f183bc9 + 0b9187d commit f845ac1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion javascript/extractor/src/com/semmle/js/extractor/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class Main {
* A version identifier that should be updated every time the extractor changes in such a way that
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
*/
public static final String EXTRACTOR_VERSION = "2025-01-09";
public static final String EXTRACTOR_VERSION = "2025-01-21";

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

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

query predicate toplevels(TopLevel top) { any() }

0 comments on commit f845ac1

Please sign in to comment.