From 54896e23e942bb0beb34a97ee6d8eac3411e7c66 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 8 Jan 2024 23:12:18 -0300 Subject: [PATCH 1/5] If requested, the parser will populate the comments as well --- package-lock.json | 183 +++++++++++++++----------- package.json | 8 +- src/ASTBuilder.ts | 15 +-- src/ast-types.ts | 35 +++-- src/parser.ts | 24 ++-- src/tokens.ts | 52 ++++++-- src/types.ts | 1 + test/comments.ts | 326 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 519 insertions(+), 125 deletions(-) create mode 100644 test/comments.ts diff --git a/package-lock.json b/package-lock.json index 7376d82..7b32b1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,9 @@ "devDependencies": { "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", - "@types/node": "^20.10.5", - "@typescript-eslint/eslint-plugin": "^6.15.0", - "@typescript-eslint/parser": "^6.15.0", + "@types/node": "^20.10.7", + "@typescript-eslint/eslint-plugin": "^6.18.0", + "@typescript-eslint/parser": "^6.18.0", "antlr4": "^4.13.1-patch-1", "assert": "^2.1.0", "chai": "^4.3.10", @@ -29,7 +29,7 @@ "mocha": "^10.2.0", "nyc": "^15.1.0", "prettier": "^3.1.1", - "puppeteer": "^21.6.1", + "puppeteer": "^21.7.0", "ts-node": "^10.9.2", "typescript": "^5.3.3", "util": "^0.12.5", @@ -773,9 +773,9 @@ } }, "node_modules/@puppeteer/browsers": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-1.9.0.tgz", - "integrity": "sha512-QwguOLy44YBGC8vuPP2nmpX4MUN2FzWbsnvZJtiCzecU3lHmVZkaC1tq6rToi9a200m8RzlVtDyxCS0UIDrxUg==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-1.9.1.tgz", + "integrity": "sha512-PuvK6xZzGhKPvlx3fpfdM2kYY3P/hB1URtK8wA7XUJ6prn6pp22zvJHu48th0SGcHL9SutbPHrFuQgfXTFobWA==", "dev": true, "dependencies": { "debug": "4.3.4", @@ -910,9 +910,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.10.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", - "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", + "version": "20.10.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.7.tgz", + "integrity": "sha512-fRbIKb8C/Y2lXxB5eVMj4IU7xpdox0Lh8bUPEdtLysaylsml1hOOx1+STloRs/B9nf7C6kPRmmg/V7aQW7usNg==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -935,16 +935,16 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.15.0.tgz", - "integrity": "sha512-j5qoikQqPccq9QoBAupOP+CBu8BaJ8BLjaXSioDISeTZkVO3ig7oSIKh3H+rEpee7xCXtWwSB4KIL5l6hWZzpg==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.0.tgz", + "integrity": "sha512-3lqEvQUdCozi6d1mddWqd+kf8KxmGq2Plzx36BlkjuQe3rSTm/O98cLf0A4uDO+a5N1KD2SeEEl6fW97YHY+6w==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.15.0", - "@typescript-eslint/type-utils": "6.15.0", - "@typescript-eslint/utils": "6.15.0", - "@typescript-eslint/visitor-keys": "6.15.0", + "@typescript-eslint/scope-manager": "6.18.0", + "@typescript-eslint/type-utils": "6.18.0", + "@typescript-eslint/utils": "6.18.0", + "@typescript-eslint/visitor-keys": "6.18.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -970,15 +970,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.15.0.tgz", - "integrity": "sha512-MkgKNnsjC6QwcMdlNAel24jjkEO/0hQaMDLqP4S9zq5HBAUJNQB6y+3DwLjX7b3l2b37eNAxMPLwb3/kh8VKdA==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.18.0.tgz", + "integrity": "sha512-v6uR68SFvqhNQT41frCMCQpsP+5vySy6IdgjlzUWoo7ALCnpaWYcz/Ij2k4L8cEsL0wkvOviCMpjmtRtHNOKzA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.15.0", - "@typescript-eslint/types": "6.15.0", - "@typescript-eslint/typescript-estree": "6.15.0", - "@typescript-eslint/visitor-keys": "6.15.0", + "@typescript-eslint/scope-manager": "6.18.0", + "@typescript-eslint/types": "6.18.0", + "@typescript-eslint/typescript-estree": "6.18.0", + "@typescript-eslint/visitor-keys": "6.18.0", "debug": "^4.3.4" }, "engines": { @@ -998,13 +998,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.15.0.tgz", - "integrity": "sha512-+BdvxYBltqrmgCNu4Li+fGDIkW9n//NrruzG9X1vBzaNK+ExVXPoGB71kneaVw/Jp+4rH/vaMAGC6JfMbHstVg==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.18.0.tgz", + "integrity": "sha512-o/UoDT2NgOJ2VfHpfr+KBY2ErWvCySNUIX/X7O9g8Zzt/tXdpfEU43qbNk8LVuWUT2E0ptzTWXh79i74PP0twA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.15.0", - "@typescript-eslint/visitor-keys": "6.15.0" + "@typescript-eslint/types": "6.18.0", + "@typescript-eslint/visitor-keys": "6.18.0" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1015,13 +1015,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.15.0.tgz", - "integrity": "sha512-CnmHKTfX6450Bo49hPg2OkIm/D/TVYV7jO1MCfPYGwf6x3GO0VU8YMO5AYMn+u3X05lRRxA4fWCz87GFQV6yVQ==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.18.0.tgz", + "integrity": "sha512-ZeMtrXnGmTcHciJN1+u2CigWEEXgy1ufoxtWcHORt5kGvpjjIlK9MUhzHm4RM8iVy6dqSaZA/6PVkX6+r+ChjQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.15.0", - "@typescript-eslint/utils": "6.15.0", + "@typescript-eslint/typescript-estree": "6.18.0", + "@typescript-eslint/utils": "6.18.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1042,9 +1042,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.15.0.tgz", - "integrity": "sha512-yXjbt//E4T/ee8Ia1b5mGlbNj9fB9lJP4jqLbZualwpP2BCQ5is6BcWwxpIsY4XKAhmdv3hrW92GdtJbatC6dQ==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.18.0.tgz", + "integrity": "sha512-/RFVIccwkwSdW/1zeMx3hADShWbgBxBnV/qSrex6607isYjj05t36P6LyONgqdUrNLl5TYU8NIKdHUYpFvExkA==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1055,16 +1055,17 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.15.0.tgz", - "integrity": "sha512-7mVZJN7Hd15OmGuWrp2T9UvqR2Ecg+1j/Bp1jXUEY2GZKV6FXlOIoqVDmLpBiEiq3katvj/2n2mR0SDwtloCew==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.0.tgz", + "integrity": "sha512-klNvl+Ql4NsBNGB4W9TZ2Od03lm7aGvTbs0wYaFYsplVPhr+oeXjlPZCDI4U9jgJIDK38W1FKhacCFzCC+nbIg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.15.0", - "@typescript-eslint/visitor-keys": "6.15.0", + "@typescript-eslint/types": "6.18.0", + "@typescript-eslint/visitor-keys": "6.18.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", + "minimatch": "9.0.3", "semver": "^7.5.4", "ts-api-utils": "^1.0.1" }, @@ -1081,18 +1082,42 @@ } } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@typescript-eslint/utils": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.15.0.tgz", - "integrity": "sha512-eF82p0Wrrlt8fQSRL0bGXzK5nWPRV2dYQZdajcfzOD9+cQz9O7ugifrJxclB+xVOvWvagXfqS4Es7vpLP4augw==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.18.0.tgz", + "integrity": "sha512-wiKKCbUeDPGaYEYQh1S580dGxJ/V9HI7K5sbGAVklyf+o5g3O+adnS4UNJajplF4e7z2q0uVBaTdT/yLb4XAVA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.15.0", - "@typescript-eslint/types": "6.15.0", - "@typescript-eslint/typescript-estree": "6.15.0", + "@typescript-eslint/scope-manager": "6.18.0", + "@typescript-eslint/types": "6.18.0", + "@typescript-eslint/typescript-estree": "6.18.0", "semver": "^7.5.4" }, "engines": { @@ -1107,12 +1132,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.15.0.tgz", - "integrity": "sha512-1zvtdC1a9h5Tb5jU9x3ADNXO9yjP8rXlaoChu0DQX40vf5ACVpYIVIZhIMZ6d5sDXH7vq4dsZBT1fEGj8D2n2w==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.0.tgz", + "integrity": "sha512-1wetAlSZpewRDb2h9p/Q8kRjdGuqdTAQbkJIOUMLug2LBLG+QOjiWoSj6/3B/hA9/tVTFFdtiKvAYoYnSRW/RA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.15.0", + "@typescript-eslint/types": "6.18.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1738,9 +1763,9 @@ ] }, "node_modules/chai": { - "version": "4.3.10", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz", - "integrity": "sha512-0UXG04VuVbruMUYbJ6JctvH0YnC/4q3/AkT18q4NaITo91CUm0liMS9VqzT9vZhVQ/1eqPanMWjBM+Juhfb/9g==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.0.tgz", + "integrity": "sha512-x9cHNq1uvkCdU+5xTkNh5WtgD4e4yDFCsp9jVc7N7qVeKeftv3gO/ZrviX5d+3ZfxdYnZXZYujjRInu1RogU6A==", "dev": true, "dependencies": { "assertion-error": "^1.1.0", @@ -1856,9 +1881,9 @@ } }, "node_modules/chromium-bidi": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.5.1.tgz", - "integrity": "sha512-dcCqOgq9fHKExc2R4JZs/oKbOghWpUNFAJODS8WKRtLhp3avtIH5UDCBrutdqZdh3pARogH8y1ObXm87emwb3g==", + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.5.2.tgz", + "integrity": "sha512-PbVOSddxgKyj+JByqavWMNqWPCoCaT6XK5Z1EFe168sxnB/BM51LnZEPXSbFcFAJv/+u2B4XNTs9uXxy4GW3cQ==", "dev": true, "dependencies": { "mitt": "3.0.1", @@ -3099,9 +3124,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -4476,12 +4501,12 @@ } }, "node_modules/loupe": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", - "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", "dev": true, "dependencies": { - "get-func-name": "^2.0.0" + "get-func-name": "^2.0.1" } }, "node_modules/lru-cache": { @@ -5519,15 +5544,15 @@ } }, "node_modules/puppeteer": { - "version": "21.6.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-21.6.1.tgz", - "integrity": "sha512-O+pbc61oj8ln6m8EJKncrsQFmytgRyFYERtk190PeLbJn5JKpmmynn2p1PiFrlhCitAQXLJ0MOy7F0TeyCRqBg==", + "version": "21.7.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-21.7.0.tgz", + "integrity": "sha512-Yy+UUy0b9siJezbhHO/heYUoZQUwyqDK1yOQgblTt0l97tspvDVFkcW9toBlnSvSfkDmMI3Dx9cZL6R8bDArHA==", "dev": true, "hasInstallScript": true, "dependencies": { - "@puppeteer/browsers": "1.9.0", + "@puppeteer/browsers": "1.9.1", "cosmiconfig": "8.3.6", - "puppeteer-core": "21.6.1" + "puppeteer-core": "21.7.0" }, "bin": { "puppeteer": "lib/esm/puppeteer/node/cli.js" @@ -5537,17 +5562,17 @@ } }, "node_modules/puppeteer-core": { - "version": "21.6.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-21.6.1.tgz", - "integrity": "sha512-0chaaK/RL9S1U3bsyR4fUeUfoj51vNnjWvXgG6DcsyMjwYNpLcAThv187i1rZCo7QhJP0wZN8plQkjNyrq2h+A==", + "version": "21.7.0", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-21.7.0.tgz", + "integrity": "sha512-elPYPozrgiM3phSy7VDUJCVWQ07SPnOm78fpSaaSNFoQx5sur/MqhTSro9Wz8lOEjqCykGC6WRkwxDgmqcy1dQ==", "dev": true, "dependencies": { - "@puppeteer/browsers": "1.9.0", - "chromium-bidi": "0.5.1", + "@puppeteer/browsers": "1.9.1", + "chromium-bidi": "0.5.2", "cross-fetch": "4.0.0", "debug": "4.3.4", "devtools-protocol": "0.0.1203626", - "ws": "8.15.1" + "ws": "8.16.0" }, "engines": { "node": ">=16.13.2" @@ -6917,9 +6942,9 @@ } }, "node_modules/ws": { - "version": "8.15.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.15.1.tgz", - "integrity": "sha512-W5OZiCjXEmk0yZ66ZN82beM5Sz7l7coYxpRkzS+p9PP+ToQry8szKh+61eNktr7EA9DOwvFGhfC605jDHbP6QQ==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", "dev": true, "engines": { "node": ">=10.0.0" diff --git a/package.json b/package.json index 06c536a..8d7386b 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,9 @@ "devDependencies": { "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", - "@types/node": "^20.10.5", - "@typescript-eslint/eslint-plugin": "^6.15.0", - "@typescript-eslint/parser": "^6.15.0", + "@types/node": "^20.10.7", + "@typescript-eslint/eslint-plugin": "^6.18.0", + "@typescript-eslint/parser": "^6.18.0", "antlr4": "^4.13.1-patch-1", "assert": "^2.1.0", "chai": "^4.3.10", @@ -63,7 +63,7 @@ "mocha": "^10.2.0", "nyc": "^15.1.0", "prettier": "^3.1.1", - "puppeteer": "^21.6.1", + "puppeteer": "^21.7.0", "ts-node": "^10.9.2", "typescript": "^5.3.3", "util": "^0.12.5", diff --git a/src/ASTBuilder.ts b/src/ASTBuilder.ts index fbe9d37..6e3fe05 100644 --- a/src/ASTBuilder.ts +++ b/src/ASTBuilder.ts @@ -4,17 +4,6 @@ import SolidityVisitor from './antlr/SolidityVisitor' import { ParseOptions } from './types' import * as AST from './ast-types' -interface SourceLocation { - start: { - line: number - column: number - } - end: { - line: number - column: number - } -} - interface WithMeta { __withMeta: never } @@ -1966,8 +1955,8 @@ export class ASTBuilder throw new Error('Assertion error: non-exhaustive stateMutability check') } - private _loc(ctx: ParserRuleContext): SourceLocation { - const sourceLocation: SourceLocation = { + private _loc(ctx: ParserRuleContext): AST.Location { + const sourceLocation: AST.Location = { start: { line: ctx.start.line, column: ctx.start.column, diff --git a/src/ast-types.ts b/src/ast-types.ts index 687a5f1..6b1006c 100644 --- a/src/ast-types.ts +++ b/src/ast-types.ts @@ -3,19 +3,36 @@ // Alex Browne // Xiao Liang -interface Location { - start: { - line: number - column: number - } - end: { - line: number - column: number - } +export interface Position { + line: number + column: number } +export interface Location { + start: Position + end: Position +} + +export interface BaseComment { + type: 'BlockComment' | 'LineComment' + value: string + range?: [number, number] + loc?: Location +} + +export interface BlockComment extends BaseComment { + type: 'BlockComment' +} + +export interface LineComment extends BaseComment { + type: 'LineComment' +} + +export type Comment = BlockComment | LineComment + export interface BaseASTNode { type: ASTNodeTypeString + comments?: Comment[] range?: [number, number] loc?: Location } diff --git a/src/parser.ts b/src/parser.ts index bdb7323..3e999bb 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -11,7 +11,7 @@ import { } from './ast-types' import { ASTBuilder } from './ASTBuilder' import ErrorListener from './ErrorListener' -import { buildTokenList } from './tokens' +import { buildCommentList, buildTokenList } from './tokens' import { ParseOptions, Token, TokenizeOptions } from './types' interface ParserErrorItem { @@ -69,26 +69,30 @@ export function parse(input: string, options: ParseOptions = {}): ParseResult { astBuilder.visit(sourceUnit) - const ast: ParseResult | null = astBuilder.result as any + const ast: ParseResult | null = astBuilder.result if (ast === null) { throw new Error('ast should never be null') } - let tokenList: Token[] = [] if (options.tokens === true) { - tokenList = buildTokenList(tokenStream.tokens, options) + ast.tokens = buildTokenList(tokenStream.tokens, options) } - if (options.tolerant !== true && listener.hasErrors()) { - throw new ParserError({ errors: listener.getErrors() }) + if (options.comments === true) { + ast.comments = buildCommentList( + tokenStream.tokens, + lexer.channelNames.indexOf('HIDDEN'), + options + ) } - if (options.tolerant === true && listener.hasErrors()) { + + if (listener.hasErrors()) { + if (options.tolerant !== true) { + throw new ParserError({ errors: listener.getErrors() }) + } ast.errors = listener.getErrors() } - if (options.tokens === true) { - ast.tokens = tokenList - } return ast } diff --git a/src/tokens.ts b/src/tokens.ts index 27d0efe..06c25a9 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -1,6 +1,7 @@ import { Token as AntlrToken } from 'antlr4' import { Token, TokenizeOptions } from './types' import { tokens } from './antlr/solidity-tokens' +import type { Comment, Location } from './ast-types' const TYPE_TOKENS = [ 'var', @@ -40,27 +41,58 @@ function getTokenType(value: string) { } } +function range(token: AntlrToken): [number, number] { + return [token.start, token.stop + 1] +} + +function loc(token: AntlrToken): Location { + const textInLines = token.text?.split(/\r?\n/) ?? [''] + const numberOfNewLines = textInLines.length - 1 + return { + start: { line: token.line, column: token.column }, + end: { + line: token.line + numberOfNewLines, + column: + textInLines[numberOfNewLines].length + + (numberOfNewLines === 0 ? token.column : 0), + }, + } +} + export function buildTokenList( tokensArg: AntlrToken[], options: TokenizeOptions ): Token[] { - const result = tokensArg.map((token) => { + return tokensArg.map((token) => { const type = getTokenType(tokens[token.type.toString()]) const node: Token = { type, value: token.text } if (options.range === true) { - node.range = [token.start, token.stop + 1] + node.range = range(token) } if (options.loc === true) { - node.loc = { - start: { line: token.line, column: token.column }, - end: { - line: token.line, - column: token.column + (token.text?.length ?? 0), - }, - } + node.loc = loc(token) } return node }) +} - return result +export function buildCommentList( + tokensArg: AntlrToken[], + commentsChannelId: number, + options: TokenizeOptions +): Comment[] { + return tokensArg + .filter((token) => token.channel === commentsChannelId) + .map((token) => { + const comment: Comment = token.text.startsWith('//') + ? { type: 'LineComment', value: token.text.slice(2) } + : { type: 'BlockComment', value: token.text.slice(2, -2) } + if (options.range === true) { + comment.range = range(token) + } + if (options.loc === true) { + comment.loc = loc(token) + } + return comment + }) } diff --git a/src/types.ts b/src/types.ts index e2c650b..dbca2fc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,6 +8,7 @@ export interface TokenizeOptions { } export interface ParseOptions extends TokenizeOptions { + comments?: boolean tokens?: boolean tolerant?: boolean } diff --git a/test/comments.ts b/test/comments.ts new file mode 100644 index 0000000..fee352b --- /dev/null +++ b/test/comments.ts @@ -0,0 +1,326 @@ +import { assert } from 'chai' +import * as parser from '../src/index' + +describe('Comments', () => { + it('LineComment', function () { + const ast: any = parser.parse('// LineComment', { comments: true }) + assert.deepEqual(ast.comments, [ + { type: 'LineComment', value: ' LineComment' }, + ]) + }) + + it('LineComment with Location and Range', function () { + const ast: any = parser.parse('// LineComment', { + comments: true, + loc: true, + range: true, + }) + assert.deepEqual(ast.comments, [ + { + type: 'LineComment', + value: ' LineComment', + range: [0, 14], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 14 }, + }, + }, + ]) + }) + + it('LineComment within a LineComment', function () { + const ast: any = parser.parse('// LineComment // LineComment', { + comments: true, + loc: true, + range: true, + }) + assert.deepEqual(ast.comments, [ + { + type: 'LineComment', + value: ' LineComment // LineComment', + range: [0, 29], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 29 }, + }, + }, + ]) + }) + + it('BlockComment within a LineComment', function () { + const ast: any = parser.parse('// LineComment /* BlockComment */', { + comments: true, + loc: true, + range: true, + }) + assert.deepEqual(ast.comments, [ + { + type: 'LineComment', + value: ' LineComment /* BlockComment */', + range: [0, 33], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 33 }, + }, + }, + ]) + }) + + it('LineComment within a contract', function () { + const ast: any = parser.parse( + `contract test { + // + // LineComment + // +}`, + { + comments: true, + loc: true, + range: true, + } + ) + assert.deepEqual(ast.comments, [ + { + type: 'LineComment', + value: '', + range: [20, 22], + loc: { + start: { line: 2, column: 4 }, + end: { line: 2, column: 6 }, + }, + }, + { + type: 'LineComment', + value: ' LineComment', + range: [27, 41], + loc: { + start: { line: 3, column: 4 }, + end: { line: 3, column: 18 }, + }, + }, + { + type: 'LineComment', + value: '', + range: [46, 48], + loc: { + start: { line: 4, column: 4 }, + end: { line: 4, column: 6 }, + }, + }, + ]) + }) + + it('BlockComment', function () { + const ast: any = parser.parse('/* BlockComment */', { comments: true }) + assert.deepEqual(ast.comments, [ + { + type: 'BlockComment', + value: ' BlockComment ', + }, + ]) + }) + + it('BlockComment with Location and Range', function () { + const ast: any = parser.parse('/* BlockComment */', { + comments: true, + loc: true, + range: true, + }) + assert.deepEqual(ast.comments, [ + { + type: 'BlockComment', + value: ' BlockComment ', + range: [0, 18], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 18 }, + }, + }, + ]) + }) + + it('LineComment within a BlockComment', function () { + const ast: any = parser.parse( + `/* + BlockComment + // LineComment +*/`, + { + comments: true, + loc: true, + range: true, + } + ) + assert.deepEqual(ast.comments, [ + { + type: 'BlockComment', + value: '\n BlockComment\n // LineComment\n', + range: [0, 37], + loc: { + start: { line: 1, column: 0 }, + end: { line: 4, column: 2 }, + }, + }, + ]) + }) + + it('BlockComment within a contract', function () { + const ast: any = parser.parse( + `contract test { + /* + * BlockComment + */ +}`, + { + comments: true, + loc: true, + range: true, + } + ) + assert.deepEqual(ast.comments, [ + { + type: 'BlockComment', + value: '\n * BlockComment\n ', + range: [20, 50], + loc: { + start: { line: 2, column: 4 }, + end: { line: 4, column: 7 }, + }, + }, + ]) + }) + + it('Multiple Comments within a contract', function () { + const ast: any = parser.parse( + `pragma solidity ^0.4.24; + +/** + * @title Just for comments + * @author Klaus Hott + */ +contract Comments { + /* solhint-disable var-name-mixedcase */ +IEIP712DomainSeparator private EIP712domainSeparator; // Trailing Comment +/* solhint-enable var-name-mixedcase */ + + /// @notice Does nothing + /// @dev just to show comments + function() { + // solhint-disable-previous-line no-empty-blocks + } /* + * comment trailing function + */ /* + * BlockComment trailing BlockComment + */ +}/* +* comment trailing function +*/ // LineComment trailing BlockComment`, + { + comments: true, + loc: true, + range: true, + } + ) + assert.deepEqual(ast.comments, [ + { + type: 'BlockComment', + value: '*\n * @title Just for comments\n * @author Klaus Hott\n ', + range: [26, 83], + loc: { + start: { line: 3, column: 0 }, + end: { line: 6, column: 3 }, + }, + }, + { + type: 'BlockComment', + value: ' solhint-disable var-name-mixedcase ', + range: [106, 146], + loc: { + start: { line: 8, column: 2 }, + end: { line: 8, column: 42 }, + }, + }, + { + type: 'LineComment', + value: ' Trailing Comment', + range: [201, 220], + loc: { + start: { line: 9, column: 54 }, + end: { line: 9, column: 73 }, + }, + }, + { + type: 'BlockComment', + value: ' solhint-enable var-name-mixedcase ', + range: [221, 260], + loc: { + start: { line: 10, column: 0 }, + end: { line: 10, column: 39 }, + }, + }, + { + type: 'LineComment', + value: '/ @notice Does nothing', + range: [266, 290], + loc: { + start: { line: 12, column: 4 }, + end: { line: 12, column: 28 }, + }, + }, + { + type: 'LineComment', + value: '/ @dev just to show comments', + range: [295, 325], + loc: { + start: { line: 13, column: 4 }, + end: { line: 13, column: 34 }, + }, + }, + { + type: 'LineComment', + value: ' solhint-disable-previous-line no-empty-blocks', + range: [351, 399], + loc: { + start: { line: 15, column: 8 }, + end: { line: 15, column: 56 }, + }, + }, + { + type: 'BlockComment', + value: '\n * comment trailing function\n ', + range: [406, 453], + loc: { + start: { line: 16, column: 6 }, + end: { line: 18, column: 9 }, + }, + }, + { + type: 'BlockComment', + value: '\n * BlockComment trailing BlockComment\n ', + range: [454, 510], + loc: { + start: { line: 18, column: 10 }, + end: { line: 20, column: 9 }, + }, + }, + { + type: 'BlockComment', + value: '\n* comment trailing function\n', + range: [512, 545], + loc: { + start: { line: 21, column: 1 }, + end: { line: 23, column: 2 }, + }, + }, + { + type: 'LineComment', + value: ' LineComment trailing BlockComment', + range: [546, 582], + loc: { + start: { line: 23, column: 3 }, + end: { line: 23, column: 39 }, + }, + }, + ]) + }) +}) From 9a15c2ec7a0e274700876044136080c52c58eeb5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 9 Jan 2024 19:22:44 -0300 Subject: [PATCH 2/5] updating dependencies --- package-lock.json | 96 +++++++++++++++++++++++------------------------ package.json | 6 +-- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7b32b1a..8f10ce2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,9 @@ "devDependencies": { "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", - "@types/node": "^20.10.7", - "@typescript-eslint/eslint-plugin": "^6.18.0", - "@typescript-eslint/parser": "^6.18.0", + "@types/node": "^20.11.0", + "@typescript-eslint/eslint-plugin": "^6.18.1", + "@typescript-eslint/parser": "^6.18.1", "antlr4": "^4.13.1-patch-1", "assert": "^2.1.0", "chai": "^4.3.10", @@ -910,9 +910,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.10.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.7.tgz", - "integrity": "sha512-fRbIKb8C/Y2lXxB5eVMj4IU7xpdox0Lh8bUPEdtLysaylsml1hOOx1+STloRs/B9nf7C6kPRmmg/V7aQW7usNg==", + "version": "20.11.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.0.tgz", + "integrity": "sha512-o9bjXmDNcF7GbM4CNQpmi+TutCgap/K3w1JyKgxAjqx41zp9qlIAVFi0IhCNsJcXolEqLWhbFbEeL0PvYm4pcQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -935,16 +935,16 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.0.tgz", - "integrity": "sha512-3lqEvQUdCozi6d1mddWqd+kf8KxmGq2Plzx36BlkjuQe3rSTm/O98cLf0A4uDO+a5N1KD2SeEEl6fW97YHY+6w==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.1.tgz", + "integrity": "sha512-nISDRYnnIpk7VCFrGcu1rnZfM1Dh9LRHnfgdkjcbi/l7g16VYRri3TjXi9Ir4lOZSw5N/gnV/3H7jIPQ8Q4daA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.18.0", - "@typescript-eslint/type-utils": "6.18.0", - "@typescript-eslint/utils": "6.18.0", - "@typescript-eslint/visitor-keys": "6.18.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/type-utils": "6.18.1", + "@typescript-eslint/utils": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -970,15 +970,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.18.0.tgz", - "integrity": "sha512-v6uR68SFvqhNQT41frCMCQpsP+5vySy6IdgjlzUWoo7ALCnpaWYcz/Ij2k4L8cEsL0wkvOviCMpjmtRtHNOKzA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.18.1.tgz", + "integrity": "sha512-zct/MdJnVaRRNy9e84XnVtRv9Vf91/qqe+hZJtKanjojud4wAVy/7lXxJmMyX6X6J+xc6c//YEWvpeif8cAhWA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.18.0", - "@typescript-eslint/types": "6.18.0", - "@typescript-eslint/typescript-estree": "6.18.0", - "@typescript-eslint/visitor-keys": "6.18.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4" }, "engines": { @@ -998,13 +998,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.18.0.tgz", - "integrity": "sha512-o/UoDT2NgOJ2VfHpfr+KBY2ErWvCySNUIX/X7O9g8Zzt/tXdpfEU43qbNk8LVuWUT2E0ptzTWXh79i74PP0twA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.18.1.tgz", + "integrity": "sha512-BgdBwXPFmZzaZUuw6wKiHKIovms97a7eTImjkXCZE04TGHysG+0hDQPmygyvgtkoB/aOQwSM/nWv3LzrOIQOBw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.0", - "@typescript-eslint/visitor-keys": "6.18.0" + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1015,13 +1015,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.18.0.tgz", - "integrity": "sha512-ZeMtrXnGmTcHciJN1+u2CigWEEXgy1ufoxtWcHORt5kGvpjjIlK9MUhzHm4RM8iVy6dqSaZA/6PVkX6+r+ChjQ==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.18.1.tgz", + "integrity": "sha512-wyOSKhuzHeU/5pcRDP2G2Ndci+4g653V43gXTpt4nbyoIOAASkGDA9JIAgbQCdCkcr1MvpSYWzxTz0olCn8+/Q==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.18.0", - "@typescript-eslint/utils": "6.18.0", + "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/utils": "6.18.1", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1042,9 +1042,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.18.0.tgz", - "integrity": "sha512-/RFVIccwkwSdW/1zeMx3hADShWbgBxBnV/qSrex6607isYjj05t36P6LyONgqdUrNLl5TYU8NIKdHUYpFvExkA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.18.1.tgz", + "integrity": "sha512-4TuMAe+tc5oA7wwfqMtB0Y5OrREPF1GeJBAjqwgZh1lEMH5PJQgWgHGfYufVB51LtjD+peZylmeyxUXPfENLCw==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1055,13 +1055,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.0.tgz", - "integrity": "sha512-klNvl+Ql4NsBNGB4W9TZ2Od03lm7aGvTbs0wYaFYsplVPhr+oeXjlPZCDI4U9jgJIDK38W1FKhacCFzCC+nbIg==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.1.tgz", + "integrity": "sha512-fv9B94UAhywPRhUeeV/v+3SBDvcPiLxRZJw/xZeeGgRLQZ6rLMG+8krrJUyIf6s1ecWTzlsbp0rlw7n9sjufHA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.0", - "@typescript-eslint/visitor-keys": "6.18.0", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1107,17 +1107,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.18.0.tgz", - "integrity": "sha512-wiKKCbUeDPGaYEYQh1S580dGxJ/V9HI7K5sbGAVklyf+o5g3O+adnS4UNJajplF4e7z2q0uVBaTdT/yLb4XAVA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.18.1.tgz", + "integrity": "sha512-zZmTuVZvD1wpoceHvoQpOiewmWu3uP9FuTWo8vqpy2ffsmfCE8mklRPi+vmnIYAIk9t/4kOThri2QCDgor+OpQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.18.0", - "@typescript-eslint/types": "6.18.0", - "@typescript-eslint/typescript-estree": "6.18.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/typescript-estree": "6.18.1", "semver": "^7.5.4" }, "engines": { @@ -1132,12 +1132,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.0.tgz", - "integrity": "sha512-1wetAlSZpewRDb2h9p/Q8kRjdGuqdTAQbkJIOUMLug2LBLG+QOjiWoSj6/3B/hA9/tVTFFdtiKvAYoYnSRW/RA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.1.tgz", + "integrity": "sha512-/kvt0C5lRqGoCfsbmm7/CwMqoSkY3zzHLIjdhHZQW3VFrnz7ATecOHR7nb7V+xn4286MBxfnQfQhAmCI0u+bJA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.18.0", + "@typescript-eslint/types": "6.18.1", "eslint-visitor-keys": "^3.4.1" }, "engines": { diff --git a/package.json b/package.json index 8d7386b..9dc01ff 100644 --- a/package.json +++ b/package.json @@ -45,9 +45,9 @@ "devDependencies": { "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", - "@types/node": "^20.10.7", - "@typescript-eslint/eslint-plugin": "^6.18.0", - "@typescript-eslint/parser": "^6.18.0", + "@types/node": "^20.11.0", + "@typescript-eslint/eslint-plugin": "^6.18.1", + "@typescript-eslint/parser": "^6.18.1", "antlr4": "^4.13.1-patch-1", "assert": "^2.1.0", "chai": "^4.3.10", From 7f1b564b60e3fc4d3f7995339ba719e1791850b0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jan 2024 17:23:13 -0300 Subject: [PATCH 3/5] adding change to the changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32791f5..60c5e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased + +- Parser function now has an option to return comments as part of the parsed result. (#105) + # 0.17.0 - Using the official typescript target for antlr4. (#103) From 95bcea2f3e8eb319ebd6fe03f7cb87be419ac336 Mon Sep 17 00:00:00 2001 From: Klaus Hott Vidal Date: Thu, 11 Jan 2024 12:38:30 -0300 Subject: [PATCH 4/5] Update src/tokens.ts Co-authored-by: Franco Victorio --- src/tokens.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tokens.ts b/src/tokens.ts index 06c25a9..6b75ce9 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -46,7 +46,8 @@ function range(token: AntlrToken): [number, number] { } function loc(token: AntlrToken): Location { - const textInLines = token.text?.split(/\r?\n/) ?? [''] + const tokenText = token.text ?? '' + const textInLines = tokenText.split(/\r?\n/) const numberOfNewLines = textInLines.length - 1 return { start: { line: token.line, column: token.column }, From 000440588dc164736e22b5b992a4c4ef8cc39d6a Mon Sep 17 00:00:00 2001 From: Klaus Hott Vidal Date: Thu, 11 Jan 2024 15:34:30 -0300 Subject: [PATCH 5/5] Update src/ast-types.ts Co-authored-by: Franco Victorio --- src/ast-types.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/ast-types.ts b/src/ast-types.ts index 6b1006c..d12cd73 100644 --- a/src/ast-types.ts +++ b/src/ast-types.ts @@ -13,23 +13,13 @@ export interface Location { end: Position } -export interface BaseComment { +export interface Comment { type: 'BlockComment' | 'LineComment' value: string range?: [number, number] loc?: Location } -export interface BlockComment extends BaseComment { - type: 'BlockComment' -} - -export interface LineComment extends BaseComment { - type: 'LineComment' -} - -export type Comment = BlockComment | LineComment - export interface BaseASTNode { type: ASTNodeTypeString comments?: Comment[]