@erickmerchant/framework
Advanced tools
Comparing version 43.3.1 to 43.4.0
@@ -181,9 +181,4 @@ import {tokenTypes} from './html.js' | ||
const isIterator = child?.[Symbol.iterator] | ||
const isArray = Array.isArray(child) | ||
if (typeof child === 'string' || !isIterator) { | ||
if (!Array.isArray(child)) { | ||
child = [child] | ||
} else if (isIterator && !isArray) { | ||
child = Array.from(child) | ||
} | ||
@@ -190,0 +185,0 @@ } else { |
235
html.js
@@ -29,149 +29,150 @@ const weakMap = new WeakMap() | ||
const tokenizer = { | ||
*get(acc, strs, vlength) { | ||
let afterVar = false | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
let str | ||
let i | ||
const tokenize = (acc, strs, vlength) => { | ||
const tokens = [] | ||
let afterVar = false | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
let str | ||
let 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() | ||
} | ||
afterVar = false | ||
afterVar = false | ||
yield { | ||
type: !end ? tokenTypes.tag : tokenTypes.endtag, | ||
value | ||
} | ||
tokens.push({ | ||
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++ | ||
} | ||
if (value.trim() || (afterVar && current() !== '<')) { | ||
yield { | ||
type: tokenTypes.text, | ||
value | ||
} | ||
} | ||
if (value.trim() || (afterVar && current() !== '<')) { | ||
tokens.push({ | ||
type: tokenTypes.text, | ||
value | ||
}) | ||
} | ||
} else if (isSpaceChar(current())) { | ||
i++ | ||
} else if (current() === '/' && next() === '>') { | ||
yield* [ | ||
END, | ||
{ | ||
type: tokenTypes.endtag, | ||
value: tag | ||
}, | ||
END | ||
] | ||
} | ||
} else if (isSpaceChar(current())) { | ||
i++ | ||
} else if (current() === '/' && next() === '>') { | ||
tokens.push( | ||
END, | ||
{ | ||
type: tokenTypes.endtag, | ||
value: tag | ||
}, | ||
END | ||
) | ||
tag = false | ||
tag = false | ||
i += 2 | ||
} else if (current() === '>') { | ||
yield END | ||
i += 2 | ||
} else if (current() === '>') { | ||
tokens.push(END) | ||
tag = false | ||
tag = false | ||
i++ | ||
} else if (isOfKey(current())) { | ||
let value = '' | ||
i-- | ||
while (next() && isOfKey(next())) { | ||
i++ | ||
} else if (isOfKey(current())) { | ||
let value = '' | ||
i-- | ||
value += current() | ||
} | ||
while (next() && isOfKey(next())) { | ||
i++ | ||
tokens.push({ | ||
type: tokenTypes.key, | ||
value | ||
}) | ||
value += current() | ||
} | ||
if (next() === '=') { | ||
i++ | ||
yield { | ||
type: tokenTypes.key, | ||
value | ||
} | ||
let quote = '' | ||
let value = '' | ||
if (next() === '=') { | ||
if (next() && isQuoteChar(next())) { | ||
i++ | ||
let quote = '' | ||
let value = '' | ||
quote = current() | ||
if (next() && isQuoteChar(next())) { | ||
i++ | ||
while (next() !== quote) { | ||
if (next()) { | ||
i++ | ||
quote = current() | ||
while (next() !== quote) { | ||
if (next()) { | ||
i++ | ||
value += current() | ||
} else { | ||
throw createAssertionError('', quote) | ||
} | ||
value += current() | ||
} else { | ||
throw createAssertionError('', quote) | ||
} | ||
} | ||
i++ | ||
i++ | ||
yield { | ||
type: tokenTypes.value, | ||
value | ||
} | ||
} else if (next()) { | ||
throw createAssertionError(next(), '"') | ||
} | ||
} else { | ||
yield valueTrue | ||
tokens.push({ | ||
type: tokenTypes.value, | ||
value | ||
}) | ||
} else if (next()) { | ||
throw createAssertionError(next(), '"') | ||
} | ||
} else { | ||
tokens.push(valueTrue) | ||
} | ||
i++ | ||
} | ||
i++ | ||
} | ||
} | ||
acc.tag = tag | ||
acc.tag = tag | ||
if (index < vlength) { | ||
afterVar = true | ||
if (index < vlength) { | ||
afterVar = true | ||
yield { | ||
type: tokenTypes.variable, | ||
value: index | ||
} | ||
} | ||
tokens.push({ | ||
type: tokenTypes.variable, | ||
value: index | ||
}) | ||
} | ||
} | ||
return tokens | ||
} | ||
const parse = (nextToken, parent, tag, variables) => { | ||
const parse = (tokens, parent, tag, variables) => { | ||
const child = { | ||
@@ -188,3 +189,3 @@ tag, | ||
for (;;) { | ||
token = nextToken() | ||
token = tokens.shift() | ||
@@ -199,3 +200,3 @@ if (!token || token === END) break | ||
key = token.value | ||
token = nextToken() | ||
token = tokens.shift() | ||
@@ -242,3 +243,3 @@ const firstChar = key.charAt(0) | ||
for (;;) { | ||
token = nextToken() | ||
token = tokens.shift() | ||
@@ -250,3 +251,3 @@ if (!token) break | ||
} else if (token.type === tokenTypes.tag) { | ||
const dynamic = parse(nextToken, child, token.value, variables) | ||
const dynamic = parse(tokens, child, token.value, variables) | ||
@@ -287,16 +288,8 @@ child.dynamic = child.dynamic || dynamic | ||
const tokens = tokenizer.get(acc, strs, variables.length) | ||
const tokens = tokenize(acc, strs, variables.length) | ||
const nextToken = () => { | ||
const token = tokens.next() | ||
if (token.done) return | ||
return token.value | ||
} | ||
const children = [] | ||
for (;;) { | ||
const token = nextToken() | ||
const token = tokens.shift() | ||
@@ -306,3 +299,3 @@ if (!token) break | ||
if (token.type === tokenTypes.tag) { | ||
parse(nextToken, {children}, token.value, variables) | ||
parse(tokens, {children}, token.value, variables) | ||
} else if (token.type === tokenTypes.text && token.value.trim()) { | ||
@@ -331,3 +324,3 @@ throw createAssertionError(token.type, "'node'") | ||
return Object.assign({variables}, result) | ||
return {variables, ...result} | ||
} | ||
@@ -334,0 +327,0 @@ |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "43.3.1", | ||
"version": "43.4.0", | ||
"description": "A front-end framework.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/erickmerchant/framework#readme", |
@@ -85,3 +85,3 @@ import {escape} from './escape.js' | ||
if (!child?.[Symbol.iterator] || typeof child === 'string') { | ||
if (!Array.isArray(child)) { | ||
child = [child] | ||
@@ -108,7 +108,6 @@ } | ||
case tokenTypes.node: | ||
result += stringify( | ||
Object.assign({}, child, { | ||
variables: child.view ? child.variables : variables | ||
}) | ||
) | ||
result += stringify({ | ||
variables: child.view ? child.variables : variables, | ||
...child | ||
}) | ||
break | ||
@@ -115,0 +114,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17864
587