MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / parse

Method parse

src/ext/worker.js:70–163  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

68 }
69
70 static parse(parser) {
71 if (parser.matchToken("worker")) {
72 var name = parser.requireElement("dotOrColonPath");
73 var qualifiedName = name.evalStatically();
74 var nameSpace = qualifiedName.split(".");
75 var workerName = nameSpace.pop();
76
77 // Parse extra scripts
78 var extraScripts = [];
79 if (parser.matchOpToken("(")) {
80 if (parser.matchOpToken(")")) {
81 // no external scripts
82 } else {
83 do {
84 var extraScript = parser.requireTokenType("STRING").value;
85 var absoluteUrl = new URL(extraScript, location.href).href;
86 extraScripts.push(absoluteUrl);
87 } while (parser.matchOpToken(","));
88 parser.requireOpToken(")");
89 }
90 }
91
92 // Consume worker methods
93
94 var funcNames = [];
95 var bodyStartIndex = parser.consumed.length;
96 var bodyEndIndex = parser.consumed.length;
97 do {
98 var feature = parser.parseAnyOf(["defFeature", "jsFeature"]);
99 if (feature) {
100 if (feature.type === "defFeature") {
101 funcNames.push(feature.name);
102 bodyEndIndex = parser.consumed.length;
103 } else {
104 if (parser.hasMore()) continue;
105 }
106 } else break;
107 } while (parser.matchToken("end") && parser.hasMore()); // worker end
108
109 var bodyTokens = parser.consumed.slice(bodyStartIndex, bodyEndIndex + 1);
110 var bodySrc = parser.source.substring(bodyTokens[0].start, bodyTokens[bodyTokens.length - 1].end);
111
112 // Create worker
113
114 var worker = new Worker(workerUri);
115
116 // Send init message to worker
117
118 worker.postMessage({
119 type: "init",
120 _hyperscript: document.currentScript?.src || '/dist/_hyperscript.js',
121 extraScripts: extraScripts,
122 src: bodySrc,
123 });
124
125 var workerPromise = new Promise(function (resolve, reject) {
126 worker.addEventListener(
127 "message",

Callers 1

workerFuncFunction · 0.45

Calls 9

matchTokenMethod · 0.45
requireElementMethod · 0.45
evalStaticallyMethod · 0.45
matchOpTokenMethod · 0.45
requireTokenTypeMethod · 0.45
requireOpTokenMethod · 0.45
parseAnyOfMethod · 0.45
hasMoreMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected