Skip to content

Commit 4d5464e

Browse files
authored
Revert "Support declaration emit for late bound element accesses assigned to functions in both TS and JS (#36593)" (#37034)
This reverts commit 3e4ce47.
1 parent 9ed73eb commit 4d5464e

13 files changed

+13
-449
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,20 +3069,9 @@ namespace ts {
30693069
function resolveExternalModuleSymbol(moduleSymbol: Symbol | undefined, dontResolveAlias?: boolean): Symbol | undefined;
30703070
function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol {
30713071
if (moduleSymbol) {
3072-
const links = getSymbolLinks(moduleSymbol);
3073-
if (!dontResolveAlias) {
3074-
links.resolvedExternalModuleSymbol = "circular";
3075-
}
30763072
const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias);
30773073
const exported = getCommonJsExportEquals(getMergedSymbol(exportEquals), getMergedSymbol(moduleSymbol));
3078-
const result = getMergedSymbol(exported) || moduleSymbol;
3079-
if (!dontResolveAlias) {
3080-
// we "cache" this result, but because both the input _and_ the output are mergeable, literally every call could need
3081-
// a different result, assuming the inputs and outputs get merged with. So instead we just use this as a flag that
3082-
// export assignment resolution has occured on this symbol at least once. (because it might happen many times!)
3083-
links.resolvedExternalModuleSymbol = result;
3084-
}
3085-
return result;
3074+
return getMergedSymbol(exported) || moduleSymbol;
30863075
}
30873076
return undefined!;
30883077
}
@@ -5554,7 +5543,7 @@ namespace ts {
55545543
function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean) {
55555544
const symbolName = unescapeLeadingUnderscores(symbol.escapedName);
55565545
const isDefault = symbol.escapedName === InternalSymbolName.Default;
5557-
if ((isStringANonContextualKeyword(symbolName) || !isIdentifierText(symbolName, languageVersion)) && !isDefault && symbol.escapedName !== InternalSymbolName.ExportEquals) {
5546+
if (isStringANonContextualKeyword(symbolName) && !isDefault) {
55585547
// Oh no. We cannot use this symbol's name as it's name... It's likely some jsdoc had an invalid name like `export` or `default` :(
55595548
context.encounteredError = true;
55605549
// TODO: Issue error via symbol tracker?
@@ -5705,8 +5694,7 @@ namespace ts {
57055694
}
57065695

57075696
function getNamespaceMembersForSerialization(symbol: Symbol) {
5708-
const exports = getExportsOfSymbol(symbol);
5709-
return !exports ? [] : filter(arrayFrom((exports).values()), p => !((p.flags & SymbolFlags.Prototype) || (p.escapedName === "prototype")));
5697+
return !symbol.exports ? [] : filter(arrayFrom((symbol.exports).values()), p => !((p.flags & SymbolFlags.Prototype) || (p.escapedName === "prototype")));
57105698
}
57115699

57125700
function isTypeOnlyNamespace(symbol: Symbol) {
@@ -8908,17 +8896,6 @@ namespace ts {
89088896
function getResolvedMembersOrExportsOfSymbol(symbol: Symbol, resolutionKind: MembersOrExportsResolutionKind): UnderscoreEscapedMap<Symbol> {
89098897
const links = getSymbolLinks(symbol);
89108898
if (!links[resolutionKind]) {
8911-
// We _must_ resolve any possible commonjs export assignments _before_ merging in late bound members, as cjs export assignments may cause
8912-
// things to be merged (?!?) into this symbol; moreover, we _can't_ resolve those export assignments if we're already resolving the containing
8913-
// module (as then we'll issue a circularity error)
8914-
const p = symbol.valueDeclaration?.parent;
8915-
if (p && isSourceFile(p) && p.symbol && !getSymbolLinks(p.symbol).resolvedExternalModuleSymbol) {
8916-
const exported = resolveExternalModuleSymbol(p.symbol);
8917-
const targetLinks = exported && getSymbolLinks(exported);
8918-
if (targetLinks && targetLinks[resolutionKind]) {
8919-
return links[resolutionKind] = targetLinks[resolutionKind]!;
8920-
}
8921-
}
89228899
const isStatic = resolutionKind === MembersOrExportsResolutionKind.resolvedExports;
89238900
const earlySymbols = !isStatic ? symbol.members :
89248901
symbol.flags & SymbolFlags.Module ? getExportsOfModuleWorker(symbol) :
@@ -35285,8 +35262,8 @@ namespace ts {
3528535262
}
3528635263
}
3528735264

35288-
function createTypeOfDeclaration(declarationIn: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression | ElementAccessExpression | BinaryExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean) {
35289-
const declaration = getParseTreeNode(declarationIn, isPossiblyPropertyLikeDeclaration);
35265+
function createTypeOfDeclaration(declarationIn: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean) {
35266+
const declaration = getParseTreeNode(declarationIn, isVariableLikeOrAccessor);
3529035267
if (!declaration) {
3529135268
return createToken(SyntaxKind.AnyKeyword) as KeywordTypeNode;
3529235269
}

src/compiler/transformers/declarations.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,20 +1157,13 @@ namespace ts {
11571157
fakespace.locals = createSymbolTable(props);
11581158
fakespace.symbol = props[0].parent!;
11591159
const declarations = mapDefined(props, p => {
1160-
if (!isPropertyAccessExpression(p.valueDeclaration) && !isElementAccessExpression(p.valueDeclaration) && !isBinaryExpression(p.valueDeclaration)) {
1161-
return undefined;
1162-
}
1163-
if (hasDynamicName(p.valueDeclaration) && !resolver.isLateBound(getParseTreeNode(p.valueDeclaration) as Declaration)) {
1164-
return undefined;
1165-
}
1166-
const name = unescapeLeadingUnderscores(p.escapedName);
1167-
if (!isIdentifierText(name, ScriptTarget.ES3)) {
1168-
return undefined; // TODO: Rather than quietly eliding (as is current behavior), maybe we should issue errors?
1160+
if (!isPropertyAccessExpression(p.valueDeclaration)) {
1161+
return undefined; // TODO GH#33569: Handle element access expressions that created late bound names (rather than silently omitting them)
11691162
}
11701163
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.valueDeclaration);
11711164
const type = resolver.createTypeOfDeclaration(p.valueDeclaration, fakespace, declarationEmitNodeBuilderFlags, symbolTracker);
11721165
getSymbolAccessibilityDiagnostic = oldDiag;
1173-
const varDecl = createVariableDeclaration(name, type, /*initializer*/ undefined);
1166+
const varDecl = createVariableDeclaration(unescapeLeadingUnderscores(p.escapedName), type, /*initializer*/ undefined);
11741167
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([varDecl]));
11751168
});
11761169
const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name!, createModuleBlock(declarations), NodeFlags.Namespace);

src/compiler/transformers/declarations/diagnostics.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ namespace ts {
2727
| TypeAliasDeclaration
2828
| ConstructorDeclaration
2929
| IndexSignatureDeclaration
30-
| PropertyAccessExpression
31-
| ElementAccessExpression
32-
| BinaryExpression;
30+
| PropertyAccessExpression;
3331

3432
export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing {
3533
return isVariableDeclaration(node) ||
@@ -50,9 +48,7 @@ namespace ts {
5048
isTypeAliasDeclaration(node) ||
5149
isConstructorDeclaration(node) ||
5250
isIndexSignatureDeclaration(node) ||
53-
isPropertyAccessExpression(node) ||
54-
isElementAccessExpression(node) ||
55-
isBinaryExpression(node);
51+
isPropertyAccessExpression(node);
5652
}
5753

5854
export function createGetSymbolAccessibilityDiagnosticForNodeName(node: DeclarationDiagnosticProducing) {
@@ -129,7 +125,7 @@ namespace ts {
129125
}
130126

131127
export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing): (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic | undefined {
132-
if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node) || isBinaryExpression(node) || isBindingElement(node) || isConstructorDeclaration(node)) {
128+
if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isPropertyAccessExpression(node) || isBindingElement(node) || isConstructorDeclaration(node)) {
133129
return getVariableDeclarationTypeVisibilityError;
134130
}
135131
else if (isSetAccessor(node) || isGetAccessor(node)) {
@@ -170,7 +166,7 @@ namespace ts {
170166
}
171167
// This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit
172168
// The only exception here is if the constructor was marked as private. we are not emitting the constructor parameters at all.
173-
else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression || node.kind === SyntaxKind.BinaryExpression || node.kind === SyntaxKind.PropertySignature ||
169+
else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.PropertySignature ||
174170
(node.kind === SyntaxKind.Parameter && hasModifier(node.parent, ModifierFlags.Private))) {
175171
// TODO(jfreeman): Deal with computed properties in error reporting.
176172
if (hasModifier(node, ModifierFlags.Static)) {

src/compiler/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ namespace ts {
39353935
isOptionalUninitializedParameterProperty(node: ParameterDeclaration): boolean;
39363936
isExpandoFunctionDeclaration(node: FunctionDeclaration): boolean;
39373937
getPropertiesOfContainerFunction(node: Declaration): Symbol[];
3938-
createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression | ElementAccessExpression | BinaryExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean): TypeNode | undefined;
3938+
createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean): TypeNode | undefined;
39393939
createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
39403940
createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined;
39413941
createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker): Expression;
@@ -4109,7 +4109,6 @@ namespace ts {
41094109
deferralParent?: Type; // Source union/intersection of a deferred type
41104110
cjsExportMerged?: Symbol; // Version of the symbol with all non export= exports merged with the export= target
41114111
typeOnlyDeclaration?: TypeOnlyCompatibleAliasDeclaration | false; // First resolved alias declaration that makes the symbol only usable in type constructs
4112-
resolvedExternalModuleSymbol?: Symbol | "circular"; // Cached result of `resolveExternalModuleSymbol`
41134112
}
41144113

41154114
/* @internal */

src/compiler/utilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,10 +1299,6 @@ namespace ts {
12991299
return isVariableLike(node) || isAccessor(node);
13001300
}
13011301

1302-
export function isPossiblyPropertyLikeDeclaration(node: Node): node is AccessorDeclaration | VariableLikeDeclaration | PropertyAccessExpression | ElementAccessExpression {
1303-
return isVariableLikeOrAccessor(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node) || isBinaryExpression(node);
1304-
}
1305-
13061302
export function isVariableDeclarationInVariableStatement(node: VariableDeclaration) {
13071303
return node.parent.kind === SyntaxKind.VariableDeclarationList
13081304
&& node.parent.parent.kind === SyntaxKind.VariableStatement;

tests/baselines/reference/lateBoundElementAccessAssignmentDeclarations.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/baselines/reference/lateBoundElementAccessAssignmentDeclarations.symbols

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)