mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
feat(plugin): Allow taking the inner data from versioned (#5071)
This commit is contained in:
parent
dcc4f2a706
commit
e1aa937183
@ -4,7 +4,7 @@
|
||||
//! `swc_common`.
|
||||
#![allow(unused)]
|
||||
|
||||
use std::any::type_name;
|
||||
use std::{any::type_name, mem};
|
||||
|
||||
use anyhow::Error;
|
||||
use bytecheck::CheckBytes;
|
||||
@ -174,4 +174,27 @@ impl Serialized {
|
||||
#[derive(Archive, Deserialize, Serialize)]
|
||||
#[repr(transparent)]
|
||||
#[archive_attr(repr(transparent), derive(CheckBytes))]
|
||||
pub struct VersionedSerializable<T>(#[with(AsBox)] pub (u32, T));
|
||||
pub struct VersionedSerializable<T>(#[with(AsBox)] (u32, T));
|
||||
|
||||
impl<T> VersionedSerializable<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
// TODO: we'll add compile time flag to augment schema version.
|
||||
// User should not try to set version by themselves.
|
||||
VersionedSerializable((1, value))
|
||||
}
|
||||
|
||||
pub fn version(&self) -> u32 {
|
||||
self.0 .0
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &T {
|
||||
&self.0 .1
|
||||
}
|
||||
|
||||
pub fn take(&mut self) -> T
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
mem::take(&mut self.0 .1)
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,12 @@ pub enum Program {
|
||||
Script(Script),
|
||||
}
|
||||
|
||||
impl Default for Program {
|
||||
fn default() -> Self {
|
||||
Program::Module(Module::dummy())
|
||||
}
|
||||
}
|
||||
|
||||
#[ast_node("Module")]
|
||||
#[derive(Eq, Hash, EqIgnoreSpan)]
|
||||
pub struct Module {
|
||||
|
Loading…
Reference in New Issue
Block a user