Skip to content

Commit

Permalink
fix invalid test #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 20, 2023
1 parent 9e3e2a2 commit 711a7ee
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
3 changes: 2 additions & 1 deletion dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -4667,7 +4667,8 @@
}

function expand(ast) {
if (!['AstRule', 'AstRuleStyleSheet', 'AstAtRule'].includes(ast.typ)) {
//
if (!['Rule', 'StyleSheet', 'AtRule'].includes(ast.typ)) {
return ast;
}
if ('Rule' == ast.typ) {
Expand Down
3 changes: 2 additions & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4665,7 +4665,8 @@ function* walkValues(values, parent) {
}

function expand(ast) {
if (!['AstRule', 'AstRuleStyleSheet', 'AstAtRule'].includes(ast.typ)) {
//
if (!['Rule', 'StyleSheet', 'AtRule'].includes(ast.typ)) {
return ast;
}
if ('Rule' == ast.typ) {
Expand Down
3 changes: 2 additions & 1 deletion dist/lib/ast/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import '../renderer/utils/color.js';
import { walkValues } from './walk.js';

function expand(ast) {
if (!['AstRule', 'AstRuleStyleSheet', 'AstAtRule'].includes(ast.typ)) {
//
if (!['Rule', 'StyleSheet', 'AtRule'].includes(ast.typ)) {
return ast;
}
if ('Rule' == ast.typ) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ast/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {walkValues} from "./walk";
import {renderToken} from "../renderer";

export function expand(ast: AstNode): AstNode {

if (!['AstRule', 'AstRuleStyleSheet', 'AstAtRule'].includes(ast.typ)) {
//
if (!['Rule', 'StyleSheet', 'AtRule'].includes(ast.typ)) {

return ast;
}
Expand Down
42 changes: 21 additions & 21 deletions test/specs/expand.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* generate from test/specs/nesting.spec.ts */
import {expect as f} from '../../node_modules/@esm-bundle/chai/esm/chai.js';
import {transform, render, expand} from '../../dist/node/index.js';
import {parse, render} from '../../dist/node/index.js';

describe('flatten nested css rules', function () {
it('flatten #1', function () {
Expand All @@ -11,9 +11,9 @@ describe('flatten nested css rules', function () {
&Bar { color: red; }
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.foo {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.foo {
color: blue
}
Bar.foo {
Expand All @@ -35,9 +35,9 @@ Bar.foo {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.header {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.header {
background-color: blue
}
.header p {
Expand All @@ -60,9 +60,9 @@ Bar.foo {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.foo {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.foo {
display: grid
}
@media (orientation:landscape) {
Expand All @@ -82,9 +82,9 @@ Bar.foo {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.foo {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.foo {
display: grid
}
@media (orientation:landscape) {
Expand All @@ -108,9 +108,9 @@ Bar.foo {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.foo {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.foo {
display: grid
}
@media (orientation:landscape) {
Expand Down Expand Up @@ -139,9 +139,9 @@ html {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`@layer base {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`@layer base {
html {
block-size: 100%
}
Expand All @@ -167,9 +167,9 @@ html {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`@layer base {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`@layer base {
html {
block-size: 100%
}
Expand All @@ -194,9 +194,9 @@ html {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.card {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.card {
inline-size: 40ch;
aspect-ratio: 3/4
}
Expand All @@ -214,9 +214,9 @@ html {
&& { padding: 2ch; }
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`.foo {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`.foo {
color: blue
}
.foo.foo {
Expand All @@ -238,9 +238,9 @@ html {
}
}
`;
return transform(nesting1, {
return parse(nesting1, {
minify: true, nestingRules: true
}).then((result) => f(render(expand(result.ast), {minify: false}).code).equals(`@scope (.card) to (>header) {
}).then((result) => f(render(result.ast, {minify: false, expandNestingRules: true}).code).equals(`@scope (.card) to (>header) {
:scope {
inline-size: 40ch;
aspect-ratio: 3/4
Expand Down

0 comments on commit 711a7ee

Please sign in to comment.