mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00: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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user