Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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