Repository navigation
feat(transpiler): implement TC39 standard ES decorators lowering #26436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
499d2d3
feat(transpiler): implement TC39 standard ES decorators lowering
Jarred-Sumner e0c5e03
refactor(transpiler): extract decorator lowering into lowerDecorators…
Jarred-Sumner bff4726
[autofix.ci] apply automated fixes
autofix-ci[bot] 90d20c6
fix(test): copy esbuild decorator tests into test dir for CI
Jarred-Sumner f621bab
fix(transpiler): address review feedback for ES decorators
Jarred-Sumner 3048ff4
fix(test): clean up esbuild decorator test boilerplate
Jarred-Sumner 3f89145
fix(test): update snapshot for cyclic-imports-async-bundler test
Jarred-Sumner 02d6a87
fix(test): update snapshots and add experimentalDecorators to legacy …
Jarred-Sumner 0131156
fix(transpiler): fix export default class crash and accessor ! parsin…
Jarred-Sumner c5f6b24
fix(transpiler): improve decorator lowering robustness
Jarred-Sumner 20c47da
fix(transpiler): complete rewriteStmts coverage and use innerIndex() …
Jarred-Sumner 9dc410b
Merge branch 'main' into jarred/esdecorator
dylan-conway 42df22a
Merge branch 'main' into jarred/esdecorator
Jarred-Sumner cbeeec9
Update html-import-manifest.test.ts
Jarred-Sumner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,7 @@ pub fn NewParser_( | |
| pub const parseStmtsUpTo = parse_zig.parseStmtsUpTo; | ||
| pub const parseAsyncPrefixExpr = parse_zig.parseAsyncPrefixExpr; | ||
| pub const parseTypeScriptDecorators = parse_zig.parseTypeScriptDecorators; | ||
| pub const parseStandardDecorator = parse_zig.parseStandardDecorator; | ||
| pub const parseTypeScriptNamespaceStmt = parse_zig.parseTypeScriptNamespaceStmt; | ||
| pub const parseTypeScriptImportEqualsStmt = parse_zig.parseTypeScriptImportEqualsStmt; | ||
| pub const parseTypescriptEnumStmt = parse_zig.parseTypescriptEnumStmt; | ||
|
|
@@ -136,6 +137,10 @@ pub fn NewParser_( | |
| pub const findSymbol = symbols_zig.findSymbol; | ||
| pub const findSymbolWithRecordUsage = symbols_zig.findSymbolWithRecordUsage; | ||
|
|
||
| const lowerDecorators_zig = @import("./lowerDecorators.zig").LowerDecorators(parser_feature__typescript, parser_feature__jsx, parser_feature__scan_only); | ||
| pub const lowerStandardDecoratorsStmt = lowerDecorators_zig.lowerStandardDecoratorsStmt; | ||
| pub const lowerStandardDecoratorsExpr = lowerDecorators_zig.lowerStandardDecoratorsExpr; | ||
|
|
||
| macro: MacroState = undefined, | ||
| allocator: Allocator, | ||
| options: Parser.Options, | ||
|
|
@@ -486,6 +491,10 @@ pub fn NewParser_( | |
| /// Used for react refresh, it must be able to insert `const _s = $RefreshSig$();` | ||
| nearest_stmt_list: ?*ListManaged(Stmt) = null, | ||
|
|
||
| /// Name from assignment context for anonymous decorated class expressions. | ||
| /// Set before visitExpr, consumed by lowerStandardDecoratorsImpl. | ||
| decorator_class_name: ?[]const u8 = null, | ||
|
|
||
| const RecentlyVisitedTSNamespace = struct { | ||
| expr: Expr.Data = Expr.empty.data, | ||
| map: ?*js_ast.TSNamespaceMemberMap = null, | ||
|
|
@@ -3759,7 +3768,10 @@ pub fn NewParser_( | |
| } | ||
| }, | ||
| else => { | ||
| Output.panic("Unexpected type in export default", .{}); | ||
| // Standard decorator lowering can produce non-class | ||
| // statements as the export default value; conservatively | ||
| // assume they have side effects. | ||
| return false; | ||
| }, | ||
| } | ||
| }, | ||
|
|
@@ -4857,6 +4869,11 @@ pub fn NewParser_( | |
| ) []Stmt { | ||
| switch (stmtorexpr) { | ||
| .stmt => |stmt| { | ||
| // Standard decorator lowering path (for both JS and TS files) | ||
| if (stmt.data.s_class.class.should_lower_standard_decorators) { | ||
| return p.lowerStandardDecoratorsStmt(stmt); | ||
| } | ||
|
Comment on lines
+4872
to
+4875
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Please add/verify a regression for 🤖 Prompt for AI Agents |
||
|
|
||
| if (comptime !is_typescript_enabled) { | ||
| if (!stmt.data.s_class.class.has_decorators) { | ||
| var stmts = p.allocator.alloc(Stmt, 1) catch unreachable; | ||
|
|
@@ -5007,7 +5024,7 @@ pub fn NewParser_( | |
| } | ||
| } | ||
| }, | ||
| .spread, .declare => {}, // not allowed in a class | ||
| .spread, .declare, .auto_accessor => {}, // not allowed in a class (auto_accessor is standard decorators only) | ||
| .class_static_block => {}, // not allowed to decorate this | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider private field prefix if this is internal-only
If
decorator_class_nameisn’t part of the public parser state API, prefer#decorator_class_nameand adjust accessors accordingly.As per coding guidelines: Use the
#prefix for private fields in Zig structs, e.g.,struct {#foo: u32 };🤖 Prompt for AI Agents