Skip to content

@noSelf changed to not affect merged namespaces#689

Merged
Perryvw merged 1 commit intomasterfrom
bugfix/noself-ns-merge
Jul 26, 2019
Merged

@noSelf changed to not affect merged namespaces#689
Perryvw merged 1 commit intomasterfrom
bugfix/noself-ns-merge

Conversation

@tomblind
Copy link
Copy Markdown
Collaborator

fixes #686

Previously, if a namespace or class was decorated with @noSelf, this affected all declarations merged with it. This changes that behavior so, for example, methods in a class merged with a @noSelf decorated namespace will retain their self parameter.

Example:

declare class A {
    method(s: string): void;
}

/** @noSelf */
declare namespace A {
    export function noSelf(s: string): void;
}

declare namespace A {
    export function hasSelf(s: string): void;
}

const c = new A();
c.method("foo");
A.noSelf("bar");
A.hasSelf("baz");

=>

local c = A.new()
c:method("foo")
A.noSelf("bar")
A:hasSelf("baz")

{
value: "anonMethodClassMergedNoSelfNS.method",
definition: `class AnonMethodClassMergedNoSelfNS { method(s: string): string { return s; } }
/** @noSelf */ namespace AnonMethodClassMergedNoSelfNS { export function nsFunc(s: string) { return s; } }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do these actually fail without the transformer change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, because the class method will have it's self stripped due to the namespace using @noSelf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But the call to the function will adjust accordingly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but the assignment test would fail since it would try to assign the method to a type with a self parameter. Also, those tests actually call the function and verify parameters are in correct order. That could probably be moved out to separate tests, but that seems out of scope for this PR.

@Perryvw Perryvw merged commit ef7e027 into master Jul 26, 2019
@Perryvw Perryvw deleted the bugfix/noself-ns-merge branch July 26, 2019 17:02
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.

noSelf for declaration merging

2 participants