Skip to content

Commit

Permalink
feat: Support escaped characters in composed class names (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed May 7, 2020
1 parent e3519b1 commit 6cd4d8a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ Object {
},
}
`;

exports[`/processor.js composition should compose with escaped classes 1`] = `
Object {
"escaped-classes.css": Object {
"c": "sm:foo c",
"sm:foo": "sm:foo",
},
}
`;
16 changes: 16 additions & 0 deletions packages/processor/test/composition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,21 @@ describe("/processor.js", () => {

expect(compositions).toMatchSnapshot();
});

it("should compose with escaped classes", async () => {
await processor.string(
"./escaped-classes.css",
dedent(`
.sm\\:foo { color: red; }
.c {
composes: sm\\:foo;
}
`)
);

const { compositions } = await processor.output();

expect(compositions).toMatchSnapshot();
});
});
});
24 changes: 23 additions & 1 deletion parsers/shared.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@ s "string"
= "\"" chars:[^\"\r\n]* "\"" { return chars.join(""); }
/ "\'" chars:[^\'\r\n]* "\'" { return chars.join(""); }


hex_digit
= [0-9a-f]i

nonascii
= [\x80-\uFFFF]

unicode
= "\\" digits:$(hex_digit hex_digit? hex_digit? hex_digit? hex_digit? hex_digit?) ("\r\n" / [ \t\r\n\f])? {
return String.fromCharCode(parseInt(digits, 16));
}

escape
= unicode
/ "\\" char:[^\r\n\f0-9a-f]i { return char; }

nmchar
= [_a-z0-9-]i
/ nonascii
/ escape


// Partials

// wooga
ident "identifier"
= chars:[a-z0-9-_]i+ { return chars.join(""); }
= chars:nmchar+ { return chars.join(""); }

global_keyword "global"
= "global"
Expand Down

0 comments on commit 6cd4d8a

Please sign in to comment.