-
Notifications
You must be signed in to change notification settings - Fork 52
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
Invalid parse after use of <template> as expression #297
Comments
Ohhhh, interesting. Thank you! |
I figured out how to extract the transformed intermediate representation, which makes the syntax error visible: import Component from '@glimmer/component';
console.log(({} as typeof import("glint-environment-ember-template-imports/-private/dsl")).template(function(𝚪, χ: typeof import("glint-environment-ember-template-imports/-private/dsl")) {
𝚪; χ;
}));
export class A extends Component {
<static { ({} as typeof import("glint-environment-ember-template-imports/-private/dsl")).template(function(𝚪: import("glint-environment-ember-template-imports/-private/dsl").ResolveContext<A>, χ: typeof import("glint-environment-ember-template-imports/-private/dsl")) {
𝚪; χ;
}) as unknown }
} Looks like an off-by-one error during the handling of the first template leaves a stray Edit to add: for completeness and my own notes, the preprocessed-but-not-yet-transformed version is: import Component from '@glimmer[/component]()';
console.log([___T``]);
export class A extends Component {
[___T`Hello`]
} |
I understand better what is failing here. I think it's probably also causing #263. The bug starts with this code, which is doing a risky thing because the positions that it's assigning are positions in the original source code. But the node they're assigning them on is about to get appended to an AST representing the "preprocessed-but-not-yet-transformed" form that I pasted above. Now, this might still seem OK because later when we call But |
Ideas for the fix:
|
Thank you for the thorough investigation here, @ef4! Based on the timestamps I'm afraid I might have been able to save you a few hours of spelunking if I'd seen this sooner, but ultimately it's probably a good thing to have some of the sins I'm committing in In the near term, I think your idea 2 is likely the most straightforward route to fixing this. That's likely how propagating this location information would have been implemented in the first place had Longer-term I think we'll aim to eliminate most of this plumbing and coordination by making |
I don't think this bug is quite the cause of #263, but it's certainly related—both are the result of a fairly naive transition from using Babel for parsing to using TypeScript's own parser, without accounting for the differences in treatment of trivia you've outlined here. |
This is a fix for typed-ember#297. It allows environment-defined transforms to emit template locations via meta instead of using `node.pos` (which is unreliable when the source has been preprocessed into an intermediate form).
Given the file:
Glint's parse ends up off:
(more errors follow that one, but they all seem to be fallout from the parser being off)
If I comment out the the
console.log
line, the whole thing parses and type checks OK.The runtime is working fine, so I don't think this is a problem with ember-template-imports. The code it emits looks correct. This is only a type-checking problem.
The text was updated successfully, but these errors were encountered: