Repository: eslint/eslint
File: lib/rules/utils/ast-utils.js (JavaScript)

Code before:

        return true;
    };
}

/**
 * Checks if a node is used as an import attribute key, either in a static or dynamic import.
 * @param {ASTNode} node The node to check.
 * @returns {boolean} Whether the node is used as an import attribute key.
 */
function isImportAttributeKey(node) {
    const { parent } = node;

    // static import/re-export
    if (parent.type === "ImportAttribute" && parent.key === node) {
        return true;
    }

    // dynamic import
    if (
        parent.type === "Property" &&
        !parent.computed &&
        (parent.key === node || parent.value === node && parent.shorthand && !parent.method) &&
        parent.parent.type === "ObjectExpression"
    ) {
        const objectExpression = parent.parent;

        if (
            objectExpression.parent.type === "ImportExpression" &&
            objectExpression.parent.options === objectExpression
        ) {
            return true;
        }

        // nested key
        if (
            objectExpression.parent.type === "Property" &&
            objectExpression.parent.value === objectExpression
        ) {
            return isImportAttributeKey(objectExpression.parent.key);
        }
    }

    return false;
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = {

Review comment (refactor):
It looks like you're only using this to get `objectExpression.parent` below. Maybe we could simplify by setting this to:

```suggestion
        const objectExpressionParent = parent.parent.parent;
```

And then just using `objectExpressionParent` below?

Code after:

        return true;
    };
}

/**
 * Checks if a node is used as an import attribute key, either in a static or dynamic import.
 * @param {ASTNode} node The node to check.
 * @returns {boolean} Whether the node is used as an import attribute key.
 */
function isImportAttributeKey(node) {
    const { parent } = node;

    // static import/re-export
    if (parent.type === "ImportAttribute" && parent.key === node) {
        return true;
    }

    // dynamic import
    if (
        parent.type === "Property" &&
        !parent.computed &&
        (parent.key === node || parent.value === node && parent.shorthand && !parent.method) &&
        parent.parent.type === "ObjectExpression"
    ) {
        const objectExpression = parent.parent;
        const objectExpressionParent = objectExpression.parent;

        if (
            objectExpressionParent.type === "ImportExpression" &&
            objectExpressionParent.options === objectExpression
        ) {
            return true;
        }

        // nested key
        if (
            objectExpressionParent.type === "Property" &&
            objectExpressionParent.value === objectExpression
        ) {
            return isImportAttributeKey(objectExpressionParent.key);
        }
    }

    return false;
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------