Skip to content

Commit

Permalink
fix(build): skip preload treeshaking for nested braces (#17687)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 15, 2024
1 parent b723a75 commit 4be96b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions playground/dynamic-import/nested/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 4be96b4

Please sign in to comment.