Skip to content

Commit 9686a88

Browse files
feat: add jsx precompile skip element option (#23457)
<!-- Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> This PR wires up a new `jsxPrecompileSkipElements` option in `compilerOptions` that can be used to exempt a list of elements from being precompiled with the `precompile` JSX transform.
1 parent aac7a8c commit 9686a88

8 files changed

Lines changed: 38 additions & 2 deletions

File tree

cli/args/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn ts_config_to_transpile_and_emit_options(
185185
jsx_fragment_factory: options.jsx_fragment_factory,
186186
jsx_import_source: options.jsx_import_source,
187187
precompile_jsx,
188-
precompile_jsx_skip_elements: None,
188+
precompile_jsx_skip_elements: options.jsx_precompile_skip_elements,
189189
transform_jsx,
190190
var_decl_imports: false,
191191
},

cli/schemas/config-file.v1.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
"default": "react",
7777
"markdownDescription": "Specify module specifier used to import the JSX factory functions when using jsx: `react-jsx*`.\n\nSee more: https://www.typescriptlang.org/tsconfig/#jsxImportSource"
7878
},
79+
"jsxPrecompileSkipElements": {
80+
"description": "Specify list of elements that should be exempt from being precompiled when the jsx 'precompile' transform is used.",
81+
"type": "array",
82+
"items": {
83+
"type": "string"
84+
},
85+
"markdownDescription": "Specify list of elements that should be exempt from being precompiled when the jsx `precompile` transform is used."
86+
},
7987
"keyofStringsOnly": {
8088
"description": "Make keyof only return strings instead of string, numbers or symbols. Legacy option.",
8189
"type": "boolean",

cli/tsc/99_main_compiler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,9 @@ delete Object.prototype.__proto__;
958958
if (config.jsx === "precompile") {
959959
config.jsx = "react-jsx";
960960
}
961+
if (config.jsxPrecompileSkipElements) {
962+
delete config.jsxPrecompileSkipElements;
963+
}
961964
return config;
962965
}
963966

tests/integration/run_tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,12 @@ itest!(jsx_import_source_precompile_import_map {
20982098
http_server: true,
20992099
});
21002100

2101+
itest!(jsx_import_source_precompile_import_map_skip_element {
2102+
args: "run --reload --check --import-map jsx/import-map.json --no-lock --config jsx/deno-jsx-precompile-skip.jsonc run/jsx_precompile/skip.tsx",
2103+
output: "run/jsx_precompile/skip.out",
2104+
http_server: true,
2105+
});
2106+
21012107
itest!(jsx_import_source_import_map {
21022108
args: "run --reload --import-map jsx/import-map.json --no-lock --config jsx/deno-jsx-import-map.jsonc run/jsx_import_source_no_pragma.tsx",
21032109
output: "run/jsx_import_source_import_map.out",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "precompile",
4+
"jsxImportSource": "jsx-precompile",
5+
"jsxPrecompileSkipElements": ["a", "img"]
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Download http://localhost:4545/jsx/jsx-precompile/index.ts
2+
Check file:///[WILDCARD]/run/jsx_precompile/skip.tsx
3+
imported http://localhost:4545/jsx/jsx-precompile/index.ts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function A() {
2+
return (
3+
<div>
4+
<a href="#">foo</a>
5+
<p>hello</p>
6+
<img src="#" alt="" />
7+
</div>
8+
);
9+
}

tools/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async function ensureNoNewITests() {
213213
"pm_tests.rs": 0,
214214
"publish_tests.rs": 28,
215215
"repl_tests.rs": 0,
216-
"run_tests.rs": 381,
216+
"run_tests.rs": 382,
217217
"shared_library_tests.rs": 0,
218218
"task_tests.rs": 30,
219219
"test_tests.rs": 80,

0 commit comments

Comments
 (0)