From 98e585a284f6b8bb568cec52ca3599612b663ef3 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sun, 16 Feb 2020 21:11:44 +1100 Subject: Fix issue with detecting AMD like imports (#4009) --- cli/js/compiler_sourcefile.ts | 7 ++++++- cli/tests/integration_tests.rs | 6 ++++++ cli/tests/js_import_detect.ts | 3 +++ cli/tests/js_import_detect.ts.out | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 cli/tests/js_import_detect.ts create mode 100644 cli/tests/js_import_detect.ts.out (limited to 'cli') diff --git a/cli/js/compiler_sourcefile.ts b/cli/js/compiler_sourcefile.ts index c0a301786..ca7cf27df 100644 --- a/cli/js/compiler_sourcefile.ts +++ b/cli/js/compiler_sourcefile.ts @@ -100,7 +100,12 @@ export class SourceFile { log(`Skipping imports for "${this.filename}"`); return []; } - const preProcessedFileInfo = ts.preProcessFile(this.sourceCode, true, true); + const preProcessedFileInfo = ts.preProcessFile( + this.sourceCode, + true, + this.mediaType === MediaType.JavaScript || + this.mediaType === MediaType.JSX + ); this.processed = true; const files = (this.importedFiles = [] as Array<[string, string]>); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 35127c155..fb35163f0 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -588,6 +588,12 @@ itest!(_054_info_local_imports { exit_code: 0, }); +itest!(js_import_detect { + args: "run --reload js_import_detect.ts", + output: "js_import_detect.ts.out", + exit_code: 0, +}); + itest!(lock_write_fetch { args: "run --allow-read --allow-write --allow-env --allow-run lock_write_fetch.ts", diff --git a/cli/tests/js_import_detect.ts b/cli/tests/js_import_detect.ts new file mode 100644 index 000000000..7b90dfe63 --- /dev/null +++ b/cli/tests/js_import_detect.ts @@ -0,0 +1,3 @@ +function define(_foo: string[]): void {} +define(["long"]); +console.log("ok"); diff --git a/cli/tests/js_import_detect.ts.out b/cli/tests/js_import_detect.ts.out new file mode 100644 index 000000000..9766475a4 --- /dev/null +++ b/cli/tests/js_import_detect.ts.out @@ -0,0 +1 @@ +ok -- cgit v1.2.3