@@ -159,6 +159,7 @@ export class BaseVariableResolver {
159159 variables . forEach ( variable => {
160160 const existingVariable = mergedVariables . find ( v =>
161161 v . name === variable . name && v . scope === variable . scope
162+ && ! v . usedBy && ! variable . usedBy
162163 ) ;
163164
164165 if ( existingVariable ) {
@@ -251,7 +252,7 @@ export class BaseVariableResolver {
251252 *
252253 * @async
253254 * @param {ModdleElement } element
254- * @returns {Array<ProcessVariable> } variables
255+ * @returns {Promise< Array<ProcessVariable> > } variables
255256 */
256257 async getVariablesForElement ( element ) {
257258 const bo = getBusinessObject ( element ) ;
@@ -261,14 +262,14 @@ export class BaseVariableResolver {
261262
262263 // (1) get variables for given scope
263264 var scopeVariables = allVariables . filter ( function ( variable ) {
264- return variable . scope . id === bo . id ;
265+ return variable . scope && variable . scope . id === bo . id ;
265266 } ) ;
266267
267268 // (2) get variables for parent scopes
268269 var parents = getParents ( bo ) ;
269270
270271 var parentsScopeVariables = allVariables . filter ( function ( variable ) {
271- return parents . find ( function ( parent ) {
272+ return variable . scope && parents . find ( function ( parent ) {
272273 return parent . id === variable . scope . id ;
273274 } ) ;
274275 } ) ;
@@ -294,6 +295,31 @@ export class BaseVariableResolver {
294295 return false ;
295296 } ) ;
296297 }
298+
299+ /**
300+ * Returns consumed variables for an element — variables
301+ * the element needs as input for its expressions and mappings.
302+ *
303+ * Uses `getVariables()` instead of `getVariablesForElement()` to
304+ * bypass the name-based deduplication that would drop requirement
305+ * entries for variables that also exist in ancestor scopes.
306+ *
307+ * @param {Object } element
308+ * @returns {Promise<Array<ProcessVariable>> }
309+ */
310+ async getConsumedVariablesForElement ( element ) {
311+ const allVariablesByRoot = await this . getVariables ( )
312+ . catch ( ( ) => {
313+ return { } ;
314+ } ) ;
315+
316+ const allVariables = Object . values ( allVariablesByRoot ) . flat ( ) ;
317+
318+ return allVariables . filter ( v =>
319+ v . usedBy && v . usedBy . length > 0
320+ && v . origin . length === 1 && v . origin [ 0 ] . id === element . id
321+ ) ;
322+ }
297323}
298324
299325BaseVariableResolver . $inject = [ 'eventBus' , 'bpmnjs' ] ;
0 commit comments