Skip to content

Commit 4718b53

Browse files
authored
Merge pull request #7879 from QwikDev/v2-update-rust
chore: update rust version
2 parents 870a90a + a5bc0c1 commit 4718b53

19 files changed

+789
-801
lines changed

Cargo.lock

Lines changed: 564 additions & 562 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/qwik/src/optimizer/core/src/add_side_effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use std::path::Path;
44
use crate::collector::GlobalCollect;
55
use crate::parse::PathData;
66
use path_slash::PathBufExt;
7-
use swc_atoms::JsWord;
7+
use swc_atoms::Atom;
88
use swc_common::DUMMY_SP;
99
use swc_ecmascript::ast;
1010
use swc_ecmascript::visit::{VisitMut, VisitMutWith};
1111

1212
pub struct SideEffectVisitor<'a> {
1313
global_collector: &'a GlobalCollect,
14-
imports: HashSet<JsWord>,
14+
imports: HashSet<Atom>,
1515
path_data: &'a PathData,
1616
src_dir: &'a Path,
1717
}

packages/qwik/src/optimizer/core/src/code_move.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::words::*;
55

66
use anyhow::Error;
77
use std::collections::BTreeMap;
8-
use swc_atoms::JsWord;
8+
use swc_atoms::Atom;
99
use swc_common::comments::{SingleThreadedComments, SingleThreadedCommentsMap};
1010
use swc_common::DUMMY_SP;
1111
use swc_ecmascript::ast;
@@ -24,7 +24,7 @@ pub struct NewModuleCtx<'a> {
2424
pub local_idents: &'a [Id],
2525
pub scoped_idents: &'a [Id],
2626
pub global: &'a GlobalCollect,
27-
pub core_module: &'a JsWord,
27+
pub core_module: &'a Atom,
2828
pub need_transform: bool,
2929
pub explicit_extensions: bool,
3030
pub leading_comments: SingleThreadedCommentsMap,
@@ -162,7 +162,7 @@ fn create_named_export(expr: Box<ast::Expr>, name: &str) -> ast::ModuleItem {
162162
span: DUMMY_SP,
163163
definite: false,
164164
name: ast::Pat::Ident(ast::BindingIdent::from(ast::Ident::new(
165-
JsWord::from(name),
165+
Atom::from(name),
166166
DUMMY_SP,
167167
Default::default(),
168168
))),

packages/qwik/src/optimizer/core/src/collector.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::{HashMap, HashSet};
22

3-
use swc_atoms::{js_word, JsWord};
3+
use swc_atoms::{atom, Atom};
44
use swc_common::{Span, SyntaxContext, DUMMY_SP};
55
use swc_ecmascript::ast;
66
use swc_ecmascript::utils::private_ident;
@@ -12,7 +12,7 @@ macro_rules! id {
1212
};
1313
}
1414

15-
pub type Id = (JsWord, SyntaxContext);
15+
pub type Id = (Atom, SyntaxContext);
1616

1717
pub fn new_ident_from_id(id: &Id) -> ast::Ident {
1818
ast::Ident::new(id.0.clone(), DUMMY_SP, id.1)
@@ -27,8 +27,8 @@ pub enum ImportKind {
2727

2828
#[derive(Clone)]
2929
pub struct Import {
30-
pub source: JsWord,
31-
pub specifier: JsWord,
30+
pub source: Atom,
31+
pub specifier: Atom,
3232
pub kind: ImportKind,
3333
pub synthetic: bool,
3434
pub asserts: Option<Box<ast::ObjectLit>>,
@@ -37,10 +37,10 @@ pub struct Import {
3737
pub struct GlobalCollect {
3838
pub synthetic: Vec<(Id, Import)>,
3939
pub imports: HashMap<Id, Import>,
40-
pub exports: HashMap<Id, Option<JsWord>>,
40+
pub exports: HashMap<Id, Option<Atom>>,
4141
pub root: HashMap<Id, Span>,
4242

43-
rev_imports: HashMap<(JsWord, JsWord), Id>,
43+
rev_imports: HashMap<(Atom, Atom), Id>,
4444
in_export_decl: bool,
4545
}
4646

@@ -60,7 +60,7 @@ pub fn global_collect(program: &ast::Program) -> GlobalCollect {
6060
}
6161

6262
impl GlobalCollect {
63-
pub fn get_imported_local(&self, specifier: &JsWord, source: &JsWord) -> Option<Id> {
63+
pub fn get_imported_local(&self, specifier: &Atom, source: &Atom) -> Option<Id> {
6464
self.imports
6565
.iter()
6666
.find(|(_, import)| &import.specifier == specifier && &import.source == source)
@@ -80,7 +80,7 @@ impl GlobalCollect {
8080
false
8181
}
8282

83-
pub fn import(&mut self, specifier: &JsWord, source: &JsWord) -> Id {
83+
pub fn import(&mut self, specifier: &Atom, source: &Atom) -> Id {
8484
self.rev_imports
8585
.get(&(specifier.clone(), source.clone()))
8686
.cloned()
@@ -114,7 +114,7 @@ impl GlobalCollect {
114114
self.imports.insert(local, import);
115115
}
116116

117-
pub fn add_export(&mut self, local: Id, exported: Option<JsWord>) -> bool {
117+
pub fn add_export(&mut self, local: Id, exported: Option<Atom>) -> bool {
118118
if let std::collections::hash_map::Entry::Vacant(e) = self.exports.entry(local) {
119119
e.insert(exported);
120120
true
@@ -177,7 +177,7 @@ impl Visit for GlobalCollect {
177177
id!(default.local),
178178
Import {
179179
source: node.src.value.clone(),
180-
specifier: js_word!("default"),
180+
specifier: atom!("default"),
181181
kind: ImportKind::Default,
182182
synthetic: false,
183183
asserts: node.with.clone(),
@@ -223,7 +223,7 @@ impl Visit for GlobalCollect {
223223
ast::ExportSpecifier::Default(default) => {
224224
self.exports
225225
.entry(id!(default.exported))
226-
.or_insert(Some(js_word!("default")));
226+
.or_insert(Some(atom!("default")));
227227
}
228228
ast::ExportSpecifier::Namespace(namespace) => {
229229
if let ast::ModuleExportName::Ident(ident) = &namespace.name {
@@ -264,12 +264,12 @@ impl Visit for GlobalCollect {
264264
match &node.decl {
265265
ast::DefaultDecl::Class(class) => {
266266
if let Some(ident) = &class.ident {
267-
self.add_export(id!(ident), Some(js_word!("default")));
267+
self.add_export(id!(ident), Some(atom!("default")));
268268
}
269269
}
270270
ast::DefaultDecl::Fn(func) => {
271271
if let Some(ident) = &func.ident {
272-
self.add_export(id!(ident), Some(js_word!("default")));
272+
self.add_export(id!(ident), Some(atom!("default")));
273273
}
274274
}
275275
_ => {

packages/qwik/src/optimizer/core/src/entry_strategy.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::transform::{SegmentData, SegmentKind};
22
use serde::{Deserialize, Serialize};
3-
use swc_atoms::JsWord;
3+
use swc_atoms::Atom;
44

55
use lazy_static::lazy_static;
66

77
lazy_static! {
8-
static ref ENTRY_SEGMENTS: JsWord = JsWord::from("entry_segments");
8+
static ref ENTRY_SEGMENTS: Atom = Atom::from("entry_segments");
99
}
1010

1111
// EntryStrategies
@@ -22,14 +22,14 @@ pub enum EntryStrategy {
2222
}
2323

2424
pub trait EntryPolicy: Send + Sync {
25-
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<JsWord>;
25+
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<Atom>;
2626
}
2727

2828
#[derive(Default, Clone)]
2929
pub struct InlineStrategy;
3030

3131
impl EntryPolicy for InlineStrategy {
32-
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<JsWord> {
32+
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<Atom> {
3333
Some(ENTRY_SEGMENTS.clone())
3434
}
3535
}
@@ -44,7 +44,7 @@ impl SingleStrategy {
4444
}
4545

4646
impl EntryPolicy for SingleStrategy {
47-
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<JsWord> {
47+
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<Atom> {
4848
Some(ENTRY_SEGMENTS.clone())
4949
}
5050
}
@@ -59,7 +59,7 @@ impl PerSegmentStrategy {
5959
}
6060

6161
impl EntryPolicy for PerSegmentStrategy {
62-
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<JsWord> {
62+
fn get_entry_for_sym(&self, _context: &[String], _segment: &SegmentData) -> Option<Atom> {
6363
None
6464
}
6565
}
@@ -74,10 +74,10 @@ impl PerComponentStrategy {
7474
}
7575

7676
impl EntryPolicy for PerComponentStrategy {
77-
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<JsWord> {
77+
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<Atom> {
7878
context.first().map_or_else(
7979
|| Some(ENTRY_SEGMENTS.clone()),
80-
|root| Some(JsWord::from([&segment.origin, "_entry_", root].concat())),
80+
|root| Some(Atom::from([&segment.origin, "_entry_", root].concat())),
8181
)
8282
}
8383
}
@@ -92,7 +92,7 @@ impl SmartStrategy {
9292
}
9393

9494
impl EntryPolicy for SmartStrategy {
95-
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<JsWord> {
95+
fn get_entry_for_sym(&self, context: &[String], segment: &SegmentData) -> Option<Atom> {
9696
// Event handlers without scope variables are put into a separate file
9797
if segment.scoped_idents.is_empty()
9898
&& (segment.ctx_kind != SegmentKind::Function || &segment.ctx_name == "event$")
@@ -107,7 +107,7 @@ impl EntryPolicy for SmartStrategy {
107107
// Top-level QRLs are put into a separate file
108108
|| None,
109109
// Other QRLs are put into a file named after the original file + the root component
110-
|root| Some(JsWord::from([&segment.origin, "_entry_", root].concat())),
110+
|root| Some(Atom::from([&segment.origin, "_entry_", root].concat())),
111111
)
112112
}
113113
}

packages/qwik/src/optimizer/core/src/filter_exports.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use swc_atoms::JsWord;
1+
use swc_atoms::Atom;
22
use swc_common::DUMMY_SP;
33
use swc_ecmascript::ast;
44
use swc_ecmascript::visit::VisitMut;
55

66
pub struct StripExportsVisitor<'a> {
7-
pub filter_symbols: &'a [JsWord],
7+
pub filter_symbols: &'a [Atom],
88
}
99

1010
impl<'a> StripExportsVisitor<'a> {
11-
pub const fn new(filter_symbols: &'a [JsWord]) -> Self {
11+
pub const fn new(filter_symbols: &'a [Atom]) -> Self {
1212
Self { filter_symbols }
1313
}
1414
}
@@ -61,7 +61,7 @@ fn empty_module_item(ident: ast::Ident) -> ast::ModuleItem {
6161
span: DUMMY_SP,
6262
arg: Box::new(ast::Expr::Lit(ast::Lit::Str(ast::Str {
6363
span: DUMMY_SP,
64-
value: JsWord::from("Symbol removed by Qwik Optimizer, it can not be called from current platform"),
64+
value: Atom::from("Symbol removed by Qwik Optimizer, it can not be called from current platform"),
6565
raw: None,
6666
}))),
6767
})],

packages/qwik/src/optimizer/core/src/inlined_fn.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,14 @@ pub fn render_expr(expr: &ast::Expr) -> String {
200200
expr.visit_mut_with(&mut hygiene_with_config(Default::default()));
201201
expr.visit_mut_with(&mut fixer(None));
202202
emitter
203-
.emit_module_item(&ast::ModuleItem::Stmt(ast::Stmt::Expr(ast::ExprStmt {
203+
.emit_module(&ast::Module {
204204
span: DUMMY_SP,
205-
expr: Box::new(expr),
206-
})))
205+
body: vec![ast::ModuleItem::Stmt(ast::Stmt::Expr(ast::ExprStmt {
206+
span: DUMMY_SP,
207+
expr: Box::new(expr),
208+
}))],
209+
shebang: None,
210+
})
207211
.expect("Should emit");
208212

209213
str::from_utf8(&buf)

packages/qwik/src/optimizer/core/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use anyhow::Error;
3131
use serde::{Deserialize, Serialize};
3232
use std::path::Path;
3333
use std::str;
34-
use swc_atoms::JsWord;
34+
use swc_atoms::Atom;
3535

3636
use crate::entry_strategy::parse_entry_strategy;
3737
pub use crate::entry_strategy::EntryStrategy;
@@ -65,17 +65,17 @@ pub struct TransformModulesOptions {
6565
pub scope: Option<String>,
6666

6767
pub core_module: Option<String>,
68-
pub strip_exports: Option<Vec<JsWord>>,
69-
pub strip_ctx_name: Option<Vec<JsWord>>,
68+
pub strip_exports: Option<Vec<Atom>>,
69+
pub strip_ctx_name: Option<Vec<Atom>>,
7070
pub strip_event_handlers: bool,
71-
pub reg_ctx_name: Option<Vec<JsWord>>,
71+
pub reg_ctx_name: Option<Vec<Atom>>,
7272
pub is_server: Option<bool>,
7373
}
7474

7575
pub fn transform_modules(config: TransformModulesOptions) -> Result<TransformOutput, Error> {
7676
let core_module = config
7777
.core_module
78-
.map_or(BUILDER_IO_QWIK.clone(), |s| s.into());
78+
.map_or_else(|| BUILDER_IO_QWIK.clone(), |s| s.into());
7979
let src_dir = std::path::Path::new(&config.src_dir);
8080
let root_dir = config.root_dir.as_ref().map(Path::new);
8181

0 commit comments

Comments
 (0)