MCPcopy Create free account
hub / github.com/effect-app/libs / findMatchingBrace

Function findMatchingBrace

packages/eslint-codegen-model/src/cli.ts:68–126  ·  view source on GitHub ↗
(source: string, openIndex: number)

Source from the content-addressed store, hash-verified

66}
67
68function findMatchingBrace(source: string, openIndex: number): number {
69 let depth = 0
70 let quote: "\"" | "'" | "`" | undefined
71 let escaped = false
72 let lineComment = false
73 let blockComment = false
74
75 for (let index = openIndex; index < source.length; index++) {
76 const char = source[index]!
77 const next = source[index + 1]
78
79 if (lineComment) {
80 if (char === "\n") lineComment = false
81 continue
82 }
83 if (blockComment) {
84 if (char === "*" && next === "/") {
85 blockComment = false
86 index++
87 }
88 continue
89 }
90 if (quote) {
91 if (escaped) {
92 escaped = false
93 } else if (char === "\\") {
94 escaped = true
95 } else if (char === quote) {
96 quote = undefined
97 }
98 continue
99 }
100
101 if (char === "/" && next === "/") {
102 lineComment = true
103 index++
104 continue
105 }
106 if (char === "/" && next === "*") {
107 blockComment = true
108 index++
109 continue
110 }
111 if (char === "\"" || char === "'" || char === "`") {
112 quote = char
113 continue
114 }
115 if (char === "{") {
116 depth++
117 continue
118 }
119 if (char === "}") {
120 depth--
121 if (depth === 0) return index
122 }
123 }
124
125 return -1

Callers 2

findClassEndFunction · 0.85
tryStructPrivateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…