Skip to content

Commit 34f0723

Browse files
docs: playground button for TypeScript code example (#19671)
* docs: add plyground button for ts code example * send languageOptions with ts code * fix lint error
1 parent dc942a4 commit 34f0723

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

docs/.eleventy.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,33 @@ module.exports = function (eleventyConfig) {
219219

220220
const isRuleRemoved = !Object.hasOwn(env.rules_meta, env.title);
221221

222-
/*
223-
* TypeScript isn't yet supported on the playground:
224-
* https://github.com/eslint/eslint.org/issues/709
225-
*/
226-
if (isRuleRemoved || isTypeScriptCode) {
222+
const tsLanguageOptions = {
223+
languageOptions: {
224+
...languageOptions,
225+
parser: "@typescript-eslint/parser",
226+
parserOptions: {
227+
ecmaFeatures: {
228+
jsx: true,
229+
},
230+
sourceType: "module",
231+
},
232+
},
233+
};
234+
235+
const languageOptionsForPlayground = languageOptions
236+
? { languageOptions }
237+
: void 0;
238+
239+
if (isRuleRemoved) {
227240
return `<div class="${type}">`;
228241
}
229242

230243
// See https://github.com/eslint/eslint.org/blob/29e1d8a000592245e4a30c1996e794643e9b263a/src/playground/App.js#L91-L105
231244
const state = encodeToBase64(
232245
JSON.stringify({
233-
options: languageOptions ? { languageOptions } : void 0,
246+
options: isTypeScriptCode
247+
? tsLanguageOptions
248+
: languageOptionsForPlayground,
234249
text: code,
235250
}),
236251
);

0 commit comments

Comments
 (0)