Skip to content

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

Closed
@jonathantneal

Description

@jonathantneal

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions