Skip to content

Commit a02d1a7

Browse files
committed
Implement RFC#1070 via telling the runtime lexicalScope check that the allowed globals can be accessed
1 parent 1a1c816 commit a02d1a7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
STRICT_MODE_KEYWORDS,
55
STRICT_MODE_TRANSFORMS,
66
} from './plugins/index';
7+
import { ALLOWED_GLOBALS } from './plugins/allowed-globals';
78
import type { EmberPrecompileOptions, PluginFunc } from './types';
89
import COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE from './dasherize-component-name';
910

@@ -39,6 +40,10 @@ function buildCompileOptions(_options: EmberPrecompileOptions): EmberPrecompileO
3940
const globalScopeEvaluator = (value: string) => new Function(`return ${value};`)();
4041

4142
options.lexicalScope = (variable: string) => {
43+
if (ALLOWED_GLOBALS.has(variable)) {
44+
return true;
45+
}
46+
4247
if (inScope(variable, localScopeEvaluator)) {
4348
return !inScope(variable, globalScopeEvaluator);
4449
}
@@ -52,7 +57,13 @@ function buildCompileOptions(_options: EmberPrecompileOptions): EmberPrecompileO
5257
if ('scope' in options) {
5358
const scope = (options.scope as () => Record<string, unknown>)();
5459

55-
options.lexicalScope = (variable: string) => variable in scope;
60+
options.lexicalScope = (variable: string) => {
61+
if (ALLOWED_GLOBALS.has(variable)) {
62+
return true;
63+
}
64+
65+
return variable in scope;
66+
};
5667

5768
delete options.scope;
5869
}

0 commit comments

Comments
 (0)