josephschmitt/Clamp.js

useNativeClamp: false is broken

php4fan opened this issue · 3 comments

When using useNativeClamp: false I get this error:

clamp.js:117 Uncaught TypeError: Cannot read properties of null (reading 'children')

In getLastChild(elem):

            if (elem.lastChild.children && elem.lastChild.children.length > 0) {
                return getLastChild(Array.prototype.slice.call(elem.children).pop());
            }

Is this supposed to be:

            if (elem.lastChild && elem.lastChild.children && elem.lastChild.children.length > 0) {
                return getLastChild(Array.prototype.slice.call(elem.children).pop());
            }

or

            if (elem.children && elem.children.length > 0) {
                return getLastChild(Array.prototype.slice.call(elem.children).pop());
            }

?

Looks more likely to be the latter.

Also here:

            //This is the absolute last child, a text node, but something's wrong with it. Remove it and keep trying
            else if (!elem.lastChild || !elem.lastChild.nodeValue || elem.lastChild.nodeValue == '' || elem.lastChild.nodeValue == opt.truncationChar) {
                elem.lastChild.parentNode.removeChild(elem.lastChild); ///////////////// 1
                return getLastChild(element);                          ///////////////// 2
            }
  1. This throws error "cannot read property parentNode of null..." if elem.lastChild is null which is a possibility and does happen
  2. I'm pretty sure you mean elem, not element

Oh shit I'm wasting my time, this project hasn't been touched in 9 years.