Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tsc/internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,13 @@ func (c *Checker) getJsxNamespaceContainerForImplicitImport(location *ast.Node)
if moduleReference == "" {
return nil
}
// A script file (non-module) cannot resolve imports, so the implicit JSX runtime import will
// not resolve regardless of whether the package is installed. Report that instead of the
// generic "module path does not exist" message.
errorMessage := diagnostics.This_JSX_tag_requires_the_module_path_0_to_exist_but_none_could_be_found_Make_sure_you_have_types_for_the_appropriate_package_installed
if !ast.IsExternalOrCommonJSModule(file) {
errorMessage = diagnostics.This_JSX_tag_requires_the_module_0_which_cannot_be_resolved_in_a_script_file_Add_an_empty_export_statement_to_make_this_file_a_module
Comment on lines +1480 to +1481
}
mod := c.resolveExternalModule(core.OrElse(specifier, canonicalErrorTag), moduleReference, errorMessage, canonicalErrorTag, false, nil /*importAttributesType*/)
var result *ast.Symbol
if mod != nil && mod != c.unknownSymbol {
Expand Down
1 change: 1 addition & 0 deletions tsc/internal/diagnostics/diagnosticMessages.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@
"This_expression_is_never_nullish_2881": "This expression is never nullish.",
"Cannot_find_module_or_type_declarations_for_side_effect_import_of_0_2882": "Cannot find module or type declarations for side-effect import of '{0}'.",
"The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_2883": "The inferred type of '{0}' cannot be named without a reference to '{2}' from '{1}'. This is likely not portable. A type annotation is necessary.",
"This_JSX_tag_requires_the_module_0_which_cannot_be_resolved_in_a_script_file_Add_an_empty_export_sta_2884": "This JSX tag requires the module '{0}', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.",
"Import_declaration_0_is_using_private_name_1_4000": "Import declaration '{0}' is using private name '{1}'.",
"Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002": "Type parameter '{0}' of exported class has or is using private name '{1}'.",
"Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004": "Type parameter '{0}' of exported interface has or is using private name '{1}'.",
Expand Down
4 changes: 4 additions & 0 deletions tsc/internal/diagnostics/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4050,6 +4050,10 @@
"category": "Error",
"code": 2883
},
"This JSX tag requires the module '{0}', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.": {
"category": "Error",
"code": 2884
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
3 changes: 3 additions & 0 deletions tsc/internal/diagnostics/diagnostics_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2875: This JSX tag requires the module path 'react/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2884: This JSX tag requires the module 'react/jsx-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
commentsOnJSXExpressionsArePreserved.tsx(18,9): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.


Expand Down Expand Up @@ -38,7 +38,7 @@ commentsOnJSXExpressionsArePreserved.tsx(18,9): error TS7026: JSX element implic
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2875: This JSX tag requires the module path 'react/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
!!! error TS2884: This JSX tag requires the module 'react/jsx-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
~~~~~~
!!! error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2875: This JSX tag requires the module path 'react/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
commentsOnJSXExpressionsArePreserved.tsx(5,16): error TS2884: This JSX tag requires the module 'react/jsx-dev-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
commentsOnJSXExpressionsArePreserved.tsx(18,9): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.


Expand Down Expand Up @@ -38,7 +38,7 @@ commentsOnJSXExpressionsArePreserved.tsx(18,9): error TS7026: JSX element implic
~~~~~~~~~~~~~~~~~~~~~~~~
</div>;
~~~~~~~~~~~~~~
!!! error TS2875: This JSX tag requires the module path 'react/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
!!! error TS2884: This JSX tag requires the module 'react/jsx-dev-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
~~~~~~
!!! error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
index.tsx(1,18): error TS2875: This JSX tag requires the module path 'solid-js/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
index.tsx(1,18): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.


==== index.tsx (2 errors) ====
export const x = <div />;
~~~~~~~
!!! error TS2875: This JSX tag requires the module path 'solid-js/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
~~~~~~~
!!! error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//// [tests/cases/compiler/jsxImportSourceModuleMissing.tsx] ////

//// [index.tsx]
export const x = <div />;


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
const jsx_runtime_1 = require("solid-js/jsx-runtime");
exports.x = (0, jsx_runtime_1.jsx)("div", {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/jsxImportSourceModuleMissing.tsx] ////

=== index.tsx ===
export const x = <div />;
>x : Symbol(x, Decl(index.tsx, 0, 12))

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [tests/cases/compiler/jsxImportSourceModuleMissing.tsx] ////

=== index.tsx ===
export const x = <div />;
>x : any
><div /> : any
>div : any

11 changes: 11 additions & 0 deletions tsc/testdata/baselines/reference/compiler/jsxScriptFile.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
index.tsx(1,11): error TS2884: This JSX tag requires the module 'solid-js/jsx-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
index.tsx(1,11): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.


==== index.tsx (2 errors) ====
const x = <div />;
~~~~~~~
!!! error TS2884: This JSX tag requires the module 'solid-js/jsx-runtime', which cannot be resolved in a script file. Add an empty 'export {}' statement to make this file a module.
~~~~~~~
!!! error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

9 changes: 9 additions & 0 deletions tsc/testdata/baselines/reference/compiler/jsxScriptFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/jsxScriptFile.tsx] ////

//// [index.tsx]
const x = <div />;


//// [index.js]
"use strict";
const x = _jsx("div", {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/jsxScriptFile.tsx] ////

=== index.tsx ===
const x = <div />;
>x : Symbol(x, Decl(index.tsx, 0, 5))

8 changes: 8 additions & 0 deletions tsc/testdata/baselines/reference/compiler/jsxScriptFile.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [tests/cases/compiler/jsxScriptFile.tsx] ////

=== index.tsx ===
const x = <div />;
>x : any
><div /> : any
>div : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxScriptFileResolvableImportSource.tsx] ////

//// [jsx-runtime.d.ts]
export namespace JSX {
interface IntrinsicElements {
div: {};
}
}
export function jsx(type: any, props: any, key?: any): any;
export const Fragment: unique symbol;

//// [index.tsx]
const x = <div />;


//// [index.js]
"use strict";
const x = _jsx("div", {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/jsxScriptFileResolvableImportSource.tsx] ////

=== node_modules/solid-js/jsx-runtime.d.ts ===
export namespace JSX {
>JSX : Symbol(JSX, Decl(jsx-runtime.d.ts, 0, 0))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsx-runtime.d.ts, 0, 22))

div: {};
>div : Symbol(IntrinsicElements.div, Decl(jsx-runtime.d.ts, 1, 33))
}
}
export function jsx(type: any, props: any, key?: any): any;
>jsx : Symbol(jsx, Decl(jsx-runtime.d.ts, 4, 1))
>type : Symbol(type, Decl(jsx-runtime.d.ts, 5, 20))
>props : Symbol(props, Decl(jsx-runtime.d.ts, 5, 30))
>key : Symbol(key, Decl(jsx-runtime.d.ts, 5, 42))

