Skip to content

Commit e63f159

Browse files
committed
Revert Template.blockParams -> Template.locals change for now
The rename is motivated by: 1. It's confusing for the root node to have "block params" 2. All other AST nodes that has `blockParams` also has a `params` field that exposes the source location as `VarHead`s There is some uncertainty in: 1. Whether there are a lot of existing AST consumers that uses it (shouldn't be a big deal in itself, as it's just a deprecation) 2. Whether the direction of using `Template.locals` as the source of truth for outside local variables will ultimately prevail When we have more certainty on those and if this rename is still desired, it should be possible to revert this commit
1 parent 31cc612 commit e63f159

File tree

6 files changed

+14
-52
lines changed

6 files changed

+14
-52
lines changed

packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export abstract class HandlebarsNodeVisitors extends Parser {
3535
abstract override beginAttributeValue(quoted: boolean): void;
3636
abstract override finishAttributeValue(): void;
3737

38-
parse(program: HBS.Program, locals: string[]): ASTv1.Template {
38+
parse(program: HBS.Program, blockParams: string[]): ASTv1.Template {
3939
let node = b.template({
4040
body: [],
41-
locals,
41+
blockParams,
4242
loc: this.source.spanFor(program.loc),
4343
});
4444

packages/@glimmer/syntax/lib/v1/legacy-interop.ts

-29
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,6 @@ import type * as ASTv1 from './nodes-v1';
55

66
import b from './public-builders';
77

8-
export type TemplateParams = Omit<ASTv1.Template, 'type' | 'blockParams'>;
9-
10-
export function buildLegacyTemplate({ body, locals, loc }: TemplateParams): ASTv1.Template {
11-
const node = {
12-
type: 'Template',
13-
body,
14-
locals,
15-
loc,
16-
};
17-
18-
Object.defineProperty(node, 'blockParams', {
19-
enumerable: false,
20-
get(): string[] {
21-
deprecate(
22-
`Template nodes can never have block params, for in-scope variables, use locals instead`
23-
);
24-
return this.locals;
25-
},
26-
set(value: string[]) {
27-
deprecate(
28-
`Template nodes can never have block params, for in-scope variables, use locals instead`
29-
);
30-
this.locals = value;
31-
},
32-
});
33-
34-
return node as ASTv1.Template;
35-
}
36-
378
export type MustacheStatementParams = Omit<ASTv1.MustacheStatement, 'type' | 'escaped'>;
389

3910
export function buildLegacyMustache({

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

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ export type EntityEncodingState = 'transformed' | 'raw';
2929

3030
export interface Template extends CommonProgram {
3131
type: 'Template';
32-
locals: string[];
33-
34-
/**
35-
* @deprecated use locals instead
36-
*/
3732
blockParams: string[];
3833
}
3934

packages/@glimmer/syntax/lib/v1/parser-builders.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { assert } from '@glimmer/util';
44
import type * as ASTv1 from './api';
55

66
import { SourceSpan } from '../source/span';
7-
import {
8-
buildLegacyLiteral,
9-
buildLegacyMustache,
10-
buildLegacyPath,
11-
buildLegacyTemplate,
12-
} from './legacy-interop';
7+
import { buildLegacyLiteral, buildLegacyMustache, buildLegacyPath } from './legacy-interop';
138

149
const DEFAULT_STRIP = {
1510
close: false,
@@ -60,18 +55,19 @@ class Builders {
6055

6156
template({
6257
body,
63-
locals,
58+
blockParams,
6459
loc,
6560
}: {
6661
body: ASTv1.Statement[];
67-
locals: string[];
62+
blockParams: string[];
6863
loc: SourceSpan;
6964
}): ASTv1.Template {
70-
return buildLegacyTemplate({
65+
return {
66+
type: 'Template',
7167
body,
72-
locals,
68+
blockParams,
7369
loc,
74-
});
70+
};
7571
}
7672

7773
mustache({

packages/@glimmer/syntax/lib/v1/public-builders.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function buildBlock(
6868
if (_defaultBlock.type === 'Template') {
6969
deprecate(`b.program is deprecated. Use b.blockItself instead.`);
7070
defaultBlock = b.blockItself({
71-
params: buildBlockParams(_defaultBlock.locals),
71+
params: buildBlockParams(_defaultBlock.blockParams),
7272
body: _defaultBlock.body,
7373
loc: _defaultBlock.loc,
7474
});
@@ -78,7 +78,7 @@ function buildBlock(
7878

7979
if (_elseBlock?.type === 'Template') {
8080
deprecate(`b.program is deprecated. Use b.blockItself instead.`);
81-
assert(_elseBlock.locals.length === 0, '{{else}} block cannot have block params');
81+
assert(_elseBlock.blockParams.length === 0, '{{else}} block cannot have block params');
8282

8383
elseBlock = b.blockItself({
8484
params: [],
@@ -422,12 +422,12 @@ function buildBlockItself(
422422

423423
function buildTemplate(
424424
body: ASTv1.Statement[] = [],
425-
locals: string[] = [],
425+
blockParams: string[] = [],
426426
loc?: SourceLocation
427427
): ASTv1.Template {
428428
return b.template({
429429
body,
430-
locals,
430+
blockParams,
431431
loc: buildLoc(loc || null),
432432
});
433433
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function normalize(
4141
let normalizeOptions = {
4242
strictMode: false,
4343
...options,
44-
locals: ast.locals,
44+
locals: ast.blockParams,
4545
};
4646

4747
let top = SymbolTable.top(

0 commit comments

Comments
 (0)