refactor(compiler-cli): Move diagnostics files to language service (#33809)

The following files are consumed only by the language service and do not
have to be in compiler-cli:

1. expression_diagnostics.ts
2. expression_type.ts
3. typescript_symbols.ts
4. symbols.ts

PR Close #33809
This commit is contained in:
Keen Yee Liau 2019-11-13 14:26:58 -08:00 committed by Alex Rickabaugh
parent 784fd26473
commit 9935aa43ad
19 changed files with 82 additions and 145 deletions

View File

@ -8,10 +8,6 @@
import {NodeJSFileSystem, setFileSystem} from './src/ngtsc/file_system';
export {AotCompilerHost, AotCompilerHost as StaticReflectorHost, StaticReflector, StaticSymbol} from '@angular/compiler';
export {DiagnosticTemplateInfo, getExpressionScope, getTemplateExpressionDiagnostics} from './src/diagnostics/expression_diagnostics';
export {AstType, ExpressionDiagnosticsContext} from './src/diagnostics/expression_type';
export {BuiltinType, DeclarationKind, Definition, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from './src/diagnostics/symbols';
export {getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from './src/diagnostics/typescript_symbols';
export {VERSION} from './src/version';
export * from './src/metadata';

View File

@ -14,10 +14,6 @@ Angular modules and Typescript as this will indirectly add a dependency
to the language service.
*/
export {DiagnosticTemplateInfo, ExpressionDiagnostic, getExpressionDiagnostics, getExpressionScope, getTemplateExpressionDiagnostics} from './diagnostics/expression_diagnostics';
export {AstType, DiagnosticKind, ExpressionDiagnosticsContext, TypeDiagnostic} from './diagnostics/expression_type';
export {BuiltinType, DeclarationKind, Definition, Location, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from './diagnostics/symbols';
export {getClassFromStaticSymbol, getClassMembers, getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from './diagnostics/typescript_symbols';
export {MetadataCollector, ModuleMetadata} from './metadata';
export {CompilerOptions} from './transformers/api';
export {MetadataReaderCache, MetadataReaderHost, createMetadataReaderCache, readMetadata} from './transformers/metadata_reader';

View File

@ -1,28 +1,11 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
ts_library(
name = "mocks",
testonly = True,
srcs = [
"mocks.ts",
],
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/core",
"@npm//typescript",
],
)
# check_types_spec
ts_library(
name = "check_types_lib",
testonly = True,
srcs = ["check_types_spec.ts"],
deps = [
":mocks",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"@npm//typescript",
@ -49,69 +32,6 @@ jasmine_node_test(
],
)
# expression_diagnostics_spec
ts_library(
name = "expression_diagnostics_lib",
testonly = True,
srcs = ["expression_diagnostics_spec.ts"],
deps = [
":mocks",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/language-service",
"@npm//typescript",
],
)
jasmine_node_test(
name = "expression_diagnostics",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
"//packages/forms:npm_package",
],
tags = [
# Disabled as these tests pertain to diagnostics in the old ngc compiler. The Ivy ngtsc
# compiler has its own tests for diagnostics.
"no-ivy-aot",
],
deps = [
":expression_diagnostics_lib",
"//packages/core",
"//tools/testing:node",
],
)
# typescript_symbols_spec
ts_library(
name = "typescript_symbols_lib",
testonly = True,
srcs = ["typescript_symbols_spec.ts"],
deps = [
":mocks",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/compiler/test:test_utils",
"//packages/language-service",
"@npm//typescript",
],
)
jasmine_node_test(
name = "typescript_symbols",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
],
deps = [
":typescript_symbols_lib",
"//packages/core",
"//tools/testing:node",
],
)
# typescript_version_spec
ts_library(
name = "typescript_version_lib",

View File

@ -7,10 +7,10 @@
*/
import {AST, AstPath, Attribute, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, CssSelector, Element, ElementAst, ImplicitReceiver, NAMED_ENTITIES, Node as HtmlAst, NullTemplateVisitor, ParseSpan, PropertyRead, TagContentType, Text, findNode, getHtmlTagDefinition} from '@angular/compiler';
import {getExpressionScope} from '@angular/compiler-cli/src/language_services';
import {$$, $_, isAsciiLetter, isDigit} from '@angular/compiler/src/chars';
import {AstResult} from './common';
import {getExpressionScope} from './expression_diagnostics';
import {getExpressionCompletions} from './expressions';
import {attributeNames, elementNames, eventNames, propertyNames} from './html_info';
import {InlineTemplate} from './template';

View File

@ -7,15 +7,16 @@
*/
import {NgAnalyzedModules} from '@angular/compiler';
import {getTemplateExpressionDiagnostics} from '@angular/compiler-cli/src/language_services';
import * as path from 'path';
import * as ts from 'typescript';
import {AstResult} from './common';
import {getTemplateExpressionDiagnostics} from './expression_diagnostics';
import * as ng from './types';
import {TypeScriptServiceHost} from './typescript_host';
import {findPropertyValueOfType, findTightestNode, offsetSpan, spanOf} from './utils';
/**
* Return diagnostic information for the parsed AST of the template.
* @param ast contains HTML and template AST

View File

@ -7,7 +7,7 @@
*/
import {AST, ASTWithSource, AstPath as AstPathBase, NullAstVisitor, visitAstChildren} from '@angular/compiler';
import {AstType} from '@angular/compiler-cli/src/language_services';
import {AstType} from './expression_type';
import {BuiltinType, Span, Symbol, SymbolQuery, SymbolTable} from './types';
import {inSpan} from './utils';

View File

@ -7,9 +7,9 @@
*/
import {AST, Attribute, BoundDirectivePropertyAst, BoundEventAst, CompileTypeSummary, CssSelector, DirectiveAst, ElementAst, SelectorMatcher, TemplateAstPath, findNode, tokenReference} from '@angular/compiler';
import {getExpressionScope} from '@angular/compiler-cli/src/language_services';
import {AstResult} from './common';
import {getExpressionScope} from './expression_diagnostics';
import {getExpressionSymbol} from './expressions';
import {Definition, DirectiveKind, Span, Symbol} from './types';
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, inSpan, offsetSpan, spanOf} from './utils';

View File

@ -6,13 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from '@angular/compiler-cli';
import * as ts from 'typescript';
import {isAstResult} from './common';
import {createGlobalSymbolTable} from './global_symbols';
import * as ng from './types';
import {TypeScriptServiceHost} from './typescript_host';
import {getClassMembersFromDeclaration, getPipesTable, getSymbolQuery} from './typescript_symbols';
/**
* A base class to represent a template and which component class it is

View File

@ -7,9 +7,9 @@
*/
import {CompileDirectiveMetadata, NgAnalyzedModules, StaticSymbol} from '@angular/compiler';
import {BuiltinType, DeclarationKind, Definition, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from '@angular/compiler-cli/src/language_services';
import {AstResult} from './common';
import {BuiltinType, DeclarationKind, Definition, PipeInfo, Pipes, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from './symbols';
export {
BuiltinType,
@ -26,6 +26,7 @@ export {
SymbolTable
};
/**
* The information `LanguageService` needs from the `LanguageServiceHost` to describe the content of
* a template and the language context the template is in.

View File

@ -11,7 +11,6 @@ import * as path from 'path';
import * as ts from 'typescript';
import {BuiltinType, DeclarationKind, Definition, Signature, Span, Symbol, SymbolDeclaration, SymbolQuery, SymbolTable} from './symbols';
import {isVersionBetween} from './typescript_version';
// In TypeScript 2.1 these flags moved
// These helpers work for both 2.0 and 2.1.
@ -396,14 +395,7 @@ class SignatureResultOverride implements Signature {
get result(): Symbol { return this.resultType; }
}
/**
* Indicates the lower bound TypeScript version supporting `SymbolTable` as an ES6 `Map`.
* For lower versions, `SymbolTable` is implemented as a dictionary
*/
const MIN_TS_VERSION_SUPPORTING_MAP = '2.2';
export const toSymbolTableFactory = (tsVersion: string) => (symbols: ts.Symbol[]) => {
if (isVersionBetween(tsVersion, MIN_TS_VERSION_SUPPORTING_MAP)) {
export function toSymbolTableFactory(symbols: ts.Symbol[]) {
// ∀ Typescript version >= 2.2, `SymbolTable` is implemented as an ES6 `Map`
const result = new Map<string, ts.Symbol>();
for (const symbol of symbols) {
@ -414,15 +406,7 @@ export const toSymbolTableFactory = (tsVersion: string) => (symbols: ts.Symbol[]
// Otherwise, `Map<string, ts.Symbol>` and `ts.SymbolTable` will be considered as incompatible
// types by the compiler
return <ts.SymbolTable>(<any>result);
}
// ∀ Typescript version < 2.2, `SymbolTable` is implemented as a dictionary
const result: {[name: string]: ts.Symbol} = {};
for (const symbol of symbols) {
result[symbol.name] = symbol;
}
return <ts.SymbolTable>(<any>result);
};
}
function toSymbols(symbolTable: ts.SymbolTable | undefined): ts.Symbol[] {
if (!symbolTable) return [];
@ -456,8 +440,7 @@ class SymbolTableWrapper implements SymbolTable {
if (Array.isArray(symbols)) {
this.symbols = symbols;
const toSymbolTable = toSymbolTableFactory(ts.version);
this.symbolTable = toSymbolTable(symbols);
this.symbolTable = toSymbolTableFactory(symbols);
} else {
this.symbols = toSymbols(symbols);
this.symbolTable = symbols;

View File

@ -7,10 +7,10 @@
*/
import {AstPath, CompileDirectiveSummary, CompileTypeMetadata, CssSelector, DirectiveAst, ElementAst, EmbeddedTemplateAst, ParseSourceSpan, RecursiveTemplateAstVisitor, TemplateAst, TemplateAstPath, identifierName, templateVisitAll} from '@angular/compiler';
import {DiagnosticTemplateInfo} from '@angular/compiler-cli/src/language_services';
import * as ts from 'typescript';
import {AstResult, SelectorInfo} from './common';
import {DiagnosticTemplateInfo} from './expression_diagnostics';
import {Span} from './types';
export interface SpanHolder {

View File

@ -3,15 +3,25 @@ load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(
include = ["**/*.ts"],
exclude = ["project/**/*"],
),
srcs = [
"completions_spec.ts",
"definitions_spec.ts",
"diagnostics_spec.ts",
"global_symbols_spec.ts",
"hover_spec.ts",
"html_info_spec.ts",
"language_service_spec.ts",
"reflector_host_spec.ts",
"template_references_spec.ts",
"template_spec.ts",
"test_utils.ts",
"ts_plugin_spec.ts",
"typescript_host_spec.ts",
"utils_spec.ts",
],
data = glob(["project/**/*"]),
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/language-service",
"@npm//typescript",
@ -32,3 +42,37 @@ jasmine_node_test(
":test_lib",
],
)
ts_library(
name = "diagnostics_lib",
testonly = True,
srcs = [
"expression_diagnostics_spec.ts",
"mocks.ts",
"typescript_symbols_spec.ts",
],
deps = [
"//packages/compiler",
"//packages/compiler-cli/test:test_utils",
"//packages/core",
"//packages/language-service",
"@npm//typescript",
],
)
jasmine_node_test(
name = "diagnostics",
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
"//packages/forms:npm_package",
],
tags = [
# Disabled as these tests pertain to diagnostics in the old ngc compiler. The Ivy ngtsc
# compiler has its own tests for diagnostics.
"no-ivy-aot",
],
deps = [
":diagnostics_lib",
],
)

View File

@ -7,11 +7,11 @@
*/
import {StaticSymbol} from '@angular/compiler';
import {Directory} from '@angular/compiler-cli/test/mocks';
import {ReflectorHost} from '@angular/language-service/src/reflector_host';
import * as ts from 'typescript';
import {getTemplateExpressionDiagnostics} from '../../src/diagnostics/expression_diagnostics';
import {Directory} from '../mocks';
import {getTemplateExpressionDiagnostics} from '../src/expression_diagnostics';
import {DiagnosticContext, MockLanguageServiceHost, getDiagnosticTemplateInfo} from './mocks';

View File

@ -6,10 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {getSymbolQuery} from '@angular/compiler-cli';
import * as ts from 'typescript/lib/tsserverlibrary';
import {EMPTY_SYMBOL_TABLE, createGlobalSymbolTable} from '../src/global_symbols';
import {getSymbolQuery} from '../src/typescript_symbols';
import {MockTypescriptHost} from './test_utils';

View File

@ -7,15 +7,15 @@
*/
import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, I18NHtmlParser, InterpolationConfig, JitSummaryResolver, Lexer, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, Parser, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, StaticSymbolResolverHost, SummaryResolver, TemplateParser, analyzeNgModules, createOfflineCompileUrlResolver} from '@angular/compiler';
import {Directory, MockAotContext} from '@angular/compiler-cli/test/mocks';
import {setup} from '@angular/compiler-cli/test/test_support';
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
import {DiagnosticTemplateInfo} from '../../src/diagnostics/expression_diagnostics';
import {getClassMembers, getPipesTable, getSymbolQuery} from '../../src/diagnostics/typescript_symbols';
import {Directory, MockAotContext} from '../mocks';
import {setup} from '../test_support';
import {DiagnosticTemplateInfo} from '../src/expression_diagnostics';
import {getClassMembers, getPipesTable, getSymbolQuery} from '../src/typescript_symbols';
const realFiles = new Map<string, string>();

View File

@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directory} from '@angular/compiler-cli/test/mocks';
import {ReflectorHost} from '@angular/language-service/src/reflector_host';
import * as ts from 'typescript';
import {BuiltinType, Symbol, SymbolQuery, SymbolTable} from '../../src/diagnostics/symbols';
import {getSymbolQuery, toSymbolTableFactory} from '../../src/diagnostics/typescript_symbols';
import {Directory} from '../mocks';
import {BuiltinType, Symbol, SymbolQuery, SymbolTable} from '../src/symbols';
import {getSymbolQuery, toSymbolTableFactory} from '../src/typescript_symbols';
import {DiagnosticContext, MockLanguageServiceHost} from './mocks';
@ -74,15 +74,10 @@ describe('symbol query', () => {
});
describe('toSymbolTableFactory(tsVersion)', () => {
it('should return a Map for versions of TypeScript >= 2.2 and a dictionary otherwise', () => {
it('should return a Map for versions of TypeScript >= 2.2', () => {
const a = { name: 'a' } as ts.Symbol;
const b = { name: 'b' } as ts.Symbol;
expect(toSymbolTableFactory('2.1')([a, b]) instanceof Map).toEqual(false);
expect(toSymbolTableFactory('2.4')([a, b]) instanceof Map).toEqual(true);
// Check that for the lower bound version `2.2`, toSymbolTableFactory('2.2') returns a map
expect(toSymbolTableFactory('2.2')([a, b]) instanceof Map).toEqual(true);
expect(toSymbolTableFactory([a, b]) instanceof Map).toEqual(true);
});
});