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

Function scanTemplateAndSetTokenValue

test/fixtures/snapshot/typescript.js:11094–11147  ·  view source on GitHub ↗

* Sets the current 'tokenValue' and returns a NoSubstitutionTemplateLiteral or * a literal component of a TemplateExpression.

(isTaggedTemplate)

Source from the content-addressed store, hash-verified

11092 * a literal component of a TemplateExpression.
11093 */
11094 function scanTemplateAndSetTokenValue(isTaggedTemplate) {
11095 var startedWithBacktick = text.charCodeAt(pos) === 96 /* CharacterCodes.backtick */;
11096 pos++;
11097 var start = pos;
11098 var contents = "";
11099 var resultingToken;
11100 while (true) {
11101 if (pos >= end) {
11102 contents += text.substring(start, pos);
11103 tokenFlags |= 4 /* TokenFlags.Unterminated */;
11104 error(ts.Diagnostics.Unterminated_template_literal);
11105 resultingToken = startedWithBacktick ? 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ : 17 /* SyntaxKind.TemplateTail */;
11106 break;
11107 }
11108 var currChar = text.charCodeAt(pos);
11109 // '`'
11110 if (currChar === 96 /* CharacterCodes.backtick */) {
11111 contents += text.substring(start, pos);
11112 pos++;
11113 resultingToken = startedWithBacktick ? 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ : 17 /* SyntaxKind.TemplateTail */;
11114 break;
11115 }
11116 // '${'
11117 if (currChar === 36 /* CharacterCodes.$ */ && pos + 1 < end && text.charCodeAt(pos + 1) === 123 /* CharacterCodes.openBrace */) {
11118 contents += text.substring(start, pos);
11119 pos += 2;
11120 resultingToken = startedWithBacktick ? 15 /* SyntaxKind.TemplateHead */ : 16 /* SyntaxKind.TemplateMiddle */;
11121 break;
11122 }
11123 // Escape character
11124 if (currChar === 92 /* CharacterCodes.backslash */) {
11125 contents += text.substring(start, pos);
11126 contents += scanEscapeSequence(isTaggedTemplate);
11127 start = pos;
11128 continue;
11129 }
11130 // Speculated ECMAScript 6 Spec 11.8.6.1:
11131 // <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> for Template Values
11132 if (currChar === 13 /* CharacterCodes.carriageReturn */) {
11133 contents += text.substring(start, pos);
11134 pos++;
11135 if (pos < end && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
11136 pos++;
11137 }
11138 contents += "\n";
11139 start = pos;
11140 continue;
11141 }
11142 pos++;
11143 }
11144 ts.Debug.assert(resultingToken !== undefined);
11145 tokenValue = contents;
11146 return resultingToken;
11147 }
11148 function scanEscapeSequence(isTaggedTemplate) {
11149 var start = pos;
11150 pos++;

Callers 3

scanFunction · 0.85
reScanTemplateTokenFunction · 0.85

Calls 3

scanEscapeSequenceFunction · 0.85
assertMethod · 0.80
errorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…