Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 3dd2cd8

Browse files
committed
refactor: improve AlephResolveFold
1 parent 2b89d6e commit 3dd2cd8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

compiler/src/resolve_fold.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl Fold for AlephResolveFold {
5050
// - development mode:
5151
// - `import React, {useState} from "https://esm.sh/react"` -> `import React, {useState} from "/-/esm.sh/react.js"`
5252
// - `import * as React from "https://esm.sh/react"` -> `import * as React from "/-/esm.sh/react.js"`
53-
// - `import Logo from "../components/logo.tsx"` -> `import Logo from "/components/logo.{HASH_PLACEHOLDER}.js"`
54-
// - `import "../style/index.css" -> `import "/style/index.css.{HASH_PLACEHOLDER}.js"`
53+
// - `import Logo from "../components/logo.tsx"` -> `import Logo from "/components/logo.js"`
54+
// - `import "../style/index.css" -> `import "/style/index.css.js"`
5555
// - `export React, {useState} from "https://esm.sh/react"` -> `export React, {useState} from * from "/-/esm.sh/react.js"`
5656
// - `export * from "https://esm.sh/react"` -> `export * from "/-/esm.sh/react.js"`
5757
// - bundling mode:
@@ -216,8 +216,9 @@ impl Fold for AlephResolveFold {
216216

217217
// resolve dynamic import url & sign useDeno hook
218218
// - `import("https://esm.sh/rect")` -> `import("/-/esm.sh/react.js")`
219-
// - `import("../components/logo.tsx")` -> `import("/-/esm.sh/react.js")`
220-
// - `useDeno(() => {})` -> `useDeno(() => {}, false, "useDeno.RANDOM_KEY")`
219+
// - `import("../components/logo.tsx")` -> `import("../components/logo.js#/components/logo.tsx@000000")`
220+
// - `import("../components/logo.tsx")` -> `__ALEPH.import("../components/logo.js#/components/logo.tsx@000000", "/pages/index.tsx")`
221+
// - `useDeno(() => {})` -> `useDeno(() => {}, false, "useDeno.KEY")`
221222
fn fold_call_expr(&mut self, mut call: CallExpr) -> CallExpr {
222223
if is_call_expr_by_name(&call, "import") {
223224
let url = match call.args.first() {
@@ -241,6 +242,12 @@ impl Fold for AlephResolveFold {
241242
spread: None,
242243
expr: Box::new(Expr::Lit(Lit::Str(new_str(resolver.resolve(url, true).0)))),
243244
}];
245+
if resolver.bundle_mode {
246+
call.args.push(ExprOrSpread {
247+
spread: None,
248+
expr: Box::new(Expr::Lit(Lit::Str(new_str(resolver.specifier.clone())))),
249+
})
250+
}
244251
} else if is_call_expr_by_name(&call, "useDeno") {
245252
let callback_span = match call.args.first() {
246253
Some(ExprOrSpread { expr, .. }) => match expr.as_ref() {

compiler/src/swc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ mod tests {
595595
assert!(!code.contains("__ALEPH.pack[\"/shared/iife.ts\"]"));
596596
assert!(code.contains("import \"../shared/iife2.bundling.js#/shared/iife2.ts@000000\""));
597597
assert!(code
598-
.contains("AsyncLogo = React.lazy(()=>__ALEPH.import(\"../components/async-logo.bundle.js#/components/async-logo.tsx@000000\""));
598+
.contains("AsyncLogo = React.lazy(()=>__ALEPH.import(\"../components/async-logo.bundle.js#/components/async-logo.tsx@000000\", \"/pages/index.tsx\""));
599599
assert!(code.contains(
600600
"__ALEPH_Head = __ALEPH.pack[\"https://deno.land/x/aleph/framework/react/head.ts\"].default"
601601
));

0 commit comments

Comments
 (0)