Skip to content

Commit 1580b97

Browse files
committed
Make strict mode the default for template()
1 parent 49c88fd commit 1580b97

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/@ember/-internals/glimmer/tests/integration/components/runtime-template-compiler-explicit-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { template } from '@ember/template-compiler/runtime';
22
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers';
33
import GlimmerishComponent from '../../utils/glimmerish-component';
4+
import { on } from '@ember/modifier/on';
5+
import { fn } from '@ember/helper';
46

57
moduleFor(
68
'Strict Mode - Runtime Template Compiler (explicit)',
@@ -274,7 +276,7 @@ moduleFor(
274276
};
275277

276278
return template('<button {{on "click" (fn handleClick 123)}}>Click</button>', {
277-
scope: () => ({ handleClick }),
279+
scope: () => ({ handleClick, on, fn }),
278280
});
279281
});
280282

packages/@ember/-internals/glimmer/tests/integration/components/runtime-template-compiler-implicit-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import { template } from '@ember/template-compiler/runtime';
33
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers';
44
import GlimmerishComponent from '../../utils/glimmerish-component';
5+
import { on } from '@ember/modifier/on';
6+
import { fn } from '@ember/helper';
7+
8+
// Assign these to constants so that they don't get removed by an
9+
// eager transpiler pass. These days, people should be using
10+
// verbatim-mode compilers, but this codebase isn't doing that yet.
11+
const _ = [on, fn];
512

613
moduleFor(
714
'Strict Mode - Runtime Template Compiler (implicit)',

packages/@ember/template-compiler/lib/template.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ type ComponentClass = abstract new (...args: any[]) => object;
1414
*/
1515
export interface BaseTemplateOptions {
1616
moduleName?: string;
17+
/**
18+
* Whether the template should be treated as a strict-mode template. Defaults
19+
* to `true`.
20+
*/
21+
strictMode?: boolean;
1722
}
1823

1924
/**
@@ -230,8 +235,9 @@ export function template<C extends ComponentClass>(
230235
): C;
231236
export function template(
232237
templateString: string,
233-
options?: BaseTemplateOptions | BaseClassTemplateOptions<any>
238+
providedOptions?: BaseTemplateOptions | BaseClassTemplateOptions<any>
234239
): object {
240+
const options: EmberPrecompileOptions = { strictMode: true, ...providedOptions };
235241
const evaluate = buildEvaluator(options);
236242

237243
const normalizedOptions = compileOptions(options);
@@ -261,12 +267,10 @@ function buildEvaluator(options: Partial<EmberPrecompileOptions> | undefined) {
261267
} else {
262268
const scope = options.scope?.();
263269

264-
if (!scope && options.component) {
270+
if (!scope) {
265271
return evaluator;
266272
}
267273

268-
assert(`The 'template' function must be called with an evaluator, scope or component`, scope);
269-
270274
return (source: string) => {
271275
const argNames = Object.keys(scope);
272276
const argValues = Object.values(scope);

0 commit comments

Comments
 (0)