@erickmerchant/framework
Advanced tools
Comparing version 48.0.1 to 48.0.2
256
html.js
@@ -6,13 +6,18 @@ const weakMap = new WeakMap() | ||
export const tokenTypes = { | ||
variable: 0, | ||
tag: 1, | ||
endtag: 2, | ||
key: 3, | ||
value: 4, | ||
node: 5, | ||
text: 6, | ||
constant: 7 | ||
} | ||
export const tokenTypes = [ | ||
'variable', | ||
'tag', | ||
'endtag', | ||
'key', | ||
'value', | ||
'node', | ||
'text', | ||
'constant', | ||
'end' | ||
].reduce((acc, val) => { | ||
acc[val] = val | ||
return acc | ||
}, {}) | ||
const valueTrue = { | ||
@@ -23,3 +28,5 @@ type: tokenTypes.value, | ||
const END = Symbol('end') | ||
const END = { | ||
type: tokenTypes.end | ||
} | ||
@@ -31,141 +38,138 @@ const isSpaceChar = (char) => !char.trim() | ||
const tokenize = (acc, strs, vlength) => { | ||
const tokens = [] | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
let str, i | ||
const tokenizer = { | ||
*tokenize(acc, strs, vlength) { | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
let str, i | ||
for (let index = 0, length = strs.length; index < length; index++) { | ||
str = strs[index] | ||
i = 0 | ||
for (let index = 0, length = strs.length; index < length; index++) { | ||
str = strs[index] | ||
i = 0 | ||
let tag = acc.tag | ||
let tag = acc.tag | ||
while (current()) { | ||
if (!tag) { | ||
let value = '' | ||
while (current()) { | ||
if (!tag) { | ||
let value = '' | ||
if (current() === '<') { | ||
let end = false | ||
if (current() === '<') { | ||
let end = false | ||
if (next() === '/') { | ||
end = true | ||
if (next() === '/') { | ||
end = true | ||
i++ | ||
} | ||
i++ | ||
} | ||
while (next() && isOfTag(next())) { | ||
i++ | ||
while (next() && isOfTag(next())) { | ||
i++ | ||
value += current() | ||
} | ||
value += current() | ||
} | ||
tokens.push({ | ||
type: !end ? tokenTypes.tag : tokenTypes.endtag, | ||
value | ||
}) | ||
yield { | ||
type: !end ? tokenTypes.tag : tokenTypes.endtag, | ||
value | ||
} | ||
tag = value | ||
tag = value | ||
i++ | ||
} else { | ||
while (current() && current() !== '<') { | ||
value += current() | ||
i++ | ||
} else { | ||
while (current() && current() !== '<') { | ||
value += current() | ||
i++ | ||
i++ | ||
} | ||
if (value.trim()) { | ||
yield { | ||
type: tokenTypes.text, | ||
value | ||
} | ||
} | ||
} | ||
} else if (isSpaceChar(current())) { | ||
i++ | ||
} else if (current() === '/' && next() === '>') { | ||
yield END | ||
if (value.trim()) { | ||
tokens.push({ | ||
type: tokenTypes.text, | ||
value | ||
}) | ||
} | ||
} | ||
} else if (isSpaceChar(current())) { | ||
i++ | ||
} else if (current() === '/' && next() === '>') { | ||
tokens.push( | ||
END, | ||
{ | ||
yield { | ||
type: tokenTypes.endtag, | ||
value: tag | ||
}, | ||
END | ||
) | ||
} | ||
tag = false | ||
tag = false | ||
i += 2 | ||
} else if (current() === '>') { | ||
tokens.push(END) | ||
i += 2 | ||
} else if (current() === '>') { | ||
yield END | ||
tag = false | ||
tag = false | ||
i++ | ||
} else if (isOfKey(current())) { | ||
let value = '' | ||
i-- | ||
while (next() && isOfKey(next())) { | ||
i++ | ||
} else if (isOfKey(current())) { | ||
let value = '' | ||
value += current() | ||
} | ||
i-- | ||
tokens.push({ | ||
type: tokenTypes.key, | ||
value | ||
}) | ||
while (next() && isOfKey(next())) { | ||
i++ | ||
if (next() === '=') { | ||
i++ | ||
value += current() | ||
} | ||
let quote = '' | ||
let value = '' | ||
yield { | ||
type: tokenTypes.key, | ||
value | ||
} | ||
if (next() && isQuoteChar(next())) { | ||
if (next() === '=') { | ||
i++ | ||
quote = current() | ||
let quote = '' | ||
let value = '' | ||
while (next() !== quote) { | ||
if (next()) { | ||
i++ | ||
if (next() && isQuoteChar(next())) { | ||
i++ | ||
value += current() | ||
} else { | ||
throw createAssertionError('', quote) | ||
quote = current() | ||
while (next() !== quote) { | ||
if (next()) { | ||
i++ | ||
value += current() | ||
} else { | ||
throw createAssertionError('', quote) | ||
} | ||
} | ||
} | ||
i++ | ||
i++ | ||
tokens.push({ | ||
type: tokenTypes.value, | ||
value | ||
}) | ||
} else if (next()) { | ||
throw createAssertionError(next(), '"') | ||
yield { | ||
type: tokenTypes.value, | ||
value | ||
} | ||
} else if (next()) { | ||
throw createAssertionError(next(), '"') | ||
} | ||
} else { | ||
yield valueTrue | ||
} | ||
} else { | ||
tokens.push(valueTrue) | ||
i++ | ||
} | ||
i++ | ||
} | ||
} | ||
acc.tag = tag | ||
acc.tag = tag | ||
if (index < vlength) { | ||
tokens.push({ | ||
type: tokenTypes.variable, | ||
value: index | ||
}) | ||
if (index < vlength) { | ||
yield { | ||
type: tokenTypes.variable, | ||
value: index | ||
} | ||
} | ||
} | ||
} | ||
return tokens | ||
} | ||
@@ -189,27 +193,25 @@ | ||
for (;;) { | ||
token = tokens.shift() | ||
token = tokens.next().value | ||
if (!token || token === END) break | ||
let key = false | ||
let constant = false | ||
let value = token.value | ||
if (token.type === tokenTypes.key) { | ||
key = token.value | ||
token = tokens.shift() | ||
const key = token.value | ||
token = tokens.next().value | ||
const firstChar = key.charAt(0) | ||
const special = ':' === firstChar || '@' === firstChar | ||
constant = token.type === tokenTypes.value | ||
value = token.value | ||
let value = token.value | ||
let constant = false | ||
if (token.type === tokenTypes.variable && !special && !html.dev) { | ||
if (token.type === tokenTypes.value) { | ||
constant = true | ||
} else if (token.type === tokenTypes.variable && !special && !html.dev) { | ||
value = variables[value] | ||
constant = true | ||
} | ||
} | ||
if (key) { | ||
if (constant) { | ||
@@ -233,3 +235,3 @@ child.offsets.attributes++ | ||
} else { | ||
throw createAssertionError(variables[value], null) | ||
throw createAssertionError(token.type, END.type) | ||
} | ||
@@ -239,3 +241,3 @@ } | ||
for (;;) { | ||
token = tokens.shift() | ||
token = tokens.next().value | ||
@@ -285,3 +287,3 @@ if (!token) break | ||
const tokens = tokenize(acc, strs, variables.length) | ||
const tokens = tokenizer.tokenize(acc, strs, variables.length) | ||
@@ -292,3 +294,3 @@ const children = [] | ||
for (;;) { | ||
const token = tokens.shift() | ||
const token = tokens.next().value | ||
@@ -300,3 +302,3 @@ if (!token) break | ||
} else if (token.type === tokenTypes.text && token.value.trim()) { | ||
throw createAssertionError(token.type, "'node'") | ||
throw createAssertionError(token.type, tokenTypes.node) | ||
} | ||
@@ -303,0 +305,0 @@ } |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "48.0.1", | ||
"version": "48.0.2", | ||
"description": "A front-end framework.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/erickmerchant/framework#readme", |
16705