mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 16:34:39 -06:00
Fix sending correct symbol when using commonjs require and destructuring (#43511)
* Fix sending correct symbol when using commonjs require and destructuring * Check BindingElement
This commit is contained in:
parent
6002cff776
commit
5a6a499d0e
@ -1477,7 +1477,7 @@ namespace ts.FindAllReferences {
|
||||
|
||||
if (!hasMatchingMeaning(referenceLocation, state)) return;
|
||||
|
||||
const referenceSymbol = state.checker.getSymbolAtLocation(referenceLocation);
|
||||
let referenceSymbol = state.checker.getSymbolAtLocation(referenceLocation);
|
||||
if (!referenceSymbol) {
|
||||
return;
|
||||
}
|
||||
@ -1514,6 +1514,11 @@ namespace ts.FindAllReferences {
|
||||
Debug.assertNever(state.specialSearchKind);
|
||||
}
|
||||
|
||||
// Use the parent symbol if the location is commonjs require syntax on javascript files only.
|
||||
referenceSymbol = isInJSFile(referenceLocation) && referenceLocation.parent.kind === SyntaxKind.BindingElement && isRequireVariableDeclaration(referenceLocation.parent)
|
||||
? referenceLocation.parent.symbol
|
||||
: referenceSymbol;
|
||||
|
||||
getImportOrExportReferences(referenceLocation, referenceSymbol, search, state);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
// === /tests/cases/fourslash/bar.js ===
|
||||
// const { /*FIND ALL REFS*/[|foo|]: bar } = require('./foo');
|
||||
|
||||
// === /tests/cases/fourslash/foo.js ===
|
||||
// module.exports = {
|
||||
// [|foo|]: '1'
|
||||
// };
|
||||
|
||||
[
|
||||
{
|
||||
"definition": {
|
||||
"containerKind": "",
|
||||
"containerName": "",
|
||||
"fileName": "/tests/cases/fourslash/foo.js",
|
||||
"kind": "property",
|
||||
"name": "(property) foo: string",
|
||||
"textSpan": {
|
||||
"start": 23,
|
||||
"length": 3
|
||||
},
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "(",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": "property",
|
||||
"kind": "text"
|
||||
},
|
||||
{
|
||||
"text": ")",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "foo",
|
||||
"kind": "propertyName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "string",
|
||||
"kind": "keyword"
|
||||
}
|
||||
],
|
||||
"contextSpan": {
|
||||
"start": 23,
|
||||
"length": 8
|
||||
}
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"textSpan": {
|
||||
"start": 23,
|
||||
"length": 3
|
||||
},
|
||||
"fileName": "/tests/cases/fourslash/foo.js",
|
||||
"contextSpan": {
|
||||
"start": 23,
|
||||
"length": 8
|
||||
},
|
||||
"isWriteAccess": true,
|
||||
"isDefinition": true
|
||||
},
|
||||
{
|
||||
"textSpan": {
|
||||
"start": 8,
|
||||
"length": 3
|
||||
},
|
||||
"fileName": "/tests/cases/fourslash/bar.js",
|
||||
"contextSpan": {
|
||||
"start": 0,
|
||||
"length": 38
|
||||
},
|
||||
"isWriteAccess": false,
|
||||
"isDefinition": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @checkJs: true
|
||||
|
||||
// @Filename: foo.js
|
||||
//// module.exports = {
|
||||
//// foo: '1'
|
||||
//// };
|
||||
|
||||
// @Filename: bar.js
|
||||
//// const { /*1*/foo: bar } = require('./foo');
|
||||
|
||||
verify.baselineFindAllReferences("1");
|
||||
Loading…
x
Reference in New Issue
Block a user