Skip to content

Commit

Permalink
fixup! tools: fix bug in prefer-primordials ESLint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 27, 2021
1 parent 899670a commit c73865c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/parallel/test-eslint-prefer-primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ new RuleTester({
code: 'const { Map } = primordials; new Map()',
options: [{ name: 'Map', into: 'Safe' }],
},
{
code: `
const { Function } = primordials;
const rename = Function;
const obj = { rename };
`,
options: [{ name: 'Function' }],
},
],
invalid: [
{
Expand Down
3 changes: 2 additions & 1 deletion tools/eslint-rules/prefer-primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ module.exports = {
const defs = globalScope.set.get(name)?.defs;
if (parentName && isTarget(nameMap, parentName)) {
if (defs?.[0].name.name !== 'primordials' &&
!reported.has(parent.range[0])) {
!reported.has(parent.range[0]) &&
parent.parent?.id?.type !== 'Identifier') {
reported.add(node.range[0]);
const into = renameMap.get(name);
context.report({
Expand Down

0 comments on commit c73865c

Please sign in to comment.