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: encode _ and . in different way #8508

Merged
merged 3 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion packages/vite/src/node/utils.ts
Expand Up @@ -37,7 +37,10 @@ export function unwrapId(id: string): string {
}

export const flattenId = (id: string): string =>
id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.:]/g, '_')
id
.replace(/(\s*>\s*)/g, '__')
.replace(/[\/:]/g, '_')
.replace(/[\.]/g, '___')
patak-dev marked this conversation as resolved.
Show resolved Hide resolved

export const normalizeId = (id: string): string =>
id.replace(/(\s*>\s*)/g, ' > ')
Expand Down
5 changes: 5 additions & 0 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Expand Up @@ -121,6 +121,11 @@ test('variable names are reused in different scripts', async () => {
expect(await page.textContent('.reused-variable-names')).toBe('reused')
})

test('flatten id should generate correctly', async () => {
expect(await page.textContent('.clonedeep-slash')).toBe('clonedeep-slash')
expect(await page.textContent('.clonedeep-dot')).toBe('clonedeep-dot')
})

test.runIf(isServe)('error on builtin modules usage', () => {
expect(browserLogs).toEqual(
expect.arrayContaining([
Expand Down
12 changes: 12 additions & 0 deletions playground/optimize-deps/index.html
Expand Up @@ -74,6 +74,10 @@ <h2>Alias with colon</h2>
<h2>Reused variable names</h2>
<div>This should show reused: <span class="reused-variable-names"></span></div>

<h2>Flatten Id</h2>
<div class="clonedeep-slash"></div>
<div class="clonedeep-dot"></div>

<script>
function text(el, text) {
document.querySelector(el).textContent = text
Expand Down Expand Up @@ -169,3 +173,11 @@ <h2>Reused variable names</h2>
read()
}
</script>

<script type="module">
import cloneDeepSlash from 'lodash/cloneDeep'
import cloneDeepDot from 'lodash.clonedeep'

text('.clonedeep-slash', cloneDeepSlash({ name: 'clonedeep-slash' }).name)
text('.clonedeep-dot', cloneDeepDot({ name: 'clonedeep-dot' }).name)
</script>
4 changes: 3 additions & 1 deletion playground/optimize-deps/package.json
Expand Up @@ -30,7 +30,9 @@
"resolve-linked": "workspace:0.0.0",
"url": "^0.11.0",
"vue": "^3.2.37",
"vuex": "^4.0.2"
"vuex": "^4.0.2",
"lodash": "^4.17.21",
"lodash.clonedeep": "^4.5.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "workspace:*"
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.