fix(editor): Skip optional chaining operators in Code Node editor linting (#4592)

* 🐛 Skip optional chaining operators

*  Wrap in try-catch
This commit is contained in:
Iván Ovejero 2022-11-14 11:22:35 +01:00 committed by GitHub
parent e0ec5a6aa9
commit ccacd42b37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
*/