Skip to content

Commit ebe95de

Browse files
committed
Support printing created identifiers
1 parent d7295d3 commit ebe95de

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

flow-typed/recast.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,4 @@ declare class NodePath {
3434
map<T>(f: (p: NodePath) => T): Array<T>;
3535
filter(f: (p: NodePath) => boolean): Array<NodePath>;
3636
push(node: ASTNode): void;
37-
38-
// our addition
39-
getSrc(): string;
4037
}

src/utils/__tests__/__snapshots__/getPropType-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object {
1010
exports[`getPropType detects custom validation functions for function 1`] = `
1111
Object {
1212
"name": "custom",
13-
"raw": "(function() {})",
13+
"raw": "function() {}",
1414
}
1515
`;
1616

src/utils/__tests__/resolveObjectValuesToArray-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ describe('resolveObjectValuesToArray', () => {
6666
);
6767
});
6868

69+
it('does not resolve Object.values with complex computed key', () => {
70+
const path = parse(
71+
['var foo = { [()=>{}]: 1, [5]: 2};', 'Object.values(foo);'].join('\n'),
72+
);
73+
74+
expect(resolveObjectValuesToArray(path)).toBeNull();
75+
});
76+
6977
it('resolves Object.values when using resolvable spread', () => {
7078
const path = parse(
7179
[

src/utils/printValue.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ function getSrcFromAst(path: NodePath): string {
3434
* Prints the given path without leading or trailing comments.
3535
*/
3636
export default function printValue(path: NodePath): string {
37+
if (path.node.start == null) {
38+
if (path.node.type === 'Literal') {
39+
return `"${path.node.value}"`;
40+
}
41+
throw new Error(
42+
`Cannot print raw value for type '${
43+
path.node.type
44+
}'. Please report this with an example at https://github.com/reactjs/react-docgen/issues`,
45+
);
46+
}
3747
const src = getSrcFromAst(path);
3848

39-
// TODO: Filter out comments in returned code
40-
4149
return deindent(src.slice(path.node.start, path.node.end));
4250
}

src/utils/resolveObjectValuesToArray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function resolveObjectToPropMap(
111111
}
112112

113113
/**
114-
* Returns an ArrayExpression which contains all the keys resolved from an object
114+
* Returns an ArrayExpression which contains all the values resolved from an object
115115
*
116116
* Ignores setters in objects
117117
*

0 commit comments

Comments
 (0)