Fix SWC decorator parsing to support TS5 stage-3 decorators#94274
Fix SWC decorator parsing to support TS5 stage-3 decorators#94274arab971 wants to merge 1 commit into
Conversation
…8360) SWC rejected @decorator syntax at the parser level for TypeScript files unless experimentalDecorators was set in tsconfig. This made TS5 stage-3 decorators impossible even when the transform was correctly configured. - Always enable decorator parsing for .ts/.tsx files in SWC parser options - Use decoratorVersion "2022-03" (stage-3) when experimentalDecorators is not set, matching Turbopack's DecoratorsKind::Ecma behavior - Gate emitDecoratorMetadata on experimentalDecorators being enabled - Add integration test for TS5 decorators in production build
|
@kdy1 I completely understand why that looks off—it looks like a date! However, |
|
Please do not ping me |
What happened here? Why is this PR closed without reviewing? Why cannot contributers ping reviewers? TS 7 has already been RC version, Next.js hasn't fully supported TS 5 ?! Support custom SWC configuration just like Babel, or merge this PR please! |
|
@TechQuery Thank you for your support. I apologize for closing the PR; I was feeling frustrated by the response from the reviewer, as well as the general lack of feedback and reviews over such a long period. I truly appreciate you bringing this to my attention. |
You're welcome, Next.js mainteners are the people who should be blamed. I had similar situation in fixing the broken Vercel serverless template: vercel/examples#835 I think, maybe Vercel is humanless now. If I'm not too busy in the future, I will finish my SSR framework based on Web components standard & fully customable SWC compiler: EasyWebApp/WebSSR#1 |
|
@lubieowoce — this PR fixes TS5/TS7 stage-3 decorator support in SWC builds. kdy1 confirmed the SWC convention is correct. Can you take a look? |
What?
Fix SWC decorator parsing to support TS5 stage-3 decorators. Currently, SWC rejects
@decoratorsyntax at the parser level for TypeScript files unlessexperimentalDecoratorsis set in tsconfig, making TS5 stage-3 decorators impossible.Why?
TypeScript 5 introduced stage-3 decorators as the default (no flag needed). Next.js users adopting TS5 decorators hit a parse error (
Unexpected token '@') because SWC's parser only enabled decorator syntax whenexperimentalDecorators: truewas set. This is the #1 blocker reported in #48360.How?
swc/options.ts): Always enable decorator parsing for.ts/.tsxfiles, regardless ofexperimentalDecoratorsswc/options.ts): UsedecoratorVersion: "2022-03"(stage-3 Ecma proposal) whenexperimentalDecoratorsis not set, matching Turbopack'sDecoratorsKind::Ecmabehaviorwebpack-config.ts): Setdecorators: trueunconditionally; gateemitDecoratorMetadataonexperimentalDecorators(metadata is a legacy-only feature)Fixes #48360
Test plan
test/production/ts5-decorators/— builds a page using TS5 decorators and verifies it renderspnpm test-start-webpack test/production/ts5-decorators/index.test.tspassesManual verification with issue reproduction app