Skip to content

Commit

Permalink
fix(compiler/runtime-dom): ignore comments in inline styles (vuejs#6808)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyxu1102 authored and chrislone committed Feb 4, 2023
1 parent 8c90490 commit 51ea28e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 16 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ test('should work', () => {
expect(result.code).toMatch(`export function render(`)
})

// #6807
test('should work with style comment', () => {
const source = `
<div style="
/* nothing */
width: 300px;
height: 100px/* nothing */
">{{ render }}</div>
`

const result = compile({ filename: 'example.vue', source })
expect(result.errors.length).toBe(0)
expect(result.source).toBe(source)
expect(result.code).toMatch(`{"width":"300px","height":"100px"}`)
})

test('preprocess pug', () => {
const template = parse(
`
Expand Down
16 changes: 10 additions & 6 deletions packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ export function normalizeStyle(

const listDelimiterRE = /;(?![^(]*\))/g
const propertyDelimiterRE = /:([^]+)/
const styleCommentRE = /\/\*.*?\*\//gs

export function parseStringStyle(cssText: string): NormalizedStyle {
const ret: NormalizedStyle = {}
cssText.split(listDelimiterRE).forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
cssText
.replace(styleCommentRE, '')
.split(listDelimiterRE)
.forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
return ret
}

Expand Down

0 comments on commit 51ea28e

Please sign in to comment.