diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts
index 1c459c83e64..b19eca59266 100644
--- a/src/compiler/utilities.ts
+++ b/src/compiler/utilities.ts
@@ -6054,7 +6054,7 @@ namespace ts {
export function getJSXImplicitImportBase(compilerOptions: CompilerOptions, file?: SourceFile): string | undefined {
const jsxImportSourcePragmas = file?.pragmas.get("jsximportsource");
- const jsxImportSourcePragma = isArray(jsxImportSourcePragmas) ? jsxImportSourcePragmas[0] : jsxImportSourcePragmas;
+ const jsxImportSourcePragma = isArray(jsxImportSourcePragmas) ? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1] : jsxImportSourcePragmas;
return compilerOptions.jsx === JsxEmit.ReactJSX ||
compilerOptions.jsx === JsxEmit.ReactJSXDev ||
compilerOptions.jsxImportSource ||
diff --git a/tests/baselines/reference/jsxImportSourceNonPragmaComment.errors.txt b/tests/baselines/reference/jsxImportSourceNonPragmaComment.errors.txt
new file mode 100644
index 00000000000..01a65e4e587
--- /dev/null
+++ b/tests/baselines/reference/jsxImportSourceNonPragmaComment.errors.txt
@@ -0,0 +1,26 @@
+tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx(3,21): error TS2307: Cannot find module '@emotion/react' or its corresponding type declarations.
+tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx(7,5): error TS2307: Cannot find module '@emotion/react/jsx-runtime' or its corresponding type declarations.
+
+
+==== tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx (2 errors) ====
+ /* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+ /** @jsxImportSource @emotion/react */
+ import { css } from "@emotion/react";
+ ~~~~~~~~~~~~~~~~
+!!! error TS2307: Cannot find module '@emotion/react' or its corresponding type declarations.
+
+ export default function Component() {
+ return (
+
+ ~~~~~~
+!!! error TS2307: Cannot find module '@emotion/react/jsx-runtime' or its corresponding type declarations.
+ );
+ }
\ No newline at end of file
diff --git a/tests/baselines/reference/jsxImportSourceNonPragmaComment.js b/tests/baselines/reference/jsxImportSourceNonPragmaComment.js
new file mode 100644
index 00000000000..fd0373a209c
--- /dev/null
+++ b/tests/baselines/reference/jsxImportSourceNonPragmaComment.js
@@ -0,0 +1,30 @@
+//// [jsxImportSourceNonPragmaComment.tsx]
+/* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+/** @jsxImportSource @emotion/react */
+import { css } from "@emotion/react";
+
+export default function Component() {
+ return (
+
+ );
+}
+
+//// [jsxImportSourceNonPragmaComment.jsx]
+"use strict";
+var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
+ return cooked;
+};
+exports.__esModule = true;
+/* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+/** @jsxImportSource @emotion/react */
+var react_1 = require("@emotion/react");
+function Component() {
+ return ();
+}
+exports["default"] = Component;
+var templateObject_1;
diff --git a/tests/baselines/reference/jsxImportSourceNonPragmaComment.symbols b/tests/baselines/reference/jsxImportSourceNonPragmaComment.symbols
new file mode 100644
index 00000000000..c71d617d958
--- /dev/null
+++ b/tests/baselines/reference/jsxImportSourceNonPragmaComment.symbols
@@ -0,0 +1,20 @@
+=== tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx ===
+/* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+/** @jsxImportSource @emotion/react */
+import { css } from "@emotion/react";
+>css : Symbol(css, Decl(jsxImportSourceNonPragmaComment.tsx, 2, 8))
+
+export default function Component() {
+>Component : Symbol(Component, Decl(jsxImportSourceNonPragmaComment.tsx, 2, 37))
+
+ return (
+ css : Symbol(css, Decl(jsxImportSourceNonPragmaComment.tsx, 6, 10))
+>css : Symbol(css, Decl(jsxImportSourceNonPragmaComment.tsx, 2, 8))
+
+ color: red;
+ `}
+ />
+ );
+}
diff --git a/tests/baselines/reference/jsxImportSourceNonPragmaComment.types b/tests/baselines/reference/jsxImportSourceNonPragmaComment.types
new file mode 100644
index 00000000000..23e11e9264a
--- /dev/null
+++ b/tests/baselines/reference/jsxImportSourceNonPragmaComment.types
@@ -0,0 +1,27 @@
+=== tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx ===
+/* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+/** @jsxImportSource @emotion/react */
+import { css } from "@emotion/react";
+>css : any
+
+export default function Component() {
+>Component : () => any
+
+ return (
+>( ) : any
+
+ : any
+>input : any
+
+ css={css`
+>css : any
+>css` color: red; ` : any
+>css : any
+>` color: red; ` : "\n color: red;\n "
+
+ color: red;
+ `}
+ />
+ );
+}
diff --git a/tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx b/tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx
new file mode 100644
index 00000000000..9b14a982bc5
--- /dev/null
+++ b/tests/cases/compiler/jsxImportSourceNonPragmaComment.tsx
@@ -0,0 +1,14 @@
+// @jsx: preserve
+/* eslint-disable react/react-in-jsx-scope -- Unaware of @jsxImportSource */
+/** @jsxImportSource @emotion/react */
+import { css } from "@emotion/react";
+
+export default function Component() {
+ return (
+
+ );
+}
\ No newline at end of file