Skip to content

Commit 4be96b4

Browse files
authored
fix(build): skip preload treeshaking for nested braces (#17687)
1 parent b723a75 commit 4be96b4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const preloadMarkerRE = new RegExp(preloadMarker, 'g')
4242
const dynamicImportPrefixRE = /import\s*\(/
4343

4444
const dynamicImportTreeshakenRE =
45-
/((?:\bconst\s+|\blet\s+|\bvar\s+|,\s*)(\{[^}.=]+\})\s*=\s*await\s+import\([^)]+\))|(\(\s*await\s+import\([^)]+\)\s*\)(\??\.[\w$]+))|\bimport\([^)]+\)(\s*\.then\(\s*(?:function\s*)?\(\s*\{([^}.=]+)\}\))/g
45+
/((?:\bconst\s+|\blet\s+|\bvar\s+|,\s*)(\{[^{}.=]+\})\s*=\s*await\s+import\([^)]+\))|(\(\s*await\s+import\([^)]+\)\s*\)(\??\.[\w$]+))|\bimport\([^)]+\)(\s*\.then\(\s*(?:function\s*)?\(\s*\{([^{}.=]+)\}\))/g
4646

4747
function toRelativePath(filename: string, importer: string) {
4848
const relPath = path.posix.relative(path.posix.dirname(importer), filename)

playground/dynamic-import/nested/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,21 @@ import(`../nested/nested/${base}.js`).then((mod) => {
175175
({ foo = {} }) => foo,
176176
)
177177
await import('./treeshaken/syntax.js').then((mod) => mod.foo({ foo }))
178+
const obj = [
179+
'',
180+
{
181+
async lazy() {
182+
const { foo } = await import('./treeshaken/treeshaken.js')
183+
return { foo: aaa(foo) }
184+
},
185+
},
186+
]
178187
default1()
179188
default2()
180189
other()
181190
foo()
182191
foo2()
192+
obj[1].lazy()
183193
})()
184194

185195
import(`../nested/static.js`).then((mod) => {

0 commit comments

Comments
 (0)