Skip to content

feat(DEP0121): net._setSimultaneousAccepts()#278

Open
vespa7 wants to merge 6 commits intonodejs:mainfrom
vespa7:alex/DEP0121
Open

feat(DEP0121): net._setSimultaneousAccepts()#278
vespa7 wants to merge 6 commits intonodejs:mainfrom
vespa7:alex/DEP0121

Conversation

@vespa7
Copy link
Copy Markdown

@vespa7 vespa7 commented Nov 19, 2025

Closes #173

Comment thread package.json Outdated
Comment thread recipes/net-setSimultaneousAccepts-migration/README.md
Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test case for dynamic import

@vespa7
Copy link
Copy Markdown
Author

vespa7 commented Nov 19, 2025

Missing test case for dynamic import

Yes, it’s in draft. It doesn’t need to be corrected yet. I’m waiting for a question to be resolved.

@JakobJingleheimer
Copy link
Copy Markdown
Member

Yes, it’s in draft. It doesn’t need to be corrected yet. I’m waiting for a question to be resolved.

I don't see a question. Is it something we can help with? (Could you point us to it?)

@vespa7 vespa7 marked this pull request as ready for review November 20, 2025 13:50
@JakobJingleheimer JakobJingleheimer added the awaiting reviewer Author has responded and needs action from the reviewer label Nov 27, 2025
Comment thread package.json Outdated
"codemod",
"migrations",
"node.js"
"node.js"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"node.js"
"node.js"

@AugustinMauroy
Copy link
Copy Markdown
Member

What the current state of this pr ?

@vespa7
Copy link
Copy Markdown
Author

vespa7 commented Nov 28, 2025

What the current state of this pr ?

The PR is ready to be reviewed.

Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too bad, good job but there are serval part of the implementation that need to be discussed

@@ -0,0 +1,21 @@
schema_version: "1.0"
name: "@nodejs/net-setSimultaneousAccepts-migration"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "@nodejs/net-setSimultaneousAccepts-migration"
name: "@nodejs/net-setSimultaneousAccepts-deprecation"

#namingIsHard @nodejs/userland-migrations what do you think

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, the suggestion is more correct.

const linesToRemove: Range[] = [];

const netImportStatements = getAllNetImportStatements(root);
if (netImportStatements.length === 0) return null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (netImportStatements.length === 0) return null;
// If no import found we don't process the file
if (!netImportStatements.length) return null;

processNetImportStatement(rootNode, statement, linesToRemove, edits);
}

if (edits.length === 0 && linesToRemove.length === 0) return null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (edits.length === 0 && linesToRemove.length === 0) return null;
// If there aren't any change we don't try to modify something
if (!edits.length && !linesToRemove.length) return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "No changes, nothing to do" for the comment

