Fix generate interfaces script (#6031)

* Fix typo in TSPropertySignature type definition

* Sort fields in generate-interfaces script
This commit is contained in:
Brian Ng 2017-08-01 13:38:46 -05:00 committed by Henry Zhu
parent 889f4e7791
commit 21eeed8a8c
4 changed files with 675 additions and 181 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2183,7 +2183,7 @@ Aliases: `TSTypeElement`
- `key`: `Expression` (required)
- `typeAnnotation`: `TypeAnnotation` (default: `null`)
- `initializer`: `Expresssion` (default: `null`)
- `initializer`: `Expression` (default: `null`)
- `computed`: `boolean` (default: `null`)
- `optional`: `boolean` (default: `null`)
- `readonly`: `boolean` (default: `null`)

View File

@ -115,7 +115,7 @@ defineType("TSPropertySignature", {
...namedTypeElementCommon,
readonly: validateOptional(bool),
typeAnnotation: validateOptionalType("TypeAnnotation"),
initializer: validateOptionalType("Expresssion"),
initializer: validateOptionalType("Expression"),
},
});

View File

@ -54,7 +54,16 @@ for (const type in t.NODE_FIELDS) {
const struct = ['type: "' + type + '";'];
const args = [];
for (const fieldName in fields) {
Object.keys(t.NODE_FIELDS[type])
.sort((fieldA, fieldB) => {
const indexA = t.BUILDER_KEYS[type].indexOf(fieldA);
const indexB = t.BUILDER_KEYS[type].indexOf(fieldB);
if (indexA === indexB) return fieldA < fieldB ? -1 : 1;
if (indexA === -1) return 1;
if (indexB === -1) return -1;
return indexA - indexB;
})
.forEach(fieldName => {
const field = fields[fieldName];
let suffix = "";
@ -94,16 +103,18 @@ for (const type in t.NODE_FIELDS) {
}
args.push(t.toBindingIdentifierName(fieldName) + suffix);
if (!t.isValidIdentifier(fieldName)) continue;
if (t.isValidIdentifier(fieldName)) {
struct.push(fieldName + suffix + ";");
}
});
code += `declare class ${NODE_PREFIX}${type} extends ${NODE_PREFIX} {
${struct.join("\n ").trim()}
}\n\n`;
// Flow chokes on super() :/
if (type !== "Super") {
// Flow chokes on super() and import() :/
if (type !== "Super" && type !== "Import") {
lines.push(
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(
", "