diff --git a/packages/language-service/src/template.ts b/packages/language-service/src/template.ts index afd13214e1..e882b1ca81 100644 --- a/packages/language-service/src/template.ts +++ b/packages/language-service/src/template.ts @@ -98,7 +98,9 @@ export class InlineTemplate extends BaseTemplate { throw new Error(`Inline template and component class should belong to the same source file`); } this.fileName = sourceFile.fileName; - this.source = templateNode.text; + // node.text returns the TS internal representation of the normalized text, + // and all CR characters are stripped. node.getText() returns the raw text. + this.source = templateNode.getText().slice(1, -1); // strip leading and trailing quotes this.span = { // TS string literal includes surrounding quotes in the start/end offsets. start: templateNode.getStart() + 1, diff --git a/packages/language-service/test/diagnostics_spec.ts b/packages/language-service/test/diagnostics_spec.ts index 531a55a7c6..7d721cdbd3 100644 --- a/packages/language-service/test/diagnostics_spec.ts +++ b/packages/language-service/test/diagnostics_spec.ts @@ -804,16 +804,15 @@ describe('diagnostics', () => { }); }); - it('should work correctly with CRLF endings', () => { + it('should work correctly with CRLF endings in external template', () => { // https://github.com/angular/vscode-ng-language-service/issues/235 // In the example below, the string // `\r\n{{line0}}\r\n{{line1}}\r\n{{line2}}` is tokenized as a whole, // and then CRLF characters are converted to LF. // Source span information is lost in the process. - const fileName = '/app/test.ng'; - const content = - mockHost.override(fileName, '\r\n