Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"test": "oxlint && tsc && npm run test:vitest:run && npm run bench",
"test:vitest": "vitest",
"test:vitest:run": "vitest run",
"format": "prettier src/**/*.{d.ts,js} test/**/*.js --write",
"format": "prettier src/**/*.{d.ts,js} test/**/*.{js,jsx} --write",
"prepublishOnly": "npm run build",
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},
Expand Down
8 changes: 7 additions & 1 deletion src/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
VOID_ELEMENTS,
NAMESPACE_REPLACE_REGEX,
SVG_CAMEL_CASE,
HTML_ENUMERATED,
HTML_LOWER_CASE,
getContext,
setDirty,
Expand All @@ -22,7 +23,7 @@ import { options, Fragment } from 'preact';
const UNNAMED = [];

const EMPTY_ARR = [];

const EMPTY_STR = '';
/**
* Render Preact JSX + Components to a pretty-printed HTML-like string.
* @param {VNode} vnode JSX Element / VNode to render
Expand Down Expand Up @@ -254,6 +255,11 @@ function _renderToStringPretty(
name = 'http-equiv';
} else if (NAMESPACE_REPLACE_REGEX.test(name)) {
name = name.replace(NAMESPACE_REPLACE_REGEX, '$1:$2').toLowerCase();
} else if (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mirrors the check in index.js.

(name.at(4) === '-' || HTML_ENUMERATED.has(name)) &&
v != null
) {
v = v + EMPTY_STR;
} else if (isSvgMode) {
if (SVG_CAMEL_CASE.test(name)) {
name =
Expand Down
9 changes: 9 additions & 0 deletions test/jsx.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@ describe('jsx', () => {
it('should not render function children', () => {
expect(renderJsx(<div>{() => {}}</div>)).to.equal('<div></div>');
});

it('should render enumerated attributes', () => {
expect(renderJsx(<div draggable={true} />)).to.equal(
'<div draggable="true"></div>'
);
expect(renderJsx(<div draggable={false} />)).to.equal(
'<div draggable="false"></div>'
);
});
});