Skip to content

Commit

Permalink
Proposal: module ID = 0 gets skipped when serializing tokens too (#4422)
Browse files Browse the repository at this point in the history
Just like in AST nodes.

Also I think "is_top_level" communicates intention better than is_default
  • Loading branch information
adamchalmers authored Nov 7, 2024
1 parent c8c3a24 commit 9e50b06
Show file tree
Hide file tree
Showing 14 changed files with 5 additions and 2,321 deletions.
6 changes: 4 additions & 2 deletions src/wasm-lib/kcl/src/ast/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Node<T> {
pub inner: T,
pub start: usize,
pub end: usize,
#[serde(default, skip_serializing_if = "ModuleId::is_default")]
#[serde(default, skip_serializing_if = "ModuleId::is_top_level")]
pub module_id: ModuleId,
}

Expand Down Expand Up @@ -536,7 +536,9 @@ impl ModuleId {
usize::try_from(self.0).expect("module ID should fit in a usize")
}

fn is_default(&self) -> bool {
/// Top-level file is the one being executed.
/// Represented by module ID of 0, i.e. the default value.
pub fn is_top_level(&self) -> bool {
*self == Self::default()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/wasm-lib/kcl/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub struct Token {
pub start: usize,
/// Offset in the source code where this token ends.
pub end: usize,
#[serde(default, skip_serializing_if = "ModuleId::is_top_level")]
pub module_id: ModuleId,
pub value: String,
}
Expand Down
Loading

0 comments on commit 9e50b06

Please sign in to comment.