Skip to content
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Changelog

## v1.4.6

- [x] Fix if syntax expansion regression bug #134

## v1.4.5

- [x] Temporarily disable if syntax expansion
- [x] Temporarily disable if syntax expansion #131

## v1.4.4

### Validation changes

- [x] Added the `state` and `errors` properties to nodes to expose their validation status and any associated validation errors.
- [x] Added the `state` and `errors` properties to nodes to expose their validation status and any associated validation errors. #127
- [x] Nodes that fail validation are no longer discarded. Nodes are discarded only if they are invalid, unparsed, or malformed. Unknown nodes are discarded when lenient parsing is disabled.

### Color
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ $ deno add @tbela99/css-parser
## Syntax lowering
CSS-Parser can transform these modern CSS features into lower-level CSS syntax:
* **Nested CSS transpilation** to legacy-compatible syntax.
* **`if()` function transpilation** for broader browser compatibility.
* **`color-mix()` function conversion** convert new color-mix() syntax to any of the supported colors.

## Benchmark
Expand Down
25 changes: 0 additions & 25 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -12107,29 +12107,6 @@
if (!doNotValidate && !result?.success && result.errors.length > 0) {
errors.push(...result.errors);
}
if (!doNotValidate && !(success || result.success)) {
return Object.defineProperties(Object.assign(name, {
typ: exports.EnumToken.DeclarationNodeType,
nam: name.val,
val: parseTokens(tokens),
}), {
state: {
...definedPropertySettings,
value: exports.EnumAstNodeStatus.ValidationFailed,
},
errors: {
...definedPropertySettings,
value: result?.errors ?? [],
},
loc: {
...definedPropertySettings,
value: {
...name.loc,
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
},
},
});
}
}
}
for (i = 0; i < tokens.length; i++) {
Expand Down Expand Up @@ -30131,8 +30108,6 @@
if (options.resolveImport) {
options.resolveUrls = true;
}
// turn off expandIfSyntax for now
options.expandIfSyntax = false;
const startTime = performance.now();
const errors = [];
const src = options.src;
Expand Down
25 changes: 0 additions & 25 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9211,29 +9211,6 @@ function parseDeclaration(tokens, parent, options, errors) {
if (!doNotValidate && !result?.success && result.errors.length > 0) {
errors.push(...result.errors);
}
if (!doNotValidate && !(success || result.success)) {
return Object.defineProperties(Object.assign(name, {
typ: exports.EnumToken.DeclarationNodeType,
nam: name.val,
val: parseTokens(tokens),
}), {
state: {
...definedPropertySettings,
value: exports.EnumAstNodeStatus.ValidationFailed,
},
errors: {
...definedPropertySettings,
value: result?.errors ?? [],
},
loc: {
...definedPropertySettings,
value: {
...name.loc,
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
},
},
});
}
}
}
for (i = 0; i < tokens.length; i++) {
Expand Down Expand Up @@ -29896,8 +29873,6 @@ async function doParse(iter, options = {}) {
if (options.resolveImport) {
options.resolveUrls = true;
}
// turn off expandIfSyntax for now
options.expandIfSyntax = false;
const startTime = performance.now();
const errors = [];
const src = options.src;
Expand Down
2 changes: 0 additions & 2 deletions dist/lib/parser/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ async function doParse(iter, options = {}) {
if (options.resolveImport) {
options.resolveUrls = true;
}
// turn off expandIfSyntax for now
options.expandIfSyntax = false;
const startTime = performance.now();
const errors = [];
const src = options.src;
Expand Down
24 changes: 0 additions & 24 deletions dist/lib/parser/utils/declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { walkValues } from '../../ast/walk.js';
import { equalsIgnoreCase } from './text.js';
import { buildExpression } from '../../ast/math/expression.js';
import { splitTokenList } from '../../validation/utils/list.js';
import { parseTokens } from '../parse.js';

/**
*
Expand Down Expand Up @@ -333,29 +332,6 @@ function parseDeclaration(tokens, parent, options, errors) {
if (!doNotValidate && !result?.success && result.errors.length > 0) {
errors.push(...result.errors);
}
if (!doNotValidate && !(success || result.success)) {
return Object.defineProperties(Object.assign(name, {
typ: EnumToken.DeclarationNodeType,
nam: name.val,
val: parseTokens(tokens),
}), {
state: {
...definedPropertySettings,
value: EnumAstNodeStatus.ValidationFailed,
},
errors: {
...definedPropertySettings,
value: result?.errors ?? [],
},
loc: {
...definedPropertySettings,
value: {
...name.loc,
end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
},
},
});
}
}
}
for (i = 0; i < tokens.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion files/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ children:
- [Benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)

------
[About →](./about.md)
[Getting Started →](./getting-started.md)
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbela99/css-parser",
"version": "1.4.5",
"version": "1.4.6",
"publish": {
"include": [
"src",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tbela99/css-parser",
"description": "CSS parser, minifier and validator for node and the browser",
"version": "1.4.5",
"version": "1.4.6",
"exports": {
".": "./dist/node.js",
"./node": "./dist/node.js",
Expand Down
3 changes: 0 additions & 3 deletions src/lib/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,6 @@ export async function doParse(
options.resolveUrls = true;
}

// turn off expandIfSyntax for now
options.expandIfSyntax = false;

const startTime: number = performance.now();
const errors: ErrorDescription[] = [];
const src: string = options.src as string;
Expand Down
27 changes: 0 additions & 27 deletions src/lib/parser/utils/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,33 +451,6 @@ export function parseDeclaration(
if (!doNotValidate && !result?.success && result!.errors!.length > 0) {
errors.push(...result!.errors);
}

if (!doNotValidate && !(success || result!.success)) {
return Object.defineProperties(
Object.assign(name, {
typ: EnumToken.DeclarationNodeType,
nam: name.val,
val: parseTokens(tokens),
}),
{
state: {
...definedPropertySettings,
value: EnumAstNodeStatus.ValidationFailed,
},
errors: {
...definedPropertySettings,
value: result?.errors ?? [],
},
loc: {
...definedPropertySettings,
value: {
...name.loc,
end: tokens[tokens.length - 1]?.loc!.end ?? name.loc!.end,
},
},
},
) as AstDeclaration;
}
}
}

Expand Down
66 changes: 33 additions & 33 deletions test/specs/code/at-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,40 +1333,40 @@ supports((selector(h2 > p)) and (font-tech(color-COLRv1))) {



// it('do not minify supports() arguments #58', function () {
// return transform(`

// body {
// background-color: if(
// supports(color: oklch(0.7 0.185 232)): oklch(0.7 0.185 232);
// else: #00adf3;
// );
it('do not minify supports() arguments #58', function () {
return transform(`

body {
background-color: if(
supports(color: oklch(0.7 0.185 232)): oklch(0.7 0.185 232);
else: #00adf3;
);

// &::after {
// content: if(
// supports(color: oklch(0.7 0.185 232)): "Your browser supports OKLCH";
// else: "Your browser does not support OKLCH";
// );
// }
// }

// `, {
// beautify: true,
// expandIfSyntax: true,
// validation: true
// }).then((result) => expect(result.code).equals(`body {
// background-color: #00adf3;
// @supports (color:oklch(.7 .185 232)) {
// background-color: #00aefc
// }
// &:after {
// content: "Your browser does not support OKLCH";
// @supports (color:oklch(.7 .185 232)) {
// content: "Your browser supports OKLCH"
// }
// }
// }`));
// });
&::after {
content: if(
supports(color: oklch(0.7 0.185 232)): "Your browser supports OKLCH";
else: "Your browser does not support OKLCH";
);
}
}

`, {
beautify: true,
expandIfSyntax: true,
validation: true
}).then((result) => expect(result.code).equals(`body {
background-color: #00adf3;
@supports (color:oklch(.7 .185 232)) {
background-color: #00aefc
}
&:after {
content: "Your browser does not support OKLCH";
@supports (color:oklch(.7 .185 232)) {
content: "Your browser supports OKLCH"
}
}
}`));
});



Expand Down
Loading
Loading