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

Add an API for parse metadata so that content-tag can be used with eslint, prettier, and glint #19

Closed
mansona opened this issue Aug 29, 2023 · 6 comments · Fixed by #22

Comments

@mansona
Copy link
Member

mansona commented Aug 29, 2023

Look at this file and port over the tests.

  • copy tests over from ember-template-tag (a js implementation)
    • parseTemplates
      • parseTemplates does not exist in content-tag today
      • return shape in JS should be the same when implemented in content-tag
  • implement the code in content-tag that makes the above implemented tests pass
@patricklx
Copy link

patricklx commented Aug 29, 2023

What would also be needed is this:
https://github.com/patricklx/ember-template-tag/blob/48981bbdd682144403216f4b44e64d99d5504fd8/__tests__/preprocess-embedded-templates.test.ts#L44

This is so that offsets do not change anywhere

@NullVoxPopuli
Copy link
Contributor

This is required to unblock Glint: typed-ember/glint#615

turns out half the tooling out there needs line/col information.

Example: https://github.com/typed-ember/glint/blob/main/packages/environment-ember-template-imports/-private/environment/preprocess.ts#L18

@NullVoxPopuli NullVoxPopuli changed the title Create tests that emit the right metadata for linters Add an API for parse metadata so that content-tag can be used with eslint, prettier, and glint Sep 10, 2023
@NullVoxPopuli NullVoxPopuli pinned this issue Sep 10, 2023
@ef4
Copy link
Collaborator

ef4 commented Sep 15, 2023

I would add that: it would be fine to do an exact port of the existing parse API that just emits location information. But I'm pretty sure every place that uses that API also immediately follows up by slicing and dicing the source to replace the content tags.

So it would be even better to

  • make our preprocess accept an optional replacement callback that controls what we transpile the content tags into
  • make it emit relocation information alongside the transformed content

This would eliminate the need for other systems like glint or the eslint plugin to do their own source mangling after calling content-tag.

@patricklx
Copy link

I think ember template lint uses only location info.
Also, i do not think we need some callback transform.
It willl just complicate things. Since one needs to distinguish between class body and others.
We just need another format which can be parsed and does not change any location information around the templates.

@ef4
Copy link
Collaborator

ef4 commented Sep 15, 2023

I think ember template lint uses only location info.

No, ember-template-lint does exactly the kind of slicing I'm talking about in _applyFixes.

It willl just complicate things. Since one needs to distinguish between class body and others.

But this is the whole point of why we made content-tag. It already knows that difference! The proper place to detect that difference is in the parser. A lot of the way the existing system worked is hacks to get around the fact that the previous parser can't tell the difference, and we can get rid of those hacks now.

@patricklx
Copy link

Oh, i understand it wrong then.
You mean slice original source to extract template content? That's what the meta data of ember-templatr-tag also emits.

What do you mean by the replacement callback then? Maybe can you give an example, then i might understand it better.

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 a pull request may close this issue.

4 participants