Skip to content

Commit

Permalink
fix(feature-targeting): prevent accidental nesting of mdc-feature-tar…
Browse files Browse the repository at this point in the history
…gets mixin (#4281)
  • Loading branch information
mmalerba authored and abhiomkar committed Jan 23, 2019
1 parent 67a1f18 commit 3405bc4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/mdc-feature-targeting/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@

@import "./functions";

// Tracks whether the current context is inside a `mdc-feature-targets` mixin.
$mdc-feature-targets-context_: false;

// Mixin that annotates the contained styles as applying to specific cross-cutting features
// indicated by the given list of feature targets.
@mixin mdc-feature-targets($feature-targets...) {
// Prevent accidental nesting of this mixin, which could lead to unexpected results.
@if $mdc-feature-targets-context_ {
@error "mdc-feature-targets must not be used inside of another mdc-feature-targets block";
}

$mdc-feature-targets-context_: true !global;
$parsed-targets: mdc-feature-parse-targets($feature-targets);

@if mdc-feature-is-query-satisfied_(map-get($parsed-targets, query), map-get($parsed-targets, available)) {
@content;
}

$mdc-feature-targets-context_: false !global;
}

0 comments on commit 3405bc4

Please sign in to comment.