Skip to content

Commit 6d500e4

Browse files
committed
using strip-comments
1 parent 64785ca commit 6d500e4

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@babel/code-frame": "^7.25.7",
9292
"@types/jest": "^29.5.13",
9393
"@types/semver": "^7.5.8",
94+
"@types/strip-comments": "^2.0.4",
9495
"@typescript-eslint/eslint-plugin": "^8.10.0",
9596
"@typescript-eslint/parser": "^8.10.0",
9697
"c8": "^9.1.0",
@@ -108,6 +109,7 @@
108109
"prettier": "^3.3.3",
109110
"proxyquire": "^2.1.3",
110111
"solc": "^0.8.28",
112+
"strip-comments": "^2.0.1",
111113
"ts-loader": "^9.5.1",
112114
"ts-node": "^10.9.2",
113115
"typescript": "^5.6.3",

src/slang-utils/infer-language.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { VersionExpressionSets as SlangVersionExpressionSets } from '@nomicfoundation/slang/ast';
1+
import { VersionExpressionSets } from '@nomicfoundation/slang/ast';
22
import { NonterminalKind, Query } from '@nomicfoundation/slang/cst';
33
import { Parser } from '@nomicfoundation/slang/parser';
4+
import strip from 'strip-comments';
45
import {
56
maxSatisfying,
67
minSatisfying,
@@ -9,7 +10,6 @@ import {
910
minVersion,
1011
validRange
1112
} from 'semver';
12-
import { VersionExpressionSets } from '../slang-nodes/VersionExpressionSets.js';
1313

1414
const supportedVersions = Parser.supportedVersions();
1515

@@ -60,14 +60,12 @@ function tryToCollectPragmas(text: string, version: string): string {
6060

6161
let match;
6262
while ((match = matches.next())) {
63-
const versionRange = new SlangVersionExpressionSets(
64-
match.captures.versionRanges[0].node.asNonterminalNode()!
65-
);
6663
ranges.push(
67-
// Replace all comments that could be in the expression with whitespace
68-
new VersionExpressionSets(versionRange, 0).comments.reduce(
69-
(range, comment) => range.replace(comment.value, ' '),
70-
versionRange.cst.unparse()
64+
strip(
65+
new VersionExpressionSets(
66+
match.captures.versionRanges[0].node.asNonterminalNode()!
67+
).cst.unparse(),
68+
{ keepProtected: true }
7169
)
7270
);
7371
}

0 commit comments

Comments
 (0)