Skip to content

Commit c8090dc

Browse files
author
Joseph Watts
committed
Emit unchanged output for undeclared private names
1 parent 24ad88c commit c8090dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/compiler/transformers/esnext.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ namespace ts {
149149
if (nameString in environment) {
150150
return environment[nameString].weakMap;
151151
}
152-
throw new Error("Accessing undeclared private name.");
152+
// Undeclared private name.
153+
return undefined;
153154
}
154155

155156
function visitPropertyAccessExpression(node: PropertyAccessExpression): Expression {
156157
if (isPrivateName(node.name)) {
157158
const weakMapName = accessPrivateName(node.name);
159+
if (!weakMapName) {
160+
return node;
161+
}
158162
return setOriginalNode(
159163
setTextRange(
160164
createClassPrivateFieldGetHelper(context, node.expression, weakMapName),
@@ -473,6 +477,10 @@ namespace ts {
473477
isPrivateName(node.left.name)) {
474478

475479
const weakMapName = accessPrivateName(node.left.name);
480+
if (!weakMapName) {
481+
// Don't change output for undeclared private names (error).
482+
return node;
483+
}
476484
if (isCompoundAssignment(node.operatorToken.kind)) {
477485
let setReceiver: Expression;
478486
let getReceiver: Expression;

0 commit comments

Comments
 (0)