mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
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:
parent
e0ec5a6aa9
commit
ccacd42b37
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue