File tree 2 files changed +40
-2
lines changed
2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -1920,7 +1920,6 @@ describe('htmlbars-inline-precompile', function () {
1920
1920
) ;
1921
1921
1922
1922
expect ( transformed ) . toEqualCode ( `
1923
- import HelloWorld from "somewhere";
1924
1923
import { precompileTemplate } from "@ember/template-compilation";
1925
1924
import { setComponentTemplate } from "@ember/component";
1926
1925
import templateOnly from "@ember/component/template-only";
Original file line number Diff line number Diff line change @@ -12,6 +12,45 @@ 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: 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
+
15
54
/*
16
55
`mode` refers to the implicit and explicit formats defined here:
17
56
@@ -72,7 +111,7 @@ export class ScopeLocals {
72
111
73
112
#isInJsScope( hbsName : string , jsPath : NodePath ) {
74
113
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 ) ;
76
115
}
77
116
78
117
// this AST transform discovers all possible upvars in HBS that refer to valid
You can’t perform that action at this time.
0 commit comments