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

Function statementEnd

src/resolution/frameworks/react.ts:1786–1807  ·  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

1784 * across, where JavaScript ends a statement without a semicolon.
1785 */
1786function statementEnd(text: string, from: number, comma = false): number {
1787 let last = '';
1788 for (let i = from; i < text.length; i++) {
1789 const ch = text[i]!;
1790 if (ch === '"' || ch === "'" || ch === '`' || ch === '{' || ch === '(' || ch === '[') {
1791 const end = ch === '{' || ch === '(' || ch === '[' ? matchBracket(text, i) : skipString(text, i);
1792 if (end < 0) return text.length;
1793 i = end;
1794 last = text[end]!;
1795 continue;
1796 }
1797 if (ch === ';' || ch === '}' || ch === ')' || ch === ']' || (comma && ch === ',')) return i;
1798 if (ch === '\n') {
1799 let j = i + 1;
1800 while (j < text.length && /\s/.test(text[j]!)) j++;
1801 if (last && !/[=(,[{?:&|+\-*/%<>!.]/.test(last) && !/[.?:&|+\-*/%=<>,([]/.test(text[j] ?? '')) return i;
1802 continue;
1803 }
1804 if (!/\s/.test(ch)) last = ch;
1805 }
1806 return text.length;
1807}
1808
1809/** What expression `text` evaluates to in a loader, or null when it is not one this reads. */
1810function 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