From 1e5d94d8ad42234b534be2b1d1e87d6af2d06f36 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 25 Feb 2020 15:16:21 +1100 Subject: [PATCH] Fix issues with JavaScript importing JavaScript. Fixes #3852 Fixes #4117 --- cli/js/compiler_host.ts | 8 ++++---- cli/js/compiler_util.ts | 6 +++++- cli/tests/038_checkjs.tsconfig.json | 1 + cli/tests/fix_js_import_js.ts | 3 +++ cli/tests/fix_js_import_js.ts.out | 1 + cli/tests/integration_tests.rs | 5 +++++ cli/tests/subdir/mod6.js | 1 + 7 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 cli/tests/fix_js_import_js.ts create mode 100644 cli/tests/fix_js_import_js.ts.out create mode 100644 cli/tests/subdir/mod6.js diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts index d44bc7a03b9835..78ed4889a70934 100644 --- a/cli/js/compiler_host.ts +++ b/cli/js/compiler_host.ts @@ -47,18 +47,18 @@ export const defaultBundlerOptions: ts.CompilerOptions = { /** Default options used by the compiler Host when compiling. */ export const defaultCompileOptions: ts.CompilerOptions = { - allowJs: true, + allowJs: false, allowNonTsExtensions: true, - strict: true, checkJs: false, esModuleInterop: true, + jsx: ts.JsxEmit.React, module: ts.ModuleKind.ESNext, outDir: OUT_DIR, resolveJsonModule: true, sourceMap: true, + strict: true, stripComments: true, - target: ts.ScriptTarget.ESNext, - jsx: ts.JsxEmit.React + target: ts.ScriptTarget.ESNext }; /** Options that need to be used when doing a runtime (non bundled) compilation */ diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts index a28e2d109d6de6..6da38ab3be2d80 100644 --- a/cli/js/compiler_util.ts +++ b/cli/js/compiler_util.ts @@ -304,7 +304,11 @@ export const ignoredDiagnostics = [ // support JSON imports. Allegedly this was fixed in // Microsoft/TypeScript#26825 but that doesn't seem to be working here, // so we will ignore complaints about this compiler setting. - 5070 + 5070, + // TS7016: Could not find a declaration file for module '...'. '...' + // implicitly has an 'any' type. This is due to `allowJs` being off by + // default but importing of a JavaScript module. + 7016 ]; /** When doing a host configuration, processing the response and logging out diff --git a/cli/tests/038_checkjs.tsconfig.json b/cli/tests/038_checkjs.tsconfig.json index 08ac60b6cd8f28..46d96db9ede96d 100644 --- a/cli/tests/038_checkjs.tsconfig.json +++ b/cli/tests/038_checkjs.tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "allowJs": true, "checkJs": true } } diff --git a/cli/tests/fix_js_import_js.ts b/cli/tests/fix_js_import_js.ts new file mode 100644 index 00000000000000..c9f341748c05d9 --- /dev/null +++ b/cli/tests/fix_js_import_js.ts @@ -0,0 +1,3 @@ +import { isMod4 } from "./subdir/mod6.js"; + +console.log(isMod4); diff --git a/cli/tests/fix_js_import_js.ts.out b/cli/tests/fix_js_import_js.ts.out new file mode 100644 index 00000000000000..27ba77ddaf6153 --- /dev/null +++ b/cli/tests/fix_js_import_js.ts.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 1767be7c2b1a54..ccc57133147b7e 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1160,6 +1160,11 @@ itest!(cafile_info { http_server: true, }); +itest!(fix_js_import_js { + args: "run --reload fix_js_import_js.ts", + output: "fix_js_import_js.ts.out", +}); + itest!(fix_js_imports { args: "run --reload fix_js_imports.ts", output: "fix_js_imports.ts.out", diff --git a/cli/tests/subdir/mod6.js b/cli/tests/subdir/mod6.js new file mode 100644 index 00000000000000..5e17c9ee025271 --- /dev/null +++ b/cli/tests/subdir/mod6.js @@ -0,0 +1 @@ +export { isMod4 } from "./mod4.js";