@joshuahhh/pretty-print 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty-print.d.ts","sourceRoot":"","sources":["../src/pretty-print.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+GAA+G;IAC/G,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AA2BD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,kBAAuB,GAC/B,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CA2BvB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAE,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAClE,IAAI,CAQN;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,SAAS,EACT,GAAG,OAAO,EACX,EAAE,kBAAkB,GAAG;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,2CAyFA;
|
|
1
|
+
{"version":3,"file":"pretty-print.d.ts","sourceRoot":"","sources":["../src/pretty-print.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+GAA+G;IAC/G,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AA2BD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,kBAAuB,GAC/B,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CA2BvB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAE,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAClE,IAAI,CAQN;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,SAAS,EACT,GAAG,OAAO,EACX,EAAE,kBAAkB,GAAG;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,2CAyFA;AAmUD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAaR;AAGD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;CAYpB,CAAC"}
|
package/dist/pretty-print.js
CHANGED
|
@@ -141,8 +141,6 @@ function prettyPrintToDoc(value, tagger, options, visited = new Set(), path = []
|
|
|
141
141
|
const props = element.props;
|
|
142
142
|
const { children, ...otherProps } = props;
|
|
143
143
|
const openTag = colorize(`<${type}`, "keyword", [...path, 0]);
|
|
144
|
-
const closeTag = colorize(`</${type}>`, "keyword", [...path, 4]);
|
|
145
|
-
const selfCloseTag = colorize("/>", "keyword", [...path, 2]);
|
|
146
144
|
// Format props
|
|
147
145
|
const propEntries = Object.entries(otherProps);
|
|
148
146
|
const propDocs = [];
|
|
@@ -166,9 +164,11 @@ function prettyPrintToDoc(value, tagger, options, visited = new Set(), path = []
|
|
|
166
164
|
const childrenArray = React.Children.toArray(children);
|
|
167
165
|
const hasChildren = childrenArray.length > 0;
|
|
168
166
|
if (!hasChildren && propEntries.length === 0) {
|
|
167
|
+
const selfCloseTag = colorize("/>", "keyword", [...path, 2]);
|
|
169
168
|
return [openTag, " ", selfCloseTag];
|
|
170
169
|
}
|
|
171
170
|
if (!hasChildren) {
|
|
171
|
+
const selfCloseTag = colorize("/>", "keyword", [...path, 2]);
|
|
172
172
|
return group([
|
|
173
173
|
openTag,
|
|
174
174
|
indent(propDocs),
|
|
@@ -176,6 +176,7 @@ function prettyPrintToDoc(value, tagger, options, visited = new Set(), path = []
|
|
|
176
176
|
selfCloseTag,
|
|
177
177
|
]);
|
|
178
178
|
}
|
|
179
|
+
const closeTag = colorize(`</${type}>`, "keyword", [...path, 4]);
|
|
179
180
|
const childDocs = childrenArray.map((child, i) => typeof child === "string" || typeof child === "number"
|
|
180
181
|
? String(child)
|
|
181
182
|
: prettyPrintToDoc(child, tagger, options, visited, [...path, 3, i]));
|
|
@@ -381,6 +382,7 @@ function prettyPrintToDoc(value, tagger, options, visited = new Set(), path = []
|
|
|
381
382
|
return "[Unknown]";
|
|
382
383
|
}
|
|
383
384
|
export function prettyPrintToString(value, options = {}) {
|
|
385
|
+
console.log("value", value);
|
|
384
386
|
const { width = 80, useColor = true } = options;
|
|
385
387
|
const tagger = useColor ? new StringTagger() : null;
|
|
386
388
|
const doc = prettyPrintToDoc(value, tagger, options);
|
|
@@ -263,4 +263,11 @@ describe("prettyPrintToString", () => {
|
|
|
263
263
|
/>
|
|
264
264
|
</g>`);
|
|
265
265
|
});
|
|
266
|
+
it("should print nested JSX elements with color enabled", () => {
|
|
267
|
+
// Nested JSX with children triggers the bug: phantom selfCloseTag/closeTag
|
|
268
|
+
// spans get registered in tagger.tag() but never appear in the formatted
|
|
269
|
+
// output, corrupting path-based marker matching in expand().
|
|
270
|
+
const element = React.createElement("g", { transform: "translate(0,0)" }, React.createElement("rect", { width: 10, height: 20 }), React.createElement("text", { x: 5 }, "hello"));
|
|
271
|
+
expect(() => prettyPrintToString(element, { width: 60, useColor: true })).not.toThrow();
|
|
272
|
+
});
|
|
266
273
|
});
|