在eslint的偏好-破坏规则的指导下,我定义了如下几个常量:
const {
NODE_ENV,
API_URL,
} = process.env;是否可以通过export语句的前缀导出这些常量?
export const {
NODE_ENV,
API_URL,
} = process.env;这看起来很自然,但eslint plugin-import抱怨违反了进口/命名规则:API_URL not found in '../constants'。事实上,export的这种用法在相关的MDN页面上也没有描述。
那么,我们必须在一个单独的export语句中重复所有常量吗?
const {
NODE_ENV,
API_URL,
} = process.env;
export {
NODE_ENV,
API_URL,
};发布于 2019-01-01 14:00:00
是否可以通过
export语句的前缀导出这些常量? 出口NODE_ENV,API_URL,}= process.env;
是的,根据规格,这是完全有效的。您可以在导出的const的声明中使用析构模式。
这看起来很自然,但eslint plugin-import抱怨违反了进口/命名规则:
API_URL not found in '../constants'。
听起来那个插件坏了。事实上,您以前确实是用例据报为工作。
发布于 2019-01-01 13:55:22
“规范”第15.2.2.3条规定:
..。ExportDeclaration :出口VariableStatement ExportDeclaration :出口申报单
第13.1.4条规定:
声明: LexicalDeclaration
第13.3条规定:
LexicalDeclaration: LetOrConst BindingList;LetOrConst : let const BindingList : LexicalBinding BindingList,LexicalBinding LexicalBinding: BindingPattern初始化器
因此,这一点:
// ExportDeclaration
export // export
// Declaration
// LexicalDeclaration:
const // LetOrConst
// LexicalBindingList
// LexicalBinding
{ NODE_ENV, API_URL } // BindingPattern
= process.env; // Initializer是完全有效的JavaScript。
https://stackoverflow.com/questions/53995529
复制相似问题