Skip to content

Commit a08584b

Browse files
committed
fix(docs): enhance decorator transpilation
- Updated the `transpileDecorators` function to accept an options parameter for enabling experimental decorators. - Added a new export pattern for plugins in `package.json` to support dynamic imports. - Integrated the updated decorator transpilation in the Eleventy configuration. Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent 77117a1 commit a08584b

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎projects/internals/vite/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"exports": {
1313
".": "./src/index.js",
14+
"./plugins/*.js": "./src/plugins/*.js",
1415
"./runners/*.js": "./src/runners/*.js",
1516
"./setup/*.js": "./src/setup/*.js",
1617
"./configs/*.js": "./src/configs/*.js"

‎projects/internals/vite/src/plugins/decorators.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ import { transformWithEsbuild } from 'vite';
33
/**
44
* - https://github.com/oxc-project/oxc/issues/9170
55
* - https://vite.dev/guide/migration#javascript-transforms-by-oxc
6+
* @param {{ experimentalDecorators?: boolean }} [options]
67
*/
7-
exportconsttranspileDecorators=()=>{
8+
exportconsttranspileDecorators=({ experimentalDecorators =false}={})=>{
89
return{
9-
// Oxc preserves TC39 decorators (only transpiles legacy), but Istanbul's
10-
// Babel parser can't parse them. Use esbuild to downlevel decorators.
10+
// Oxc preserves TC39 decorators, but downstream runtimes and tooling don't
11+
// consistently support them. Use esbuild to downlevel decorators.
1112
name: 'transpile-decorators',
1213
asynctransform(code,id){
1314
if(!id.includes('.ts')||!/(?:^|\s)@\w+/m.test(code))returnnull;
14-
constresult=awaittransformWithEsbuild(code,id,{target: 'es2022'});
15+
constresult=awaittransformWithEsbuild(code,id,{
16+
target: 'es2022',
17+
...(experimentalDecorators
18+
? {
19+
tsconfigRaw: {
20+
compilerOptions: {
21+
experimentalDecorators: true,
22+
useDefineForClassFields: false
23+
}
24+
}
25+
}
26+
: {})
27+
});
1528
return{code: result.code,map: result.map};
1629
}
1730
};

‎projects/site/eleventy.config.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import{EleventyRenderPlugin,HtmlBasePlugin,IdAttributePlugin}from'@11ty/eleventy';
44
importEleventyPluginVitefrom'@11ty/eleventy-plugin-vite';
5+
import{transpileDecorators}from'@internals/vite/plugins/decorators.js';
56
importlitPluginfrom'@lit-labs/eleventy-plugin-lit';
67

78
import{BASE_URL}from'./src/_11ty/layouts/metadata.js';
@@ -144,6 +145,7 @@ export default function (eleventyConfig) {
144145
: undefined
145146
},
146147
plugins: [
148+
transpileDecorators({experimentalDecorators: true}),
147149
{
148150
name: 'remove-sourcemaps',
149151
transform(code){

0 commit comments

Comments
 (0)