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

Implement the comma operator #589

Merged
merged 3 commits into from
Jul 29, 2020
Merged

Implement the comma operator #589

merged 3 commits into from
Jul 29, 2020

Conversation

kashparty
Copy link
Contributor

@kashparty kashparty commented Jul 22, 2020

This Pull Request fixes/closes #569 .

It changes the following:

  • Adds the comma operator
  • Changes assignment operator parsing so that the comma operator is not parsed as part of the assignment (explained below)
  • Adds tests

Examples:

var a, b;
b = 10;
a = (b++, b);

// a is now 11, b is now 11
var a, b;
b = 10;
a = (b += 5, b - 1);

// a is now 14, b is now 15
var a, b;
b = 10;
a = (b += 5, b *= 2, b - 1);

// a is now 29, b is now 30

The reason why assignment operator parsing is changed is because otherwise, for cases like the second example, the parser continues to parse the tokens after the comma operator as part of the assignment. For the second example, this would cause the b to be assigned the value of 5, b - 1 (which is b - 1). So I made a minor change to the assignment operator parsing so that it stops parsing when it reaches a comma operator.

@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #589 into master will increase coverage by 0.00%.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #589   +/-   ##
=======================================
  Coverage   71.10%   71.10%           
=======================================
  Files         177      177           
  Lines       11420    11428    +8     
=======================================
+ Hits         8120     8126    +6     
- Misses       3300     3302    +2     
Impacted Files Coverage Δ
boa/src/syntax/ast/op.rs 9.19% <0.00%> (-0.11%) ⬇️
boa/src/syntax/ast/punctuator.rs 2.10% <0.00%> (-0.03%) ⬇️
boa/src/exec/operator/mod.rs 68.83% <66.66%> (+0.61%) ⬆️
boa/src/exec/tests.rs 100.00% <100.00%> (ø)
boa/src/syntax/parser/expression/assignment/mod.rs 70.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbd7dd2...2df2db3. Read the comment docs.

@HalidOdat HalidOdat added enhancement New feature or request execution Issues or PRs related to code execution labels Jul 25, 2020
@HalidOdat HalidOdat added this to the v0.10.0 milestone Jul 25, 2020
@Lan2u Lan2u merged commit 9a3b69f into boa-dev:master Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the "Comma" operator
3 participants