mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Allow singleline string writer to be recursively used (#18297)
* Allow singleline string writer to be recursively used * Add unit test exposing issue * Fix lints
This commit is contained in:
1 parent
697c4d3353
commit
5c779b1edb
4 files changed
+53
-4
No files matched your search
@@ -32,7 +32,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
const stringWriter = createSingleLineStringWriter();
|
||||
let stringWriterAcquired = false;
|
||||
|
||||
function createSingleLineStringWriter(): StringSymbolWriter {
|
||||
let str = "";
|
||||
@@ -62,15 +61,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function usingSingleLineStringWriter(action: (writer: StringSymbolWriter) => void): string {
|
||||
const oldString = stringWriter.string();
|
||||
try {
|
||||
Debug.assert(!stringWriterAcquired);
|
||||
stringWriterAcquired = true;
|
||||
action(stringWriter);
|
||||
return stringWriter.string();
|
||||
}
|
||||
finally {
|
||||
stringWriter.clear();
|
||||
stringWriterAcquired = false;
|
||||
stringWriter.writeKeyword(oldString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user