生成es6模块导出

编程入门 行业动态 更新时间:2024-10-27 16:36:11
本文介绍了生成es6模块导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想以编程方式生成模块的导出,是否可能在es6中?

I'm wanting to programmatically generate the exports for a module, is this possible in es6?

以下这些行:

const ids = ['foo', 'bar', 'baz']; ids.forEach(id => { export const [id.toUpperCase()] = id; });

推荐答案

不,不是。出口和进口需要在ES6模块中静态分析。

No, it's not. Exports and imports are required to be statically analysable in ES6 modules.

不仅没有顶级导出声明语法错误,而且您尝试使用动态名称声明变量。括号符号仅用于计算的属性。

Not only is that no-top-level export declaration a syntax error, but also your attempt at declaring variables with dynamic names. The bracket notation is reserved for computed properties only.

因此,如果要以编程方式生成模块导出,则需要动态生成模块源文本(作为构建过程的一部分)。

So if you are going to programmatically generate module exports, you'll need to dynamically generate the module source text (as a part of your build process).

更多推荐

生成es6模块导出

本文发布于:2023-07-24 13:27:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1203714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!