Skip to content

Commit

Permalink
Revert "fix(compiler): Support dynamic slot names (#9605)" (#9999)
Browse files Browse the repository at this point in the history
* Revert "fix(compiler): Support dynamic slot names (#9605)"

This reverts commit 8ce40a4.

* chore: changeset

* Update .changeset/weak-pans-sit.md

* chore: bump compiler version

* fix failing test

We were expecting the source code to produce an error, but in
2.4.0 of the compiler, that generates valid code

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
  • Loading branch information
MoustaphaDev and Princesseuh committed Feb 6, 2024
1 parent 56db6ae commit c53a313
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-pans-sit.md
@@ -0,0 +1,5 @@
---
"astro": patch
---

Rollbacks the feature which allowed to dynamically generate slots with variable slot names due to unexpected regressions.
2 changes: 1 addition & 1 deletion packages/astro/package.json
Expand Up @@ -114,7 +114,7 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^2.5.0",
"@astrojs/compiler": "^2.5.3",
"@astrojs/internal-helpers": "workspace:*",
"@astrojs/markdown-remark": "workspace:*",
"@astrojs/telemetry": "workspace:*",
Expand Down
5 changes: 1 addition & 4 deletions packages/astro/src/runtime/server/index.ts
Expand Up @@ -45,11 +45,8 @@ import { addAttribute, Renderer } from './render/index.js';

export function mergeSlots(...slotted: unknown[]) {
const slots: Record<string, () => any> = {};
for (let slot of slotted) {
for (const slot of slotted) {
if (!slot) continue;
if (Array.isArray(slot)) {
slot = mergeSlots(...slot);
}
if (typeof slot === 'object') {
Object.assign(slots, slot);
} else if (typeof slot === 'function') {
Expand Down
20 changes: 0 additions & 20 deletions packages/astro/test/astro-slots.test.js
Expand Up @@ -30,26 +30,6 @@ describe('Slots', () => {
expect($('#default').text().trim()).to.equal('Default');
});

it('Dynamic named slots work with map work', async () => {
const html = await fixture.readFile('/dynamic-map/index.html');
const $ = cheerio.load(html);

expect($('#a').text().trim()).to.equal('A');
expect($('#b').text().trim()).to.equal('B');
expect($('#c').text().trim()).to.equal('C');
expect($('#default').text().trim()).to.equal('Default');
});

it('Dynamic named slots work with for loop', async () => {
const html = await fixture.readFile('/dynamic-for/index.html');
const $ = cheerio.load(html);

expect($('#a').text().trim()).to.equal('A');
expect($('#b').text().trim()).to.equal('B');
expect($('#c').text().trim()).to.equal('C');
expect($('#default').text().trim()).to.equal('Default');
});

it('Conditional named slots work', async () => {
const html = await fixture.readFile('/conditional/index.html');
const $ = cheerio.load(html);
Expand Down

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c53a313

Please sign in to comment.