Skip to content

Commit

Permalink
fix(runtime): revert alignment of commonjs exports dependency (#4679)
Browse files Browse the repository at this point in the history
Revert "feat(runtime): alignment of commonjs exports dependency (#4572)"

This reverts commit 89eac9d.
  • Loading branch information
JSerFeng authored Nov 17, 2023
1 parent 9e53989 commit 3e4362d
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ source: crates/rspack_testing/src/run_fixture.rs
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
"./zh_locale.js": (function (__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({
Object.defineProperty(exports, "__esModule", {
value: true
}));
});
exports["default"] = void 0;
/* eslint-disable no-template-curly-in-string */ var _default = {};
exports["default"] = _default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ source: crates/rspack_testing/src/run_fixture.rs
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
"./zh_locale.js": (function (__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({
Object.defineProperty(exports, "__esModule", {
value: true
}));
});
exports["default"] = void 0;
/* eslint-disable no-template-curly-in-string */ var _default = {};
exports["default"] = _default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ __webpack_require__.r(__webpack_exports__);
/*#__PURE__*/ (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache = __webpack_require__.t(_lib__WEBPACK_IMPORTED_MODULE_0__, 2)));
}),
"./lib.js": (function (__unused_webpack_module, exports, __webpack_require__) {
exports.a = 100000;
exports['a'] = 100000;
}),
},function(__webpack_require__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ __webpack_require__.r(__webpack_exports__);
/*#__PURE__*/ (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache = __webpack_require__.t(_lib__WEBPACK_IMPORTED_MODULE_0__, 2)));
}),
"./lib.js": (function (__unused_webpack_module, exports, __webpack_require__) {
exports.a = 100000;
exports['a'] = 100000;
}),
},function(__webpack_require__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ __webpack_require__.el(/* ./bar */"./bar.js").then(__webpack_require__.bind(__we
console.log(mod);
});
const a = "a";
__webpack_exports__.test = 30;
exports.test = 30;
}),
"./foo.js": (function (module, exports, __webpack_require__) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ __webpack_require__.el(/* ./bar */"./bar.js").then(__webpack_require__.bind(__we
console.log(mod);
});
const a = "a";
__webpack_exports__.test = 30;
exports.test = 30;
}),
"./foo.js": (function (module, exports, __webpack_require__) {
{
Expand Down
3 changes: 0 additions & 3 deletions crates/rspack_core/src/dependency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub enum DependencyType {
DynamicImportEager,
// cjs require
CjsRequire,
// cjs exports
CjsExports,
// new URL("./foo", import.meta.url)
NewUrl,
// new Worker()
Expand Down Expand Up @@ -110,7 +108,6 @@ impl DependencyType {
DependencyType::EsmImportSpecifier => Cow::Borrowed("esm import specifier"),
DependencyType::DynamicImport => Cow::Borrowed("dynamic import"),
DependencyType::CjsRequire => Cow::Borrowed("cjs require"),
DependencyType::CjsExports => Cow::Borrowed("cjs exports"),
DependencyType::NewUrl => Cow::Borrowed("new URL()"),
DependencyType::NewWorker => Cow::Borrowed("new Worker()"),
DependencyType::ImportMetaHotAccept => Cow::Borrowed("import.meta.webpackHot.accept"),
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/dependency/runtime_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn export_from_import(
format!("var {import_var}_namespace_cache;\n",),
InitFragmentStage::StageHarmonyExports,
-1,
InitFragmentKey::unique(),
InitFragmentKey::uniqie(),
None,
)
.boxed(),
Expand Down
7 changes: 2 additions & 5 deletions crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ impl ExportsInfoId {
let info = self.get_read_only_export_info(&name, mg);
info.get_used_name(&name, runtime).map(UsedName::Str)
}
UsedName::Vec(_) => {
// TODO
Some(name.clone())
}
UsedName::Vec(_) => todo!(),
}
}

Expand Down Expand Up @@ -518,7 +515,7 @@ impl ExportsInfo {
}
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum UsedName {
Str(JsWord),
Vec(Vec<JsWord>),
Expand Down
12 changes: 6 additions & 6 deletions crates/rspack_core/src/init_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub struct InitFragmentContents {
pub end: Option<String>,
}

pub struct InitFragmentKeyUnique;
pub type InitFragmentKeyUKey = rspack_database::Ukey<InitFragmentKeyUnique>;
pub struct InitFragmentKeyUniqie;
pub type InitFragmentKeyUKey = rspack_database::Ukey<InitFragmentKeyUniqie>;

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum InitFragmentKey {
Expand All @@ -31,12 +31,12 @@ pub enum InitFragmentKey {
AwaitDependencies,
HarmonyCompatibility,
ModuleDecorator(String /* module_id */),
Unique(InitFragmentKeyUKey),
Uniqie(InitFragmentKeyUKey),
}

impl InitFragmentKey {
pub fn unique() -> Self {
Self::Unique(rspack_database::Ukey::new())
pub fn uniqie() -> Self {
Self::Uniqie(rspack_database::Ukey::new())
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ impl InitFragmentKey {
| InitFragmentKey::HarmonyExportStar(_)
| InitFragmentKey::ExternalModule(_)
| InitFragmentKey::ModuleDecorator(_) => first(fragments),
InitFragmentKey::HarmonyCompatibility | InitFragmentKey::Unique(_) => {
InitFragmentKey::HarmonyCompatibility | InitFragmentKey::Uniqie(_) => {
debug_assert!(fragments.len() == 1, "fragment = {:?}", self);
first(fragments)
}
Expand Down
3 changes: 0 additions & 3 deletions crates/rspack_core/src/runtime_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ bitflags! {
* the System.register context object
*/
const SYSTEM_CONTEXT = 1 << 49;

const THIS_AS_EXPORTS = 1 << 50;
}
}

Expand Down Expand Up @@ -292,7 +290,6 @@ impl RuntimeGlobals {
R::HARMONY_MODULE_DECORATOR => "__webpack_require__.hmd",
R::NODE_MODULE_DECORATOR => "__webpack_require__.nmd",
R::SYSTEM_CONTEXT => "__webpack_require__.y",
R::THIS_AS_EXPORTS => "top-level-this-exports",
r => panic!(
"Unexpected flag `{r:?}`. RuntimeGlobals should only be printed for one single flag."
),
Expand Down
Loading

0 comments on commit 3e4362d

Please sign in to comment.