From 98b6176c63aee07bd38400f449e2c2b1c8581e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 26 Aug 2015 16:54:40 +0200 Subject: [PATCH] Take references to other scopes into account when deconflicting. --- src/Scope.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Scope.js b/src/Scope.js index 1577d51..0e475ed 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -48,6 +48,18 @@ export default class Scope { deconflict ( rename = underscorePrefix ) { const names = this.used; + this.ids.filter( ref => ref instanceof Reference ).forEach( ref => { + // Same scope. + if ( ref.scope.ids === this.ids ) return; + + // Another scope! + while ( ref instanceof Reference ) { + ref = dereference( ref ); + } + + names[ ref.name ] = ref; + }); + this.ids.filter( isntReference ).forEach( id => { if ( typeof id === 'string' ) { throw new Error( `Required name ${id} undefined!` );