Bind module.export = {Thing} with alias symbols

This commit is contained in:
Wesley Wigham
2020-10-27 15:43:00 -07:00
parent 9ed608b439
commit d1bc6b1ba6
38 changed files with 463 additions and 145 deletions
+9
View File
@@ -2833,6 +2833,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
@@ -2841,6 +2846,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)
+4 -8
View File
@@ -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')