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

validate if in-element has already been transformed #1159

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@glimmer/compiler/lib/template-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,11 @@ export default class TemplateCompiler implements Processor<InputOps> {
let { key, value } = pairs[i];

if (isInElement) {
if (key === 'guid') {
if (
key === 'guid' &&
value.type === 'StringLiteral' &&
!value.value.startsWith('%cursor:')
Comment on lines +455 to +456
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why would we expect guid to be passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this happens when I do glimmer preprocess -> print (at this stage its passing guid) -> preprocess printed result again fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this only happens when compiling not when parsing / printing. Maybe you are using an older version of glimmer-vm that did this during syntax parsing?

Can you describe the tooling that you are using (and the versions) that hit the issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #1164 which shows that we can do the following:

import { preprocess, print } from '@glimmer/syntax';

let template = '{{#in-element this.someElement}}Content here{{/in-element}}';
let ast = preprocess(template);
let reprintedOutput = print(ast);

assert.equal(reprintedOutput, template);

Copy link
Contributor Author

@patricklx patricklx Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that could be. was trying out custom hbs preprocessing (not ast plugin).
So, i was using the glimmer package directly (v0.42.2).
But when the template was processed by ember it failed to process it.
"ember-source": "^3.21.1"

actually with embroider:
"@embroider/core": "^0.23.0"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this happens when I do glimmer preprocess -> print (at this stage its passing guid) -> preprocess printed result again fails.

Maybe you are using an older version of glimmer-vm that did this during syntax parsing?

Specifically, I think you are probably using a version of glimmer-vm prior to this PR: #1086. That landed in @glimmer/syntax@0.52.1.

Copy link
Contributor Author

@patricklx patricklx Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just tested again to be sure, but this does still fail:

const glimmer = require('@glimmer/syntax');

const result = glimmer.preprocess(`<div>{{#in-element destinationElement~}}
    {{yield yieldHash}}
  {{~/in-element}}</div>`);

const printed = glimmer.print(result);
console.log(printed);

glimmer.preprocess(printed);

console.log:
<div>{{#in-element destinationElement guid="%cursor:0%" insertBefore=undefined~}}{{yield yieldHash}}{{~/in-element}}</div>

error:
SyntaxError: Cannot pass guid from user space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, updated to latest version works!

) {
throw new SyntaxError(
`Cannot pass \`guid\` to \`{{#in-element}}\` on line ${value.loc.start.line}.`,
value.loc
Expand Down