Skip to content

Conversation

@jdbrannon
Copy link

Since the parser does not have options for the included paths (paths to imported files), the imported variables are not compiled when converter.getStructured() invokes parser.parseStructured().

This is not an issue for imports that are top level variables. This is because the variable will be computed when invoking converter.renderPropertyValue() later on in the converter.compileStructure() method. However, an issue occurs for nested variables that are referenced from an external file. This is because the nested variable inside the map will not have knowledge about the contents of the imported map since the Parser does not have knowledge of the includedPaths.

Steps to reproduce:

  1. Create an SCSS file called _test-map.scss with the following contents
@use 'sass:color';

$map: (
  'palette': (
    'primary': (
      'main': blue,
      'light': color.scale(blue, $lightness: 15%),
      'dark': color.scale(blue, $lightness: -15%),
      'contrast-text': white,
    )
  )
);
  1. Create a file called test-import.scss with the following contents
@import './test-map';

$map-container: (
  $map-copy: $map
);
  1. Run "sass-export test-import.scss -d . -o test-import.json" to parse the test-import.scss file and see that it fails to parse the imported map variable
  2. Observe that while the output displays the full compiledValue, it does not flesh out the mapValue of the full nested map

This solves the issue by parsing the compiled value of a map property before evaluating if it is a nested map and then evaluating the contents of the nested map.

One downside to this method is that there are some methods in the Parser that had to be made public. And it would potentially be more efficient to handle the import logic within the parser and correctly parse the full path all in one shot. But that would require more restructuring and require passing in the includedPaths to the Parser.

There are also some other bugs with parsing/compiling maps that are not handled by this PR. Such as copying a map directly to another variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant