embroider-build / content-tag

A rust program that uses my swc fork to parse GJS
MIT License
7 stars 7 forks source link

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

Closed mansona closed 9 months ago

mansona commented 10 months ago

Look at this file and port over the tests.

patricklx commented 10 months ago

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 commented 10 months ago

This is required to unblock Glint: https://github.com/typed-ember/glint/pull/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

ef4 commented 9 months ago

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

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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.

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