refactor(ast)!: replace ExportDefaultDeclaration exported field with default_span#12803
Closed
overlookmotel wants to merge 1 commit intomainfrom
Closed
Conversation
Member
Author
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
CodSpeed Instrumentation Performance ReportMerging #12803 will not alter performanceComparing Summary
|
…ith `default_span`
4af75b4 to
9ceca68
Compare
camc314
approved these changes
Aug 4, 2025
graphite-app bot
pushed a commit
that referenced
this pull request
Aug 5, 2025
…12808) We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`. The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again. After #12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all. So we can remove the whole field. This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more! It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal! (alternative to #12803)
Member
Author
|
Superceded by #12808. |
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
…xc-project#12808) We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`. The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again. After oxc-project#12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all. So we can remove the whole field. This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more! It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal! (alternative to oxc-project#12803)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

We currently store the
defaultkeyword forExportDefaultDeclarationas aModuleExportName. This is overkill because the name is always, by definition,default.Replace this field with
default_span: Spanwhich is enough to provides the only useful information.This reduces size of
ExportDefaultDeclarationfrom 80 bytes to 32. That has very limited impact, because each file can only have 1export defaultstatement. But still... less is more!Ideally we'd get rid of this field entirely. Span of
defaultkeyword doesn't appear in ESTree AST, is not used in linter, and is ignored in codegen.Only reason this span is present in AST is: parser records it temporarily in AST, so that
ModuleRecordBuildercan pull it out again later to add it to module record. There is probably a way to achieve the same thing without using AST as a temporary storage location.UPDATE: I found a way to remove the field entirely: #12808.