Skip to content

feat: re-order fields#37

Merged
overlookmotel merged 11 commits intomainfrom
05-28-feat_re-order_fields
May 28, 2025
Merged

feat: re-order fields#37
overlookmotel merged 11 commits intomainfrom
05-28-feat_re-order_fields

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 28, 2025

Re-order fields of all AST nodes in snapshots according to defined field orders derived from Oxc.

The field orders we're using come from the field order in Oxc's Rust types, which have been put in visitation order. This matches the visitation order of TS-ESLint, with the following exceptions:

  • ExportSpecifier
  • TSImportType
  • TSIndexedAccessType
  • TSMethodSignature
  • TSPropertySignature
  • TSTypePredicate

In these types, TS-ESLint's visitorKeys has the wrong visitation order, because it does not visit fields in source order.

The JSON file specifying field orders was produced by codegen in https://github.com/oxc-project/oxc/tree/overlookmotel/estree-field-orders (commit oxc-project/oxc@fcb73d8).

Copy link
Member Author

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

@overlookmotel overlookmotel marked this pull request as ready for review May 28, 2025 21:55
@overlookmotel overlookmotel merged commit e6d4a89 into main May 28, 2025
2 checks passed
@overlookmotel overlookmotel deleted the 05-28-feat_re-order_fields branch May 28, 2025 21:55
graphite-app bot pushed a commit to oxc-project/oxc that referenced this pull request May 29, 2025
Re-order fields in ESTree and TS-ESTree ASTs to be in visitation order (which is the order in which they're defined in Rust types).

This does not align with either Acorn or TS-ESLint, but for the reasons discussed in #9705 (comment), I feel this isn't a concern. The field order doesn't matter much per se, only that it's consistent, and this change has other benefits - it will make it simpler to build a visitor which visits fields in the correct order, and allows adding other parsers to `acorn-test262` in order to produce test cases for decorators.

Visitation order aligns with TS-ESLint except for the following types:

* `ExportSpecifier`
* `TSImportType`
* `TSIndexedAccessType`
* `TSMethodSignature`
* `TSPropertySignature`
* `TSTypePredicate`

In these 6 cases, TS-ESLint's `visitorKeys` has the wrong visitation order, because it does not visit fields in source order. I will open an issue and hopefully they can fix.

This PR also bumps `acorn-test262` to include oxc-project/estree-conformance#37 which re-orders the fields in fixture snapshots to match the new field order here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant