Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/too_many_file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed Aug 30, 2024
2 parents e39b668 + 5ee13bb commit f7a36b0
Show file tree
Hide file tree
Showing 44 changed files with 742 additions and 330 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 0.8.7

`2024-08-30`

* refactor: 🎨 assign tpl's span to literal string by [@stormslowly](https://github.com/umijs/mako/pull/1529)
* perf: reapply pr 1509 and sourcemap missing when chain_map is empty by [@xusd320](https://github.com/umijs/mako/pull/1542)
* chore: ✨ strip span when parsing define's expression by [@stormslowly](https://github.com/umijs/mako/pull/1540)
* feat: support to control crossorigin for async chunk scripts and links by [@PeachScript](https://github.com/umijs/mako/)pull/1539
* refactory: in str-impl chunk generate, remove cm when merge_code_and_sourcemap by [@stormslowly](https://github.com/umijs/mako/pull/1541)
* fix: entry support sub paths by [@sorrycc](https://github.com/umijs/mako/pull/1547)
* fix: filename too long when use pnpm by [@Jinbao1001](https://github.com/umijs/mako/pull/1421)
* refactor: Unify the static server in bundler-mako and devServer by [@whyer11](https://github.com/umijs/mako/pull/1468)
* feat: #1491 add duplicate package checker plugin by [@jeasonnow](https://github.com/umijs/mako/pull/1496)
* fix: #1478 support react class-component hot-update by [@jeasonnow](https://github.com/umijs/mako/pull/1489)
* fix(plugin:emotion): panic when target to chrome 40 by [@stormslowly](https://github.com/umijs/mako/pull/1527)


**Full Changelog**: https://github.com/umijs/mako/compare/v0.8.4...v0.8.7


## 0.8.4

`2024-08-23`
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG_zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 0.8.7

`2024-08-30`

* 特性: 支持控制异步块脚本和链接的 crossorigin 属性 by [@PeachScript](https://github.com/umijs/mako/)pull/1539
* 特性: 添加重复包检查插件 by [@jeasonnow](https://github.com/umijs/mako/pull/1496)
* 重构: 在 str-impl 块生成中,当 merge_code_and_sourcemap 时删除 cm by [@stormslowly](https://github.com/umijs/mako/pull/1541)
* 重构: 统一 bundler-mako 和 devServer 中的静态服务器 by [@whyer11](https://github.com/umijs/mako/pull/1468)
* 修复: 修复入口支持子路径的问题 by [@sorrycc](https://github.com/umijs/mako/pull/1547)
* 修复: 修复使用 pnpm 时文件名过长的问题 by [@Jinbao1001](https://github.com/umijs/mako/pull/1421)
* 修复: 支持 React 类组件热更新 by [@jeasonnow](https://github.com/umijs/mako/pull/1489)
* 修复(plugin:emotion): 修复将目标设置为 Chrome 40 时 emotion 插件崩溃的问题 by [@stormslowly](https://github.com/umijs/mako/pull/1527)
* 改进: 🎨 将 tpl 的 span 分配给文字字符串 by [@stormslowly](https://github.com/umijs/mako/pull/1529)
* 优化: 重新应用 PR 1509,修复 chain_map 为空时 sourcemap 丢失的问题 by [@xusd320](https://github.com/umijs/mako/pull/1542)
* 杂项: 解析 define 表达式时去除 span by [@stormslowly](https://github.com/umijs/mako/pull/1540)



## 0.8.4

`2024-08-23`
Expand Down
17 changes: 9 additions & 8 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/mako/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ puffin_egui = { version = "0.22.0", optional = true }
rayon = "1.7.0"
regex = "1.9.3"
sailfish = "0.8.3"
semver = "1.0.23"
serde-xml-rs = "0.6.0"
serde_yaml = "0.9.22"
svgr-rs = "0.1.3"
Expand Down
101 changes: 35 additions & 66 deletions crates/mako/src/ast/js_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::fmt;
use std::sync::Arc;

use anyhow::{anyhow, Result};
use swc_core::base::try_with_handler;
use swc_core::common::errors::HANDLER;
use swc_core::common::util::take::Take;
use swc_core::common::{FileName, Mark, Spanned, GLOBALS};
use swc_core::ecma::ast::{EsVersion, Module};
Expand All @@ -12,7 +10,7 @@ use swc_core::ecma::codegen::{Config as JsCodegenConfig, Emitter};
use swc_core::ecma::parser::error::SyntaxError;
use swc_core::ecma::parser::lexer::Lexer;
use swc_core::ecma::parser::{EsConfig, Parser, StringInput, Syntax, TsConfig};
use swc_core::ecma::transforms::base::helpers::{inject_helpers, Helpers, HELPERS};
use swc_core::ecma::transforms::base::helpers::inject_helpers;
use swc_core::ecma::utils::contains_top_level_await;
use swc_core::ecma::visit;
use swc_core::ecma::visit::{VisitMutWith, VisitWith};
Expand All @@ -23,7 +21,6 @@ use crate::ast::{error, utils};
use crate::compiler::Context;
use crate::config::{DevtoolConfig, Mode, OutputMode};
use crate::module::Dependency;
use crate::plugin::PluginTransformJsParam;
use crate::utils::base64_encode;
use crate::visitors::dep_analyzer::DepAnalyzer;

Expand Down Expand Up @@ -134,74 +131,46 @@ impl JsAst {
&mut self,
mut_visitors: &mut Vec<Box<dyn visit::VisitMut>>,
folders: &mut Vec<Box<dyn visit::Fold>>,
file: &File,
should_inject_helpers: bool,
context: Arc<Context>,
_context: Arc<Context>,
) -> Result<()> {
let cm = context.meta.script.cm.clone();
GLOBALS.set(&context.meta.script.globals, || {
try_with_handler(cm, Default::default(), |handler| {
HELPERS.set(&Helpers::new(true), || {
HANDLER.set(handler, || {
let ast = &mut self.ast;

// visitors
for visitor in mut_visitors {
ast.visit_mut_with(visitor.as_mut());
}
let ast = &mut self.ast;

// folders
let body = ast.body.take();
let mut module = Module {
span: ast.span,
shebang: ast.shebang.clone(),
body,
};
for folder in folders {
module = folder.as_mut().fold_module(module);
}
ast.body = module.body;
// visitors
for visitor in mut_visitors {
ast.visit_mut_with(visitor.as_mut());
}

// transform with plugin
context.plugin_driver.transform_js(
&PluginTransformJsParam {
handler,
path: file.path.to_str().unwrap(),
top_level_mark: self.top_level_mark,
unresolved_mark: self.unresolved_mark,
},
ast,
&context,
)?;
// folders
let mut module = ast.take();
for folder in folders {
module = folder.as_mut().fold_module(module);
}
*ast = module;

// FIXME: remove this, it's special logic
// inject helpers
// why need to handle cjs specially?
// because the ast is currently a module, not a program
// if not handled specially, the injected helpers will all be in esm format
// which is not as expected in the cjs scenario
// ref: https://github.com/umijs/mako/pull/831
if should_inject_helpers {
if utils::is_esm(ast) {
ast.visit_mut_with(&mut inject_helpers(self.unresolved_mark));
} else {
let body = ast.body.take();
let mut script_ast = swc_core::ecma::ast::Script {
span: ast.span,
shebang: ast.shebang.clone(),
body: body.into_iter().map(|i| i.stmt().unwrap()).collect(),
};
script_ast
.visit_mut_with(&mut inject_helpers(self.unresolved_mark));
ast.body = script_ast.body.into_iter().map(|i| i.into()).collect();
}
}
// FIXME: remove this, it's special logic
// inject helpers
// why need to handle cjs specially?
// because the ast is currently a module, not a program
// if not handled specially, the injected helpers will all be in esm format
// which is not as expected in the cjs scenario
// ref: https://github.com/umijs/mako/pull/831
if should_inject_helpers {
if utils::is_esm(ast) {
ast.visit_mut_with(&mut inject_helpers(self.unresolved_mark));
} else {
let body = ast.body.take();
let mut script_ast = swc_core::ecma::ast::Script {
span: ast.span,
shebang: ast.shebang.clone(),
body: body.into_iter().map(|i| i.stmt().unwrap()).collect(),
};
script_ast.visit_mut_with(&mut inject_helpers(self.unresolved_mark));
ast.body = script_ast.body.into_iter().map(|i| i.into()).collect();
}
}

Ok(())
})
})
})
})
Ok(())
}

pub fn analyze_deps(&self, context: Arc<Context>) -> Vec<Dependency> {
Expand Down
Loading

0 comments on commit f7a36b0

Please sign in to comment.