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

single / triggers syntax error in JSX #622

Open
1 task
garfieldnate opened this issue Nov 11, 2022 · 1 comment
Open
1 task

single / triggers syntax error in JSX #622

garfieldnate opened this issue Nov 11, 2022 · 1 comment
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@garfieldnate
Copy link

What version of astro are you using?

1.6.7

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

None

What package manager are you using?

npm, yarn

What operating system are you using?

Mac

Describe the Bug

In the linked example, I have an astro component where I'm trying to create a <ul> list in JSX by mapping over an array. I want to choose a section of the array using slice, and need to calculate the arguments using division.

The weird thing is: using a single division in the slice call results in a syntax error. The error is not highlighted in VS code, and the line/column given by Astro does not correspond to any line in the source astro component, so I don't know where exactly the issue is.

Also interesting: if you add another division in the slice call, the syntax error goes away. And if I use a division in an index operation instead of inside of a slice call, there is no syntax error. There's also no error if I use subtraction in the slice call. The behavior is very strange, and smells like an issue with string manipulation of source somewhere. Examples below:

<!-- These work fine: -->
<ul>{pokemon.slice(0,8).map(p => <li>{p.name}</li>)}</ul>
<ul>{pokemon.slice(0/1,8/2).map(p => <li>{p.name}</li>)}</ul><ul>{pokemon.slice(0,8-2).map(p => <li>{p.name}</li>)}</ul>
<ul>{pokemon[4/2].name}</ul>

<!-- These break: -->
<ul>{pokemon.slice(0/1,8).map(p => <li>{p.name}</li>)}</ul>
<ul>{pokemon.slice(0,8/2).map(p => <li>{p.name}</li>)}</ul>

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

cc @natemoo-re compiler related

@matthewp matthewp transferred this issue from withastro/astro Nov 11, 2022
@Princesseuh Princesseuh added the needs triage Issue needs to be triaged label Nov 12, 2023
@MoustaphaDev MoustaphaDev added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Dec 19, 2023
@MoustaphaDev MoustaphaDev self-assigned this Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants