@@ -11,7 +11,6 @@ import type {
1111 OnStartResult ,
1212 OutputFile ,
1313 PartialMessage ,
14- PartialNote ,
1514 Plugin ,
1615 PluginBuild ,
1716} from 'esbuild' ;
@@ -34,91 +33,10 @@ import { BundleStylesheetOptions, bundleComponentStylesheet } from '../styleshee
3433import { AngularCompilation , FileEmitter } from './angular-compilation' ;
3534import { AngularHostOptions } from './angular-host' ;
3635import { AotCompilation } from './aot-compilation' ;
36+ import { convertTypeScriptDiagnostic } from './diagnostics' ;
3737import { JitCompilation } from './jit-compilation' ;
3838import { setupJitPluginCallbacks } from './jit-plugin-callbacks' ;
3939
40- /**
41- * Converts TypeScript Diagnostic related information into an esbuild compatible note object.
42- * Related information is a subset of a full TypeScript Diagnostic and also used for diagnostic
43- * notes associated with the main Diagnostic.
44- * @param info The TypeScript diagnostic relative information to convert.
45- * @returns An esbuild diagnostic message as a PartialMessage object
46- */
47- function convertTypeScriptDiagnosticInfo (
48- info : ts . DiagnosticRelatedInformation ,
49- textPrefix ?: string ,
50- ) : PartialNote {
51- const newLine = platform ( ) === 'win32' ? '\r\n' : '\n' ;
52- let text = ts . flattenDiagnosticMessageText ( info . messageText , newLine ) ;
53- if ( textPrefix ) {
54- text = textPrefix + text ;
55- }
56-
57- const note : PartialNote = { text } ;
58-
59- if ( info . file ) {
60- note . location = {
61- file : info . file . fileName ,
62- length : info . length ,
63- } ;
64-
65- // Calculate the line/column location and extract the full line text that has the diagnostic
66- if ( info . start ) {
67- const { line, character } = ts . getLineAndCharacterOfPosition ( info . file , info . start ) ;
68- note . location . line = line + 1 ;
69- note . location . column = character ;
70-
71- // The start position for the slice is the first character of the error line
72- const lineStartPosition = ts . getPositionOfLineAndCharacter ( info . file , line , 0 ) ;
73-
74- // The end position for the slice is the first character of the next line or the length of
75- // the entire file if the line is the last line of the file (getPositionOfLineAndCharacter
76- // will error if a nonexistent line is passed).
77- const { line : lastLineOfFile } = ts . getLineAndCharacterOfPosition (
78- info . file ,
79- info . file . text . length - 1 ,
80- ) ;
81- const lineEndPosition =
82- line < lastLineOfFile
83- ? ts . getPositionOfLineAndCharacter ( info . file , line + 1 , 0 )
84- : info . file . text . length ;
85-
86- note . location . lineText = info . file . text . slice ( lineStartPosition , lineEndPosition ) . trimEnd ( ) ;
87- }
88- }
89-
90- return note ;
91- }
92-
93- /**
94- * Converts a TypeScript Diagnostic message into an esbuild compatible message object.
95- * @param diagnostic The TypeScript diagnostic to convert.
96- * @returns An esbuild diagnostic message as a PartialMessage object
97- */
98- function convertTypeScriptDiagnostic ( diagnostic : ts . Diagnostic ) : PartialMessage {
99- let codePrefix = 'TS' ;
100- let code = `${ diagnostic . code } ` ;
101- if ( diagnostic . source === 'ngtsc' ) {
102- codePrefix = 'NG' ;
103- // Remove `-99` Angular prefix from diagnostic code
104- code = code . slice ( 3 ) ;
105- }
106-
107- const message : PartialMessage = {
108- ...convertTypeScriptDiagnosticInfo ( diagnostic , `${ codePrefix } ${ code } : ` ) ,
109- // Store original diagnostic for reference if needed downstream
110- detail : diagnostic ,
111- } ;
112-
113- if ( diagnostic . relatedInformation ?. length ) {
114- message . notes = diagnostic . relatedInformation . map ( ( info ) =>
115- convertTypeScriptDiagnosticInfo ( info ) ,
116- ) ;
117- }
118-
119- return message ;
120- }
121-
12240const USING_WINDOWS = platform ( ) === 'win32' ;
12341const WINDOWS_SEP_REGEXP = new RegExp ( `\\${ path . win32 . sep } ` , 'g' ) ;
12442
0 commit comments