Rename maker.js to extractor.js
parent
e2d035ed11
commit
502a7f21ff
|
@ -4,7 +4,7 @@ const assert = require('assert');
|
|||
|
||||
const {partition, log} = require('./utils');
|
||||
|
||||
function make(node) {
|
||||
function extract(node) {
|
||||
if (!handlers[node.type]) {
|
||||
log(node);
|
||||
return null;
|
||||
|
@ -15,21 +15,21 @@ function make(node) {
|
|||
|
||||
const handlers = {
|
||||
TypeAlias(node) {
|
||||
return make(node.right);
|
||||
return extract(node.right);
|
||||
},
|
||||
|
||||
InterfaceDeclaration(node) {
|
||||
return make(node.body);
|
||||
return extract(node.body);
|
||||
},
|
||||
|
||||
ClassDeclaration(node) {
|
||||
return make(node.body);
|
||||
return extract(node.body);
|
||||
},
|
||||
|
||||
ClassBody(node) {
|
||||
return {
|
||||
type: 'report',
|
||||
fields: node.body.map(make).filter(Boolean),
|
||||
fields: node.body.map(extract).filter(Boolean),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -41,8 +41,8 @@ const handlers = {
|
|||
let type = node.leadingComments && getLastPragma(node.leadingComments);
|
||||
|
||||
return {
|
||||
name: make(node.key),
|
||||
type: type || make(node.typeAnnotation),
|
||||
name: extract(node.key),
|
||||
type: type || extract(node.typeAnnotation),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -53,20 +53,20 @@ const handlers = {
|
|||
ObjectTypeAnnotation(node) {
|
||||
if (node.indexers.length > 0) {
|
||||
// Allow functions, getters and setters.
|
||||
const properties = node.properties.map(make).filter(Boolean);
|
||||
const properties = node.properties.map(extract).filter(Boolean);
|
||||
|
||||
assert.equal(properties.length, 0);
|
||||
assert.equal(node.indexers.length, 1);
|
||||
|
||||
return {
|
||||
type: 'map',
|
||||
values: make(node.indexers[0]),
|
||||
values: extract(node.indexers[0]),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'record',
|
||||
fields: node.properties.map(make).filter(Boolean),
|
||||
fields: node.properties.map(extract).filter(Boolean),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -78,7 +78,7 @@ const handlers = {
|
|||
}
|
||||
|
||||
if (!type) {
|
||||
type = make(node.value);
|
||||
type = extract(node.value);
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
|
@ -86,21 +86,21 @@ const handlers = {
|
|||
}
|
||||
|
||||
return {
|
||||
name: make(node.key),
|
||||
name: extract(node.key),
|
||||
type,
|
||||
};
|
||||
},
|
||||
|
||||
ObjectTypeIndexer(node) {
|
||||
const key = make(node.key);
|
||||
const key = extract(node.key);
|
||||
|
||||
assert.equal(key, 'string');
|
||||
|
||||
return make(node.value);
|
||||
return extract(node.value);
|
||||
},
|
||||
|
||||
TypeAnnotation(node) {
|
||||
return make(node.typeAnnotation);
|
||||
return extract(node.typeAnnotation);
|
||||
},
|
||||
|
||||
NumberTypeAnnotation(node) {
|
||||
|
@ -118,7 +118,7 @@ const handlers = {
|
|||
ArrayTypeAnnotation(node) {
|
||||
return {
|
||||
type: 'array',
|
||||
items: make(node.elementType),
|
||||
items: extract(node.elementType),
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -128,7 +128,7 @@ const handlers = {
|
|||
let [symbols, variants] = partition(node.types, isEnumSymbol);
|
||||
|
||||
symbols = symbols.map(unwrapEnumSymbol);
|
||||
variants = variants.map(make);
|
||||
variants = variants.map(extract);
|
||||
|
||||
if (symbols.length > 0) {
|
||||
const enumeration = {
|
||||
|
@ -147,7 +147,7 @@ const handlers = {
|
|||
},
|
||||
|
||||
NullableTypeAnnotation(node) {
|
||||
return ['null', make(node.typeAnnotation)];
|
||||
return ['null', extract(node.typeAnnotation)];
|
||||
},
|
||||
|
||||
NullLiteralTypeAnnotation(node) {
|
||||
|
@ -164,7 +164,7 @@ const handlers = {
|
|||
},
|
||||
|
||||
GenericTypeAnnotation(node) {
|
||||
return make(node.id);
|
||||
return extract(node.id);
|
||||
},
|
||||
|
||||
FunctionTypeAnnotation(node) {
|
||||
|
@ -212,7 +212,7 @@ function isValidPragma(pragma) {
|
|||
|
||||
function getLastPragma(comments) {
|
||||
const pragmas = comments
|
||||
.map(make)
|
||||
.map(extract)
|
||||
.filter(Boolean);
|
||||
|
||||
return pragmas.length > 0 ? pragmas[pragmas.length - 1] : null;
|
||||
|
@ -226,4 +226,4 @@ function unwrapEnumSymbol(node) {
|
|||
return node.value;
|
||||
}
|
||||
|
||||
module.exports = make;
|
||||
module.exports = extract;
|
|
@ -4,10 +4,10 @@ const assert = require('assert');
|
|||
|
||||
const parse = require('./parser');
|
||||
const visit = require('./visitor');
|
||||
const make = require('./maker');
|
||||
const extract = require('./extractor');
|
||||
|
||||
function collect(node, schemes) {
|
||||
const scheme = make(node);
|
||||
const scheme = extract(node);
|
||||
|
||||
const name = node.id.name;
|
||||
|
||||
|
|
Loading…
Reference in New Issue