feat(es/proposal): add decorators 2023-11 support#11686
Conversation
🦋 Changeset detectedLatest commit: 886afdf The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Binary Sizes
Commit: 4d2cb38 |
a8be077 to
8472435
Compare
There was a problem hiding this comment.
Pull request overview
Adds decoratorVersion: "2023-11" support to SWC with Babel applyDecs2311 parity, including the transform pass, helper registration, test fixtures, and bug fixes to existing 2022-03 decorator output.
Changes:
- Wire
DecoratorVersion::V202311transform pass and_apply_decs_2311helper - Import Babel 2023-11 decorator test fixtures and fix existing 2022-03 output issues
- Fix
ClassNameTdzFolderto useto_id()comparison and skip static-private helper class refs
Reviewed changes
Copilot reviewed 295 out of 578 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/swc/src/config/mod.rs |
Wire V202311 decorator pass instead of todo!() |
crates/swc_ecma_transforms_proposal/src/lib.rs |
Export decorator_2023_11 module |
crates/swc_ecma_transforms_proposal/src/decorator_2023_11.rs |
New pass delegating to decorator_impl |
crates/swc_ecma_transforms_proposal/Cargo.toml |
Add dev-dependencies for tests |
crates/swc_ecma_transforms_base/src/helpers/mod.rs |
Register apply_decs_2311 helper |
crates/swc_ecma_transforms_base/src/helpers/_class_name_tdz_error.js |
Change Error to ReferenceError |
crates/swc_ecma_compat_es2022/src/class_properties/class_name_tdz.rs |
Fix id comparison and skip static-private helper args |
tests/decorators/2023-11-*/** |
New test fixtures |
tests/decorators/2022-03-*/**/output.js |
Updated existing test outputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| if matches!( | ||
| &**sym, | ||
| "_class_static_private_field_destructure" | ||
| | "_class_static_private_field_spec_set" | ||
| | "_class_static_private_field_update" | ||
| | "_class_static_private_method_get" | ||
| | "_class_static_private_field_spec_get" | ||
| ) |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21810dfe37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.is_unresolved_ident(id) { | ||
| self.implicit_globals.insert(id.sym.clone()); | ||
| assign.left = AssignTarget::Simple(SimpleAssignTarget::Member( | ||
| self.global_this_member_expr(id.sym.clone(), id.span), | ||
| )); |
There was a problem hiding this comment.
Avoid rewriting unresolved assignments to globalThis
This branch changes runtime semantics for real user code when decoratorVersion: "2023-11" is enabled: any unresolved assignment like foo = 1 is rewritten to globalThis.foo = 1, so ESM/strict code that should throw ReferenceError now silently mutates globals. Because visit_mut_expr runs over normal program expressions (not just test harness wrappers), this introduces behavior that diverges from JavaScript semantics and Babel output in production transforms.
Useful? React with 👍 / 👎.
Code Review: feat(es/proposal) — Decorators 2023-11 SupportImpressive piece of work bringing full High Priority1. fn is_unresolved_ident(&self, ident: &Ident) -> bool {
matches!(ident.ctxt.as_u32(), 0 | 1)
}This is fragile — 2. Implicit globals rewrite to Medium Priority3. if let Some(value) = prop.value.clone() {The value is immediately overwritten on the next line, so the clone creates a wasted allocation. Using 4. Hard-coded helper name list in 5. 6. Duplicate utility code in Low Priority7. 8. self.state.static_non_field_lhs.drain(..)
.chain(...)
.collect::<Vec<_>>()
.into_iter()The 9. 10. 11. Obscure JS expression in if ((kind & 8) == isStatic && !kindOnly == isField) {
Positives
SummaryThe implementation is solid overall with good Babel parity. The two high-priority items ( 🤖 Generated with Claude Code |
Summary
decoratorVersion: "2023-11"support in SWC with Babel parity.applyDecs2311behavior.What changed
"2023-11"todecoratorVersioninpackages/types/index.ts.DecoratorVersion::V202311incrates/swc/src/config/mod.rs.decorator_2023_11pass and export it from proposal transforms.decorator_impl.rswith 2023-11 specific descriptor encoding and helper call path.applyDecs2311argument ordering and optional args behavior (classDecsHaveThis,instanceBrand,parentClass)._apply_decs_2311helper in transforms base and helpers package.todo!()pass gap.exec.tsfixtures.input.ts, resolve expected file asoutput.tsfirst, fallback tooutput.js.2023-11*decorators fixtures (including assumptions fixtures and options files).Validation
git submodule update --init --recursiveUPDATE=1 cargo test -p swc_ecma_transforms_proposalcargo test -p swc_ecma_transforms_proposalUPDATE=1 cargo test -p swc_ecma_transforms_proposal --test decorators fixture_tests -- --ignoredcargo test -p swc_ecma_transforms_proposal --test decorators fixture_tests -- --ignoredcargo test -p swc_ecma_transforms_basecargo test -p swcfails insource_maptests due missing external node modulesourcemap-validatorin this environment.cargo fmt --all/cargo clippy --all --all-targets -- -D warningsblocked by unrelated pre-existing syntax error incrates/swc_es_parser/tests/bench_parser_inputs.rs.execignored tests requiremocha; unavailable in this environment.