diff --git a/crates/oxc_transformer/src/typescript/diagnostics.rs b/crates/oxc_transformer/src/typescript/diagnostics.rs index 7289cf3b3..53096792e 100644 --- a/crates/oxc_transformer/src/typescript/diagnostics.rs +++ b/crates/oxc_transformer/src/typescript/diagnostics.rs @@ -15,3 +15,8 @@ pub fn ambient_module_nested(span0: Span) -> OxcDiagnostic { OxcDiagnostic::warn("Ambient modules cannot be nested in other modules or namespaces.") .with_label(span0) } + +pub fn namespace_exporting_non_const(span0: Span) -> OxcDiagnostic { + OxcDiagnostic::warn("Namespaces exporting non-const are not supported by Babel. Change to const or see: https://babeljs.io/docs/en/babel-plugin-transform-typescript") + .with_label(span0) +} diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index 6718e53f3..4e1d5a97d 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -1,6 +1,9 @@ use rustc_hash::FxHashSet; -use super::{diagnostics::ambient_module_nested, TypeScript}; +use super::{ + diagnostics::{ambient_module_nested, namespace_exporting_non_const}, + TypeScript, +}; use oxc_allocator::{Box, Vec}; use oxc_ast::{ast::*, syntax_directed_operations::BoundNames}; @@ -238,6 +241,11 @@ impl<'a> TypeScript<'a> { ); } Declaration::VariableDeclaration(var_decl) => { + var_decl.declarations.iter().for_each(|decl| { + if !decl.kind.is_const() { + self.ctx.error(namespace_exporting_non_const(decl.span)); + } + }); is_empty = false; let stmts = self.handle_variable_declaration(var_decl, &name); new_stmts.extend(stmts); diff --git a/tasks/transform_conformance/babel.snap.md b/tasks/transform_conformance/babel.snap.md index 34754d209..f95dd43eb 100644 --- a/tasks/transform_conformance/babel.snap.md +++ b/tasks/transform_conformance/babel.snap.md @@ -1,6 +1,6 @@ commit: 4bd1b2c2 -Passed: 473/930 +Passed: 474/930 # All Passed: * babel-preset-react @@ -445,13 +445,12 @@ Passed: 473/930 * opts/optimizeConstEnums/input.ts * opts/rewriteImportExtensions/input.ts -# babel-plugin-transform-typescript (130/154) +# babel-plugin-transform-typescript (131/154) * enum/mix-references/input.ts * enum/ts5.0-const-foldable/input.ts * exports/declared-types/input.ts * imports/type-only-export-specifier-2/input.ts * namespace/empty-removed/input.ts -* namespace/mutable-fail/input.ts * namespace/namespace-flag/input.ts * namespace/nested/input.ts * namespace/nested-destructuring/input.ts