Skip to content
Draft
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
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
"smoke": "node tests/smoke/run"
},
"lint-staged": {
"*.js": [
"prettier --write \"**/*.{js,json}\"",
"git add"
]
"*.js": ["prettier --write \"**/*.{js,json}\"", "git add"]
},
"author": {
"name": "Algolia, Inc.",
Expand Down Expand Up @@ -87,8 +84,6 @@
"react-is": "18.1.0"
},
"jest": {
"setupFilesAfterEnv": [
"<rootDir>tests/setupTests.js"
]
"setupFilesAfterEnv": ["<rootDir>tests/setupTests.js"]
}
}
10 changes: 1 addition & 9 deletions src/formatter/formatProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ export default (
let attributeFormattedMultiline = `\n${spacer(lvl + 1, tabStop)}`;
const isMultilineAttribute = formattedPropValue.includes('\n');

if (
useBooleanShorthandSyntax &&
formattedPropValue === '{false}' &&
!hasDefaultValue
) {
// If a boolean is false and not different from it's default, we do not render the attribute
attributeFormattedInline = '';
attributeFormattedMultiline = '';
} else if (useBooleanShorthandSyntax && formattedPropValue === '{true}') {
if (useBooleanShorthandSyntax && formattedPropValue === '{true}') {
attributeFormattedInline += `${name}`;
attributeFormattedMultiline += `${name}`;
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/formatter/formatProp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ describe('formatProp', () => {
expect(
formatProp('foo', true, false, false, null, true, 0, options)
).toEqual({
attributeFormattedInline: '',
attributeFormattedMultiline: '',
attributeFormattedInline: ' foo={false}',
attributeFormattedMultiline: `
foo={false}`,
isMultilineAttribute: false,
});

Expand Down
20 changes: 18 additions & 2 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,22 @@ describe('reactElementToJSXString(ReactElement)', () => {
);
});

it('reactElementToJSXString(<TestComponent />, { useBooleanShorthandSyntax: true })', () => {
expect(
reactElementToJSXString(
<TestComponent testTrue={true} testFalse={false} />,
{
useBooleanShorthandSyntax: true,
}
)
).toEqual(
`<TestComponent
testFalse={false}
testTrue
/>`
);
});

it('should render default props', () => {
expect(reactElementToJSXString(<DefaultPropsComponent />)).toEqual(
`<DefaultPropsComponent
Expand Down Expand Up @@ -888,10 +904,10 @@ describe('reactElementToJSXString(ReactElement)', () => {
).toEqual('<div primary />');
});

it('should omit attributes with false as value', () => {
it('should not omit attributes with false as value', () => {
expect(
reactElementToJSXString(<div primary={false} />) // eslint-disable-line react/jsx-boolean-value
).toEqual('<div />');
).toEqual('<div primary={false} />');
});

it('should return the actual functions when "showFunctions" is true', () => {
Expand Down