Provide way to determine various parts of a rule #153

Closed
mahonnaise opened this Issue Aug 10, 2011 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

mahonnaise commented Aug 10, 2011

This [1] is weird. I assumed each rule was self-contained piece and not a self-contained piece within a closure (which was generated by the build process).

If you are trying to write a new rule, you might feel inclined to skip the whole building process (because it's kinda annoying) and just include the new rule on your test page. However, your new rule won't be inside that closure anymore and parserlib will be undefined (-> "Fatal error, cannot continue: parserlib is not defined").

There are at least two options:

  1. Pass parserlib as third argument to a rule's init function.
  2. Introduce a different way to identify pieces which doesn't rely on instanceof.

Either way, I'd get the rules out of that closure. They shouldn't have access to it.

Edit: [1] Original title was "Rules gain access to parserlib via closure"

Contributor

mahonnaise commented Aug 10, 2011

On a related note: The public clearRules function currently doesn't serve any purpose. (Yes, it allows you to remove all rules, but that's a dead end. You can't go anywhere from there.)

Contributor

nzakas commented Sep 27, 2011

You can now use the following constants:

parser.DEFAULT_TYPE = 0;
parser.COMBINATOR_TYPE = 1;
parser.MEDIA_FEATURE_TYPE = 2;
parser.MEDIA_QUERY_TYPE = 3;
parser.PROPERTY_NAME_TYPE = 4;
parser.PROPERTY_VALUE_TYPE = 5;
parser.PROPERTY_VALUE_PART_TYPE = 6;
parser.SELECTOR_TYPE = 7;
parser.SELECTOR_PART_TYPE = 8;
parser.SELECTOR_SUB_PART_TYPE = 9;

That, along with the type property of each selector part allow you to do things like:

if (part.type == parser.SELECTOR_PART_TYPE) { ... }    

nzakas closed this in b60aeaf Sep 27, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment