Skip to content

Commit 28d1711

Browse files
committed
Remove invalid callee nodes from AST v2
`{{("foo")}}` etc is illegal and already covered by existing tests. Currently this is checked by the parser (handlebars-node-visitors) but AST plugins can violate this constraint in theory.
1 parent ba48821 commit 28d1711

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

packages/@glimmer/compiler/lib/passes/1-normalization/keywords/impl.ts

-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ class KeywordImpl<
7878
}
7979
}
8080

81-
export type PossibleNode =
82-
| ASTv2.PathExpression
83-
| ASTv2.AppendContent
84-
| ASTv2.CallExpression
85-
| ASTv2.InvokeBlock;
86-
8781
export const KEYWORD_NODES = {
8882
Call: ['Call'],
8983
Block: ['InvokeBlock'],

packages/@glimmer/syntax/lib/v1/nodes-v1.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface CallParts {
4343
path: CallableExpression;
4444
params: Expression[];
4545
hash: Hash;
46+
loc: src.SourceSpan;
4647
}
4748

4849
export type CallNode =

packages/@glimmer/syntax/lib/v2/builders.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SpanList } from '../source/span-list';
99
import * as ASTv2 from './api';
1010

1111
export interface CallParts {
12-
callee: ASTv2.ExpressionNode;
12+
callee: ASTv2.CalleeNode;
1313
args: ASTv2.Args;
1414
}
1515

packages/@glimmer/syntax/lib/v2/normalize.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class ExpressionNormalizer {
243243
* it to an ASTv2 CallParts.
244244
*/
245245
callParts(parts: ASTv1.CallParts, context: ASTv2.FreeVarResolution): CallParts {
246-
let { path, params, hash } = parts;
246+
let { path, params, hash, loc } = parts;
247247

248248
let callee = this.normalize(path, context);
249249
let paramList = params.map((p) => this.normalize(p, ASTv2.STRICT_RESOLUTION));
@@ -261,6 +261,21 @@ class ExpressionNormalizer {
261261
this.block.loc(hash.loc)
262262
);
263263

264+
switch (callee.type) {
265+
case 'Literal':
266+
throw generateSyntaxError(
267+
`Invalid invocation of a literal value (\`${callee.value}\`)`,
268+
loc
269+
);
270+
271+
// This really shouldn't be possible, something has gone pretty wrong
272+
case 'Interpolate':
273+
throw generateSyntaxError(
274+
`Invalid invocation of a interpolated string`,
275+
loc
276+
);
277+
}
278+
264279
return {
265280
callee,
266281
args: this.block.builder.args(positional, named, argsLoc),
@@ -402,6 +417,7 @@ class StatementNormalizer {
402417
path,
403418
params,
404419
hash,
420+
loc,
405421
},
406422
resolution.result
407423
);

packages/@glimmer/syntax/lib/v2/objects/base.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SerializedSourceSpan } from '../../source/span';
22
import type { Args } from './args';
33
import type { ElementModifier } from './attr-block';
44
import type { AppendContent, ContentNode, InvokeBlock, InvokeComponent } from './content';
5-
import type { CallExpression, ExpressionNode } from './expr';
5+
import type { CallExpression, PathExpression } from './expr';
66
import type { BaseNodeFields } from './node';
77

88
export interface SerializedBaseNode {
@@ -14,10 +14,14 @@ export interface GlimmerParentNodeOptions extends BaseNodeFields {
1414
}
1515

1616
export interface CallFields extends BaseNodeFields {
17-
callee: ExpressionNode;
17+
callee: CalleeNode;
1818
args: Args;
1919
}
2020

21+
export type CalleeNode =
22+
| PathExpression
23+
| CallExpression;
24+
2125
export type CallNode =
2226
| CallExpression
2327
| InvokeBlock

0 commit comments

Comments
 (0)