Skip to content

Commit

Permalink
style(editor compiler): expand abbreviations in variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
netux committed Jan 28, 2024
1 parent d2f6b9f commit ccb1e73
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/javascript/src/utils/compiler/for.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ export function evaluateForLoops(joinedItems) {
let match
const forRegex = /@for\s+\(\s*((?:(\w+)\s+)?(?:from\s+))?(\d+)\s+(?:(through|to)\s+)?(\d+)(?:\s*in steps of\s+(\d+))?\s*\)\s*\{/g // Matches "@for ([var] [from] number through|to number [in steps of number]) {" in groups for each param
while ((match = forRegex.exec(joinedItems)) != null) {
const [full, _, variable, startStr, clusivityKw, endStr, stepStr = "1"] = match
const [full, _, variable, startString, clusivityKeyword, endString, stepString = "1"] = match

const inclusive = clusivityKw === "through"
const inclusive = clusivityKeyword === "through"
const openingBracketIndex = match.index + full.length - 1
const closingBracketIndex = getClosingBracket(joinedItems, "{", "}", openingBracketIndex - 1)

const content = joinedItems.substring(openingBracketIndex + 1, closingBracketIndex)

const [start, end, step] = [parseInt(startStr), parseInt(endStr), parseInt(stepStr)]
const [start, end, step] = [parseInt(startString), parseInt(endString), parseInt(stepString)]
if (step === 0) throw new Error("For loop would cause an infinite loop")

// Replace "For.[variable]" with the current index
Expand Down

0 comments on commit ccb1e73

Please sign in to comment.