Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Deep clone diagnostic objects #76

Merged
merged 1 commit into from
May 11, 2021

Conversation

spahnke
Copy link
Contributor

@spahnke spahnke commented Mar 17, 2021

Fixes microsoft/monaco-editor#2392

Before this change the ts.Diagnostic objects internal to TypeScript were mutated. This was fine when the file property was cleared completely, but broke with #74 where we kept the fileName. The method computeLineStarts in typescriptServices.js then gets a parameter which is undefined (the source text of the file) causing the exception in the issue.

I tested with the code from the issue, the use-case from #74 and the original use-case from #48.

~line 8874 in out/amd/lib/typescriptServices.js

function computeLineStarts(text) { // text is now undefined
        var result = new Array();
        var pos = 0;
        var lineStart = 0;
        while (pos < text.length) {
            var ch = text.charCodeAt(pos);
            pos++;
            switch (ch) {
                case 13 /* carriageReturn */:
                    if (text.charCodeAt(pos) === 10 /* lineFeed */) {
                        pos++;
                    }
                // falls through
                case 10 /* lineFeed */:
                    result.push(lineStart);
                    lineStart = pos;
                    break;
                default:
                    if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) {
                        result.push(lineStart);
                        lineStart = pos;
                    }
                    break;
            }
        }
        result.push(lineStart);
        return result;
    }

@alexdima
Copy link
Member

Thank you!

@alexdima alexdima merged commit e9fb83d into microsoft:main May 11, 2021
@alexdima alexdima added this to the April 2021 milestone May 11, 2021
@alexdima alexdima self-assigned this May 11, 2021
@spahnke spahnke deleted the related-diagnostic-fix branch June 1, 2021 08:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'length' of undefined
2 participants