MCPcopy Create free account
hub / github.com/codecombat/codecombat / convert

Function convert

app/lib/code-to-blocks.js:588–636  ·  view source on GitHub ↗
(node, ctx)

Source from the content-addressed store, hash-verified

586}
587
588function convert (node, ctx) {
589 if (Array.isArray(node)) {
590 const result = []
591 for (const n of node) {
592 if (n.leadingComments) {
593 for (const c of n.leadingComments) {
594 if (/[Δ∆]/.test(c.value)) continue
595 c.handled = true
596 result.push({
597 type: 'comment',
598 fields: {
599 COMMENT: c.value.substr(1),
600 },
601 start: c.loc.start.line,
602 end: c.loc.end.line,
603 })
604 }
605 }
606 const o = convert(n, ctx)
607 result.push(o)
608 }
609 return nextify(result, ctx)
610 }
611 try {
612 if (!Converters[`Convert${node.type}`]) {
613 console.log(node)
614 throw new Error(`No converter for ${node.type}`)
615 }
616 const b = Converters[`Convert${node.type}`](node, ctx)
617 if (b && node.loc) {
618 b.start = node.loc.start.line
619 b.end = node.loc.end.line
620 }
621 return b
622 } catch (e) {
623 console.error('EN', ctx.context, node, e)
624 let code
625
626 if (node && node.range) code = ctx.code.substr(node.range[0], node.range[1] - node.range[0])
627 else if (node) code = ctx.code.substr(node.start, node.end - node.start)
628
629 return {
630 type: ctx.context === 'value' ? 'raw_code_value' : 'raw_code',
631 fields: {
632 CODE: code || '<CoDe>',
633 },
634 }
635 }
636}
637
638function findAllBlocks (thing) {
639 const result = []

Callers 15

ConvertProgramMethod · 0.85
ConvertBlockStatementMethod · 0.85
ConvertWhileStatementMethod · 0.85
ConvertForStatementMethod · 0.85
ConvertForOfStatementMethod · 0.85
ConvertIfStatementMethod · 0.85

Calls 3

nextifyFunction · 0.85
logMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected