fix(language-service): Update types for TypeScript nullability support
This commit is contained in:
@ -48,7 +48,7 @@ describe('completions', () => {
|
||||
const fileName = '/app/test.ng';
|
||||
mockHost.override(fileName, ' > {{tle<\n {{retl ><bel/beled}}di>\n la</b </d &a ');
|
||||
expect(() => ngService.getCompletionsAt(fileName, 31)).not.toThrow();
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
});
|
||||
|
||||
it('should be able to infer the type of a ngForOf', () => {
|
||||
@ -101,7 +101,7 @@ describe('completions', () => {
|
||||
}
|
||||
}
|
||||
try {
|
||||
const originalContent = mockHost.getFileContent(fileName);
|
||||
const originalContent = mockHost.getFileContent(fileName) !;
|
||||
|
||||
// For each character in the file, add it to the file and request a completion after it.
|
||||
for (let index = 0, len = originalContent.length; index < len; index++) {
|
||||
@ -133,7 +133,7 @@ describe('completions', () => {
|
||||
tryCompletionsAt(position);
|
||||
});
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}).not.toThrow();
|
||||
});
|
||||
@ -169,12 +169,12 @@ export class MyComponent {
|
||||
try {
|
||||
cb(fileName, newContent);
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}
|
||||
|
||||
function contains(fileName: string, locationMarker: string, ...names: string[]) {
|
||||
let location = mockHost.getMarkerLocations(fileName)[locationMarker];
|
||||
let location = mockHost.getMarkerLocations(fileName) ![locationMarker];
|
||||
if (location == null) {
|
||||
throw new Error(`No marker ${locationMarker} found.`);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ describe('definitions', () => {
|
||||
|
||||
function localReference(code: string) {
|
||||
addCode(code, fileName => {
|
||||
const refResult = mockHost.getReferenceMarkers(fileName);
|
||||
const refResult = mockHost.getReferenceMarkers(fileName) !;
|
||||
for (const name in refResult.references) {
|
||||
const references = refResult.references[name];
|
||||
const definitions = refResult.definitions[name];
|
||||
@ -100,14 +100,14 @@ describe('definitions', () => {
|
||||
const definition: string = p2 ? p1 : undefined;
|
||||
let span: Span = p2 && p1.start != null ? p1 : undefined;
|
||||
if (definition && !span) {
|
||||
const referencedFileMarkers = mockHost.getReferenceMarkers(referencedFile);
|
||||
const referencedFileMarkers = mockHost.getReferenceMarkers(referencedFile) !;
|
||||
expect(referencedFileMarkers).toBeDefined(); // If this fails the test data is wrong.
|
||||
const spans = referencedFileMarkers.definitions[definition];
|
||||
expect(spans).toBeDefined(); // If this fails the test data is wrong.
|
||||
span = spans[0];
|
||||
}
|
||||
addCode(code, fileName => {
|
||||
const refResult = mockHost.getReferenceMarkers(fileName);
|
||||
const refResult = mockHost.getReferenceMarkers(fileName) !;
|
||||
let tests = 0;
|
||||
for (const name in refResult.references) {
|
||||
const references = refResult.references[name];
|
||||
@ -144,12 +144,12 @@ describe('definitions', () => {
|
||||
try {
|
||||
cb(fileName, newContent);
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function matchingSpan(aSpans: Span[], bSpans: Span[]): Span {
|
||||
function matchingSpan(aSpans: Span[], bSpans: Span[]): Span|undefined {
|
||||
for (const a of aSpans) {
|
||||
for (const b of bSpans) {
|
||||
if (a.start == b.start && a.end == b.end) {
|
||||
|
@ -32,9 +32,9 @@ describe('diagnostics', () => {
|
||||
function diagnostics(template: string): Diagnostics {
|
||||
try {
|
||||
mockHost.override(fileName, template);
|
||||
return ngService.getDiagnostics(fileName);
|
||||
return ngService.getDiagnostics(fileName) !;
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,10 +84,10 @@ describe('diagnostics', () => {
|
||||
const code = '\n@Component({template: \'<div></div>\'}) export class MyComponent {}';
|
||||
addCode(code, (fileName, content) => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
const offset = content.lastIndexOf('@Component') + 1;
|
||||
const offset = content !.lastIndexOf('@Component') + 1;
|
||||
const len = 'Component'.length;
|
||||
includeDiagnostic(
|
||||
diagnostics, 'Component \'MyComponent\' is not included in a module', offset, len);
|
||||
diagnostics !, 'Component \'MyComponent\' is not included in a module', offset, len);
|
||||
});
|
||||
});
|
||||
|
||||
@ -95,7 +95,7 @@ describe('diagnostics', () => {
|
||||
const code = '\n@Component({template: \'<form></form>\'}) export class MyComponent {}';
|
||||
addCode(code, (fileName, content) => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
onlyModuleDiagnostics(diagnostics);
|
||||
onlyModuleDiagnostics(diagnostics !);
|
||||
});
|
||||
});
|
||||
|
||||
@ -119,7 +119,7 @@ describe('diagnostics', () => {
|
||||
addCode(code, (fileName, content) => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
includeDiagnostic(
|
||||
diagnostics, 'Function calls are not supported.', '() => \'foo\'', content);
|
||||
diagnostics !, 'Function calls are not supported.', '() => \'foo\'', content);
|
||||
});
|
||||
});
|
||||
|
||||
@ -134,7 +134,7 @@ describe('diagnostics', () => {
|
||||
` @Component({template: \`<div *ngIf="something === 'foo'"></div>\`}) export class MyComponent { something: 'foo' | 'bar'; }`;
|
||||
addCode(code, fileName => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
onlyModuleDiagnostics(diagnostics);
|
||||
onlyModuleDiagnostics(diagnostics !);
|
||||
});
|
||||
});
|
||||
|
||||
@ -144,7 +144,7 @@ describe('diagnostics', () => {
|
||||
addCode(code, (fileName, content) => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
includeDiagnostic(
|
||||
diagnostics, 'Unexpected callable expression. Expected a method call', 'onClick',
|
||||
diagnostics !, 'Unexpected callable expression. Expected a method call', 'onClick',
|
||||
content);
|
||||
});
|
||||
});
|
||||
@ -155,7 +155,7 @@ describe('diagnostics', () => {
|
||||
` @Component({template: \`<div *ngIf="something === undefined"></div>\`}) export class MyComponent { something = 'foo'; }})`;
|
||||
addCode(code, fileName => {
|
||||
const diagnostics = ngService.getDiagnostics(fileName);
|
||||
onlyModuleDiagnostics(diagnostics);
|
||||
onlyModuleDiagnostics(diagnostics !);
|
||||
});
|
||||
});
|
||||
|
||||
@ -165,7 +165,7 @@ describe('diagnostics', () => {
|
||||
` @Component({template: '<p> Using an invalid pipe {{data | dat}} </p>'}) export class MyComponent { data = 'some data'; }`;
|
||||
addCode(code, fileName => {
|
||||
const diagnostic =
|
||||
ngService.getDiagnostics(fileName).filter(d => d.message.indexOf('pipe') > 0)[0];
|
||||
ngService.getDiagnostics(fileName) !.filter(d => d.message.indexOf('pipe') > 0)[0];
|
||||
expect(diagnostic).not.toBeUndefined();
|
||||
expect(diagnostic.span.end - diagnostic.span.start).toBeLessThan(11);
|
||||
});
|
||||
@ -267,7 +267,7 @@ describe('diagnostics', () => {
|
||||
try {
|
||||
cb(fileName, newContent);
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ describe('hover', () => {
|
||||
function hover(code: string, hoverText: string) {
|
||||
addCode(code, fileName => {
|
||||
let tests = 0;
|
||||
const markers = mockHost.getReferenceMarkers(fileName);
|
||||
const markers = mockHost.getReferenceMarkers(fileName) !;
|
||||
const keys = Object.keys(markers.references).concat(Object.keys(markers.definitions));
|
||||
for (const referenceName of keys) {
|
||||
const references = (markers.references[referenceName] ||
|
||||
@ -96,7 +96,7 @@ describe('hover', () => {
|
||||
try {
|
||||
cb(fileName, newContent);
|
||||
} finally {
|
||||
mockHost.override(fileName, undefined);
|
||||
mockHost.override(fileName, undefined !);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ describe('service without angular', () => {
|
||||
let ngHost = new TypeScriptServiceHost(mockHost, service);
|
||||
let ngService = createLanguageService(ngHost);
|
||||
const fileName = '/app/test.ng';
|
||||
let position = mockHost.getMarkerLocations(fileName)['h1-content'];
|
||||
let position = mockHost.getMarkerLocations(fileName) !['h1-content'];
|
||||
|
||||
it('should not crash a get template references',
|
||||
() => expect(() => ngService.getTemplateReferences()));
|
||||
|
@ -21,7 +21,7 @@ describe('references', () => {
|
||||
let service: ts.LanguageService;
|
||||
let program: ts.Program;
|
||||
let ngHost: TypeScriptServiceHost;
|
||||
let ngService: LanguageService = createLanguageService(ngHost);
|
||||
let ngService: LanguageService = createLanguageService(undefined !);
|
||||
|
||||
beforeEach(() => {
|
||||
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
|
||||
|
@ -63,7 +63,7 @@ missingCache.set(
|
||||
missingCache.set('/node_modules/@angular/forms/src/directives/form_interface.metadata.json', true);
|
||||
|
||||
export class MockTypescriptHost implements ts.LanguageServiceHost {
|
||||
private angularPath: string;
|
||||
private angularPath: string|undefined;
|
||||
private nodeModulesPath: string;
|
||||
private scriptVersion = new Map<string, number>();
|
||||
private overrides = new Map<string, string>();
|
||||
@ -120,7 +120,7 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
|
||||
return (this.scriptVersion.get(fileName) || 0).toString();
|
||||
}
|
||||
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot|undefined {
|
||||
const content = this.getFileContent(fileName);
|
||||
if (content) return ts.ScriptSnapshot.fromString(content);
|
||||
return undefined;
|
||||
@ -145,19 +145,19 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
|
||||
}
|
||||
}
|
||||
|
||||
getReferenceMarkers(fileName: string): ReferenceResult {
|
||||
getReferenceMarkers(fileName: string): ReferenceResult|undefined {
|
||||
let content = this.getRawFileContent(fileName);
|
||||
if (content) {
|
||||
return getReferenceMarkers(content);
|
||||
}
|
||||
}
|
||||
|
||||
getFileContent(fileName: string): string {
|
||||
getFileContent(fileName: string): string|undefined {
|
||||
const content = this.getRawFileContent(fileName);
|
||||
if (content) return removeReferenceMarkers(removeLocationMarkers(content));
|
||||
}
|
||||
|
||||
private getRawFileContent(fileName: string): string {
|
||||
private getRawFileContent(fileName: string): string|undefined {
|
||||
if (this.overrides.has(fileName)) {
|
||||
return this.overrides.get(fileName);
|
||||
}
|
||||
@ -225,7 +225,7 @@ function find(fileName: string, data: MockData): MockData|undefined {
|
||||
if (typeof current === 'string')
|
||||
return undefined;
|
||||
else
|
||||
current = (<MockDirectory>current)[name];
|
||||
current = (<MockDirectory>current)[name] !;
|
||||
if (!current) return undefined;
|
||||
}
|
||||
return current;
|
||||
@ -241,7 +241,7 @@ function open(fileName: string, data: MockData): string|undefined {
|
||||
|
||||
function directoryExists(dirname: string, data: MockData): boolean {
|
||||
let result = find(dirname, data);
|
||||
return result && typeof result !== 'string';
|
||||
return !!result && typeof result !== 'string';
|
||||
}
|
||||
|
||||
const locationMarker = /\~\{(\w+(-\w+)*)\}/g;
|
||||
|
@ -195,7 +195,7 @@ describe('plugin', () => {
|
||||
});
|
||||
|
||||
function getMarkerLocation(fileName: string, locationMarker: string): number {
|
||||
const location = mockHost.getMarkerLocations(fileName)[locationMarker];
|
||||
const location = mockHost.getMarkerLocations(fileName) ![locationMarker];
|
||||
if (location == null) {
|
||||
throw new Error(`No marker ${locationMarker} found.`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user