Skip to content

Commit

Permalink
lib, tools: remove duplicate requires
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Sep 15, 2024
1 parent cb99bcf commit 51d2a72
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
12 changes: 3 additions & 9 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const {
kDeserialize,
kTransfer,
kTransferList,
markTransferMode,
} = require('internal/worker/js_transferable');

let _MessageChannel;
let markTransferMode;

const kDontThrowSymbol = Symbol('kDontThrowSymbol');

Expand All @@ -82,12 +82,6 @@ function lazyMessageChannel() {
return new _MessageChannel();
}

function lazyMarkTransferMode(obj, cloneable, transferable) {
markTransferMode ??=
require('internal/worker/js_transferable').markTransferMode;
markTransferMode(obj, cloneable, transferable);
}

const clearTimeoutRegistry = new SafeFinalizationRegistry(clearTimeout);
const gcPersistentSignals = new SafeSet();

Expand Down Expand Up @@ -168,7 +162,7 @@ class AbortSignal extends EventTarget {
this[kReason] = reason;
this[kComposite] = composite;
if (transferable) {
lazyMarkTransferMode(this, false, true);
markTransferMode(this, false, true);
}
}

Expand Down Expand Up @@ -425,7 +419,7 @@ class AbortController {
function transferableAbortSignal(signal) {
if (signal?.[kAborted] === undefined)
throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal);
lazyMarkTransferMode(signal, false, true);
markTransferMode(signal, false, true);
return signal;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const {
setHasStartedUserCJSExecution,
stripBOM,
toRealPath,
stripTypeScriptTypes,
} = require('internal/modules/helpers');
const packageJsonReader = require('internal/modules/package_json_reader');
const { getOptionValue, getEmbedderOptions } = require('internal/options');
Expand Down Expand Up @@ -1362,7 +1363,6 @@ function loadESMFromCJS(mod, filename) {
if (isUnderNodeModules(filename)) {
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
}
const { stripTypeScriptTypes } = require('internal/modules/helpers');
source = stripTypeScriptTypes(source, filename);
}
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
Expand Down Expand Up @@ -1576,7 +1576,6 @@ function loadCTS(module, filename) {
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
}
const source = getMaybeCachedSource(module, filename);
const { stripTypeScriptTypes } = require('internal/modules/helpers');
const code = stripTypeScriptTypes(source, filename);
module._compile(code, filename, 'commonjs');
}
Expand All @@ -1592,7 +1591,6 @@ function loadTS(module, filename) {
}
// If already analyzed the source, then it will be cached.
const source = getMaybeCachedSource(module, filename);
const { stripTypeScriptTypes } = require('internal/modules/helpers');
const content = stripTypeScriptTypes(source, filename);
let format;
const pkg = packageJsonReader.getNearestParentPackageJSON(filename);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-eslint-duplicate-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ new RuleTester({
}).run('no-duplicate-requires', rule, {
valid: [
{
code: 'require("a"); require("b"); (function() { require("a"); });',
code: '(function() { require("a"); }); (function() { require("a"); });',
},
{
code: 'require(a); require(a);',
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint-rules/no-duplicate-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {

return {
CallExpression(node) {
if (isRequireCall(node) && isTopLevel(node)) {
if (isRequireCall(node)) {
const [firstArg] = node.arguments;
if (isString(firstArg)) {
const moduleName = firstArg.value.trim();
Expand All @@ -43,7 +43,7 @@ module.exports = {
node,
message: `'${moduleName}' require is duplicated.`,
});
} else {
} else if (isTopLevel(node)) {
requiredModules.add(moduleName);
}
}
Expand Down

0 comments on commit 51d2a72

Please sign in to comment.