A follow up from https://github.com/babel/babel/pull/2969 were we added support for consts in the block-scoping plugin.
17 lines
457 B
JavaScript
17 lines
457 B
JavaScript
export default function ({ messages }) {
|
|
return {
|
|
visitor: {
|
|
Scope({ scope }) {
|
|
for (let name in scope.bindings) {
|
|
let binding = scope.bindings[name];
|
|
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
|
|
|
for (let violation of (binding.constantViolations: Array)) {
|
|
throw violation.buildCodeFrameError(messages.get("readOnly", name));
|
|
}
|
|
}
|
|
},
|
|
}
|
|
};
|
|
}
|