rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
153 stars 47 forks source link

Adds `Alias` Statement #1151

Closed markwpearce closed 2 months ago

markwpearce commented 2 months ago

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 commented 2 months ago

addresses #1113

markwpearce commented 2 months ago

Updated to fixes review comments.