Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/oxc_ast/src/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ pub struct StringLiteral<'a> {
#[content_eq(skip)]
pub raw: Option<Atom<'a>>,

/// The string value contains replacement character (U+FFFD).
/// The string value contains lone surrogates.
///
/// `value` is encoded using `\u{FFFD}` (the lossy replacement character) as an escape character.
/// Lone surrogates are encoded as `\u{FFFD}XXXX`, where `XXXX` is the code unit in hex.
/// The lossy escape character itself is encoded as `\u{FFFD}fffd`.
#[builder(default)]
#[estree(skip)]
pub lossy: bool,
pub lone_surrogates: bool,
}

/// BigInt literal
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ const _: () = {
assert!(offset_of!(StringLiteral, span) == 0);
assert!(offset_of!(StringLiteral, value) == 8);
assert!(offset_of!(StringLiteral, raw) == 24);
assert!(offset_of!(StringLiteral, lossy) == 40);
assert!(offset_of!(StringLiteral, lone_surrogates) == 40);

assert!(size_of::<BigIntLiteral>() == 32);
assert!(align_of::<BigIntLiteral>() == 8);
Expand Down Expand Up @@ -2167,7 +2167,7 @@ const _: () = {
assert!(offset_of!(StringLiteral, span) == 0);
assert!(offset_of!(StringLiteral, value) == 8);
assert!(offset_of!(StringLiteral, raw) == 16);
assert!(offset_of!(StringLiteral, lossy) == 24);
assert!(offset_of!(StringLiteral, lone_surrogates) == 24);

assert!(size_of::<BigIntLiteral>() == 20);
assert!(align_of::<BigIntLiteral>() == 4);
Expand Down
143 changes: 91 additions & 52 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,32 @@ impl<'a> AstBuilder<'a> {
Expression::StringLiteral(self.alloc_string_literal(span, value, raw))
}

/// Build an [`Expression::StringLiteral`] with `lossy`.
/// Build an [`Expression::StringLiteral`] with `lone_surrogates`.
///
/// This node contains a [`StringLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn expression_string_literal_with_lossy<A>(
pub fn expression_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> Expression<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
Expression::StringLiteral(self.alloc_string_literal_with_lossy(span, value, raw, lossy))
Expression::StringLiteral(self.alloc_string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build an [`Expression::TemplateLiteral`].
Expand Down Expand Up @@ -7843,25 +7848,30 @@ impl<'a> AstBuilder<'a> {
ImportAttributeKey::StringLiteral(self.string_literal(span, value, raw))
}

/// Build an [`ImportAttributeKey::StringLiteral`] with `lossy`.
/// Build an [`ImportAttributeKey::StringLiteral`] with `lone_surrogates`.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn import_attribute_key_string_literal_with_lossy<A>(
pub fn import_attribute_key_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> ImportAttributeKey<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
ImportAttributeKey::StringLiteral(self.string_literal_with_lossy(span, value, raw, lossy))
ImportAttributeKey::StringLiteral(self.string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build an [`ExportNamedDeclaration`].
Expand Down Expand Up @@ -8442,25 +8452,30 @@ impl<'a> AstBuilder<'a> {
ModuleExportName::StringLiteral(self.string_literal(span, value, raw))
}

/// Build a [`ModuleExportName::StringLiteral`] with `lossy`.
/// Build a [`ModuleExportName::StringLiteral`] with `lone_surrogates`.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn module_export_name_string_literal_with_lossy<A>(
pub fn module_export_name_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> ModuleExportName<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
ModuleExportName::StringLiteral(self.string_literal_with_lossy(span, value, raw, lossy))
ModuleExportName::StringLiteral(self.string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build a [`V8IntrinsicExpression`].
Expand Down Expand Up @@ -8598,7 +8613,12 @@ impl<'a> AstBuilder<'a> {
where
A: IntoIn<'a, Atom<'a>>,
{
StringLiteral { span, value: value.into_in(self.allocator), raw, lossy: Default::default() }
StringLiteral {
span,
value: value.into_in(self.allocator),
raw,
lone_surrogates: Default::default(),
}
}

/// Build a [`StringLiteral`], and store it in the memory arena.
Expand All @@ -8622,50 +8642,53 @@ impl<'a> AstBuilder<'a> {
Box::new_in(self.string_literal(span, value, raw), self.allocator)
}

/// Build a [`StringLiteral`] with `lossy`.
/// Build a [`StringLiteral`] with `lone_surrogates`.
///
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_string_literal_with_lossy`] instead.
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_string_literal_with_lone_surrogates`] instead.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn string_literal_with_lossy<A>(
pub fn string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> StringLiteral<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
StringLiteral { span, value: value.into_in(self.allocator), raw, lossy }
StringLiteral { span, value: value.into_in(self.allocator), raw, lone_surrogates }
}

/// Build a [`StringLiteral`] with `lossy`, and store it in the memory arena.
/// Build a [`StringLiteral`] with `lone_surrogates`, and store it in the memory arena.
///
/// Returns a [`Box`] containing the newly-allocated node. If you want a stack-allocated node, use [`AstBuilder::string_literal_with_lossy`] instead.
/// Returns a [`Box`] containing the newly-allocated node. If you want a stack-allocated node, use [`AstBuilder::string_literal_with_lone_surrogates`] instead.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn alloc_string_literal_with_lossy<A>(
pub fn alloc_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> Box<'a, StringLiteral<'a>>
where
A: IntoIn<'a, Atom<'a>>,
{
Box::new_in(self.string_literal_with_lossy(span, value, raw, lossy), self.allocator)
Box::new_in(
self.string_literal_with_lone_surrogates(span, value, raw, lone_surrogates),
self.allocator,
)
}

/// Build a [`BigIntLiteral`].
Expand Down Expand Up @@ -9444,29 +9467,32 @@ impl<'a> AstBuilder<'a> {
JSXAttributeValue::StringLiteral(self.alloc_string_literal(span, value, raw))
}

/// Build a [`JSXAttributeValue::StringLiteral`] with `lossy`.
/// Build a [`JSXAttributeValue::StringLiteral`] with `lone_surrogates`.
///
/// This node contains a [`StringLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn jsx_attribute_value_string_literal_with_lossy<A>(
pub fn jsx_attribute_value_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> JSXAttributeValue<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
JSXAttributeValue::StringLiteral(
self.alloc_string_literal_with_lossy(span, value, raw, lossy),
)
JSXAttributeValue::StringLiteral(self.alloc_string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build a [`JSXAttributeValue::ExpressionContainer`].
Expand Down Expand Up @@ -9949,27 +9975,32 @@ impl<'a> AstBuilder<'a> {
TSEnumMemberName::String(self.alloc_string_literal(span, value, raw))
}

/// Build a [`TSEnumMemberName::String`] with `lossy`.
/// Build a [`TSEnumMemberName::String`] with `lone_surrogates`.
///
/// This node contains a [`StringLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn ts_enum_member_name_string_with_lossy<A>(
pub fn ts_enum_member_name_string_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> TSEnumMemberName<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
TSEnumMemberName::String(self.alloc_string_literal_with_lossy(span, value, raw, lossy))
TSEnumMemberName::String(self.alloc_string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build a [`TSTypeAnnotation`].
Expand Down Expand Up @@ -10106,27 +10137,32 @@ impl<'a> AstBuilder<'a> {
TSLiteral::StringLiteral(self.alloc_string_literal(span, value, raw))
}

/// Build a [`TSLiteral::StringLiteral`] with `lossy`.
/// Build a [`TSLiteral::StringLiteral`] with `lone_surrogates`.
///
/// This node contains a [`StringLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn ts_literal_string_literal_with_lossy<A>(
pub fn ts_literal_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> TSLiteral<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
TSLiteral::StringLiteral(self.alloc_string_literal_with_lossy(span, value, raw, lossy))
TSLiteral::StringLiteral(self.alloc_string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build a [`TSLiteral::TemplateLiteral`].
Expand Down Expand Up @@ -13387,27 +13423,30 @@ impl<'a> AstBuilder<'a> {
TSModuleDeclarationName::StringLiteral(self.string_literal(span, value, raw))
}

/// Build a [`TSModuleDeclarationName::StringLiteral`] with `lossy`.
/// Build a [`TSModuleDeclarationName::StringLiteral`] with `lone_surrogates`.
///
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The value of the string.
/// * `raw`: The raw string as it appears in source code.
/// * `lossy`: The string value contains replacement character (U+FFFD).
/// * `lone_surrogates`: The string value contains lone surrogates.
#[inline]
pub fn ts_module_declaration_name_string_literal_with_lossy<A>(
pub fn ts_module_declaration_name_string_literal_with_lone_surrogates<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
lossy: bool,
lone_surrogates: bool,
) -> TSModuleDeclarationName<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
TSModuleDeclarationName::StringLiteral(
self.string_literal_with_lossy(span, value, raw, lossy),
)
TSModuleDeclarationName::StringLiteral(self.string_literal_with_lone_surrogates(
span,
value,
raw,
lone_surrogates,
))
}

/// Build a [`TSModuleDeclarationBody::TSModuleDeclaration`].
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4843,7 +4843,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for StringLiteral<'_> {
span: CloneIn::clone_in(&self.span, allocator),
value: CloneIn::clone_in(&self.value, allocator),
raw: CloneIn::clone_in(&self.raw, allocator),
lossy: CloneIn::clone_in(&self.lossy, allocator),
lone_surrogates: CloneIn::clone_in(&self.lone_surrogates, allocator),
}
}

Expand All @@ -4852,7 +4852,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for StringLiteral<'_> {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
value: CloneIn::clone_in_with_semantic_ids(&self.value, allocator),
raw: CloneIn::clone_in_with_semantic_ids(&self.raw, allocator),
lossy: CloneIn::clone_in_with_semantic_ids(&self.lossy, allocator),
lone_surrogates: CloneIn::clone_in_with_semantic_ids(&self.lone_surrogates, allocator),
}
}
}
Expand Down
Loading