@@ -12,6 +12,76 @@ import { ASTPluginEnvironment, NodeVisitor } from '@glimmer/syntax';
12
12
import { astNodeHasBinding } from './hbs-utils' ;
13
13
import { readOnlyArray } from './read-only-array' ;
14
14
15
+ /**
16
+ * RFC: https://github.com/emberjs/rfcs/pull/1070
17
+ *
18
+ * Criteria for inclusion in this list:
19
+ *
20
+ * Any of:
21
+ * - begins with an uppercase letter
22
+ * - guaranteed to never be added to glimmer as a keyword (e.g.: globalThis)
23
+ *
24
+ * And:
25
+ * - must not need new to invoke
26
+ * - must not require lifetime management (e.g.: setTimeout)
27
+ * - must not be a single-word lower-case API, because of potential collision with future new HTML elements
28
+ * - if the API is a function, the return value should not be a promise
29
+ * - must be one one of these lists:
30
+ * - https://tc39.es/ecma262/#sec-global-object
31
+ * - https://tc39.es/ecma262/#sec-function-properties-of-the-global-object
32
+ * - https://html.spec.whatwg.org/multipage/nav-history-apis.html#window
33
+ * - https://html.spec.whatwg.org/multipage/indices.html#all-interfaces
34
+ * - https://html.spec.whatwg.org/multipage/webappapis.html
35
+ */
36
+ export const ALLOWED_GLOBALS = new Set ( [
37
+ // ////////////////
38
+ // namespaces
39
+ // ////////////////
40
+ // TC39
41
+ 'globalThis' ,
42
+ 'Atomics' ,
43
+ 'JSON' ,
44
+ 'Math' ,
45
+ 'Reflect' ,
46
+ // WHATWG
47
+ 'localStorage' ,
48
+ 'sessionStorage' ,
49
+ // ////////////////
50
+ // functions / utilities
51
+ // ////////////////
52
+ // TC39
53
+ 'isNaN' ,
54
+ 'isFinite' ,
55
+ 'parseInt' ,
56
+ 'parseFloat' ,
57
+ 'decodeURI' ,
58
+ 'decodeURIComponent' ,
59
+ 'encodeURI' ,
60
+ 'encodeURIComponent' ,
61
+ // WHATWG
62
+ 'postMessage' ,
63
+ 'structuredClone' ,
64
+ // ////////////////
65
+ // new-less Constructors (still functions)
66
+ // ////////////////
67
+ // TC39
68
+ 'Array' , // different behavior from (array)
69
+ 'BigInt' ,
70
+ 'Boolean' ,
71
+ 'Date' ,
72
+ 'Number' ,
73
+ 'Object' , // different behavior from (hash)
74
+ 'String' ,
75
+ // ////////////////
76
+ // Values
77
+ // ////////////////
78
+ // TC39
79
+ 'Infinity' ,
80
+ 'NaN' ,
81
+ // WHATWG
82
+ 'isSecureContext' ,
83
+ ] ) ;
84
+
15
85
/*
16
86
`mode` refers to the implicit and explicit formats defined here:
17
87
@@ -72,7 +142,7 @@ export class ScopeLocals {
72
142
73
143
#isInJsScope( hbsName : string , jsPath : NodePath ) {
74
144
let jsName = this . #mapping[ hbsName ] ?? hbsName ;
75
- return [ 'globalThis' ] . includes ( jsName ) || jsPath . scope . getBinding ( jsName ) ;
145
+ return ALLOWED_GLOBALS . has ( jsName ) || jsPath . scope . getBinding ( jsName ) ;
76
146
}
77
147
78
148
// this AST transform discovers all possible upvars in HBS that refer to valid
0 commit comments