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

bug: dependencies are not tracked with the as-element="compose" attribute #130

Open
rmja opened this issue Nov 1, 2017 · 4 comments
Open
Assignees

Comments

@rmja
Copy link

rmja commented Nov 1, 2017

I'm submitting a bug report

  • Library Version:
    2.0.0-rc.5

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    7.6.0

  • NPM Version:
    4.1.2

  • JSPM OR Webpack AND Version
    webpack 3.8.1

  • Browser:
    all

  • Language:
    TypeScript 2.5.3

Current behavior:
The plugin correctly tracks dependencies for the <compose view-model="./vs" /> but not for <some-other-tag as-element="compose" view-model="./vm" />

Expected/desired behavior:
It should be possible to use the as-element in a similar way as with compose directly.

@jods4 jods4 self-assigned this Nov 1, 2017
@jods4
Copy link
Contributor

jods4 commented Nov 1, 2017

Seems legitimate but given how the html parser (re-used from Webpack) works that might be a bit tricky.

I know it does not exactly solve this issue but it might help to know that you can register your own tag/attribute combinations as modules, see https://github.com/aurelia/webpack-plugin/wiki/Managing-dependencies#html-dependencies

@3cp
Copy link
Member

3cp commented Mar 15, 2018

It doesn't sound too difficult to me, but I am using a different html parser.

As reference, with htmlparser2, I do

let parser = new htmlparser.Parser({
    onopentag: function(name, attrs) {
      // <require from="dep"></require>
      if (name === 'require') {
        add(attrs.from);
      // <compose view-model="vm" view="view"></compose>
      // <any as-element="compose" view-model="vm" view="view"></any>
      } else if (name === 'compose' || attrs['as-element'] === 'compose') {
        add([attrs['view-model'], attrs.view]);
      // <router-view layout-view-model="lvm" layout-view="ly"></router-view>
      // <any as-element === 'router-view' layout-view-model="lvm" layout-view="ly"></any>
      } else if (name === 'router-view' || attrs['as-element'] === 'router-view') {
        add([attrs['layout-view-model'], attrs['layout-view']]);
      }
    }
  });

@jods4
Copy link
Contributor

jods4 commented Mar 15, 2018

I used the same parser as Webpack to minimize the number of dependencies installed.

It calls you back with with one (tag, attr) pair for each attribute in document order.

This means you can see layout-view attribute on <div> first and later be called with as-element='compose' for the same <div>.

But what is worse is that it's the only callback so you can't know if the second call with as-element attribute is on the same <div> as the first call or another one.

So basically, it's impossible to support as-element with the current parser, we have to switch to another one.

@3cp
Copy link
Member

3cp commented Mar 15, 2018

That's unfortunate. The parser looks quite small. It might not be too difficult to bring the code in and customize it, but that has risk on introducing bug.

Personally I will side to one more dep on htmlparser2 for simplicity and flexibility. Just my 2c.

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

No branches or pull requests

3 participants