MCPcopy Index your code
hub / github.com/codecombat/codecombat / rewriteBlocklyJS

Function rewriteBlocklyJS

app/core/blocklyUtils.js:1357–1378  ·  view source on GitHub ↗
(code, { product })

Source from the content-addressed store, hash-verified

1355}
1356
1357function rewriteBlocklyJS (code, { product }) {
1358 // Replace var greeting;\n\ngreeting = 'Hello'; with var greeting = 'Hello';
1359 code = code.replace(/^var (\S+,? ?)+\n*/, '')
1360 const found = []
1361 code = code.replace(/^(\s*)([a-zA-Z0-9_-]+) = /mg, (m, s, n) => {
1362 if (found.indexOf(n) !== -1) return m
1363 found.push(n)
1364 return s + 'var ' + n + ' = '
1365 })
1366
1367 // Replace count, count2, etc. repeat variables with i, j, etc.
1368 code = code.replace(/\bcount(\d*)\b(\+\+)?/g, (match, num, increment) => {
1369 const index = num ? parseInt(num) : 1
1370 const letter = String.fromCharCode(105 + index - 1) // 105 is ASCII code for 'i'
1371 return increment ? `${letter}${increment}` : letter
1372 })
1373
1374 // Replace var with let
1375 code = code.replace(/\bvar\b/g, 'let')
1376
1377 return code.trim()
1378}
1379
1380function rewriteBlocklyPython (code, { product }) {
1381 let oldCode

Callers 1

blocklyUtils.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected