heavily simplify constants transformer
This commit is contained in:
parent
33128b0ccf
commit
2dd8c40618
@ -1,41 +1,18 @@
|
|||||||
import * as messages from "../../../messages";
|
import * as messages from "../../../messages";
|
||||||
|
|
||||||
function checkPath(path, file) {
|
export function Scope(node, parent, scope) {
|
||||||
var ids = path.getBindingIdentifiers();
|
for (var name in scope.bindings) {
|
||||||
|
var binding = scope.bindings[name];
|
||||||
for (var name in ids) {
|
|
||||||
var id = ids[name];
|
|
||||||
|
|
||||||
var binding = path.scope.getBinding(name);
|
|
||||||
|
|
||||||
// no binding exists
|
|
||||||
if (!binding) continue;
|
|
||||||
|
|
||||||
// not a constant
|
// not a constant
|
||||||
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
||||||
|
|
||||||
// check if the assignment id matches the constant declaration id
|
for (var violation of (binding.constantViolations: Array)) {
|
||||||
// if it does then it was the id used to initially declare the
|
throw violation.errorWithNode(messages.get("readOnly", name));
|
||||||
// constant so we can just ignore it
|
}
|
||||||
if (binding.identifier === id) continue;
|
|
||||||
|
|
||||||
throw file.errorWithNode(id, messages.get("readOnly", name));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AssignmentExpression(node, parent, scope, file) {
|
|
||||||
checkPath(this, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { AssignmentExpression as UpdateExpression };
|
|
||||||
|
|
||||||
export function VariableDeclaration(node) {
|
export function VariableDeclaration(node) {
|
||||||
if (node.kind === "const") node.kind = "let";
|
if (node.kind === "const") node.kind = "let";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ForXStatement(node, parent, scope, file) {
|
|
||||||
var left = this.get("left");
|
|
||||||
if (left.isIdentifier() || left.isPattern()) {
|
|
||||||
checkPath(left, file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user