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

test: add test for Astro components #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unindented
Copy link

Which issue does this PR address?

Repro for #22

@nikku
Copy link
Owner

nikku commented Feb 27, 2025

Thanks for the PR! It allowed me to investigate this issue.

I checked what eslint-astro-parser generates as a syntax tree, parsing the source code file you provided:

---
const name = 'world';
---

<h1>Hello {name}!</h1>

The AST visible to this plug-in (and hence the one the plug-in derives it's magic and/or builds on top) is the following:

<ref *2> Node {
  type: 'Program',
  loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 0 } },
  range: [ 0, 54, [length]: 2 ],
  body: [
    <ref *1> Node {
      type: 'VariableDeclaration',
      loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 21 } },
      range: [ 4, 25, [length]: 2 ],
      declarations: [
        Node {
          type: 'VariableDeclarator',
          loc: [Object],
          range: [Array],
          id: [Node],
          init: [Node],
          [start]: [Getter],
          [end]: [Getter],
          parent: [Circular *1]
        },
        [length]: 1
      ],
      kind: 'const',
      [start]: [Getter],
      [end]: [Getter],
      parent: [Circular *2]
    },
    <ref *3> Node {
      type: 'AstroFragment',
      loc: { start: { line: 5, column: 0 }, end: { line: 6, column: 0 } },
      range: [ 31, 54, [length]: 2 ],
      children: [ ... ],
      [start]: [Getter],
      [end]: [Getter],
      parent: [Circular *2]
    },
    [length]: 2
  ]

You see that the first program node starts at character 4, behind the ---. The --- is available as Punctuation in the token list, but has no proper AST representation. Without any representation, and no way for the plug-in to find out about the context it operates in. So I'm afraid, we'll not be able to easily support .astro files.

You could ping back that question to the astro creators: How is consuming their parsers output supposed to work? Why do they hide the --- token? Svelte and Vue parsers don't hide essential information, hence allowing to detect their components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants