Skip to content
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

JavaScript API define need able to return hash Object when second parameter is a function. #2782

Open
hooozen opened this issue Mar 30, 2023 · 0 comments

Comments

@hooozen
Copy link
Contributor

hooozen commented Mar 30, 2023

To reproduce:

var stylus = require('stylus');

str = `
.foo 
  for p, v in obj
    {p}: v

.bar
  for p, v in getObj(#aaa)
    {p}: v
`
stylus(str)
  .set('filename', 'nesting.css')
  .define('obj', { display: 'block', color: 'white' }, true)
  .define("getObj", function (color) {
    return { display: 'block', color: color }
  }, true)
  .render(function (err, css) {
    if (err) throw err;
    console.log(css);
  }, true)

Current behavior:

.foo {
  display: 'block';
  color: 'white';
}
.bar {
  display: 0;
  color: 1;
}

Expected behavior:

.foo {
  display: 'block';
  color: 'white';
}
.bar {
  display: block;
  color: #aaa;
}

When I pass a JavaScript object variable to define() and want to get a hash object variable, I can do this by setting raw to true, as mentioned in #2780 and #1286. But when I pass a function that returns a JavaScript object to define(), the raw will not work as the former. see utils.js#L304.

Environment information:

  • stylus version: 0.59.0
  • nodejs version: 18.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant