-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/minifier): Support
module: "unknown"
(#9026)
**Related issue:** - Closes #8571
- Loading branch information
Showing
11 changed files
with
119 additions
and
102 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
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
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::fmt; | ||
|
||
use serde::{ | ||
de::{Unexpected, Visitor}, | ||
Deserialize, Deserializer, Serialize, Serializer, | ||
}; | ||
|
||
use crate::merge::Merge; | ||
|
||
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub enum IsModule { | ||
Bool(bool), | ||
Unknown, | ||
} | ||
|
||
impl Default for IsModule { | ||
fn default() -> Self { | ||
IsModule::Bool(true) | ||
} | ||
} | ||
|
||
impl Merge for IsModule { | ||
fn merge(&mut self, other: Self) { | ||
if *self == Default::default() { | ||
*self = other; | ||
} | ||
} | ||
} | ||
|
||
impl Serialize for IsModule { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
match *self { | ||
IsModule::Bool(ref b) => b.serialize(serializer), | ||
IsModule::Unknown => "unknown".serialize(serializer), | ||
} | ||
} | ||
} | ||
|
||
struct IsModuleVisitor; | ||
|
||
impl<'de> Visitor<'de> for IsModuleVisitor { | ||
type Value = IsModule; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("a boolean or the string 'unknown'") | ||
} | ||
|
||
fn visit_bool<E>(self, b: bool) -> Result<Self::Value, E> | ||
where | ||
E: serde::de::Error, | ||
{ | ||
Ok(IsModule::Bool(b)) | ||
} | ||
|
||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E> | ||
where | ||
E: serde::de::Error, | ||
{ | ||
match s { | ||
"unknown" => Ok(IsModule::Unknown), | ||
_ => Err(serde::de::Error::invalid_value(Unexpected::Str(s), &self)), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for IsModule { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
deserializer.deserialize_any(IsModuleVisitor) | ||
} | ||
} |
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
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
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,7 +1,7 @@ | ||
{ | ||
"name": "@swc/types", | ||
"packageManager": "[email protected]", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Typings for the swc project.", | ||
"sideEffects": false, | ||
"scripts": { | ||
|