Skip to content

Commit

Permalink
refactor(span/source-type): make SourceType factories const
Browse files Browse the repository at this point in the history
I found myself wanting this while writing `no-unused-vars` and while using oxc
in some downstream personal projects.
  • Loading branch information
DonIsaac committed Aug 27, 2024
1 parent 9f526f9 commit 849d3bd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ impl SourceType {
}

#[must_use]
pub fn with_script(mut self, yes: bool) -> Self {
pub const fn with_script(mut self, yes: bool) -> Self {
if yes {
self.module_kind = ModuleKind::Script;
}
self
}

#[must_use]
pub fn with_module(mut self, yes: bool) -> Self {
pub const fn with_module(mut self, yes: bool) -> Self {
if yes {
self.module_kind = ModuleKind::Module;
} else {
Expand All @@ -87,31 +87,31 @@ impl SourceType {
}

#[must_use]
pub fn with_typescript(mut self, yes: bool) -> Self {
pub const fn with_typescript(mut self, yes: bool) -> Self {
if yes {
self.language = Language::TypeScript;
}
self
}

#[must_use]
pub fn with_typescript_definition(mut self, yes: bool) -> Self {
pub const fn with_typescript_definition(mut self, yes: bool) -> Self {
if yes {
self.language = Language::TypeScriptDefinition;
}
self
}

#[must_use]
pub fn with_jsx(mut self, yes: bool) -> Self {
pub const fn with_jsx(mut self, yes: bool) -> Self {
if yes {
self.variant = LanguageVariant::Jsx;
}
self
}

#[must_use]
pub fn with_always_strict(mut self, yes: bool) -> Self {
pub const fn with_always_strict(mut self, yes: bool) -> Self {
self.always_strict = yes;
self
}
Expand Down

0 comments on commit 849d3bd

Please sign in to comment.