Skip to content

Commit 09dfac7

Browse files
committed
feat: typescript 3.6 support followup
1 parent 0aee256 commit 09dfac7

8 files changed

Lines changed: 29 additions & 24 deletions

File tree

packages/compiler-cli/src/perform_compile.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ export function formatDiagnosticPosition(
3636
}
3737

3838
export function flattenDiagnosticMessageChain(
39-
chain: api.DiagnosticMessageChain, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
40-
let result = chain.messageText;
41-
let indent = 1;
42-
let current = chain.next;
39+
chain: api.DiagnosticMessageChain, host: ts.FormatDiagnosticsHost = defaultFormatHost, indent = 0): string {
4340
const newLine = host.getNewLine();
44-
while (current) {
41+
let result = "";
42+
if (indent) {
4543
result += newLine;
44+
4645
for (let i = 0; i < indent; i++) {
47-
result += ' ';
46+
result += " ";
4847
}
49-
result += current.messageText;
50-
const position = current.position;
51-
if (position) {
52-
result += ` at ${formatDiagnosticPosition(position, host)}`;
48+
}
49+
result += chain.messageText;
50+
indent++;
51+
if (chain.next) {
52+
for (const kid of chain.next) {
53+
result += flattenDiagnosticMessageChain(kid, host, indent);
5354
}
54-
current = current.next;
55-
indent++;
5655
}
5756
return result;
5857
}

packages/compiler-cli/src/transformers/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ function diagnosticChainFromFormattedDiagnosticChain(chain: FormattedMessageChai
11091109
DiagnosticMessageChain {
11101110
return {
11111111
messageText: chain.message,
1112-
next: chain.next && diagnosticChainFromFormattedDiagnosticChain(chain.next),
1112+
next: chain.next && chain.next.map(diagnosticChainFromFormattedDiagnosticChain),
11131113
position: chain.position
11141114
};
11151115
}

packages/compiler-cli/test/diagnostics/expression_diagnostics_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('expression diagnostics', () => {
3939
if (typeof messageText == 'string') {
4040
return messageText;
4141
} else {
42-
if (messageText.next) return messageText.messageText + messageToString(messageText.next);
42+
if (messageText.next) return messageText.messageText + messageText.next.map(messageToString);
4343
return messageText.messageText;
4444
}
4545
}

packages/compiler/src/aot/formatted_error.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface Position {
1717
export interface FormattedMessageChain {
1818
message: string;
1919
position?: Position;
20-
next?: FormattedMessageChain;
20+
next?: FormattedMessageChain[];
2121
}
2222

2323
export type FormattedError = Error & {
@@ -41,9 +41,15 @@ function formatChain(chain: FormattedMessageChain | undefined, indent: number =
4141
'';
4242
const prefix = position && indent === 0 ? `${position}: ` : '';
4343
const postfix = position && indent !== 0 ? ` at ${position}` : '';
44-
const message = `${prefix}${chain.message}${postfix}`;
44+
let message = `${prefix}${chain.message}${postfix}`;
4545

46-
return `${indentStr(indent)}${message}${(chain.next && ('\n' + formatChain(chain.next, indent + 2))) || ''}`;
46+
if (chain.next) {
47+
for (const kid of chain.next) {
48+
message += formatChain(kid, indent + 2);
49+
}
50+
}
51+
52+
return `${indentStr(indent)}${message}`;
4753
}
4854

4955
export function formattedError(chain: FormattedMessageChain): FormattedError {

packages/compiler/src/aot/static_reflector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ function formatMetadataMessageChain(
10561056
const next: FormattedMessageChain|undefined = chain.next ?
10571057
formatMetadataMessageChain(chain.next, advise) :
10581058
advise ? {message: advise} : undefined;
1059-
return {message, position, next};
1059+
return { message, position, next: next ? [next]: undefined};
10601060
}
10611061

10621062
function formatMetadataError(e: Error, context: StaticSymbol): Error {

packages/language-service/src/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function chainDiagnostics(chain: ng.DiagnosticMessageChain): ts.DiagnosticMessag
219219
messageText: chain.message,
220220
category: ts.DiagnosticCategory.Error,
221221
code: 0,
222-
next: chain.next ? chainDiagnostics(chain.next) : undefined
222+
next: chain.next ? chain.next.map(chainDiagnostics) : undefined
223223
};
224224
}
225225

packages/language-service/src/typescript_host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ function spanAt(sourceFile: ts.SourceFile, line: number, column: number): Span|u
612612
}
613613

614614
function convertChain(chain: FormattedMessageChain): DiagnosticMessageChain {
615-
return {message: chain.message, next: chain.next ? convertChain(chain.next) : undefined};
615+
return { message: chain.message, next: chain.next ? chain.next.map(convertChain) : undefined};
616616
}
617617

618618
function errorToDiagnosticWithChain(error: FormattedError, span: Span): DeclarationError {

packages/language-service/test/diagnostics_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ describe('diagnostics', () => {
176176
const firstPart = messageText as ts.DiagnosticMessageChain;
177177
expect(firstPart.messageText).toBe(`Error during template compile of 'AppComponent'`);
178178
const secondPart = firstPart.next !;
179-
expect(secondPart.messageText).toBe('Function expressions are not supported in decorators');
180-
const thirdPart = secondPart.next !;
181-
expect(thirdPart.messageText)
179+
expect(secondPart[0].messageText).toBe('Function expressions are not supported in decorators');
180+
const thirdPart = secondPart[0].next !;
181+
expect(thirdPart[0].messageText)
182182
.toBe('Consider changing the function expression into an exported function');
183-
expect(thirdPart.next).toBeFalsy();
183+
expect(thirdPart[0].next).toBeFalsy();
184184
});
185185

186186
it('should not throw for an invalid class', () => {

0 commit comments

Comments
 (0)