Skip to content

Commit

Permalink
fix: keep tree nodes until all children are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 1, 2022
1 parent b9c37ac commit e254d15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/core/tree.spec.ts
Expand Up @@ -79,6 +79,17 @@ describe('Tree', () => {
]).toEqual(['a', 'b'])
})

it('removes the node after all named views', () => {
const tree = createPrefixTree(DEFAULT_OPTIONS)
tree.insert('index.vue')
tree.insert('index@a.vue')
expect(tree.children.get('index')).toBeDefined()
tree.remove('index@a.vue')
expect(tree.children.get('index')).toBeDefined()
tree.remove('index.vue')
expect(tree.children.get('index')).toBeUndefined()
})

it('handles multiple params', () => {
const tree = createPrefixTree(DEFAULT_OPTIONS)
tree.insert('[a]-[b].vue')
Expand Down
2 changes: 1 addition & 1 deletion src/core/tree.ts
Expand Up @@ -80,7 +80,7 @@ export class TreeLeaf {
child.value.filePaths.delete(viewName)
}
// this is the file we wanted to remove
if (child.children.size === 0) {
if (child.children.size === 0 && child.value.filePaths.size === 0) {
this.children.delete(segment)
}
}
Expand Down

0 comments on commit e254d15

Please sign in to comment.