Skip to content

Commit 10da2f9

Browse files
crisbetokirjs
authored andcommitted
fix(compiler): better types for a few expression AST nodes
We had `any` types for `LiteralArray.expressions`, `Chain.expressions`, `BindingPipe.args`, `LiteralPrimitive.value` and `LiteralMap.values`. These changes add proper types to them.
1 parent b93d5ec commit 10da2f9

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/compiler/src/expression_parser/ast.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Chain extends AST {
7070
constructor(
7171
span: ParseSpan,
7272
sourceSpan: AbsoluteSourceSpan,
73-
public expressions: any[],
73+
public expressions: AST[],
7474
) {
7575
super(span, sourceSpan);
7676
}
@@ -173,7 +173,7 @@ export class BindingPipe extends ASTWithName {
173173
sourceSpan: AbsoluteSourceSpan,
174174
public exp: AST,
175175
public name: string,
176-
public args: any[],
176+
public args: AST[],
177177
readonly type: BindingPipeType,
178178
nameSpan: AbsoluteSourceSpan,
179179
) {
@@ -188,7 +188,7 @@ export class LiteralPrimitive extends AST {
188188
constructor(
189189
span: ParseSpan,
190190
sourceSpan: AbsoluteSourceSpan,
191-
public value: any,
191+
public value: string | number | boolean | null | undefined,
192192
) {
193193
super(span, sourceSpan);
194194
}
@@ -201,7 +201,7 @@ export class LiteralArray extends AST {
201201
constructor(
202202
span: ParseSpan,
203203
sourceSpan: AbsoluteSourceSpan,
204-
public expressions: any[],
204+
public expressions: AST[],
205205
) {
206206
super(span, sourceSpan);
207207
}
@@ -223,7 +223,7 @@ export class LiteralMap extends AST {
223223
span: ParseSpan,
224224
sourceSpan: AbsoluteSourceSpan,
225225
public keys: LiteralMapKey[],
226-
public values: any[],
226+
public values: AST[],
227227
) {
228228
super(span, sourceSpan);
229229
}

packages/language-service/src/references_and_rename_utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,12 @@ export function getRenameTextAndSpanAtPosition(
387387
return getRenameTextAndSpanAtPosition(node.left, position);
388388
} else if (node instanceof LiteralPrimitive) {
389389
const span = toTextSpan(node.sourceSpan);
390-
const text = node.value;
391-
if (typeof text === 'string') {
390+
if (typeof node.value === 'string') {
392391
// The span of a string literal includes the quotes but they should be removed for renaming.
393392
span.start += 1;
394393
span.length -= 2;
395394
}
396-
return {text, span};
395+
return {text: `${node.value}`, span};
397396
} else if (node instanceof TmplAstElement || node instanceof TmplAstDirective) {
398397
return {text: node.name, span: toTextSpan(node.startSourceSpan)};
399398
} else if (node instanceof TmplAstComponent) {

0 commit comments

Comments
 (0)