* Checks whether this javascript parser is pure. * @param {Expression | Declaration | PrivateIdentifier | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | null | undefined} expr an expression * @param {number} commentsStartPos source position from which annotation comments are checke
(expr, commentsStartPos)
| 5088 | * @returns {boolean} true, when the expression is pure |
| 5089 | */ |
| 5090 | isPure(expr, commentsStartPos) { |
| 5091 | if (!expr) return true; |
| 5092 | const result = this.hooks.isPure |
| 5093 | .for(expr.type) |
| 5094 | .call(expr, commentsStartPos); |
| 5095 | if (typeof result === "boolean") return result; |
| 5096 | switch (expr.type) { |
| 5097 | case "ClassDeclaration": |
| 5098 | case "ClassExpression": { |
| 5099 | if (expr.body.type !== "ClassBody") return false; |
| 5100 | if ( |
| 5101 | expr.superClass && |
| 5102 | !this.isPure(expr.superClass, /** @type {Range} */ (expr.range)[0]) |
| 5103 | ) { |
| 5104 | return false; |
| 5105 | } |
| 5106 | const items = expr.body.body; |
| 5107 | return items.every((item) => { |
| 5108 | if (item.type === "StaticBlock") { |
| 5109 | return false; |
| 5110 | } |
| 5111 | |
| 5112 | if ( |
| 5113 | item.computed && |
| 5114 | item.key && |
| 5115 | !this.isPure( |
| 5116 | item.key, |
| 5117 | /** @type {Range} */ |
| 5118 | (item.range)[0] |
| 5119 | ) |
| 5120 | ) { |
| 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | if ( |
| 5125 | item.static && |
| 5126 | item.value && |
| 5127 | !this.isPure( |
| 5128 | item.value, |
| 5129 | item.key |
| 5130 | ? /** @type {Range} */ (item.key.range)[1] |
| 5131 | : /** @type {Range} */ (item.range)[0] |
| 5132 | ) |
| 5133 | ) { |
| 5134 | return false; |
| 5135 | } |
| 5136 | |
| 5137 | if ( |
| 5138 | expr.superClass && |
| 5139 | item.type === "MethodDefinition" && |
| 5140 | item.kind === "constructor" |
| 5141 | ) { |
| 5142 | return false; |
| 5143 | } |
| 5144 | |
| 5145 | return true; |
| 5146 | }); |
| 5147 | } |
no test coverage detected