chore: clean up branch for merge
This commit is contained in:
parent
201ef0ae7d
commit
25be6a2898
@ -23,7 +23,6 @@ function reflectType5(srcFile, options = { debug: false }) {
|
|||||||
const src = String(readFileSync(srcFile))
|
const src = String(readFileSync(srcFile))
|
||||||
const defs = String(readFileSync(defFile))
|
const defs = String(readFileSync(defFile))
|
||||||
const parsedDefs = ts2json(defFile)
|
const parsedDefs = ts2json(defFile)
|
||||||
console.log('Defs from', defFile, 'are', parsedDefs)
|
|
||||||
|
|
||||||
const typeDefMatches = defs.matchAll(/: ({(?:(?!\n}).)+\n}) & (?:(?!ReflectedTypeInfo).)+ReflectedTypeInfo/gs)
|
const typeDefMatches = defs.matchAll(/: ({(?:(?!\n}).)+\n}) & (?:(?!ReflectedTypeInfo).)+ReflectedTypeInfo/gs)
|
||||||
if (!typeDefMatches) {
|
if (!typeDefMatches) {
|
||||||
@ -48,8 +47,10 @@ function reflectType5(srcFile, options = { debug: false }) {
|
|||||||
|
|
||||||
for (const id in parsedDefs) {
|
for (const id in parsedDefs) {
|
||||||
if (id.includes('interface')) continue
|
if (id.includes('interface')) continue
|
||||||
|
if (parsedDefs[id] === undefined) continue
|
||||||
|
log(` Tagging ${id} with type data`, parsedDefs[id])
|
||||||
srcReflected +=
|
srcReflected +=
|
||||||
`\n${id}._reflectedType6 = ${JSON.stringify(parsedDefs[id])}\n`
|
`\n${id}._reflectedType5 = ${JSON.stringify(parsedDefs[id])}\n`
|
||||||
}
|
}
|
||||||
writeFileSync(srcFile, srcReflected)
|
writeFileSync(srcFile, srcReflected)
|
||||||
|
|
||||||
|
@ -101,7 +101,6 @@ function typeStructure(typeNode, checker) {
|
|||||||
_index: typeStructure(typeNode.indexType, checker)
|
_index: typeStructure(typeNode.indexType, checker)
|
||||||
}
|
}
|
||||||
case ts.SyntaxKind.TypeOperator:
|
case ts.SyntaxKind.TypeOperator:
|
||||||
console.log('structuring operator', typeNode)
|
|
||||||
const key = typeOperatorKeywords.get(
|
const key = typeOperatorKeywords.get(
|
||||||
typeNode.operator,
|
typeNode.operator,
|
||||||
'_unidentified_operator'
|
'_unidentified_operator'
|
||||||
@ -139,27 +138,31 @@ function typeStructure(typeNode, checker) {
|
|||||||
|
|
||||||
const visit = (parent, checker) => node => {
|
const visit = (parent, checker) => node => {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
|
// Currently, we are ignoring the following sorts of statements
|
||||||
|
// that may appear in .d.ts files. We may need to revisit these,
|
||||||
|
// especially the InterfaceDeclaration and TypeAliasDeclaration,
|
||||||
|
// if we want to generate runtime information on pure type
|
||||||
|
// declarations. I think this may be necessary for example to compute
|
||||||
|
// the "RealType" of a type at runtime.
|
||||||
|
case ts.SyntaxKind.EndOfFileToken:
|
||||||
|
case ts.SyntaxKind.ExportDeclaration:
|
||||||
case ts.SyntaxKind.ImportDeclaration:
|
case ts.SyntaxKind.ImportDeclaration:
|
||||||
console.log('Skipping import from', node.moduleSpecifier.text)
|
case ts.SyntaxKind.InterfaceDeclaration:
|
||||||
|
case ts.SyntaxKind.TypeAliasDeclaration:
|
||||||
break
|
break
|
||||||
case ts.SyntaxKind.VariableStatement:
|
case ts.SyntaxKind.VariableStatement:
|
||||||
console.log('Processing variable',
|
|
||||||
ts.SyntaxKind[node.declarationList.kind])
|
|
||||||
node.declarationList.declarations.forEach(visit(parent, checker))
|
node.declarationList.declarations.forEach(visit(parent, checker))
|
||||||
console.log('Done with variable')
|
|
||||||
break
|
break
|
||||||
case ts.SyntaxKind.VariableDeclaration: {
|
case ts.SyntaxKind.VariableDeclaration: {
|
||||||
console.log('Processing var dec', node.name.text)
|
|
||||||
const typeStruc = typeStructure(node.type, checker)
|
const typeStruc = typeStructure(node.type, checker)
|
||||||
parent.addChild(node.name.text, typeStruc)
|
parent.addChild(node.name.text, typeStruc)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ts.SyntaxKind.FunctionDeclaration: {
|
case ts.SyntaxKind.FunctionDeclaration: {
|
||||||
console.log('Processing func dec', node.name.text)
|
const typeStruc = {
|
||||||
const typeStruc = {
|
_parameters: node.parameters.map(
|
||||||
_parameters: node.parameters.map(
|
p => parameterTypeStructure(p, checker)),
|
||||||
p => parameterTypeStructure(p, checker)),
|
_returns: typeStructure(node.type, checker)
|
||||||
_returns: typeStructure(node.type, checker)
|
|
||||||
}
|
}
|
||||||
if (node.typeParameters) {
|
if (node.typeParameters) {
|
||||||
typeStruc._typeParameters = node.typeParameters.map(
|
typeStruc._typeParameters = node.typeParameters.map(
|
||||||
@ -170,20 +173,11 @@ const visit = (parent, checker) => node => {
|
|||||||
}
|
}
|
||||||
case ts.SyntaxKind.ModuleDeclaration:
|
case ts.SyntaxKind.ModuleDeclaration:
|
||||||
let moduleName = node.name.text
|
let moduleName = node.name.text
|
||||||
console.log('Declaring', moduleName)
|
visit(parent.addChild(moduleName), checker)(node.body)
|
||||||
ts.forEachChild(node, visit(parent.addChild(moduleName), checker))
|
|
||||||
break
|
break
|
||||||
case ts.SyntaxKind.ModuleBlock:
|
case ts.SyntaxKind.ModuleBlock:
|
||||||
console.log('Block')
|
|
||||||
ts.forEachChild(node, visit(parent, checker));
|
ts.forEachChild(node, visit(parent, checker));
|
||||||
break
|
break
|
||||||
case ts.SyntaxKind.InterfaceDeclaration:
|
|
||||||
let interfaceName = node.name.text
|
|
||||||
console.log('Skipping Interface', interfaceName);
|
|
||||||
break
|
|
||||||
parent[interfaceName] = {}
|
|
||||||
ts.forEachChild(node, visit(parent.addChild(interfaceName), checker))
|
|
||||||
break
|
|
||||||
case ts.SyntaxKind.PropertySignature:
|
case ts.SyntaxKind.PropertySignature:
|
||||||
let propertyName = node.name
|
let propertyName = node.name
|
||||||
let propertyType = node.type
|
let propertyType = node.type
|
||||||
@ -217,9 +211,6 @@ const visit = (parent, checker) => node => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ts.SyntaxKind.EndOfFileToken:
|
|
||||||
console.log('File ended.')
|
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
console.warn(
|
console.warn(
|
||||||
'Unhandled node kind',
|
'Unhandled node kind',
|
||||||
|
Loading…
Reference in New Issue
Block a user