Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rollup/rollup into sync-1…
Browse files Browse the repository at this point in the history
…78794ba
  • Loading branch information
docschina-bot committed Jun 8, 2024
2 parents 9cad8d8 + 178794b commit 38e5eed
Show file tree
Hide file tree
Showing 57 changed files with 1,435 additions and 1,126 deletions.
24 changes: 9 additions & 15 deletions rust/parse_ast/src/ast_nodes/arrow_function_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use swc_ecma_ast::{ArrowExpr, BlockStmtOrExpr};

use crate::convert_ast::annotations::AnnotationKind;
use crate::convert_ast::converter::ast_constants::{
ARROW_FUNCTION_EXPRESSION_ANNOTATIONS_OFFSET, ARROW_FUNCTION_EXPRESSION_ASYNC_FLAG,
ARROW_FUNCTION_EXPRESSION_BODY_OFFSET, ARROW_FUNCTION_EXPRESSION_EXPRESSION_FLAG,
ARROW_FUNCTION_EXPRESSION_FLAGS_OFFSET, ARROW_FUNCTION_EXPRESSION_GENERATOR_FLAG,
ARROW_FUNCTION_EXPRESSION_ANNOTATIONS_OFFSET, ARROW_FUNCTION_EXPRESSION_BODY_OFFSET,
ARROW_FUNCTION_EXPRESSION_PARAMS_OFFSET, ARROW_FUNCTION_EXPRESSION_RESERVED_BYTES,
TYPE_ARROW_FUNCTION_EXPRESSION,
};
use crate::convert_ast::converter::{convert_annotation, AstConverter};
use crate::store_arrow_function_expression_flags;

