Skip to content
This repository

Class name gets `undefined` #610

chowey opened this Issue · 6 comments

6 participants

Cameron Howey TJ Holowaychuk Jonathan Buchanan Eli Skeggs Forbes Lindesay Volodymyr Iatsyshyn
Cameron Howey

This is a minor bug for class attributes.

The following jade

- var obj = {}
div(class=obj.class) Test

renders like


so that undefined attributes are not added.

However, this jade

- var obj = {} Test

renders like

<div class="foo undefined">Test</div>

so that the undefined attribute is added.

TJ Holowaychuk

ahhh good find thanks for reporting, I bet foo(class=['foo', 'bar', undefined]) is the same too

Cameron Howey
chowey commented

This could probably be fixed by compiling attrs.class as an Array instead of a String.

In lib/compiler.js#L588:

classes = '[' + classes.join(', ') + ']';

instead of

classes = classes.join(" + ' ' + ");

Then "runtime.js" would need to be updated so attrs will unwrap an Array of Arrays (in case the user passes an Array as a class) to make it one big array.

Plus anywhere else where classes are monkeyed with would need to be checked to make sure it didn't break anything.

Jonathan Buchanan
insin commented

The suggested fix seems to work, quick test implementation here (with a disgusting in-place filter and flatten!):

Eli Skeggs

Just came across this bug. Any chance it could be fixed?

Forbes Lindesay

If I see a pull request that fixes it, I'll merge it.

Volodymyr Iatsyshyn

This issues relates to #1024 array in class attribute is joined with ',' instead of ' '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.