Skip to content

Commit

Permalink
[Refactor] minor performance refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 16, 2023
1 parent 3cb966e commit ee6e1be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
6 changes: 3 additions & 3 deletions scripts/copyMetafiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const files = [
'.nycrc',
];

const directories = [
const directories = [].concat(
'memo-parser',
...resolverDirectories,
resolverDirectories,
'utils',
];
);

for (const directory of directories) {
for (const file of files) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const tsTypePrefix = 'type:';
*/
function isTypescriptFunctionOverloads(nodes) {
const nodesArr = Array.from(nodes);
const types = new Set(nodesArr.map(node => node.parent.type));

const idents = flatMap(nodesArr, (node) => (
node.declaration && (
Expand All @@ -51,6 +50,7 @@ function isTypescriptFunctionOverloads(nodes) {
return true;
}

const types = new Set(nodesArr.map(node => node.parent.type));
if (!types.has('TSDeclareFunction')) {
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions src/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ function getVariableNamesInScope(scopeManager, node) {
currentNode = currentNode.parent;
scope = scopeManager.acquire(currentNode, true);
}
return new Set([
...scope.variables.map(variable => variable.name),
...scope.upper.variables.map(variable => variable.name),
]);
return new Set(scope.variables.concat(scope.upper.variables).map(variable => variable.name));
}

/**
Expand Down
32 changes: 16 additions & 16 deletions tests/src/rules/consistent-type-specifier-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ context('TypeScript', () => {
},
});
ruleTester.run('consistent-type-specifier-style', rule, {
valid: [
...COMMON_TESTS.valid,
...TS_ONLY.valid,
],
invalid: [
...COMMON_TESTS.invalid,
...TS_ONLY.invalid,
],
valid: [].concat(
COMMON_TESTS.valid,
TS_ONLY.valid,
),
invalid: [].concat(
COMMON_TESTS.invalid,
TS_ONLY.invalid,
),
});
});

Expand All @@ -391,13 +391,13 @@ context('Babel/Flow', () => {
},
});
ruleTester.run('consistent-type-specifier-style', rule, {
valid: [
...COMMON_TESTS.valid,
...FLOW_ONLY.valid,
],
invalid: [
...COMMON_TESTS.invalid,
...FLOW_ONLY.invalid,
],
valid: [].concat(
COMMON_TESTS.valid,
FLOW_ONLY.valid,
),
invalid: [].concat(
COMMON_TESTS.invalid,
FLOW_ONLY.invalid,
),
});
});

0 comments on commit ee6e1be

Please sign in to comment.