These changes could be moved to https://github.com/caitp/angular.js/blob/64bd86728b88c55f68de7619b8897a64c94ebea6/src/ng/compile.js#L1676 if it's not desirable to put this directly in `replaceWith()`