export const Fragment: unique symbol;
>Fragment : Symbol(Fragment, Decl(jsx-runtime.d.ts, 6, 12))

=== index.tsx ===
const x = <div />;
>x : Symbol(x, Decl(index.tsx, 0, 5))
>div : Symbol(JSX.IntrinsicElements.div, Decl(jsx-runtime.d.ts, 1, 33))

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//// [tests/cases/compiler/jsxScriptFileResolvableImportSource.tsx] ////

=== node_modules/solid-js/jsx-runtime.d.ts ===
export namespace JSX {
interface IntrinsicElements {
div: {};
>div : {}
}
}
export function jsx(type: any, props: any, key?: any): any;
>jsx : (type: any, props: any, key?: any) => any
>type : any
>props : any
>key : any

export const Fragment: unique symbol;
>Fragment : unique symbol

=== index.tsx ===
const x = <div />;
>x : error
><div /> : error
>div : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @jsx: react-jsx
// @jsxImportSource: solid-js
// @module: nodenext

// @filename: index.tsx
export const x = <div />;
7 changes: 7 additions & 0 deletions tsc/testdata/tests/cases/compiler/jsxScriptFile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @jsx: react-jsx
// @jsxImportSource: solid-js
// @module: commonjs
// @moduleDetection: legacy

// @filename: index.tsx
const x = <div />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @jsx: react-jsx
// @jsxImportSource: solid-js
// @module: commonjs
// @moduleDetection: legacy

// @filename: node_modules/solid-js/jsx-runtime.d.ts
export namespace JSX {
interface IntrinsicElements {
div: {};
}
}
export function jsx(type: any, props: any, key?: any): any;
export const Fragment: unique symbol;

// @filename: index.tsx
const x = <div />;