Skip to content

Commit d3ddf21

Browse files
committed
refactor
1 parent e3d7a03 commit d3ddf21

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

flow/compiler.js

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

8079
text?: string;
8180
attrs?: Array<{ name: string; value: string }>;
8281
props?: Array<{ name: string; value: string }>;
8382
plain?: boolean;
8483
pre?: true;
8584
ns?: string;
85+
staticProps?: Array<string>;
8686

8787
component?: string;
8888
inlineTemplate?: true;

src/compiler/helpers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export function pluckModuleFunction<F: Function> (
1515
: []
1616
}
1717

18-
export function addProp (el: ASTElement, name: string, value: string) {
18+
export function addProp (el: ASTElement, name: string, value: string, fromStaticAttr?: boolean) {
19+
if (fromStaticAttr) {
20+
(el.staticProps || (el.staticProps = [])).push(name)
21+
}
1922
(el.props || (el.props = [])).push({ name, value })
2023
}
2124

src/compiler/optimizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function optimize (root: ?ASTElement, options: CompilerOptions) {
3030

3131
function genStaticKeys (keys: string): Function {
3232
return makeMap(
33-
'type,tag,attrsList,attrsMap,plain,parent,children,attrs' +
33+
'type,tag,attrsList,attrsMap,plain,parent,children,attrs,staticProps' +
3434
(keys ? ',' + keys : '')
3535
)
3636
}
@@ -100,7 +100,7 @@ function isStatic (node: ASTNode): boolean {
100100
return true
101101
}
102102
const nodeAttrs = Object.keys(node)
103-
if (!node.hasNormalProp && node.props && node.props.length) {
103+
if (node.staticProps && node.props && node.staticProps.length === node.props.length) {
104104
remove(nodeAttrs, 'props')
105105
}
106106
return !!(node.pre || (

src/compiler/parser/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ function processAttrs (el) {
444444
}
445445
}
446446
if (isProp || platformMustUseProp(el.tag, name)) {
447-
el.hasNormalProp = true
448447
addProp(el, name, value)
449448
} else {
450449
addAttr(el, name, value)
@@ -482,9 +481,9 @@ function processAttrs (el) {
482481
// so that patches between dynamic/static are consistent
483482
if (platformMustUseProp(el.tag, name)) {
484483
if (name === 'value') {
485-
addProp(el, name, JSON.stringify(value))
484+
addProp(el, name, JSON.stringify(value), true)
486485
} else {
487-
addProp(el, name, 'true')
486+
addProp(el, name, 'true', true)
488487
}
489488
}
490489
}

0 commit comments

Comments
 (0)