Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

fix: support legal comments #143

Merged
Merged
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: 9 additions & 7 deletions packages/critters/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* the License.
*/

import path from 'path';
import { readFile } from 'fs';
import { createDocument, serializeDocument } from './dom';
import path from 'path';
import {
applyMarkedSelectors,
markOnly,
parseStylesheet,
serializeStylesheet,
validateMediaQuery,
walkStyleRules,
walkStyleRulesWithReverseMirror,
markOnly,
applyMarkedSelectors,
validateMediaQuery
} from './css';
import { createLogger, isSubpath } from './util';

Expand Down Expand Up @@ -495,10 +495,12 @@ export default class Critters {
ast,
markOnly((rule) => {
if (rule.type === 'comment') {
const comment = rule.text.trim();
// we might want to remove a leading ! on comment blocks
// critters can be part of "legal comments" which aren't striped on build
const crittersComment = rule.text.match(/^(?<!\! )critters:(.*)/);
const command = crittersComment && crittersComment[1];

if (comment.startsWith('critters')) {
const command = comment.replace(/^critters:/, '');
if (command) {
switch (command) {
case 'include':
includeNext = true;
Expand Down
7 changes: 6 additions & 1 deletion packages/critters/test/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ footer {
border-bottom: transparent solid 2px;
}

/*! critters:include */
.other-element::part(tab) {
color: #0c0dcc;
border-bottom: transparent solid 2px;
}

.custom-element::part(tab):hover {
background-color: #0c0d19;
color: #ffffff;
Expand All @@ -64,7 +70,6 @@ footer {
}
/* critters:include end */


.custom-element::part(active) {
color: #0060df;
border-color: #0a84ff !important;
Expand Down
Loading