Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Hoisted exports break as const & satisfies <type> #863

Open
bb010g opened this issue Sep 13, 2023 · 1 comment
Open

🐛 BUG: Hoisted exports break as const & satisfies <type> #863

bb010g opened this issue Sep 13, 2023 · 1 comment
Labels
- P2: has workaround Bug, but has workaround (priority)

Comments

@bb010g
Copy link

bb010g commented Sep 13, 2023

What version of @astrojs/compiler are you using?

2.1.0

What package manager are you using?

pnpm

What operating system are you using?

Windows

Describe the Bug

HoistExports in //internal/js_scanner/js_scanner.go fails to account for some TypeScript syntax when lexing.

Both of the following exported expressions will be split incorrectly, each resulting in a syntax error:

export const foo = {
} as const;

export const bar = {
} satisfies object;

Here's the compiled output for the following .astro source:

---
// Unhoisted comment.
export const bar = {
} as const satisfies object;
---
<div>Astro</div>
import {
  Fragment,
  render as $$render,
  createAstro as $$createAstro,
  createComponent as $$createComponent,
  renderComponent as $$renderComponent,
  renderHead as $$renderHead,
  maybeRenderHead as $$maybeRenderHead,
  unescapeHTML as $$unescapeHTML,
  renderSlot as $$renderSlot,
  mergeSlots as $$mergeSlots,
  addAttribute as $$addAttribute,
  spreadAttributes as $$spreadAttributes,
  defineStyleVars as $$defineStyleVars,
  defineScriptVars as $$defineScriptVars,
  renderTransition as $$renderTransition,
  createTransitionScope as $$createTransitionScope,
  createMetadata as $$createMetadata
} from "astro/runtime/server/index.js";


export const $$metadata = $$createMetadata("/Users/astro/Code/project/src/pages/foo.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });

const $$Astro = $$createAstro();
const Astro = $$Astro;
export const bar = {
}
const $$Foo = $$createComponent(async ($$result, $$props, $$slots) => {
const Astro = $$result.createAstro($$Astro, $$props, $$slots);
Astro.self = $$Foo;

// Unhoisted comment.
 as const satisfies object;


return $$render`${$$maybeRenderHead($$result)}<div>Astro</div>`;
}, '/Users/astro/Code/project/src/pages/foo.astro', undefined);
export default $$Foo;

You can see that as const satisfies object; isn't hoisted along with the rest of the exported expression.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-vlvcmq

@Princesseuh Princesseuh added the needs triage Issue needs to be triaged label Nov 12, 2023
@MoustaphaDev
Copy link
Member

Related #878

@MoustaphaDev MoustaphaDev added the - P2: has workaround Bug, but has workaround (priority) label Dec 19, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority)
Projects
None yet
Development

No branches or pull requests

3 participants