Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use double quotes for string values #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function serializeItem (item, options, delimit=true) {
if (isImmutable(item)) {
result = serializeItem(item.toJS(), options, delimit);
} else if (typeof item === 'string') {
result = delimit ? `'${item}'` : item;
result = delimit ? `"${item}"` : item;
} else if (typeof item === 'number' || typeof item === 'boolean') {
result = `${item}`;
} else if (Array.isArray(item)) {
Expand Down Expand Up @@ -111,14 +111,14 @@ function jsxToString (component, options) {
} else {
value = serializeItem(component.props[key], {...opts, key});
}
if (typeof value !== 'string' || value[0] !== "'") {
if (typeof value !== 'string' || value[0] !== '"') {
value = `{${value}}`;
}
return `${key}=${value}`;
}).join(`\n${indentation}`);

if (component.key && opts.ignoreProps.indexOf('key') === -1) {
componentData.props += `key='${component.key}'`;
componentData.props += `key="${component.key}"`;
}

if (componentData.props.length > 0) {
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ test('test a basic react component with default props', function(t) {

let output = jsxToString(<DefaultProp test="abc" />);

t.equal(output, '<DefaultProp test=\'abc\' />');
t.equal(output, '<DefaultProp test="abc" />');
});

test('test a basic react component with key props', function(t) {
t.plan(1);

let output = jsxToString(<DefaultProp key="abc" />);

t.equal(output, '<DefaultProp key=\'abc\' />');
t.equal(output, '<DefaultProp key="abc" />');
});

test('test a react component with basic props', function(t) {
Expand All @@ -66,7 +66,7 @@ test('test a react component with basic props', function(t) {
test5={{abc: "abc"}} test6="" />
);

t.equal(output, '<Basic test=\'abc\'\n test2={4}\n test4={true}\n test5={{"abc": "abc"}}\n test6=\'\' />');
t.equal(output, '<Basic test="abc"\n test2={4}\n test4={true}\n test5={{"abc": "abc"}}\n test6="" />');
});

test('test a react component with function props', function(t) {
Expand Down Expand Up @@ -279,7 +279,7 @@ test('test a react component with spread operator', function(t) {
<Basic {...someProps}/>
);

t.equal(output, '<Basic prop1={true}\n prop2=\'active\' />');
t.equal(output, '<Basic prop1={true}\n prop2="active" />');
});

test('test a react component with custom displayName', function(t) {
Expand Down Expand Up @@ -446,5 +446,5 @@ test('test a complex react component with boolean props and shortBooleanSyntax o
}
);

t.equal(output, '<Basic test=\'abc\'\n test2={4}\n test4\n test5={{"abc": "abc"}}\n test6=\'\'\n test7={false}\n test8>\n <BasicChild test1\n test2={false}\n test3={5}\n test4={6}>\n Title 1\n </BasicChild>\n</Basic>');
});
t.equal(output, '<Basic test="abc"\n test2={4}\n test4\n test5={{"abc": "abc"}}\n test6=""\n test7={false}\n test8>\n <BasicChild test1\n test2={false}\n test3={5}\n test4={6}>\n Title 1\n </BasicChild>\n</Basic>');
});