Skip to content

Commit 9065b37

Browse files
stygian-desolatorbluwy
andauthoredJun 9, 2022
fix(optimizer): encode _ and . in different way (#8508)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
1 parent 0e5c009 commit 9065b37

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed
 

‎packages/vite/src/node/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export function unwrapId(id: string): string {
3737
}
3838

3939
export const flattenId = (id: string): string =>
40-
id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.:]/g, '_')
40+
id
41+
.replace(/[\/:]/g, '_')
42+
.replace(/[\.]/g, '__')
43+
.replace(/(\s*>\s*)/g, '___')
4144

4245
export const normalizeId = (id: string): string =>
4346
id.replace(/(\s*>\s*)/g, ' > ')

‎playground/optimize-deps/__tests__/optimize-deps.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ test('variable names are reused in different scripts', async () => {
121121
expect(await page.textContent('.reused-variable-names')).toBe('reused')
122122
})
123123

124+
test('flatten id should generate correctly', async () => {
125+
expect(await page.textContent('.clonedeep-slash')).toBe('clonedeep-slash')
126+
expect(await page.textContent('.clonedeep-dot')).toBe('clonedeep-dot')
127+
})
128+
124129
test.runIf(isServe)('error on builtin modules usage', () => {
125130
expect(browserLogs).toEqual(
126131
expect.arrayContaining([

‎playground/optimize-deps/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ <h2>Alias with colon</h2>
7474
<h2>Reused variable names</h2>
7575
<div>This should show reused: <span class="reused-variable-names"></span></div>
7676

77+
<h2>Flatten Id</h2>
78+
<div class="clonedeep-slash"></div>
79+
<div class="clonedeep-dot"></div>
80+
7781
<script>
7882
function text(el, text) {
7983
document.querySelector(el).textContent = text
@@ -169,3 +173,11 @@ <h2>Reused variable names</h2>
169173
read()
170174
}
171175
</script>
176+
177+
<script type="module">
178+
import cloneDeepSlash from 'lodash/cloneDeep'
179+
import cloneDeepDot from 'lodash.clonedeep'
180+
181+
text('.clonedeep-slash', cloneDeepSlash({ name: 'clonedeep-slash' }).name)
182+
text('.clonedeep-dot', cloneDeepDot({ name: 'clonedeep-dot' }).name)
183+
</script>

‎playground/optimize-deps/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"resolve-linked": "workspace:0.0.0",
3232
"url": "^0.11.0",
3333
"vue": "^3.2.37",
34-
"vuex": "^4.0.2"
34+
"vuex": "^4.0.2",
35+
"lodash": "^4.17.21",
36+
"lodash.clonedeep": "^4.5.0"
3537
},
3638
"devDependencies": {
3739
"@vitejs/plugin-vue": "workspace:*"

‎pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.