ProjectEvergreen / ProjectEvergreen/wcc
find more idiomatic way to detect `attachShadow` usage in the JSX compiler
A pull request for this has already been merged.
- #276 by @thescientist13 — merged
- Dominant language
- JavaScript
- Stars
- 126
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
Current State
Currently, the JSX compiler does a naive check to detect if Declarative Shadow DOM is being used in a custom element definition
hasShadowRoot = moduleContents.slice(node.body.start, node.body.end).indexOf('this.attachShadow(') > 0;
The main downside to this is that it's a naive check of the contents, which could include comments. It should be more reliant on the AST to find a real usage of the attachShadow call
Desired State
It should use the AST and walk method to find this. Just spit balling...
hasShadowRoot = node.children.some((c) => {
// find `attachShadow` using the AST instead
})
Additional Context
No response
Contributor guide
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 with the JSX compiler code containing the moduleContents.slice(...).indexOf('this.attachShadow(') check, then inspect the available AST walk methods and node.children structure. Done means detection is based on a real attachShadow call in the AST, so matching text in comments does not count.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100