o
    5t¾i$  ã                   @   sn   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ deƒZd	ed
dfdd„Z	dd	eded
efdd„Z
dS )zA
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
é    N)ÚPattern)ÚFinalé   )ÚVarNameSanitizerc                   @   s¤   e Zd ZU g d¢Zeed< g d¢Zeed< g d¢Zeed< e 	d¡Z
eed< e 	d	¡Zeed
< edee fdd„ƒZedee fdd„ƒZedee fdd„ƒZdS )ÚJavaScriptVarNameSanitizer)!ÚbreakÚcaseÚcatchÚclassÚconstÚcontinueÚdebuggerÚdefaultÚdeleteÚdoÚelseÚexportÚextendsÚfinallyÚforÚfunctionÚifÚimportÚinÚ
instanceofÚnewÚreturnÚsuperÚswitchÚthisÚthrowÚtryÚtypeofÚvarÚvoidÚwhileÚwithÚyieldÚ5_JavaScriptVarNameSanitizer__JS_RESERVED_KEYWORDS_ES6)ÚenumÚ
implementsÚ	interfaceÚletÚpackageÚprivateÚ	protectedÚpublicÚstaticÚawaitÚabstractÚbooleanÚbyteÚcharÚdoubleÚfinalÚfloatÚgotoÚintÚlongÚnativeÚshortÚsynchronizedÚthrowsÚ	transientÚvolatileÚ8_JavaScriptVarNameSanitizer__JS_RESERVED_KEYWORDS_FUTURE)ÚnullÚtrueÚfalseÚ1_JavaScriptVarNameSanitizer__JS_BUILTIN_CONSTANTSz[^a-zA-Z0-9_$]Ú0_JavaScriptVarNameSanitizer__RE_INVALID_VAR_NAMEz^[^a-zA-Z$]+Ú5_JavaScriptVarNameSanitizer__RE_INVALID_VAR_NAME_HEADr   c                 C   s   | j | j | j S ©N)r(   rC   rG   ©Úself© rM   úW/home/ubuntu/.local/lib/python3.10/site-packages/pytablewriter/sanitizer/_javascript.pyÚreserved_keywordsQ   s   ÿþÿz,JavaScriptVarNameSanitizer.reserved_keywordsc                 C   ó   | j S rJ   )rI   rK   rM   rM   rN   Ú_invalid_var_name_head_reY   ó   z4JavaScriptVarNameSanitizer._invalid_var_name_head_rec                 C   rP   rJ   )rH   rK   rM   rM   rN   Ú_invalid_var_name_re]   rR   z/JavaScriptVarNameSanitizer._invalid_var_name_reN)Ú__name__Ú
__module__Ú__qualname__r(   r   Ú__annotations__rC   rG   ÚreÚcompilerH   rI   ÚpropertyÚlistÚstrrO   r   rQ   rS   rM   rM   rM   rN   r      s   
 #r   Úvar_namer   c                 C   s   t | ƒ ¡  dS )a  
    :param str var_name: Name to validate.
    :raises pathvalidate.ValidationError (ErrorReason.INVALID_CHARACTER):
        If the ``var_name`` is invalid as a JavaScript identifier.
    :raises pathvalidate.ValidationError (ErrorReason.RESERVED_NAME):
        If the ``var_name`` is equals to
        `JavaScript reserved keywords
        <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords>`__.

    .. note::

        Currently, not supported unicode variable names.
    N)r   Úvalidate)r]   rM   rM   rN   Úvalidate_js_var_nameb   s   r_   Ú Úreplacement_textc                 C   s   t | ƒ |¡S )a3  
    Make a valid JavaScript variable name from ``var_name``.

    To make a valid name:

    - Replace invalid characters for a JavaScript variable name within
      the ``var_name`` with the ``replacement_text``
    - Delete invalid chars for the beginning of the variable name
    - Append underscore (``"_"``) at the tail of the name if sanitized name
      is one of the JavaScript reserved names

    :JavaScriptstr filename: Name to sanitize.
    :param str replacement_text: Replacement text.
    :return: A replacement string.
    :rtype: str
    :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.

    :Example:
        :ref:`example-sanitize-var-name`

    .. note::
        Currently, not supported Unicode variable names.

    .. seealso::
        :py:func:`.validate_js_var_name`
    )r   Úsanitize)r]   ra   rM   rM   rN   Úsanitize_js_var_namet   s   rc   )r`   )Ú__doc__rX   r   Útypingr   Ú_baser   r   r\   r_   rc   rM   rM   rM   rN   Ú<module>   s    V