Skip to content

Commit b79fb98

Browse files
author
Robert Jackson
committed
Do not assume global variables are assigned to self.
`requirejs` is a global variable (provided by [loader.js here](https://github.com/ember-cli/loader.js/blob/v4.7.0/lib/loader/loader.js#L1)). The prior code made the assumption that all global variables are assigned to `self`/`window`, but this is _only_ true in some circumstances. For example, when the entire bundle is evaluated within an IIFE `self.requirejs` is undefined.
1 parent 6563435 commit b79fb98

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

addon/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
declare global {
2+
var requirejs: {
3+
_eak_seen: Object;
4+
};
5+
}
6+
17
import Engine from '@ember/engine';
28
import require from 'require';
39

@@ -39,7 +45,7 @@ export default function loadInitializers(app: typeof Engine, prefix: string): vo
3945
var instanceInitializers = [];
4046
// this is 2 pass because generally the first pass is the problem
4147
// and is reduced, and resolveInitializer has potential to deopt
42-
var moduleNames = Object.keys(self.requirejs._eak_seen);
48+
var moduleNames = Object.keys(requirejs._eak_seen);
4349
for (var i = 0; i < moduleNames.length; i++) {
4450
var moduleName = moduleNames[i];
4551
if (moduleName.lastIndexOf(initializerPrefix, 0) === 0) {

0 commit comments

Comments
 (0)