Skip to content

Commit

Permalink
Fix some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavbls committed Sep 17, 2023
1 parent da3e1d4 commit 49449f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/format/formatDiagnosticMessage.ts
Expand Up @@ -12,6 +12,9 @@ export const formatDiagnosticMessage = (
format: (type: string) => string
) =>
message
.replaceAll(/(?:\s)'"(.*?)(?<!\\)"'(?:\s|\:|.|$)/g, (_, p1: string) =>
formatTypeBlock("", `"${p1}"`, format)
)
// format declare module snippet
.replaceAll(
/['鈥淽(declare module )['鈥漖(.*)['鈥淽;['鈥漖/g,
Expand Down Expand Up @@ -66,7 +69,7 @@ export const formatDiagnosticMessage = (
)
// Format types
.replaceAll(
/(type|type alias|interface|module|file|file name|method's|subtype of constraint) ['鈥淽(.*?)['鈥淽(?=[\s(.|,|:)]|$)/gi,
/(type|type alias|interface|module|file|file name|method's|subtype of constraint) ['鈥淽(.*?)['鈥淽(?=[\s(.|,)]|$)/gi,
(_, p1: string, p2: string) => formatTypeBlock(p1, p2, format)
)
// Format reversed types
Expand All @@ -93,6 +96,6 @@ export const formatDiagnosticMessage = (
)
// Format regular code blocks
.replaceAll(
/['鈥淽((?:(?!:\s*}).)*?)['鈥淽 (?!\s*:)/g,
(_: string, p1: string) => `${unStyledCodeBlock(p1)} `
/(?<!.*?")(?:^|\s)['鈥淽((?:(?!:\s*}).)*?)['鈥淽(?!\s*:)(?!.*?")/g,
(_: string, p1: string) => ` ${unStyledCodeBlock(p1)} `
);
4 changes: 4 additions & 0 deletions src/test/suite/errorMessageMocks.ts
Expand Up @@ -81,3 +81,7 @@ Cannot find module 'events' or its corresponding type declarations.
const ts1360Error = d`
Property 'a' is missing in type '{ b: { name: string; icon: undefined; }; c: { name: string; icon: undefined; }; d: { name: string; icon: undefined; }; e: { name: string; icon: undefined; }; f: { ...; }; g: { ...; }; h:...' but required in type '{a: {name: string; icon: undefined}}'.
`;

const errorWithStringChars = d`
Type 'null' is not assignable to type '"' 'Oh \"'no"'
`;

0 comments on commit 49449f3

Please sign in to comment.