Skip to content

Commit 478fa47

Browse files
authoredAug 16, 2023
feat(es/ast): Expose Archived types (#7811)
**Description:** For crates using both `rkyv` and `swc`, where ast nodes from `swc_ecma_ast` are included in data that's serialized with `rkyv`, it's difficult to access the archived data from the archived ast nodes since the types are private. More context in the issue. **Related issue:** - Closes #7810.
1 parent 023042d commit 478fa47

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
 

‎crates/swc_common/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ pub mod util;
7878

7979
#[cfg(all(not(debug_assertions), feature = "plugin-rt", feature = "plugin-mode"))]
8080
compile_error!("You can't enable `plugin-rt` and `plugin-mode` at the same time");
81+
82+
/// Warning: The particular implementation of serialization and deserialization
83+
/// of the ast nodes may change in the future, and so these types would be
84+
/// removed. It's safe to say they will be serializable in some form or another,
85+
/// but not necessarily with these specific types underlying the implementation.
86+
/// As such, *use these types at your own risk*.
87+
#[cfg(feature = "rkyv-impl")]
88+
#[doc(hidden)]
89+
pub use self::syntax_pos::{
90+
ArchivedBytePos, ArchivedCharPos, ArchivedFileName, ArchivedMultiSpan, ArchivedSourceFile,
91+
ArchivedSourceFileAndBytePos, ArchivedSpan, ArchivedSpanLinesError, ArchivedSpanSnippetError,
92+
};

‎crates/swc_ecma_ast/src/lib.rs

+97
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,100 @@ impl Default for EsVersion {
145145
EsVersion::Es5
146146
}
147147
}
148+
149+
/// Warning: The particular implementation of serialization and deserialization
150+
/// of the ast nodes may change in the future, and so these types would be
151+
/// removed. It's safe to say they will be serializable in some form or another,
152+
/// but not necessarily with these specific types underlying the implementation.
153+
/// As such, *use these types at your own risk*.
154+
#[cfg(feature = "rkyv-impl")]
155+
#[doc(hidden)]
156+
pub use self::{
157+
class::{
158+
ArchivedAutoAccessor, ArchivedClass, ArchivedClassMember, ArchivedClassMethod,
159+
ArchivedClassProp, ArchivedConstructor, ArchivedDecorator, ArchivedKey, ArchivedMethodKind,
160+
ArchivedPrivateMethod, ArchivedPrivateProp, ArchivedStaticBlock,
161+
},
162+
decl::{
163+
ArchivedClassDecl, ArchivedDecl, ArchivedFnDecl, ArchivedUsingDecl, ArchivedVarDecl,
164+
ArchivedVarDeclKind, ArchivedVarDeclarator,
165+
},
166+
expr::{
167+
ArchivedArrayLit, ArchivedArrowExpr, ArchivedAssignExpr, ArchivedAwaitExpr,
168+
ArchivedBinExpr, ArchivedBlockStmtOrExpr, ArchivedCallExpr, ArchivedCallee,
169+
ArchivedClassExpr, ArchivedCondExpr, ArchivedExpr, ArchivedExprOrSpread, ArchivedFnExpr,
170+
ArchivedImport, ArchivedMemberExpr, ArchivedMemberProp, ArchivedMetaPropExpr,
171+
ArchivedMetaPropKind, ArchivedNewExpr, ArchivedObjectLit, ArchivedOptCall,
172+
ArchivedOptChainBase, ArchivedOptChainExpr, ArchivedParenExpr, ArchivedPatOrExpr,
173+
ArchivedPropOrSpread, ArchivedSeqExpr, ArchivedSpreadElement, ArchivedSuper,
174+
ArchivedSuperProp, ArchivedSuperPropExpr, ArchivedTaggedTpl, ArchivedThisExpr, ArchivedTpl,
175+
ArchivedTplElement, ArchivedUnaryExpr, ArchivedUpdateExpr, ArchivedYieldExpr,
176+
},
177+
function::{ArchivedFunction, ArchivedParam, ArchivedParamOrTsParamProp},
178+
ident::{ArchivedBindingIdent, ArchivedIdent, ArchivedPrivateName},
179+
jsx::{
180+
ArchivedJSXAttr, ArchivedJSXAttrName, ArchivedJSXAttrOrSpread, ArchivedJSXAttrValue,
181+
ArchivedJSXClosingElement, ArchivedJSXClosingFragment, ArchivedJSXElement,
182+
ArchivedJSXElementChild, ArchivedJSXElementName, ArchivedJSXEmptyExpr, ArchivedJSXExpr,
183+
ArchivedJSXExprContainer, ArchivedJSXFragment, ArchivedJSXMemberExpr,
184+
ArchivedJSXNamespacedName, ArchivedJSXObject, ArchivedJSXOpeningElement,
185+
ArchivedJSXOpeningFragment, ArchivedJSXSpreadChild, ArchivedJSXText,
186+
},
187+
lit::{
188+
ArchivedBigInt, ArchivedBool, ArchivedLit, ArchivedNull, ArchivedNumber, ArchivedRegex,
189+
ArchivedStr,
190+
},
191+
module::{
192+
ArchivedModule, ArchivedModuleItem, ArchivedProgram, ArchivedReservedUnused, ArchivedScript,
193+
},
194+
module_decl::{
195+
ArchivedDefaultDecl, ArchivedExportAll, ArchivedExportDecl, ArchivedExportDefaultDecl,
196+
ArchivedExportDefaultExpr, ArchivedExportDefaultSpecifier, ArchivedExportNamedSpecifier,
197+
ArchivedExportNamespaceSpecifier, ArchivedExportSpecifier, ArchivedImportDecl,
198+
ArchivedImportDefaultSpecifier, ArchivedImportNamedSpecifier, ArchivedImportSpecifier,
199+
ArchivedImportStarAsSpecifier, ArchivedModuleDecl, ArchivedModuleExportName,
200+
ArchivedNamedExport,
201+
},
202+
operators::{ArchivedAssignOp, ArchivedBinaryOp, ArchivedUnaryOp, ArchivedUpdateOp},
203+
pat::{
204+
ArchivedArrayPat, ArchivedAssignPat, ArchivedAssignPatProp, ArchivedKeyValuePatProp,
205+
ArchivedObjectPat, ArchivedObjectPatProp, ArchivedPat, ArchivedRestPat,
206+
},
207+
prop::{
208+
ArchivedAssignProp, ArchivedComputedPropName, ArchivedGetterProp, ArchivedKeyValueProp,
209+
ArchivedMethodProp, ArchivedProp, ArchivedPropName, ArchivedSetterProp,
210+
},
211+
stmt::{
212+
ArchivedBlockStmt, ArchivedBreakStmt, ArchivedCatchClause, ArchivedContinueStmt,
213+
ArchivedDebuggerStmt, ArchivedDoWhileStmt, ArchivedEmptyStmt, ArchivedExprStmt,
214+
ArchivedForHead, ArchivedForInStmt, ArchivedForOfStmt, ArchivedForStmt, ArchivedIfStmt,
215+
ArchivedLabeledStmt, ArchivedReturnStmt, ArchivedStmt, ArchivedSwitchCase,
216+
ArchivedSwitchStmt, ArchivedThrowStmt, ArchivedTryStmt, ArchivedVarDeclOrExpr,
217+
ArchivedWhileStmt, ArchivedWithStmt,
218+
},
219+
typescript::{
220+
ArchivedAccessibility, ArchivedTruePlusMinus, ArchivedTsArrayType, ArchivedTsAsExpr,
221+
ArchivedTsCallSignatureDecl, ArchivedTsConditionalType, ArchivedTsConstAssertion,
222+
ArchivedTsConstructSignatureDecl, ArchivedTsConstructorType, ArchivedTsEntityName,
223+
ArchivedTsEnumDecl, ArchivedTsEnumMember, ArchivedTsEnumMemberId,
224+
ArchivedTsExportAssignment, ArchivedTsExprWithTypeArgs, ArchivedTsExternalModuleRef,
225+
ArchivedTsFnOrConstructorType, ArchivedTsFnParam, ArchivedTsFnType,
226+
ArchivedTsGetterSignature, ArchivedTsImportEqualsDecl, ArchivedTsImportType,
227+
ArchivedTsIndexSignature, ArchivedTsIndexedAccessType, ArchivedTsInferType,
228+
ArchivedTsInstantiation, ArchivedTsInterfaceBody, ArchivedTsInterfaceDecl,
229+
ArchivedTsIntersectionType, ArchivedTsKeywordType, ArchivedTsKeywordTypeKind,
230+
ArchivedTsLit, ArchivedTsLitType, ArchivedTsMappedType, ArchivedTsMethodSignature,
231+
ArchivedTsModuleBlock, ArchivedTsModuleDecl, ArchivedTsModuleName, ArchivedTsModuleRef,
232+
ArchivedTsNamespaceBody, ArchivedTsNamespaceDecl, ArchivedTsNamespaceExportDecl,
233+
ArchivedTsNonNullExpr, ArchivedTsOptionalType, ArchivedTsParamProp,
234+
ArchivedTsParamPropParam, ArchivedTsParenthesizedType, ArchivedTsPropertySignature,
235+
ArchivedTsQualifiedName, ArchivedTsRestType, ArchivedTsSatisfiesExpr,
236+
ArchivedTsSetterSignature, ArchivedTsThisType, ArchivedTsThisTypeOrIdent,
237+
ArchivedTsTplLitType, ArchivedTsTupleElement, ArchivedTsTupleType, ArchivedTsType,
238+
ArchivedTsTypeAliasDecl, ArchivedTsTypeAnn, ArchivedTsTypeAssertion, ArchivedTsTypeElement,
239+
ArchivedTsTypeLit, ArchivedTsTypeOperator, ArchivedTsTypeOperatorOp, ArchivedTsTypeParam,
240+
ArchivedTsTypeParamDecl, ArchivedTsTypeParamInstantiation, ArchivedTsTypePredicate,
241+
ArchivedTsTypeQuery, ArchivedTsTypeQueryExpr, ArchivedTsTypeRef,
242+
ArchivedTsUnionOrIntersectionType, ArchivedTsUnionType,
243+
},
244+
};

0 commit comments

Comments
 (0)