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: refactor to split AST specification out as its own module#2911

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
bradzacher merged 1 commit intomasterfromseparate-spec
May 4, 2021

Conversation

@bradzacher
Copy link
Member

@bradzacherbradzacher commentedJan 2, 2021
edited
Loading

Reference issue:#2726

This PR is the basis for a big cleanup and reorganisation of the AST.
This first step takes the filetypes/src/ts-estree.ts and splits it up in its entirety.
This file was a monolith at 1700 lines - meaning it was a pain to organise and manage, and there was no way to isolate/restrict certain things (aside from adding comments).

This PR should ultimately be a no-op - there should be no breaking changes here.
I did fix up a number of types which I found when organising files into their folders.

Whilst this PR ultimately creates more LOC, the isolation enables a few things:

  • By splitting the AST into its own module, it's isolated so easier to manage / govern
  • By splitting each AST node into its own folder we can cleanly document and link to individual node specs
  • By grouping nodes decls by folder, it's easier to inspect the types to validate unions are correct.
    • I found a number of invalid nodes in unions in this PR which have been fixed.
  • In a future PR we can:

TODO:

  • separate all types from the monolithic file
  • add a test to ensure that all nodes are included in theNodes union
  • add a build step to copy a bundled declaration file to/types
  • add a build doc generation step to allow for nice documentation on website
  • add fixtures for every single node type
    • Will do this separately - #TODO

@bradzacherbradzacher added the refactorPRs that refactor code only labelJan 2, 2021
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@bradzacher!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@bradzacherbradzacher added the DO NOT MERGEPRs which should not be merged yet labelJan 2, 2021
@bradzacherbradzacherforce-pushed theseparate-spec branch 4 times, most recently from2be09bf tof8b983bCompareJanuary 2, 2021 21:26
@bradzacherbradzacher changed the base branch frommaster tounion-intersection-sortingJanuary 3, 2021 20:34
@bradzacherbradzacherforce-pushed theunion-intersection-sorting branch fromab8195c to56232c8CompareJanuary 4, 2021 00:07
Base automatically changed fromunion-intersection-sorting tomasterJanuary 4, 2021 01:12
@codecov
Copy link

codecovbot commentedJan 4, 2021
edited
Loading

Codecov Report

Merging#2911 (a5f8933) intomaster (209f6d0) willdecrease coverage by0.00%.
The diff coverage is44.44%.

@@            Coverage Diff             @@##           master    #2911      +/-   ##==========================================- Coverage   92.86%   92.85%   -0.01%==========================================  Files         318      318                Lines       11048    11048                Branches     3129     3128       -1     ==========================================- Hits        10260    10259       -1- Misses        350      352       +2+ Partials      438      437       -1
FlagCoverage Δ
unittest92.85% <44.44%> (-0.01%)⬇️

Flags with carried forward coverage won't be shown.Click here to find out more.

Impacted FilesCoverage Δ
...lugin-internal/src/rules/plugin-test-formatting.ts81.75% <ø> (ø)
...es/eslint-plugin/src/rules/no-loss-of-precision.ts91.66% <ø> (ø)
...slint-plugin/src/rules/no-unnecessary-condition.ts97.17% <ø> (ø)
...ages/eslint-plugin/src/rules/prefer-regexp-exec.ts100.00% <ø> (ø)
.../src/rules/sort-type-union-intersection-members.ts92.53% <ø> (ø)
packages/scope-manager/src/scope/ScopeBase.ts91.12% <37.50%> (-0.60%)⬇️
packages/typescript-estree/src/convert.ts98.24% <100.00%> (ø)

@armano2
Copy link
Collaborator

few notes:

  1. jsx should be in its own group, and not a "special"
  2. there should be separate group for Declarations and Statements -> Declarations are Statements

we could actually follow a lead of typescript or estree on this eg,
https://github.com/estree/estree/blob/390a050fd2d6a7b69688f1434e0929d7c7455d05/es5.md#statements

generally i like this idea, but i feel like this is a little to granular, maybe if we group them a little better we can have set of files that can contain multiple definition

@bradzacher
Copy link
MemberAuthor

jsx should be in its own group, and not a "special"

sounds like a good idea

there should be separate group for Declarations and Statements -> Declarations are Statements
we could actually follow a lead of typescript or estree on this

