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

Does not work for a simple component #226

Closed
boris-petrov opened this issue Mar 11, 2020 · 7 comments · Fixed by #498 · May be fixed by #233
Closed

Does not work for a simple component #226

boris-petrov opened this issue Mar 11, 2020 · 7 comments · Fixed by #498 · May be fixed by #233
Labels

Comments

@boris-petrov
Copy link
Contributor

ember new hbs-minifier-test
cd hbs-minifier-test
ember install ember-hbs-minifier
echo "{{#if true}}\n      {{log 1}}\n{{/if}}\n{{#if true}}\n    Hi there\n{{/if}}" > app/components/some-component.hbs
ember server

Generates:

block: "{\"symbols\":[],\"statements\":[[4,\"if\",[true],null,{\"statements\":[[0,\"      \"],[1,[28,\"log\",[1],null],false],[0,\"\\n\"]],\"parameters\":[]},null],[4,\"if\",[true],null,{\"statements\":[[0,\"    Hi there\\n\"]],\"parameters\":[]},null]],\"hasEval\":false}",

You can still see the spaces in the generated "machine code". Am I missing something? Isn't this supposed to remove these spaces by default with no configuration?

Happens on both Ember 3.16 and 3.17.

@Turbo87
Copy link
Collaborator

Turbo87 commented Mar 11, 2020

hmm, that does look strange. the whitespaces should have at least been collapsed to a single space. it almost looks like adding the addon does not have any effect at all. 🤔

@Turbo87 Turbo87 added the bug label Mar 11, 2020
@siva-sundar
Copy link
Contributor

Registering the plugin inside the setupPreprocessorRegistry hook instead of the included solved the issue. I am not sure about the reason behind this.

@Turbo87 Do you mind if I raise a PR ?

@Turbo87
Copy link
Collaborator

Turbo87 commented Apr 19, 2020

Happens on both Ember 3.16 and 3.17.

@boris-petrov do you mean ember-cli 3.16/17, or ember-source 3.16/17?

@boris-petrov
Copy link
Contributor Author

boris-petrov commented Apr 19, 2020

@Turbo87 - well, I don't remember (I would guess I was talking about ember-source), but here is the result from ember-cli 3.17.0 and ember-source 3.18.0:

block: "{\"symbols\":[],\"statements\":[[5,[27,[26,1,\"BlockHead\"],[]],[true],null,[[\"default\"],[{\"statements\":[[1,1,0,0,\"      \"],[1,0,0,0,[31,21,3,[27,[26,0,\"CallHead\"],[]],[1],null]],[1,1,0,0,\"\\n\"]],\"parameters\":[]}]]],[5,[27,[26,1,\"BlockHead\"],[]],[true],null,[[\"default\"],[{\"statements\":[[1,1,0,0,\"    Hi there\\n\"]],\"parameters\":[]}]]]],\"hasEval\":false,\"upvars\":[\"log\",\"if\"]}",

The plugin still doesn't work.

@Turbo87
Copy link
Collaborator

Turbo87 commented May 7, 2020

@boris-petrov I think the issue is that you were using a colocated component template. mainmatter/ember-test-selectors#521 fixed a similar issue for ember-test-selectors and I expect this to be the correct solution here too. Can you verify if that solves the issue for you?

@patsy-issa patsy-issa self-assigned this May 7, 2020
@boris-petrov
Copy link
Contributor Author

@Turbo87 - that does seem to fix the issue, yes!

@patsy-issa
Copy link

While this seems to have fixed the issue with the ast plugins not being loaded in the correct order it is not removing leading whitespaces in colocated component templates (I have simplified the template):

 {
    id: "qBBOrLXg",
    block: "{\"symbols\":[],\"statements\":[[2,\"    Hi there\\n\"]],\"hasEval\":false,\"upvars\":[]}",
    meta: {
      moduleName: "foo/components/some-component.hbs"
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants