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

error on 'x++.toString()' #1208

Open
strager opened this issue Mar 4, 2024 · 4 comments · May be fixed by #1212
Open

error on 'x++.toString()' #1208

strager opened this issue Mar 4, 2024 · 4 comments · May be fixed by #1212
Assignees
Labels
false negative Bug: quick-lint-js accepts syntatically-invalid code

Comments

@strager
Copy link
Collaborator

strager commented Mar 4, 2024

x++.toString() seems to be invalid JS. Reject it and suggest parentheses.

@strager strager added the false negative Bug: quick-lint-js accepts syntatically-invalid code label Mar 4, 2024
@msharipov
Copy link
Contributor

@strager Could you please assign this to me?

@msharipov
Copy link
Contributor

msharipov commented Mar 14, 2024

@strager This seems to be a more general issue when using a "member of" dot operator or a ?. directly after a postfix operator. For example, this also results in an error:

let x = 3;
console.log((x--).valueOf());  // Works fine, prints "3"
console.log((x--).constructor);  // Works fine, prints "ƒ Number()"
console.log((x--)?.constructor);  // Works fine, prints "ƒ Number()"
console.log(x--.valueOf()); // Invalid syntax
console.log(x--.constructor); // Invalid syntax
console.log(x--?.constructor); // Invalid syntax

msharipov added a commit to msharipov/quick-lint-js that referenced this issue Mar 14, 2024
This diagnostic reports an error when `.` or `?.` directly follows `++`
or `--`. Error message recommends adding parentheses around the postfix
expression. This closes issue quick-lint#1208.

quick-lint#1208
@msharipov msharipov linked a pull request Mar 14, 2024 that will close this issue
@msharipov
Copy link
Contributor

@strager This PR fixes the issue. I am also going to look for any other operators that cause a similar issue when placed after ++ or --. Let me know if you want me to add anything to this.

@msharipov
Copy link
Contributor

@strager After poking around a bit, it looks like there are a number of operators and other tokens that cause a syntax error when placed after -- and ++. Many of these are not properly reported by quick-lint-js. The following is what I've managed to find, though it is unlikely to be an exhaustive list.


Current quick-lint-js Output
Nothing
x++ (y);
x++ [y];
x++ .y;
x++ ?.y;

Current quick-lint-js Output
E0027: missing semicolon after statement
x++ new Type();
x++ ++y;
x++ --y;
x++ !y;  // Also reports E0261
x++ typeof y;
x++ void(y);
x++ delete(y);
x++ yield y;
x++ yield* y;

Current quick-lint-js Output
E0054: unexpected token
x++ ~y;
x++ : y;  // Also reports E0027
x++ ...y;

Current quick-lint-js Output
E0020: invalid expression left of assignment
x++ = y;
x++ += y;
x++ -= y;
x++ *= y;
x++ **= y;
x++ /= y;
x++ %= y;
x++ <<= y;
x++ >>= y;
x++ >>>= y;
x++ &= y;
x++ |= y;
x++ ^= y;
x++ &&= y;
x++ ||= y;

Current quick-lint-js Output
E0151: invalid function parameter
x++ => y;

The cases that report E0020, E0027, and E0151 make sense, while the rest probably need to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false negative Bug: quick-lint-js accepts syntatically-invalid code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants