Skip to content

Commit 6cf0323

Browse files
authored
feat: support @container (#2127)
1 parent e09acfc commit 6cf0323

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@
6161
}
6262
```
6363

64+
* Add support for the new `@container` CSS rule ([#2127](https://github.com/evanw/esbuild/pull/2127))
65+
66+
This release adds support for [`@container`](https://drafts.csswg.org/css-contain-3/#container-rule) in CSS files. This means esbuild will now pretty-print and minify these rules better since it now better understands the internal structure of these rules:
67+
68+
```css
69+
/* Original code */
70+
@container (width <= 150px) {
71+
#inner {
72+
color: yellow;
73+
}
74+
}
75+
76+
/* Old output (with --minify) */
77+
@container (width <= 150px){#inner {color: yellow;}}
78+
79+
/* New output (with --minify) */
80+
@container (width <= 150px){#inner{color:#ff0}}
81+
```
82+
83+
This was contributed by [@yisibl](https://github.com/yisibl).
84+
6485
## 0.14.30
6586

6687
* Change the context of TypeScript parameter decorators ([#2147](https://github.com/evanw/esbuild/issues/2147))
@@ -508,7 +529,7 @@
508529

509530
* Remove simplified statement-level literal expressions ([#2063](https://github.com/evanw/esbuild/issues/2063))
510531

511-
With this release, esbuild now removes simplified statement-level expressions if the simplified result is a literal expression even when minification is disabled. Previously this was only done when minification is enabled. This change was only made because some people are bothered by seeing top-level literal expressions. This change has no effect on code behavior.
532+
With this release, esbuild now removes simplified statement-level expressions if the simplified result is a literal expression even when minification is disabled. Previously this was only done when minification is enabled. This change was only made because some people are bothered by seeing top-level literal expressions. This change has no effect on code behavior.
512533

513534
* Ignore `.d.ts` rules in `paths` in `tsconfig.json` files ([#2074](https://github.com/evanw/esbuild/issues/2074), [#2075](https://github.com/evanw/esbuild/pull/2075))
514535

@@ -5452,7 +5473,7 @@ In addition to the breaking changes above, the following features are also inclu
54525473

54535474
* Fix some obscure TypeScript type parsing edge cases
54545475

5455-
In TypeScript, type parameters come after a type and are placed in angle brackets like `Foo<T>`. However, certain built-in types do not accept type parameters including primitive types such as `number`. This means `if (x as number < 1) {}` is not a syntax error while `if (x as Foo < 1) {}` is a syntax error. This release changes TypeScript type parsing to allow type parameters in a more restricted set of situations, which should hopefully better resolve these type parsing ambiguities.
5476+
In TypeScript, type parameters come after a type and are placed in angle brackets like `Foo<T>`. However, certain built-in types do not accept type parameters including primitive types such as `number`. This means `if (x as number < 1) {}` is not a syntax error while `if (x as Foo < 1) {}` is a syntax error. This release changes TypeScript type parsing to allow type parameters in a more restricted set of situations, which should hopefully better resolve these type parsing ambiguities.
54565477

54575478
## 0.10.2
54585479

internal/css_parser/css_parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ var specialAtRules = map[string]atRuleKind{
700700
"styleset": atRuleDeclarations,
701701
"stylistic": atRuleDeclarations,
702702
"swash": atRuleDeclarations,
703+
704+
// Container Queries
705+
// Reference: https://drafts.csswg.org/css-contain-3/#container-rule
706+
"container": atRuleInheritContext,
703707
}
704708

705709
type atRuleValidity uint8

internal/css_parser/css_parser_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,32 @@ func TestAtRule(t *testing.T) {
870870
}
871871
`)
872872

873+
// https://drafts.csswg.org/css-contain-3/#container-rule
874+
expectPrinted(t, `
875+
@container my-layout (inline-size > 45em) {
876+
.foo {
877+
color: skyblue;
878+
}
879+
}
880+
`, `@container my-layout (inline-size > 45em) {
881+
.foo {
882+
color: skyblue;
883+
}
884+
}
885+
`)
886+
expectPrintedMinify(t, `@container card ( inline-size > 30em ) and style( --responsive = true ) {
887+
.foo {
888+
color: skyblue;
889+
}
890+
}`, "@container card (inline-size > 30em) and style(--responsive = true){.foo{color:skyblue}}")
891+
expectPrintedMangleMinify(t, `@supports ( container-type: size ) {
892+
@container ( width <= 150px ) {
893+
#inner {
894+
background-color: skyblue;
895+
}
896+
}
897+
}`, "@supports (container-type: size){@container (width <= 150px){#inner{background-color:#87ceeb}}}")
898+
873899
// https://drafts.csswg.org/css-counter-styles/#the-counter-style-rule
874900
expectPrinted(t, `
875901
@counter-style box-corner {

0 commit comments

Comments
 (0)