Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/internals/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"exports": {
".": "./src/index.js",
"./plugins/*.js": "./src/plugins/*.js",
"./runners/*.js": "./src/runners/*.js",
"./setup/*.js": "./src/setup/*.js",
"./configs/*.js": "./src/configs/*.js"
Expand Down
21 changes: 17 additions & 4 deletions projects/internals/vite/src/plugins/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import { transformWithEsbuild } from 'vite';
/**
* - https://github.com/oxc-project/oxc/issues/9170
* - https://vite.dev/guide/migration#javascript-transforms-by-oxc
* @param {{ experimentalDecorators?: boolean }} [options]
*/
export const transpileDecorators = () => {
export const transpileDecorators = ({ experimentalDecorators = false } = {}) => {
return {
// Oxc preserves TC39 decorators (only transpiles legacy), but Istanbul's
// Babel parser can't parse them. Use esbuild to downlevel decorators.
// Oxc preserves TC39 decorators, but downstream runtimes and tooling don't
// consistently support them. Use esbuild to downlevel decorators.
name: 'transpile-decorators',
async transform(code, id) {
if (!id.includes('.ts') || !/(?:^|\s)@\w+/m.test(code)) return null;
const result = await transformWithEsbuild(code, id, { target: 'es2022' });
const result = await transformWithEsbuild(code, id, {
target: 'es2022',
...(experimentalDecorators
? {
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
useDefineForClassFields: false
}
}
}
: {})
});
return { code: result.code, map: result.map };
}
};
Expand Down
2 changes: 2 additions & 0 deletions projects/site/eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { EleventyRenderPlugin, HtmlBasePlugin, IdAttributePlugin } from '@11ty/eleventy';
import EleventyPluginVite from '@11ty/eleventy-plugin-vite';
import { transpileDecorators } from '@internals/vite/plugins/decorators.js';
import litPlugin from '@lit-labs/eleventy-plugin-lit';

import { BASE_URL } from './src/_11ty/layouts/metadata.js';
Expand Down Expand Up @@ -144,6 +145,7 @@ export default function (eleventyConfig) {
: undefined
},
plugins: [
transpileDecorators({ experimentalDecorators: true }),
{
name: 'remove-sourcemaps',
transform(code) {
Expand Down