MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / statementEnd

Function statementEnd

src/resolution/frameworks/react.ts:1808–1829  ·  view source on GitHub ↗

* Where the statement or declarator from `from` ends: at a `;`, a closing * bracket, a `,` when `comma`, or at a line break neither line continues * across, where JavaScript ends a statement without a semicolon.

(text: string, from: number, comma = false)

Source from the content-addressed store, hash-verified

1806 * across, where JavaScript ends a statement without a semicolon.
1807 */
1808function statementEnd(text: string, from: number, comma = false): number {
1809 let last = '';
1810 for (let i = from; i < text.length; i++) {
1811 const ch = text[i]!;
1812 if (ch === '"' || ch === "'" || ch === '`' || ch === '{' || ch === '(' || ch === '[') {
1813 const end = ch === '{' || ch === '(' || ch === '[' ? matchBracket(text, i) : skipString(text, i);
1814 if (end < 0) return text.length;
1815 i = end;
1816 last = text[end]!;
1817 continue;
1818 }
1819 if (ch === ';' || ch === '}' || ch === ')' || ch === ']' || (comma && ch === ',')) return i;
1820 if (ch === '\n') {
1821 let j = i + 1;
1822 while (j < text.length && /\s/.test(text[j]!)) j++;
1823 if (last && !/[=(,[{?:&|+\-*/%<>!.]/.test(last) && !/[.?:&|+\-*/%=<>,([]/.test(text[j] ?? '')) return i;
1824 continue;
1825 }
1826 if (!/\s/.test(ch)) last = ch;
1827 }
1828 return text.length;
1829}
1830
1831/** What expression `text` evaluates to in a loader, or null when it is not one this reads. */
1832function valueOf(text: string, scope: LoaderScope): Loaded | null {

Callers 6

defaultExportedNameFunction · 0.70
heldBindingFunction · 0.70
handedComponentFunction · 0.70
wrappedComponentNameFunction · 0.70
blockValueFunction · 0.70
declareFunction · 0.70

Calls 2

matchBracketFunction · 0.90
skipStringFunction · 0.90

Tested by

no test coverage detected