Skip to content

Context of parent gets overwritten #2

Description

@RaenonX

Input

const tree = treeifyPaths([
  ['parent', {name: 'a'}],
  ['parent/child1/1', {name: 'b'}],
  ['parent/child2', {name: 'c'}],
  ['parent/child2/1', {name: 'd'}],
  ['parent/child3', {name: 'e'}],
  ['parent/child4', {name: 'f'}],
  ['another', {name: 'g'}],
  ['another/child1/A/B', {name: 'h'}],
  ['another/child2/A/B', {name: 'i'}],
]);

console.log(JSON.stringify(tree, null, 3));

Output

{
   "path": "",
   "name": "",
   "children": [
      {
         "path": "another",
         "name": "another",
         "children": [
            {
               "path": "another/child1",
               "name": "",
               "children": [
                  {
                     "path": "another/child1/A",
                     "name": "",
                     "children": [
                        {
                           "path": "another/child1/A/B",
                           "name": "B",
                           "children": [],
                           "ctx": {
                              "name": "h"
                           }
                        }
                     ],
                     "ctx": {
                        "name": "h"
                     }
                  }
               ],
               "ctx": {
                  "name": "h"
               }
            },
            {
               "path": "another/child2",
               "name": "",
               "children": [
                  {
                     "path": "another/child2/A",
                     "name": "",
                     "children": [
                        {
                           "path": "another/child2/A/B",
                           "name": "B",
                           "children": [],
                           "ctx": {
                              "name": "i"
                           }
                        }
                     ],
                     "ctx": {
                        "name": "i"
                     }
                  }
               ],
               "ctx": {
                  "name": "i"
               }
            }
         ],
         "ctx": {
            "name": "i"
         }
      },
      {
         "path": "parent",
         "name": "parent",
         "children": [
            {
               "path": "parent/child1",
               "name": "",
               "children": [
                  {
                     "path": "parent/child1/1",
                     "name": "1",
                     "children": [],
                     "ctx": {
                        "name": "b"
                     }
                  }
               ],
               "ctx": {
                  "name": "b"
               }
            },
            {
               "path": "parent/child2",
               "name": "child2",
               "children": [
                  {
                     "path": "parent/child2/1",
                     "name": "1",
                     "children": [],
                     "ctx": {
                        "name": "d"
                     }
                  }
               ],
               "ctx": {
                  "name": "d"
               }
            },
            {
               "path": "parent/child3",
               "name": "child3",
               "children": [],
               "ctx": {
                  "name": "e"
               }
            },
            {
               "path": "parent/child4",
               "name": "child4",
               "children": [],
               "ctx": {
                  "name": "f"
               }
            }
         ],
         "ctx": {
            "name": "f"
         }
      }
   ]
}

Expected

  • ctx with path = another and name = another should be g but not i.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions