mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(editor): Ensure full tree on expression editor parse (#5027)
🐛 Ensure full tree on expression editor parse
This commit is contained in:
parent
8881ba8d4a
commit
47854ebc36
|
@ -432,3 +432,5 @@ export enum STORES {
|
||||||
WEBHOOKS = 'webhooks',
|
WEBHOOKS = 'webhooks',
|
||||||
HISTORY = 'history',
|
HISTORY = 'history',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const EXPRESSION_EDITOR_PARSER_TIMEOUT = 15_000; // ms
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import mixins from 'vue-typed-mixins';
|
import mixins from 'vue-typed-mixins';
|
||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { syntaxTree } from '@codemirror/language';
|
import { ensureSyntaxTree, syntaxTree } from '@codemirror/language';
|
||||||
|
|
||||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||||
import { useNDVStore } from '@/stores/ndv';
|
import { useNDVStore } from '@/stores/ndv';
|
||||||
|
import { EXPRESSION_EDITOR_PARSER_TIMEOUT } from '@/constants';
|
||||||
|
|
||||||
import type { PropType } from 'vue';
|
import type { PropType } from 'vue';
|
||||||
import type { EditorView } from '@codemirror/view';
|
import type { EditorView } from '@codemirror/view';
|
||||||
|
@ -60,9 +61,17 @@ export const expressionManager = mixins(workflowHelpers).extend({
|
||||||
|
|
||||||
const rawSegments: RawSegment[] = [];
|
const rawSegments: RawSegment[] = [];
|
||||||
|
|
||||||
syntaxTree(this.editor.state)
|
const fullTree = ensureSyntaxTree(
|
||||||
.cursor()
|
this.editor.state,
|
||||||
.iterate((node) => {
|
this.editor.state.doc.length,
|
||||||
|
EXPRESSION_EDITOR_PARSER_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (fullTree === null) {
|
||||||
|
throw new Error(`Failed to parse expression: ${this.editor.state.doc.toString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullTree.cursor().iterate((node) => {
|
||||||
if (!this.editor || node.type.name === 'Program') return;
|
if (!this.editor || node.type.name === 'Program') return;
|
||||||
|
|
||||||
rawSegments.push({
|
rawSegments.push({
|
||||||
|
|
Loading…
Reference in a new issue