rokucommunity / brighterscript-formatter

A code formatter for BrighterScript (and BrightScript)
MIT License
14 stars 6 forks source link

Breaks BrighterScript regex literal on return statment #81

Open chrisdp opened 6 months ago

chrisdp commented 6 months ago

starting code examples:

function getRegex() as dynamic
    regex = /([\xA9\xAE\x{2000}-\x{3300}\x{1F000}-\x{1FBFF}])/gmi
    return regex
end function

function getRegex() as dynamic
    return /([\xA9\xAE\x{2000}-\x{3300}\x{1F000}-\x{1FBFF}])/gmi
end function

after formatting:

function getRegex() as dynamic
    regex = /([\xA9\xAE\x{2000}-\x{3300}\x{1F000}-\x{1FBFF}])/gmi
    return regex
end function

function getRegex() as dynamic
    return / ([ \ xA9 \ xAE \ x{ 2000 } - \ x{ 3300 } \ x{ 1F000 } - \ x{ 1FBFF }]) / gmi
end function

As you can see the second functions regex is mutated after formatting.

TwitchBronBron commented 6 months ago

Looks like this isn't actually a formatter problem. BrighterScript isn't properly parsing regex expressions in a return statement.

image