Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(ast-spec): tighter types and documentation for declaration/*#9211

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@Josh-Cena
Copy link
Member

PR Checklist

Overview

Although the types are tighter, it contains no breaking tree shape changes.

Also added a bunch of documentation.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@Josh-Cena!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint.

@netlify
Copy link

netlifybot commentedJun 2, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commitfc730f1
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/667820724fdaf50008c178e7
😎 Deploy Previewhttps://deploy-preview-9211--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (🔴 down 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@nx-cloud
Copy link

nx-cloudbot commentedJun 2, 2024
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commitfc730f1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 fromNxCloud.

Copy link
MemberAuthor

@Josh-CenaJosh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Some comments

/**
* The kind of the export.
*/
// TODO(#1852) - breaking change remove this because it is a semantic error to have it
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

TS now allowsexport type * from

* The kind of the export. Always `value` for default exports.
*/
exportKind:ExportKind;
exportKind:'value';
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Tightened:export type default is not legal

attributes:ImportAttribute[];
declaration:null;
source:null;
specifiers:ExportSpecifier[];
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Removals here are not breaking because these properties are already declared on the base

Comment on lines 44 to 45
// TODO: we should have a way to differentiate between these two cases
specifiers:ImportClause[];
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For the future:specifiers should be able to benull, like howtypeParameters can be both empty ornull

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This won't ever happen, sadly. The ESTree spec is pretty well locked in once defined and so we're stuck with the decisions of the past.

If we change something like this then we're liable to break all sorts of rules that assume it's always defined.

In general we can only ever change our AST extension shapes and the "core" AST is fixed.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hhhh, I forgot this is not TS specific. Fine then.

Comment on lines 6 to 9
/**
* TS1183: An implementation cannot be declared in ambient contexts.
*/
body:undefined;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Tightened: I think this is safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is not correct to do.
The error you cited is asemantic error, not asyntax error.
This means that TS produces an AST for the error and us we do too.

playground

Comment on lines 18 to 26
/**
* TS1040: 'async' modifier cannot be used in an ambient context.
*/
async:false;
declare:true;
/**
* TS1221: Generators are not allowed in an ambient context.
*/
generator:false;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Tightened

Copy link
Member

@bradzacherbradzacherJun 2, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ditto above - the errors are semantic and TS still produces an AST - AND it includes these flags correctly.
So we can't refine these.

playgroubd

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Aren't we supposed to throw on semantic errors? Wasn't fisker fixing some of these before?

*/
moduleReference:EntityName|TSExternalModuleReference;
// TODO(#1852) - breaking change remove this as it is invalid
moduleReference:Identifier|TSQualifiedName|TSExternalModuleReference;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Slight tightening:EntityName is a moving target and doesn't really make sense here. I will continue to fix uses of it. It broke whenThisExpression became a validEntityName.

Comment on lines +61 to +63
exporttypeTSImportEqualsDeclaration=
|TSImportEqualsNamespaceDeclaration
|TSImportEqualsRequireDeclaration;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Changed to union

Comment on lines +114 to +116
// TODO: we emit the wrong AST for `module A.B {}`
// https://github.com/typescript-eslint/typescript-eslint/pull/6272 only fixed namespaces
// Maybe not worth fixing since it's legacy
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Worth pointing out

Comment on lines 94 to 98
exporttypeLetOrConstOrVarDeclaration=
|LetOrVarDeclaredDeclaration
|LetOrVarNonDeclaredDeclaration
|ConstDeclaredDeclaration
|ConstNonDeclaredDeclaration;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The biggest change: madeLetOrConstOrVarDeclaration much stricter.

Copy link
Member

@bradzacherbradzacherJun 2, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The thing that needs to be checked with these changes is likeconst x; - do we have a syntax error or do we produce an AST.

If it's the latter then we can't refine the types as the types have to reflect the AST we output.

For the specific example ofconst x: - we produce an AST so the types must allow the case ofconst with aninit: null.playground

or egconst x! = 1; - we produce an AST so the tyoes nust allow the case.playground

Copy link
Member

@bradzacherbradzacher left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A lot of this is great!
But there's a chunk that I think causes drift between the types and the ASTs we produce.

The important distinction when looking at TS errors is "does TS crash, or does it produce an AST"? In most cases it's the latter.
TS's parser is very forgiving and most errors are semantic errors, not syntactic errors - meaning it produces an AST even if the code has errors.

If TS produces an AST then in most cases we do too. So we need to ensure that the types respect that.

We can always add hard errors to our AST translation step to enforce invariants so that we can change the types! But doing so will be a breaking change for the v8 branch.

Please also add tests for any cases / permutations that you think are missing. More AST snapshots is always good!

@Josh-Cena
Copy link
MemberAuthor

We can always add hard errors to our AST translation step to enforce invariants so that we can change the types! But doing so will be a breaking change for the v8 branch.

Really, even when the AST is nonsense and no program is not going to work? For example#7202 was not breaking

@bradzacher
Copy link
Member

bradzacher commentedJun 3, 2024
edited
Loading

It generally would require a quick chat with the prettier folk. We want to make sure that we're not breaking their experience by throwing on parsable code. If they're okay then we can land it non-breaking.

In the past a lot of the invariants we've encoded were just the invariants that prettier itself encoded (allowing them to delete the checks and make assumptions).

I'm all for a stricter AST transform - just don't want to kill downstream usecases with it.

@Josh-Cena
Copy link
MemberAuthor

#9219,#9220,#9221

@Josh-CenaJosh-Cena marked this pull request as draftJune 3, 2024 05:06
@Josh-CenaJosh-Cena marked this pull request as ready for reviewJune 3, 2024 11:53
@Josh-Cena
Copy link
MemberAuthor

@bradzacher I am splitting normative changes out into separate PRs

bradzacher and JoshuaKGoldberg reacted with heart emoji

@Josh-CenaJosh-Cena changed the titlefeat(ast-spec): tighter types for declaration/*feat(ast-spec): tighter types and documentation for declaration/*Jun 4, 2024
bradzacher
bradzacher previously approved these changesJun 23, 2024
Copy link
Member

@bradzacherbradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@bradzacherbradzacher added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJun 23, 2024
@bradzacher
Copy link
Member

a few lint errors@Josh-Cena otherwise ready to ship

@bradzacherbradzacher added the awaiting responseIssues waiting for a reply from the OP or another party labelJun 23, 2024
@bradzacherbradzacher merged commit5c4a5de intotypescript-eslint:mainJun 23, 2024
@Josh-CenaJosh-Cena deleted the ast-spec-tighten-1 branchJune 23, 2024 13:58
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 1, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@bradzacherbradzacherbradzacher approved these changes

@JoshuaKGoldbergJoshuaKGoldbergAwaiting requested review from JoshuaKGoldberg

Assignees

No one assigned

Labels

1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we mergeawaiting responseIssues waiting for a reply from the OP or another party

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Josh-Cena@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp