Skip to content

Commit d49ee24

Browse files
committed
2 parents 7e27805 + 162639f commit d49ee24

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/modules/twoslash.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const CODEBLOCK = '```';
1111
// bad. It doesn't properly handle escaping back ticks, so we instead insert zero width spaces
1212
// so that users cannot escape our code block.
1313
function escapeCode(code: string) {
14-
return code.replace(/```/g, '`\u200B`\u200B`');
14+
return code.replace(/`(?=`)/g, '`\u200B');
15+
}
16+
17+
// Remove `@noErrorTruncation` from the source; this can cause lag/crashes for large errors
18+
function redactNoErrorTruncation(code: string) {
19+
return code.replace(/@noErrorTruncation/g, '');
1520
}
1621

1722
export class TwoslashModule extends Module {
@@ -40,7 +45,7 @@ export class TwoslashModule extends Module {
4045
`:warning: could not find any TypeScript codeblocks in the past 10 messages`,
4146
);
4247

43-
const ret = twoslasher(code, 'ts', {
48+
const ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
4449
defaultOptions: { noErrorValidation: true },
4550
});
4651

@@ -85,7 +90,7 @@ export class TwoslashModule extends Module {
8590
}
8691

8792
private async twoslashBlock(msg: Message, code: string) {
88-
const ret = twoslasher(code, 'ts', {
93+
const ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
8994
defaultOptions: {
9095
noErrorValidation: true,
9196
noStaticSemanticInfo: false,

0 commit comments

Comments
 (0)