Skip to content

Commit

Permalink
add ROADMAP.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 24, 2023
1 parent 5f267fe commit 01d5d86
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/errors.txt
/syntax.txt
/ROADMAP.draft.md

# Logs
logs
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/benchmark
/tools
/ROADMAP.md
/ROADMAP.draft.md
/rollup.config.mjs
/tsconfig.json
/src
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $ npm install @tbela99/css-parser
- efficient minification, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
- replace @import at-rules with actual css content of the imported rule
- automatically generate nested css rules
- compute css shorthands. see the list
- expand nested css
- works the same way in node and web browser

Expand Down
59 changes: 59 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

## v0.0.1

### Minification

- [x] merge identical rules
- [x] merge adjacent rules
- [x] minify colors
- [x] minify numbers and Dimensions tokens
- [x] compute shorthand: see the list below
- [x] remove redundant declarations
- [x] simple shorthand properties (padding, margin, etc). must have all required properties
- [x] complex shorthand properties (background, font, etc.). may have optional properties
- [x] conditionally unwrap :is()
- [x] automatic css nesting
- [x] automatically wrap selectors using :is()
- [x] multi-level shorthand properties (border - [border-width, border-color, border-style, etc.]) https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
- [x] avoid reparsing (declarations, selectors, at-rule)
- [x] node and browser versions
- [x] decode and replace utf-8 escape sequence

### Computed shorthands
- [x] background
- [x] border
- [x] border-bottom
- [x] border-color
- [x] border-left
- [x] border-radius
- [x] border-right
- [x] border-style
- [x] border-top
- [x] border-width
- [x] font
- [x] inset
- [x] margin
- [x] outline
- [x] overflow
- [x] padding
- [x] text-decoration

### Performance
- [x] flatten @import

### Error handling
- [x] parse bad comments / cdo comments
- [x] parse bad string 1
- [x] parse bad string 2
- [x] parse empty declaration
- [x] parse unclosed rule
- [x] parse unclosed at-rule
- [x] parse bad import

# Testing
- [x] node tests
- [x] browser tests

