MCPcopy Create free account
hub / github.com/nodejs/node / formatOnOpeningCurly

Function formatOnOpeningCurly

test/fixtures/snapshot/typescript.js:147005–147029  ·  view source on GitHub ↗
(position, sourceFile, formatContext)

Source from the content-addressed store, hash-verified

147003 }
147004 formatting.formatOnSemicolon = formatOnSemicolon;
147005 function formatOnOpeningCurly(position, sourceFile, formatContext) {
147006 var openingCurly = findImmediatelyPrecedingTokenOfKind(position, 18 /* SyntaxKind.OpenBraceToken */, sourceFile);
147007 if (!openingCurly) {
147008 return [];
147009 }
147010 var curlyBraceRange = openingCurly.parent;
147011 var outermostNode = findOutermostNodeWithinListLevel(curlyBraceRange);
147012 /**
147013 * We limit the span to end at the opening curly to handle the case where
147014 * the brace matched to that just typed will be incorrect after further edits.
147015 * For example, we could type the opening curly for the following method
147016 * body without brace-matching activated:
147017 * ```
147018 * class C {
147019 * foo()
147020 * }
147021 * ```
147022 * and we wouldn't want to move the closing brace.
147023 */
147024 var textRange = {
147025 pos: ts.getLineStartPositionForPosition(outermostNode.getStart(sourceFile), sourceFile),
147026 end: position
147027 };
147028 return formatSpan(textRange, sourceFile, formatContext, 4 /* FormattingRequestKind.FormatOnOpeningCurlyBrace */);
147029 }
147030 formatting.formatOnOpeningCurly = formatOnOpeningCurly;
147031 function formatOnClosingCurly(position, sourceFile, formatContext) {
147032 var precedingToken = findImmediatelyPrecedingTokenOfKind(position, 19 /* SyntaxKind.CloseBraceToken */, sourceFile);

Callers

nothing calls this directly

Calls 3

formatSpanFunction · 0.85

Tested by

no test coverage detected