Unverified Commit 5deb11e8 authored by Eng Zer Jun's avatar Eng Zer Jun Committed by GitHub

refactor: replace `indexOf === 0` with `startsWith` (#68116)

It is more readable to call `startsWith` than to call `indexOf === 0`
and compare the result with zero to determine whether a string starts
with a given prefix.

Only these 4 lines of code still call `indexOf === 0`.
Signed-off-by: 's avatarEng Zer Jun <engzerjun@gmail.com>
Co-authored-by: 's avatarSam Ko <sam@vercel.com>
parent 726dabf0
...@@ -216,7 +216,7 @@ function normalizeSourceMap(map: any, resourcePath: string) { ...@@ -216,7 +216,7 @@ function normalizeSourceMap(map: any, resourcePath: string) {
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
newMap.sources = newMap.sources.map((source: string) => { newMap.sources = newMap.sources.map((source: string) => {
// Non-standard syntax from `postcss` // Non-standard syntax from `postcss`
if (source.indexOf('<') === 0) { if (source.startsWith('<')) {
return source return source
} }
...@@ -297,7 +297,7 @@ function normalizeSourceMapForRuntime(map: any, loaderContext: any) { ...@@ -297,7 +297,7 @@ function normalizeSourceMapForRuntime(map: any, loaderContext: any) {
resultMap.sources = resultMap.sources.map((source: string) => { resultMap.sources = resultMap.sources.map((source: string) => {
// Non-standard syntax from `postcss` // Non-standard syntax from `postcss`
if (source.indexOf('<') === 0) { if (source.startsWith('<')) {
return source return source
} }
......
...@@ -68,7 +68,7 @@ function normalizeSourceMapAfterPostcss(map: any, resourceContext: string) { ...@@ -68,7 +68,7 @@ function normalizeSourceMapAfterPostcss(map: any, resourceContext: string) {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
newMap.sources = newMap.sources.map((source: string) => { newMap.sources = newMap.sources.map((source: string) => {
if (source.indexOf('<') === 0) { if (source.startsWith('<')) {
return source return source
} }
......
...@@ -118,7 +118,7 @@ function formatMessage( ...@@ -118,7 +118,7 @@ function formatMessage(
} }
// Cleans up verbose "module not found" messages for files and packages. // Cleans up verbose "module not found" messages for files and packages.
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) { if (lines[1] && lines[1].startsWith('Module not found: ')) {
lines = [ lines = [
lines[0], lines[0],
lines[1] lines[1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment