garden icon indicating copy to clipboard operation
garden copied to clipboard

garden.selectors broken in v2.0.0

Open hkjels opened this issue 7 years ago • 6 comments

Whenever selectors/& is used an exception is raised: Assert failed: (vector? tagged-data)

Using the vector-form works [:&:.foo], but as far as I know, that can not be combined with other selector-fns like selectors/+ etc.

hkjels avatar Jun 09 '17 12:06 hkjels

Yes. The selectors namespace has not been updated with an implementation of garden.parse/IParse for CSSSelector. That is the reason you are seeing an exception.

noprompt avatar Jun 16 '17 05:06 noprompt

Does that mean, that it's not possible to express this selector at the moment? Or is there some other way around it?

[(selector/& (selector/not :Vertically)) {:flex-direction :row}]

hkjels avatar Jun 18 '17 17:06 hkjels

@hkjels No but I think we can resolve this problem by defining and implementation of garden.parse/IParse for the garden.selectors.CSSSelector class. That implementation could return a new AST node type of :css.selector/raw which would just be a string.

In selectors.cljs:

(defrecord CSSSelector [selector]
  garden.parse/IParse
  (-parse [this]
    [:css.selector/raw (css-selector this)]))

and in parse.cljc we'd have

(spec/def ::raw-selector
  string?)

(spec/def ::selector
  (spec/or ::simple-selector ::simple-selector
           ::compound-selector ::compound-selector
           ::complex-selector ::complex-selector
           ::raw-selector ::raw-selector)) ;; Support "raw" selectors but only at the top.

We'd then need to add a method for it in normalize.cljc and compiler.cljc.

This isn't a great solution though because it makes the resolution of nested selectors during the normalization process much more complex.

A better alternative would be to parse the result of calling css-selector and return a selector AST that fits in with what currently exists e.g. a :css.selector/complex node, etc. Since there's existing code which already does some lightweight analysis of CSS selector syntax, I think this would be the best direction to go.

noprompt avatar Jun 18 '17 18:06 noprompt

See #137

noprompt avatar Jun 18 '17 18:06 noprompt

@hkjels Apologies for thinking out loud. The game plan will be to implement a parser for the CSS selector syntax and use that in the implementation of garden.parse/IParse for the garden.selector.CSSSelector class.

noprompt avatar Jun 18 '17 18:06 noprompt

Hey, don't apologise. I love it! 👍 I don't quite follow you, but I'll look into it and see if I can grasp what your saying here :)

hkjels avatar Jun 18 '17 18:06 hkjels