eslint/no-import-assign 正确性
规则作用
禁止为导入的绑定分配值
为什么这样做不妥
ES 模块导入绑定更新会引发运行时错误。
示例
javascript
import mod, { named } from "./mod.mjs";
import * as mod_ns from "./mod.mjs";
mod = 1; // ERROR: 'mod' is readonly.
named = 2; // ERROR: 'named' is readonly.
mod_ns.named = 3; // ERROR: The members of 'mod_ns' are readonly.
mod_ns = {}; // ERROR: 'mod_ns' is readonly.
// Can't extend 'mod_ns'
Object.assign(mod_ns, { foo: "foo" }); // ERROR: The members of 'mod_ns' are readonly.