MCPcopy Index your code
hub / github.com/nodejs/node / scanJsxToken

Function scanJsxToken

test/fixtures/snapshot/typescript.js:12028–12090  ·  view source on GitHub ↗
(allowMultilineJsxText)

Source from the content-addressed store, hash-verified

12026 return token = 57 /* SyntaxKind.QuestionToken */;
12027 }
12028 function scanJsxToken(allowMultilineJsxText) {
12029 if (allowMultilineJsxText === void 0) { allowMultilineJsxText = true; }
12030 startPos = tokenPos = pos;
12031 if (pos >= end) {
12032 return token = 1 /* SyntaxKind.EndOfFileToken */;
12033 }
12034 var char = text.charCodeAt(pos);
12035 if (char === 60 /* CharacterCodes.lessThan */) {
12036 if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
12037 pos += 2;
12038 return token = 30 /* SyntaxKind.LessThanSlashToken */;
12039 }
12040 pos++;
12041 return token = 29 /* SyntaxKind.LessThanToken */;
12042 }
12043 if (char === 123 /* CharacterCodes.openBrace */) {
12044 pos++;
12045 return token = 18 /* SyntaxKind.OpenBraceToken */;
12046 }
12047 // First non-whitespace character on this line.
12048 var firstNonWhitespace = 0;
12049 // These initial values are special because the first line is:
12050 // firstNonWhitespace = 0 to indicate that we want leading whitespace,
12051 while (pos < end) {
12052 char = text.charCodeAt(pos);
12053 if (char === 123 /* CharacterCodes.openBrace */) {
12054 break;
12055 }
12056 if (char === 60 /* CharacterCodes.lessThan */) {
12057 if (isConflictMarkerTrivia(text, pos)) {
12058 pos = scanConflictMarkerTrivia(text, pos, error);
12059 return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
12060 }
12061 break;
12062 }
12063 if (char === 62 /* CharacterCodes.greaterThan */) {
12064 error(ts.Diagnostics.Unexpected_token_Did_you_mean_or_gt, pos, 1);
12065 }
12066 if (char === 125 /* CharacterCodes.closeBrace */) {
12067 error(ts.Diagnostics.Unexpected_token_Did_you_mean_or_rbrace, pos, 1);
12068 }
12069 // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
12070 // i.e (- : whitespace)
12071 // <div>----
12072 // </div> becomes <div></div>
12073 //
12074 // <div>----</div> becomes <div>----</div>
12075 if (isLineBreak(char) && firstNonWhitespace === 0) {
12076 firstNonWhitespace = -1;
12077 }
12078 else if (!allowMultilineJsxText && isLineBreak(char) && firstNonWhitespace > 0) {
12079 // Stop JsxText on each line during formatting. This allows the formatter to
12080 // indent each line correctly.
12081 break;
12082 }
12083 else if (!isWhiteSpaceLike(char)) {
12084 firstNonWhitespace = pos;
12085 }

Callers 1

reScanJsxTokenFunction · 0.85

Calls 5

isConflictMarkerTriviaFunction · 0.85
scanConflictMarkerTriviaFunction · 0.85
isLineBreakFunction · 0.85
isWhiteSpaceLikeFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…