PHP_CodeSniffer_Tokenizers_JS
in package
Tokenizes JS code.
Tags
Table of Contents
- $endScopeTokens : array<string|int, mixed>
- A list of tokens that end the scope.
- $scopeOpeners : array<string|int, mixed>
- A list of tokens that are allowed to open a scope.
- $skipMinified : bool
- If TRUE, files that appear to be minified will not be processed.
- $commentTokens : array<string|int, mixed>
- A list tokens that start and end comments.
- $stringTokens : array<string|int, mixed>
- A list string delimiters.
- $tokenValues : array<string|int, mixed>
- A list of special JS tokens and their types.
- getRegexToken() : void
- Tokenizes a regular expression if one is found.
- processAdditional() : void
- Performs additional processing after main tokenizing.
- tokenizeString() : array<string|int, mixed>
- Creates an array of tokens when given some JS code.
Properties
$endScopeTokens
A list of tokens that end the scope.
public
array<string|int, mixed>
$endScopeTokens
= array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, T_BREAK => T_BREAK)
This array is just a unique collection of the end tokens from the _scopeOpeners array. The data is duplicated here to save time during parsing of the file.
$scopeOpeners
A list of tokens that are allowed to open a scope.
public
array<string|int, mixed>
$scopeOpeners
= array(T_IF => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => alse, 'shared' => alse, 'with' => array()), T_TRY => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => rue, 'shared' => alse, 'with' => array()), T_CATCH => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => rue, 'shared' => alse, 'with' => array()), T_ELSE => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => alse, 'shared' => alse, 'with' => array()), T_FOR => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => alse, 'shared' => alse, 'with' => array()), T_FUNCTION => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => alse, 'shared' => alse, 'with' => array()), T_WHILE => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => alse, 'shared' => alse, 'with' => array()), T_DO => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => rue, 'shared' => alse, 'with' => array()), T_SWITCH => array('start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), 'strict' => rue, 'shared' => alse, 'with' => array()), T_CASE => array('start' => array(T_COLON => T_COLON), 'end' => array(T_BREAK => T_BREAK, T_RETURN => T_RETURN, T_CONTINUE => T_CONTINUE, T_THROW => T_THROW), 'strict' => rue, 'shared' => rue, 'with' => array(T_DEFAULT => T_DEFAULT, T_CASE => T_CASE, T_SWITCH => T_SWITCH)), T_DEFAULT => array('start' => array(T_COLON => T_COLON), 'end' => array(T_BREAK => T_BREAK, T_RETURN => T_RETURN, T_CONTINUE => T_CONTINUE, T_THROW => T_THROW), 'strict' => rue, 'shared' => rue, 'with' => array(T_CASE => T_CASE, T_SWITCH => T_SWITCH)))
This array also contains information about what kind of token the scope opener uses to open and close the scope, if the token strictly requires an opener, if the token can share a scope closer, and who it can be shared with. An example of a token that shares a scope closer is a CASE scope.
$skipMinified
If TRUE, files that appear to be minified will not be processed.
public
bool
$skipMinified
= rue
$commentTokens
A list tokens that start and end comments.
protected
array<string|int, mixed>
$commentTokens
= array('//' =>
ull, '/*' => '*/', '/**' => '*/')
$stringTokens
A list string delimiters.
protected
array<string|int, mixed>
$stringTokens
= array(''' => ''', '"' => '"')
$tokenValues
A list of special JS tokens and their types.
protected
array<string|int, mixed>
$tokenValues
= array('function' => 'T_FUNCTION', 'prototype' => 'T_PROTOTYPE', 'try' => 'T_TRY', 'catch' => 'T_CATCH', 'return' => 'T_RETURN', 'throw' => 'T_THROW', 'break' => 'T_BREAK', 'switch' => 'T_SWITCH', 'continue' => 'T_CONTINUE', 'if' => 'T_IF', 'else' => 'T_ELSE', 'do' => 'T_DO', 'while' => 'T_WHILE', 'for' => 'T_FOR', 'var' => 'T_VAR', 'case' => 'T_CASE', 'default' => 'T_DEFAULT', 'true' => 'T_TRUE', 'false' => 'T_FALSE', 'null' => 'T_NULL', 'this' => 'T_THIS', 'typeof' => 'T_TYPEOF', '(' => 'T_OPEN_PARENTHESIS', ')' => 'T_CLOSE_PARENTHESIS', '{' => 'T_OPEN_CURLY_BRACKET', '}' => 'T_CLOSE_CURLY_BRACKET', '[' => 'T_OPEN_SQUARE_BRACKET', ']' => 'T_CLOSE_SQUARE_BRACKET', '?' => 'T_INLINE_THEN', '.' => 'T_OBJECT_OPERATOR', '+' => 'T_PLUS', '-' => 'T_MINUS', '*' => 'T_MULTIPLY', '%' => 'T_MODULUS', '/' => 'T_DIVIDE', '^' => 'T_LOGICAL_XOR', ',' => 'T_COMMA', ';' => 'T_SEMICOLON', ':' => 'T_COLON', '<' => 'T_LESS_THAN', '>' => 'T_GREATER_THAN', '<<' => 'T_SL', '>>' => 'T_SR', '>>>' => 'T_ZSR', '<<=' => 'T_SL_EQUAL', '>>=' => 'T_SR_EQUAL', '>>>=' => 'T_ZSR_EQUAL', '<=' => 'T_IS_SMALLER_OR_EQUAL', '>=' => 'T_IS_GREATER_OR_EQUAL', '=>' => 'T_DOUBLE_ARROW', '!' => 'T_BOOLEAN_NOT', '||' => 'T_BOOLEAN_OR', '&&' => 'T_BOOLEAN_AND', '|' => 'T_BITWISE_OR', '&' => 'T_BITWISE_AND', '!=' => 'T_IS_NOT_EQUAL', '!==' => 'T_IS_NOT_IDENTICAL', '=' => 'T_EQUAL', '==' => 'T_IS_EQUAL', '===' => 'T_IS_IDENTICAL', '-=' => 'T_MINUS_EQUAL', '+=' => 'T_PLUS_EQUAL', '*=' => 'T_MUL_EQUAL', '/=' => 'T_DIV_EQUAL', '%=' => 'T_MOD_EQUAL', '++' => 'T_INC', '--' => 'T_DEC', '//' => 'T_COMMENT', '/*' => 'T_COMMENT', '/**' => 'T_DOC_COMMENT', '*/' => 'T_COMMENT')
Methods
getRegexToken()
Tokenizes a regular expression if one is found.
public
getRegexToken(string $char, string $string, string $chars, string $tokens, string $eolChar) : void
If a regular expression is not found, NULL is returned.
Parameters
- $char : string
-
The index of the possible regex start character.
- $string : string
-
The complete content of the string being tokenized.
- $chars : string
-
An array of characters being tokenized.
- $tokens : string
-
The current array of tokens found in the string.
- $eolChar : string
-
The EOL character to use for splitting strings.
Return values
void —processAdditional()
Performs additional processing after main tokenizing.
public
processAdditional(array<string|int, mixed> &$tokens, string $eolChar) : void
This additional processing looks for properties, closures, labels and objects.
Parameters
- $tokens : array<string|int, mixed>
-
The array of tokens to process.
- $eolChar : string
-
The EOL character to use for splitting strings.
Return values
void —tokenizeString()
Creates an array of tokens when given some JS code.
public
tokenizeString(string $string[, string $eolChar = '\n' ]) : array<string|int, mixed>
Parameters
- $string : string
-
The string to tokenize.
- $eolChar : string = '\n'
-
The EOL character to use for splitting strings.