lezer-parser / highlight

Syntax highlighting from Lezer trees
MIT License
30 stars 9 forks source link

CodeMirror plugin crashed: TypeError: t is not iterable #14

Closed Bizarrus closed 3 weeks ago

Bizarrus commented 3 weeks ago

I've get following Error:

main.js:74 CodeMirror plugin crashed: TypeError: t is not iterable
    at rh.style (index.js:261:29)
    at index.js:278:33
    at Yl.highlightRange (index.js:365:22)
    at Wl (index.js:306:13)
    at hh.buildDeco (index.js:1773:13)
    at new hh (index.js:1751:33)
    at Ji.create (index.js:2478:42)
    at tn.update (index.js:2497:44)
    at new Jr (index.js:7413:20)
    at ux.init (main.js:74:22)

On Following Line (Builded):

function tagHighlighter(tags, options) {
    let map = Object.create(null);
    for (let style of tags) {
        if (!Array.isArray(style.tag))
            map[style.tag.id] = style.class;
        else
            for (let tag of style.tag)
                map[tag.id] = style.class;
    }
    let { scope, all = null } = options || {};
    return {
        style: (tags) => {
            let cls = all;
            for (let tag of tags) { /// <<<<<<<<<<<<<<<<<<<< Here
                for (let sub of tag.set) {
                    let tagClass = map[sub.id];
                    if (tagClass) {
                        cls = cls ? cls + " " + tagClass : tagClass;
                        break;
                    }
                }
            }
            return cls;
        },
        scope
    };
}

When i wrap the tags-Loop with a check:

if(typeof(tags) !== 'undefined') {
    for (let tag of tags) {
        // [....]
    }
}

The script works.

Line that is involved: https://github.com/lezer-parser/highlight/blob/95aa69ecd22bfc8b3e1c793610e0d5cda1174e61/src/highlight.ts#L249-L251

The Source-Code of these problem can be found here: https://github.com/fruithost/Panel/default/js/codemirror

[!NOTE] Build Instructions:

// Clone the Repo git clone https://github.com/fruithost/Panel.git

// Go to the destination folder cd Panel/default/js/codemirror/

// Install depencies npm install

// Build Editor npm start

Open the index.html from /src/ folder in Browser

marijnh commented 3 weeks ago

Using npm 10.8.0, that page works for me. If you're using an old npm, or yarn, you may have a messed up node_modules that duplicates some packages, keeping old versions alongside upgraded ones. That might lead to the result you're seeing.

Bizarrus commented 3 weeks ago

Im using:

npm -v
10.8.2

node -v
v22.5.1

Edit:

The problem is not the node or npm version. I've downgraded to npm 10.8.0. like you, the problem already exists.

marijnh commented 3 weeks ago

Well, I cannot reproduce it, regardless.

Bizarrus commented 3 weeks ago

Can you confirm the bug, when using @codemirror/view version 6.32.0?

I have now gone through all npm-packages and compared the versions. I had installed version 6.32.0 and have now changed this to version 6.33.0, apparently the error no longer occurs here?

marijnh commented 3 weeks ago

Nothing that could possibly be related to this changed between @codemirror/view 6.32.0 and 6.33.0. I suspect you just did a full reinstall and that fixed a duplication in your dependency tree. Anyway, closing the issue.