Skip to content

Commit

Permalink
closes #119
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Jul 9, 2019
1 parent a21fc04 commit 376f817
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
31 changes: 18 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@riotjs/parser": "^4.0.3",
"acorn": "^6.2.0",
"acorn-dynamic-import": "^4.0.0",
"cssesc": "^3.0.0",
"cumpa": "^1.0.1",
"curri": "^1.0.1",
"dom-nodes": "^1.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/generators/css/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {builders, types} from '../../utils/build-types'
import {TAG_CSS_PROPERTY} from '../../constants'
import cssEscape from 'cssesc'
import getPreprocessorTypeByAttribute from '../../utils/get-preprocessor-type-by-attribute'
import preprocess from '../../utils/preprocess-node'

Expand Down Expand Up @@ -95,8 +96,12 @@ export default function css(sourceNode, source, meta, ast) {
const { options } = meta
const cssNode = compactCss(sourceNode.text)
const preprocessorOutput = preprocess('css', preprocessorName, meta, cssNode)
const escapedCssIdentifier = cssEscape(meta.tagName, {
isIdentifier: true
})

const cssCode = (options.scopedCss ?
scopedCSS(meta.tagName, preprocessorOutput.code) :
scopedCSS(escapedCssIdentifier, preprocessorOutput.code) :
preprocessorOutput.code
).trim()

Expand Down
6 changes: 6 additions & 0 deletions test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('Core specs', () => {
expect(output.default.template).to.be.ok
})

it('Tags with weird namespaces can output properly css names', async function() {
const result = compile(getFixture('weird-namespace.riot'))

expect(result.code).to.match(/weird\\:namespace/)
})

it('Tags without html and javascript can be properly compiled', async function() {
const result = compile(getFixture('only-css.riot'))
const output = evaluateScript(result.code)
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/weird-namespace.riot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<weird:namespace>
<style>
:host { color: red; }
</style>
</weird:namespace>

0 comments on commit 376f817

Please sign in to comment.