fix: textArr join error in syntaxChecker (#307)

This commit is contained in:
Kristin Aoki
2023-04-14 16:28:16 -04:00
committed by GitHub
parent 1d2a4c212d
commit 405003045c
2 changed files with 9 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ export const cleanHTML = ({ initialText }) => {
export const syntaxChecker = ({ textArr, lang }) => {
const diagnostics = [];
if (lang === 'xml') {
if (lang === 'xml' && textArr) {
const docString = textArr.join('\n');
const xmlDoc = `<?xml version="1.0" encoding="UTF-8"?> ${docString}`;
@@ -70,7 +70,7 @@ export const createCodeMirrorDomNode = ({
languageExtension,
EditorView.lineWrapping,
linter((view) => {
const textArr = view.docView.view.viewState.state.doc.text;
const textArr = view.state.doc.text;
return syntaxChecker({ textArr, lang });
}),
],

View File

@@ -123,6 +123,13 @@ describe('CodeEditor', () => {
expect(diagnostics).toEqual([]);
});
});
describe('textArr is undefined', () => {
it('returns empty array', () => {
let textArr;
const diagnostics = hooks.syntaxChecker({ textArr, lang: 'html' });
expect(diagnostics).toEqual([]);
});
});
describe('lang equals xml', () => {
it('returns empty array', () => {
const textArr = ['<problem>', '<p>', 'this is some text', '</p>', '</problem>'];