Skip to content

Commit

Permalink
refactor(language-service): ensure compatibility with noImplicitOverr…
Browse files Browse the repository at this point in the history
…ide (#42512)

Adds the `override` keyword to the `language-service` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
  • Loading branch information
devversion authored and AndrewKushnir committed Jul 12, 2021
1 parent fdc6786 commit 367ef56
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
15 changes: 13 additions & 2 deletions packages/language-service/ivy/template_target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,22 @@ export interface TwoWayBindingContext {
nodes: [t.BoundAttribute, t.BoundEvent];
}

/**
* Special marker AST that can be used when the cursor is within the `sourceSpan` but not
* the key or value span of a node with key/value spans.
*/
class OutsideKeyValueMarkerAst extends e.AST {
visit(): null {
return null;
}
}

/**
* This special marker is added to the path when the cursor is within the sourceSpan but not the key
* or value span of a node with key/value spans.
*/
const OUTSIDE_K_V_MARKER = new e.AST(new ParseSpan(-1, -1), new e.AbsoluteSourceSpan(-1, -1));
const OUTSIDE_K_V_MARKER =
new OutsideKeyValueMarkerAst(new ParseSpan(-1, -1), new e.AbsoluteSourceSpan(-1, -1));

/**
* Return the template AST node or expression AST node that most accurately
Expand Down Expand Up @@ -415,7 +426,7 @@ class ExpressionVisitor extends e.RecursiveAstVisitor {
super();
}

visit(node: e.AST, path: Array<t.Node|e.AST>) {
override visit(node: e.AST, path: Array<t.Node|e.AST>) {
if (node instanceof e.ASTWithSource) {
// In order to reduce noise, do not include `ASTWithSource` in the path.
// For the purpose of source spans, there is no difference between
Expand Down
14 changes: 7 additions & 7 deletions packages/language-service/src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,23 +408,23 @@ class ExpressionVisitor extends NullTemplateVisitor {
return Array.from(this.completions.values());
}

visitDirectiveProperty(ast: BoundDirectivePropertyAst): void {
override visitDirectiveProperty(ast: BoundDirectivePropertyAst): void {
this.processExpressionCompletions(ast.value);
}

visitElementProperty(ast: BoundElementPropertyAst): void {
override visitElementProperty(ast: BoundElementPropertyAst): void {
this.processExpressionCompletions(ast.value);
}

visitEvent(ast: BoundEventAst): void {
override visitEvent(ast: BoundEventAst): void {
this.processExpressionCompletions(ast.handler);
}

visitElement(): void {
override visitElement(): void {
// no-op for now
}

visitAttr(ast: AttrAst) {
override visitAttr(ast: AttrAst) {
const binding = getBindingDescriptor(ast.name);
if (binding && binding.kind === ATTR.KW_MICROSYNTAX) {
// This a template binding given by micro syntax expression.
Expand Down Expand Up @@ -459,7 +459,7 @@ class ExpressionVisitor extends NullTemplateVisitor {
}
}

visitReference(_ast: ReferenceAst, context: ElementAst) {
override visitReference(_ast: ReferenceAst, context: ElementAst) {
context.directives.forEach(dir => {
const {exportAs} = dir.directive;
if (exportAs) {
Expand All @@ -469,7 +469,7 @@ class ExpressionVisitor extends NullTemplateVisitor {
});
}

visitBoundText(ast: BoundTextAst) {
override visitBoundText(ast: BoundTextAst) {
if (inSpan(this.position, ast.value.sourceSpan)) {
const completions = getExpressionCompletions(
this.getExpressionScope(), ast.value, this.position, this.info.template);
Expand Down
20 changes: 10 additions & 10 deletions packages/language-service/src/expression_diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function getReferences(info: ng.DiagnosticTemplateInfo): SymbolDeclaration[] {
}

const visitor = new class extends RecursiveTemplateAstVisitor {
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
override visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
super.visitEmbeddedTemplate(ast, context);
processReferences(ast.references);
}
visitElement(ast: ElementAst, context: any): any {
override visitElement(ast: ElementAst, context: any): any {
super.visitElement(ast, context);
processReferences(ast.references);
}
Expand Down Expand Up @@ -257,38 +257,38 @@ class ExpressionDiagnosticsVisitor extends RecursiveTemplateAstVisitor {
this.path = new AstPath<TemplateAst>([]);
}

visitDirective(ast: DirectiveAst, context: any): any {
override visitDirective(ast: DirectiveAst, context: any): any {
// Override the default child visitor to ignore the host properties of a directive.
if (ast.inputs && ast.inputs.length) {
templateVisitAll(this, ast.inputs, context);
}
}

visitBoundText(ast: BoundTextAst): void {
override visitBoundText(ast: BoundTextAst): void {
this.push(ast);
this.diagnoseExpression(ast.value, ast.sourceSpan.start.offset, false);
this.pop();
}

visitDirectiveProperty(ast: BoundDirectivePropertyAst): void {
override visitDirectiveProperty(ast: BoundDirectivePropertyAst): void {
this.push(ast);
this.diagnoseExpression(ast.value, this.attributeValueLocation(ast), false);
this.pop();
}

visitElementProperty(ast: BoundElementPropertyAst): void {
override visitElementProperty(ast: BoundElementPropertyAst): void {
this.push(ast);
this.diagnoseExpression(ast.value, this.attributeValueLocation(ast), false);
this.pop();
}

visitEvent(ast: BoundEventAst): void {
override visitEvent(ast: BoundEventAst): void {
this.push(ast);
this.diagnoseExpression(ast.handler, this.attributeValueLocation(ast), true);
this.pop();
}

visitVariable(ast: VariableAst): void {
override visitVariable(ast: VariableAst): void {
const directive = this.directiveSummary;
if (directive && ast.value) {
const context = this.info.query.getTemplateContext(directive.type.reference)!;
Expand All @@ -304,13 +304,13 @@ class ExpressionDiagnosticsVisitor extends RecursiveTemplateAstVisitor {
}
}

visitElement(ast: ElementAst, context: any): void {
override visitElement(ast: ElementAst, context: any): void {
this.push(ast);
super.visitElement(ast, context);
this.pop();
}

visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
override visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
const previousDirectiveSummary = this.directiveSummary;

this.push(ast);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/src/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type AstPath = AstPathBase<AST>;
function findAstAt(ast: AST, position: number, excludeEmpty: boolean = false): AstPath {
const path: AST[] = [];
const visitor = new class extends RecursiveAstVisitor {
visit(ast: AST) {
override visit(ast: AST) {
if ((!excludeEmpty || ast.sourceSpan.start < ast.sourceSpan.end) &&
inSpan(position, ast.sourceSpan)) {
const isNotNarrower = path.length && !isNarrower(ast.span, path[path.length - 1].span);
Expand Down
8 changes: 4 additions & 4 deletions packages/language-service/src/locate_symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,28 @@ function findParentOfBinding(
}
}

visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
override visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
return this.visitChildren(context, visit => {
visit(ast.directives);
visit(ast.children);
});
}

visitElement(ast: ElementAst, context: any): any {
override visitElement(ast: ElementAst, context: any): any {
return this.visitChildren(context, visit => {
visit(ast.directives);
visit(ast.children);
});
}

visitDirective(ast: DirectiveAst) {
override visitDirective(ast: DirectiveAst) {
const result = this.visitChildren(ast, visit => {
visit(ast.inputs);
});
return result;
}

visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: DirectiveAst) {
override visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: DirectiveAst) {
if (ast === binding) {
res = context;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {AstResult, Declaration, DeclarationError, DiagnosticMessageChain, Langua
* syntactically incorrect templates.
*/
export class DummyHtmlParser extends HtmlParser {
parse(): ParseTreeResult {
override parse(): ParseTreeResult {
return new ParseTreeResult([], []);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/src/typescript_symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class TypeWrapper implements Symbol {
// If stringIndexType a primitive type(e.g. 'string'), the Symbol is undefined;
// and in AstType.resolvePropertyRead method, the Symbol.type should get the right type.
class StringIndexTypeWrapper extends TypeWrapper {
public readonly type = new TypeWrapper(this.tsType, this.context);
public override readonly type = new TypeWrapper(this.tsType, this.context);
}

class SymbolWrapper implements Symbol {
Expand Down
6 changes: 3 additions & 3 deletions packages/language-service/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function findTemplateAstAt(ast: TemplateAst[], position: number): Templat
}
}

visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
override visitEmbeddedTemplate(ast: EmbeddedTemplateAst, context: any): any {
return this.visitChildren(context, visit => {
// Ignore reference, variable and providers
visit(ast.attrs);
Expand All @@ -116,7 +116,7 @@ export function findTemplateAstAt(ast: TemplateAst[], position: number): Templat
});
}

visitElement(ast: ElementAst, context: any): any {
override visitElement(ast: ElementAst, context: any): any {
return this.visitChildren(context, visit => {
// Ingnore providers
visit(ast.attrs);
Expand All @@ -128,7 +128,7 @@ export function findTemplateAstAt(ast: TemplateAst[], position: number): Templat
});
}

visitDirective(ast: DirectiveAst, context: any): any {
override visitDirective(ast: DirectiveAst, context: any): any {
// Ignore the host properties of a directive
const result = this.visitChildren(context, visit => {
visit(ast.inputs);
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class DiagnosticContext {
};
const urlResolver = createOfflineCompileUrlResolver();
const htmlParser = new class extends HtmlParser {
parse(): ParseTreeResult {
override parse(): ParseTreeResult {
return new ParseTreeResult([], []);
}
};
Expand Down

0 comments on commit 367ef56

Please sign in to comment.