Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94d6603

Browse files
authored
Merge pull request#430 from reteps/main
Fix JSX renderer to correctly render enumerated properties
2 parents99df7ab +13b2dbe commit94d6603

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

‎.changeset/fifty-oranges-sip.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string':patch
3+
---
4+
5+
Fix JSX renderer to correctly render enumerated properties

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"test":"oxlint && tsc && npm run test:vitest:run && npm run bench",
5151
"test:vitest":"vitest",
5252
"test:vitest:run":"vitest run",
53-
"format":"prettier src/**/*.{d.ts,js} test/**/*.js --write",
53+
"format":"prettier src/**/*.{d.ts,js} test/**/*.{js,jsx} --write",
5454
"prepublishOnly":"npm run build",
5555
"release":"npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
5656
},

‎src/pretty.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
VOID_ELEMENTS,
1010
NAMESPACE_REPLACE_REGEX,
1111
SVG_CAMEL_CASE,
12+
HTML_ENUMERATED,
1213
HTML_LOWER_CASE,
1314
getContext,
1415
setDirty,
@@ -22,6 +23,7 @@ import { options, Fragment } from 'preact';
2223
constUNNAMED=[];
2324

2425
constEMPTY_ARR=[];
26+
constEMPTY_STR='';
2527

2628
/**
2729
* Render Preact JSX + Components to a pretty-printed HTML-like string.
@@ -254,6 +256,11 @@ function _renderToStringPretty(
254256
name='http-equiv';
255257
}elseif(NAMESPACE_REPLACE_REGEX.test(name)){
256258
name=name.replace(NAMESPACE_REPLACE_REGEX,'$1:$2').toLowerCase();
259+
}elseif(
260+
(name.at(4)==='-'||HTML_ENUMERATED.has(name))&&
261+
v!=null
262+
){
263+
v=v+EMPTY_STR;
257264
}elseif(isSvgMode){
258265
if(SVG_CAMEL_CASE.test(name)){
259266
name=

‎test/jsx.test.jsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,13 @@ describe('jsx', () => {
171171
it('should not render function children',()=>{
172172
expect(renderJsx(<div>{()=>{}}</div>)).to.equal('<div></div>');
173173
});
174+
175+
it('should render enumerated attributes',()=>{
176+
expect(renderJsx(<divdraggable={true}/>)).to.equal(
177+
'<div draggable="true"></div>'
178+
);
179+
expect(renderJsx(<divdraggable={false}/>)).to.equal(
180+
'<div draggable="false"></div>'
181+
);
182+
});
174183
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp