Skip to content

Commit 997ff5f

Browse files
committed
incorrectly parse shorthand #6
1 parent e8dc908 commit 997ff5f

File tree

5 files changed

+139
-2
lines changed

5 files changed

+139
-2
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
/package-lock.json
1010
/node_modules
1111
/coverage
12-
/.github
12+
/.github
13+
/.gitattributes

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,62 @@ Single JavaScript file
160160
<script src="dist/index-umd-web.js"></script>
161161
```
162162

163+
## Example
164+
165+
### Automatic CSS Nesting
166+
167+
CSS
168+
169+
```css
170+
171+
table.colortable td {
172+
text-align:center;
173+
}
174+
table.colortable td.c {
175+
text-transform:uppercase;
176+
}
177+
table.colortable td:first-child, table.colortable td:first-child+td {
178+
border:1px solid black;
179+
}
180+
table.colortable th {
181+
text-align:center;
182+
background:black;
183+
color:white;
184+
}
185+
```
186+
187+
Javascript
188+
```javascript
189+
import {parse, render} from '@tbela99/css-parser';
190+
191+
192+
const options = {minify: true, nestingRules: true};
193+
194+
const {code} = await parse(css, options).then(result => render(result.ast, {minify: false}));
195+
//
196+
console.debug(code);
197+
```
198+
199+
Result
200+
```css
201+
table.colortable {
202+
& td {
203+
text-align: center;
204+
&.c {
205+
text-transform: uppercase
206+
}
207+
&:first-child,&:first-child+td {
208+
border: 1px solid #000
209+
}
210+
}
211+
& th {
212+
text-align: center;
213+
background: #000;
214+
color: #fff
215+
}
216+
}
217+
```
218+
163219
## AST
164220

165221
### Comment

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@types/mocha": "^10.0.1",
5151
"@types/node": "^20.4.10",
5252
"@web/test-runner": "^0.17.0",
53-
"@webref/css": "^6.6.2",
5453
"c8": "^8.0.1",
5554
"mocha": "^10.2.0",
5655
"rollup": "^3.28.0",

src/lib/parser/declaration/map.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class PropertyMap {
8282
continue;
8383
}
8484

85+
// @ts-ignore
8586
if (('propertyName' in acc[i] && acc[i].propertyName == property) || matchType(acc[i], props)) {
8687

8788
if ('prefix' in props && props.previous != null && !(props.previous in tokens)) {

test/specs/shorthand.spec.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* generate from test/specs/shorthand.spec.ts */
22
import { expect as f } from '../../node_modules/@esm-bundle/chai/esm/chai.js';
33
import { transform } from '../../dist/node/index.js';
4+
import {render} from "../../dist/index.js";
45

56
const options = {
67
minify: true,
@@ -234,4 +235,83 @@ border: #333 solid 1px;
234235
}
235236
`, options).then(result => f(result.code).equals('html{font:clamp(12px,.8rem + .25vw,20px)/1.7 Blanco,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}'));
236237
});
238+
239+
it('shorthand parsing #16', function () {
240+
return transform(`
241+
@media all {
242+
html {
243+
font-family: Blanco, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
244+
font-size: clamp(12px, 0.8rem + 0.25vw, 20px);
245+
font-weight: 400;
246+
line-height: 1.7;
247+
}
248+
}
249+
250+
button.jetpack-instant-search__overlay-close {
251+
align-items: center;
252+
appearance: none;
253+
background-image: none;
254+
background-position: initial;
255+
background-size: initial;
256+
background-repeat: initial;
257+
background-attachment: initial;
258+
background-origin: initial;
259+
background-clip: initial;
260+
border-top: none;
261+
border-right: none;
262+
border-left: none;
263+
border-image: initial;
264+
border-bottom: 1px solid rgb(230, 241, 245);
265+
border-radius: 0px;
266+
box-shadow: none;
267+
cursor: pointer;
268+
display: flex;
269+
height: 61px;
270+
justify-content: center;
271+
line-height: 1;
272+
margin: 0px;
273+
outline: none;
274+
padding: 0px;
275+
text-decoration: none;
276+
text-shadow: none;
277+
text-transform: none;
278+
width: 60px;
279+
background-color: transparent !important;
280+
}
281+
282+
`, options).then(result => f(render(result.ast, {minify: false}).code).equals(`html {
283+
font: clamp(12px,.8rem + .25vw,20px)/1.7 Blanco,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"
284+
}
285+
button.jetpack-instant-search__overlay-close {
286+
align-items: center;
287+
appearance: none;
288+
background-image: none;
289+
background-position: initial;
290+
background-size: initial;
291+
background-repeat: initial;
292+
background-attachment: initial;
293+
background-origin: initial;
294+
background-clip: initial;
295+
background-color: #0000 !important;
296+
border-top: none;
297+
border-right: none;
298+
border-left: none;
299+
border-image: initial;
300+
border-bottom: 1px solid #e6f1f5;
301+
border-radius: 0;
302+
box-shadow: none;
303+
cursor: pointer;
304+
display: flex;
305+
height: 61px;
306+
justify-content: center;
307+
line-height: 1;
308+
margin: 0;
309+
outline: none;
310+
padding: 0;
311+
text-decoration: none;
312+
text-shadow: none;
313+
text-transform: none;
314+
width: 60px
315+
}`));
316+
});
237317
});

0 commit comments

Comments
 (0)