Skip to content

Commit 8667252

Browse files
petegleesonNoviny
authored andcommitted
Fix typeof usecase (#23)
* adds failing example of typeof usage * fixes problem with parsing typeof paths
1 parent e93f558 commit 8667252

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

__snapshots__/test.js.snap

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,44 @@ Object {
29572957
}
29582958
`;
29592959

2960+
exports[`typeof statements 1`] = `
2961+
Object {
2962+
"classes": Array [
2963+
Object {
2964+
"kind": "object",
2965+
"members": Array [
2966+
Object {
2967+
"key": Object {
2968+
"kind": "id",
2969+
"name": "a",
2970+
},
2971+
"kind": "property",
2972+
"optional": false,
2973+
"value": Object {
2974+
"kind": "typeof",
2975+
"name": undefined,
2976+
"type": Object {
2977+
"kind": "generic",
2978+
"value": Object {
2979+
"kind": "number",
2980+
"referenceIdName": "one",
2981+
"value": 1,
2982+
},
2983+
},
2984+
},
2985+
},
2986+
],
2987+
"name": Object {
2988+
"kind": "id",
2989+
"name": "Component",
2990+
"type": null,
2991+
},
2992+
},
2993+
],
2994+
"kind": "program",
2995+
}
2996+
`;
2997+
29602998
exports[`unary operator 1`] = `
29612999
Object {
29623000
"classes": Array [

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ converters.NewExpression = (path, context) /*: K.New*/ => {
338338
};
339339

340340
converters.TypeofTypeAnnotation = (path, context) /*: K.Typeof*/ => {
341-
let type = convert(path.get("argument"), context);
341+
let type = convert(path.get("argument"), {...context, mode: 'value' });
342342
return {
343343
kind: "typeof",
344344
type,

test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,16 @@ const TESTS = [
822822
}
823823
}
824824
`
825-
}
825+
},
826+
{
827+
name: "typeof statements",
828+
typeSystem: "flow",
829+
code: `
830+
const one = 1;
831+
832+
class Component extends React.Component<{ a: typeof one }> {}
833+
`
834+
},
826835
];
827836

828837
for (let testCase of TESTS) {

0 commit comments

Comments
 (0)