MCPcopy
hub / github.com/webpack/webpack / getGlobalObject

Function getGlobalObject

lib/RuntimeTemplate.js:80–96  ·  view source on GitHub ↗

* Gets global object. * @param {string | undefined} definition global object definition * @returns {string | undefined} save to use global object

(definition)

Source from the content-addressed store, hash-verified

78 * @returns {string | undefined} save to use global object
79 */
80function getGlobalObject(definition) {
81 if (!definition) return definition;
82 const trimmed = definition.trim();
83
84 if (
85 // identifier, we do not need real identifier regarding ECMAScript/Unicode
86 /^[_\p{L}][_0-9\p{L}]*$/iu.test(trimmed) ||
87 // iife
88 // call expression
89 // expression in parentheses
90 /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
91 ) {
92 return trimmed;
93 }
94
95 return `Object(${trimmed})`;
96}
97
98class RuntimeTemplate {
99 /**

Callers 1

constructorMethod · 0.85

Calls 1

testMethod · 0.45

Tested by

no test coverage detected