fix(build): skip preload treeshaking for nested braces (#17687)

This commit is contained in:
Bjorn Lu 2024-07-15 21:06:07 +08:00 committed by GitHub
parent b723a753ce
commit 4be96b48bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -42,7 +42,7 @@ const preloadMarkerRE = new RegExp(preloadMarker, 'g')
const dynamicImportPrefixRE = /import\s*\(/
const dynamicImportTreeshakenRE =
/((?:\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
/((?:\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
function toRelativePath(filename: string, importer: string) {
const relPath = path.posix.relative(path.posix.dirname(importer), filename)

View File

@ -175,11 +175,21 @@ import(`../nested/nested/${base}.js`).then((mod) => {
({ foo = {} }) => foo,
)
await import('./treeshaken/syntax.js').then((mod) => mod.foo({ foo }))
const obj = [
'',
{
async lazy() {
const { foo } = await import('./treeshaken/treeshaken.js')
return { foo: aaa(foo) }
},
},
]
default1()
default2()
other()
foo()
foo2()
obj[1].lazy()
})()
import(`../nested/static.js`).then((mod) => {