mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge pull request #41287 from weswigham/bind-exports-assigned-object-as-alias
Bind `module.export = {Thing}` with alias symbols
This commit is contained in:
@@ -2834,6 +2834,11 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isObjectLiteralExpression(assignedExpression) && every(assignedExpression.properties, isShorthandPropertyAssignment)) {
|
||||
forEach(assignedExpression.properties, bindExportAssignedObjectMemberAlias);
|
||||
return;
|
||||
}
|
||||
|
||||
// 'module.exports = expr' assignment
|
||||
const flags = exportAssignmentIsAlias(node)
|
||||
? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class
|
||||
@@ -2842,6 +2847,10 @@ namespace ts {
|
||||
setValueDeclaration(symbol, node);
|
||||
}
|
||||
|
||||
function bindExportAssignedObjectMemberAlias(node: ShorthandPropertyAssignment) {
|
||||
declareSymbol(file.symbol.exports!, file.symbol, node, SymbolFlags.Alias | SymbolFlags.Assignment, SymbolFlags.None);
|
||||
}
|
||||
|
||||
function bindThisPropertyAssignment(node: BindablePropertyAssignmentExpression | PropertyAccessExpression | LiteralLikeElementAccessExpression) {
|
||||
Debug.assert(isInJSFile(node));
|
||||
// private identifiers *must* be declared (even in JS files)
|
||||
|
||||
@@ -6807,21 +6807,17 @@ namespace ts {
|
||||
), ModifierFlags.None);
|
||||
break;
|
||||
}
|
||||
// At present, the below case should be entirely unhit, as, generally speaking, the below case is *usually* bound
|
||||
// such that the `BinaryExpression` is the declaration rather than the specific, nested binding element
|
||||
// (because we don't seek to emit an alias in these forms yet). As such, the `BinaryExpression` switch case
|
||||
// will be what actually handles this form. _However_, in anticipation of binding the below with proper
|
||||
// alias symbols, I'm _pretty comfortable_ including the case here, even though it is not yet live.
|
||||
// We don't know how to serialize this (nested?) binding element
|
||||
Debug.failBadSyntaxKind(node.parent?.parent || node, "Unhandled binding element grandparent kind in declaration serialization");
|
||||
break;
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
if (node.parent?.parent?.kind === SyntaxKind.BinaryExpression) {
|
||||
// module.exports = { SomeClass }
|
||||
serializeExportSpecifier(
|
||||
unescapeLeadingUnderscores(symbol.escapedName),
|
||||
targetName
|
||||
);
|
||||
break;
|
||||
}
|
||||
// We don't know how to serialize this (nested?) binding element
|
||||
Debug.failBadSyntaxKind(node.parent?.parent || node, "Unhandled binding element grandparent kind in declaration serialization");
|
||||
break;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
// commonjs require: const x = require('y')
|
||||
|
||||
Reference in New Issue
Block a user