Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/app/converter/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Converter class', () => {
results = converter.getArray();
});

it('should include variables form both files', () => {
it('should include variables from both files', () => {
let foundFirst = Utils.getDeclarationByName(results, '$brand-solitude');
expect(foundFirst.value).to.equal('#ebeff2');

Expand Down Expand Up @@ -122,15 +122,19 @@ describe('Converter class', () => {
});

describe('includePaths support', () => {
const opts = { inputFiles: [path.resolve('./test/scss/_with-import.scss')], includePaths: [] };
opts.includePaths = [path.resolve('./test/scss/')];
const converter = new Converter(opts);
const structured = converter.getStructured();

it('should import variables from other files', () => {
let opts = { inputFiles: [path.resolve('./test/scss/_with-import.scss')], includePaths: [] };
opts.includePaths = [path.resolve('./test/scss/')];
let converter = new Converter(opts);
let structured = converter.getStructured();

expect(structured.variables[0]).to.have.property('compiledValue');
});

it('should parse map imports from other files', () => {
expect(structured.variables[1].mapValue[0].mapValue[0]).to.have.property('compiledValue');
expect(structured.variables[1].mapValue[0].mapValue[0].name).to.be.equal('breakpoints');
});
});

describe('path patterns support', () => {
Expand Down
25 changes: 24 additions & 1 deletion src/app/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Converter {

if (declaration.mapValue) {
declaration.mapValue.map((mapDeclaration) => {
mapDeclaration.compiledValue = this.renderPropertyValue(content, mapDeclaration, true);
this.compileMapStructure(mapDeclaration);
return mapDeclaration;
});
}
Expand All @@ -80,6 +80,29 @@ export class Converter {
return this.checkForMixins(structuredDeclaration);
}

private compileMapStructure(structuredDeclaration: IDeclaration)
{
let content = this.getContent();
var parser = new Parser(content);

// set compiledValue
structuredDeclaration.compiledValue = this.renderPropertyValue(content, structuredDeclaration, true);

// set mapValue
let map = parser.extractMapDeclarations(structuredDeclaration.compiledValue);
if (map.length) {
structuredDeclaration.mapValue = map.map((declaration) => {
const singleDeclaration = parser.parseSingleDeclaration(
`$${declaration};`,
true
);
this.compileMapStructure(singleDeclaration);

return singleDeclaration;
});
}
}


public getContent(): string {
let inputFiles = [];
Expand Down
4 changes: 2 additions & 2 deletions src/app/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Parser {
return matches as any;
}

private extractMapDeclarations(content: string): [any] {
public extractMapDeclarations(content: string): [any] {
const matches = content.match(new RegExp(MAP_DECLARATIOM_REGEX, 'g'));

if (!matches) {
Expand All @@ -107,7 +107,7 @@ export class Parser {
}


private parseSingleDeclaration(matchDeclaration: string, isMap: boolean = false): IDeclaration {
public parseSingleDeclaration(matchDeclaration: string, isMap: boolean = false): IDeclaration {
let matches = matchDeclaration
.replace(/\s*!(default|global)\s*;/, ';')
.match(new RegExp(this.getDeclarationPattern(isMap)));
Expand Down
6 changes: 6 additions & 0 deletions test/scss/_maps.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ $levels: (
500: 0,
900: 80%
);

$container-map: (
'breakpoints': $bps,
'icons': $icons,
'levels': $levels
);
8 changes: 7 additions & 1 deletion test/scss/_with-import.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@import "breakpoints";
@import "maps";

$imported-value: $bp-desktop;
$imported-value: $bp-desktop;

$imported-maps: (
"container-map-copy": $container-map,
"bps-copy": $bps
);