Skip to content

Commit

Permalink
ignore top level or when parsing the from clause of the on feat…
Browse files Browse the repository at this point in the history
…ure, so the language interprets `or` as an event handler separator
  • Loading branch information
1cg committed Mar 2, 2023
1 parent 0d4e586 commit 4024d7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/_hyperscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4117,7 +4117,12 @@
if (tokens.matchToken("elsewhere")) {
elsewhere = true;
} else {
from = parser.parseElement("expression", tokens);
tokens.pushFollow("or");
try {
from = parser.requireElement("expression", tokens)
} finally {
tokens.popFollow();
}
if (!from) {
parser.raiseParseError(tokens, 'Expected either target value or "elsewhere".');
}
Expand All @@ -4134,12 +4139,12 @@

if (tokens.matchToken("debounced")) {
tokens.requireToken("at");
var timeExpr = parser.requireElement("expression", tokens);
var timeExpr = parser.requireElement("unaryExpression", tokens);
// @ts-ignore
var debounceTime = timeExpr.evaluate({}); // OK No promise TODO make a literal time expr
} else if (tokens.matchToken("throttled")) {
tokens.requireToken("at");
var timeExpr = parser.requireElement("expression", tokens);
var timeExpr = parser.requireElement("unaryExpression", tokens);
// @ts-ignore
var throttleTime = timeExpr.evaluate({}); // OK No promise TODO make a literal time expr
}
Expand Down
16 changes: 16 additions & 0 deletions test/features/on.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,4 +778,20 @@ describe("the on feature", function () {
div.innerHTML.should.equal("clicked");
});

it("can handle an or after a from clause", function () {
var d1 = make("<div id='d1'></div>");
var d2 = make("<div id='d2'></div>");
var div = make(
"<div _=' " +
" on click from #d1 or click from #d2 " +
" increment @count then put @count into me" +
" '></div>"
);
d1.click();
div.innerHTML.should.equal("1");
d2.click();
div.innerHTML.should.equal("2");

});

});

0 comments on commit 4024d7d

Please sign in to comment.