oxc/crates/oxc_syntax/src/node.rs
Boshen 697b6b70c0
feat: merge features serde and wasm to serialize (#2716)
This PR merges the previous confusing features `serde` and `wasm` into a
single `serialize` feature.

We'll eventually do serialize + type information for both wasm and napi
targets.

`oxc_macros` is removed from `oxc_ast`'s dependency because it requires
`syn` and friends, which goes against our policy ["Third-party
dependencies should be
minimal."](https://oxc-project.github.io/docs/contribute/rules.html#development-policy)
2024-03-14 17:13:12 +08:00

41 lines
960 B
Rust

use bitflags::bitflags;
use oxc_index::define_index_type;
define_index_type! {
pub struct AstNodeId = usize;
}
#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = r#"
export type AstNodeId = number;
export type NodeFlags = {
JSDoc: 1,
Class: 2,
HasYield: 4
};
"#;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NodeFlags: u8 {
const JSDoc = 1 << 0; // If the Node has a JSDoc comment attached
const Class = 1 << 1; // If Node is inside a class
const HasYield = 1 << 2; // If function has yield statement
}
}
impl NodeFlags {
pub fn has_jsdoc(&self) -> bool {
self.contains(Self::JSDoc)
}
pub fn has_class(&self) -> bool {
self.contains(Self::Class)
}
pub fn has_yield(&self) -> bool {
self.contains(Self::HasYield)
}
}