Skip to content

Commit eca73f2

Browse files
defccyyx990803
authored andcommitted
fix directive sort compare (vuejs#3776)
* fix directive sort compare * fix directive sort compare. and update normal directives test case.
1 parent 64f7113 commit eca73f2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/compiler/compile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,20 @@ function sortDirectives (dirs) {
122122

123123
var groupedMap = {}
124124
var i, j, k, l
125+
var index = 0
126+
var priorities = []
125127
for (i = 0, j = dirs.length; i < j; i++) {
126128
var dir = dirs[i]
127129
var priority = dir.descriptor.def.priority || DEFAULT_PRIORITY
128130
var array = groupedMap[priority]
129131
if (!array) {
130132
array = groupedMap[priority] = []
133+
priorities.push(priority)
131134
}
132135
array.push(dir)
133136
}
134137

135-
var index = 0
136-
var priorities = Object.keys(groupedMap).sort(function (a, b) {
138+
priorities.sort(function (a, b) {
137139
return a > b ? -1 : a === b ? 0 : 1
138140
})
139141
for (i = 0, j = priorities.length; i < j; i++) {

test/unit/specs/compiler/compile_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe('Compile', function () {
5353
it('normal directives', function () {
5454
el.setAttribute('v-a', 'b')
5555
el.innerHTML = '<p v-a:hello.a.b="a" v-b="1">hello</p><div v-b.literal="foo"></div>'
56-
var defA = { priority: 1 }
57-
var defB = { priority: 2 }
56+
var defA = { priority: 250 }
57+
var defB = { priority: 1100 }
5858
var options = _.mergeOptions(Vue.options, {
5959
directives: {
6060
a: defA,

0 commit comments

Comments
 (0)