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

Enhancement: Throw errors for invalid UpdateExpressions #7196

Closed
4 tasks done
fisker opened this issue Jul 11, 2023 · 4 comments · Fixed by #7202
Closed
4 tasks done

Enhancement: Throw errors for invalid UpdateExpressions #7196

fisker opened this issue Jul 11, 2023 · 4 comments · Fixed by #7202
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@fisker
Copy link
Contributor

fisker commented Jul 11, 2023

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

parser

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

These expressions should be invalid.

1 ++;

(1)++;
(1)--;

++(1);
--(1);

(1 + 2)++;
(1 + 2)--;

++(1 + 2);
--(1 + 2);

(x + x)++;
(x + x)--;

++(x + x);
--(x + x);
@fisker fisker added enhancement New feature or request triage Waiting for maintainers to take a look labels Jul 11, 2023
@fisker fisker changed the title Enhancement: Throw errors for invalid UpdateExpression Enhancement: Throw errors for invalid UpdateExpressions Jul 11, 2023
@bradzacher
Copy link
Member

These are all semantic errors in TS.
And looking at the eslint playground they're syntax errors in espree - so this seems like a good thing to error on.

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jul 11, 2023
@Josh-Cena
Copy link
Member

Looking into it...

@Josh-Cena
Copy link
Member

Josh-Cena commented Jul 11, 2023

@bradzacher First time working with the parser. I have a few questions.

In #6589 (and other similar PRs), we use our own parser logic to generate the error. But we already have the allowlistSupportedDiagnostics function. Do these two reporting facilities serve different purposes?

Also, should I add test cases in ast-spec? How do I generate snapshots?

@bradzacher
Copy link
Member

We avoid evaluating semantic diagnostics because they are slow to compute (~50ms per file). So instead we write our own logic to catch and report the errors.

The allowlisted errors thing isn't actually used in normal parsing. It's behind an option and I reckon we could probably remove it in a major.

Also, should I add test cases in ast-spec? How do I generate snapshots?

Yup - add test cases there - it's the only place we have them now!

This issue has a good rundown steps to add test cases (we should probably put this in the readme) #6065

Run them with cd packages/ast-spec && yarn test.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants