MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / parse

Method parse

www/js/_hyperscript.esm.js:7619–7664  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

7617 }
7618 }
7619 static parse(parser) {
7620 if (!parser.matchToken("add")) return;
7621 var classRef = parser.parseElement("classRef");
7622 var attributeRef = null;
7623 var cssDeclaration = null;
7624 var valueExpr = null;
7625 if (classRef == null) {
7626 attributeRef = parser.parseElement("attributeRef");
7627 if (attributeRef == null) {
7628 cssDeclaration = parser.parseElement("styleLiteral");
7629 if (cssDeclaration == null) {
7630 parser.pushFollow("to");
7631 try {
7632 valueExpr = parser.parseElement("expression");
7633 } finally {
7634 parser.popFollow();
7635 }
7636 if (valueExpr == null || !parser.currentToken() || parser.currentToken().value !== "to") {
7637 parser.raiseError("Expected either a class reference or attribute expression");
7638 }
7639 }
7640 }
7641 } else {
7642 var classRefs = [classRef];
7643 while (classRef = parser.parseElement("classRef")) {
7644 classRefs.push(classRef);
7645 }
7646 }
7647 if (parser.matchToken("to")) {
7648 var toExpr = parser.requireElement("expression");
7649 } else {
7650 var toExpr = parser.requireElement("implicitMeTarget");
7651 }
7652 if (parser.matchToken("when")) {
7653 var when = parser.requireElement("expression");
7654 }
7655 if (classRefs) {
7656 return new _AddCommand("class", classRefs, null, null, toExpr, when);
7657 } else if (attributeRef) {
7658 return new _AddCommand("attribute", null, attributeRef, null, toExpr, when);
7659 } else if (cssDeclaration) {
7660 return new _AddCommand("css", null, null, cssDeclaration, toExpr, null);
7661 } else {
7662 return new _AddCommand("collection", null, null, null, toExpr, null, valueExpr);
7663 }
7664 }
7665 resolve(context, { to, classRefs, css, value }) {
7666 var runtime2 = context.meta.runtime;
7667 var cmd = this;

Callers

nothing calls this directly

Calls 7

matchTokenMethod · 0.45
parseElementMethod · 0.45
pushFollowMethod · 0.45
popFollowMethod · 0.45
currentTokenMethod · 0.45
raiseErrorMethod · 0.45
requireElementMethod · 0.45

Tested by

no test coverage detected