TS: Fix a crash when allowJs: true was set

This commit is contained in:
Asger F
2019-11-18 13:02:12 +00:00
parent 7d558d165a
commit 01ab8f07eb
7 changed files with 30 additions and 1 deletions

View File

@@ -578,6 +578,11 @@ public class AutoBuild {
for (File sourceFile : project.getSourceFiles()) {
Path sourcePath = sourceFile.toPath();
if (!files.contains(normalizePath(sourcePath))) continue;
if (!FileType.TYPESCRIPT.getExtensions().contains(FileUtil.extension(sourcePath))) {
// For the time being, skip non-TypeScript files, even if the TypeScript
// compiler can parse them for us.
continue;
}
if (!extractedFiles.contains(sourcePath)) {
typeScriptFiles.add(sourcePath.toFile());
}

View File

@@ -147,7 +147,8 @@ public class Main {
List<File> filesToExtract = new ArrayList<>();
for (File sourceFile : project.getSourceFiles()) {
if (files.contains(normalizeFile(sourceFile))
&& !extractedFiles.contains(sourceFile.getAbsoluteFile())) {
&& !extractedFiles.contains(sourceFile.getAbsoluteFile())
&& FileType.TYPESCRIPT.getExtensions().contains(FileUtil.extension(sourceFile))) {
filesToExtract.add(sourceFile);
}
}

View File

@@ -0,0 +1,2 @@
import f = require("./tst");
f("world");

View File

@@ -0,0 +1,5 @@
| main.ts:1:8:1:8 | f | (x: string) => string |
| main.ts:1:20:1:26 | "./tst" | any |
| main.ts:2:1:2:1 | f | (x: string) => string |
| main.ts:2:1:2:10 | f("world") | string |
| main.ts:2:3:2:9 | "world" | "world" |

View File

@@ -0,0 +1,4 @@
import javascript
from Expr e
select e, e.getType()

View File

@@ -0,0 +1,6 @@
{
"compilerOptions": {
"allowJs": true
},
"include": ["."]
}

View File

@@ -0,0 +1,6 @@
/**
* @param {String} x
*/
module.exports = function(x) {
return 'Hello ' + x;
}