Skip to content

Commit

Permalink
feat: use u32 + Number.MAX_SAFE_INTEGER
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-x committed Dec 23, 2024
1 parent 3a0de8f commit 610aaf0
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl From<RawCssModuleParserOptions> for CssModuleParserOptions {
#[derive(Debug, Default)]
#[napi(object)]
pub struct RawJsonParserOptions {
pub exports_depth: Option<f64>,
pub exports_depth: Option<u32>,
}

impl From<RawJsonParserOptions> for JsonParserOptions {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/options/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub struct CssModuleParserOptions {
#[cacheable]
#[derive(Debug, Clone, MergeFrom)]
pub struct JsonParserOptions {
pub exports_depth: Option<f64>,
pub exports_depth: Option<u32>,
}

#[derive(Debug)]
Expand Down
11 changes: 5 additions & 6 deletions crates/rspack_plugin_json/src/json_exports_dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub struct JsonExportsDependency {
id: DependencyId,
#[cacheable(with=AsPreset)]
data: JsonValue,
exports_depth: f64,
exports_depth: u32,
}

impl JsonExportsDependency {
pub fn new(data: JsonValue, exports_depth: f64) -> Self {
pub fn new(data: JsonValue, exports_depth: u32) -> Self {
Self {
data,
id: DependencyId::new(),
Expand All @@ -33,9 +33,8 @@ impl Dependency for JsonExportsDependency {
}

fn get_exports(&self, _mg: &ModuleGraph) -> Option<ExportsSpec> {
let exports_depth: u64 = self.exports_depth as u64;
Some(ExportsSpec {
exports: get_exports_from_data(&self.data, exports_depth, 1)
exports: get_exports_from_data(&self.data, self.exports_depth, 1)
.unwrap_or(ExportsOfExportsSpec::Null),
..Default::default()
})
Expand Down Expand Up @@ -74,8 +73,8 @@ impl DependencyTemplate for JsonExportsDependency {

fn get_exports_from_data(
data: &JsonValue,
exports_depth: u64,
cur_depth: u64,
exports_depth: u32,
cur_depth: u32,
) -> Option<ExportsOfExportsSpec> {
if cur_depth > exports_depth {
return None;
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod utils;
#[cacheable]
#[derive(Debug)]
struct JsonParserAndGenerator {
pub exports_depth: f64,
pub exports_depth: u32,
}

#[cacheable_dyn]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Object {
wrappedContextRegExp: /\\.\\*/,
},
json: Object {
exportsDepth: Infinity,
exportsDepth: 9007199254740991,
},
},
rules: Array [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
- "mode": "none",
+ "mode": "development",
@@ ... @@
- "exportsDepth": Infinity,
- "exportsDepth": 9007199254740991,
+ "exportsDepth": 1,
@@ ... @@
- "chunkIds": "natural",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
- "mode": "none",
+ "mode": "development",
@@ ... @@
- "exportsDepth": Infinity,
- "exportsDepth": 9007199254740991,
+ "exportsDepth": 1,
@@ ... @@
- "chunkIds": "natural",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const applyModuleDefaults = (
D(
module.parser[JSON_MODULE_TYPE],
"exportsDepth",
mode === "development" ? 1 : Number.POSITIVE_INFINITY
mode === "development" ? 1 : Number.MAX_SAFE_INTEGER
);

if (css) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
module: {
parser: {
json: {
exportsDepth: Infinity
exportsDepth: Number.MAX_SAFE_INTEGER
}
}
}
Expand Down

0 comments on commit 610aaf0

Please sign in to comment.