jcberquist / sublimetext-cfml

CFML (ColdFusion and Lucee) package for Sublime Text
MIT License
115 stars 24 forks source link

Arrow Function Scopes Differ Based on Use of Parentheses Around Single Argument #136

Closed michaelalandawson closed 3 years ago

michaelalandawson commented 3 years ago

I noticed ligatures were not being displayed for my arrow functions in a cfscript block. I found that the difference is caused by the optional parentheses around a single function argument.

When an arrow function has a single argument, the argument does not have to be enclosed in parentheses. Multiple arguments MUST be wrapped in parentheses.

In the example below, the .filter() function does not wrap row in parentheses. The => ligature is not displayed.

The .map() function wraps row in parentheses. The => ligature is displayed as expected.

cfml-syntax-arrow-functions

Here are the scopes for each example:

.filter(row => {})

embedding.cfml
text.html.cfml
source.cfml.script
meta.function-call.method.support.cfml
meta.function-call.parameters.method.support.cfml
keyword.operator.assignment.binary.cfml

.map((row) => {})

embedding.cfml
text.html.cfml
source.cfml.script
meta.function-call.method.support.cfml
meta.function-call.parameters.method.support.cfml
meta.function.anonymous.cfml
meta.function.declaration.cfml
storage.type.function.arrow.cfml
jcberquist commented 3 years ago

Thanks! This should be fixed in the latest version(s). (Once Package Control picks them up.)

michaelalandawson commented 3 years ago

Thank you!

michaelalandawson commented 3 years ago

@jcberquist

Package Control hasn't yet picked up the changes yet, so I can't confirm this issue after your fix, but here are a few more test cases for this issue.

Depending on the existence of the parentheses around the function arguments, the comparison operators in the return statements are displayed differently. Some comparison operators are ligatures, some are not. One is both (third example).

<cfscript>
photos = photos.filter(row => {
    return a == 1;
});

photos = photos.filter((row) => {
    return a == 1;
});

photos = photos.filter(row => {
    return a === 1;
});

photos = photos.filter((row) => {
    return a === 1;
});

photos = photos.filter(row => {
    return a != 1;
});

photos = photos.filter((row) => {
    return a != 1;
});
</cfscript>

cfml-ligatures-in-return-statement

Thanks! mike

michaelalandawson commented 3 years ago

Another bit of info. It appears the issue only affects the first comparison operator it finds. Subsequent operators display correctly and even fix the ligatures in the return statements.

<cfscript>
photos = photos.filter(row => {
    if (a == 1){}
    if (a == 1){}

    return a == 1;
});

photos = photos.filter((row) => {
    if (a == 1){}
    if (a == 1){}

    return a == 1;
});
</cfscript>

cfml-ligatures-in-return-statement

michaelalandawson commented 3 years ago

Just confirmed 0.30.2 fixed all these issues.

Thanks! mike