Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const TEMPLATE = document.createElement('template');
const reg = /(\$_h\[\d+\])/g;

export default function html(statics) {
const tpl = CACHE[statics] || (CACHE[statics] = build(statics));
const key = statics.reduce((key, s) => key + s.length + '$' + s, '');
const tpl = CACHE[key] || (CACHE[key] = build(statics));
// eslint-disable-next-line prefer-rest-params
return tpl(this, arguments);
}
Expand Down
20 changes: 20 additions & 0 deletions test/babel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ describe('htm/babel', () => {
).toBe(`h("div",{id:"hello"},["hello"]);`);
});

test('cache key should be unique', () => {
transform('html`<div>Hello, World!</div>`;', {
babelrc: false,
compact: true,
plugins: [
htmBabelPlugin
]
});

expect(
transform('html`<div>Hello${comma} World!</div>`;', {
babelrc: false,
compact: true,
plugins: [
htmBabelPlugin
]
}).code
).toBe(`h("div",{},["Hello",comma," World!"]);`);
});

test('basic transformation with variable', () => {
expect(
transform('var name="world";html`<div id=hello>hello, ${name}</div>`;', {
Expand Down
2 changes: 1 addition & 1 deletion test/preact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('performance', () => {
let count = 0;
function go(count) {
return html(
statics.concat(['count:', count]),
statics.concat(['count:', ''+count]),
`id${count}`,
html(['<li data-id="','">', '</li>'], 'i'+count, 'some text #'+count),
Foo, Foo, Foo
Expand Down