Comment on lines +45 to +47
...getNodeImportStatements(root, 'node:net'),
...getNodeImportCalls(root, 'node:net'),
...getNodeRequireCalls(root, 'node:net'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...getNodeImportStatements(root, 'node:net'),
...getNodeImportCalls(root, 'node:net'),
...getNodeRequireCalls(root, 'node:net'),
...getNodeImportStatements(root, 'net'),
...getNodeImportCalls(root, 'net'),
...getNodeRequireCalls(root, 'net'),

the node: isn't needed theses functions catch it

Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts
/**
* Finds all _setSimultaneousAccepts() call expressions
*/
function findSetSimultaneousAcceptsCalls(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't valuable. You can "hardcode" this query in the parent functio

Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts Outdated
Comment on lines +154 to +171
for (const objDecl of objDeclarations) {
const objectLiterals = objDecl.findAll({ rule: { kind: 'object' } });

for (const obj of objectLiterals) {
const pairs = obj.findAll({ rule: { kind: 'pair' } });

for (const pair of pairs) {
const key = pair.child(0);
if (key?.text() === propertyName) {
const rangeWithComma = expandRangeToIncludeTrailingComma(
pair.range(),
rootNode.text()
);
linesToRemove.push(rangeWithComma);
}
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a loop that push to an array then iterate on this array to avoid 3th level of nested loop

Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts
Copy link
Copy Markdown
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It's a good first :)

I think this could use some additional test-cases that include more things happening from node:net to ensure they don't get broken.

Comment thread package.json Outdated
"codemod",
"migrations",
"node.js"
"node.js"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"node.js"
"node.js"

Comment on lines +12 to +15
const net = require("node:net");

-net._setSimultaneousAccepts(false);
const server = net.createServer();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const net = require("node:net");
-net._setSimultaneousAccepts(false);
const server = net.createServer();
const net = require("node:net");
- net._setSimultaneousAccepts(false);
const server = net.createServer();

processNetImportStatement(rootNode, statement, linesToRemove, edits);
}

if (edits.length === 0 && linesToRemove.length === 0) return null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "No changes, nothing to do" for the comment

Comment on lines +101 to +105
if (argKind === 'member_expression') {
handleMemberExpressionArgument(rootNode, argNode, linesToRemove);
} else if (argKind === 'identifier') {
handleIdentifierArgument(rootNode, argNode, linesToRemove);
}
Copy link
Copy Markdown
Member

@JakobJingleheimer JakobJingleheimer Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: switch makes it more clear that it's inspecting the same condition for each.

Suggested change
if (argKind === 'member_expression') {
handleMemberExpressionArgument(rootNode, argNode, linesToRemove);
} else if (argKind === 'identifier') {
handleIdentifierArgument(rootNode, argNode, linesToRemove);
}
switch(argKind) {
case 'member_expression': handleMemberExpressionArgument(rootNode, argNode, linesToRemove); break;
case 'identifier': handleIdentifierArgument(rootNode, argNode, linesToRemove); break;
}

Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts Outdated
Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts Outdated
@JakobJingleheimer JakobJingleheimer added awaiting author Reviewer has requested something from the author and removed awaiting reviewer Author has responded and needs action from the reviewer labels Dec 1, 2025
Comment thread recipes/net-setSimultaneousAccepts-migration/src/workflow.ts Outdated
@JakobJingleheimer JakobJingleheimer changed the title feat(net-setsimultaneousaccepts-migration): create recipe feat(DEP0121): net._setSimultaneousAccepts() Feb 22, 2026
Copy link
Copy Markdown
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I see there is some uncertainty (#173 (comment)) about the proper handling for this, so let's get someone from @nodejs/net to chime in before landing.

PS Sorry this took me a while to get back to.

Comment on lines +43 to +52
/**
* Collects all import/require statements for 'node:net'
*/
function getAllNetImportStatements(root: SgRoot<Js>): SgNode<Js>[] {
return [
...getNodeImportStatements(root, 'net'),
...getNodeImportCalls(root, 'net'),
...getNodeRequireCalls(root, 'net'),
];
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this PR was opened, we added this as a built-in utility: @nodejs/codemod-utils:getModuleDependencies

Comment on lines +28 to +35
const netImportStatements = getAllNetImportStatements(root);

// If no import found we don't process the file
if (!netImportStatements.length) return null;

for (const statement of netImportStatements) {
processNetImportStatement(rootNode, statement, linesToRemove, edits);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length check is unnecessary: getAllNetImportStatements (and @nodejs/codemod-utils:getModuleDependencies) always return an array, so the for…of won't break and will simply do nothing when the array is empty; then the check right after will handle aborting, affectively achieving the same thing with less code.

Suggested change
const netImportStatements = getAllNetImportStatements(root);
// If no import found we don't process the file
if (!netImportStatements.length) return null;
for (const statement of netImportStatements) {
processNetImportStatement(rootNode, statement, linesToRemove, edits);
}
for (const statement of getAllNetImportStatements(root)) {
processNetImportStatement(rootNode, statement, linesToRemove, edits);
}
Suggested change
const netImportStatements = getAllNetImportStatements(root);
// If no import found we don't process the file
if (!netImportStatements.length) return null;
for (const statement of netImportStatements) {
processNetImportStatement(rootNode, statement, linesToRemove, edits);
}
for (const statement of getModuleDependencies(root)) {
processNetImportStatement(rootNode, statement, linesToRemove, edits);
}

Comment on lines +1 to +5
import {
getNodeImportStatements,
getNodeImportCalls,
} from '@nodejs/codemod-utils/ast-grep/import-statement';
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (see below)

Suggested change
import {
getNodeImportStatements,
getNodeImportCalls,
} from '@nodejs/codemod-utils/ast-grep/import-statement';
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies';

Comment on lines +76 to +78
if (argNode) {
handleCallArgument(rootNode, argNode, linesToRemove);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if (argNode) {
handleCallArgument(rootNode, argNode, linesToRemove);
}
if (argNode) handleCallArgument(rootNode, argNode, linesToRemove);

Comment on lines +96 to +97
case 'member_expression': handleMemberExpressionArgument(rootNode, argNode, linesToRemove); break;
case 'identifier': handleIdentifierArgument(rootNode, argNode, linesToRemove); break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some extra indentation on the second case which at first glance makes it look like nested code.

A nit line-break for the break so it doesn't get (visually) lost and look like fall-through.

Suggested change
case 'member_expression': handleMemberExpressionArgument(rootNode, argNode, linesToRemove); break;
case 'identifier': handleIdentifierArgument(rootNode, argNode, linesToRemove); break;
case 'member_expression': handleMemberExpressionArgument(rootNode, argNode, linesToRemove);
break;
case 'identifier': handleIdentifierArgument(rootNode, argNode, linesToRemove);
break;

Comment on lines +180 to +182
index: endPos + 1,
column: range.end.column + 1
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (formatting/linting)

Suggested change
index: endPos + 1,
column: range.end.column + 1
}
column: range.end.column + 1,
index: endPos + 1,
},

Comment on lines +234 to +236
if (topLevelStatement) {
linesToRemove.push(topLevelStatement.range());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
if (topLevelStatement) {
linesToRemove.push(topLevelStatement.range());
}
if (topLevelStatement) linesToRemove.push(topLevelStatement.range());

Comment on lines +243 to +258
function findTopLevelStatement(node: SgNode<Js>): SgNode<Js> | null {
let current: SgNode<Js> | null = node;

while (current) {
const parent = current.parent();
if (!parent) break;

if (parent.kind() === 'program') {
return current;
}

current = parent;
}

return null;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified:

Suggested change
function findTopLevelStatement(node: SgNode<Js>): SgNode<Js> | null {
let current: SgNode<Js> | null = node;
while (current) {
const parent = current.parent();
if (!parent) break;
if (parent.kind() === 'program') {
return current;
}
current = parent;
}
return null;
}
function findTopLevelStatement(node: SgNode<Js>): SgNode<Js> | null {
let current: SgNode<Js> | null = node;
while (current = current.parent()) {
if (current?.kind() === 'program') return current;
}
return null;
}

I checked with a quick test:

function generateNode(kind) {
	let i = 1;
	return {
		parent() {
			if (i++ < 4) return {
				kind() { return kind },
			};
			return null;
		},
	};
}

findTopLevelStatement(generateNode('not-program'); // null
findTopLevelStatement(generateNode('program'); // { kind: 𝑓 }

Copy link
Copy Markdown
Member

@brunocroh brunocroh Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And alternative that I personally prefer is use a query, that one check if this is inside of a program independent of the level/distance

const program = match.find({
  rule: {
    inside: {
      kind: 'program',
      stopBy: 'end',
    },
  }
})

Comment thread package.json
"codemod",
"migrations",
"node.js"
"node.js"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"node.js"
"node.js"

@JakobJingleheimer
Copy link
Copy Markdown
Member

I asked @jasnell to take a look, and he said

looks reasonable

So I think we're g2g here

Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT !

Copy link
Copy Markdown
Member

@brunocroh brunocroh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JakobJingleheimer
Copy link
Copy Markdown
Member

@vespa7 CI is angry about package-lock. I'm not sure why.

Copilot AI review requested due to automatic review settings April 22, 2026 09:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new codemod recipe to remove deprecated net._setSimultaneousAccepts() calls (DEP0121) from JS/TS codebases, including fixture coverage for CommonJS, ESM, and dynamic imports.

Changes:

  • Introduce net-setSimultaneousAccepts-migration recipe (workflow, transform, metadata, README, and fixtures).
  • Add input/expected fixtures validating call removal and some unused-argument cleanup.
  • Register the new recipe in the repo’s lockfile and adjust root package.json formatting.

Reviewed changes

Copilot reviewed 35 out of 37 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
recipes/net-setSimultaneousAccepts-migration/workflow.yaml Workflow entry to run the new transform via js-ast-grep.
recipes/net-setSimultaneousAccepts-migration/src/workflow.ts Transform implementation removing _setSimultaneousAccepts calls and some related unused declarations/properties.
recipes/net-setSimultaneousAccepts-migration/tests/input/* New fixtures covering various import styles and call locations.
recipes/net-setSimultaneousAccepts-migration/tests/expected/* Expected outputs after the codemod runs.
recipes/net-setSimultaneousAccepts-migration/package.json Recipe package metadata and test script.
recipes/net-setSimultaneousAccepts-migration/codemod.yaml Codemod registry metadata for the recipe.
recipes/net-setSimultaneousAccepts-migration/README.md Usage/examples documentation for the recipe.
package.json Minor formatting change in keywords array.
package-lock.json Adds a linked workspace entry for the new recipe package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

},
"author": "Alejandro Espa",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setsimultaneousaccepts-migration/README.md",
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

homepage URL path has the same directory casing mismatch as repository.directory, so the generated link will 404. Update it to point at recipes/net-setSimultaneousAccepts-migration/README.md.

Suggested change
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setsimultaneousaccepts-migration/README.md",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setSimultaneousAccepts-migration/README.md",

Copilot uses AI. Check for mistakes.
if (expressionStatement) {
linesToRemove.push(expressionStatement.range());
} else {
edits.push(callNode.replace(''));
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When _setSimultaneousAccepts() appears in a non-statement context (e.g. initializer/argument), removeCallExpression falls back to callNode.replace(''), which can leave invalid syntax (e.g. const x = ; or fn(, y)). This needs a syntactically-safe replacement (e.g. void 0) or logic to remove/repair the surrounding construct instead of emitting an empty string.

Suggested change
edits.push(callNode.replace(''));
edits.push(callNode.replace('void 0'));

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is nonsense…

kind: 'pair',
has: {
field: 'key',
regex: propertyName,
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property removal matches object keys using regex: propertyName, which can accidentally match superset keys (e.g. port matches portNumber) and can misbehave if propertyName ever contains regex metacharacters. Prefer matching the key as a property_identifier with an anchored regex (^...$) or an exact pattern match.

Suggested change
regex: propertyName,
pattern: propertyName,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a good suggestion, but I'm not that familiar with JSSG. I see an example in the docs that seems to suggest this would work: https://docs.codemod.com/jssg/reference#basic-example

@brunocroh thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the documentation about it: https://ast-grep.github.io/guide/rule-config/atomic-rule.html#regex

Yeah, normally I try to suggest and use pattern instead of regex, but I’m experimenting with this scenario and for some reason, it isn’t working as intended. That’s fine, we can keep it this way for this case.

I’ll try to take a deeper dive into it; maybe it’s an issue on the codemod/ast-grep.

name: Apply AST Transformations
type: automatic
steps:
- name: Handle DEDEP0121 Remove net._setSimultaneousAccepts().
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step name has a typo in the deprecation identifier (DEDEP0121). This should be DEP0121 to match the Node.js deprecation code and the rest of the recipe metadata/searchability.

Copilot uses AI. Check for mistakes.
schema_version: "1.0"
name: "@nodejs/net-setSimultaneousAccepts-deprecation"
version: 1.0.0
description: "Handle DEDEP0121: Remove net._setSimultaneousAccepts()"
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codemod.yaml metadata has the same typo (DEDEP0121). Please change to DEP0121 so the recipe description is accurate and consistent with the Node.js deprecation identifier.

Suggested change
description: "Handle DEDEP0121: Remove net._setSimultaneousAccepts()"
description: "Handle DEP0121: Remove net._setSimultaneousAccepts()"

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +17
"directory": "recipes/net-setsimultaneousaccepts-migration",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Alejandro Espa",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setsimultaneousaccepts-migration/README.md",
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository.directory does not match this recipe’s actual folder path (recipes/net-setSimultaneousAccepts-migration). The current value uses a different casing (net-setsimultaneousaccepts-migration), which will produce broken links in npm/GitHub metadata.

Suggested change
"directory": "recipes/net-setsimultaneousaccepts-migration",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Alejandro Espa",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setsimultaneousaccepts-migration/README.md",
"directory": "recipes/net-setSimultaneousAccepts-migration",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Alejandro Espa",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/net-setSimultaneousAccepts-migration/README.md",

Copilot uses AI. Check for mistakes.
Comment thread package.json
"codemod",
"migrations",
"node.js"
"node.js"
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace after the "node.js" keyword entry will cause noisy diffs / potential lint failures. Please remove the extra space at end of the line.

Suggested change
"node.js"
"node.js"

Copilot uses AI. Check for mistakes.
Comment thread recipes/net-setSimultaneousAccepts-migration/codemod.yaml
Comment on lines +137 to +158
const pairs = rootNode
.findAll({
rule: {
kind: 'variable_declarator',
has: {
kind: 'identifier',
field: 'name',
pattern: objectName,
},
},
})
.flatMap((decl) =>
decl.findAll({
rule: {
kind: 'pair',
has: {
field: 'key',
regex: propertyName,
},
},
}),
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one can be simplified using relational rules, like inside.

https://ast-grep.github.io/guide/rule-config/relational-rule.html#relational-rules

	const pairs = rootNode.findAll({
		rule: {
			kind: 'pair',
			has: {
				field: 'key',
				regex: propertyName,
			},
			inside: {
				kind: 'variable_declarator',
				has: {
					kind: 'identifier',
					field: 'name',
					pattern: objectName,
				},
				stopBy: 'end',
			},
		},
	});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author Reviewer has requested something from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: handle net._setSimultaneousAccepts() deprecation

7 participants