php-imports
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -12,3 +12,3 @@ import executePattern from './executePattern'; | ||
matchPattern: (pattern: import("..").Path, example: import("..").Path) => boolean; | ||
removeNode: (tree: import("./types").TreeUseNamespace, path: import("..").Path) => boolean; | ||
removeNode: (tree: import("./types").TreeUseNamespace, path: import("..").Path, type: "item" | "namespace") => boolean; | ||
}; |
import { Path } from '..'; | ||
import { TreeUseNamespace } from '.'; | ||
declare const _default: (tree: TreeUseNamespace, path: Path) => boolean; | ||
declare const _default: (tree: TreeUseNamespace, path: Path, type: 'item' | 'namespace') => boolean; | ||
export default _default; |
@@ -6,3 +6,4 @@ import { Modifier } from '..'; | ||
aggregated: string; | ||
items: Map<string, TreeUseNamespace | TreeUseItem>; | ||
namespaces: Map<string, TreeUseNamespace>; | ||
items: Map<string, TreeUseItem>; | ||
count: number; | ||
@@ -9,0 +10,0 @@ }; |
@@ -8,3 +8,3 @@ { | ||
"license": "MIT", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "JavaScript library for formatting PHP imports", | ||
@@ -11,0 +11,0 @@ "homepage": "https://github.com/Tarik02/js-php-imports#readme", |
@@ -29,3 +29,4 @@ import { Tree, TreeUseNamespace } from '../tree' | ||
input.namespaces.clear() | ||
input.items.clear() | ||
} |
@@ -100,5 +100,3 @@ import { Tree, TreeUseItem, TreeUseNamespace } from '../tree' | ||
for (const match of items) { | ||
if (!Tree.removeNode(input, Utils.aggregatedToPath(match.aggregated))) { | ||
console.log(match.aggregated, Utils.aggregatedToPath(match.aggregated)) | ||
} | ||
Tree.removeNode(input, Utils.aggregatedToPath(match.aggregated), 'item') | ||
} | ||
@@ -105,0 +103,0 @@ |
@@ -63,3 +63,3 @@ import { Tree, TreeUseItem, TreeUseNamespace } from '../tree' | ||
Tree.removeNode(input, parts) | ||
Tree.removeNode(input, parts, 'item') | ||
@@ -66,0 +66,0 @@ parts.pop() |
@@ -27,3 +27,3 @@ import { TreeUseItem, TreeUseNamespace } from '.' | ||
++indent | ||
const items = [...node.items.values()] | ||
const items = [...node.namespaces.values(), ...node.items.values()] | ||
for (const item of items) { | ||
@@ -45,3 +45,3 @@ enter(item) | ||
++indent | ||
const items = [...root.items.values()] | ||
const items = [...root.namespaces.values(), ...root.items.values()] | ||
for (const item of items) { | ||
@@ -48,0 +48,0 @@ enter(item) |
@@ -13,10 +13,8 @@ import { Modifier, Path } from '../types' | ||
case '*': | ||
for (const item of node.items.values()) { | ||
if (item.type === 'namespace') { | ||
yield* executePattern( | ||
item, | ||
pattern.slice(1), | ||
modifiers, | ||
) | ||
} | ||
for (const namespace of node.namespaces.values()) { | ||
yield* executePattern( | ||
namespace, | ||
pattern.slice(1), | ||
modifiers, | ||
) | ||
} | ||
@@ -26,13 +24,13 @@ break | ||
case '**': | ||
for (const item of node.namespaces.values()) { | ||
yield* executePattern( | ||
item, | ||
['**'], | ||
modifiers, | ||
) | ||
} | ||
for (const item of node.items.values()) { | ||
if (item.type === 'namespace') { | ||
yield* executePattern( | ||
item, | ||
['**'], | ||
modifiers, | ||
) | ||
} else { | ||
if (modifiers.length === 0 || modifiers.some(it => it === item.modifier)) { | ||
yield item | ||
} | ||
if (modifiers.length === 0 || modifiers.some(it => it === item.modifier)) { | ||
yield item | ||
} | ||
@@ -43,4 +41,4 @@ } | ||
default: | ||
const item = node.items.get(pattern[0]) | ||
if (item && item.type === 'namespace') { | ||
const item = node.namespaces.get(pattern[0]) | ||
if (item) { | ||
yield* executePattern( | ||
@@ -47,0 +45,0 @@ item, |
@@ -5,13 +5,9 @@ import { TreeUseItem, TreeUseNamespace } from '.' | ||
export default function* flatten(node: TreeUseNamespace): Generator<TreeUseItem> { | ||
for (const subnode of node.items.values()) { | ||
switch (subnode.type) { | ||
case 'namespace': | ||
yield* flatten(subnode) | ||
break | ||
for (const namespace of node.namespaces.values()) { | ||
yield* flatten(namespace) | ||
} | ||
case 'item': | ||
yield subnode | ||
break | ||
} | ||
for (const item of node.items.values()) { | ||
yield item | ||
} | ||
} |
@@ -11,2 +11,3 @@ import { FlatUseItem } from '../flat' | ||
aggregated: '', | ||
namespaces: new Map(), | ||
items: new Map(), | ||
@@ -32,2 +33,3 @@ count: 0, | ||
aggregated: aggregatedPath, | ||
namespaces: new Map(), | ||
items: new Map(), | ||
@@ -37,3 +39,3 @@ count: 0, | ||
namespaces.set(aggregatedPath, namespace) | ||
parent.items.set(slice, namespace) | ||
parent.namespaces.set(slice, namespace) | ||
} | ||
@@ -40,0 +42,0 @@ |
@@ -6,8 +6,8 @@ import { Path } from '..' | ||
export default (tree: TreeUseNamespace, path: Path): boolean => { | ||
export default (tree: TreeUseNamespace, path: Path, type: 'item' | 'namespace'): boolean => { | ||
let node = tree | ||
for (const item of path.slice(0, -1)) { | ||
const next = node.items.get(item) | ||
const next = node.namespaces.get(item) | ||
if (!next || next.type !== 'namespace') { | ||
if (!next) { | ||
return false | ||
@@ -19,4 +19,14 @@ } | ||
if (!node.items.delete(path[path.length - 1])) { | ||
return false | ||
switch (type) { | ||
case 'namespace': | ||
if (!node.namespaces.delete(path[path.length - 1])) { | ||
return false | ||
} | ||
break | ||
case 'item': | ||
if (!node.items.delete(path[path.length - 1])) { | ||
return false | ||
} | ||
break | ||
} | ||
@@ -28,5 +38,5 @@ | ||
for (const item of path.slice(0, -1)) { | ||
const next = node.items.get(item) | ||
const next = node.namespaces.get(item) | ||
if (!next || next.type !== 'namespace') { | ||
if (!next) { | ||
return false | ||
@@ -38,3 +48,3 @@ } | ||
if (next.count === 0) { | ||
node.items.delete(item) | ||
node.namespaces.delete(item) | ||
break | ||
@@ -41,0 +51,0 @@ } |
@@ -8,3 +8,4 @@ import { Modifier } from '..' | ||
aggregated: string; | ||
items: Map<string, TreeUseNamespace | TreeUseItem>; | ||
namespaces: Map<string, TreeUseNamespace>; | ||
items: Map<string, TreeUseItem>; | ||
count: number; | ||
@@ -11,0 +12,0 @@ }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
208118
3382