Skip to content

Commit e3d7a03

Browse files
committed
fix special static attrs as dom prop
1 parent c9fa2e6 commit e3d7a03

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

flow/compiler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ declare type ASTElement = {
7575
staticInFor?: boolean;
7676
staticProcessed?: boolean;
7777
hasBindings?: boolean;
78+
hasNormalProp?: true;
7879

7980
text?: string;
8081
attrs?: Array<{ name: string; value: string }>;

src/compiler/optimizer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { makeMap, isBuiltInTag, cached, no } from 'shared/util'
3+
import { makeMap, isBuiltInTag, cached, no, remove } from 'shared/util'
44

55
let isStaticKey
66
let isPlatformReservedTag
@@ -99,13 +99,17 @@ function isStatic (node: ASTNode): boolean {
9999
if (node.type === 3) { // text
100100
return true
101101
}
102+
const nodeAttrs = Object.keys(node)
103+
if (!node.hasNormalProp && node.props && node.props.length) {
104+
remove(nodeAttrs, 'props')
105+
}
102106
return !!(node.pre || (
103107
!node.hasBindings && // no dynamic bindings
104108
!node.if && !node.for && // not v-if or v-for or v-else
105109
!isBuiltInTag(node.tag) && // not a built-in
106110
isPlatformReservedTag(node.tag) && // not a component
107111
!isDirectChildOfTemplateFor(node) &&
108-
Object.keys(node).every(isStaticKey)
112+
nodeAttrs.every(isStaticKey)
109113
))
110114
}
111115

src/compiler/parser/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ function processAttrs (el) {
444444
}
445445
}
446446
if (isProp || platformMustUseProp(el.tag, name)) {
447+
el.hasNormalProp = true
447448
addProp(el, name, value)
448449
} else {
449450
addAttr(el, name, value)

test/unit/modules/compiler/optimizer.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ describe('optimizer', () => {
191191
expect(ast.children[0].static).toBe(false)
192192
})
193193

194+
it('mark static with static dom property', () => {
195+
const ast = parse('<input type="text" value="1">', baseOptions)
196+
optimize(ast, baseOptions)
197+
expect(ast.static).toBe(true)
198+
})
199+
194200
it('not root ast', () => {
195201
const ast = null
196202
optimize(ast, baseOptions)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy