Skip to content

Commit 7cf02c1

Browse files
authored
Merge pull request #5 from microsoft/connor4312/fix-copilot-parse
fix: replace estraverse with eslint keys
2 parents 35c8964 + eedcd33 commit 7cf02c1

4 files changed

Lines changed: 39 additions & 24 deletions

File tree

package-lock.json

Lines changed: 11 additions & 18 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Extension Test Runner",
44
"description": "Runs tests in VS Code extensions",
55
"publisher": "ms-vscode",
6-
"version": "0.0.3",
6+
"version": "0.0.4",
77
"icon": "icon.png",
88
"engines": {
99
"vscode": "^1.83.0"
@@ -102,7 +102,6 @@
102102
},
103103
"devDependencies": {
104104
"@types/chai": "^4.3.7",
105-
"@types/estraverse": "^5.1.4",
106105
"@types/estree": "^1.0.2",
107106
"@types/glob": "^8.1.0",
108107
"@types/mocha": "^10.0.2",
@@ -133,7 +132,7 @@
133132
"data-uri-to-buffer": "^6.0.1",
134133
"enhanced-resolve": "^5.15.0",
135134
"error-stack-parser": "^2.1.4",
136-
"estraverse": "^5.3.0",
135+
"eslint-visitor-keys": "^3.4.3",
137136
"minimatch": "^9.0.3",
138137
"split2": "^4.2.0",
139138
"stacktrace-parser": "^0.1.10"

src/extract/syntax.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Options } from 'acorn';
66
import { parse } from 'acorn-loose';
7-
import { traverse } from 'estraverse';
7+
import * as evk from 'eslint-visitor-keys';
88
import { Node } from 'estree';
99
import { IParsedNode, ITestSymbols, NodeKind } from '.';
1010

@@ -32,6 +32,30 @@ const getStringish = (nameArg: Node | undefined): string | undefined => {
3232
}
3333
};
3434

35+
const traverse = (
36+
node: Node,
37+
visitor: { enter: (node: Node) => void; leave: (node: Node) => void },
38+
) => {
39+
if (!node) {
40+
return;
41+
}
42+
visitor.enter(node);
43+
44+
const keys = evk.KEYS[node.type];
45+
if (keys) {
46+
for (const key of keys) {
47+
const child = (node as unknown as Record<string, Node | Node[]>)[key];
48+
if (child instanceof Array) {
49+
child.forEach((c) => traverse(c, visitor));
50+
} else if (child) {
51+
traverse(child, visitor);
52+
}
53+
}
54+
}
55+
56+
visitor.leave(node);
57+
};
58+
3559
export const extractWithAst = (text: string, symbols: ITestSymbols) => {
3660
const ast = parse(text, acornOptions);
3761

src/metadata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5-
import * as path from 'path';
65
import * as vscode from 'vscode';
76

87
export const enum ItemType {
@@ -46,7 +45,7 @@ export function* getContainingItemsForFile(
4645
const item = ctrl.createTestItem(
4746
filePath[i],
4847
filePath[i],
49-
uri.with({ path: filePath.slice(0, i + 1).join(path.sep) }),
48+
uri.with({ path: filePath.slice(0, i + 1).join('/') }),
5049
);
5150
item.tags = createOpts.tags;
5251
testMetadata.set(

0 commit comments

Comments
 (0)