Skip to content

Commit 6de04ce

Browse files
authored
Add basic check for @customname in property access transform (#1534)
1 parent 4142750 commit 6de04ce

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/transformation/visitors/access.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
captureThisValue,
2424
} from "./optional-chaining";
2525
import { SyntaxKind } from "typescript";
26+
import { getCustomNameFromSymbol } from "./identifier";
2627

2728
function addOneToArrayAccessArgument(
2829
context: TransformationContext,
@@ -108,10 +109,16 @@ export function transformPropertyAccessExpressionWithCapture(
108109
node: ts.PropertyAccessExpression,
109110
thisValueCapture: lua.Identifier | undefined
110111
): ExpressionWithThisValue {
111-
const property = node.name.text;
112112
const type = context.checker.getTypeAtLocation(node.expression);
113113
const isOptionalLeft = isOptionalContinuation(node.expression);
114114

115+
let property = node.name.text;
116+
const symbol = context.checker.getSymbolAtLocation(node.name);
117+
const customName = getCustomNameFromSymbol(symbol);
118+
if (customName) {
119+
property = customName;
120+
}
121+
115122
const constEnumValue = tryGetConstEnumValue(context, node);
116123
if (constEnumValue) {
117124
return { expression: constEnumValue };

test/translation/__snapshots__/transformation.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ escapedCharsInTemplateString = "\\\\ \\0 \\b \\t \\n \\v \\f \\" ' \`"
2424
nonEmptyTemplateString = ("Level 0: \\n\\t " .. ("Level 1: \\n\\t\\t " .. ("Level 3: \\n\\t\\t\\t " .. "Last level \\n --") .. " \\n --") .. " \\n --") .. " \\n --""
2525
`;
2626

27+
exports[`Transformation (customNameWithNoSelf) 1`] = `"TestNamespace.pass()"`;
28+
2729
exports[`Transformation (exportStatement) 1`] = `
2830
"local ____exports = {}
2931
local xyz = 4
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @noSelf */
2+
declare namespace TestNamespace {
3+
/** @customName pass */
4+
function fail(): void;
5+
}
6+
7+
TestNamespace.fail();

0 commit comments

Comments
 (0)