MCPcopy
hub / github.com/jquery/esprima / scanComments

Method scanComments

src/scanner.ts:240–306  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238 }
239
240 public scanComments() {
241 let comments;
242 if (this.trackComment) {
243 comments = [];
244 }
245
246 let start = (this.index === 0);
247 while (!this.eof()) {
248 let ch = this.source.charCodeAt(this.index);
249
250 if (Character.isWhiteSpace(ch)) {
251 ++this.index;
252 } else if (Character.isLineTerminator(ch)) {
253 ++this.index;
254 if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
255 ++this.index;
256 }
257 ++this.lineNumber;
258 this.lineStart = this.index;
259 start = true;
260 } else if (ch === 0x2F) { // U+002F is '/'
261 ch = this.source.charCodeAt(this.index + 1);
262 if (ch === 0x2F) {
263 this.index += 2;
264 const comment = this.skipSingleLineComment(2);
265 if (this.trackComment) {
266 comments = comments.concat(comment);
267 }
268 start = true;
269 } else if (ch === 0x2A) { // U+002A is '*'
270 this.index += 2;
271 const comment = this.skipMultiLineComment();
272 if (this.trackComment) {
273 comments = comments.concat(comment);
274 }
275 } else {
276 break;
277 }
278 } else if (start && ch === 0x2D) { // U+002D is '-'
279 // U+003E is '>'
280 if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
281 // '-->' is a single-line comment
282 this.index += 3;
283 const comment = this.skipSingleLineComment(3);
284 if (this.trackComment) {
285 comments = comments.concat(comment);
286 }
287 } else {
288 break;
289 }
290 } else if (ch === 0x3C && !this.isModule) { // U+003C is '<'
291 if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
292 this.index += 4; // `<!--`
293 const comment = this.skipSingleLineComment(4);
294 if (this.trackComment) {
295 comments = comments.concat(comment);
296 }
297 } else {

Callers 5

peekJSXTokenMethod · 0.80
collectCommentsMethod · 0.80
isLexicalDeclarationMethod · 0.80
matchAsyncFunctionMethod · 0.80
getNextTokenMethod · 0.80

Calls 3

eofMethod · 0.95
skipSingleLineCommentMethod · 0.95
skipMultiLineCommentMethod · 0.95

Tested by

no test coverage detected