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

Unary operator used immediately before exponentiation expression #2191

Closed
mischnic opened this issue Aug 31, 2021 · 1 comment · Fixed by #2222
Closed

Unary operator used immediately before exponentiation expression #2191

mischnic opened this issue Aug 31, 2021 · 1 comment · Fixed by #2222
Labels
Milestone

Comments

@mischnic
Copy link
Contributor

Describe the bug

If a unary operator is used as the first operand of an exponentiation, then that operand needs to be wrapped in parentheses.

Input code

function uint16ToFloat64(h) {
  return (-1) ** h;
}
exports.uint16ToFloat64 = uint16ToFloat64;

Config

{
	"env": {}
}

and "browserslist": "Chrome 90"

Expected behavior
swc output = input

Current behaviour

function uint16ToFloat64(h) {
    return -1 ** h;
}
exports.uint16ToFloat64 = uint16ToFloat64;

results in

    return -1 ** h;
           ^^^^^

SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence

Version
The version of @swc/core: 1.2.83

Additional context
Came up in parcel-bundler/parcel#6525

@mischnic mischnic added the C-bug label Aug 31, 2021
@kdy1 kdy1 modified the milestones: v1.2.86, v1.2.85 Sep 3, 2021
@kdy1 kdy1 mentioned this issue Sep 9, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Sep 9, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Sep 9, 2021
@kdy1 kdy1 closed this as completed in #2222 Sep 9, 2021
kdy1 added a commit that referenced this issue Sep 9, 2021
swc_ecma_parser:
 - Don't panic on `typeof import(T)`. (#2198)
 - Fix parsing of ternary. (#2196)

swc_ecma_transforms_base:
 - `fixer`: Handle unary in lhs of an exponentation expression. (#2191)

swc_ecma_transforms_compat:
 - Use variable for `this` in arrow expressions. (#2212)

swc_ecma_visit:
 - Add a trait `InjectVars`.

node_swc:
 - Increease recursion limit while deserializing. (#2223)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 22, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants