MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / prepareNode

Method prepareNode

tools/nodered2mcu.js:419–1680  ·  view source on GitHub ↗
(type, config, dones, errors, statuses, nodes, imports)

Source from the content-addressed store, hash-verified

417 return parts.join("\n");
418 }
419 prepareNode(type, config, dones, errors, statuses, nodes, imports) {
420 switch (type) {
421 case "status": {
422 delete config.scope;
423 } break;
424
425 case "catch": {
426 delete config.uncaught;
427 delete config.scope;
428 } break;
429
430 case "complete": {
431 delete config.uncaught;
432 delete config.scope;
433 } break;
434
435 case "group": {
436 const env = this.prepareEnv(config.env);
437 config.env = `[[JSON]]{\n` + env.join("\n") + "\n}"
438
439 delete config.nodes;
440 delete config.style;
441 delete config.w;
442 delete config.h;
443 } break;
444
445 case "debug": {
446 if ("jsonata" === config.targetType)
447 throw new Error("jsonata unimplemented");
448
449 const getter = [];
450 getter.push(`function (msg) {`);
451 if ("true" === config.complete)
452 getter.push(`\t\t\treturn msg;`);
453 else {
454 let name = config.complete;
455 if ("false" === name)
456 name = "payload";
457 getter.push(`\t\t\treturn msg${this.prepareProp(name)};`);
458 }
459 getter.push(`\t\t}`);
460 config.getter = getter.join("\n");
461
462 if (config.tostatus) {
463 const statusType = config.statusType ?? "auto";
464 if ("auto" === statusType)
465 config.statusVal = config.getter;
466 else if ("msg" === statusType) {
467 getter.length = 1;
468 getter.push(`\t\t\treturn msg.${config.statusVal};`);
469 getter.push(`\t\t}`);
470 config.statusVal = getter.join("\n");
471 }
472 else
473 throw new Error(`unimplemented statusType: ${config.statusType}`);
474 }
475
476 config.active = !!config.active;

Callers 1

transformFlowsMethod · 0.80

Calls 15

prepareEnvMethod · 0.80
preparePropMethod · 0.80
testMethod · 0.80
resolveValueMethod · 0.80
createPropPathMethod · 0.80
makeStorageArgsMethod · 0.80
replaceMethod · 0.80
fromStringMethod · 0.80
findMethod · 0.80
repeatMethod · 0.80
mapMethod · 0.80
resolveSwitchMethod · 0.80

Tested by

no test coverage detected