Skip to content
Open
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
5 changes: 5 additions & 0 deletions tsc/internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,11 @@ func (c *Checker) getJsxNamespaceContainerForImplicitImport(location *ast.Node)
if moduleReference == "" {
return nil
}
if !ast.IsExternalOrCommonJSModule(file) {
c.error(canonicalErrorTag, diagnostics.This_JSX_tag_cannot_be_used_in_a_script_file_Consider_adding_an_empty_export_statement_to_make_this_file_a_module)
links.jsxImplicitImportContainer = c.unknownSymbol
return nil
}
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
mod := c.resolveExternalModule(core.OrElse(specifier, canonicalErrorTag), moduleReference, errorMessage, canonicalErrorTag, false, nil /*importAttributesType*/)
var result *ast.Symbol
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 @@ -1010,6 +1010,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_cannot_be_used_in_a_script_file_Consider_adding_an_empty_export_statement_to_make_this__2884": "This JSX tag cannot be used in a script file. Consider adding 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 @@ -4022,6 +4022,10 @@
"category": "Error",
"code": 2875
},
"This JSX tag cannot be used in a script file. Consider adding an empty 'export {}' statement to make this file a module.": {
"category": "Error",
"code": 2884
},
"This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to \"{0}\".": {
"category": "Error",
"code": 2876
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 cannot be used in a script file. Consider adding 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 cannot be used in a script file. Consider adding 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 cannot be used in a script file. Consider adding 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 cannot be used in a script file. Consider adding 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
18 changes: 18 additions & 0 deletions tsc/testdata/baselines/reference/compiler/jsxScriptFile.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
index.tsx(1,11): error TS2884: This JSX tag cannot be used in a script file. Consider adding 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.


==== node_modules/solid-js/jsx-runtime.d.ts (0 errors) ====
export namespace JSX {
interface IntrinsicElements {
div: {};
}
}

==== index.tsx (2 errors) ====
const x = <div />;
~~~~~~~
!!! error TS2884: This JSX tag cannot be used in a script file. Consider adding an empty 'export {}' statement to make this file a module.
~~~~~~~
!!! error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

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

//// [jsx-runtime.d.ts]
export namespace JSX {
interface IntrinsicElements {
div: {};
}
}

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


//// [index.js]
"use strict";
const x = _jsx("div", {});
18 changes: 18 additions & 0 deletions tsc/testdata/baselines/reference/compiler/jsxScriptFile.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxScriptFile.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))
}
}

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

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

=== node_modules/solid-js/jsx-runtime.d.ts ===
export namespace JSX {
interface IntrinsicElements {
div: {};
>div : {}
}
}

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

13 changes: 13 additions & 0 deletions tsc/testdata/tests/cases/compiler/jsxScriptFile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @jsx: react-jsx
// @jsxImportSource: solid-js
// @moduleDetection: legacy

// @filename: node_modules/solid-js/jsx-runtime.d.ts
export namespace JSX {
interface IntrinsicElements {
div: {};
}
}

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