astro icon indicating copy to clipboard operation
astro copied to clipboard

Astro transform fails on several forms of multiline exports

Open duanwilliam opened this issue 2 years ago • 0 comments

What version of astro are you using?

1.1.5

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

WSL2

Describe the Bug

(don't know if this should go in the compiler repo)

(Seems similar to the recently submitted #4600, but found independently and (I think) more accurate on reproduction / diagnosing the cause.)

Astro fails at parsing certain forms of multiline exports (not sure exactly why), some of which are not uncommon patterns.

For context, I encountered this bug when trying to define a Props interface for a component, that extended a subset of some other defined type:

export interface Props extends Pick<
    OtherType,
        | 'key1'
        | 'etc'
> {
    // ...
}

where I would consistently get an error message of

Transform failed with 1 error: [path/lineno/position]: ERROR: Expected ">" but found "$$[filename excluding extension]"

This error occurs not just for interfaces or generic types, but also for basic and union types if not on the same line as the export keyword (with slightly different expected/found in the error message):

export type Foo =
    'string'
export type UnionType =
    | 'foo'
    | 'bar'

It's not restricted to types, either:

export const foo =
    'foo'
export const noop =
    () => {}

Notably, these issues only occur relating to some part of the expression going to a new line, and only when the expression in question is being exported: if the export keyword is removed, the transform no longer fails. This can be seen in the minimal reproduction example.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-hmtihg-ej7ccx?file=src/pages/index.astro

Participation

  • [ ] I am willing to submit a pull request for this issue.

duanwilliam avatar Sep 04 '22 04:09 duanwilliam