Skip to content

Commit

Permalink
Allow double quotes in map keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatiello authored and civan committed Mar 26, 2019
1 parent 6aded63 commit aece166
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/app/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const VARIABLE_PATERN = '(?!\\d)[\\w_-][\\w\\d_-]*';
const VALUE_PATERN = '[^;]+|"(?:[^"]+|(?:\\\\"|[^"])*)"';
const DECLARATION_PATTERN =
`\\$'?(${VARIABLE_PATERN})'?\\s*:\\s*(${VALUE_PATERN})(?:\\s*!(global|default)\\s*;|\\s*;(?![^\\{]*\\}))`;
`\\$['"]?(${VARIABLE_PATERN})['"]?\\s*:\\s*(${VALUE_PATERN})(?:\\s*!(global|default)\\s*;|\\s*;(?![^\\{]*\\}))`;

const MAP_DECLARATIOM_REGEX = /['"]?((?!\d)[\w_-][\w\d_-]*)['"]?\s*:\s*([^,)\/]+)/gi;

const MAP_DECLARATIOM_REGEX = /'?((?!\d)[\w_-][\w\d_-]*)'?\s*:\s*([^,)\/]+)/gi;
const QUOTES_PATTERN = /^(['"]).*\1$/;
const QUOTES_REPLACE = /^(['"])|(['"])$/g;

Expand All @@ -21,21 +22,20 @@ export class Parser {
this.rawContent = rawContent;
}


public parse(): IDeclaration[] {
let matches = this.extractDeclarations(this.rawContent);
let declarations = [];

for (let match of matches) {
if (!this.checkIsSectionStart(match) && !this.checkIsSectionStart(match)) {
let parsed = this.parseSingleDecaration(match);
let parsed = this.parseSingleDeclaration(match);

if (parsed) {
let map = this.extractMapDeclarations(parsed.value);

// in case the variable is a sass map
if (map.length) {
parsed.mapValue = map.map((declaration) => this.parseSingleDecaration(`$${declaration};`));
parsed.mapValue = map.map((declaration) => this.parseSingleDeclaration(`$${declaration};`));
}

declarations.push(parsed);
Expand Down Expand Up @@ -69,14 +69,14 @@ export class Parser {
} else if (this.checkIsSectionEnd(match)) {
currentSection = DEFAULT_SECTION;
} else {
let parsed = this.parseSingleDecaration(match);
let parsed = this.parseSingleDeclaration(match);

if (parsed) {
let map = this.extractMapDeclarations(parsed.value);

// in case the variable is a sass map
if (map.length) {
parsed.mapValue = map.map((declaration) => this.parseSingleDecaration(`$${declaration};`));
parsed.mapValue = map.map((declaration) => this.parseSingleDeclaration(`$${declaration};`));
}

declarations[currentSection].push(parsed);
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Parser {
}


private parseSingleDecaration(matchDeclaration: string): IDeclaration {
private parseSingleDeclaration(matchDeclaration: string): IDeclaration {
let matches = matchDeclaration
.replace(/\s*!(default|global)\s*;/, ';')
.match(new RegExp(DECLARATION_PATTERN));
Expand Down

0 comments on commit aece166

Please sign in to comment.