maybe better

This commit is contained in:
Chris Wanstrath 2025-11-02 13:09:16 -08:00
parent 24e0b49679
commit 67e0db090b

View File

@ -39,7 +39,7 @@ const tagCall = (tagName: string, atNamed = {}, ...args: any[]) => {
const space = attrs.length ? ' ' : '' const space = attrs.length ? ' ' : ''
const children = args const children = args
.reverse() .reverse()
.map(a => a === null ? buffer.pop() : a) .map(a => a === TAG_TOKEN ? buffer.pop() : a)
.reverse().join(' ') .reverse().join(' ')
.replaceAll(` ${NOSPACE_TOKEN} `, '') .replaceAll(` ${NOSPACE_TOKEN} `, '')
@ -50,13 +50,16 @@ const tagCall = (tagName: string, atNamed = {}, ...args: any[]) => {
} }
const tag = async (tagName: string, atNamed = {}, ...args: any[]) => { const tag = async (tagName: string, atNamed = {}, ...args: any[]) => {
if (typeof args[0] === 'function') if (typeof args[0] === 'function') {
await tagBlock(tagName, atNamed, args[0]) await tagBlock(tagName, atNamed, args[0])
else } else {
tagCall(tagName, atNamed, ...args) tagCall(tagName, atNamed, ...args)
return TAG_TOKEN
}
} }
const NOSPACE_TOKEN = '!!ribbit-nospace!!' const NOSPACE_TOKEN = '!!ribbit-nospace!!'
const TAG_TOKEN = '!!ribbit-tag!!'
const SELF_CLOSING = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"] const SELF_CLOSING = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]
describe('ribbit', () => { describe('ribbit', () => {