Skip to content

Commit

Permalink
Fix bug in # replace
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Apr 12, 2024
1 parent 72d3330 commit 6af74a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export function parser(_strings: TemplateStringsArray, ..._values: any[]): Parse
}
}

if (x === '#' && !string[i + 1]?.match(/[A-z]/)) {
// have to account for ids and hex colours
if (x === '#' && string[i + 1]?.match(/[A-z][0-9]|\s/)) {
if (openGlobal) {
globalOuts.push(outs, placeHolderHash)
} else {
Expand Down
13 changes: 10 additions & 3 deletions test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import render from 'mithril-node-render'
import CSS, { sheets, pretty } from '../lib'
import { JSDOM } from 'jsdom'

const assertStringEq = (a:string,b: string) => {
if (a !== b ) {
throw new Error('strings not equal: \n' + a + '\n' + b)
}
}


test('server', async () => {
const { css, m } = CSS(hyperscript, { server: true})
const desktop = css('@media(min-width: 1000px)')
Expand Down Expand Up @@ -38,7 +45,7 @@ test('server', async () => {
</html>
`)

assert.equal(
assertStringEq(
pretty([...sheets.values()].join('')),
pretty(`
css-node {
Expand All @@ -59,6 +66,6 @@ test('server', async () => {
await new Promise((Y) => setTimeout(Y, 200))
const h1 = jsdom.window.document.body.querySelector('h1')

assert.equal(h1?.className, className)
assert.equal(h1?.getAttribute('style'), `--${className}-1:red;--${className}-2:blue`)
assertStringEq(h1?.className!, className)
assertStringEq(h1?.getAttribute('style')!, `--${className}-1:red;--${className}-2:blue`)
})

0 comments on commit 6af74a7

Please sign in to comment.