From 0dea32d1b24dec6cae249876d3ed5aa34a54b16d Mon Sep 17 00:00:00 2001 From: moushicheng <1163675107@qq.com> Date: Fri, 9 Sep 2022 21:58:14 +0800 Subject: [PATCH 1/2] fix(stringifyStatic):remove boolean attribute for false (#6617) --- .../transforms/stringifyStatic.spec.ts | 23 +++++++++++++++++++ .../src/transforms/stringifyStatic.ts | 10 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts index c737071a827..bedec9fc00a 100644 --- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts @@ -410,6 +410,29 @@ describe('stringify static html', () => { }) }) + // #6617 + test('should remove boolean attribute for `false`', () => { + const { ast } = compileWithStringify( + `${repeat( + `
`, + StringifyThresholds.NODE_COUNT + )}` + ) + expect(ast.hoists[0]).toMatchObject({ + type: NodeTypes.JS_CALL_EXPRESSION, + callee: CREATE_STATIC, + arguments: [ + JSON.stringify( + `${repeat( + `
`, + StringifyThresholds.NODE_COUNT + )}` + ), + '21' + ] + }) + }) + test('should stringify svg', () => { const svg = `` const repeated = `` diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts index a268d86cd07..1e113fce434 100644 --- a/packages/compiler-dom/src/transforms/stringifyStatic.ts +++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts @@ -28,7 +28,8 @@ import { normalizeStyle, stringifyStyle, makeMap, - isKnownSvgAttr + isKnownSvgAttr, + isBooleanAttr } from '@vue/shared' import { DOMNamespaces } from '../parserOptions' @@ -298,6 +299,13 @@ function stringifyElement( }="__VUE_EXP_START__${exp.content}__VUE_EXP_END__"` continue } + // #6568 + if ( + isBooleanAttr((p.arg as SimpleExpressionNode).content) && + exp.content == 'false' + ) { + continue + } // constant v-bind, e.g. :foo="1" let evaluated = evaluateConstant(exp) if (evaluated != null) { From cfeef712de2287160fb2b546ceb0a2d1eb395d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=90=E6=97=B6=E6=A9=99?= <1163675107@qq.com> Date: Fri, 9 Sep 2022 22:01:28 +0800 Subject: [PATCH 2/2] Update packages/compiler-dom/src/transforms/stringifyStatic.ts Co-authored-by: btea <2356281422@qq.com> --- packages/compiler-dom/src/transforms/stringifyStatic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts index 1e113fce434..d3f58bdb9da 100644 --- a/packages/compiler-dom/src/transforms/stringifyStatic.ts +++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts @@ -302,7 +302,7 @@ function stringifyElement( // #6568 if ( isBooleanAttr((p.arg as SimpleExpressionNode).content) && - exp.content == 'false' + exp.content === 'false' ) { continue }