Skip to content

Commit

Permalink
JavaScript: skip spread operators
Browse files Browse the repository at this point in the history
Related to universal-ctags#3435.

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Nov 16, 2023
1 parent 1039940 commit 18fb843
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Units/parser-javascript.r/spread-operator.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
8 changes: 8 additions & 0 deletions Units/parser-javascript.r/spread-operator.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
foo input.js /^const embedded = { foo: 'bar' }$/;" p variable:embedded
embedded input.js /^const embedded = { foo: 'bar' }$/;" v
baz input.js /^ baz: 'fox',$/;" p variable:something
something input.js /^const something = {$/;" v
mapGetters input.js /^const mapGetters = function() {}$/;" f
computed input.js /^const computed = {$/;" C
fn input.js /^ fn: () => { \/* doing something *\/ },$/;" m variable:FNO
FNO input.js /^const FNO = {$/;" v
22 changes: 22 additions & 0 deletions Units/parser-javascript.r/spread-operator.d/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// This test input is based on the comment submitted by AdrienGiboire in #3435
//

const embedded = { foo: 'bar' }
const something = {
...embedded,
baz: 'fox',
}

const mapGetters = function() {}
const computed = {
...mapGetters([
'getAsylumAssistant',
'getModel',
'getType',
]),
}

const FNO = {
fn: () => { /* doing something */ },
}
6 changes: 6 additions & 0 deletions parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,12 @@ static bool parseMethods (tokenInfo *const token, int class_index,

deleteToken (saved_token);
}
else if (isType (token, TOKEN_DOTS))
{
/* maybe spread operator. Just skip the next expression. */
findCmdTerm(token, true, true);
continue;
}

if (! isType (token, TOKEN_KEYWORD) &&
! isType (token, TOKEN_SEMICOLON))
Expand Down

0 comments on commit 18fb843

Please sign in to comment.