@@ -55,6 +55,7 @@ import { scanBuildStripPlugin } from './plugins/scan'
5555import { validateImportPlugin } from './plugins/validate-import'
5656import { vitePluginFindSourceMapURL } from './plugins/find-source-map-url'
5757import { parseCssVirtual , toCssVirtual , parseIdQuery } from './plugins/shared'
58+ import { stripLiteral } from 'strip-literal'
5859
5960const isRolldownVite = 'rolldownVersion' in vite
6061
@@ -702,10 +703,11 @@ export default function vitePluginRsc(
702703 if ( ! code . includes ( 'import.meta.viteRsc.loadModule' ) ) return
703704 const { server } = manager
704705 const s = new MagicString ( code )
705- for ( const match of code . matchAll (
706+ for ( const match of stripLiteral ( code ) . matchAll (
706707 / i m p o r t \. m e t a \. v i t e R s c \. l o a d M o d u l e \( ( [ \s \S ] * ?) \) / dg,
707708 ) ) {
708- const argCode = match [ 1 ] ! . trim ( )
709+ const [ argStart , argEnd ] = match . indices ! [ 1 ] !
710+ const argCode = code . slice ( argStart , argEnd ) . trim ( )
709711 const [ environmentName , entryName ] = evalValue ( `[${ argCode } ]` )
710712 let replacement : string
711713 if (
@@ -973,10 +975,11 @@ export default assetsManifest.bootstrapScriptContent;
973975 assert ( this . environment . name !== 'client' )
974976 const output = new MagicString ( code )
975977
976- for ( const match of code . matchAll (
978+ for ( const match of stripLiteral ( code ) . matchAll (
977979 / i m p o r t \s * \. \s * m e t a \s * \. \s * v i t e R s c \s * \. \s * l o a d B o o t s t r a p S c r i p t C o n t e n t \( ( [ \s \S ] * ?) \) / dg,
978980 ) ) {
979- const argCode = match [ 1 ] ! . trim ( )
981+ const [ argStart , argEnd ] = match . indices ! [ 1 ] !
982+ const argCode = code . slice ( argStart , argEnd ) . trim ( )
980983 const entryName = evalValue ( argCode )
981984 assert (
982985 entryName ,
@@ -2087,11 +2090,12 @@ function vitePluginRscCss(
20872090 const output = new MagicString ( code )
20882091 let importAdded = false
20892092
2090- for ( const match of code . matchAll (
2093+ for ( const match of stripLiteral ( code ) . matchAll (
20912094 / i m p o r t \. m e t a \. v i t e R s c \. l o a d C s s \( ( [ \s \S ] * ?) \) / dg,
20922095 ) ) {
20932096 const [ start , end ] = match . indices ! [ 0 ] !
2094- const argCode = match [ 1 ] ! . trim ( )
2097+ const [ argStart , argEnd ] = match . indices ! [ 1 ] !
2098+ const argCode = code . slice ( argStart , argEnd ) . trim ( )
20952099 let importer = id
20962100 if ( argCode ) {
20972101 const argValue = evalValue < string > ( argCode )
0 commit comments