Skip to content

Commit 8f60a1a

Browse files
committed
Handle double braces (fixes GoogleChromeLabs#20)
1 parent 8540775 commit 8f60a1a

3 files changed

Lines changed: 42 additions & 18 deletions

File tree

src/engine.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ interface Block {
388388
function parseSelector(p: AdhocParser): string | undefined {
389389
let startIndex = p.index;
390390
eatUntil("{", p);
391+
if (startIndex === p.index) {
392+
throw Error("Empty selector");
393+
}
391394
return p.sheetSrc.slice(startIndex, p.index);
392395
}
393396

@@ -448,14 +451,6 @@ function parseIdentifier(p: AdhocParser): string {
448451
return match[0];
449452
}
450453

451-
// This function does stuff like `min-width` => `MinWidth`
452-
function undashify(s: string): string {
453-
const v = s
454-
.replace(/-(\w)/, (_, l) => l.toUpperCase())
455-
.replace(/^\w/, (v) => v.toUpperCase());
456-
return v;
457-
}
458-
459454
function parseMeasurementName(p: AdhocParser): string {
460455
return parseIdentifier(p).toLowerCase();
461456
}

tests/empty_href.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<style></style>
3+
<link rel="stylesheet" href="" />
4+
<script type="text/x-handlebars">
5+
{{#foo}}
6+
{{/foo}} <!-- Infinite loop when looking at first { on this line -->
7+
{{#foo}}
8+
{{/foo}}
9+
</script>
10+
<div></div>
11+
<script type="module">
12+
import { doubleRaf, testSuite, assert } from "./test-utils.js";
13+
import "/cqfill.js";
14+
15+
testSuite("Manual transpiling", async () => {});
16+
</script>

tests/index.html

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,36 @@
3333
"dynamic_container",
3434
"simple_new_syntax",
3535
"simple_new_long_syntax",
36+
"empty_href",
3637
];
3738

3839
const { results, iframe } = document.all;
39-
const messageStream = new ReadableStream({
40-
start(controller) {
41-
window.addEventListener("message", (ev) => controller.enqueue(ev.data));
42-
},
43-
});
40+
function nextEvent(el, name) {
41+
return new Promise((resolve) => {
42+
el.addEventListener(name, (ev) => resolve(ev));
43+
});
44+
}
45+
46+
function sleep(ms) {
47+
return new Promise((resolve) => {
48+
setTimeout(resolve, ms);
49+
});
50+
}
51+
52+
function nextEventTimeout(el, name, timeout) {
53+
return Promise.race([
54+
nextEvent(el, name),
55+
sleep(timeout).then(() => ({ data: "Timeout" })),
56+
]);
57+
}
58+
4459
async function run() {
4560
const testResults = {};
4661
for (const test of TESTS) {
4762
iframe.src = `./${test}.html`;
48-
const reader = messageStream.getReader();
49-
const { value: message } = await reader.read();
50-
testResults[test] = message;
51-
reader.releaseLock();
52-
results.innerHTML += `<span><a href="./${test}.html">${test}</a></span><span>${message}</span>`;
63+
const result = await nextEventTimeout(window, "message", 2000);
64+
testResults[test] = result.data;
65+
results.innerHTML += `<span><a href="./${test}.html">${test}</a></span><span>${result.data}</span>`;
5366
}
5467
return testResults;
5568
}

0 commit comments

Comments
 (0)