impl<'a> AstConverter<'a> {
pub fn store_arrow_function_expression(&mut self, arrow_expression: &ArrowExpr) {
Expand All @@ -33,18 +32,13 @@ impl<'a> AstConverter<'a> {
);
}
// flags
let mut flags = 0u32;
if arrow_expression.is_async {
flags |= ARROW_FUNCTION_EXPRESSION_ASYNC_FLAG;
}
if arrow_expression.is_generator {
flags |= ARROW_FUNCTION_EXPRESSION_GENERATOR_FLAG;
}
if let BlockStmtOrExpr::Expr(_) = &*arrow_expression.body {
flags |= ARROW_FUNCTION_EXPRESSION_EXPRESSION_FLAG;
}
let flags_position = end_position + ARROW_FUNCTION_EXPRESSION_FLAGS_OFFSET;
self.buffer[flags_position..flags_position + 4].copy_from_slice(&flags.to_ne_bytes());
store_arrow_function_expression_flags!(
self,
end_position,
async => arrow_expression.is_async,
expression => matches!(&*arrow_expression.body, BlockStmtOrExpr::Expr(_)),
generator => arrow_expression.is_generator
);
// params
self.convert_item_list(
&arrow_expression.params,
Expand Down
30 changes: 7 additions & 23 deletions rust/parse_ast/src/ast_nodes/assignment_expression.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
use swc_ecma_ast::{AssignExpr, AssignOp};

use crate::convert_ast::converter::ast_constants::{
ASSIGNMENT_EXPRESSION_LEFT_OFFSET, ASSIGNMENT_EXPRESSION_OPERATOR_OFFSET,
ASSIGNMENT_EXPRESSION_RESERVED_BYTES, ASSIGNMENT_EXPRESSION_RIGHT_OFFSET,
TYPE_ASSIGNMENT_EXPRESSION,
};
use crate::convert_ast::converter::string_constants::{
STRING_ADDASSIGN, STRING_ANDASSIGN, STRING_ASSIGN, STRING_BITANDASSIGN, STRING_BITORASSIGN,
STRING_BITXORASSIGN, STRING_DIVASSIGN, STRING_EXPASSIGN, STRING_LSHIFTASSIGN, STRING_MODASSIGN,
STRING_MULASSIGN, STRING_NULLISHASSIGN, STRING_ORASSIGN, STRING_RSHIFTASSIGN, STRING_SUBASSIGN,
STRING_ZEROFILLRSHIFTASSIGN,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_assignment_expression;

impl<'a> AstConverter<'a> {
pub fn store_assignment_expression(&mut self, assignment_expression: &AssignExpr) {
let end_position = self.add_type_and_start(
&TYPE_ASSIGNMENT_EXPRESSION,
&assignment_expression.span,
ASSIGNMENT_EXPRESSION_RESERVED_BYTES,
false,
);
// left
self.update_reference_position(end_position + ASSIGNMENT_EXPRESSION_LEFT_OFFSET);
self.convert_pattern_or_expression(&assignment_expression.left);
// operator
let operator_position = end_position + ASSIGNMENT_EXPRESSION_OPERATOR_OFFSET;
self.buffer[operator_position..operator_position + 4].copy_from_slice(
match assignment_expression.op {
store_assignment_expression!(
self,
span => assignment_expression.span,
operator => match assignment_expression.op {
AssignOp::Assign => &STRING_ASSIGN,
AssignOp::AddAssign => &STRING_ADDASSIGN,
AssignOp::SubAssign => &STRING_SUBASSIGN,
Expand All @@ -45,11 +32,8 @@ impl<'a> AstConverter<'a> {
AssignOp::OrAssign => &STRING_ORASSIGN,
AssignOp::NullishAssign => &STRING_NULLISHASSIGN,
},
left => [assignment_expression.left, convert_pattern_or_expression],
right => [assignment_expression.right, convert_expression]
);
// right
self.update_reference_position(end_position + ASSIGNMENT_EXPRESSION_RIGHT_OFFSET);
self.convert_expression(&assignment_expression.right);
// end
self.add_end(end_position, &assignment_expression.span);
}
}
18 changes: 5 additions & 13 deletions rust/parse_ast/src/ast_nodes/await_expression.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
use swc_ecma_ast::AwaitExpr;

use crate::convert_ast::converter::ast_constants::{
AWAIT_EXPRESSION_ARGUMENT_OFFSET, AWAIT_EXPRESSION_RESERVED_BYTES, TYPE_AWAIT_EXPRESSION,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_await_expression;

impl<'a> AstConverter<'a> {
pub fn store_await_expression(&mut self, await_expression: &AwaitExpr) {
let end_position = self.add_type_and_start(
&TYPE_AWAIT_EXPRESSION,
&await_expression.span,
AWAIT_EXPRESSION_RESERVED_BYTES,
false,
store_await_expression!(
self,
span => await_expression.span,
argument => [await_expression.arg, convert_expression]
);
// argument
self.update_reference_position(end_position + AWAIT_EXPRESSION_ARGUMENT_OFFSET);
self.convert_expression(&await_expression.arg);
// end
self.add_end(end_position, &await_expression.span);
}
}
20 changes: 5 additions & 15 deletions rust/parse_ast/src/ast_nodes/break_statement.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
use swc_ecma_ast::BreakStmt;

use crate::convert_ast::converter::ast_constants::{
BREAK_STATEMENT_LABEL_OFFSET, BREAK_STATEMENT_RESERVED_BYTES, TYPE_BREAK_STATEMENT,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_break_statement;

impl<'a> AstConverter<'a> {
pub fn store_break_statement(&mut self, break_statement: &BreakStmt) {
let end_position = self.add_type_and_start(
&TYPE_BREAK_STATEMENT,
&break_statement.span,
BREAK_STATEMENT_RESERVED_BYTES,
false,
store_break_statement!(
self,
span => break_statement.span,
label => [break_statement.label, convert_identifier]
);
// label
if let Some(label) = break_statement.label.as_ref() {
self.update_reference_position(end_position + BREAK_STATEMENT_LABEL_OFFSET);
self.convert_identifier(label);
}
// end
self.add_end(end_position, &break_statement.span);
}
}
11 changes: 3 additions & 8 deletions rust/parse_ast/src/ast_nodes/call_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use swc_ecma_ast::{Expr, ExprOrSpread, OptCall, Super};
use crate::convert_ast::annotations::AnnotationKind;
use crate::convert_ast::converter::ast_constants::{
CALL_EXPRESSION_ANNOTATIONS_OFFSET, CALL_EXPRESSION_ARGUMENTS_OFFSET,
CALL_EXPRESSION_CALLEE_OFFSET, CALL_EXPRESSION_FLAGS_OFFSET, CALL_EXPRESSION_OPTIONAL_FLAG,
CALL_EXPRESSION_RESERVED_BYTES, TYPE_CALL_EXPRESSION,
CALL_EXPRESSION_CALLEE_OFFSET, CALL_EXPRESSION_RESERVED_BYTES, TYPE_CALL_EXPRESSION,
};
use crate::convert_ast::converter::{convert_annotation, AstConverter};
use crate::store_call_expression_flags;

impl<'a> AstConverter<'a> {
pub fn store_call_expression(
Expand Down Expand Up @@ -39,12 +39,7 @@ impl<'a> AstConverter<'a> {
);
}
// flags
let mut flags = 0u32;
if is_optional {
flags |= CALL_EXPRESSION_OPTIONAL_FLAG;
};
let flags_position = end_position + CALL_EXPRESSION_FLAGS_OFFSET;
self.buffer[flags_position..flags_position + 4].copy_from_slice(&flags.to_ne_bytes());
store_call_expression_flags!(self, end_position, optional => is_optional);
// callee
self.update_reference_position(end_position + CALL_EXPRESSION_CALLEE_OFFSET);
match callee {
Expand Down
28 changes: 7 additions & 21 deletions rust/parse_ast/src/ast_nodes/conditional_expression.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
use swc_ecma_ast::CondExpr;

use crate::convert_ast::converter::ast_constants::{
CONDITIONAL_EXPRESSION_ALTERNATE_OFFSET, CONDITIONAL_EXPRESSION_CONSEQUENT_OFFSET,
CONDITIONAL_EXPRESSION_RESERVED_BYTES, CONDITIONAL_EXPRESSION_TEST_OFFSET,
TYPE_CONDITIONAL_EXPRESSION,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_conditional_expression;

impl<'a> AstConverter<'a> {
pub fn store_conditional_expression(&mut self, conditional_expression: &CondExpr) {
let end_position = self.add_type_and_start(
&TYPE_CONDITIONAL_EXPRESSION,
&conditional_expression.span,
CONDITIONAL_EXPRESSION_RESERVED_BYTES,
false,
store_conditional_expression!(
self,
span => conditional_expression.span,
test => [conditional_expression.test, convert_expression],
consequent => [conditional_expression.cons, convert_expression],
alternate => [conditional_expression.alt, convert_expression]
);
// test
self.update_reference_position(end_position + CONDITIONAL_EXPRESSION_TEST_OFFSET);
self.convert_expression(&conditional_expression.test);
// consequent
self.update_reference_position(end_position + CONDITIONAL_EXPRESSION_CONSEQUENT_OFFSET);
self.convert_expression(&conditional_expression.cons);
// alternate
self.update_reference_position(end_position + CONDITIONAL_EXPRESSION_ALTERNATE_OFFSET);
self.convert_expression(&conditional_expression.alt);
// end
self.add_end(end_position, &conditional_expression.span);
}
}
20 changes: 5 additions & 15 deletions rust/parse_ast/src/ast_nodes/continue_statement.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
use swc_ecma_ast::ContinueStmt;

use crate::convert_ast::converter::ast_constants::{
CONTINUE_STATEMENT_LABEL_OFFSET, CONTINUE_STATEMENT_RESERVED_BYTES, TYPE_CONTINUE_STATEMENT,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_continue_statement;

impl<'a> AstConverter<'a> {
pub fn store_continue_statement(&mut self, continue_statement: &ContinueStmt) {
let end_position = self.add_type_and_start(
&TYPE_CONTINUE_STATEMENT,
&continue_statement.span,
CONTINUE_STATEMENT_RESERVED_BYTES,
false,
store_continue_statement!(
self,
span => continue_statement.span,
label => [continue_statement.label, convert_identifier]
);
// label
if let Some(label) = continue_statement.label.as_ref() {
self.update_reference_position(end_position + CONTINUE_STATEMENT_LABEL_OFFSET);
self.convert_identifier(label);
}
// end
self.add_end(end_position, &continue_statement.span);
}
}
12 changes: 2 additions & 10 deletions rust/parse_ast/src/ast_nodes/debugger_statement.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
use swc_ecma_ast::DebuggerStmt;

use crate::convert_ast::converter::ast_constants::{
DEBUGGER_STATEMENT_RESERVED_BYTES, TYPE_DEBUGGER_STATEMENT,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_debugger_statement;

impl<'a> AstConverter<'a> {
pub fn store_debugger_statement(&mut self, debugger_statement: &DebuggerStmt) {
let end_position = self.add_type_and_start(
&TYPE_DEBUGGER_STATEMENT,
&debugger_statement.span,
DEBUGGER_STATEMENT_RESERVED_BYTES,
false,
);
self.add_end(end_position, &debugger_statement.span);
store_debugger_statement!(self, span => debugger_statement.span);
}
}
21 changes: 6 additions & 15 deletions rust/parse_ast/src/ast_nodes/directive.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
use swc_atoms::JsWord;
use swc_ecma_ast::ExprStmt;

use crate::convert_ast::converter::ast_constants::{
DIRECTIVE_DIRECTIVE_OFFSET, DIRECTIVE_EXPRESSION_OFFSET, DIRECTIVE_RESERVED_BYTES, TYPE_DIRECTIVE,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_directive;

impl<'a> AstConverter<'a> {
pub fn store_directive(&mut self, expression_statement: &ExprStmt, directive: &JsWord) {
let end_position = self.add_type_and_start(
&TYPE_DIRECTIVE,
&expression_statement.span,
DIRECTIVE_RESERVED_BYTES,
false,
store_directive!(
self,
span => expression_statement.span,
directive => directive,
expression => [expression_statement.expr, convert_expression]
);
// directive
self.convert_string(directive, end_position + DIRECTIVE_DIRECTIVE_OFFSET);
// expression
self.update_reference_position(end_position + DIRECTIVE_EXPRESSION_OFFSET);
self.convert_expression(&expression_statement.expr);
// end
self.add_end(end_position, &expression_statement.span);
}
}
23 changes: 6 additions & 17 deletions rust/parse_ast/src/ast_nodes/do_while_statement.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
use swc_ecma_ast::DoWhileStmt;

use crate::convert_ast::converter::ast_constants::{
DO_WHILE_STATEMENT_BODY_OFFSET, DO_WHILE_STATEMENT_RESERVED_BYTES,
DO_WHILE_STATEMENT_TEST_OFFSET, TYPE_DO_WHILE_STATEMENT,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_do_while_statement;

impl<'a> AstConverter<'a> {
pub fn store_do_while_statement(&mut self, do_while_statement: &DoWhileStmt) {
let end_position = self.add_type_and_start(
&TYPE_DO_WHILE_STATEMENT,
&do_while_statement.span,
DO_WHILE_STATEMENT_RESERVED_BYTES,
false,
store_do_while_statement!(
self,
span => do_while_statement.span,
body => [do_while_statement.body, convert_statement],
test => [do_while_statement.test, convert_expression]
);
// body
self.update_reference_position(end_position + DO_WHILE_STATEMENT_BODY_OFFSET);
self.convert_statement(&do_while_statement.body);
// test
self.update_reference_position(end_position + DO_WHILE_STATEMENT_TEST_OFFSET);
self.convert_expression(&do_while_statement.test);
// end
self.add_end(end_position, &do_while_statement.span);
}
}
12 changes: 2 additions & 10 deletions rust/parse_ast/src/ast_nodes/empty_statement.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
use swc_ecma_ast::EmptyStmt;

use crate::convert_ast::converter::ast_constants::{
EMPTY_STATEMENT_RESERVED_BYTES, TYPE_EMPTY_STATEMENT,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_empty_statement;

impl<'a> AstConverter<'a> {
pub fn store_empty_statement(&mut self, empty_statement: &EmptyStmt) {
let end_position = self.add_type_and_start(
&TYPE_EMPTY_STATEMENT,
&empty_statement.span,
EMPTY_STATEMENT_RESERVED_BYTES,
false,
);
self.add_end(end_position, &empty_statement.span)
store_empty_statement!(self, span => empty_statement.span);
}
}
27 changes: 7 additions & 20 deletions rust/parse_ast/src/ast_nodes/export_specifier.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
use swc_ecma_ast::ExportNamedSpecifier;

use crate::convert_ast::converter::ast_constants::{
EXPORT_SPECIFIER_EXPORTED_OFFSET, EXPORT_SPECIFIER_LOCAL_OFFSET, EXPORT_SPECIFIER_RESERVED_BYTES,
TYPE_EXPORT_SPECIFIER,
};
use crate::convert_ast::converter::AstConverter;
use crate::store_export_specifier;

impl<'a> AstConverter<'a> {
pub fn store_export_named_specifier(&mut self, export_named_specifier: &ExportNamedSpecifier) {
let end_position = self.add_type_and_start(
&TYPE_EXPORT_SPECIFIER,
&export_named_specifier.span,
EXPORT_SPECIFIER_RESERVED_BYTES,
false,
pub fn store_export_specifier(&mut self, export_named_specifier: &ExportNamedSpecifier) {
store_export_specifier!(
self,
span => &export_named_specifier.span,
local => [export_named_specifier.orig, convert_module_export_name],
exported => [export_named_specifier.exported, convert_module_export_name]
);
// local
self.update_reference_position(end_position + EXPORT_SPECIFIER_LOCAL_OFFSET);
self.convert_module_export_name(&export_named_specifier.orig);
// exported
if let Some(exported) = export_named_specifier.exported.as_ref() {
self.update_reference_position(end_position + EXPORT_SPECIFIER_EXPORTED_OFFSET);
self.convert_module_export_name(exported);
}
// end
self.add_end(end_position, &export_named_specifier.span);
}
}
Loading

0 comments on commit 38e5eed

Please sign in to comment.