Skip to content

Commit 01ab8f0

Browse files
committed
TS: Fix a crash when allowJs: true was set
1 parent 7d558d1 commit 01ab8f0

File tree

7 files changed

+30
-1
lines changed

7 files changed

+30
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ private Set<Path> extractTypeScript(
578578
for (File sourceFile : project.getSourceFiles()) {
579579
Path sourcePath = sourceFile.toPath();
580580
if (!files.contains(normalizePath(sourcePath))) continue;
581+
if (!FileType.TYPESCRIPT.getExtensions().contains(FileUtil.extension(sourcePath))) {
582+
// For the time being, skip non-TypeScript files, even if the TypeScript
583+
// compiler can parse them for us.
584+
continue;
585+
}
581586
if (!extractedFiles.contains(sourcePath)) {
582587
typeScriptFiles.add(sourcePath.toFile());
583588
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public void run(String[] args) {
147147
List<File> filesToExtract = new ArrayList<>();
148148
for (File sourceFile : project.getSourceFiles()) {
149149
if (files.contains(normalizeFile(sourceFile))
150-
&& !extractedFiles.contains(sourceFile.getAbsoluteFile())) {
150+
&& !extractedFiles.contains(sourceFile.getAbsoluteFile())
151+
&& FileType.TYPESCRIPT.getExtensions().contains(FileUtil.extension(sourceFile))) {
151152
filesToExtract.add(sourceFile);
152153
}
153154
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import f = require("./tst");
2+
f("world");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| main.ts:1:8:1:8 | f | (x: string) => string |
2+
| main.ts:1:20:1:26 | "./tst" | any |
3+
| main.ts:2:1:2:1 | f | (x: string) => string |
4+
| main.ts:2:1:2:10 | f("world") | string |
5+
| main.ts:2:3:2:9 | "world" | "world" |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from Expr e
4+
select e, e.getType()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true
4+
},
5+
"include": ["."]
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @param {String} x
3+
*/
4+
module.exports = function(x) {
5+
return 'Hello ' + x;
6+
}

0 commit comments

Comments
 (0)