Skip to content

Commit

Permalink
refactor: remove trimWhitespaceAndComments
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 10, 2023
1 parent 6488905 commit 4001b2a
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
} from 'es-module-lexer'
import { init, parse as parseImports } from 'es-module-lexer'
import { parse as parseJS } from 'acorn'
import { stripLiteral } from 'strip-literal'
import type { Node } from 'estree'
import { findStaticImports, parseStaticImport } from 'mlly'
import { makeLegalIdentifier } from '@rollup/pluginutils'
Expand Down Expand Up @@ -80,13 +79,6 @@ const hasImportInQueryParamsRE = /[?&]import=?\b/

export const hasViteIgnoreRE = /\/\*\s*@vite-ignore\s*\*\//

const trimWhitespaceRE = /^(\s*)(\S|\S[\s\S]*\S)\s*$/
const trimWhitespaceAndComments = (code: string) => {
const cleanedCode = stripLiteral(code)
const match = trimWhitespaceRE.exec(cleanedCode)
return match ? code.slice(match[1].length, match[2].length) : code
}

const urlIsStringRE = /^(?:'.*'|".*"|`.*`)$/

const templateLiteralRE = /^\s*`(.*)`\s*$/
Expand Down Expand Up @@ -663,13 +655,11 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
}

if (!ssr) {
const url = trimWhitespaceAndComments(rawUrl)
if (
!urlIsStringRE.test(url) ||
isExplicitImportRequired(url.slice(1, -1))
!urlIsStringRE.test(rawUrl) ||
isExplicitImportRequired(rawUrl.slice(1, -1))
) {
needQueryInjectHelper = true
// Use rawUrl to avoid removing comments like @vite-ignore
str().overwrite(
start,
end,
Expand Down

0 comments on commit 4001b2a

Please sign in to comment.