From ccacd42b3706267b704f370f1044eb1ca7f5286c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Mon, 14 Nov 2022 11:22:35 +0100 Subject: [PATCH] fix(editor): Skip optional chaining operators in Code Node editor linting (#4592) * :bug: Skip optional chaining operators * :zap: Wrap in try-catch --- .../editor-ui/src/components/CodeNodeEditor/linter.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/editor-ui/src/components/CodeNodeEditor/linter.ts b/packages/editor-ui/src/components/CodeNodeEditor/linter.ts index 0660ee2a8c..439aba0215 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/linter.ts +++ b/packages/editor-ui/src/components/CodeNodeEditor/linter.ts @@ -30,6 +30,15 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({ } catch (syntaxError) { let line; + try { + const lineAtError = editorView.state.doc.line(syntaxError.lineNumber - 1).text; + + // optional chaining operators currently unsupported by esprima-next + if (['?.', ']?'].some((operator) => lineAtError.includes(operator))) return []; + } catch (_) { + return []; + } + try { line = editorView.state.doc.line(syntaxError.lineNumber); @@ -41,7 +50,7 @@ export const linterExtension = (Vue as CodeNodeEditorMixin).extend({ message: this.$locale.baseText('codeNodeEditor.linter.bothModes.syntaxError'), }, ]; - } catch (error) { + } catch (_) { /** * For invalid (e.g. half-written) n8n syntax, esprima errors with an off-by-one line number for the final line. In future, we should add full linting for n8n syntax before parsing JS. */