from typing import List
from typing import Pattern
import re
from typing import Optional
from typing import Match


def _target_js_variable_is_used(
        *, var_name: str, exp_lines: List[str]) -> bool:
    """
    Get a boolean value whether target variable is used in
    js expression or not.

    Parameters
    ----------
    var_name : str
        Target variable name.
    exp_lines : list of str
        js expression lines.

    Returns
    -------
    result : bool
        If target variable is used in js expression, True will be
        returned.
    """
    var_pattern: Pattern = re.compile(pattern=rf'var ({var_name}) = ')
    used_pattern_1: Pattern = re.compile(
        pattern=rf'{var_name}[ ;\)\.}},\]\[]')
    used_pattern_2: Pattern = re.compile(
        pattern=rf'{var_name}$')
    for line in exp_lines:
        if '//' in line:
            continue
        if var_name not in line:
            continue
        match: Optional[Match] = var_pattern.search(string=line)
        if match is not None:
            continue
        match = used_pattern_1.search(string=line)
        if match is not None:
            return True
        match = used_pattern_2.search(string=line)
        if match is not None:
            return True
    return False