Skip to content

Commit

Permalink
JavaScript: handle spread syntax
Browse files Browse the repository at this point in the history
With this change, the parser skip "..." and the subsequent expression.

ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

Related to universal-ctags#3435.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Nov 17, 2023
1 parent d5aa12d commit 014fbcd
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 014fbcd

Please sign in to comment.