Skip to content

Commit ac0655f

Browse files
committed
Use JSON.stringify for cache key generation
1 parent e42f58d commit ac0655f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/index.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
const CACHE = {};
1515

16+
const stringify = JSON.stringify;
17+
1618
export default function html(statics) {
17-
const key = statics.length + statics;
19+
const key = stringify(statics);
1820
const tpl = CACHE[key] || (CACHE[key] = build(statics));
1921

2022
// eslint-disable-next-line prefer-rest-params
@@ -55,12 +57,12 @@ const build = (statics) => {
5557
if (!inTag) {
5658
if (field || (buffer = buffer.replace(/^\s*\n\s*|\s*\n\s*$/g,''))) {
5759
if (hasChildren++) out += ',';
58-
out += field || JSON.stringify(buffer);
60+
out += field || stringify(buffer);
5961
}
6062
}
6163
else if (mode === MODE_TAGNAME) {
6264
if (hasChildren++) out += ',';
63-
out += 'h(' + (field || JSON.stringify(buffer));
65+
out += 'h(' + (field || stringify(buffer));
6466
mode = MODE_WHITESPACE;
6567
}
6668
else if (mode === MODE_ATTRIBUTE || (mode === MODE_WHITESPACE && buffer === '...')) {
@@ -77,8 +79,8 @@ const build = (statics) => {
7779
if (!props) props += '{';
7880
else props += ',' + (propsClose ? '' : '{');
7981
propsClose = '}';
80-
props += JSON.stringify(propName) + ':';
81-
props += field || ((propHasValue || buffer) && JSON.stringify(buffer)) || 'true';
82+
props += stringify(propName) + ':';
83+
props += field || ((propHasValue || buffer) && stringify(buffer)) || 'true';
8284
propName = '';
8385
}
8486
propHasValue = false;

0 commit comments

Comments
 (0)