Skip to content

Commit d0aa833

Browse files
sapphi-redunderfinpatak-dev
authored
fix(css): inline css correctly for double quote use strict (vitejs#19590)
Co-authored-by: underfin <[email protected]> Co-authored-by: patak <[email protected]>
1 parent 367d968 commit d0aa833

File tree

1 file changed

+9
-2
lines changed
  • packages/vite/src/node/plugins

1 file changed

+9
-2
lines changed

packages/vite/src/node/plugins/css.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,19 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
939939
`document.head.appendChild(${style});`
940940
let injectionPoint
941941
const wrapIdx = code.indexOf('System.register')
942+
const singleQuoteUseStrict = `'use strict';`
943+
const doubleQuoteUseStrict = `"use strict";`
942944
if (wrapIdx >= 0) {
943945
const executeFnStart = code.indexOf('execute:', wrapIdx)
944946
injectionPoint = code.indexOf('{', executeFnStart) + 1
947+
} else if (code.includes(singleQuoteUseStrict)) {
948+
injectionPoint =
949+
code.indexOf(singleQuoteUseStrict) + singleQuoteUseStrict.length
950+
} else if (code.includes(doubleQuoteUseStrict)) {
951+
injectionPoint =
952+
code.indexOf(doubleQuoteUseStrict) + doubleQuoteUseStrict.length
945953
} else {
946-
const insertMark = "'use strict';"
947-
injectionPoint = code.indexOf(insertMark) + insertMark.length
954+
throw new Error('Injection point for inlined CSS not found')
948955
}
949956
s ||= new MagicString(code)
950957
s.appendRight(injectionPoint, injectCode)

0 commit comments

Comments
 (0)