Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 18, 2025

When the source type is JS/JSX, parseSync returns an AST without any of the TS fields present (properties not present at all, not just defined as undefined / null). So to make our type defs match that AST (and also the TS AST which does have these fields), these fields need to be optional.

Copy link
Member Author

overlookmotel commented Mar 18, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@graphite-app graphite-app bot changed the base branch from 03-18-fix_ast_estree_add_directive_field_to_ts_ast to graphite-base/9846 March 18, 2025 05:10
@overlookmotel overlookmotel marked this pull request as ready for review March 18, 2025 05:12
@overlookmotel overlookmotel requested a review from hi-ogawa March 18, 2025 05:12
@overlookmotel
Copy link
Member Author

overlookmotel commented Mar 18, 2025

@hi-ogawa I'm not a TypeScript user, and don't understand the TS syntax well. Can you please check this is correct?

@graphite-app graphite-app bot force-pushed the 03-18-fix_ast_estree_make_ts-only_fields_optional_in_ts_type_defs branch from d3af692 to ca81b25 Compare March 18, 2025 05:28
@graphite-app graphite-app bot force-pushed the graphite-base/9846 branch from 9676cb8 to 3f858c4 Compare March 18, 2025 05:28
@graphite-app graphite-app bot changed the base branch from graphite-base/9846 to main March 18, 2025 05:29
@graphite-app graphite-app bot force-pushed the 03-18-fix_ast_estree_make_ts-only_fields_optional_in_ts_type_defs branch from ca81b25 to 6db8335 Compare March 18, 2025 05:29
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Makes sense to me 👍 This can potentially give inconvenience for users expecting typescript estree types, which has some fields strictly defined (for examples Class.implements array https://github.com/typescript-eslint/typescript-eslint/blob/3efd99e954d1749225d65b774cfb3650a54ff083/packages/ast-spec/src/base/ClassBase.ts#L50), but this typing is more correct as oxc types.

Additionally, I think we can add jsdoc on each ts-only fields, so it's easier to tell which fields can be assumed to be strictly defined when users are exclusively using astType: 'ts' parser.

@hi-ogawa hi-ogawa added the 0-merge Merge with Graphite Merge Queue label Mar 18, 2025
Copy link
Contributor

hi-ogawa commented Mar 18, 2025

Merge activity

  • Mar 18, 3:39 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 18, 3:39 AM EDT: A user added this pull request to the Graphite merge queue.
  • Mar 18, 3:53 AM EDT: A user merged this pull request with the Graphite merge queue.

When the source type is JS/JSX, `parseSync` returns an AST without any of the TS fields present (properties not present at all, not just defined as `undefined` / `null`). So to make our type defs match that AST (and also the TS AST which *does* have these fields), these fields need to be optional.
@graphite-app graphite-app bot force-pushed the 03-18-fix_ast_estree_make_ts-only_fields_optional_in_ts_type_defs branch from 6db8335 to 7b711f0 Compare March 18, 2025 07:46
@graphite-app graphite-app bot merged commit 7b711f0 into main Mar 18, 2025
14 checks passed
@graphite-app graphite-app bot deleted the 03-18-fix_ast_estree_make_ts-only_fields_optional_in_ts_type_defs branch March 18, 2025 07:53
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 18, 2025
@overlookmotel
Copy link
Member Author

overlookmotel commented Mar 18, 2025

Thanks for reviewing. We could also codegen 2 sets of types for JS-only and with-TS ASTs. As we're codegen-ing everything, that wouldn't be too much work.

But I don't know if it'd be an improvement or not, because parseSync returns one or the other depending on input. That's not possible to statically type, I don't think.

@hi-ogawa
Copy link
Contributor

Thanks for reviewing. We could also codegen 2 sets of types for JS-only and with-TS ASTs. As we're codegen-ing everything, that wouldn't be too much work.

But I don't know if it'd be an improvement or not, because parseSync returns one or the other depending on input. That's not possible to statically type, I don't think.

I don't think it's necessary right now, but just providing ts ast types can be useful without coupling with parseSync since that allows using that type mostly and only need program as any as TsProgram in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants