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

Handle case where css float property is converted to cssFloat by autoprefixer camelCase function #224

Merged
merged 3 commits into from
Aug 2, 2017
Merged
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
5 changes: 2 additions & 3 deletions src/ast-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ function prefixAst (args, t) {
return properties.push(
t.objectProperty(key, prefixedValue, property.computed)
)

// literal value or array of literal values
} else if (
// literal value or array of literal values
isLiteral(property.value) ||
(t.isArrayExpression(property.value) &&
property.value.elements.every(isLiteral))
Expand Down Expand Up @@ -140,7 +139,7 @@ export default class ASTObject {
return {
computed: false,
composes: key === 'composes',
ast: t.stringLiteral(key)
ast: t.stringLiteral(key === 'cssFloat' ? 'float' : key)
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/__snapshots__/css.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ exports[`css css variables 1`] = `
/>
`;

exports[`css float property 1`] = `
.glamor-0 {
float: left;
}

<div
className="glamor-0"
/>
`;

exports[`css flushes correctly 1`] = `
.glamor-0 {
display: -webkit-box;
Expand Down Expand Up @@ -159,6 +169,7 @@ exports[`css handles more than 10 dynamic properties 1`] = `

exports[`css handles objects 1`] = `
.glamor-0 {
float: left;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/react.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ exports[`styled nested 1`] = `

exports[`styled no dynamic 1`] = `
.glamor-1 {
font-size: 12px;
float: left;
}

<h1
Expand Down
10 changes: 10 additions & 0 deletions test/babel/__snapshots__/css.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ exports[`babel css inline css random expression 1`] = `
});"
`;

exports[`babel css inline css with float property 1`] = `
"
/*#__PURE__*/css([], [], function createEmotionStyledRules() {
return [{
\\"float\\": \\"left\\"
}];
});"
`;

exports[`babel css inline interpolation in selector 1`] = `
"
const cls2 = /*#__PURE__*/css([], [className], function createEmotionStyledRules(x0) {
Expand Down Expand Up @@ -323,6 +332,7 @@ exports[`babel css inline nested expanded properties 1`] = `
exports[`babel css inline object with a bunch of stuff 1`] = `
"
const cls2 = css({
'float': 'left',
'display': '-webkit-box; display: -ms-flexbox; display: flex',
'WebkitBoxFlex': '1',
'msFlex': '1',
Expand Down
12 changes: 12 additions & 0 deletions test/babel/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ describe('babel css', () => {
expect(code).toMatchSnapshot()
})

test('css with float property', () => {
const basic = `
css\`
float: left;
\``
const {code} = babel.transform(basic, {
plugins: [[plugin]]
})
expect(code).toMatchSnapshot()
})

test('css random expression', () => {
const basic = `css\`
font-size: 20px;
Expand Down Expand Up @@ -234,6 +245,7 @@ describe('babel css', () => {
test('object with a bunch of stuff', () => {
const basic = `
const cls2 = css({
float: 'left',
display: 'flex',
flex: 1,
alignItems: \`\${'center'}\`
Expand Down
10 changes: 10 additions & 0 deletions test/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { sheet, css, flush } from '../src/index'
expect.addSnapshotSerializer(serializer(sheet))

describe('css', () => {
test('float property', () => {
const cls1 = css`
float: left
`

const tree = renderer.create(<div className={cls1}/>).toJSON()
expect(tree).toMatchSnapshot()
})

test('handles more than 10 dynamic properties', () => {
const cls1 = css`
text-decoration: ${'underline'};
Expand Down Expand Up @@ -63,6 +72,7 @@ describe('css', () => {

test('handles objects', () => {
const cls1 = css({
float: 'left',
display: 'flex',
color: `${'blue'}`,
fontSize: `${'20px'}`,
Expand Down
2 changes: 1 addition & 1 deletion test/react.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ expect.addSnapshotSerializer(serializer(sheet))

describe('styled', () => {
test('no dynamic', () => {
const H1 = styled.h1`font-size: 12px;`
const H1 = styled.h1`float: left;`

const tree = renderer.create(<H1>hello world</H1>).toJSON()

Expand Down