UNPKG

@aurahelper/languages

Version:

Language Libraries to work with XML, Aura, Apex... files. tokenizers, parsers, system classes and much more

617 lines 30.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JSTokenizer = void 0; var core_1 = require("@aurahelper/core"); var StrUtils = core_1.CoreUtils.StrUtils; var Utils = core_1.CoreUtils.Utils; var Validator = core_1.CoreUtils.Validator; var symbolTokens = { ">>>=": core_1.JSTokenTypes.OPERATOR.BITWISE.UNSIGNED_RIGHT_ASSIGN, ">>=": core_1.JSTokenTypes.OPERATOR.BITWISE.SIGNED_RIGTH_ASSIGN, "<<=": core_1.JSTokenTypes.OPERATOR.BITWISE.LEFT_ASSIGN, ">>>": core_1.JSTokenTypes.OPERATOR.BITWISE.UNSIGNED_RIGHT, "!==": core_1.JSTokenTypes.OPERATOR.LOGICAL.INEQUALITY_EXACT, "===": core_1.JSTokenTypes.OPERATOR.LOGICAL.EQUALITY_EXACT, ">>": core_1.JSTokenTypes.OPERATOR.BITWISE.SIGNED_RIGHT, "<<": core_1.JSTokenTypes.OPERATOR.BITWISE.SIGNED_LEFT, "^=": core_1.JSTokenTypes.OPERATOR.BITWISE.EXCLUSIVE_OR_ASSIGN, "--": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.DECREMENT, "++": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.INCREMENT, "!=": core_1.JSTokenTypes.OPERATOR.LOGICAL.INEQUALITY, "==": core_1.JSTokenTypes.OPERATOR.LOGICAL.EQUALITY, "||": core_1.JSTokenTypes.OPERATOR.LOGICAL.OR, "|=": core_1.JSTokenTypes.OPERATOR.LOGICAL.OR_ASSIGN, "&&": core_1.JSTokenTypes.OPERATOR.LOGICAL.AND, "&=": core_1.JSTokenTypes.OPERATOR.LOGICAL.AND_ASSIGN, ">=": core_1.JSTokenTypes.OPERATOR.LOGICAL.GREATER_THAN_EQUALS, "<=": core_1.JSTokenTypes.OPERATOR.LOGICAL.LESS_THAN_EQUALS, "+=": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.ADD_ASSIGN, "-=": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.SUBSTRACT_ASSIGN, "*=": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.MULTIPLY_ASSIGN, "/=": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.DIVIDE_ASSIGN, "^": core_1.JSTokenTypes.OPERATOR.BITWISE.EXCLUSIVE_OR, "|": core_1.JSTokenTypes.OPERATOR.BITWISE.OR, "&": core_1.JSTokenTypes.OPERATOR.BITWISE.AND, "+": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.ADD, "-": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.SUBSTRACT, "*": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.MULTIPLY, "/": core_1.JSTokenTypes.OPERATOR.ARITHMETIC.DIVIDE, "!": core_1.JSTokenTypes.OPERATOR.LOGICAL.NOT, "<": core_1.JSTokenTypes.OPERATOR.LOGICAL.LESS_THAN, ">": core_1.JSTokenTypes.OPERATOR.LOGICAL.GREATER_THAN, "=": core_1.JSTokenTypes.OPERATOR.ASSIGN.ASSIGN, "/**": core_1.JSTokenTypes.COMMENT.BLOCK_START, "/*": core_1.JSTokenTypes.COMMENT.BLOCK_START, "*/": core_1.JSTokenTypes.COMMENT.BLOCK_END, "//": core_1.JSTokenTypes.COMMENT.LINE, "///": core_1.JSTokenTypes.COMMENT.LINE_DOC, "(": core_1.JSTokenTypes.OPERATOR.PRIORITY.PARENTHESIS_OPEN, ")": core_1.JSTokenTypes.OPERATOR.PRIORITY.PARENTHESIS_CLOSE, "{": core_1.JSTokenTypes.BRACKET.CURLY_OPEN, "}": core_1.JSTokenTypes.BRACKET.CURLY_CLOSE, "[": core_1.JSTokenTypes.BRACKET.SQUARE_OPEN, "]": core_1.JSTokenTypes.BRACKET.SQUARE_CLOSE, ",": core_1.JSTokenTypes.PUNCTUATION.COMMA, ";": core_1.JSTokenTypes.PUNCTUATION.SEMICOLON, ":": core_1.JSTokenTypes.PUNCTUATION.COLON, ".": core_1.JSTokenTypes.PUNCTUATION.OBJECT_ACCESSOR, "?.": core_1.JSTokenTypes.PUNCTUATION.SAFE_OBJECT_ACCESSOR, "\\": core_1.JSTokenTypes.PUNCTUATION.BACKSLASH, "'": core_1.JSTokenTypes.PUNCTUATION.QUOTTES, '"': core_1.JSTokenTypes.PUNCTUATION.DOUBLE_QUOTTES, "@": core_1.JSTokenTypes.PUNCTUATION.AT, "?": core_1.JSTokenTypes.PUNCTUATION.EXMARK, }; var reservedKeywords = { "abstract": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "arguments": core_1.JSTokenTypes.KEYWORD.OTHER, "await": core_1.JSTokenTypes.KEYWORD.OTHER, "boolean": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "break": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.BREAK, "byte": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "case": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.SWITCH_CASE, "catch": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.CATCH, "char": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "class": core_1.JSTokenTypes.KEYWORD.DECLARATION.CLASS, "const": core_1.JSTokenTypes.KEYWORD.DECLARATION.CONSTANT, "continue": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.CONTINUE, "constructor": core_1.JSTokenTypes.KEYWORD.DECLARATION.CONSTRUCTOR, "debugger": core_1.JSTokenTypes.KEYWORD.OTHER, "default": core_1.JSTokenTypes.KEYWORD.OTHER, "double": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "do": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.DO, "else": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.ELSE, "enum": core_1.JSTokenTypes.KEYWORD.DECLARATION.ENUM, "eval": core_1.JSTokenTypes.KEYWORD.OTHER, "export": core_1.JSTokenTypes.KEYWORD.OTHER, "extends": core_1.JSTokenTypes.KEYWORD.DECLARATION.EXTENDS, "false": core_1.JSTokenTypes.LITERAL.BOOLEAN, "final": core_1.JSTokenTypes.KEYWORD.MODIFIER.FINAL, "finally": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.FINALLY, "float": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "for": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.FOR, "function": core_1.JSTokenTypes.KEYWORD.DECLARATION.FUNCTION, "goto": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "if": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.IF, "implements": core_1.JSTokenTypes.KEYWORD.DECLARATION.IMPLEMENTS, "import": core_1.JSTokenTypes.KEYWORD.OTHER, "Infinity": core_1.JSTokenTypes.LITERAL.INFINITY, "in": core_1.JSTokenTypes.KEYWORD.OTHER, "instanceof": core_1.JSTokenTypes.OPERATOR.LOGICAL.INSTANCE_OF, "int": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "interface": core_1.JSTokenTypes.KEYWORD.DECLARATION.INTERFACE, "let": core_1.JSTokenTypes.KEYWORD.DECLARATION.VARIABLE, "long": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "NaN": core_1.JSTokenTypes.LITERAL.NAN, "native": core_1.JSTokenTypes.KEYWORD.OTHER, "new": core_1.JSTokenTypes.KEYWORD.OBJECT.NEW, "null": core_1.JSTokenTypes.LITERAL.NULL, "of": core_1.JSTokenTypes.KEYWORD.OTHER, "package": core_1.JSTokenTypes.KEYWORD.OTHER, "private": core_1.JSTokenTypes.KEYWORD.MODIFIER.ACCESS, "protected": core_1.JSTokenTypes.KEYWORD.MODIFIER.ACCESS, "public": core_1.JSTokenTypes.KEYWORD.MODIFIER.ACCESS, "return": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.RETURN, "short": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "static": core_1.JSTokenTypes.KEYWORD.MODIFIER.STATIC, "super": core_1.JSTokenTypes.KEYWORD.OBJECT.SUPER, "switch": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.SWITCH, "synchronized": core_1.JSTokenTypes.KEYWORD.FOR_FUTURE, "this": core_1.JSTokenTypes.KEYWORD.OBJECT.THIS, "throw": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.THROW, "throws": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.THROW, "transient": core_1.JSTokenTypes.KEYWORD.MODIFIER.TRANSIENT, "true": core_1.JSTokenTypes.LITERAL.BOOLEAN, "try": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.TRY, "typeof": core_1.JSTokenTypes.KEYWORD.OBJECT.TYPEOF, "undefined": core_1.JSTokenTypes.LITERAL.UNDEFINED, "var": core_1.JSTokenTypes.KEYWORD.DECLARATION.VARIABLE, "void": core_1.JSTokenTypes.DATATYPE.VOID, "volatile": core_1.JSTokenTypes.KEYWORD.OTHER, "while": core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.WHILE, "with": core_1.JSTokenTypes.KEYWORD.OTHER, "yield": core_1.JSTokenTypes.KEYWORD.OTHER, 'Array': core_1.JSTokenTypes.DATATYPE.ARRAY, 'Date': core_1.JSTokenTypes.DATATYPE.DATE, 'String': core_1.JSTokenTypes.DATATYPE.STRING, 'Math': core_1.JSTokenTypes.DATATYPE.MATH, 'Number': core_1.JSTokenTypes.DATATYPE.NUMBER, 'Object': core_1.JSTokenTypes.DATATYPE.OBJECT, 'prototype': core_1.JSTokenTypes.KEYWORD.OBJECT.PROTOTYPE, }; var predefinedObjects = [ 'hasOwnProperty', 'isFinite', 'isNaN', 'isPrototypeOf', 'length', 'name', 'toString', 'valueOf', 'getClass', 'java', 'JavaArray', 'javaClass', 'JavaObject', 'JavaPackage', 'alert', 'all', 'anchor', 'anchors', 'area', 'assign', 'blur', 'button', 'checkbox', 'clearInterval', 'clearTimeout', 'clientInformation', 'close', 'closed', 'confirm', 'crypto', 'decodeURI', 'decodeURIComponent', 'defaultStatus', 'embeds', 'encodeURI', 'encodeURIComponent', 'escape', 'event', 'fileUpload', 'focus', 'form', 'forms', 'frame', 'innerHeight', 'innerWidth', 'layer', 'layers', 'link', 'location', 'mimeTypes', 'navigate', 'navigator', 'frames', 'frameRate', 'hidden', 'history', 'image', 'images', 'offscreenBuffering', 'open', 'opener', 'option', 'outerHeight', 'outerWidth', 'packages', 'pageXOffset', 'pageYOffset', 'parent', 'parseFloat', 'parseInt', 'password', 'pkcs11', 'plugin', 'prompt', 'propertyIsEnum', 'radio', 'reset', 'screenX', 'screenY', 'scroll', 'secure', 'select', 'self', 'setInterval', 'setTimeout', 'status', 'submit', 'taint', 'text', 'textarea', 'top', 'unescape', 'untaint', 'window', 'onblur', 'onclick', 'onerror', 'onfocus', 'onkeydown', 'onkeypress', 'onkeyup', 'onmouseover', 'onload', 'onmouseup', 'onmousedown', 'onsubmit' ]; /** * Class to Tokenizer Aura Javascript files */ var JSTokenizer = /** @class */ (function () { function JSTokenizer() { } /** * Method to Tokenize Aura Javscript file * @param {string} filePathOrContent File path or file content to tokenize * @param {number} [tabSize] Tab size * @returns {Token[]} Return file tokens */ JSTokenizer.tokenize = function (filePathOrContent, tabSize) { if (!tabSize) { tabSize = 4; } var content; if (Utils.isString(filePathOrContent)) { try { content = core_1.FileReader.readFileSync(Validator.validateFilePath(filePathOrContent)); } catch (error) { content = filePathOrContent; } } else { throw new Error('You must to select a file path,or file content'); } var NUM_FORMAT = /[0-9]/; var ID_FORMAT = /([a-zA-Z0-9À-ÿ]|_|–)/; content = StrUtils.replace(content, '\r\n', '\n'); var tokens = []; var lineNumber = 0; var column = 0; var onCommentBlock = false; var onCommentLine = false; var onText = false; var parentIndex = []; var bracketIndex = []; var auxBracketIndex = []; var classDeclarationIndex = []; var enumDeclarationIndex = []; var sqBracketIndex = []; var quottesIndex = []; var commentBlockIndex = []; for (var charIndex = 0, len = content.length; charIndex < len; charIndex++) { var fourChars = content.substring(charIndex, charIndex + 4); var threeChars = content.substring(charIndex, charIndex + 3); var twoChars = content.substring(charIndex, charIndex + 2); var char = content.charAt(charIndex); var token = void 0; var lastToken = (tokens.length > 0) ? tokens[tokens.length - 1] : undefined; if (fourChars.length === 4 && symbolTokens[fourChars]) { token = new core_1.Token(symbolTokens[fourChars], fourChars, lineNumber, column); charIndex += 3; column += 4; } else if (threeChars.length === 3 && symbolTokens[threeChars]) { token = new core_1.Token(symbolTokens[threeChars], threeChars, lineNumber, column); charIndex += 2; column += 3; } else if (twoChars.length === 2 && symbolTokens[twoChars]) { token = new core_1.Token(symbolTokens[twoChars], twoChars, lineNumber, column); charIndex += 1; column += 2; } else if (symbolTokens[char]) { token = new core_1.Token(symbolTokens[char], char, lineNumber, column); column++; } else if (NUM_FORMAT.test(char)) { var numContent = ''; while (NUM_FORMAT.test(char) || char === '.' || char === ':' || char === '+' || char === '-' || char.toLowerCase() === 't' || char.toLowerCase() === 'z') { numContent += char; char = content.charAt(++charIndex); } if (numContent.indexOf(':') !== -1 && numContent.indexOf('-') !== -1) { token = new core_1.Token(core_1.JSTokenTypes.LITERAL.DATETIME, numContent, lineNumber, column); } else if (numContent.indexOf('-') !== -1) { token = new core_1.Token(core_1.JSTokenTypes.LITERAL.DATE, numContent, lineNumber, column); } else if (numContent.indexOf(':') !== -1) { token = new core_1.Token(core_1.JSTokenTypes.LITERAL.TIME, numContent, lineNumber, column); } else if (numContent.indexOf('.') !== -1) { token = new core_1.Token(core_1.JSTokenTypes.LITERAL.DOUBLE, numContent, lineNumber, column); } else { token = new core_1.Token(core_1.JSTokenTypes.LITERAL.INTEGER, numContent, lineNumber, column); } charIndex--; column += numContent.length; } else if (ID_FORMAT.test(char)) { var idContent = ''; while (ID_FORMAT.test(char)) { idContent += char; char = content.charAt(++charIndex); } charIndex--; token = new core_1.Token(core_1.JSTokenTypes.IDENTIFIER, idContent, lineNumber, column); column += idContent.length; } else if (char === "\n") { if (onCommentLine) { onCommentLine = false; } lineNumber++; column = 0; } else if (char !== "\t" && char !== " " && char.trim().length !== 0) { token = new core_1.Token(core_1.JSTokenTypes.UNKNOWN, char, lineNumber, column); column++; } else if (char === "\t") { column += tabSize; } else { column++; } if (token !== undefined) { if (!onText && !onCommentBlock && !onCommentLine && token.type === core_1.JSTokenTypes.PUNCTUATION.QUOTTES && (!lastToken || lastToken.text !== '\\')) { token.type = core_1.JSTokenTypes.PUNCTUATION.QUOTTES_START; onText = true; token.parentToken = tokens.length - 1; quottesIndex.push(tokens.length); } else if (onText && token.type === core_1.JSTokenTypes.PUNCTUATION.QUOTTES && (!lastToken || lastToken.text !== '\\')) { token.type = core_1.JSTokenTypes.PUNCTUATION.QUOTTES_END; onText = false; if (quottesIndex.length > 0) { var index = quottesIndex.pop(); if (index !== undefined) { token.pairToken = index; tokens[index].pairToken = tokens.length; token.parentToken = tokens[index].parentToken; } } } else if (!onText && !onCommentBlock && !onCommentLine && token.type === core_1.JSTokenTypes.PUNCTUATION.DOUBLE_QUOTTES && (!lastToken || lastToken.text !== '\\')) { token.type = core_1.JSTokenTypes.PUNCTUATION.DOUBLE_QUOTTES_START; onText = true; token.parentToken = tokens.length - 1; quottesIndex.push(tokens.length); } else if (onText && token.type === core_1.JSTokenTypes.PUNCTUATION.DOUBLE_QUOTTES && (!lastToken || lastToken.text !== '\\')) { token.type = core_1.JSTokenTypes.PUNCTUATION.DOUBLE_QUOTTES_END; onText = false; if (quottesIndex.length > 0) { var index = quottesIndex.pop(); if (index !== undefined) { token.pairToken = index; tokens[index].pairToken = tokens.length; token.parentToken = tokens[index].parentToken; } } } else if (!onText && !onCommentBlock && !onCommentLine && token.type === core_1.JSTokenTypes.COMMENT.BLOCK_START) { onCommentBlock = true; token.parentToken = tokens.length - 1; commentBlockIndex.push(tokens.length); } else if (onCommentBlock && token.type === core_1.JSTokenTypes.COMMENT.BLOCK_END) { onCommentBlock = false; if (commentBlockIndex.length > 0) { var index = commentBlockIndex.pop(); if (index !== undefined) { token.pairToken = index; tokens[index].pairToken = tokens.length; token.parentToken = tokens[index].parentToken; } } } else if (!onText && !onCommentBlock && !onCommentLine && (token.type === core_1.JSTokenTypes.COMMENT.LINE || token.type === core_1.JSTokenTypes.COMMENT.LINE_DOC)) { token.parentToken = tokens.length - 1; onCommentLine = true; } else if (onText) { token.type = core_1.JSTokenTypes.LITERAL.STRING; if (quottesIndex.length > 0) { token.parentToken = quottesIndex[quottesIndex.length - 1]; } } else if (onCommentBlock || onCommentLine) { token.type = core_1.JSTokenTypes.COMMENT.CONTENT; if (commentBlockIndex.length > 0) { token.parentToken = commentBlockIndex[commentBlockIndex.length - 1]; } } else if (token.type === core_1.JSTokenTypes.BRACKET.CURLY_OPEN && lastToken) { if (lastToken.parentToken !== undefined) { token.parentToken = lastToken.parentToken; } else { token.parentToken = tokens.length - 1; } if (lastToken.type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_CLOSE || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.ELSE || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.TRY || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.FINALLY || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.DO) { if (lastToken.type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_CLOSE && lastToken.parentToken !== undefined) { token.parentToken = lastToken.parentToken; } else { token.parentToken = tokens.length - 1; } } if (classDeclarationIndex.length > 0) { token.parentToken = classDeclarationIndex.pop(); } bracketIndex.push(tokens.length); } else if (token.type === core_1.JSTokenTypes.BRACKET.CURLY_CLOSE) { if (bracketIndex.length > 0) { var index = bracketIndex.pop(); if (index !== undefined) { if (tokens[index].parentToken) { token.parentToken = tokens[index].parentToken; } else { token.parentToken = index; } token.pairToken = index; tokens[index].pairToken = tokens.length; } } if (enumDeclarationIndex.length > 0) { enumDeclarationIndex.pop(); } } else if (token.type === core_1.JSTokenTypes.BRACKET.SQUARE_OPEN) { sqBracketIndex.push(tokens.length); } else if (token.type === core_1.JSTokenTypes.BRACKET.SQUARE_CLOSE) { if (sqBracketIndex.length > 0) { var index = sqBracketIndex.pop(); if (index !== undefined) { token.pairToken = index; tokens[index].pairToken = tokens.length; } } } else if (token.type === core_1.JSTokenTypes.OPERATOR.PRIORITY.PARENTHESIS_OPEN) { if (lastToken && lastToken.type === core_1.JSTokenTypes.DECLARATION.ENTITY.VARIABLE) { tokens[tokens.length - 1].type = core_1.JSTokenTypes.DECLARATION.ENTITY.FUNCTION; token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_OPEN; } else if (lastToken && lastToken.type === core_1.JSTokenTypes.ENTITY.VARIABLE) { tokens[tokens.length - 1].type = core_1.JSTokenTypes.ENTITY.FUNCTION; token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_PARAM_OPEN; } else if (lastToken && lastToken.type === core_1.JSTokenTypes.DECLARATION.ENTITY.FUNCTION) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_OPEN; } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.FUNCTION) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_OPEN; } else if (lastToken && (lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.IF || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.ELSE_IF || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.CATCH || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.WHILE || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.FOR)) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_OPEN; } token.parentToken = tokens.length - 1; parentIndex.push(tokens.length); } else if (token.type === core_1.JSTokenTypes.OPERATOR.PRIORITY.PARENTHESIS_CLOSE) { if (parentIndex.length > 0) { var index = parentIndex.pop(); if (index !== undefined && tokens[index]) { if (tokens[index].type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_PARAM_OPEN) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_PARAM_CLOSE; } else if (tokens[index].type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_OPEN) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_CLOSE; } else if (tokens[index].type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_OPEN) { token.type = core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_CLOSE; } token.parentToken = tokens[index].parentToken; token.pairToken = index; tokens[index].pairToken = tokens.length; } } } else if (token.type === core_1.JSTokenTypes.IDENTIFIER) { if (reservedKeywords[token.text]) { token.type = reservedKeywords[token.text]; classDeclarationIndex.push(tokens.length); } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.CLASS) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.CLASS; classDeclarationIndex.push(tokens.length); } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.ENUM) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.ENUM; classDeclarationIndex.push(tokens.length); enumDeclarationIndex.push(tokens.length); } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.INTERFACE) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.INTERFACE; classDeclarationIndex.push(tokens.length); } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.VARIABLE) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.VARIABLE; } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.CONSTANT) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.CONSTANT; } else if (lastToken && lastToken.type === core_1.JSTokenTypes.KEYWORD.DECLARATION.FUNCTION) { token.type = core_1.JSTokenTypes.DECLARATION.ENTITY.FUNCTION; } else { token.type = core_1.JSTokenTypes.ENTITY.VARIABLE; } } if (lastToken && (lastToken.type === core_1.JSTokenTypes.BRACKET.PARENTHESIS_GUARD_CLOSE || lastToken.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.ELSE)) { if (token.type !== core_1.JSTokenTypes.BRACKET.CURLY_OPEN && token.type !== core_1.JSTokenTypes.PUNCTUATION.SEMICOLON) { var newToken = new core_1.Token(core_1.JSTokenTypes.BRACKET.CURLY_OPEN, '{', lastToken.range.start.line, lastToken.range.start.character + 1); newToken.isAux = true; newToken.parentToken = (lastToken.parentToken) ? lastToken.parentToken : tokens.length - 1; auxBracketIndex.push(tokens.length); tokens.push(newToken); } } else if (token.type === core_1.JSTokenTypes.BRACKET.CURLY_CLOSE && !token.isAux && auxBracketIndex.length > 0) { for (var _i = 0, auxBracketIndex_1 = auxBracketIndex; _i < auxBracketIndex_1.length; _i++) { var index = auxBracketIndex_1[_i]; var tokenAux = tokens[index]; var newToken = new core_1.Token(core_1.JSTokenTypes.BRACKET.CURLY_CLOSE, '}', 0, 0); newToken.parentToken = (tokenAux.parentToken) ? tokenAux.parentToken : token.parentToken; newToken.isAux = true; newToken.pairToken = index; tokens[index].pairToken = tokens.length; tokens.push(newToken); } auxBracketIndex = []; } tokens.push(token); if ((token.type === core_1.JSTokenTypes.PUNCTUATION.SEMICOLON) && auxBracketIndex.length > 0) { var index = auxBracketIndex.pop(); if (index !== undefined) { var tokenAux = tokens[index]; var newToken = new core_1.Token(core_1.JSTokenTypes.BRACKET.CURLY_CLOSE, '}', token.range.start.line + 1, token.range.start.character - 4); newToken.isAux = true; newToken.parentToken = tokenAux.parentToken; newToken.pairToken = index; tokens[index].pairToken = tokens.length; tokens.push(newToken); var tokentmp = tokens[index - 1]; if (tokentmp.type === core_1.JSTokenTypes.KEYWORD.FLOW_CONTROL.ELSE && auxBracketIndex.length > 0) { index = auxBracketIndex.pop(); if (index !== undefined) { tokenAux = tokens[index]; newToken = new core_1.Token(core_1.JSTokenTypes.BRACKET.CURLY_CLOSE, '}', 0, 0); newToken.isAux = true; newToken.parentToken = tokenAux.parentToken; newToken.pairToken = index; tokens[index].pairToken = tokens.length; tokens.push(newToken); } } } } } } return tokens; }; return JSTokenizer; }()); exports.JSTokenizer = JSTokenizer; //# sourceMappingURL=tokenizer.js.map