From f3b52adde6dbf7e146c372bcd6db90d6156453c0 Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 21 Jan 2025 14:02:17 +0100 Subject: [PATCH 1/5] JS: Add test showing DB-CHECK failure --- .../EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected | 3 +++ .../EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue | 7 +++++++ .../EmbeddedTypeScriptNoTSConfig/test.expected | 1 + .../RegressionTests/EmbeddedTypeScriptNoTSConfig/test.js | 1 + .../RegressionTests/EmbeddedTypeScriptNoTSConfig/test.ql | 3 +++ 5 files changed, 15 insertions(+) create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.js create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.ql diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected new file mode 100644 index 000000000000..fcda4e941917 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected @@ -0,0 +1,3 @@ +[VALUE_NOT_IN_TYPE] predicate toplevel_parent_xml_node(@toplevel toplevel, @xml_node_with_code xmlnode): Value 16 of field toplevel is not in type @toplevel. Appears in tuple (16,-16777216) + Relevant element: toplevel=16 + Full ID for 16: @"script;(0),4,25". The ID may expand to @"script;{@"/Users/asger/git/code/ql/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue;sourcefile"},4,25" diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue new file mode 100644 index 000000000000..6b6436aa2b47 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue @@ -0,0 +1,7 @@ + + + diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected new file mode 100644 index 000000000000..f8f117b4b5da --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected @@ -0,0 +1 @@ +| test.js:1:1:2:0 | | diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.js b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.js new file mode 100644 index 000000000000..702f4280cee7 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.js @@ -0,0 +1 @@ +console.log("hello"); diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.ql b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.ql new file mode 100644 index 000000000000..0b69fee6d49f --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.ql @@ -0,0 +1,3 @@ +import javascript + +query predicate toplevels(TopLevel top) { any() } From 784d07c95b9b35a00a8a2f31494ce2b687768d98 Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 21 Jan 2025 13:58:44 +0100 Subject: [PATCH 2/5] JS: Ensure embedded TypeScript is extracted even when not associated with a tsconfig --- javascript/extractor/src/com/semmle/js/extractor/Main.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index b455a2c9e099..e5a4a7cad9f7 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -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; @@ -179,6 +180,12 @@ public void run(String[] args) { remainingTypescriptFiles.add(f); } } + for (Map.Entry 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) { From dd55460d7f78fb469138fe1ac7d2665c96460913 Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 21 Jan 2025 14:03:10 +0100 Subject: [PATCH 3/5] JS: Update test output --- .../EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected | 3 --- .../RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected deleted file mode 100644 index fcda4e941917..000000000000 --- a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/DB-CHECK.expected +++ /dev/null @@ -1,3 +0,0 @@ -[VALUE_NOT_IN_TYPE] predicate toplevel_parent_xml_node(@toplevel toplevel, @xml_node_with_code xmlnode): Value 16 of field toplevel is not in type @toplevel. Appears in tuple (16,-16777216) - Relevant element: toplevel=16 - Full ID for 16: @"script;(0),4,25". The ID may expand to @"script;{@"/Users/asger/git/code/ql/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/embedded-typescript.vue;sourcefile"},4,25" diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected index f8f117b4b5da..d13f8c732645 100644 --- a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmbeddedTypeScriptNoTSConfig/test.expected @@ -1 +1,2 @@ +| embedded-typescript.vue:5:1:6:0 | | | test.js:1:1:2:0 | | From a9d21e70c25071e0686b8ac29e2d87235c7f32c3 Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 21 Jan 2025 14:04:12 +0100 Subject: [PATCH 4/5] JS: Bump extractor version string --- javascript/extractor/src/com/semmle/js/extractor/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index e5a4a7cad9f7..57198709460e 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -42,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"); From 0b9187d76c6bef66f27040af4d678aa9356a8adb Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 21 Jan 2025 14:17:35 +0100 Subject: [PATCH 5/5] JS: Add change note --- .../ql/src/change-notes/2025-01-21-vue-ts-notsconfig.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 javascript/ql/src/change-notes/2025-01-21-vue-ts-notsconfig.md diff --git a/javascript/ql/src/change-notes/2025-01-21-vue-ts-notsconfig.md b/javascript/ql/src/change-notes/2025-01-21-vue-ts-notsconfig.md new file mode 100644 index 000000000000..fb2dddb47a78 --- /dev/null +++ b/javascript/ql/src/change-notes/2025-01-21-vue-ts-notsconfig.md @@ -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.