From 95f6d31f9c3e57f2db050564890e452d7093683b Mon Sep 17 00:00:00 2001 From: underfin Date: Thu, 6 Mar 2025 17:36:11 +0900 Subject: [PATCH 1/3] fix(css): inline css correctly for double quote use strict --- packages/vite/src/node/plugins/css.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b78f52ebc96380..db021ac4c720fb 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -939,12 +939,19 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `document.head.appendChild(${style});` let injectionPoint const wrapIdx = code.indexOf('System.register') + const singleQuoteUseStruct = `'use strict';` + const doubleQuoteUseStruct = `"use strict";` if (wrapIdx >= 0) { const executeFnStart = code.indexOf('execute:', wrapIdx) injectionPoint = code.indexOf('{', executeFnStart) + 1 + } else if (code.includes(singleQuoteUseStruct)) { + injectionPoint = + code.indexOf(singleQuoteUseStruct) + singleQuoteUseStruct.length + } else if (code.includes(doubleQuoteUseStruct)) { + injectionPoint = + code.indexOf(doubleQuoteUseStruct) + doubleQuoteUseStruct.length } else { - const insertMark = "'use strict';" - injectionPoint = code.indexOf(insertMark) + insertMark.length + throw new Error('Not found injection point for inlined CSS') } s ||= new MagicString(code) s.appendRight(injectionPoint, injectCode) From 7c8a966d110ccbc80d94eed3bbfea7c93b8dea88 Mon Sep 17 00:00:00 2001 From: patak <583075+patak-dev@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:14:16 +0100 Subject: [PATCH 2/3] chore: update --- packages/vite/src/node/plugins/css.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index db021ac4c720fb..3aa300ece80e0e 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -951,7 +951,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { injectionPoint = code.indexOf(doubleQuoteUseStruct) + doubleQuoteUseStruct.length } else { - throw new Error('Not found injection point for inlined CSS') + throw new Error('Injection point for inlined CSS not found') } s ||= new MagicString(code) s.appendRight(injectionPoint, injectCode) From c7bd1032f42c08e13f8545eac3acc8dcd1583934 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 7 Mar 2025 14:52:57 +0900 Subject: [PATCH 3/3] chore: it's strict --- packages/vite/src/node/plugins/css.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 3aa300ece80e0e..45a2709758cd45 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -939,17 +939,17 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `document.head.appendChild(${style});` let injectionPoint const wrapIdx = code.indexOf('System.register') - const singleQuoteUseStruct = `'use strict';` - const doubleQuoteUseStruct = `"use strict";` + const singleQuoteUseStrict = `'use strict';` + const doubleQuoteUseStrict = `"use strict";` if (wrapIdx >= 0) { const executeFnStart = code.indexOf('execute:', wrapIdx) injectionPoint = code.indexOf('{', executeFnStart) + 1 - } else if (code.includes(singleQuoteUseStruct)) { + } else if (code.includes(singleQuoteUseStrict)) { injectionPoint = - code.indexOf(singleQuoteUseStruct) + singleQuoteUseStruct.length - } else if (code.includes(doubleQuoteUseStruct)) { + code.indexOf(singleQuoteUseStrict) + singleQuoteUseStrict.length + } else if (code.includes(doubleQuoteUseStrict)) { injectionPoint = - code.indexOf(doubleQuoteUseStruct) + doubleQuoteUseStruct.length + code.indexOf(doubleQuoteUseStrict) + doubleQuoteUseStrict.length } else { throw new Error('Injection point for inlined CSS not found') }