mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Use ad-hoc code for nested destructuring in require (#40188)
* Use ad-hoc code for nested destructuring in require
Nested destructuring doesn't really map to ES imports:
```js
const { utils: { nub, intercalate } } = require('./monopackage')
```
Previously, isRequireVariableDeclaration walked up binding elements
until it reached a variable declaration. This change instead only walks
up one binding element and stops. Then it's not bound as an alias and
uses the checker-only code to produce types for the nested-imported
identifiers.
Fixes #40143
* revert binder formatting change
This commit is contained in:
committed by
GitHub
parent
45dedd6b87
commit
b7c598ea39
@@ -1939,7 +1939,9 @@ namespace ts {
|
||||
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: true): node is RequireVariableDeclaration;
|
||||
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration;
|
||||
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration {
|
||||
node = getRootDeclaration(node);
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
node = node.parent.parent;
|
||||
}
|
||||
return isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), requireStringLiteralLikeArgument);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user