Skip to content

Improved Lambda Argument Handling #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2016

Conversation

amadeus
Copy link
Collaborator

@amadeus amadeus commented Apr 20, 2016

This is a first pass at adding back in the jsArrowFuncArgs matching when using parenthesis.

It should mostly fix issues specified at #378 and #364.

I have been using the following test file to ensure syntax highlighting seems to work, I would be open to more test cases to add to this to ensure things are working.

/* eslint vars-on-top:0 */
function test1({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = {}) {
    console.log(size, cords, radius);
}

var test2 = function(test2arg = () => {
    return true;
}) {

};

var test3 = function(){};

var test4 = (test4arg, { test4arg2 = 2 }) => {};

test3((arg) => {
    var test5 = (test5arg) => {
    };
});

test3((test6arg = 2 + 2, { test6arg2: x, test6arg3: y }) => {
});

test3((test7arg) => {});

test3(test8arg => {});

var test9 = function(x, y){
    var tub = () => {};
};

var test10 = (test10arg, /* test comment */ test10arg2 = () => {}) => {};

var test11 = {};

test3.then(
    (result) => {
        var test12 = (test12arg = { test12arg2: [] }) => {};
        this.send(result);
    }
);

test3('_.blind()', () => {});

test3((test13arg, test13arg2) => test4.exists(test13arg, (test14arg) => {
    return true;
}));

// Checking syntax highlighting on the line before this, should be empty

We don't handle this file perfectly, but we do breakdown 'gracefully' (meaning we do not show error parenthesis groups).

Current issues I haven't been able to figure out:

  • How to handle parenthesis inside the jsArrowFuncArgs match
  • Handle a multiline version of jsArrowFuncArgs

I have done a bit of research into other editors like Sublime and Atom, and none can even handle this file completely correctly, and they ALL break with the 2 issues I mentioned above (at least their default syntax highlighting, I never explored plugins that may do things better).

@davidchambers
Copy link
Collaborator

Nice work, @amadeus! I'm pleased to see how minimal the changes are.

@amadeus
Copy link
Collaborator Author

amadeus commented Apr 20, 2016

I've gone ahead and push a copy of this branch to this repo, so it's easier for you guys to test:

https://github.com/pangloss/vim-javascript/tree/lambda-experiments

@amadeus amadeus force-pushed the lambda-experiments branch from 9b58fcc to b9feef0 Compare April 22, 2016 04:12
@alexlafroscia
Copy link

alexlafroscia commented Apr 22, 2016

@amadeus I tried out that branch, it fixed some issues I was seeing around highlighting getting messed up when using "fat arrow" functions, in cases where the parameters are surrounded in parenthesis. Stuff like this:

myFunction((foo) => {
  return foo.bar;
});

Where the ) on the last line would be highlighted in bright red, as if it was an error.

Thanks for the fix!

@amadeus amadeus merged commit 48263c8 into pangloss:develop Apr 22, 2016
@amadeus amadeus deleted the lambda-experiments branch April 22, 2016 22:08
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.

3 participants