Skip to content

Commit ab4d319

Browse files
authored
Fixed Go To Definition using jsconfig (#47434)
* Fixed Go To Definition using jsconfig * Fixed formatting
1 parent 7e3ecce commit ab4d319

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3467,8 +3467,14 @@ namespace ts {
34673467
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
34683468
const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, mode);
34693469
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
3470-
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
3470+
const sourceFile = resolvedModule
3471+
&& (!resolutionDiagnostic || resolutionDiagnostic === Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set)
3472+
&& host.getSourceFile(resolvedModule.resolvedFileName);
34713473
if (sourceFile) {
3474+
// If there's a resolutionDiagnostic we need to report it even if a sourceFile is found.
3475+
if (resolutionDiagnostic) {
3476+
error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName);
3477+
}
34723478
if (sourceFile.symbol) {
34733479
if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
34743480
errorOnImplicitAnyModule(/*isError*/ false, errorNode, resolvedModule, moduleReference);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/bar.jsx(1,17): error TS6142: Module '/foo' was resolved to '/foo.jsx', but '--jsx' is not set.
2+
/bar.jsx(2,11): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
3+
/foo.jsx(2,5): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
4+
5+
6+
==== /foo.jsx (1 errors) ====
7+
const Foo = () => (
8+
<div>foo</div>
9+
~~~~~
10+
!!! error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
11+
);
12+
export default Foo;
13+
14+
==== /bar.jsx (2 errors) ====
15+
import Foo from '/foo';
16+
~~~~~~
17+
!!! error TS6142: Module '/foo' was resolved to '/foo.jsx', but '--jsx' is not set.
18+
const a = <Foo />
19+
~~~~~~~
20+
!!! error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/checkJsxNotSetError.ts] ////
2+
3+
//// [foo.jsx]
4+
const Foo = () => (
5+
<div>foo</div>
6+
);
7+
export default Foo;
8+
9+
//// [bar.jsx]
10+
import Foo from '/foo';
11+
const a = <Foo />
12+
13+
//// [foo.js]
14+
"use strict";
15+
exports.__esModule = true;
16+
var Foo = function () { return (<div>foo</div>); };
17+
exports["default"] = Foo;
18+
//// [bar.js]
19+
"use strict";
20+
exports.__esModule = true;
21+
var foo_1 = require("/foo");
22+
var a = <foo_1["default"] />;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== /foo.jsx ===
2+
const Foo = () => (
3+
>Foo : Symbol(Foo, Decl(foo.jsx, 0, 5))
4+
5+
<div>foo</div>
6+
);
7+
export default Foo;
8+
>Foo : Symbol(Foo, Decl(foo.jsx, 0, 5))
9+
10+
=== /bar.jsx ===
11+
import Foo from '/foo';
12+
>Foo : Symbol(Foo, Decl(bar.jsx, 0, 6))
13+
14+
const a = <Foo />
15+
>a : Symbol(a, Decl(bar.jsx, 1, 5))
16+
>Foo : Symbol(Foo, Decl(bar.jsx, 0, 6))
17+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== /foo.jsx ===
2+
const Foo = () => (
3+
>Foo : () => any
4+
>() => ( <div>foo</div>) : () => any
5+
>( <div>foo</div>) : any
6+
7+
<div>foo</div>
8+
><div>foo</div> : any
9+
>div : any
10+
>div : any
11+
12+
);
13+
export default Foo;
14+
>Foo : () => any
15+
16+
=== /bar.jsx ===
17+
import Foo from '/foo';
18+
>Foo : () => any
19+
20+
const a = <Foo />
21+
>a : any
22+
><Foo /> : any
23+
>Foo : () => any
24+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
4+
// @Filename: /foo.jsx
5+
const Foo = () => (
6+
<div>foo</div>
7+
);
8+
export default Foo;
9+
10+
// @Filename: /bar.jsx
11+
import Foo from '/foo';
12+
const a = <Foo />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Regresion tests for GH#46854
4+
5+
// @allowJs: true
6+
7+
// @Filename: /foo.jsx
8+
//// const /*def*/Foo = () => (
9+
//// <div>foo</div>
10+
//// );
11+
//// export default Foo;
12+
13+
// @Filename: /bar.jsx
14+
//// import Foo from './foo';
15+
//// const a = <[|/*use*/Foo|] />
16+
17+
verify.goToDefinition("use", "def");

0 commit comments

Comments
 (0)