mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Fixed Go To Definition using jsconfig (#47434)
* Fixed Go To Definition using jsconfig * Fixed formatting
This commit is contained in:
parent
7e3eccedd7
commit
ab4d3198ed
@ -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);
|
||||
|
||||
20
tests/baselines/reference/checkJsxNotSetError.errors.txt
Normal file
20
tests/baselines/reference/checkJsxNotSetError.errors.txt
Normal 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.
|
||||
22
tests/baselines/reference/checkJsxNotSetError.js
Normal file
22
tests/baselines/reference/checkJsxNotSetError.js
Normal 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"] />;
|
||||
17
tests/baselines/reference/checkJsxNotSetError.symbols
Normal file
17
tests/baselines/reference/checkJsxNotSetError.symbols
Normal 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))
|
||||
|
||||
24
tests/baselines/reference/checkJsxNotSetError.types
Normal file
24
tests/baselines/reference/checkJsxNotSetError.types
Normal 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
|
||||
|
||||
12
tests/cases/compiler/checkJsxNotSetError.ts
Normal file
12
tests/cases/compiler/checkJsxNotSetError.ts
Normal 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 />
|
||||
17
tests/cases/fourslash/goToDefinitionJsxNotSet.ts
Normal file
17
tests/cases/fourslash/goToDefinitionJsxNotSet.ts
Normal 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");
|
||||
Loading…
x
Reference in New Issue
Block a user