Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass targets for swc/helpers to Rust and only filter them for preset env #8020

Merged
merged 4 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {bar} from "./other.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const bar = "bar";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as helpers from "@swc/helpers";
import * as bar from "./bar";
import * as foo from "foo";

export default [helpers, bar, foo];

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"browserslist": "ie 11"
}
8 changes: 8 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5110,6 +5110,14 @@ describe('javascript', function () {
assert.deepEqual(res, {a: 4});
});

it('should not use arrow functions for reexport declarations unless supported', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-export-arrow-support/index.js'),
);
let content = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(!content.includes('=>'));
});

it('should support import namespace declarations of other ES modules', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-import-namespace/a.js'),
Expand Down
16 changes: 11 additions & 5 deletions packages/transformers/js/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Config {
is_library: bool,
is_esm_output: bool,
trace_bailouts: bool,
is_swc_helpers: bool,
}

#[derive(Serialize, Debug, Default)]
Expand Down Expand Up @@ -318,11 +319,16 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
..Default::default()
};
let versions = targets_to_versions(&config.targets);
if let Some(versions) = versions {
preset_env_config.targets = Some(Targets::Versions(versions));
preset_env_config.shipped_proposals = true;
preset_env_config.mode = Some(Entry);
preset_env_config.bugfixes = true;
if !config.is_swc_helpers {
// Avoid transpiling @swc/helpers so that we don't cause infinite recursion.
// Filter the versions for preset_env only so that syntax support checks
// (e.g. in esm2cjs) still work correctly.
if let Some(versions) = versions {
preset_env_config.targets = Some(Targets::Versions(versions));
preset_env_config.shipped_proposals = true;
preset_env_config.mode = Some(Entry);
preset_env_config.bugfixes = true;
}
}

let mut diagnostics = vec![];
Expand Down
6 changes: 1 addition & 5 deletions packages/transformers/js/src/JSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ export default (new Transformer({
targets = {node: semver.minVersion(asset.env.engines.node)?.toString()};
}

// Avoid transpiling @swc/helpers so that we don't cause infinite recursion.
if (/@swc[/\\]helpers/.test(asset.filePath)) {
targets = null;
}

let env: EnvMap = {};

if (!config?.inlineEnvironment) {
Expand Down Expand Up @@ -420,6 +415,7 @@ export default (new Transformer({
is_library: asset.env.isLibrary,
is_esm_output: asset.env.outputFormat === 'esmodule',
trace_bailouts: options.logLevel === 'verbose',
is_swc_helpers: /@swc[/\\]helpers/.test(asset.filePath),
});

let convertLoc = loc => {
Expand Down