//
// Copyright IBM Corp. 2018, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

/// Used by `exports` mixin to track which modules have been imported
/// @type Map
/// @access public
/// @group @carbon/import-once
$imported-modules: () !default;

/// Module export mixin that helps making sure a module is imported once and only once
/// @access public
/// @param {String} $name - Name of exported module
/// @param {Bool} $warn [false] - Warn when a module has been already imported
/// @content Declaration blocks to be imported
/// @group @carbon/import-once
@mixin exports($name, $warn: false) {
  @if (index($imported-modules, $name) == null) {
    $imported-modules: append($imported-modules, $name) !global;
    @content;
  } @else if $warn == true {
    @warn 'Module `#{$name}` has already been imported.';
  }
}
