为什么我的无效的科拉斯式操作员没有被汇总插件转移给Babel?

发布于 2025-02-11 04:52:45 字数 863 浏览 4 评论 0原文

我有一个Svelte项目,我想使用Rollup Plugin @lollup/plumin/plugin-babel将无效的无效操作员(ES2020)转换为ES5,它是默认情况下启用了@babel/preset-env-env,因为babel v7.6.3

但是,在我的项目中,它行不通。我在这样的组件中的脚本标签中有一个无效的coalascing操作员:

<script>
    let count = 0;
    let aCool;
    let canio;
    const increment = () => {
        if (count % 6 === 0) {
            canio = 1;
        }
        count += 1;
        aCool = canio ?? 0;
    };

    console.log('aCool', aCool);
</script>

可以找到一个最小的svelte项目在这里

Babel似乎正在运行并添加来自Core-Js的多填充物,但它与??运算符无关。为什么不移交?

I have a svelte project that I would like to transpile nullish-coalascing operators (es2020) to es5 using the rollup plugin @rollup/plugin-babel which is enabled by default in @babel/preset-env since babel v7.6.3.

However in my project it does not work. I have a nullish-coalascing operator in a script tag in a component like this:

<script>
    let count = 0;
    let aCool;
    let canio;
    const increment = () => {
        if (count % 6 === 0) {
            canio = 1;
        }
        count += 1;
        aCool = canio ?? 0;
    };

    console.log('aCool', aCool);
</script>

A minimal svelte project can be found here.

Babel seems to run and add the polyfills from core-js but it does nothing with the ?? operator. Why is it not transpiled?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2025-02-18 04:52:45

我发现它不起作用的原因是因为我忘了将.svelte作为文件扩展名,而Babel应该在 rollup插件因此,它甚至都不查看Svelte代码。谢谢@jlhwung!

I found out the reason why it does not work is because I forgot to set .svelte as a file extension that Babel should transpile in the rollup plugin hence it doesn't even look at the svelte code. Thanks @JLHwung!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文