Skip to content

Commit 77d31e9

Browse files
committed
yay
1 parent 11481d5 commit 77d31e9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

__tests__/tests.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,6 @@ describe('htmlbars-inline-precompile', function () {
19201920
);
19211921

19221922
expect(transformed).toEqualCode(`
1923-
import HelloWorld from "somewhere";
19241923
import { precompileTemplate } from "@ember/template-compilation";
19251924
import { setComponentTemplate } from "@ember/component";
19261925
import templateOnly from "@ember/component/template-only";

src/scope-locals.ts

+40-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,45 @@ import { ASTPluginEnvironment, NodeVisitor } from '@glimmer/syntax';
1212
import { astNodeHasBinding } from './hbs-utils';
1313
import { readOnlyArray } from './read-only-array';
1414

15+
/**
16+
* RFC: Pending....
17+
*
18+
* tl;dr:
19+
* - utilities that begin with uppercase letter
20+
* OR are guaranteed to never be added to glimmer as a keyword (e.g.: globalThis)
21+
* - must not need `new` to invoke
22+
*
23+
* Ref:
24+
* - https://tc39.es/ecma262/#sec-global-object
25+
* - https://tc39.es/ecma262/#sec-function-properties-of-the-global-object
26+
*/
27+
const ALLOWED_GLOBALS = new Set([
28+
// namespaces
29+
'globalThis',
30+
'JSON',
31+
'Math',
32+
'Atomics',
33+
'Reflect',
34+
// functions
35+
'isNaN',
36+
'isFinite',
37+
'parseInt',
38+
'parseFloat',
39+
'decodeURI',
40+
'decodeURIComponent',
41+
'encodeURI',
42+
'encodeURIComponent',
43+
// new-less Constructors (still functions)
44+
'Number',
45+
'Object', // different behavior from (hash)
46+
'Array', // different behavior from (array)
47+
'String',
48+
'BigInt',
49+
'Date',
50+
// Values
51+
'Infinity',
52+
]);
53+
1554
/*
1655
`mode` refers to the implicit and explicit formats defined here:
1756
@@ -72,7 +111,7 @@ export class ScopeLocals {
72111

73112
#isInJsScope(hbsName: string, jsPath: NodePath) {
74113
let jsName = this.#mapping[hbsName] ?? hbsName;
75-
return ['globalThis'].includes(jsName) || jsPath.scope.getBinding(jsName);
114+
return ALLOWED_GLOBALS.has(jsName) || jsPath.scope.getBinding(jsName);
76115
}
77116

78117
// this AST transform discovers all possible upvars in HBS that refer to valid

0 commit comments

Comments
 (0)