Skip to content

Commit

Permalink
Further createDeclaration improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstart committed Apr 28, 2020
1 parent 22e3a8c commit eb43854
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bin/createDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ for (let file of files)
// for each class, set up a declaration for it
for (const classData of classes)
{
output += `declare class ${classData.className} extends animate.${classData.baseClass} {
${classData.props.map(({ name, source, type }) => ` ${name}: ${source ? '' : 'animate.'}${type};`).join('\n')}
}
output += `declare class ${classData.className} extends animate.${classData.baseClass} {${classData.props.length
? '\n' + classData.props
.map(({ name, source, type }) => ` ${name}: ${source ? '' : 'animate.'}${type};`)
.join('\n') + '\n'
: ''}}
`;
}
// create an interface for our specific library
Expand All @@ -126,7 +128,7 @@ ${classes.map(({ className }) => ` ${className}: typeof ${className};`).join(
// figure out which class is the root class
const [, root] = (/data\.stage ?= ?data\.lib\.([a-zA-Z0-9$_]+)/).exec(source);
// declare the data object, mix in our specific library (can't override it, I think?)
output += `declare const data: animate.AnimateAsset & {lib: Lib, stage: typeof ${root}};
output += `declare const data: Omit<animate.AnimateAsset, 'stage'|'lib'> & {lib: Lib, stage: typeof ${root}};
`;
output += `${source.match(/export default data/) ? 'export default' : 'export ='} data;
`;
Expand Down

0 comments on commit eb43854

Please sign in to comment.