@@ -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 } ) ;
@@ -299,6 +300,30 @@ export class BaseVariableResolver {
299300 throw new Error ( 'not implemented VariableResolver#_getScope' ) ;
300301 }
301302
303+ /**
304+ * Returns consumed variables for an element — variables
305+ * the element needs as input for its expressions and mappings.
306+ *
307+ * Uses `getVariables()` instead of `getVariablesForElement()` to
308+ * bypass the name-based deduplication that would drop requirement
309+ * entries for variables that also exist in ancestor scopes.
310+ *
311+ * @param {Object } element
312+ * @returns {Promise<Array<ProcessVariable>> }
313+ */
314+ async getConsumedVariablesForElement ( element ) {
315+ const allVariablesByRoot = await this . getVariables ( )
316+ . catch ( ( ) => {
317+ return { } ;
318+ } ) ;
319+
320+ const allVariables = Object . values ( allVariablesByRoot ) . flat ( ) ;
321+
322+ return allVariables . filter ( v =>
323+ v . usedBy && v . usedBy . length > 0
324+ && v . origin . length === 1 && v . origin [ 0 ] . id === element . id
325+ ) ;
326+ }
302327}
303328
304329BaseVariableResolver . $inject = [ 'eventBus' , 'bpmnjs' ] ;
0 commit comments