Fix handling of aruments in the emitter

Two problems are fixed:

* `isArgumentsLocalBinding` did only `PropertyAccessExpression`, now
  it's also doing `PropertyAssignment` (doesn't affect other files,
  since it's only used in the emitter).

* `visitShorthandPropertyAssignment` should call `visitIdentifier` on
  the synthesized id.  (For completion it might be better to make it
  visit the the original?)

Fixes #38594.
This commit is contained in:
Eli Barzilay
2020-06-01 11:53:38 -04:00
parent b63ea4b6df
commit f447838f95
6 changed files with 130 additions and 16 deletions

View File

@@ -36095,15 +36095,16 @@ namespace ts {
// Emitter support
function isArgumentsLocalBinding(nodeIn: Identifier): boolean {
if (!isGeneratedIdentifier(nodeIn)) {
const node = getParseTreeNode(nodeIn, isIdentifier);
if (node) {
const isPropertyName = node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node;
return !isPropertyName && getReferencedValueSymbol(node) === argumentsSymbol;
}
}
return false;
// Note: does not handle isShorthandPropertyAssignment (and probably a few more)
if (isGeneratedIdentifier(nodeIn)) return false;
const node = getParseTreeNode(nodeIn, isIdentifier);
if (!node) return false;
const parent = node.parent;
if (!parent) return false;
const isPropertyName = ((isPropertyAccessExpression(parent)
|| isPropertyAssignment(parent))
&& parent.name === node);
return !isPropertyName && getReferencedValueSymbol(node) === argumentsSymbol;
}
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {

View File

@@ -583,13 +583,10 @@ namespace ts {
if (!convertedLoopState) {
return node;
}
if (isGeneratedIdentifier(node)) {
return node;
if (resolver.isArgumentsLocalBinding(node)) {
return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = createUniqueName("arguments"));
}
if (node.escapedText !== "arguments" || !resolver.isArgumentsLocalBinding(node)) {
return node;
}
return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = createUniqueName("arguments"));
return node;
}
function visitBreakOrContinueStatement(node: BreakOrContinueStatement): Statement {
@@ -3517,7 +3514,7 @@ namespace ts {
return setTextRange(
createPropertyAssignment(
node.name,
getSynthesizedClone(node.name)
visitIdentifier(getSynthesizedClone(node.name))
),
/*location*/ node
);