/
githubmirror
/
deno
Обзор
Документация
Войти
/
githubmirror
/
deno
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cli/tools/bundle/transform.rs
40 строк
1 KB
Kenta Moriuchi
chore: Happy New Year 2026 (#31748)
08 янв 2026, 18:28
Не верифицирован
08 янв 2026, 18:28
8193cf9
Код
Авторство
О чём код?
// Copyright 2018-2026 the Deno authors. MIT license. use deno_ast::swc; use deno_ast::swc::ast::Bool; use deno_ast::swc::ecma_visit::VisitMut; use deno_ast::swc::ecma_visit::VisitMutWith; pub struct BundleImportMetaMainTransform { is_entrypoint: bool, } impl BundleImportMetaMainTransform { pub fn new(is_entrypoint: bool) -> Self { Self { is_entrypoint } } } impl VisitMut for BundleImportMetaMainTransform { fn visit_mut_expr(&mut self, node: &mut swc::ast::Expr) { // if entrypoint to bundle: // import.meta.main => import.meta.main // else: // import.meta.main => false if let swc::ast::Expr::Member(member) = node && let swc::ast::Expr::MetaProp(meta_prop) = &mut *member.obj && meta_prop.kind == swc::ast::MetaPropKind::ImportMeta && member.prop.is_ident_with("main") { if self.is_entrypoint { return; } else { let span = member.span; *node = swc::ast::Expr::Lit(swc::ast::Lit::Bool(Bool { span, value: false })); return; } } node.visit_mut_children_with(self); } }