Skip to content

Why does utils.appendChild allow an empty parent array? #11

Open
@pgoldrbx

Description

@pgoldrbx

When writing tests for the utils methods, I came across some logic that was confusing:
https://github.com/benjycui/jsonml.js/blob/master/lib/utils.js#L132

} else if (child || !parent.length) {
  // append
  parent.push(child);

This allows for some unclear behavior, particularly when allowing exception for a parent with no length.

  1. append a child to an empty parent array
const jml = [];
utils.appendChild(jml, '');
// jml === ['']
const jml = []; 
utils.appendChild(jml, ['p', 'hello']);
// jml === [ ['p', 'hello'] ]

Is this a real use case or an edge case bug? I'm guessing this would never be desired and should probably not be allowed.

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