Skip to content

Commit

Permalink
fix: agressive optimizer inlining (QwikDev#3803)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Apr 17, 2023
1 parent 26fa4a0 commit 12fc478
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 190 deletions.
127 changes: 42 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/qwik/src/optimizer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ categories = ["development-tools", "development-tools::cargo-plugins"]
crate-type = ["rlib"]

[dependencies]
swc_ecmascript = { version = "0.222.22", features = ["codegen", "utils", "visit", "parser", "transforms", "typescript", "react", "optimization"] }
swc_common = { version = "0.29.39", features = ["sourcemap"] }
swc_atoms = "0.4.39"
swc_ecmascript = { version = "0.227.16", features = ["codegen", "utils", "visit", "parser", "transforms", "typescript", "react", "optimization"] }
swc_common = { version = "0.31.4", features = ["sourcemap"] }
swc_atoms = "0.5.3"
serde = "1.0.160"
serde_bytes = "0.11.9"
serde_json = "1.0.96"
Expand Down
7 changes: 1 addition & 6 deletions packages/qwik/src/optimizer/core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::utils::{Diagnostic, DiagnosticCategory, DiagnosticScope, SourceLocati
use crate::EntryStrategy;
use path_slash::PathExt;
use serde::{Deserialize, Serialize};
use swc_ecmascript::transforms::optimization::simplify::inlining::inlining;

#[cfg(feature = "fs")]
use std::fs;
Expand Down Expand Up @@ -283,6 +282,7 @@ pub fn transform_code(config: TransformCodeOptions) -> Result<TransformOutput, a
Some(&comments),
react_options,
top_level_mark,
unresolved_mark,
));
}

Expand All @@ -292,11 +292,6 @@ pub fn transform_code(config: TransformCodeOptions) -> Result<TransformOutput, a
top_level_mark,
is_type_script && !transpile_ts,
));

if transpile_ts {
main_module.visit_mut_with(&mut inlining(Default::default()));
}

// Collect import/export metadata
let mut collect = global_collect(&main_module);

Expand Down
10 changes: 10 additions & 0 deletions packages/qwik/src/optimizer/core/src/props_destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ fn transform_component_body(body: &mut ast::BlockStmt, props_transform: &mut Pro
if var_decl.kind == ast::VarDeclKind::Const {
for decl in var_decl.decls.iter_mut() {
let convert = match &decl.init {
Some(box ast::Expr::Lit(lit)) => {
let new_ident = private_ident!("_unused");
Some((
new_ident,
ast::Expr::Lit(lit.clone()),
TransformInit::Remove,
))
}
Some(box ast::Expr::Member(member_expr)) => match &member_expr.obj {
box ast::Expr::Ident(ident) => {
let new_ident = private_ident!("_unused");
Expand Down Expand Up @@ -253,6 +261,8 @@ fn transform_component_body(body: &mut ast::BlockStmt, props_transform: &mut Pro
}
}
}
} else {
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,21 @@ import { bar } from "./project/test";
import { c } from "./project/test";
import { d } from "./project/test";
import { e } from "./project/test";
import { exp1 } from "./project/test";
import { f } from "./project/test";
import { foo } from "./project/test";
import { expr2 as internal } from "./project/test";
export const Header_component_1_uWM1kg0IGO0 = ()=><Footer>

<div>{a}{b}{c}{d}{e}{f}{1}{2}{foo}{bar}{DefaultFn}</div>
<div>{a}{b}{c}{d}{e}{f}{exp1}{internal}{foo}{bar}{DefaultFn}</div>

<div>{v1}{v2}{v3}{obj}</div>

</Footer>;
export { _hW } from "@builder.io/qwik";


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/project/test.tsx\"],\"names\":[],\"mappings\":\";;;;;;;;;;8CAea,KACJ,OAAO;;YACJ,CAAC,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,GAZpB,GACI,GAWmC,KAAK,KAAK,YAAY,IAAI;;YAClE,CAAC,KAAK,IAAI,IAAI,IAAI,MAAM,IAAI;;QAChC,EAAE\"}")
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/project/test.tsx\"],\"names\":[],\"mappings\":\";;;;;;;;;;;;8CAea,KACJ,OAAO;;YACJ,CAAC,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,UAAU,KAAK,KAAK,YAAY,IAAI;;YAClE,CAAC,KAAK,IAAI,IAAI,IAAI,MAAM,IAAI;;QAChC,EAAE\"}")
/*
{
"origin": "project/test.tsx",
Expand Down
Loading

0 comments on commit 12fc478

Please sign in to comment.