-
Notifications
You must be signed in to change notification settings - Fork 51
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
Use content-tag
instead of ember-template-imports
#655
Conversation
9de2b1b
to
83f87c7
Compare
|
||
// TODO: is there a way to convert bytes to chars? | ||
// I think maybe all of this code needs to live in content-tag, | ||
// and give us the option to generate this sort of structure | ||
templateLocations.push({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all likely wrong, as the original code used character-indices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still likely wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, char positions are expected, but I only have bytes here, so whenever there is a multi-byte character, where the errors show up may be offset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how it is currently done in eslint parser:
https://github.com/NullVoxPopuli/ember-eslint-parser/blob/d1b8796436670e496f4a21de8b1a9d9219038b66/src/parser/transforms.js#L25
You need also the original string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, I'll try that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -6461,7 +6466,7 @@ ember-template-imports@^1.1.1: | |||
ember-cli-version-checker "^5.1.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above here, more reason to have glint not depend on content-tag:
=> Found "[email protected]"
info Reasons this module exists
- "_project_#@glint#environment-glimmerx#@glimmerx#component" depends on it
- Hoisted from "_project_#@glint#environment-glimmerx#@glimmerx#component#ember-template-imports"
yarn.lock
Outdated
@@ -6461,7 +6466,7 @@ ember-template-imports@^1.1.1: | |||
ember-cli-version-checker "^5.1.2" | |||
validate-peer-dependencies "^1.1.0" | |||
|
|||
ember-template-imports@^3.0.0, ember-template-imports@^3.1.1: | |||
ember-template-imports@^3.1.1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This'll soon be removed from ember-template lint as well:
=> Found "ember-template-lint#[email protected]"
info This module exists because "_project_#ts-ember-app#ember-template-lint" depends on it.
info Disk size without dependencies: "232KB"
I'm marking as ready for review, as I think this is about at the point, where I want to make sure I'm not doing anything crazy. There is still a failing test: https://github.com/typed-ember/glint/actions/runs/7254626609/job/19763687113?pr=655#step:6:107 cc @dfreeman @wagenet @gitKrystan Some things left for this PR tho:
|
} catch (e) { | ||
if (typeof e === 'object' && e !== null) { | ||
// Parse Errors from the rust parser | ||
if ('source_code' in e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful for content-tag to emit this error as a JSON object or something (maybe a property on the already emitted error?) so I don't have to parse the error-string here.
// | ||
// https://github.com/embroider-build/content-tag/blob/v1.2.2-content-tag/package.json#L13-L21 | ||
// | ||
// @ts-expect-error see above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though this ts-expect-error is here, we still get the correct type for Preprocessor
and p.parse
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I wonder why I don't get this in the prettier plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it using 1.2.2 / same tsconfig settings from glint?
let sourceOffsetBytes = 0; | ||
let deltaBytes = 0; | ||
|
||
// @ts-expect-error TS couldn't find @types/node, which are specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk why this couldn't be found
let endTagLength = template.end[0].length; | ||
let startTagOffset = start.index ?? -1; | ||
let endTagOffset = end.index ?? -1; | ||
let startTagLengthBytes = template.startRange.end - template.startRange.start; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added Bytes
to all the variables here as a suffix to keep the units straight.
See also: embroider-build/content-tag#45
* SEE: https://github.com/embroider-build/content-tag/issues/39#issuecomment-1832443310 | ||
*/ | ||
let prefixingSegment = sourceBuffer.slice(sourceOffsetBytes, startTagOffsetBytes); | ||
segments.push(prefixingSegment.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to not do this segments stuff?
@dfreeman since content-tag can transform to valid JS, could we just parse that instead?
I believe this is what @patricklx may have run in to in the past as well while iterating on the eslint parser, we need a pre-transform to post-transform index mapping for all AST nodes
|
||
// @ts-expect-error TS couldn't find @types/node, which are specified | ||
// in the root package.json | ||
let sourceBuffer = Buffer.from(source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://runkit.com/nullvoxpopuli/content-tag-byte-vs-char-offsets for a brief overview of how Buffer
solves the byte-index vs char-index issue.
(As well as embroider-build/content-tag#45 )
I like this changes! We definitely need to push it forward and land it! Works just fine inside custom glint env https://github.com/lifeart/glimmer-next/tree/master/glint-environment-gxt |
83f87c7
to
781ad32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok. I still don't have 100% context.
|
||
if (startTagOffset === -1 || endTagOffset === -1) continue; | ||
// if (startTagOffset === -1 || endTagOffset === -1) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, can do
|
||
// TODO: is there a way to convert bytes to chars? | ||
// I think maybe all of this code needs to live in content-tag, | ||
// and give us the option to generate this sort of structure | ||
templateLocations.push({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still likely wrong?
`ember-template-imports`. Resolves: typed-ember#609 Resolves: typed-ember#706 Resolves: typed-ember#694
cb694bf
to
8223b1a
Compare
@@ -11,6 +11,6 @@ | |||
"composite": true, | |||
"declaration": true, | |||
"sourceMap": true, | |||
"types": [] | |||
"types": ["@types/node"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change was needed so that the types for Buffer
existed
{ "path": "packages/vscode" }, | ||
{ "path": "packages/scripts" }, | ||
{ "path": "test-packages/test-utils" } | ||
{ "path": "./packages/core" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in one of the commits, it's explained that this change was needed so that you can ctrl+click to go to each of these tsconfigs.
It's kinda silly that tsc works with both path-formats but vscode only works with leading ./
ember-template-imports @ v4
removed all the APIs that glint was relying on for working with<template>
-tagsResolves: #609
Resolves: #706
Resolves: #694
Blocked by: embroider-build/content-tag#19Blocked by: embroider-build/content-tag#31Unblocks: NullVoxPopuli/polaris-starter#11
Supersedes: #615
Extractions:
Allows:
<pm> add ember-template-imports
in their apps and not have to downgrade to v3 if they want to use Glint