Skip to content
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

JavaScript: handle spread syntax #3846

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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