# Code Coverage
- [x] node
- [x] browser
8 changes: 1 addition & 7 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@
}
let key;
for (key of k1) {
if (!eq(a[key], b[key])) {
if (!(key in b) || !eq(a[key], b[key])) {
return false;
}
}
Expand Down Expand Up @@ -3897,10 +3897,6 @@
const result = [];
if (ast.typ == 'Rule') {
let i = 0;
// @ts-ignore
delete ast.raw;
// @ts-ignore
delete ast.optimized;
for (; i < ast.chi.length; i++) {
if (ast.chi[i].typ == 'Rule') {
const rule = ast.chi[i];
Expand All @@ -3915,8 +3911,6 @@
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
}
delete rule.raw;
delete rule.optimized;
ast.chi.splice(i--, 1);
result.push(...expandRule(rule));
}
Expand Down
8 changes: 1 addition & 7 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ function eq(a, b) {
}
let key;
for (key of k1) {
if (!eq(a[key], b[key])) {
if (!(key in b) || !eq(a[key], b[key])) {
return false;
}
}
Expand Down Expand Up @@ -3895,10 +3895,6 @@ function expandRule(node) {
const result = [];
if (ast.typ == 'Rule') {
let i = 0;
// @ts-ignore
delete ast.raw;
// @ts-ignore
delete ast.optimized;
for (; i < ast.chi.length; i++) {
if (ast.chi[i].typ == 'Rule') {
const rule = ast.chi[i];
Expand All @@ -3913,8 +3909,6 @@ function expandRule(node) {
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
}
delete rule.raw;
delete rule.optimized;
ast.chi.splice(i--, 1);
result.push(...expandRule(rule));
}
Expand Down
6 changes: 0 additions & 6 deletions dist/lib/ast/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ function expandRule(node) {
const result = [];
if (ast.typ == 'Rule') {
let i = 0;
// @ts-ignore
delete ast.raw;
// @ts-ignore
delete ast.optimized;
for (; i < ast.chi.length; i++) {
if (ast.chi[i].typ == 'Rule') {
const rule = ast.chi[i];
Expand All @@ -70,8 +66,6 @@ function expandRule(node) {
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
}
delete rule.raw;
delete rule.optimized;
ast.chi.splice(i--, 1);
result.push(...expandRule(rule));
}
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/parser/utils/eq.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function eq(a, b) {
}
let key;
for (key of k1) {
if (!eq(a[key], b[key])) {
if (!(key in b) || !eq(a[key], b[key])) {
return false;
}
}
Expand Down
26 changes: 9 additions & 17 deletions src/lib/ast/expand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AstAtRule, AstNode, AstRule, AstRuleStyleSheet} from "../../@types";
import {AstAtRule, AstNode, AstRule, AstRuleStyleSheet, Token} from "../../@types";
import {combinators, splitRule} from "./minify";
import {parseString} from "../parser";
import {walkValues} from "./walk";
Expand Down Expand Up @@ -65,23 +65,18 @@ export function expand(ast: AstNode): AstNode {

function expandRule(node: AstRule): Array<AstRule | AstAtRule> {

const ast = <AstRule>{...node, chi: node.chi.slice()};
const ast: AstRule = <AstRule>{...node, chi: node.chi.slice()};
const result: Array<AstRule | AstAtRule> = [];

if (ast.typ == 'Rule') {

let i = 0;

// @ts-ignore
delete ast.raw;
// @ts-ignore
delete ast.optimized;
let i:number = 0;

for (; i < ast.chi.length; i++) {

if (ast.chi[i].typ == 'Rule') {

const rule = <AstRule>(<AstRule>ast).chi[i];
const rule: AstRule = <AstRule>(<AstRule>ast).chi[i];

if (!rule.sel.includes('&')) {

Expand All @@ -99,16 +94,13 @@ function expandRule(node: AstRule): Array<AstRule | AstAtRule> {
rule.sel = replaceCompound(rule.sel, ast.sel);
}

delete rule.raw;
delete rule.optimized;

ast.chi.splice(i--, 1);

result.push(...<AstRule[]>expandRule(rule));
} else if (ast.chi[i].typ == 'AtRule') {


let astAtRule = <AstAtRule>ast.chi[i];
let astAtRule: AstAtRule = <AstAtRule>ast.chi[i];
const values = <Array<AstRule | AstAtRule>>[];

if (astAtRule.nam == 'scope') {
Expand All @@ -125,7 +117,7 @@ function expandRule(node: AstRule): Array<AstRule | AstAtRule> {
else {

// @ts-ignore
const clone = <AstRule>{...ast, chi: astAtRule.chi.slice()};
const clone: AstRule = <AstRule>{...ast, chi: astAtRule.chi.slice()};

// @ts-ignore
astAtRule.chi.length = 0;
Expand Down Expand Up @@ -174,7 +166,7 @@ function expandRule(node: AstRule): Array<AstRule | AstAtRule> {

export function replaceCompound(input: string, replace: string) {

const tokens = parseString(input);
const tokens: Token[] = parseString(input);

for (const t of walkValues(tokens)) {

Expand All @@ -197,7 +189,7 @@ function replaceCompoundLiteral(selector: string, replace: string) {

const tokens: string[] = [''];

let i = 0;
let i: number = 0;

for (; i < selector.length; i++) {

Expand All @@ -219,5 +211,5 @@ function replaceCompoundLiteral(selector: string, replace: string) {
}

return b == '&' ? -1 : 0;
}).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
}).reduce((acc: string, curr: string) => acc + (curr == '&' ? replace : curr), '');
}
2 changes: 1 addition & 1 deletion src/lib/parser/utils/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function eq(a: { [key: string]: any }, b: { [key: string]: any }): boolea

for (key of k1) {

if (!eq(a[key], b[key])) {
if (!(key in b) || !eq(a[key], b[key])) {

return false;
}
Expand Down

0 comments on commit 01d5d86

Please sign in to comment.