Skip to content

Commit 36a8ca4

Browse files
authored
feat: enable decorator-metadata transform automatically (#315)
1 parent d1efdd0 commit 36a8ca4

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true,
4+
"emitDecoratorMetadata": true
5+
}
6+
}

packages/vite/src/node/__tests__/plugins/oxc.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ describe('transformWithOxc', () => {
156156
expect(actual).toBe(defineForClassFieldsFalseTransformedCode)
157157
})
158158
})
159+
160+
test('supports emitDecoratorMetadata: true', async () => {
161+
const result = await transformWithOxc(
162+
`
163+
function LogMethod(target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
164+
console.log(target, propertyKey, descriptor);
165+
}
166+
167+
class Demo {
168+
@LogMethod
169+
public foo(bar: number) {}
170+
}
171+
172+
const demo = new Demo();
173+
`,
174+
path.resolve(
175+
import.meta.dirname,
176+
'./fixtures/oxc-tsconfigs/decorator-metadata/bar.ts',
177+
),
178+
)
179+
expect(result?.code).toContain('_decorateMetadata("design:type"')
180+
})
159181
})
160182

161183
describe('renderChunk', () => {

packages/vite/src/node/plugins/esbuild.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type TSConfigJSON = {
6969
preserveValueImports?: boolean
7070
target?: string
7171
useDefineForClassFields?: boolean
72+
emitDecoratorMetadata?: boolean
7273
verbatimModuleSyntax?: boolean
7374
}
7475
[key: string]: any

packages/vite/src/node/plugins/oxc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ export async function transformWithOxc(
148148
resolvedOptions.decorator ??= {}
149149
resolvedOptions.decorator.legacy = experimentalDecorators
150150
}
151+
const emitDecoratorMetadata =
152+
loadedCompilerOptions.emitDecoratorMetadata
153+
if (emitDecoratorMetadata !== undefined) {
154+
resolvedOptions.decorator ??= {}
155+
resolvedOptions.decorator.emitDecoratorMetadata =
156+
emitDecoratorMetadata
157+
}
151158
}
152159

153160
/**

0 commit comments

Comments
 (0)