forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(runtime): unwrap the function in ir (web-infra-dev#2860)
- Loading branch information
Showing
5 changed files
with
100 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 12 additions & 14 deletions
26
crates/rspack_plugin_runtime/src/runtime/common/_export_star.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
(function () { | ||
__webpack_require__.es = function (from, to) { | ||
Object.keys(from).forEach(function (k) { | ||
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) | ||
Object.defineProperty(to, k, { | ||
enumerable: true, | ||
get: function () { | ||
return from[k]; | ||
} | ||
}); | ||
}); | ||
return from; | ||
}; | ||
})(); | ||
__webpack_require__.es = function (from, to) { | ||
Object.keys(from).forEach(function (k) { | ||
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) | ||
Object.defineProperty(to, k, { | ||
enumerable: true, | ||
get: function () { | ||
return from[k]; | ||
} | ||
}); | ||
}); | ||
return from; | ||
}; |
84 changes: 41 additions & 43 deletions
84
crates/rspack_plugin_runtime/src/runtime/common/_interop_require.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
(function () { | ||
function _getRequireCache(nodeInterop) { | ||
if (typeof WeakMap !== "function") return null; | ||
function _getRequireCache(nodeInterop) { | ||
if (typeof WeakMap !== "function") return null; | ||
|
||
var cacheBabelInterop = new WeakMap(); | ||
var cacheNodeInterop = new WeakMap(); | ||
return (_getRequireCache = function (nodeInterop) { | ||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop; | ||
})(nodeInterop); | ||
} | ||
var cacheBabelInterop = new WeakMap(); | ||
var cacheNodeInterop = new WeakMap(); | ||
return (_getRequireCache = function (nodeInterop) { | ||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop; | ||
})(nodeInterop); | ||
} | ||
|
||
__webpack_require__.ir = function (obj, nodeInterop) { | ||
if (!nodeInterop && obj && obj.__esModule) { | ||
return obj; | ||
} | ||
__webpack_require__.ir = function (obj, nodeInterop) { | ||
if (!nodeInterop && obj && obj.__esModule) { | ||
return obj; | ||
} | ||
|
||
if ( | ||
obj === null || | ||
(typeof obj !== "object" && typeof obj !== "function") | ||
) { | ||
return { default: obj }; | ||
} | ||
if ( | ||
obj === null || | ||
(typeof obj !== "object" && typeof obj !== "function") | ||
) { | ||
return { default: obj }; | ||
} | ||
|
||
var cache = _getRequireCache(nodeInterop); | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj); | ||
} | ||
var cache = _getRequireCache(nodeInterop); | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj); | ||
} | ||
|
||
var newObj = {}; | ||
var hasPropertyDescriptor = | ||
Object.defineProperty && Object.getOwnPropertyDescriptor; | ||
for (var key in obj) { | ||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor | ||
? Object.getOwnPropertyDescriptor(obj, key) | ||
: null; | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
var newObj = {}; | ||
var hasPropertyDescriptor = | ||
Object.defineProperty && Object.getOwnPropertyDescriptor; | ||
for (var key in obj) { | ||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor | ||
? Object.getOwnPropertyDescriptor(obj, key) | ||
: null; | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
newObj.default = obj; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
}; | ||
})(); | ||
} | ||
newObj.default = obj; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters