| | |
| | | toIdentifier, |
| | | unaryExpression, |
| | | variableDeclaration, |
| | | variableDeclarator |
| | | variableDeclarator, |
| | | isRecordExpression, |
| | | isTupleExpression, |
| | | isObjectProperty, |
| | | isTopicReference, |
| | | isMetaProperty, |
| | | isPrivateName |
| | | } = _t; |
| | | |
| | | function gatherNodeParts(node, parts) { |
| | |
| | | }, |
| | | |
| | | Function(path) { |
| | | if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) { |
| | | path.scope.registerBinding("local", path.get("id"), path); |
| | | } |
| | | |
| | | const params = path.get("params"); |
| | | |
| | | for (const param of params) { |
| | | path.scope.registerBinding("param", param); |
| | | } |
| | | |
| | | if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) { |
| | | path.scope.registerBinding("local", path.get("id"), path); |
| | | } |
| | | }, |
| | | |
| | |
| | | } |
| | | |
| | | isStatic(node) { |
| | | if (isThisExpression(node) || isSuper(node)) { |
| | | if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) { |
| | | return true; |
| | | } |
| | | |
| | |
| | | checkBlockScopedCollisions(local, kind, name, id) { |
| | | if (kind === "param") return; |
| | | if (local.kind === "local") return; |
| | | const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const"); |
| | | const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const"; |
| | | |
| | | if (duplicate) { |
| | | throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError); |
| | |
| | | this.registerBinding(path.node.kind, declar); |
| | | } |
| | | } else if (path.isClassDeclaration()) { |
| | | if (path.node.declare) return; |
| | | this.registerBinding("let", path); |
| | | } else if (path.isImportDeclaration()) { |
| | | const specifiers = path.get("specifiers"); |
| | |
| | | if (!binding) return false; |
| | | if (constantsOnly) return binding.constant; |
| | | return true; |
| | | } else if (isThisExpression(node) || isMetaProperty(node) || isTopicReference(node) || isPrivateName(node)) { |
| | | return true; |
| | | } else if (isClass(node)) { |
| | | var _node$decorators; |
| | | |
| | | if (node.superClass && !this.isPure(node.superClass, constantsOnly)) { |
| | | return false; |
| | | } |
| | | |
| | | if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | return true; |
| | | } else if (isBinary(node)) { |
| | | return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); |
| | | } else if (isArrayExpression(node)) { |
| | | } else if (isArrayExpression(node) || isTupleExpression(node)) { |
| | | for (const elem of node.elements) { |
| | | if (!this.isPure(elem, constantsOnly)) return false; |
| | | if (elem !== null && !this.isPure(elem, constantsOnly)) return false; |
| | | } |
| | | |
| | | return true; |
| | | } else if (isObjectExpression(node)) { |
| | | } else if (isObjectExpression(node) || isRecordExpression(node)) { |
| | | for (const prop of node.properties) { |
| | | if (!this.isPure(prop, constantsOnly)) return false; |
| | | } |
| | | |
| | | return true; |
| | | } else if (isMethod(node)) { |
| | | var _node$decorators2; |
| | | |
| | | if (node.computed && !this.isPure(node.key, constantsOnly)) return false; |
| | | if (node.kind === "get" || node.kind === "set") return false; |
| | | |
| | | if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } else if (isProperty(node)) { |
| | | var _node$decorators3; |
| | | |
| | | if (node.computed && !this.isPure(node.key, constantsOnly)) return false; |
| | | return this.isPure(node.value, constantsOnly); |
| | | |
| | | if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) { |
| | | return false; |
| | | } |
| | | |
| | | if (isObjectProperty(node) || node.static) { |
| | | if (node.value !== null && !this.isPure(node.value, constantsOnly)) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } else if (isUnaryExpression(node)) { |
| | | return this.isPure(node.argument, constantsOnly); |
| | | } else if (isTaggedTemplateExpression(node)) { |
| | |
| | | } |
| | | |
| | | const declarator = variableDeclarator(opts.id, opts.init); |
| | | declarPath.node.declarations.push(declarator); |
| | | this.registerBinding(kind, declarPath.get("declarations").pop()); |
| | | const len = declarPath.node.declarations.push(declarator); |
| | | path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]); |
| | | } |
| | | |
| | | getProgramParent() { |
| | |
| | | if (binding) { |
| | | var _previousPath; |
| | | |
| | | if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param") {} else { |
| | | if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else { |
| | | return binding; |
| | | } |
| | | } else if (!binding && name === "arguments" && scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) { |
| | | break; |
| | | } |
| | | |
| | | previousPath = scope.path; |