Open rmja opened 6 years ago
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
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']]);
}
}
});
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.
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.
I'm submitting a bug report
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 withcompose
directly.