Skip to content

String(node) should produce string or throw more helpful error #72

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

Closed
jonathantneal opened this issue Mar 5, 2019 · 0 comments · Fixed by #74
Closed

String(node) should produce string or throw more helpful error #72

jonathantneal opened this issue Mar 5, 2019 · 0 comments · Fixed by #74

Comments

@jonathantneal
Copy link
Collaborator

Expected Behavior / Situation

In postcss-values-parser v2, String(node) returns the string value of any Node. In postcss-values-parser v3, one must now use the nodeToString function to retrieve the string value. Worse yet, when a node is accidentally toString’d, an error is thrown!

I would prefers things work the same as they did in v2, as well as how they still do in PostCSS.

const ast = parse('#000 url(path/to/image.jpg)');

console.log(String(ast)); // "#000 url(path/to/image.jpg)"
console.log(String(ast.nodes[0])); // "#000"

And here is an example of the stringified behavior currently in PostCSS:

import postcss from 'postcss';

const ast = postcss.parse('selector { property-name: property-value; }');

console.log(String(ast.nodes[0].nodes[0])); // "property-name: property-value"

Actual Behavior / Situation

TypeError: this[node.type] is not a function

Modification Proposal

Remove the TypeError: this[node.type] is not a function error and default toString to work like nodeToString.

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

Successfully merging a pull request may close this issue.

2 participants