HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/design.system/node_modules/react-docgen/dist/resolver/FindAnnotatedDefinitionsResolver.js
import normalizeClassDefinition from '../utils/normalizeClassDefinition.js';
import { visitors } from '@babel/traverse';
function isAnnotated(path, annotation) {
    let inspectPath = path;
    do {
        const leadingComments = inspectPath.node.leadingComments;
        // If an export doesn't have leading comments, we can simply continue
        if (leadingComments && leadingComments.length > 0) {
            // Search for the annotation in any comment.
            const hasAnnotation = leadingComments.some(({ value }) => value.includes(annotation));
            // if we found an annotation return true
            if (hasAnnotation) {
                return true;
            }
        }
        // return false if the container of the current path is an array
        // as we do not want to traverse up through this kind of nodes, like ArrayExpressions for example
        // The only exception is variable declarations
        if (Array.isArray(inspectPath.container) &&
            !inspectPath.isVariableDeclarator() &&
            !inspectPath.parentPath?.isCallExpression()) {
            return false;
        }
    } while ((inspectPath = inspectPath.parentPath));
    return false;
}
function classVisitor(path, state) {
    if (isAnnotated(path, state.annotation)) {
        normalizeClassDefinition(path);
        state.foundDefinitions.add(path);
    }
}
function statelessVisitor(path, state) {
    if (isAnnotated(path, state.annotation)) {
        state.foundDefinitions.add(path);
    }
}
const explodedVisitors = visitors.explode({
    ArrowFunctionExpression: { enter: statelessVisitor },
    FunctionDeclaration: { enter: statelessVisitor },
    FunctionExpression: { enter: statelessVisitor },
    ObjectMethod: { enter: statelessVisitor },
    ClassDeclaration: { enter: classVisitor },
    ClassExpression: { enter: classVisitor },
});
/**
 * Given an AST, this function tries to find all react components which
 * are annotated with an annotation
 */
export default class FindAnnotatedDefinitionsResolver {
    constructor({ annotation = '@component', } = {}) {
        this.annotation = annotation;
    }
    resolve(file) {
        const state = {
            foundDefinitions: new Set(),
            annotation: this.annotation,
        };
        file.traverse(explodedVisitors, state);
        return Array.from(state.foundDefinitions);
    }
}