From f7e442729c703b21f9184b4ae9094442be076ff2 Mon Sep 17 00:00:00 2001 From: FatDong1 Date: Sun, 2 Oct 2022 17:50:17 +0800 Subject: [PATCH 1/5] fix(compiler-sfc): ignore style comment in tranform stage --- packages/shared/src/normalizeProp.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index cab8090692e..9fe0798a980 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -29,13 +29,18 @@ export function normalizeStyle( const listDelimiterRE = /;(?![^(]*\))/g const propertyDelimiterRE = /:(.+)/ +const styleCommentRE = /\/\*.*?\*\//g 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() + ret[key] = value + } } }) return ret From 0f44f5be2c2e74962f774aa2f427906b9b20907d Mon Sep 17 00:00:00 2001 From: FatDong1 Date: Sun, 2 Oct 2022 17:50:29 +0800 Subject: [PATCH 2/5] test: add test case --- .../__tests__/compileTemplate.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts index f58b6338de9..b471b67c9ca 100644 --- a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts +++ b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts @@ -22,6 +22,22 @@ test('should work', () => { expect(result.code).toMatch(`export function render(`) }) +// #6807 +test('should work with style comment', () => { + const source = ` +
{{ render }}
+ ` + + 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( ` From d334d11b23f02dc154bc75811a3faeb2723fb34c Mon Sep 17 00:00:00 2001 From: FatDong1 Date: Mon, 3 Oct 2022 15:51:45 +0800 Subject: [PATCH 3/5] chore: improve code --- packages/shared/src/normalizeProp.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 9fe0798a980..419690f9f40 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -33,14 +33,10 @@ const styleCommentRE = /\/\*.*?\*\//g export function parseStringStyle(cssText: string): NormalizedStyle { const ret: NormalizedStyle = {} - cssText.split(listDelimiterRE).forEach(item => { + cssText.replace(styleCommentRE, '').split(listDelimiterRE).forEach(item => { if (item) { const tmp = item.split(propertyDelimiterRE) - if (tmp.length > 1) { - const key = tmp[0].replace(styleCommentRE, '').trim() - const value = tmp[1].replace(styleCommentRE, '').trim() - ret[key] = value - } + tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim()) } }) return ret From 7261fa1a1200186deb70a30a05f649990cb3033c Mon Sep 17 00:00:00 2001 From: Rudy Date: Mon, 3 Oct 2022 16:44:19 +0800 Subject: [PATCH 4/5] chore: improve code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲智子 --- packages/shared/src/normalizeProp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 419690f9f40..dd32c4de300 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -29,7 +29,7 @@ export function normalizeStyle( const listDelimiterRE = /;(?![^(]*\))/g const propertyDelimiterRE = /:(.+)/ -const styleCommentRE = /\/\*.*?\*\//g +const styleCommentRE = /\/\*.*?\*\//gs export function parseStringStyle(cssText: string): NormalizedStyle { const ret: NormalizedStyle = {} From 00bbd29285f508ac03f7d45e52d6d5a2f6dca4d3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 7 Nov 2022 22:36:46 -0500 Subject: [PATCH 5/5] Update normalizeProp.ts --- packages/shared/src/normalizeProp.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 351715fc85e..b6f822670fe 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -32,12 +32,15 @@ const styleCommentRE = /\/\*.*?\*\//gs export function parseStringStyle(cssText: string): NormalizedStyle { const ret: NormalizedStyle = {} - cssText.replace(styleCommentRE, '').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 }