diff --git a/lib/index.d.ts b/lib/index.d.ts index 764c435..be8b1f3 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -25,8 +25,8 @@ declare namespace postcssValueParser { before: string; /** - * The token at the end of the node - */ + * The token at the end of the node + */ after: string; } @@ -85,7 +85,7 @@ declare namespace postcssValueParser { * @param node The node to stringify * @returns The serialized CSS representation of the node */ - (nodes: Node): string; + (nodes: Node): string | undefined; } interface WalkCallback { @@ -95,7 +95,7 @@ declare namespace postcssValueParser { * @param nodes The series of parsed nodes * @returns Returning `false` will prevent traversal of descendant nodes (only applies if `bubble` was set to `true` in the `walk()` call) */ - (node: Node, index: number, nodes: Node[]): void | false; + (node: Node, index: number, nodes: Node[]): void | boolean; } /** diff --git a/lib/stringify.js b/lib/stringify.js index 5f2c845..6079671 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -16,7 +16,7 @@ function stringifyNode(node, custom) { } else if (type === "div") { return (node.before || "") + value + (node.after || ""); } else if (Array.isArray(node.nodes)) { - buf = stringify(node.nodes); + buf = stringify(node.nodes, custom); if (type !== "function") { return buf; } diff --git a/package.json b/package.json index 44e04cd..55789ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-value-parser", - "version": "4.0.3", + "version": "4.1.0", "description": "Transforms css values and at-rule params into the tree", "main": "lib/index.js", "files": [ @@ -15,7 +15,7 @@ "tape": "^4.10.2" }, "scripts": { - "lint:prettier": "prettier '**/*.js' --list-different", + "lint:prettier": "prettier '**/*.js' '**/*.ts' --list-different", "lint:js": "eslint . --cache", "lint": "yarn lint:js && yarn lint:prettier", "pretest": "yarn lint", diff --git a/test/stringify.js b/test/stringify.js index fb695a5..36d13f2 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -89,7 +89,7 @@ var tests = [ ]; test("Stringify", function(t) { - t.plan(tests.length + 3); + t.plan(tests.length + 4); tests.forEach(function(opts) { t.equal(stringify(parse(opts.fixture)), opts.fixture, opts.message); @@ -131,4 +131,13 @@ test("Stringify", function(t) { tokens[1].type = "word"; t.equal(stringify(tokens), " rgba ", "Shouldn't process nodes of work type"); + + t.equal( + stringify(parse("calc(1px + var(--bar))"), function(node) { + if (node.type === "function" && node.value === "var") { + return "10px"; + } + }), + "calc(1px + 10px)" + ); });