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

Bitwise predence not considered. #1781

Closed
PhucXDoan opened this issue Jun 3, 2021 · 1 comment · Fixed by #1783
Closed

Bitwise predence not considered. #1781

PhucXDoan opened this issue Jun 3, 2021 · 1 comment · Fixed by #1783
Assignees
Labels
Milestone

Comments

@PhucXDoan
Copy link

Describe the bug
The precedence of bitwise operations (at least for NOT) is not taken into account when compiling. Wrapping parentheses around an expression in the source code does nothing in the compiled Javascript.

Input code (Typescript)

const n = ~~(Math.PI * 10) // n = 31; Multiplication is done first and the then double bitwise NOT operation.

Output code (Javascript)

var n=~~Math.PI*10; // n = 30; The double bitwise NOT operation is done first and then multiplication.

Config

{
	"include"         : ["./ts/*.ts"],
	"compilerOptions" :
	{
		"lib"                          : ["ESNext", "DOM"],
		"target"                       : "ES6",
		"outDir"                       : "./js/",
		"alwaysStrict"                 : true,
		"noImplicitAny"                : true,
		"removeComments"               : true,
		"preserveConstEnums"           : true,
		"watch"                        : true,
		"strictNullChecks"             : true,
		"strictFunctionTypes"          : true,
		"strictPropertyInitialization" : true,
		"strictBindCallApply"          : true,
		"strict"                       : true,
		"pretty"                       : true,
		"noImplicitReturns"            : true,
		"noEmit"                       : true
	}
}

Expected behavior
The parenthesis around the expression should remain and not be omitted in compilation.

Version
The version of @swc/core: 1.2.59

@PhucXDoan PhucXDoan added the C-bug label Jun 3, 2021
@kdy1 kdy1 self-assigned this Jun 4, 2021
@kdy1 kdy1 added this to the v1.2.60 milestone Jun 4, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jun 4, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jun 4, 2021
@kdy1 kdy1 mentioned this issue Jun 4, 2021
2 tasks
@kdy1 kdy1 closed this as completed in #1783 Jun 5, 2021
kdy1 added a commit that referenced this issue Jun 5, 2021
swc_ecma_transforms_base:
- `fixer`: Wrap operand of a unary expression if it's a binary expression. (#1781, #1789)

swc_ecma_transforms_module:
 - Allow multiple `export *` even if it has the same item. (#1780)
kdy1 added a commit to kdy1/swc that referenced this issue Jul 19, 2021
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 24, 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 24, 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