oxc-project / oxc-project/backlog
AST: Correct ESTree spans for `ImportMeta` and `NewTarget`
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Parent: #210
oxc-project/oxc#24557 replaced MetaProperty with 2 new types ImportMeta and NewTarget.
oxc-project/oxc#24775 followed up with a fix to spans, aiming to handle programmatically-created nodes with empty spans (0, 0).
The idea is that it's redundant to store individual spans for the import and meta keywords in import.meta, because they can be derived from the span of the whole "phrase" import.meta.
@camc314 and I discussed an unintended downside of this change which is it doesn't handle well when some other code is transformed to import.meta e.g.:
x.y()is transformed toimport.meta.- The
ImportMetanode has the original span of thex.y()expression. - The spans for
importandmetakeywords in ESTree AST are nonsense because calculating the keyword spans from the span ofx.y()makes no sense. - This could screw up source maps if a JS-side library producing a source map looks at the spans on
importandmetakeywords.
This is an edge case, but:
- We're trying to stabilize the AST and move towards locking it (1.0), so we should IMO try to get it exactly right.
- This kind of problem will likely come up again in more consequential ways in other parts of AST, so we may do well to figure it out now.
One way to handle this without bloating ImportMeta with 2 x extra Spans:
pub struct ImportMeta {
pub node_id: Cell<NodeId>,
pub span: Span,
pub is_raw: bool,
}
- Parser sets
is_raw: true->start&endset onimportandmetakeywords in ESTree AST. - Transformer sets
is_raw: false(when creating a newImportMeta) -> keywords receive no span (0, 0) in ESTree AST.
We don't give people option to set individual spans for the keywords - but that's likely not required because import.meta is only meaningful as a complete "unit". But we do get correct spans in ESTree AST, and it only costs 1 bool (free, since ImportMeta has 4 padding bytes spare anyway).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the ImportMeta and NewTarget definitions, then find the parser and transformer construction sites mentioned in the issue. Trace how these nodes become ESTree AST spans. Done means parser-created import.meta keywords retain their spans, while transformed ImportMeta keywords receive (0, 0), without adding individual keyword spans.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100