Skip to content

Commit eb7051f

Browse files
authored
fix: export without specifier (#2421)
* fix: export without specifier * fix: test
1 parent b4c5ed5 commit eb7051f

File tree

46 files changed

+386
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+386
-34
lines changed

.changeset/cyan-emus-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rspack/core": patch
3+
---
4+
5+
fix: export without specifier

crates/rspack_plugin_javascript/src/visitors/dependency/scanner.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rspack_regex::RspackRegex;
77
use sugar_path::SugarPath;
88
use swc_core::common::{pass::AstNodePath, Mark, SyntaxContext};
99
use swc_core::ecma::ast::{
10-
BinExpr, BinaryOp, CallExpr, Callee, ExportSpecifier, Expr, Lit, MemberProp, ModuleDecl, Tpl,
10+
BinExpr, BinaryOp, CallExpr, Callee, Expr, Lit, MemberProp, ModuleDecl, Tpl,
1111
};
1212
use swc_core::ecma::utils::{quote_ident, quote_str};
1313
use swc_core::ecma::visit::{AstParentNodeRef, VisitAstPath, VisitWithPath};
@@ -131,39 +131,14 @@ impl DependencyScanner<'_> {
131131
) -> Result<(), anyhow::Error> {
132132
match module_decl {
133133
ModuleDecl::ExportNamed(node) => {
134-
node.specifiers.iter().for_each(|specifier| {
135-
match specifier {
136-
ExportSpecifier::Named(_s) => {
137-
if let Some(source_node) = &node.src {
138-
// export { name } from './other'
139-
// TODO: this should ignore from code generation or use a new dependency instead
140-
self.add_dependency(box EsmExportDependency::new(
141-
source_node.value.clone(),
142-
Some(node.span.into()),
143-
as_parent_path(ast_path),
144-
));
145-
}
146-
}
147-
ExportSpecifier::Namespace(_s) => {
148-
// export * as name from './other'
149-
let source = node
150-
.src
151-
.as_ref()
152-
.map(|str| str.value.clone())
153-
.expect("TODO:");
154-
// TODO: this should ignore from code generation or use a new dependency instead
155-
self.add_dependency(box EsmExportDependency::new(
156-
source,
157-
Some(node.span.into()),
158-
as_parent_path(ast_path),
159-
));
160-
}
161-
ExportSpecifier::Default(_) => {
162-
// export v from 'mod';
163-
// Rollup doesn't support it.
164-
}
165-
};
166-
});
134+
if let Some(src) = &node.src {
135+
// TODO: this should ignore from code generation or use a new dependency instead
136+
self.add_dependency(box EsmExportDependency::new(
137+
src.value.clone(),
138+
Some(node.span.into()),
139+
as_parent_path(ast_path),
140+
));
141+
}
167142
}
168143
ModuleDecl::ExportAll(node) => {
169144
// export * from './other'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export var x = 1;
2+
export * from "./cjs";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { c } from "./c.js";
2+
3+
const b2 = 3;
4+
const b3 = c;
5+
export { c as b1, c as b4, b2, b3 };
6+
// export const usedB1 = __webpack_exports_info__.b1.used;
7+
// export const usedB2 = __webpack_exports_info__.b2.used;
8+
// export const usedB3 = __webpack_exports_info__.b3.used;
9+
// export const usedB4 = __webpack_exports_info__.b4.used;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as c from "./d.js";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { x: 2, y: 3 };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports.a = 2;
2+
exports.b = 3;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./cjs1");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const d1 = 1;
2+
export const d2 = 2;
3+
// export const usedD1 = __webpack_exports_info__.d1.used;
4+
// export const usedD2 = __webpack_exports_info__.d2.used;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const e1 = 10;
2+
export const e2 = 20;
3+
// export const usedE1 = __webpack_exports_info__.e1.used;
4+
// export const usedE2 = __webpack_exports_info__.e2.used;

0 commit comments

Comments
 (0)