Skip to content

Commit

Permalink
Replace styled-jsx-placeholder patterns (#2)
Browse files Browse the repository at this point in the history
The original version mistakenly matched `%%styled-jsx-expression-XXX%%` while it should have matched `%%styled-jsx-placeholder-XXX%%`
  • Loading branch information
andrewb authored and giuseppeg committed Oct 18, 2017
1 parent 1ccce13 commit 0a5dcb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -2,6 +2,10 @@ const loopWhile = require('deasync').loopWhile
const processor = require('./processor')

module.exports = (css, settings) => {
const cssWithPlaceholders = css
.replace(/%%styled-jsx-placeholder-(\d+)%%/g, (_, id) =>
`/*%%styled-jsx-placeholder-${id}%%*/`
)
let processedCss
let wait = true

Expand All @@ -10,7 +14,7 @@ module.exports = (css, settings) => {
wait = false
}

processor(css)
processor(cssWithPlaceholders)
.then(resolved)
.catch(resolved)
loopWhile(() => wait)
Expand All @@ -20,4 +24,7 @@ module.exports = (css, settings) => {
}

return processedCss
.replace(/\/\*%%styled-jsx-placeholder-(\d+)%%\*\//g, (_, id) =>
`%%styled-jsx-placeholder-${id}%%`
)
}
6 changes: 3 additions & 3 deletions test.js
Expand Up @@ -9,10 +9,10 @@ describe('styled-jsx-plugin-postcss', () => {
)
})

it('works with expressions placeholders', () => {
it('works with placeholders', () => {
assert.equal(
plugin('p { img { display: block } color: %%styled-jsx-expression-1%%; }'),
'p { color: %%styled-jsx-expression-1%%; } p img { display: block }'
plugin('p { img { display: block } color: %%styled-jsx-placeholder-0%%; } %%styled-jsx-placeholder-1%%'),
'p { color: %%styled-jsx-placeholder-0%%; } p img { display: block } %%styled-jsx-placeholder-1%%'
)
})

Expand Down

0 comments on commit 0a5dcb6

Please sign in to comment.