diff --git a/packages/commonjs/src/dynamic-modules.js b/packages/commonjs/src/dynamic-modules.js index 720531374..41a59653c 100644 --- a/packages/commonjs/src/dynamic-modules.js +++ b/packages/commonjs/src/dynamic-modules.js @@ -36,7 +36,7 @@ export function getDynamicRequireModules(patterns, dynamicRequireRoot) { const dynamicRequireModules = new Map(); const dirNames = new Set(); for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) { - const isNegated = pattern.startsWith('!'); + const isNegated = pattern[0] === '!'; const modifyMap = (targetPath, resolvedPath) => isNegated ? dynamicRequireModules.delete(targetPath) diff --git a/packages/commonjs/src/resolve-id.js b/packages/commonjs/src/resolve-id.js index a2597d857..60fe0947e 100644 --- a/packages/commonjs/src/resolve-id.js +++ b/packages/commonjs/src/resolve-id.js @@ -120,7 +120,7 @@ export default function getResolveId(extensions, isPossibleCjsId) { } } - if (importee.startsWith('\0')) { + if (importee[0] === '\0') { return null; } diff --git a/packages/commonjs/src/resolve-require-sources.js b/packages/commonjs/src/resolve-require-sources.js index 84b42fa66..dc1e45477 100644 --- a/packages/commonjs/src/resolve-require-sources.js +++ b/packages/commonjs/src/resolve-require-sources.js @@ -164,7 +164,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre const requireTargets = await Promise.all( sources.map(async ({ source, isConditional }) => { // Never analyze or proxy internal modules - if (source.startsWith('\0')) { + if (source[0] === '\0') { return { id: source, allowProxy: false }; } currentlyResolvingForParent.add(source); diff --git a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js index ed1ae978e..0be767454 100644 --- a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js +++ b/packages/dynamic-import-vars/src/dynamic-import-to-glob.js @@ -88,13 +88,13 @@ export function dynamicImportToGlob(node, sourceString) { glob = glob.replace(/\*\*/g, '*'); - if (glob.startsWith('*')) { + if (glob[0] === '*') { throw new VariableDynamicImportError( `invalid import "${sourceString}". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. ${example}` ); } - if (glob.startsWith('/')) { + if (glob[0] === '/') { throw new VariableDynamicImportError( `invalid import "${sourceString}". Variable absolute imports are not supported, imports must start with ./ in the static part of the import. ${example}` ); diff --git a/packages/node-resolve/src/package/resolvePackageImports.ts b/packages/node-resolve/src/package/resolvePackageImports.ts index 00b85058e..76325fdb1 100644 --- a/packages/node-resolve/src/package/resolvePackageImports.ts +++ b/packages/node-resolve/src/package/resolvePackageImports.ts @@ -38,7 +38,7 @@ async function resolvePackageImports({ }; // Assert: specifier begins with "#". - if (!importSpecifier.startsWith('#')) { + if (importSpecifier[0] !== '#') { throw new InvalidModuleSpecifierError(context, true, 'Invalid import specifier.'); } diff --git a/packages/node-resolve/src/package/utils.ts b/packages/node-resolve/src/package/utils.ts index 00a71a791..326fbfa4f 100644 --- a/packages/node-resolve/src/package/utils.ts +++ b/packages/node-resolve/src/package/utils.ts @@ -35,7 +35,7 @@ export function isUrl(str: string) { * Conditions is an export object where all keys are conditions like 'node' (aka do not with '.') */ export function isConditions(exports: any) { - return typeof exports === 'object' && Object.keys(exports).every((k) => !k.startsWith('.')); + return typeof exports === 'object' && Object.keys(exports).every((k) => k[0] !== '.'); } /** @@ -50,7 +50,7 @@ export function isMappings(exports: any) { */ export function isMixedExports(exports: Record) { const keys = Object.keys(exports); - return keys.some((k) => k.startsWith('.')) && keys.some((k) => !k.startsWith('.')); + return keys.some((k) => k[0] === '.') && keys.some((k) => k[0] !== '.'); } export function createBaseErrorMsg(importSpecifier: string, importer: string) { diff --git a/packages/node-resolve/src/resolveImportSpecifiers.js b/packages/node-resolve/src/resolveImportSpecifiers.js index d29af56c1..5dd971256 100644 --- a/packages/node-resolve/src/resolveImportSpecifiers.js +++ b/packages/node-resolve/src/resolveImportSpecifiers.js @@ -118,7 +118,7 @@ async function resolveWithExportMap({ ignoreSideEffectsForRoot, allowExportsFolderMapping }) { - if (importSpecifier.startsWith('#')) { + if (importSpecifier[0] === '#') { // this is a package internal import, resolve using package imports field const resolveResult = await resolvePackageImports({ importSpecifier, diff --git a/packages/node-resolve/src/util.js b/packages/node-resolve/src/util.js index c61deb27d..39a383d9f 100644 --- a/packages/node-resolve/src/util.js +++ b/packages/node-resolve/src/util.js @@ -6,7 +6,7 @@ import { realpathSync } from './fs'; // returns the imported package name for bare module imports export function getPackageName(id) { - if (id.startsWith('.') || id.startsWith('/')) { + if (id[0] === '.' || id[0] === '/') { return null; }