Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): do not crash when Angular cannot be located #14123

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/@angular/compiler/src/aot/static_symbol_resolver.ts
Expand Up @@ -321,7 +321,12 @@ export class StaticSymbolResolver {
getSymbolByModule(module: string, symbolName: string, containingFile?: string): StaticSymbol {
const filePath = this.resolveModule(module, containingFile);
if (!filePath) {
throw new Error(`Could not resolve module ${module} relative to ${containingFile}`);
this.reportError(
new Error(`Could not resolve module ${module}${containingFile ? ` relative to $ {
containingFile
} `: ''}`),
null);
return this.getStaticSymbol(`ERROR:${module}`, symbolName);
}
return this.getStaticSymbol(filePath, symbolName);
}
Expand Down
36 changes: 36 additions & 0 deletions modules/@angular/language-service/test/language_service_spec.ts
@@ -0,0 +1,36 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import * as ts from 'typescript';

import {createLanguageService} from '../src/language_service';
import {Completions, LanguageService} from '../src/types';
import {TypeScriptServiceHost} from '../src/typescript_host';

import {toh} from './test_data';
import {MockTypescriptHost} from './test_utils';

describe('service without angular', () => {
let mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts'], toh);
mockHost.forgetAngular();
let service = ts.createLanguageService(mockHost);
let ngHost = new TypeScriptServiceHost(mockHost, service);
let ngService = createLanguageService(ngHost);
const fileName = '/app/test.ng';
let position = mockHost.getMarkerLocations(fileName)['h1-content'];

it('should not crash a get template references',
() => expect(() => ngService.getTemplateReferences()));
it('should not crash a get dianostics',
() => expect(() => ngService.getDiagnostics(fileName)).not.toThrow());
it('should not crash a completion',
() => expect(() => ngService.getCompletionsAt(fileName, position)).not.toThrow());
it('should not crash a get defintion',
() => expect(() => ngService.getDefinitionAt(fileName, position)).not.toThrow());
it('should not crash a hover', () => expect(() => ngService.getHoverAt(fileName, position)));
});
2 changes: 2 additions & 0 deletions modules/@angular/language-service/test/test_utils.ts
Expand Up @@ -98,6 +98,8 @@ export class MockTypescriptHost implements ts.LanguageServiceHost {
this.scriptNames.push(fileName);
}

forgetAngular() { this.angularPath = undefined; }

getCompilationSettings(): ts.CompilerOptions {
return {
target: ts.ScriptTarget.ES5,
Expand Down