diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index debaac9da..ec6d6d706 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [18.x, 20.x, 22.x] + node-version: [20.x, 22.x, 24.x] steps: - uses: actions/checkout@v2 @@ -29,26 +29,3 @@ jobs: yarn build-types [ $(git diff types.d.ts | wc -l) -gt 0 ] && echo 'Diff exists in types.d.ts. Please change jsdoc.' && exit 1 tsc --noEmit types.d.ts - - - name: install valgrind - run: sudo apt-get install -y valgrind - - - name: benchmark - run: python cachegrind.py node test/benchmark2.js > output.txt - - - name: Download previous benchmark result - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-${{matrix.node-version}}-benchmark - - - name: Store benchmark result - uses: benchmark-action/github-action-benchmark@v1 - with: - tool: "customSmallerIsBetter" - output-file-path: output.txt - external-data-json-path: ./cache/benchmark-data.json - alert-threshold: "105%" - fail-on-alert: true - env: - CI: true diff --git a/cachegrind.py b/cachegrind.py deleted file mode 100644 index ce1c38024..000000000 --- a/cachegrind.py +++ /dev/null @@ -1,137 +0,0 @@ -""" -Proof-of-concept: run_with_cachegrind a program under Cachegrind, combining all the various -metrics into one single performance metric. - -Requires Python 3. - -License: https://opensource.org/licenses/MIT - -## Features - -* Disables ASLR. -* Sets consistent cache sizes. -* Calculates a combined performance metric. - -For more information see the detailed write up at: - -https://pythonspeed.com/articles/consistent-benchmarking-in-ci/ - -## Usage - -This script has no compatibility guarnatees, I recommend copying it into your -repository. To use: - -$ python3 cachegrind.py ./yourprogram --yourparam=yourvalues - -If you're benchmarking Python, make sure to set PYTHONHASHSEED to a fixed value -(e.g. `export PYTHONHASHSEED=1234`). Other languages may have similar -requirements to reduce variability. - -The last line printed will be a combined performance metric, but you can tweak -the script to extract more info, or use it as a library. - -Copyright © 2020, Hyphenated Enterprises LLC. -""" - -import json -from typing import List, Dict -from subprocess import check_call, check_output -import sys -from tempfile import NamedTemporaryFile - -ARCH = check_output(["uname", "-m"]).strip() - - -def run_with_cachegrind(args_list: List[str]) -> Dict[str, int]: - """ - Run the the given program and arguments under Cachegrind, parse the - Cachegrind specs. - - For now we just ignore program output, and in general this is not robust. - """ - temp_file = NamedTemporaryFile("r+") - check_call([ - # Disable ASLR: - "setarch", - ARCH, - "-R", - "valgrind", - "--tool=cachegrind", - # Set some reasonable L1 and LL values, based on Haswell. You can set - # your own, important part is that they are consistent across runs, - # instead of the default of copying from the current machine. - "--I1=32768,8,64", - "--D1=32768,8,64", - "--LL=8388608,16,64", - "--cachegrind-out-file=" + temp_file.name, - ] + args_list) - return parse_cachegrind_output(temp_file) - - -def parse_cachegrind_output(temp_file): - # Parse the output file: - lines = iter(temp_file) - for line in lines: - if line.startswith("events: "): - header = line[len("events: "):].strip() - break - for line in lines: - last_line = line - assert last_line.startswith("summary: ") - last_line = last_line[len("summary:"):].strip() - return dict(zip(header.split(), [int(i) for i in last_line.split()])) - - -def get_counts(cg_results: Dict[str, int]) -> Dict[str, int]: - """ - Given the result of run_with_cachegrind(), figure out the parameters we will use for final - estimate. - - We pretend there's no L2 since Cachegrind doesn't currently support it. - - Caveats: we're not including time to process instructions, only time to - access instruction cache(s), so we're assuming time to fetch and run_with_cachegrind - instruction is the same as time to retrieve data if they're both to L1 - cache. - """ - result = {} - d = cg_results - - ram_hits = d["DLmr"] + d["DLmw"] + d["ILmr"] - - l3_hits = d["I1mr"] + d["D1mw"] + d["D1mr"] - ram_hits - - total_memory_rw = d["Ir"] + d["Dr"] + d["Dw"] - l1_hits = total_memory_rw - l3_hits - ram_hits - assert total_memory_rw == l1_hits + l3_hits + ram_hits - - result["l1"] = l1_hits - result["l3"] = l3_hits - result["ram"] = ram_hits - - return result - - -def combined_instruction_estimate(counts: Dict[str, int]) -> int: - """ - Given the result of run_with_cachegrind(), return estimate of total time to run_with_cachegrind. - - Multipliers were determined empirically, but some research suggests they're - a reasonable approximation for cache time ratios. L3 is probably too low, - but then we're not simulating L2... - """ - return counts["l1"] + (5 * counts["l3"]) + (35 * counts["ram"]) - - -def github_action_benchmark_json(value): - return json.dumps([ - { - "name": "score", - "unit": "", - "value": value, - } - ]) - - -if __name__ == "__main__": - print(github_action_benchmark_json(combined_instruction_estimate(get_counts(run_with_cachegrind(sys.argv[1:]))))) diff --git a/eslint.config.mjs b/eslint.config.mjs index 898d304ee..c0f1f0832 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -31,6 +31,7 @@ export default [ rules: { "prefer-const": "error", "no-var": "error", + "object-shorthand": "error", curly: ["error", "multi-line"], }, }, diff --git a/package.json b/package.json index d2ac370e6..987667c76 100644 --- a/package.json +++ b/package.json @@ -57,30 +57,29 @@ ], "license": "BSD-3-Clause", "devDependencies": { - "@babel/core": "^7.26.0", - "@babel/preset-env": "^7.26.0", - "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "^9.14.0", - "@types/node": "^22.9.0", - "babel-loader": "^9.2.1", + "@babel/core": "^7.27.4", + "@babel/preset-env": "^7.27.2", + "@eslint/js": "^9.29.0", + "@types/node": "^24.0.4", + "babel-loader": "^10.0.0", "benchmark": "^2.1.4", "coveralls": "^3.0.3", - "eslint": "^9.14.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-jest": "^28.9.0", - "eslint-plugin-prettier": "^5.2.1", - "globals": "^15.12.0", - "husky": "^9.1.6", - "jest": "^29.7.0", + "eslint": "^9.29.0", + "eslint-config-prettier": "^10.1.5", + "eslint-plugin-jest": "^29.0.1", + "eslint-plugin-prettier": "^5.5.0", + "globals": "^16.2.0", + "husky": "^9.1.7", + "jest": "^30.0.3", "jest-runner-eslint": "^2.2.1", - "jsdoc": "^3.6.11", + "jsdoc": "^4.0.4", "jsdoc-template": "^1.2.0", "lodash.template": ">=4.5.0", - "prettier": "^3.3.3", + "prettier": "^3.6.1", "tsd-jsdoc": "^2.5.0", - "typescript": "^5.6.3", + "typescript": "^5.8.3", "webpack": "5.96.0", - "webpack-cli": "^5.1.4", + "webpack-cli": "^6.0.1", "yarpm": "^1.2.0" }, "dependencies": {} diff --git a/src/lexer.js b/src/lexer.js index c1cee6b35..e3e387ac1 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -180,7 +180,7 @@ Lexer.prototype.setInput = function (input) { first_encaps_node: false, // for backward compatible /* istanbul ignore next */ - toString: function () { + toString() { this.label; }, }; diff --git a/src/lexer/attribute.js b/src/lexer/attribute.js index b3421baea..d708d6fb4 100644 --- a/src/lexer/attribute.js +++ b/src/lexer/attribute.js @@ -8,7 +8,7 @@ module.exports = { attributeIndex: 0, attributeListDepth: {}, - matchST_ATTRIBUTE: function () { + matchST_ATTRIBUTE() { let ch = this.input(); if (this.is_WHITESPACE()) { do { diff --git a/src/lexer/comments.js b/src/lexer/comments.js index 43501d701..aaa49ff44 100644 --- a/src/lexer/comments.js +++ b/src/lexer/comments.js @@ -9,7 +9,7 @@ module.exports = { /* * Reads a single line comment */ - T_COMMENT: function () { + T_COMMENT() { while (this.offset < this.size) { const ch = this.input(); if (ch === "\n" || ch === "\r") { @@ -35,7 +35,7 @@ module.exports = { /* * Behaviour : https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1927 */ - T_DOC_COMMENT: function () { + T_DOC_COMMENT() { let ch = this.input(); let token = this.tok.T_COMMENT; if (ch === "*") { diff --git a/src/lexer/initial.js b/src/lexer/initial.js index 1524b8048..c7daba893 100644 --- a/src/lexer/initial.js +++ b/src/lexer/initial.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - nextINITIAL: function () { + nextINITIAL() { if ( this.conditionStack.length > 1 && this.conditionStack[this.conditionStack.length - 1] === "INITIAL" @@ -18,7 +18,7 @@ module.exports = { } return this; }, - matchINITIAL: function () { + matchINITIAL() { while (this.offset < this.size) { let ch = this.input(); if (ch == "<") { diff --git a/src/lexer/numbers.js b/src/lexer/numbers.js index 0d6239461..484b35a99 100644 --- a/src/lexer/numbers.js +++ b/src/lexer/numbers.js @@ -14,7 +14,7 @@ if (process.arch == "x64") { } module.exports = { - consume_NUM: function () { + consume_NUM() { let ch = this.yytext[0]; let hasPoint = ch === "."; if (ch === "0") { @@ -124,7 +124,7 @@ module.exports = { } }, // read hexa - consume_HNUM: function () { + consume_HNUM() { while (this.offset < this.size) { const ch = this.input(); if (!this.is_HEX()) { @@ -135,7 +135,7 @@ module.exports = { return this.tok.T_LNUMBER; }, // read a generic number - consume_LNUM: function () { + consume_LNUM() { while (this.offset < this.size) { const ch = this.input(); if (!this.is_NUM()) { @@ -146,7 +146,7 @@ module.exports = { return this.tok.T_LNUMBER; }, // read binary - consume_BNUM: function () { + consume_BNUM() { let ch; while (this.offset < this.size) { ch = this.input(); @@ -158,7 +158,7 @@ module.exports = { return this.tok.T_LNUMBER; }, // read an octal number - consume_ONUM: function () { + consume_ONUM() { while (this.offset < this.size) { const ch = this.input(); if (!this.is_OCTAL()) { diff --git a/src/lexer/property.js b/src/lexer/property.js index 8d2c00259..ff46f0a59 100644 --- a/src/lexer/property.js +++ b/src/lexer/property.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - matchST_LOOKING_FOR_PROPERTY: function () { + matchST_LOOKING_FOR_PROPERTY() { let ch = this.input(); if (ch === "-") { ch = this.input(); @@ -28,7 +28,7 @@ module.exports = { if (ch) this.unput(1); return false; }, - matchST_LOOKING_FOR_VARNAME: function () { + matchST_LOOKING_FOR_VARNAME() { let ch = this.input(); // SHIFT STATE @@ -52,7 +52,7 @@ module.exports = { // stops looking for a varname and starts the scripting mode return false; }, - matchST_VAR_OFFSET: function () { + matchST_VAR_OFFSET() { const ch = this.input(); if (this.is_NUM_START()) { this.consume_NUM(); diff --git a/src/lexer/scripting.js b/src/lexer/scripting.js index 0a6a1a1a3..1da761afd 100644 --- a/src/lexer/scripting.js +++ b/src/lexer/scripting.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - matchST_IN_SCRIPTING: function () { + matchST_IN_SCRIPTING() { let ch = this.input(); switch (ch) { case " ": @@ -100,7 +100,7 @@ module.exports = { ); }, - T_WHITESPACE: function () { + T_WHITESPACE() { while (this.offset < this.size) { const ch = this.input(); if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") { diff --git a/src/lexer/strings.js b/src/lexer/strings.js index 689213e5f..99a0ead4d 100644 --- a/src/lexer/strings.js +++ b/src/lexer/strings.js @@ -19,7 +19,7 @@ const valid_after_heredoc_73 = valid_after_heredoc.concat([ ]); module.exports = { - T_CONSTANT_ENCAPSED_STRING: function () { + T_CONSTANT_ENCAPSED_STRING() { let ch; while (this.offset < this.size) { ch = this.input(); @@ -32,7 +32,7 @@ module.exports = { return this.tok.T_CONSTANT_ENCAPSED_STRING; }, // check if matching a HEREDOC state - is_HEREDOC: function () { + is_HEREDOC() { const revert = this.offset; if ( this._input[this.offset - 1] === "<" && @@ -96,7 +96,7 @@ module.exports = { this.offset = revert; return false; }, - ST_DOUBLE_QUOTES: function () { + ST_DOUBLE_QUOTES() { let ch; while (this.offset < this.size) { ch = this.input(); @@ -140,7 +140,7 @@ module.exports = { }, // check if its a DOC end sequence - isDOC_MATCH: function (offset, consumeLeadingSpaces) { + isDOC_MATCH(offset, consumeLeadingSpaces) { // @fixme : check if out of text limits // consumeLeadingSpaces is false happen DOC prematch END HEREDOC stage. @@ -221,7 +221,7 @@ module.exports = { * Prematch the end of HEREDOC/NOWDOC end tag to preset the * context of this.heredoc_label */ - prematch_ENDOFDOC: function () { + prematch_ENDOFDOC() { // reset heredoc this.heredoc_label.indentation_uses_spaces = false; this.heredoc_label.indentation = 0; @@ -248,7 +248,7 @@ module.exports = { } }, - matchST_NOWDOC: function () { + matchST_NOWDOC() { // edge case : empty now doc if (this.isDOC_MATCH(this.offset, true)) { // @fixme : never reached (may be caused by quotes) @@ -274,7 +274,7 @@ module.exports = { return this.tok.T_ENCAPSED_AND_WHITESPACE; }, - matchST_HEREDOC: function () { + matchST_HEREDOC() { // edge case : empty here doc let ch = this.input(); if (this.isDOC_MATCH(this.offset, true)) { @@ -346,7 +346,7 @@ module.exports = { return this.tok.T_ENCAPSED_AND_WHITESPACE; }, - consume_VARIABLE: function () { + consume_VARIABLE() { this.consume_LABEL(); const ch = this.input(); if (ch == "[") { @@ -370,7 +370,7 @@ module.exports = { return this.tok.T_VARIABLE; }, // HANDLES BACKQUOTES - matchST_BACKQUOTE: function () { + matchST_BACKQUOTE() { let ch = this.input(); if (ch === "$") { ch = this.input(); @@ -445,7 +445,7 @@ module.exports = { return this.tok.T_ENCAPSED_AND_WHITESPACE; }, - matchST_DOUBLE_QUOTES: function () { + matchST_DOUBLE_QUOTES() { let ch = this.input(); if (ch === "$") { ch = this.input(); diff --git a/src/lexer/tokens.js b/src/lexer/tokens.js index 217524ca8..638834da5 100644 --- a/src/lexer/tokens.js +++ b/src/lexer/tokens.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - T_STRING: function () { + T_STRING() { const token = this.yytext.toLowerCase(); let id = this.keywords[token]; if (typeof id !== "number") { @@ -83,7 +83,7 @@ module.exports = { return id; }, // reads a custom token - consume_TOKEN: function () { + consume_TOKEN() { const ch = this._input[this.offset - 1]; const fn = this.tokenTerminals[ch]; if (fn) { @@ -94,7 +94,7 @@ module.exports = { }, // list of special char tokens tokenTerminals: { - $: function () { + $() { this.offset++; if (this.is_LABEL_START()) { this.offset--; @@ -105,7 +105,7 @@ module.exports = { return "$"; } }, - "-": function () { + "-"() { const nchar = this._input[this.offset]; if (nchar === ">") { this.begin("ST_LOOKING_FOR_PROPERTY").input(); @@ -119,7 +119,7 @@ module.exports = { } return "-"; }, - "\\": function () { + "\\"() { if (this.offset < this.size) { this.input(); if (this.is_LABEL_START()) { @@ -144,14 +144,14 @@ module.exports = { } return this.tok.T_NS_SEPARATOR; }, - "/": function () { + "/"() { if (this._input[this.offset] === "=") { this.input(); return this.tok.T_DIV_EQUAL; } return "/"; }, - ":": function () { + ":"() { if (this._input[this.offset] === ":") { this.input(); return this.tok.T_DOUBLE_COLON; @@ -159,7 +159,7 @@ module.exports = { return ":"; } }, - "(": function () { + "("() { const initial = this.offset; this.input(); if (this.is_TABSPACE()) { @@ -184,7 +184,7 @@ module.exports = { this.unput(this.offset - initial); return "("; }, - "=": function () { + "="() { const nchar = this._input[this.offset]; if (nchar === ">") { this.input(); @@ -200,7 +200,7 @@ module.exports = { } return "="; }, - "+": function () { + "+"() { const nchar = this._input[this.offset]; if (nchar === "+") { this.input(); @@ -211,7 +211,7 @@ module.exports = { } return "+"; }, - "!": function () { + "!"() { if (this._input[this.offset] === "=") { if (this._input[this.offset + 1] === "=") { this.consume(2); @@ -223,7 +223,7 @@ module.exports = { } return "!"; }, - "?": function () { + "?"() { if (this.version >= 700 && this._input[this.offset] === "?") { if (this.version >= 704 && this._input[this.offset + 1] === "=") { this.consume(2); @@ -244,7 +244,7 @@ module.exports = { } return "?"; }, - "<": function () { + "<"() { let nchar = this._input[this.offset]; if (nchar === "<") { nchar = this._input[this.offset + 1]; @@ -272,7 +272,7 @@ module.exports = { } return "<"; }, - ">": function () { + ">"() { let nchar = this._input[this.offset]; if (nchar === "=") { this.input(); @@ -289,7 +289,7 @@ module.exports = { } return ">"; }, - "*": function () { + "*"() { const nchar = this._input[this.offset]; if (nchar === "=") { this.input(); @@ -305,7 +305,7 @@ module.exports = { } return "*"; }, - ".": function () { + "."() { const nchar = this._input[this.offset]; if (nchar === "=") { this.input(); @@ -316,14 +316,14 @@ module.exports = { } return "."; }, - "%": function () { + "%"() { if (this._input[this.offset] === "=") { this.input(); return this.tok.T_MOD_EQUAL; } return "%"; }, - "&": function () { + "&"() { const nchar = this._input[this.offset]; if (nchar === "=") { this.input(); @@ -334,7 +334,7 @@ module.exports = { } return "&"; }, - "|": function () { + "|"() { const nchar = this._input[this.offset]; if (nchar === "=") { this.input(); @@ -345,7 +345,7 @@ module.exports = { } return "|"; }, - "^": function () { + "^"() { if (this._input[this.offset] === "=") { this.input(); return this.tok.T_XOR_EQUAL; diff --git a/src/lexer/utils.js b/src/lexer/utils.js index 8a2733037..a02f32915 100644 --- a/src/lexer/utils.js +++ b/src/lexer/utils.js @@ -9,19 +9,19 @@ const tokens = ";:,.\\[]()|^&+-/*=%!~$<>?@"; module.exports = { // check if the char can be a numeric - is_NUM: function () { + is_NUM() { const ch = this._input.charCodeAt(this.offset - 1); return (ch > 47 && ch < 58) || ch === 95; }, // check if the char can be a numeric - is_NUM_START: function () { + is_NUM_START() { const ch = this._input.charCodeAt(this.offset - 1); return ch > 47 && ch < 58; }, // check if current char can be a label - is_LABEL: function () { + is_LABEL() { const ch = this._input.charCodeAt(this.offset - 1); return ( (ch > 96 && ch < 123) || @@ -33,7 +33,7 @@ module.exports = { }, // check if current char can be a label - is_LABEL_START: function () { + is_LABEL_START() { const ch = this._input.charCodeAt(this.offset - 1); // A - Z if (ch > 64 && ch < 91) return true; @@ -48,7 +48,7 @@ module.exports = { }, // reads each char of the label - consume_LABEL: function () { + consume_LABEL() { while (this.offset < this.size) { const ch = this.input(); if (!this.is_LABEL()) { @@ -60,22 +60,22 @@ module.exports = { }, // check if current char is a token char - is_TOKEN: function () { + is_TOKEN() { const ch = this._input[this.offset - 1]; return tokens.indexOf(ch) !== -1; }, // check if current char is a whitespace - is_WHITESPACE: function () { + is_WHITESPACE() { const ch = this._input[this.offset - 1]; return ch === " " || ch === "\t" || ch === "\n" || ch === "\r"; }, // check if current char is a whitespace (without newlines) - is_TABSPACE: function () { + is_TABSPACE() { const ch = this._input[this.offset - 1]; return ch === " " || ch === "\t"; }, // consume all whitespaces (excluding newlines) - consume_TABSPACE: function () { + consume_TABSPACE() { while (this.offset < this.size) { const ch = this.input(); if (!this.is_TABSPACE()) { @@ -86,7 +86,7 @@ module.exports = { return this; }, // check if current char can be a hexadecimal number - is_HEX: function () { + is_HEX() { const ch = this._input.charCodeAt(this.offset - 1); // 0 - 9 if (ch > 47 && ch < 58) return true; @@ -100,7 +100,7 @@ module.exports = { return false; }, // check if current char can be an octal number - is_OCTAL: function () { + is_OCTAL() { const ch = this._input.charCodeAt(this.offset - 1); // 0 - 7 if (ch > 47 && ch < 56) return true; diff --git a/src/parser/array.js b/src/parser/array.js index 0d354b209..7499a6c97 100644 --- a/src/parser/array.js +++ b/src/parser/array.js @@ -13,7 +13,7 @@ module.exports = { * '[' array_pair_list ']' * ``` */ - read_array: function () { + read_array() { let expect = null; let shortForm = false; const result = this.node("array"); @@ -39,7 +39,7 @@ module.exports = { * array_pair_list ::= array_pair (',' array_pair?)* * ``` */ - read_array_pair_list: function (shortForm) { + read_array_pair_list(shortForm) { const self = this; return this.read_list( function () { @@ -59,7 +59,7 @@ module.exports = { * | expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')' * | T_LIST '(' array_pair_list ')' */ - read_array_pair: function (shortForm) { + read_array_pair(shortForm) { if ( (!shortForm && this.token === ")") || (shortForm && this.token === "]") diff --git a/src/parser/class.js b/src/parser/class.js index cbc2c370f..1629e476f 100644 --- a/src/parser/class.js +++ b/src/parser/class.js @@ -12,7 +12,7 @@ module.exports = { * class ::= class_scope? T_CLASS T_STRING (T_EXTENDS NAMESPACE_NAME)? (T_IMPLEMENTS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' CLASS_BODY '}' * ``` */ - read_class_declaration_statement: function (attrs) { + read_class_declaration_statement(attrs) { const result = this.node("class"); const flag = this.read_class_modifiers(); // graceful mode : ignore token & go next @@ -35,7 +35,7 @@ module.exports = { return node; }, - read_class_modifiers: function () { + read_class_modifiers() { const modifier = this.read_class_modifier({ readonly: 0, final_or_abstract: 0, @@ -43,7 +43,7 @@ module.exports = { return [0, 0, modifier.final_or_abstract, modifier.readonly]; }, - read_class_modifier: function (memo) { + read_class_modifier(memo) { if (this.token === this.tok.T_READ_ONLY) { this.next(); memo.readonly = 1; @@ -73,7 +73,7 @@ module.exports = { * class_body ::= (member_flags? (T_VAR | T_STRING | T_FUNCTION))* * ``` */ - read_class_body: function (allow_variables, allow_enum_cases) { + read_class_body(allow_variables, allow_enum_cases) { let result = []; let attrs = []; while (this.token !== this.EOF && this.token !== "}") { @@ -177,7 +177,7 @@ module.exports = { * variable_list ::= (variable_declaration ',')* variable_declaration * ``` */ - read_variable_list: function (flags, attrs) { + read_variable_list(flags, attrs) { const result = this.node("propertystatement"); const properties = this.read_list( @@ -222,7 +222,7 @@ module.exports = { * constant_list ::= T_CONST [type] (constant_declaration ',')* constant_declaration * ``` */ - read_constant_list: function (flags, attrs) { + read_constant_list(flags, attrs) { if (this.expect(this.tok.T_CONST)) { this.next(); } @@ -272,7 +272,7 @@ module.exports = { * 2nd index : 0 => instance member, 1 => static member * 3rd index : 0 => normal, 1 => abstract member, 2 => final member */ - read_member_flags: function (asInterface) { + read_member_flags(asInterface) { const result = [-1, -1, -1]; if (this.is("T_MEMBER_FLAGS")) { let idx = 0, @@ -352,7 +352,7 @@ module.exports = { * | union_type '|' type { $$ = zend_ast_list_add($1, $3); } * ; */ - read_optional_type: function () { + read_optional_type() { const nullable = this.token === "?"; if (nullable) { this.next(); @@ -392,7 +392,7 @@ module.exports = { * interface ::= T_INTERFACE T_STRING (T_EXTENDS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' INTERFACE_BODY '}' * ``` */ - read_interface_declaration_statement: function (attrs) { + read_interface_declaration_statement(attrs) { const result = this.node("interface"); if (this.token !== this.tok.T_INTERFACE) { this.error(this.tok.T_INTERFACE); @@ -415,7 +415,7 @@ module.exports = { * interface_body ::= (member_flags? (T_CONST | T_FUNCTION))* * ``` */ - read_interface_body: function () { + read_interface_body() { let result = [], attrs = []; @@ -475,7 +475,7 @@ module.exports = { * trait ::= T_TRAIT T_STRING (T_EXTENDS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' FUNCTION* '}' * ``` */ - read_trait_declaration_statement: function () { + read_trait_declaration_statement() { const result = this.node("trait"); // graceful mode : ignore token & go next if (this.token !== this.tok.T_TRAIT) { @@ -498,7 +498,7 @@ module.exports = { * trait_use_statement ::= namespace_name (',' namespace_name)* ('{' trait_use_alias '}')? * ``` */ - read_trait_use_statement: function () { + read_trait_use_statement() { // defines use statements const node = this.node("traituse"); this.expect(this.tok.T_USE) && this.next(); @@ -533,7 +533,7 @@ module.exports = { * name list : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L303 * trait adaptation : https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L742 */ - read_trait_use_alias: function () { + read_trait_use_alias() { const node = this.node(); let trait = null; let method; diff --git a/src/parser/comment.js b/src/parser/comment.js index fdddb2529..387e69ec7 100644 --- a/src/parser/comment.js +++ b/src/parser/comment.js @@ -9,7 +9,7 @@ module.exports = { /* * Comments with // or # or / * ... * / */ - read_comment: function () { + read_comment() { const text = this.text(); let result = this.ast.prepare( text.substring(0, 2) === "/*" ? "commentblock" : "commentline", @@ -33,7 +33,7 @@ module.exports = { /* * Comments with / ** ... * / */ - read_doc_comment: function () { + read_doc_comment() { let result = this.ast.prepare("commentblock", null, this); const offset = this.lexer.yylloc.first_offset; const text = this.text(); diff --git a/src/parser/enum.js b/src/parser/enum.js index f380fe390..dc5554f4f 100644 --- a/src/parser/enum.js +++ b/src/parser/enum.js @@ -12,7 +12,7 @@ module.exports = { * enum ::= enum_scope? T_ENUM T_STRING (':' NAMESPACE_NAME)? (T_IMPLEMENTS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' ENUM_BODY '}' * ``` */ - read_enum_declaration_statement: function (attrs) { + read_enum_declaration_statement(attrs) { const result = this.node("enum"); // graceful mode : ignore token & go next if (!this.expect(this.tok.T_ENUM)) { @@ -32,7 +32,7 @@ module.exports = { return node; }, - read_enum_value_type: function () { + read_enum_value_type() { if (this.token === ":") { return this.next().read_namespace_name(); } @@ -40,7 +40,7 @@ module.exports = { return null; }, - read_enum_case: function () { + read_enum_case() { this.expect(this.tok.T_CASE); const result = this.node("enumcase"); let caseName = this.node("identifier"); diff --git a/src/parser/expr.js b/src/parser/expr.js index 538fffdbd..db2cdb2c6 100644 --- a/src/parser/expr.js +++ b/src/parser/expr.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - read_expr: function (expr) { + read_expr(expr) { const result = this.node(); if (this.token === "@") { if (!expr) { @@ -148,28 +148,28 @@ module.exports = { /* * Reads a cast expression */ - read_expr_cast: function (type) { + read_expr_cast(type) { return this.node("cast")(type, this.text(), this.next().read_expr()); }, /* * Read a isset variable */ - read_isset_variable: function () { + read_isset_variable() { return this.read_expr(); }, /* * Reads isset variables */ - read_isset_variables: function () { + read_isset_variables() { return this.read_function_list(this.read_isset_variable, ","); }, /* * Reads internal PHP functions */ - read_internal_functions_in_yacc: function () { + read_internal_functions_in_yacc() { let result = null; switch (this.token) { case this.tok.T_ISSET: @@ -231,7 +231,7 @@ module.exports = { /* * Reads optional expression */ - read_optional_expr: function (stopToken) { + read_optional_expr(stopToken) { if (this.token !== stopToken) { return this.read_expr(); } @@ -242,7 +242,7 @@ module.exports = { /* * Reads exit expression */ - read_exit_expr: function () { + read_exit_expr() { let expression = null; if (this.token === "(") { @@ -260,7 +260,7 @@ module.exports = { * expr ::= @todo * ``` */ - read_expr_item: function () { + read_expr_item() { let result, expr, attrs = []; @@ -571,7 +571,7 @@ module.exports = { /* * Recursively convert nested array to nested list. */ - convertToList: function (array) { + convertToList(array) { const convertedItems = array.items.map((entry) => { if ( entry.value && @@ -593,7 +593,7 @@ module.exports = { * Reads assignment * @param {*} left */ - read_assignref: function (result, left) { + read_assignref(result, left) { this.next(); let right; if (this.token === this.tok.T_NEW) { @@ -623,7 +623,7 @@ module.exports = { * ((zend_ast_decl *) $$)->lex_pos = $10; * CG(extra_fn_flags) = $9; } * */ - read_inline_function: function (flags, attrs) { + read_inline_function(flags, attrs) { if (this.token === this.tok.T_FUNCTION) { const result = this.read_function(true, flags, attrs); result.attrGroups = attrs; @@ -666,7 +666,7 @@ module.exports = { return result; }, - read_match_expression: function () { + read_match_expression() { const node = this.node("match"); this.expect(this.tok.T_MATCH) && this.next(); if (this.version < 800) { @@ -683,18 +683,18 @@ module.exports = { return node(cond, arms); }, - read_match_arms: function () { + read_match_arms() { return this.read_list(() => this.read_match_arm(), ",", true); }, - read_match_arm: function () { + read_match_arm() { if (this.token === "}") { return; } return this.node("matcharm")(this.read_match_arm_conds(), this.read_expr()); }, - read_match_arm_conds: function () { + read_match_arm_conds() { let conds = []; if (this.token === this.tok.T_DEFAULT) { conds = null; @@ -750,7 +750,7 @@ module.exports = { * ``` * https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L850 */ - read_new_expr: function () { + read_new_expr() { const result = this.node("new"); this.expect(this.tok.T_NEW) && this.next(); let args = []; @@ -800,7 +800,7 @@ module.exports = { * read_new_class_name ::= namespace_name | variable * ``` */ - read_new_class_name: function () { + read_new_class_name() { if ( this.token === this.tok.T_NS_SEPARATOR || this.token === this.tok.T_NAME_RELATIVE || @@ -820,7 +820,7 @@ module.exports = { this.expect([this.tok.T_STRING, "VARIABLE"]); } }, - handleDereferencable: function (expr) { + handleDereferencable(expr) { while (this.token !== this.EOF) { if ( this.token === this.tok.T_OBJECT_OPERATOR || diff --git a/src/parser/function.js b/src/parser/function.js index 314eca2d4..2cde2d600 100644 --- a/src/parser/function.js +++ b/src/parser/function.js @@ -9,7 +9,7 @@ module.exports = { /* * checks if current token is a reference keyword */ - is_reference: function () { + is_reference() { if (this.token === "&") { this.next(); return true; @@ -19,7 +19,7 @@ module.exports = { /* * checks if current token is a variadic keyword */ - is_variadic: function () { + is_variadic() { if (this.token === this.tok.T_ELLIPSIS) { this.next(); return true; @@ -32,7 +32,7 @@ module.exports = { * function ::= function_declaration code_block * ``` */ - read_function: function (closure, flag, attrs, locStart) { + read_function(closure, flag, attrs, locStart) { const result = this.read_function_declaration( closure ? 1 : flag ? 2 : 0, flag && flag[1] === 1, @@ -64,7 +64,7 @@ module.exports = { * function_declaration ::= T_FUNCTION '&'? T_STRING '(' parameter_list ')' * ``` */ - read_function_declaration: function (type, isStatic, attrs, locStart) { + read_function_declaration(type, isStatic, attrs, locStart) { let nodeName = "function"; if (type === 1) { nodeName = "closure"; @@ -158,7 +158,7 @@ module.exports = { ); }, - read_lexical_vars: function () { + read_lexical_vars() { let result = []; if (this.token === this.tok.T_USE) { @@ -171,7 +171,7 @@ module.exports = { return result; }, - read_list_with_dangling_comma: function (item) { + read_list_with_dangling_comma(item) { const result = []; while (this.token != this.EOF) { @@ -191,7 +191,7 @@ module.exports = { return result; }, - read_lexical_var_list: function () { + read_lexical_var_list() { return this.read_list_with_dangling_comma(this.read_lexical_var.bind(this)); }, @@ -200,7 +200,7 @@ module.exports = { * lexical_var ::= '&'? T_VARIABLE * ``` */ - read_lexical_var: function () { + read_lexical_var() { if (this.token === "&") { return this.read_byref(this.read_lexical_var.bind(this)); } @@ -216,7 +216,7 @@ module.exports = { * parameter_list ::= (parameter ',')* parameter? * ``` */ - read_parameter_list: function (is_class_constructor) { + read_parameter_list(is_class_constructor) { if (this.token !== ")") { let wasVariadic = false; @@ -248,7 +248,7 @@ module.exports = { * ``` * @see https://github.com/php/php-src/blob/493524454d66adde84e00d249d607ecd540de99f/Zend/zend_language_parser.y#L640 */ - read_parameter: function (is_class_constructor) { + read_parameter(is_class_constructor) { const node = this.node("parameter"); let parameterName = null; let value = null; @@ -320,7 +320,7 @@ module.exports = { if (attrs) result.attrGroups = attrs; return result; }, - read_types: function () { + read_types() { const MODE_UNSET = "unset"; const MODE_UNION = "union"; const MODE_INTERSECTION = "intersection"; @@ -374,7 +374,7 @@ module.exports = { : this.node("uniontype")(types); } }, - read_promoted: function () { + read_promoted() { const MODIFIER_PUBLIC = 1; const MODIFIER_PROTECTED = 2; const MODIFIER_PRIVATE = 4; @@ -396,7 +396,7 @@ module.exports = { * function_argument_list ::= '(' (argument_list (',' argument_list)*)? ')' * ``` */ - read_argument_list: function () { + read_argument_list() { let result = []; this.expect("(") && this.next(); if ( @@ -415,7 +415,7 @@ module.exports = { /* * Reads non empty argument list */ - read_non_empty_argument_list: function () { + read_non_empty_argument_list() { let wasVariadic = false; return this.read_function_list( @@ -443,7 +443,7 @@ module.exports = { * argument_list ::= T_STRING ':' expr | T_ELLIPSIS? expr * ``` */ - read_argument: function () { + read_argument() { if (this.token === this.tok.T_ELLIPSIS) { return this.node("variadic")(this.next().read_expr()); } @@ -470,7 +470,7 @@ module.exports = { * type ::= T_ARRAY | T_CALLABLE | namespace_name * ``` */ - read_type: function () { + read_type() { const result = this.node(); if (this.token === this.tok.T_ARRAY || this.token === this.tok.T_CALLABLE) { const type = this.text(); diff --git a/src/parser/if.js b/src/parser/if.js index fda94ee19..915dabe1b 100644 --- a/src/parser/if.js +++ b/src/parser/if.js @@ -13,7 +13,7 @@ module.exports = { * if ::= T_IF '(' expr ')' ':' ... * ``` */ - read_if: function () { + read_if() { const result = this.node("if"); const test = this.next().read_if_expr(); let body = null; @@ -51,7 +51,7 @@ module.exports = { /* * reads an if expression : '(' expr ')' */ - read_if_expr: function () { + read_if_expr() { this.expect("(") && this.next(); const result = this.read_expr(); this.expect(")") && this.next(); @@ -60,7 +60,7 @@ module.exports = { /* * reads an elseif (expr): statements */ - read_elseif_short: function () { + read_elseif_short() { let alternate = null; const result = this.node("if"); const test = this.next().read_if_expr(); @@ -82,7 +82,7 @@ module.exports = { /* * */ - read_else_short: function () { + read_else_short() { if (this.next().expect(":")) this.next(); const body = this.node("block"); const items = []; diff --git a/src/parser/loops.js b/src/parser/loops.js index 62847a6b8..5824171ff 100644 --- a/src/parser/loops.js +++ b/src/parser/loops.js @@ -14,7 +14,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L587 * @return {While} */ - read_while: function () { + read_while() { const result = this.node("while"); this.expect(this.tok.T_WHILE) && this.next(); let test = null; @@ -39,7 +39,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L423 * @return {Do} */ - read_do: function () { + read_do() { const result = this.node("do"); this.expect(this.tok.T_DO) && this.next(); let test = null; @@ -63,7 +63,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L425 * @return {For} */ - read_for: function () { + read_for() { const result = this.node("for"); this.expect(this.tok.T_FOR) && this.next(); let init = []; @@ -106,7 +106,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L438 * @return {Foreach} */ - read_foreach: function () { + read_foreach() { const result = this.node("foreach"); this.expect(this.tok.T_FOREACH) && this.next(); let source = null; @@ -152,7 +152,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L544 * @return {Expression} */ - read_foreach_variable: function () { + read_foreach_variable() { if (this.token === this.tok.T_LIST || this.token === "[") { const isShort = this.token === "["; const result = this.node("list"); diff --git a/src/parser/main.js b/src/parser/main.js index 8b18dfff8..f83cb053e 100644 --- a/src/parser/main.js +++ b/src/parser/main.js @@ -11,7 +11,7 @@ module.exports = { * start ::= (namespace | top_statement)* * ``` */ - read_start: function () { + read_start() { if (this.token == this.tok.T_NAMESPACE) { return this.read_namespace(); } else { diff --git a/src/parser/namespace.js b/src/parser/namespace.js index 5f1e30431..4487f00b2 100644 --- a/src/parser/namespace.js +++ b/src/parser/namespace.js @@ -17,7 +17,7 @@ module.exports = { * @see http://php.net/manual/en/language.namespaces.php * @return {Namespace} */ - read_namespace: function () { + read_namespace() { const result = this.node("namespace"); let body; this.expect(this.tok.T_NAMESPACE) && this.next(); @@ -66,7 +66,7 @@ module.exports = { * @see http://php.net/manual/en/language.namespaces.rules.php * @return {Reference} */ - read_namespace_name: function (resolveReference) { + read_namespace_name(resolveReference) { const result = this.node(); let resolution; let name = this.text(); @@ -113,7 +113,7 @@ module.exports = { * @see http://php.net/manual/en/language.namespaces.importing.php * @return {UseGroup} */ - read_use_statement: function () { + read_use_statement() { let result = this.node("usegroup"); let items = []; let name = null; @@ -135,7 +135,7 @@ module.exports = { * * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1045 */ - read_class_name_reference: function () { + read_class_name_reference() { // resolved as the same return this.read_variable(true, false); }, @@ -147,7 +147,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L380 * @return {UseItem} */ - read_use_declaration: function (typed) { + read_use_declaration(typed) { const result = this.node("useitem"); let type = null; if (typed) type = this.read_use_type(); @@ -163,7 +163,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L380 * @return {UseItem[]} */ - read_use_declarations: function (typed) { + read_use_declarations(typed) { const result = [this.read_use_declaration(typed)]; while (this.token === ",") { this.next(); @@ -198,7 +198,7 @@ module.exports = { * ``` * @return {String|null} */ - read_use_alias: function () { + read_use_alias() { let result = null; if (this.token === this.tok.T_AS) { if (this.next().expect(this.tok.T_STRING)) { @@ -218,7 +218,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L335 * @return {String|null} Possible values : function, const */ - read_use_type: function () { + read_use_type() { if (this.token === this.tok.T_FUNCTION) { this.next(); return this.ast.useitem.TYPE_FUNCTION; diff --git a/src/parser/scalar.js b/src/parser/scalar.js index f8ccea1f6..39364473c 100644 --- a/src/parser/scalar.js +++ b/src/parser/scalar.js @@ -20,7 +20,7 @@ module.exports = { /* * Unescape special chars */ - resolve_special_chars: function (text, doubleQuote) { + resolve_special_chars(text, doubleQuote) { if (!doubleQuote) { // single quote fix return text.replace(/\\\\/g, "\\").replace(/\\'/g, "'"); @@ -50,7 +50,7 @@ module.exports = { * @param {boolean} indentation_uses_spaces * @param {boolean} first_encaps_node if it is behind a variable, the first N spaces should not be removed */ - remove_heredoc_leading_whitespace_chars: function ( + remove_heredoc_leading_whitespace_chars( text, indentation, indentation_uses_spaces, @@ -93,7 +93,7 @@ module.exports = { * @param {boolean} indentation_uses_spaces * @param {boolean} first_encaps_node if it is behind a variable, the first N spaces should not be removed */ - check_heredoc_indentation_level: function ( + check_heredoc_indentation_level( text, indentation, indentation_uses_spaces, @@ -153,7 +153,7 @@ module.exports = { /* * Reads dereferencable scalar */ - read_dereferencable_scalar: function () { + read_dereferencable_scalar() { let result = null; switch (this.token) { @@ -207,7 +207,7 @@ module.exports = { * | namespace_name (T_DOUBLE_COLON T_STRING)? * ``` */ - read_scalar: function () { + read_scalar() { if (this.is("T_MAGIC_CONST")) { return this.get_magic_constant(); } else { @@ -294,7 +294,7 @@ module.exports = { /* * Handles the dereferencing */ - read_dereferencable: function (expr) { + read_dereferencable(expr) { let result, offset; const node = this.node("offsetlookup"); if (this.token === "[") { @@ -322,7 +322,7 @@ module.exports = { * @return {String|Variable|Expr|Lookup} * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1219 */ - read_encapsed_string_item: function (isDoubleQuote) { + read_encapsed_string_item(isDoubleQuote) { const encapsedPart = this.node("encapsedpart"); let syntax = null; let curly = false; @@ -427,7 +427,7 @@ module.exports = { /* * Reads an encapsed string */ - read_encapsed_string: function (expect, isBinary = false) { + read_encapsed_string(expect, isBinary = false) { const labelStart = this.lexer.yylloc.first_offset; let node = this.node("encapsed"); this.next(); @@ -483,7 +483,7 @@ module.exports = { /* * Constant token */ - get_magic_constant: function () { + get_magic_constant() { const result = this.node("magic"); const name = this.text(); this.next(); diff --git a/src/parser/statement.js b/src/parser/statement.js index 09b8f7ddf..0d6c34e18 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -12,7 +12,7 @@ module.exports = { * top_statements ::= top_statement* * ``` */ - read_top_statements: function () { + read_top_statements() { let result = []; while (this.token !== this.EOF && this.token !== "}") { const statement = this.read_top_statement(); @@ -36,7 +36,7 @@ module.exports = { * | statement * ``` */ - read_top_statement: function () { + read_top_statement() { let attrs = []; if (this.token === this.tok.T_ATTRIBUTE) { attrs = this.read_attr_list(); @@ -84,7 +84,7 @@ module.exports = { * inner_statements ::= inner_statement* * ``` */ - read_inner_statements: function () { + read_inner_statements() { let result = []; while (this.token != this.EOF && this.token !== "}") { const statement = this.read_inner_statement(); @@ -104,7 +104,7 @@ module.exports = { * const_list ::= T_CONST T_STRING '=' expr (',' T_STRING '=' expr)* ';' * ``` */ - read_const_list: function () { + read_const_list() { return this.read_list( function () { this.expect(this.tok.T_STRING); @@ -131,7 +131,7 @@ module.exports = { * ``` * @retrurn {Array} */ - read_declare_list: function () { + read_declare_list() { const result = []; while (this.token != this.EOF && this.token !== ")") { this.expect(this.tok.T_STRING); @@ -156,7 +156,7 @@ module.exports = { * inner_statement ::= '{' inner_statements '}' | token * ``` */ - read_inner_statement: function () { + read_inner_statement() { let attrs = []; if (this.token === this.tok.T_ATTRIBUTE) { attrs = this.read_attr_list(); @@ -197,7 +197,7 @@ module.exports = { /* * Reads statements */ - read_statement: function () { + read_statement() { switch (this.token) { case "{": return this.read_code_block(false); @@ -425,7 +425,7 @@ module.exports = { * code_block ::= '{' (inner_statements | top_statements) '}' * ``` */ - read_code_block: function (top) { + read_code_block(top) { const result = this.node("block"); this.expect("{") && this.next(); const body = top diff --git a/src/parser/switch.js b/src/parser/switch.js index 07c1785e7..3da60686b 100644 --- a/src/parser/switch.js +++ b/src/parser/switch.js @@ -14,7 +14,7 @@ module.exports = { * @return {Switch} * @see http://php.net/manual/en/control-structures.switch.php */ - read_switch: function () { + read_switch() { const result = this.node("switch"); this.expect(this.tok.T_SWITCH) && this.next(); this.expect("(") && this.next(); @@ -30,7 +30,7 @@ module.exports = { * ``` * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L566 */ - read_switch_case_list: function () { + read_switch_case_list() { // DETECT SWITCH MODE let expect = null; const result = this.node("block"); @@ -71,7 +71,7 @@ module.exports = { * case_list ::= ((T_CASE expr) | T_DEFAULT) (':' | ';') inner_statement* * ``` */ - read_case_list: function (stopToken) { + read_case_list(stopToken) { const result = this.node("case"); let test = null; if (this.token === this.tok.T_CASE) { diff --git a/src/parser/try.js b/src/parser/try.js index 60c396116..7cccdad80 100644 --- a/src/parser/try.js +++ b/src/parser/try.js @@ -17,7 +17,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L448 * @return {Try} */ - read_try: function () { + read_try() { this.expect(this.tok.T_TRY); const result = this.node("try"); let always = null; diff --git a/src/parser/utils.js b/src/parser/utils.js index 73734fc54..a62ef5d9a 100644 --- a/src/parser/utils.js +++ b/src/parser/utils.js @@ -11,7 +11,7 @@ module.exports = { * @param {Number} token - The ending token * @return {Block} */ - read_short_form: function (token) { + read_short_form(token) { const body = this.node("block"); const items = []; /* istanbul ignore next */ @@ -37,7 +37,7 @@ module.exports = { * @param {*} item * @param {*} separator */ - read_function_list: function (item, separator) { + read_function_list(item, separator) { const result = []; do { if (this.token == separator && this.version >= 703 && result.length > 0) { @@ -61,7 +61,7 @@ module.exports = { * list ::= separator? ( item separator )* item * ``` */ - read_list: function (item, separator, preserveFirstSeparator) { + read_list(item, separator, preserveFirstSeparator) { const result = []; if (this.token == separator) { @@ -112,7 +112,7 @@ module.exports = { * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L726 * @return {Reference[]} */ - read_name_list: function () { + read_name_list() { return this.read_list(this.read_namespace_name, ",", false); }, @@ -120,7 +120,7 @@ module.exports = { * Reads the byref token and assign it to the specified node * @param {*} cb */ - read_byref: function (cb) { + read_byref(cb) { let byref = this.node("byref"); this.next(); byref = byref(null); @@ -147,7 +147,7 @@ module.exports = { * @return {StaticVariable[]} Returns an array composed by a list of variables, or * assign values */ - read_variable_declarations: function () { + read_variable_declarations() { return this.read_list(function () { const node = this.node("staticvariable"); let variable = this.node("variable"); @@ -171,7 +171,7 @@ module.exports = { /* * Reads class extends */ - read_extends_from: function () { + read_extends_from() { if (this.token === this.tok.T_EXTENDS) { return this.next().read_namespace_name(); } @@ -182,7 +182,7 @@ module.exports = { /* * Reads interface extends list */ - read_interface_extends_list: function () { + read_interface_extends_list() { if (this.token === this.tok.T_EXTENDS) { return this.next().read_name_list(); } @@ -193,7 +193,7 @@ module.exports = { /* * Reads implements list */ - read_implements_list: function () { + read_implements_list() { if (this.token === this.tok.T_IMPLEMENTS) { return this.next().read_name_list(); } diff --git a/src/parser/variable.js b/src/parser/variable.js index 4fd36d6d5..3036c7b33 100644 --- a/src/parser/variable.js +++ b/src/parser/variable.js @@ -22,7 +22,7 @@ module.exports = { * $var->func()->property // chained calls * ``` */ - read_variable: function (read_only, encapsed) { + read_variable(read_only, encapsed) { let result; // check the byref flag if (this.token === "&") { @@ -86,7 +86,7 @@ module.exports = { }, // resolves a static call - read_static_getter: function (what, encapsed) { + read_static_getter(what, encapsed) { const result = this.node("staticlookup"); let offset, name; if (this.next().is([this.tok.T_VARIABLE, "$"])) { @@ -117,7 +117,7 @@ module.exports = { return result(what, offset); }, - read_what: function (is_static_lookup = false) { + read_what(is_static_lookup = false) { let what = null; let name = null; switch (this.next().token) { @@ -170,7 +170,7 @@ module.exports = { return what; }, - recursive_variable_chain_scan: function (result, read_only, encapsed) { + recursive_variable_chain_scan(result, read_only, encapsed) { let node, offset; recursive_scan_loop: while (this.token != this.EOF) { switch (this.token) { @@ -244,7 +244,7 @@ module.exports = { /* * https://github.com/php/php-src/blob/493524454d66adde84e00d249d607ecd540de99f/Zend/zend_language_parser.y#L1231 */ - read_encaps_var_offset: function () { + read_encaps_var_offset() { let offset = this.node(); if (this.token === this.tok.T_STRING) { const text = this.text(); @@ -288,7 +288,7 @@ module.exports = { * $foo[123]{1}; // gets the 2nd char from the 123 array entry * */ - read_reference_variable: function (encapsed) { + read_reference_variable(encapsed) { let result = this.read_simple_variable(); let offset; while (this.token != this.EOF) { @@ -310,7 +310,7 @@ module.exports = { * simple_variable ::= T_VARIABLE | '$' '{' expr '}' | '$' simple_variable * ``` */ - read_simple_variable: function () { + read_simple_variable() { let result = this.node("variable"); let name; if ( diff --git a/test/benchmark2.js b/test/benchmark2.js deleted file mode 100644 index d03e6cee7..000000000 --- a/test/benchmark2.js +++ /dev/null @@ -1,18 +0,0 @@ -const parser = require("./main"); - -const code = ` -