Skip to content

Commit

Permalink
fix: replace estraverse with eslint keys
Browse files Browse the repository at this point in the history
Fixes parsing failing in copilot due to a lack of static blocks (estools/estraverse#120)
  • Loading branch information
connor4312 committed Oct 27, 2023
1 parent 35c8964 commit 3266a67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
25 changes: 9 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
},
"devDependencies": {
"@types/chai": "^4.3.7",
"@types/estraverse": "^5.1.4",
"@types/estree": "^1.0.2",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.2",
Expand Down Expand Up @@ -133,7 +132,7 @@
"data-uri-to-buffer": "^6.0.1",
"enhanced-resolve": "^5.15.0",
"error-stack-parser": "^2.1.4",
"estraverse": "^5.3.0",
"eslint-visitor-keys": "^3.4.3",
"minimatch": "^9.0.3",
"split2": "^4.2.0",
"stacktrace-parser": "^0.1.10"
Expand Down
26 changes: 25 additions & 1 deletion src/extract/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { Options } from 'acorn';
import { parse } from 'acorn-loose';
import { traverse } from 'estraverse';
import * as evk from 'eslint-visitor-keys';
import { Node } from 'estree';
import { IParsedNode, ITestSymbols, NodeKind } from '.';

Expand Down Expand Up @@ -32,6 +32,30 @@ const getStringish = (nameArg: Node | undefined): string | undefined => {
}
};

const traverse = (
node: Node,
visitor: { enter: (node: Node) => void; leave: (node: Node) => void },
) => {
if (!node) {
return;
}
visitor.enter(node);

const keys = evk.KEYS[node.type];
if (keys) {
for (const key of keys) {
const child = (node as unknown as Record<string, Node | Node[]>)[key];
if (child instanceof Array) {
child.forEach((c) => traverse(c, visitor));
} else if (child) {
traverse(child, visitor);
}
}
}

visitor.leave(node);
};

export const extractWithAst = (text: string, symbols: ITestSymbols) => {
const ast = parse(text, acornOptions);

Expand Down
3 changes: 1 addition & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as path from 'path';
import * as vscode from 'vscode';

export const enum ItemType {
Expand Down Expand Up @@ -46,7 +45,7 @@ export function* getContainingItemsForFile(
const item = ctrl.createTestItem(
filePath[i],
filePath[i],
uri.with({ path: filePath.slice(0, i + 1).join(path.sep) }),
uri.with({ path: filePath.slice(0, i + 1).join('/') }),
);
item.tags = createOpts.tags;
testMetadata.set(
Expand Down

0 comments on commit 3266a67

Please sign in to comment.