Fix generate interfaces script (#6031)
* Fix typo in TSPropertySignature type definition * Sort fields in generate-interfaces script
This commit is contained in:
parent
889f4e7791
commit
21eeed8a8c
773
lib/types.js
773
lib/types.js
File diff suppressed because it is too large
Load Diff
@ -2183,7 +2183,7 @@ Aliases: `TSTypeElement`
|
|||||||
|
|
||||||
- `key`: `Expression` (required)
|
- `key`: `Expression` (required)
|
||||||
- `typeAnnotation`: `TypeAnnotation` (default: `null`)
|
- `typeAnnotation`: `TypeAnnotation` (default: `null`)
|
||||||
- `initializer`: `Expresssion` (default: `null`)
|
- `initializer`: `Expression` (default: `null`)
|
||||||
- `computed`: `boolean` (default: `null`)
|
- `computed`: `boolean` (default: `null`)
|
||||||
- `optional`: `boolean` (default: `null`)
|
- `optional`: `boolean` (default: `null`)
|
||||||
- `readonly`: `boolean` (default: `null`)
|
- `readonly`: `boolean` (default: `null`)
|
||||||
|
|||||||
@ -115,7 +115,7 @@ defineType("TSPropertySignature", {
|
|||||||
...namedTypeElementCommon,
|
...namedTypeElementCommon,
|
||||||
readonly: validateOptional(bool),
|
readonly: validateOptional(bool),
|
||||||
typeAnnotation: validateOptionalType("TypeAnnotation"),
|
typeAnnotation: validateOptionalType("TypeAnnotation"),
|
||||||
initializer: validateOptionalType("Expresssion"),
|
initializer: validateOptionalType("Expression"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,16 @@ for (const type in t.NODE_FIELDS) {
|
|||||||
const struct = ['type: "' + type + '";'];
|
const struct = ['type: "' + type + '";'];
|
||||||
const args = [];
|
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];
|
const field = fields[fieldName];
|
||||||
|
|
||||||
let suffix = "";
|
let suffix = "";
|
||||||
@ -94,16 +103,18 @@ for (const type in t.NODE_FIELDS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args.push(t.toBindingIdentifierName(fieldName) + suffix);
|
args.push(t.toBindingIdentifierName(fieldName) + suffix);
|
||||||
if (!t.isValidIdentifier(fieldName)) continue;
|
|
||||||
|
if (t.isValidIdentifier(fieldName)) {
|
||||||
struct.push(fieldName + suffix + ";");
|
struct.push(fieldName + suffix + ";");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
code += `declare class ${NODE_PREFIX}${type} extends ${NODE_PREFIX} {
|
code += `declare class ${NODE_PREFIX}${type} extends ${NODE_PREFIX} {
|
||||||
${struct.join("\n ").trim()}
|
${struct.join("\n ").trim()}
|
||||||
}\n\n`;
|
}\n\n`;
|
||||||
|
|
||||||
// Flow chokes on super() :/
|
// Flow chokes on super() and import() :/
|
||||||
if (type !== "Super") {
|
if (type !== "Super" && type !== "Import") {
|
||||||
lines.push(
|
lines.push(
|
||||||
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(
|
`declare function ${type[0].toLowerCase() + type.slice(1)}(${args.join(
|
||||||
", "
|
", "
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user