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

Using JavaScript API to define variables with hash values doesn't allow use of dot notation in stylesheets #1286

Closed
aeronox64 opened this Issue Dec 13, 2013 · 9 comments

Comments

Projects
None yet
6 participants
@aeronox64

aeronox64 commented Dec 13, 2013

I'm really enjoying the new hash support in Stylus. Thank you @Panya for all the work you did to make it happen.

I ran into an issue tonight with using stylus.define to set a variable in JavaScript — I might be overlooking something.

style.define('testhash', {
  a: 'value1',
  b: 'value2',
  c: {
    d: 'value 3'
  }
});

I would like to be able to access these values in my Stylus files using dot notation (ie testhash.a), but get the following error:

testhash has no property .a

When I inspect the value of testhash with the p function this is the output:

(a 'value1') (b 'value2') (c ((d 'value 3')))

Using stylus.nodes or stylus.utils is there currently a way to do this? I tried utils.coerce but it doesn't appear it's been updated for the new hashes.

@Panya

This comment has been minimized.

Show comment
Hide comment
@Panya

Panya Dec 13, 2013

Member

Thanks for the report. There is some backwards compatible thing with define. Currently if you'll pass an object as an argument it'll be coerced to the list with pairs (for example { foo: 'bar', bar: 'baz' } would become the expression (foo 'bar') (bar 'baz')). But i think it could be fixed with optional parameter or so.

Member

Panya commented Dec 13, 2013

Thanks for the report. There is some backwards compatible thing with define. Currently if you'll pass an object as an argument it'll be coerced to the list with pairs (for example { foo: 'bar', bar: 'baz' } would become the expression (foo 'bar') (bar 'baz')). But i think it could be fixed with optional parameter or so.

@simshanith

This comment has been minimized.

Show comment
Hide comment
@simshanith

simshanith Mar 21, 2014

#1358 has been closed, but looks like a simple solution.

Can we have a hash-objects option or something that uses @martinheidegger coerceObject implementation renamed to coerceObjectToHash, with the backwards-compatabile current coerceObject implementation renamed to coerceObjectToList and used as the default?

simshanith commented Mar 21, 2014

#1358 has been closed, but looks like a simple solution.

Can we have a hash-objects option or something that uses @martinheidegger coerceObject implementation renamed to coerceObjectToHash, with the backwards-compatabile current coerceObject implementation renamed to coerceObjectToList and used as the default?

@Panya

This comment has been minimized.

Show comment
Hide comment
@Panya

Panya Mar 22, 2014

Member

I've added optional hash object support through raw parameter of the define function. For example:

style.define('testhash', {
  a: 'value1',
  b: 'value2',
  c: {
    d: 'value 3'
  }
}, true);
body
  content: testhash.c.d // 'value 3'

Fix will be in the next minor release.

Member

Panya commented Mar 22, 2014

I've added optional hash object support through raw parameter of the define function. For example:

style.define('testhash', {
  a: 'value1',
  b: 'value2',
  c: {
    d: 'value 3'
  }
}, true);
body
  content: testhash.c.d // 'value 3'

Fix will be in the next minor release.

kizu added a commit that referenced this issue Apr 5, 2014

Merge branch 'pr/1444' into rc-0.43
* pr/1444:
  Added tests for `define`
  Support the hash objects in `define`. Fixes #1286

@Panya Panya closed this in 16fa016 Apr 5, 2014

@Sawtaytoes

This comment has been minimized.

Show comment
Hide comment
@Sawtaytoes

Sawtaytoes Apr 27, 2014

Is the fix in version 0.44, or it's going into 0.45?

Sawtaytoes commented Apr 27, 2014

Is the fix in version 0.44, or it's going into 0.45?

@Panya

This comment has been minimized.

Show comment
Hide comment
@Panya

Panya Apr 27, 2014

Member

@Saturn2888 this fix already in 0.44.

Member

Panya commented Apr 27, 2014

@Saturn2888 this fix already in 0.44.

@Sawtaytoes

This comment has been minimized.

Show comment
Hide comment
@Sawtaytoes

Sawtaytoes Apr 27, 2014

Looks like I was a version behind in the project I was using to test. This is such a recent fix I didn't realize I was missing it.

Awesome! Glad to see this as an available feature now 👍!

Sawtaytoes commented Apr 27, 2014

Looks like I was a version behind in the project I was using to test. This is such a recent fix I didn't realize I was missing it.

Awesome! Glad to see this as an available feature now 👍!

@acidjazz

This comment has been minimized.

Show comment
Hide comment
@acidjazz

acidjazz Jun 18, 2015

This seems to only mainly work when specifying a colin in stylus, for instance:

          &.c_red1
            color white
            background-color d.color.red1

Will give me an error: expected "indent", got "outdent", where as this

          &.c_red1
            color white
            background-color: d.color.red1

compiles just fine.

acidjazz commented Jun 18, 2015

This seems to only mainly work when specifying a colin in stylus, for instance:

          &.c_red1
            color white
            background-color d.color.red1

Will give me an error: expected "indent", got "outdent", where as this

          &.c_red1
            color white
            background-color: d.color.red1

compiles just fine.

@vendethiel

This comment has been minimized.

Show comment
Hide comment
@vendethiel

vendethiel Jun 18, 2015

Contributor

That's another thing entirely, though.

Contributor

vendethiel commented Jun 18, 2015

That's another thing entirely, though.

@acidjazz

This comment has been minimized.

Show comment
Hide comment
@acidjazz

acidjazz Jun 19, 2015

Yes @vendethiel after I wrote this I dug through issues and found issue #1405 , It seems like its still outstanding and undecided. I can see how the parser can be confused but also how this puts a dent in the sugar of stylus (like not requiring colons). Where do you think this should land?

acidjazz commented Jun 19, 2015

Yes @vendethiel after I wrote this I dug through issues and found issue #1405 , It seems like its still outstanding and undecided. I can see how the parser can be confused but also how this puts a dent in the sugar of stylus (like not requiring colons). Where do you think this should land?

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