fix(language-service): CRLF offset in inline template (#34737)
This commit fixes incorrect CRLF offsets in inline template. PR closes https://github.com/angular/vscode-ng-language-service/issues/520 PR Close #34737
This commit is contained in:
@ -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<div>\r\n{{line0}}\r\n{{line1}}\r\n{{line2}}\r\n</div>');
|
||||
const ngDiags = ngLS.getDiagnostics(fileName);
|
||||
const content = mockHost.override(
|
||||
TEST_TEMPLATE, '\r\n<div>\r\n{{line0}}\r\n{{line1}}\r\n{{line2}}\r\n</div>');
|
||||
const ngDiags = ngLS.getDiagnostics(TEST_TEMPLATE);
|
||||
expect(ngDiags.length).toBe(3);
|
||||
for (let i = 0; i < 3; ++i) {
|
||||
const {messageText, start, length} = ngDiags[i];
|
||||
@ -828,6 +827,21 @@ describe('diagnostics', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should work correctly with CRLF endings in inline template', () => {
|
||||
const fileName = mockHost.addCode(
|
||||
'\n@Component({template:`\r\n\r\n{{line}}`})export class ComponentCRLF {}');
|
||||
const content = mockHost.readFile(fileName) !;
|
||||
const ngDiags = ngLS.getDiagnostics(fileName);
|
||||
expect(ngDiags.length).toBeGreaterThan(0);
|
||||
const {messageText, start, length} = ngDiags[0];
|
||||
expect(messageText)
|
||||
.toBe(
|
||||
`Identifier 'line' is not defined. ` +
|
||||
`The component declaration, template variable declarations, and ` +
|
||||
`element references do not contain such a member`);
|
||||
expect(content.substring(start !, start ! + length !)).toBe('line');
|
||||
});
|
||||
|
||||
it('should not produce diagnostics for non-exported directives', () => {
|
||||
const fileName = '/app/test.component.ts';
|
||||
mockHost.addScript(fileName, `
|
||||
|
Reference in New Issue
Block a user