This "grouping" was based on the union types we had declared in the old mega file.
We didn't have a "declaration" union type - onlyDeclarationStatement (which didn't include variable declarations, hence I marked it for removal - it felt like a useless union)

We can nest/organise however we like!

maybe if we group them a little better we can have set of files that can contain multiple definition

Could you provide an example of what you mean by this?

but i feel like this is a little to granular

I wanted each node to have its own folder so that everything is isolated.

Eventually I want to move all the fixtures into this folder as well, and orgnaise them appropriately (even duplicate them as necessary).

The idea is that this "package" will document the types a node adheres to, and includes the examples that can generate each type.

Ideally even going as far as attempting to do every combination for a child.
EG if a property on a node has type "Expression", we should have one fixture which validates each expression type is valid.

It'll be verbose AF, but it ensures our spec is correct, and it provides clear documentation for consumers (and provides great examples for people to borrow and test against).

@armano2
Copy link
Collaborator

there is one more thing that bothers me, new package, why do we need it, why not just merge it with types, as thats what this is, types

@bradzacher
Copy link
MemberAuthor

bradzacher commentedFeb 21, 2021
edited
Loading

why not just merge it with types, as thats what this is, types

For the moment, this is just types.

But as mentioned - I want to move the fixtures here, and I want to add markdown docs to describe what a node is and what it represents.

I plan on this being a private package, and using a build step to keep the published types in thetypes package.

@armano2
Copy link
Collaborator

armano2 commentedFeb 21, 2021
edited
Loading

moving fixtures is not really good idea, as we should not ask everyone who wants to use this package to include them in their build

this package is included in types

@bradzacher
Copy link
MemberAuthor

bradzacher commentedFeb 21, 2021
edited
Loading

To clarify.

This PR should result in no actual change in the external API(s).

ast-spec would be aprivate package that is not published to NPM.
It will contain the following:

  • types for the AST (this PR)
  • markdown docs explaining the AST
  • fixtures

types will contain the types.
via a build step, we will bundle the types fromast-spec and copy them into thetypes package.
This way the fixtures, documentation, and folder structure are kept private and not published, and that way we don't need to publish another package for no reason.

armano2 reacted with rocket emoji

@bradzacherbradzacherforce-pushed theseparate-spec branch 6 times, most recently from07860e0 tof69c8efCompareMarch 31, 2021 20:03
@bradzacherbradzacher removed the DO NOT MERGEPRs which should not be merged yet labelMar 31, 2021
@bradzacherbradzacher marked this pull request as ready for reviewMarch 31, 2021 22:17
@bradzacher
Copy link
MemberAuthor

@armano2 - if you wanted to take another eyeball - this is in a good state to merge as is.
We can follow up with adding docs and fixtures in future PRs.

Fixes#2726Fixes#2912This PR is the basis for a big cleanup and reorganisation of the AST.This first step takes the file `types/src/ts-estree.ts` and splits it up in its entirety.This file was a monolith at 1700 lines - meaning it was a pain to organise and manage, and there was no way to isolate/restrict certain things (aside from adding comments).This PR should ultimately be a no-op - there should be no breaking changes here.I did fix up a number of types which I found when organising files into their folders.Whilst this PR ultimately creates more LOC, the isolation enables a few things:- By splitting the AST into its own module, it's isolated so easier to manage / govern- By splitting each AST node into its own folder we can cleanly document and link to individual node specs- By grouping nodes decls by folder, it's easier to inspect the types to validate unions are correct.    - I found a number of invalid nodes in unions in this PR which have been fixed.- In a future PR we can:    - Add lint rule(s) to validate unions are correct (eg ensure all `Expression` types are included in the `Expression` union).    - Easily add documentation about the node without cluttering things up    - Colocate fixtures/snapshots with the node specs to document the cases that we expect a node to show up    - Colocate the conversion logic here so that it's easier to validate that the spec and the conversion logic are in sync        - This will make it much easier to implement and maintain#1852
@bradzacherbradzacher merged commit25ea953 intomasterMay 4, 2021
@bradzacherbradzacher deleted the separate-spec branchMay 4, 2021 23:15
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJun 4, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@armano2armano2Awaiting requested review from armano2

Assignees

No one assigned

Labels

refactorPRs that refactor code only

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@bradzacher@armano2

[8]ページ先頭

©2009-2025 Movatter.jp