Skip to content

Commit 31cc612

Browse files
committed
Revert making Template.locals readonly
It turns out to be important that AST plugins can mutate the list of local variables in the root `Template` node. Instead, use *that* list of local variables as the ultimate source of truth after AST plugin ran.
1 parent 68509ac commit 31cc612

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

packages/@glimmer/syntax/lib/parser/tokenizer-event-handlers.ts

-4
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,6 @@ export function preprocess(
762762
options.locals ?? []
763763
);
764764

765-
if (options.strictMode && options.locals?.length) {
766-
template = b.template({ ...template, locals: options.locals });
767-
}
768-
769765
if (options?.plugins?.ast) {
770766
for (const transform of options.plugins.ast) {
771767
let env: ASTPluginEnvironment = assign({}, options, { syntax }, { plugins: undefined });

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ export function buildLegacyTemplate({ body, locals, loc }: TemplateParams): ASTv
1111
const node = {
1212
type: 'Template',
1313
body,
14+
locals,
1415
loc,
1516
};
1617

17-
Object.defineProperty(node, 'locals', {
18-
enumerable: true,
19-
writable: false,
20-
value: Object.freeze([...locals]),
21-
});
22-
2318
Object.defineProperty(node, 'blockParams', {
2419
enumerable: false,
25-
get(): readonly string[] {
20+
get(): string[] {
2621
deprecate(
2722
`Template nodes can never have block params, for in-scope variables, use locals instead`
2823
);
2924
return this.locals;
3025
},
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+
},
3132
});
3233

3334
return node as ASTv1.Template;

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

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

3030
export interface Template extends CommonProgram {
3131
type: 'Template';
32-
readonly locals: readonly string[];
32+
locals: string[];
3333

3434
/**
3535
* @deprecated use locals instead
3636
*/
37-
readonly blockParams: readonly string[];
37+
blockParams: string[];
3838
}
3939

4040
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export function normalize(
4040

4141
let normalizeOptions = {
4242
strictMode: false,
43-
locals: [],
4443
...options,
44+
locals: ast.locals,
4545
};
4646

4747
let top = SymbolTable.top(

0 commit comments

Comments
 (0)