Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ function buildOptions(projectConfig, templateCompilerPath, pluginInfo) {
return htmlbarsOptions;
}

const hasGlobalThis = (function () {
try {
let context = vm.createContext();

// we must create a sandboxed context to test if `globalThis` will be
// present _within_ it because in some contexts a globalThis polyfill has
// been evaluated. In that case globalThis would be available on the
// current global context but **would not** be inherited to the global
// contexts created by `vm.createContext`
let type = vm.runInContext(`typeof globalThis`, context);

return type !== 'undefined';
} catch (e) {
return false;
}
})();

function getTemplateCompiler(templateCompilerPath, EmberENV = {}) {
let templateCompilerFullPath = require.resolve(templateCompilerPath);
let cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
Expand Down Expand Up @@ -164,7 +181,7 @@ function getTemplateCompiler(templateCompilerPath, EmberENV = {}) {
// we must provide a `global`
//
// this is due to https://git.io/Jtb7s (Ember 3.27+)
if (typeof globalThis === 'undefined') {
if (!hasGlobalThis) {
sandbox.global = sandbox;
}

Expand Down