* Checks the left hand side of an assignment for issues, returns if ok * @param {token} left - the left hand side of the assignment * @param {token=} assignToken - the token for the assignment, used for reporting * @param {object=} options - optional object * @param {boolean} options.all
(left, assignToken, options)
| 20277 | * @returns {boolean} Whether the left hand side is OK |
| 20278 | */ |
| 20279 | function checkLeftSideAssign(left, assignToken, options) { |
| 20280 | |
| 20281 | var allowDestructuring = options && options.allowDestructuring; |
| 20282 | |
| 20283 | assignToken = assignToken || left; |
| 20284 | |
| 20285 | if (state.option.freeze) { |
| 20286 | var nativeObject = findNativePrototype(left); |
| 20287 | if (nativeObject) |
| 20288 | warning("W121", left, nativeObject); |
| 20289 | } |
| 20290 | if (checkPunctuator(left, "...")) { |
| 20291 | left = left.right; |
| 20292 | } |
| 20293 | |
| 20294 | if (left.identifier && !left.isMetaProperty) { |
| 20295 | // reassign also calls modify |
| 20296 | // but we are specific in order to catch function re-assignment |
| 20297 | // and globals re-assignment |
| 20298 | state.funct["(scope)"].block.reassign(left.value, left); |
| 20299 | } |
| 20300 | |
| 20301 | if (left.id === ".") { |
| 20302 | if (!left.left || left.left.value === "arguments" && !state.isStrict()) { |
| 20303 | warning("E031", assignToken); |
| 20304 | } |
| 20305 | |
| 20306 | state.nameStack.set(state.tokens.prev); |
| 20307 | return true; |
| 20308 | } else if (left.id === "{" || left.id === "[") { |
| 20309 | if (!allowDestructuring || !left.destructAssign) { |
| 20310 | if (left.id === "{" || !left.left) { |
| 20311 | warning("E031", assignToken); |
| 20312 | } else if (left.left.value === "arguments" && !state.isStrict()) { |
| 20313 | warning("E031", assignToken); |
| 20314 | } |
| 20315 | } |
| 20316 | |
| 20317 | if (left.id === "[") { |
| 20318 | state.nameStack.set(left.right); |
| 20319 | } |
| 20320 | |
| 20321 | return true; |
| 20322 | } else if (left.identifier && !isReserved(left) && !left.isMetaProperty) { |
| 20323 | if (state.funct["(scope)"].labeltype(left.value) === "exception") { |
| 20324 | warning("W022", left); |
| 20325 | } |
| 20326 | state.nameStack.set(left); |
| 20327 | return true; |
| 20328 | } |
| 20329 | |
| 20330 | if (left === state.syntax["function"]) { |
| 20331 | warning("W023", state.tokens.curr); |
| 20332 | } else { |
| 20333 | error("E031", assignToken); |
| 20334 | } |
| 20335 | |
| 20336 | return false; |
no test coverage detected