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

Method parse

www/js/_hyperscript-max.js:7620–7665  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

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