Skip to content

Commit

Permalink
feat: add ExportsKind::None (#315)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->

### Test Plan

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---
  • Loading branch information
hyf0 authored Nov 18, 2023
1 parent 7638193 commit efdd252
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'task, T: FileSystem + Default + 'static> NormalModuleTask<'task, T> {
star_exports: Some(star_exports),
default_export_symbol: export_default_symbol_id,
scope: Some(scope),
exports_kind,
exports_kind: Some(exports_kind),
namespace_symbol: Some(namespace_symbol),
module_type: self.module_type,
is_entry: self.is_entry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use index_vec::IndexVec;
use oxc::{ast::Visit, span::SourceType};
use rolldown_common::{ModuleId, ModuleType, ResourceId, SymbolRef};
use rolldown_common::{ExportsKind, ModuleId, ModuleType, ResourceId, SymbolRef};
use rolldown_error::BuildError;
use rolldown_oxc::{OxcCompiler, OxcProgram};

Expand Down Expand Up @@ -43,12 +43,12 @@ impl RuntimeNormalModuleTask {
named_imports,
named_exports,
stmt_infos,
import_records: _,
star_exports,
export_default_symbol_id,
imports,
exports_kind,
unique_name,
import_records: _,
exports_kind: _,
} = scan_result;

builder.id = Some(self.module_id);
Expand All @@ -65,7 +65,7 @@ impl RuntimeNormalModuleTask {
builder.default_export_symbol = export_default_symbol_id;
builder.import_records = Some(IndexVec::default());
builder.scope = Some(scope);
builder.exports_kind = exports_kind;
builder.exports_kind = Some(ExportsKind::Esm);
builder.namespace_symbol = Some(namespace_symbol);
builder.pretty_path = Some("<runtime>".to_string());

Expand Down
2 changes: 1 addition & 1 deletion crates/rolldown/src/bundler/stages/link_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl LinkStage {
}
}

pub fn sort_modules(&mut self) {
fn sort_modules(&mut self) {
let mut stack = self.entries.iter().map(|(_, m)| Action::Enter(*m)).rev().collect::<Vec<_>>();
// The runtime module should always be the first module to be executed
stack.push(Action::Enter(self.runtime.id()));
Expand Down
12 changes: 6 additions & 6 deletions crates/rolldown/src/bundler/visitors/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ScanResult {
pub star_exports: Vec<ImportRecordId>,
pub export_default_symbol_id: Option<SymbolId>,
pub imports: FxHashMap<Span, ImportRecordId>,
pub exports_kind: Option<ExportsKind>,
pub exports_kind: ExportsKind,
}

pub struct Scanner<'a> {
Expand Down Expand Up @@ -92,15 +92,15 @@ impl<'a> Scanner<'a> {

fn set_exports_kind(&mut self) {
if self.esm_export_keyword.is_some() {
self.result.exports_kind = Some(ExportsKind::Esm);
self.result.exports_kind = ExportsKind::Esm;
} else if self.cjs_export_keyword.is_some() {
self.result.exports_kind = Some(ExportsKind::CommonJs);
self.result.exports_kind = ExportsKind::CommonJs;
} else if self.module_type.is_esm() {
self.result.exports_kind = Some(ExportsKind::Esm);
self.result.exports_kind = ExportsKind::Esm;
} else if self.module_type.is_commonjs() {
self.result.exports_kind = Some(ExportsKind::CommonJs);
self.result.exports_kind = ExportsKind::CommonJs;
} else {
self.result.exports_kind = Some(ExportsKind::Esm);
self.result.exports_kind = ExportsKind::Esm;
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/rolldown_common/src/exports_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
pub enum ExportsKind {
Esm,
CommonJs,
None,
}

impl Default for ExportsKind {
fn default() -> Self {
Self::None
}
}

0 comments on commit efdd252

Please sign in to comment.