sassdoc icon indicating copy to clipboard operation
sassdoc copied to clipboard

@requires autofill: multiple of the same dependency

Open DenisMir opened this issue 10 years ago • 5 comments
trafficstars

I have found the error that requires dependencies are getting referenced multiple times in the rendered output when some mixin is using some function multiple times.

/**
 * Some function that gets used from other mixins
 */
@function base() {}

/**
 * Some mixin that uses the `base` function multiple times
 */
@mixin fails() {
  base();
  base();
}

/**
* Some mixin that uses the `base` function multiple times
* @requires base
*/
@mixin works() {
  base();
  base();
}

Manually adding the @requires fixes the bug in this simple case. In more complex mixins this is not enough and I'm getting multiple dependencies all over.

An example can be found right here:

https://github.com/DenisMir/sassdoc-bugs/blob/master/src/requires-autofill-bug.scss

DenisMir avatar Dec 10 '14 15:12 DenisMir

This one is for @FWeinb.

KittyGiraudel avatar Dec 10 '14 15:12 KittyGiraudel

This should not happen because I am using lodash#uniq here. Will look into it.

FWeinb avatar Dec 10 '14 15:12 FWeinb

@FWeinb Any idea what's going on here?

KittyGiraudel avatar Dec 29 '14 08:12 KittyGiraudel

Found the issue. And fixed it on develop a994ed5c22b487f69d6aa8eb67fdc57ec70e77f3

FWeinb avatar Dec 29 '14 16:12 FWeinb

virtualbox_2017-07-10_20-22-58

From my testing, this is still a problem both with variables and with functions. Also its counting variables/functions on lines which are commented, so if you comment out a line with a variable/function, it will still be in Requires section...

Also, if function uses a variable as default parameter, its not in Requires section. I would argue, that its still required for the mixin/function to actually work properly...

Example code (the $base-font-size is 3x in Requires section and if you remove those not needed variables using it (and the commented one), it wont be there at all, even when its a default parameter):

@function calculateEm($size, $base-size: $base-font-size) {
    $random-thing: $base-font-size;
    $why-hello-again: $base-font-size;
    // $wait-what-no-way: $base-font-size;
    @return ($size / $base-size) * 1em;
}

MiChAeLoKGB avatar Jul 10 '17 18:07 MiChAeLoKGB