Skip to content

Add basic check for customName in property access transform#1534

Merged
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
aabajyan:custom-name-in-access
Feb 7, 2024
Merged

Add basic check for customName in property access transform#1534
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
aabajyan:custom-name-in-access

Conversation

@aabajyan
Copy link
Contributor

@aabajyan aabajyan commented Feb 6, 2024

While simple name changes work as expected names with nested methods will still behave like string literals.
I will try to find a solution for this as well, but since this is my first commit I want to make this as simple as possible.

partially fixes #1528

const type = context.checker.getTypeAtLocation(node.expression);
const isOptionalLeft = isOptionalContinuation(node.expression);

// FIXME: Stuff like very.nested.call won't work, because
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with

/** @noSelf */
interface Nested {
    /** @customName pass */
    fail(): void;
}

declare namespace TestNamespace {
    const nested: Nested;
}

TestNamespace.nested.fail();

And

/** @noSelf */
interface Nested {
    /** @customName pass */
    fail(): void;
}

declare const TestObject: {
    nested: Nested;
};

TestObject.nested.fail();

And they both seem to work fine with custom name. Can you give an example test case where it doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

/** @noSelf */
declare namespace TestNamespace {
    /** @customName very.nested.call */
    function fail(): void;
}

TestNamespace.fail();

Will output:

TestNamespace["very.nested.call"]()

Instead of:

TestNamespace.very.nested.call()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** @customName very.nested.call */ Is not really intended behavior for customName at the moment.

I would prefer if you remove this FIXME comment and just deliver this code as it does seem to resolve the original bug. I think allowing nested customName values might be a nice follow-up feature for a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing

@Perryvw Perryvw merged commit 6de04ce into TypeScriptToLua:master Feb 7, 2024
@aabajyan aabajyan deleted the custom-name-in-access branch February 7, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@customName is ignored if @noSelf is applied

2 participants