Skip to content

Adds Alias Statement#1151

Merged
TwitchBronBron merged 14 commits into
release-1.0.0from
alias_statement
May 6, 2024
Merged

Adds Alias Statement#1151
TwitchBronBron merged 14 commits into
release-1.0.0from
alias_statement

Conversation

@markwpearce

Copy link
Copy Markdown
Collaborator

This is pretty cool!

alias provides a way to work around variable name shadowing... but as a side effect, it also give a way to shorthand just about any property/function you want.

alias get2 = get

namespace http
    'Do an HTTP request
    sub get()
        print get2.aa().data 'using `get2` aliased symbol here. it's now clear which item we intended to use
    end sub
end namespace

namespace get
    function aa()
        return {
            data: "abc"
        }
    end function
end namespace

transpiles to

sub http_get()
    print get_aa().data
end sub

sub get_aa()
    return {
        data: "abc"
    }
end sub

it also allows this ... which is cool?:

alias lc = lcase
alias co = createObject

sub getModelTypeLower()
   lc(co("roDeviceInfo").getModelType())
end sub

it also allows this ... which is also cool?:

alias abgdz = alpha.beta.gamma.delta.zeta

sub foo()
   print abgdz.someConst
end sub

@markwpearce markwpearce added this to the v1.0.0 milestone May 2, 2024
@markwpearce

Copy link
Copy Markdown
Collaborator Author

addresses #1113

@TwitchBronBron TwitchBronBron left a comment

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.

Looks great! Just a few small things

Comment thread docs/variable-shadowing.md Outdated
Comment thread src/DiagnosticMessages.ts Outdated
Comment thread src/files/BrsFile.spec.ts
@markwpearce

Copy link
Copy Markdown
Collaborator Author

Updated to fixes review comments.

@markwpearce
markwpearce requested a review from TwitchBronBron May 6, 2024 12:32
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.

2 participants