Skip to content

Commit

Permalink
Followup for loose-mode lexical scope
Browse files Browse the repository at this point in the history
#1351 was incomplete, and the test suite didn't make that clear because it doesn't exercise real template precompilation.

This time I've manually tested end-to-end in a real app (alongside ember canary).
  • Loading branch information
ef4 committed Oct 22, 2021
1 parent b1a69ad commit 978c924
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/@glimmer/compiler/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,17 @@ export function precompile(
isStrictMode: options.strictMode ?? false,
};

if (!options.strictMode) {
if (usedLocals.length === 0) {
delete templateJSONObject.scope;
}

// JSON is javascript
let stringified = JSON.stringify(templateJSONObject);

if (options.strictMode && usedLocals.length > 0) {
if (usedLocals.length > 0) {
let scopeFn = `()=>[${usedLocals.join(',')}]`;

stringified = stringified.replace(`"${SCOPE_PLACEHOLDER}"`, scopeFn);
} else {
stringified = stringified.replace(`"${SCOPE_PLACEHOLDER}"`, 'null');
}

return stringified;
Expand Down

0 comments on commit 978c924

Please sign in to comment.