Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pgoldrbx opened this issue Oct 23, 2017 · 0 comments
Open

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

pgoldrbx opened this issue Oct 23, 2017 · 0 comments

Comments

@pgoldrbx
Copy link
Contributor

pgoldrbx commented Oct 23, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant