Support string keys
parent
cdc9304304
commit
921bdd04cb
|
@ -12,7 +12,8 @@ import type {
|
|||
} from '@babel/types';
|
||||
|
||||
import {
|
||||
isIdentifier, isObjectTypeProperty, isStringLiteralTypeAnnotation, isClassProperty,
|
||||
isIdentifier, isStringLiteral, isObjectTypeProperty,
|
||||
isStringLiteralTypeAnnotation, isClassProperty,
|
||||
} from '@babel/types';
|
||||
|
||||
import Context from './context';
|
||||
|
@ -215,10 +216,12 @@ function makeField(ctx: Context, node: ObjectTypeProperty | ClassProperty): ?Fie
|
|||
// TODO: warning about computed properties.
|
||||
|
||||
invariant(isObjectTypeProperty(node) || !node.computed);
|
||||
invariant(isIdentifier(node.key));
|
||||
invariant(isIdentifier(node.key) || isStringLiteral(node.key));
|
||||
|
||||
const name = isIdentifier(node.key) ? node.key.name : node.key.value;
|
||||
|
||||
return {
|
||||
name: node.key.name,
|
||||
name,
|
||||
value: type,
|
||||
required: node.optional == null || !node.optional,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-06/schema#",
|
||||
"definitions": {
|
||||
"stringKeys::X": {
|
||||
"type": "object",
|
||||
"properties": {"a b": {"type": "string"}},
|
||||
"required": ["a b"]
|
||||
},
|
||||
"stringKeys::Y": {
|
||||
"type": "object",
|
||||
"properties": {"a b": {"type": "string"}},
|
||||
"required": ["a b"]
|
||||
},
|
||||
"stringKeys::Z": {
|
||||
"type": "object",
|
||||
"properties": {"a b": {"type": "string"}},
|
||||
"required": ["a b"]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
type X = {
|
||||
'a b': string;
|
||||
};
|
||||
|
||||
interface Y {
|
||||
'a b': string;
|
||||
}
|
||||
|
||||
class Z {
|
||||
'a b': string;
|
||||
}
|
||||
|
||||
export {X, Y, Z};
|
|
@ -0,0 +1,18 @@
|
|||
- kind: record
|
||||
fields:
|
||||
- name: "a b"
|
||||
value: {kind: string}
|
||||
required: true
|
||||
id: [stringKeys, X]
|
||||
- kind: record
|
||||
fields:
|
||||
- name: "a b"
|
||||
value: {kind: string}
|
||||
required: true
|
||||
id: [stringKeys, Y]
|
||||
- kind: record
|
||||
fields:
|
||||
- name: "a b"
|
||||
value: {kind: string}
|
||||
required: true
|
||||
id: [stringKeys, Z]
|
Loading…
Reference in New Issue