From 7aa8d4719f2e682cc48a3de679bd3ea09016ff6f Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Mon, 12 Jul 2021 18:08:45 +0000 Subject: [PATCH] [ci] yarn format --- docs/core-concepts/astro-components.md | 37 ++++++++++--------- .../astro/src/internal/__astro_component.ts | 12 +++--- packages/astro/src/internal/__astro_slot.ts | 6 +-- packages/astro/test/astro-slots.test.js | 2 - 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/docs/core-concepts/astro-components.md b/docs/core-concepts/astro-components.md index 1be0d631e..e8722468a 100644 --- a/docs/core-concepts/astro-components.md +++ b/docs/core-concepts/astro-components.md @@ -136,7 +136,7 @@ const { greeting = 'Hello', name } = Astro.props; ``` -Slots are especially powerful when using **named slots**. Rather than a single `` element which renders _all_ children, named slots allow you to specify where certain children should be placed. +Slots are especially powerful when using **named slots**. Rather than a single `` element which renders _all_ children, named slots allow you to specify where certain children should be placed. > **Note** The `slot` attribute is not restricted to plain HTML, components can use `slot` as well! @@ -205,25 +205,26 @@ Inside of an expression, you must wrap multiple elements in a Fragment. Fragment `.astro` files can end up looking very similar to `.jsx` files, but there are a few key differences. Here's a comparison between the two formats. -| Feature | Astro | JSX | -| ---------------------------- | ------------------------------------------ | -------------------------------------------------- | -| File extension | `.astro` | `.jsx` or `.tsx` | -| User-Defined Components | `` | `` | -| Expression Syntax | `{}` | `{}` | -| Spread Attributes | `{...props}` | `{...props}` +| Feature | Astro | JSX | +| ----------------------- | --------------- | ---------------- | +| File extension | `.astro` | `.jsx` or `.tsx` | +| User-Defined Components | `` | `` | +| Expression Syntax | `{}` | `{}` | +| Spread Attributes | `{...props}` | `{...props}` | + | -| Children | `` (with named slot support) | `children` +| Children | `` (with named slot support) | `children` | -| Boolean Attributes | `autocomplete` === `autocomplete={true}` | `autocomplete` === `autocomplete={true}` | -| Inline Functions | `{items.map(item =>
  • {item}
  • )}` | `{items.map(item =>
  • {item}
  • )}` | -| IDE Support | WIP - [VS Code][code-ext] | Phenomenal | -| Requires JS import | No | Yes, `jsxPragma` (`React` or `h`) must be in scope | -| Fragments | Automatic top-level, `<>` inside functions | Wrap with `` or `<>` | -| Multiple frameworks per-file | Yes | No | -| Modifying `` | Just use `` | Per-framework (``, ``, etc) | -| Comment Style | `` | `{/* JavaScript */}` | -| Special Characters | ` ` | `{'\xa0'}` or `{String.fromCharCode(160)}` | -| Attributes | `dash-case` | `camelCase` | +| Boolean Attributes | `autocomplete` === `autocomplete={true}` | `autocomplete` === `autocomplete={true}` | +| Inline Functions | `{items.map(item =>
  • {item}
  • )}` | `{items.map(item =>
  • {item}
  • )}` | +| IDE Support | WIP - [VS Code][code-ext] | Phenomenal | +| Requires JS import | No | Yes, `jsxPragma` (`React` or `h`) must be in scope | +| Fragments | Automatic top-level, `<>` inside functions | Wrap with `` or `<>` | +| Multiple frameworks per-file | Yes | No | +| Modifying `` | Just use `` | Per-framework (``, ``, etc) | +| Comment Style | `` | `{/* JavaScript */}` | +| Special Characters | ` ` | `{'\xa0'}` or `{String.fromCharCode(160)}` | +| Attributes | `dash-case` | `camelCase` | ### URL resolution diff --git a/packages/astro/src/internal/__astro_component.ts b/packages/astro/src/internal/__astro_component.ts index ff1d2ff54..6738600e3 100644 --- a/packages/astro/src/internal/__astro_component.ts +++ b/packages/astro/src/internal/__astro_component.ts @@ -113,9 +113,9 @@ const getComponentName = (Component: any, componentProps: any) => { } }; -const prepareSlottedChildren = (children: string|Record[]) => { +const prepareSlottedChildren = (children: string | Record[]) => { const $slots: Record = { - default: '' + default: '', }; for (const child of children) { if (typeof child === 'string') { @@ -127,9 +127,9 @@ const prepareSlottedChildren = (children: string|Record[]) => { } return { $slots }; -} +}; -const removeSlottedChildren = (_children: string|Record[]) => { +const removeSlottedChildren = (_children: string | Record[]) => { let children = ''; for (const child of _children) { if (typeof child === 'string') { @@ -140,7 +140,7 @@ const removeSlottedChildren = (_children: string|Record[]) => { } return children; -} +}; /** The main wrapper for any components in Astro files */ export function __astro_component(Component: any, metadata: AstroComponentMetadata = {} as any) { @@ -190,4 +190,4 @@ export function __astro_component(Component: any, metadata: AstroComponentMetada const astroRoot = `${html}`; return [astroRoot, script].join('\n'); }; -}; +} diff --git a/packages/astro/src/internal/__astro_slot.ts b/packages/astro/src/internal/__astro_slot.ts index c049e82bc..a719fa297 100644 --- a/packages/astro/src/internal/__astro_slot.ts +++ b/packages/astro/src/internal/__astro_slot.ts @@ -1,9 +1,9 @@ /** */ -export function __astro_slot_content({ name }: { name: string}, ...children: any[]) { - return { '$slot': name, children }; +export function __astro_slot_content({ name }: { name: string }, ...children: any[]) { + return { $slot: name, children }; } -export const __astro_slot = ({ name = 'default' }: { name: string}, _children: any, ...fallback: string[]) => { +export const __astro_slot = ({ name = 'default' }: { name: string }, _children: any, ...fallback: string[]) => { if (name === 'default' && typeof _children === 'string') { return _children ? _children : fallback; } diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.js index 343244910..69944a437 100644 --- a/packages/astro/test/astro-slots.test.js +++ b/packages/astro/test/astro-slots.test.js @@ -63,7 +63,6 @@ Slots('Slots work with multiple elements', async ({ runtime }) => { assert.equal($('#a').text(), 'ABC'); }); - Slots('Slots work on Components', async ({ runtime }) => { const result = await runtime.load('/component'); if (result.error) throw new Error(result.error); @@ -75,5 +74,4 @@ Slots('Slots work on Components', async ({ runtime }) => { assert.equal($('#default').children('astro-component').length, 1, 'Slotted component into default slot'); }); - Slots.run();