Fixed Go To Definition using jsconfig (#47434)

* Fixed Go To Definition using jsconfig

* Fixed formatting
This commit is contained in:
Armando Aguirre 2022-01-20 14:45:29 -08:00 committed by GitHub
parent 7e3eccedd7
commit ab4d3198ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 119 additions and 1 deletions

View File

@ -3467,8 +3467,14 @@ namespace ts {
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, mode);
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
const sourceFile = resolvedModule
&& (!resolutionDiagnostic || resolutionDiagnostic === Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set)
&& host.getSourceFile(resolvedModule.resolvedFileName);
if (sourceFile) {
// If there's a resolutionDiagnostic we need to report it even if a sourceFile is found.
if (resolutionDiagnostic) {
error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName);
}
if (sourceFile.symbol) {
if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) {
errorOnImplicitAnyModule(/*isError*/ false, errorNode, resolvedModule, moduleReference);

View File

@ -0,0 +1,20 @@
/bar.jsx(1,17): error TS6142: Module '/foo' was resolved to '/foo.jsx', but '--jsx' is not set.
/bar.jsx(2,11): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
/foo.jsx(2,5): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
==== /foo.jsx (1 errors) ====
const Foo = () => (
<div>foo</div>
~~~~~
!!! error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
);
export default Foo;
==== /bar.jsx (2 errors) ====
import Foo from '/foo';
~~~~~~
!!! error TS6142: Module '/foo' was resolved to '/foo.jsx', but '--jsx' is not set.
const a = <Foo />
~~~~~~~
!!! error TS17004: Cannot use JSX unless the '--jsx' flag is provided.

View File

@ -0,0 +1,22 @@
//// [tests/cases/compiler/checkJsxNotSetError.ts] ////
//// [foo.jsx]
const Foo = () => (
<div>foo</div>
);
export default Foo;
//// [bar.jsx]
import Foo from '/foo';
const a = <Foo />
//// [foo.js]
"use strict";
exports.__esModule = true;
var Foo = function () { return (<div>foo</div>); };
exports["default"] = Foo;
//// [bar.js]
"use strict";
exports.__esModule = true;
var foo_1 = require("/foo");
var a = <foo_1["default"] />;

View File

@ -0,0 +1,17 @@
=== /foo.jsx ===
const Foo = () => (
>Foo : Symbol(Foo, Decl(foo.jsx, 0, 5))
<div>foo</div>
);
export default Foo;
>Foo : Symbol(Foo, Decl(foo.jsx, 0, 5))
=== /bar.jsx ===
import Foo from '/foo';
>Foo : Symbol(Foo, Decl(bar.jsx, 0, 6))
const a = <Foo />
>a : Symbol(a, Decl(bar.jsx, 1, 5))
>Foo : Symbol(Foo, Decl(bar.jsx, 0, 6))

View File

@ -0,0 +1,24 @@
=== /foo.jsx ===
const Foo = () => (
>Foo : () => any
>() => ( <div>foo</div>) : () => any
>( <div>foo</div>) : any
<div>foo</div>
><div>foo</div> : any
>div : any
>div : any
);
export default Foo;
>Foo : () => any
=== /bar.jsx ===
import Foo from '/foo';
>Foo : () => any
const a = <Foo />
>a : any
><Foo /> : any
>Foo : () => any

View File

@ -0,0 +1,12 @@
// @allowJs: true
// @checkJs: true
// @Filename: /foo.jsx
const Foo = () => (
<div>foo</div>
);
export default Foo;
// @Filename: /bar.jsx
import Foo from '/foo';
const a = <Foo />

View File

@ -0,0 +1,17 @@
/// <reference path='fourslash.ts' />
// Regresion tests for GH#46854
// @allowJs: true
// @Filename: /foo.jsx
//// const /*def*/Foo = () => (
//// <div>foo</div>
//// );
//// export default Foo;
// @Filename: /bar.jsx
//// import Foo from './foo';
//// const a = <[|/*use*/Foo|] />
verify.goToDefinition("use", "def");