-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve keyword detection in
TSModuleDeclaration
(#15925)
- Loading branch information
Showing
5 changed files
with
51 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import assert from "node:assert"; | ||
|
||
import { locEnd, locStart } from "../loc.js"; | ||
|
||
function getTextWithoutComments(options, start, end) { | ||
let text = options.originalText.slice(start, end); | ||
|
||
for (const comment of options[Symbol.for("comments")]) { | ||
const commentStart = locStart(comment); | ||
// Comments are sorted, we can escape if the comment is after the range | ||
if (commentStart > end) { | ||
break; | ||
} | ||
|
||
const commentEnd = locEnd(comment); | ||
if (commentEnd < start) { | ||
continue; | ||
} | ||
|
||
const commentLength = commentEnd - commentStart; | ||
text = | ||
text.slice(0, commentStart - start) + | ||
" ".repeat(commentLength) + | ||
text.slice(commentEnd - start); | ||
} | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
assert(text.length === end - start); | ||
} | ||
|
||
return text; | ||
} | ||
|
||
export default getTextWithoutComments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters