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(compiler-sfc): ignore style comment in transform stage #6808

Merged
merged 6 commits into from
Nov 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ export function normalizeStyle(

const listDelimiterRE = /;(?![^(]*\))/g
const propertyDelimiterRE = /:(.+)/
const styleCommentRE = /\/\*.*?\*\//g
rudyxu1102 marked this conversation as resolved.
Show resolved Hide resolved

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())
if (tmp.length > 1) {
const key = tmp[0].replace(styleCommentRE, '').trim()
const value = tmp[1].replace(styleCommentRE, '').trim()
rudyxu1102 marked this conversation as resolved.
Show resolved Hide resolved
ret[key] = value
}
}
})
return ret
Expand Down