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: fix esbuild break when importRe matches multiline import #4054

Merged
merged 4 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/playground/vue/ScanDep.vue
@@ -1,8 +1,15 @@
<template>
<h2>Scan Deps from &lt;script setup lang=ts&gt; blocks</h2>
<div class="scan">{{ typeof debounce === 'function' ? 'ok' : 'error' }}</div>
<div class="multiline-scan">{{body}}</div>
</template>

<script setup lang="ts">
import { debounce } from 'lodash-es'
let body = ""
function testMultiline(a, b) {
body = b.body
}
testMultiline("import", {
body: "ok" });
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
</script>
1 change: 1 addition & 0 deletions packages/playground/vue/__tests__/vue.spec.ts
Expand Up @@ -24,6 +24,7 @@ test(':slotted', async () => {

test('scan deps from <script setup lang="ts">', async () => {
expect(await page.textContent('.scan')).toBe('ok')
expect(await page.textContent('.multiline-scan')).toBe('ok')
})

describe('pre-processors', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -38,7 +38,7 @@ const htmlTypesRE = /\.(html|vue|svelte)$/
// since even missed imports can be caught at runtime, and false positives will
// simply be ignored.
const importsRE =
/\bimport(?!\s+type)(?:[\w*{}\n\r\t, ]+from\s*)?\s*("[^"]+"|'[^']+')/gm
/\bimport(?!\s+type)(?:[\w*{}\n\r\t, ]+from\s*)?\s*("[^"]+"|'[^']+')$/gm
patak-dev marked this conversation as resolved.
Show resolved Hide resolved

export async function scanImports(config: ResolvedConfig): Promise<{
deps: Record<string, string>
Expand Down