Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/options/babel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{de::DeserializeOwned, Deserialize};
use crate::CompilerAssumptions;

pub use self::env::{BabelEnvOptions, BabelModule, BabelTargets};
use self::{plugins::BabelPlugins, presets::BabelPresets};
pub(crate) use self::{plugins::BabelPlugins, presets::BabelPresets};

/// Babel options
///
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_transformer/src/options/babel/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct BabelPlugins {
pub react_jsx_self: bool,
pub react_jsx_source: bool,
pub react_display_name: bool,
// modules
pub modules_commonjs: bool,
// regexp
pub sticky_flag: bool,
pub unicode_flag: bool,
Expand Down Expand Up @@ -100,6 +102,7 @@ impl TryFrom<PluginPresetEntries> for BabelPlugins {
"transform-react-display-name" => p.react_display_name = true,
"transform-react-jsx-self" => p.react_jsx_self = true,
"transform-react-jsx-source" => p.react_jsx_source = true,
"transform-modules-commonjs" => p.modules_commonjs = true,
"transform-sticky-regex" => p.sticky_flag = true,
"transform-unicode-regex" => p.unicode_flag = true,
"transform-dotall-regex" => p.dot_all_flag = true,
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_transformer/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ impl TryFrom<&BabelOptions> for TransformOptions {

let env = options.presets.env.unwrap_or_default();

let module = options.presets.env.as_ref().map(|env| env.module).unwrap_or_default();
let module = Module::try_from(&options.plugins).unwrap_or_else(|_| {
options.presets.env.as_ref().map(|env| env.module).unwrap_or_default()
});

let regexp = RegExpOptions {
sticky_flag: env.regexp.sticky_flag || options.plugins.sticky_flag,
Expand Down
12 changes: 12 additions & 0 deletions crates/oxc_transformer/src/options/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use oxc_diagnostics::Error;
use serde::Deserialize;

use super::babel::BabelPlugins;
use crate::options::babel::BabelModule;

/// Specify what module code is generated.
Expand Down Expand Up @@ -40,3 +41,14 @@ impl TryFrom<BabelModule> for Module {
}
}
}

impl TryFrom<&BabelPlugins> for Module {
type Error = Error;
fn try_from(value: &BabelPlugins) -> Result<Self, Self::Error> {
if value.modules_commonjs {
Ok(Self::CommonJS)
} else {
Err(Error::msg("Doesn't find any transform-modules-* plugin."))
}
}
}
48 changes: 44 additions & 4 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: d20b314c

Passed: 316/626
Passed: 316/633

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -460,7 +460,7 @@ x Output mismatch
x Output mismatch


# babel-plugin-transform-async-to-generator (11/24)
# babel-plugin-transform-async-to-generator (11/28)
* assumption-ignoreFunctionLength-true/basic/input.mjs
x Output mismatch

Expand Down Expand Up @@ -488,6 +488,18 @@ x Output mismatch
* bluebird-coroutines/statement/input.js
x Output mismatch

* export-async/default-arrow-export/input.mjs
x Output mismatch

* export-async/default-export/input.mjs
x Output mismatch

* export-async/import-and-export/input.mjs
x Output mismatch

* export-async/lone-export/input.mjs
x Output mismatch

* regression/15978/input.js
x Output mismatch

Expand Down Expand Up @@ -560,7 +572,7 @@ rebuilt : ScopeId(1): []
x Output mismatch


# babel-plugin-transform-typescript (40/153)
# babel-plugin-transform-typescript (40/155)
* cast/as-expression/input.ts
Unresolved references mismatch:
after transform: ["T", "x"]
Expand Down Expand Up @@ -942,6 +954,17 @@ rebuilt : ScopeId(0): []
`----


* exports/export=-to-cjs/input.ts

! `export = <value>;` is only supported when compiling modules to CommonJS.
| Please consider using `export default <value>;`, or add @babel/plugin-
| transform-modules-commonjs to your Babel config.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/exports/export=-to-cjs/input.ts:1:1]
1 | export = 0;
: ^^^^^^^^^^^
`----


* exports/imported-types/input.ts
Bindings mismatch:
after transform: ScopeId(0): ["A", "B", "C"]
Expand Down Expand Up @@ -1142,6 +1165,20 @@ rebuilt : ScopeId(0): []
`----


* imports/import=-module-to-cjs/input.ts

! `import lib = require(...);` is only supported when compiling modules
| to CommonJS.
| Please consider using `import lib from '...';` alongside Typescript's
| --allowSyntheticDefaultImports option, or add @babel/plugin-transform-
| modules-commonjs to your Babel config.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/imports/import=-module-to-cjs/input.ts:1:1]
1 | import lib = require("lib");
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | lib();
`----


* imports/only-remove-type-imports/input.ts
x Output mismatch

Expand Down Expand Up @@ -2167,7 +2204,10 @@ after transform: ["T", "f"]
rebuilt : ["f"]


# babel-plugin-transform-react-jsx (124/144)
# babel-plugin-transform-react-jsx (124/145)
* autoImport/after-polyfills-compiled-to-cjs/input.mjs
x Output mismatch

* pure/false-pragma-comment-automatic-runtime/input.js
pragma and pragmaFrag cannot be set when runtime is automatic.

Expand Down
7 changes: 5 additions & 2 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: d20b314c

Passed: 82/91
Passed: 82/92

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -168,10 +168,13 @@ rebuilt : SymbolId(2): []
x Output mismatch


# babel-plugin-transform-react-jsx (31/33)
# babel-plugin-transform-react-jsx (31/34)
* refresh/does-not-transform-it-because-it-is-not-used-in-the-AST/input.jsx
x Output mismatch

* refresh/react-refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/input.jsx
x Output mismatch

* refresh/react-refresh/supports-typescript-namespace-syntax/input.tsx
x Output mismatch

Expand Down