Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { code } = await babel.transformAsync(source, { ...babelConfig, filename: tsxPath });
if (/import \w* from 'prop-types'/.test(code)) {
throw new Error('TypeScript demo contains prop-types, please remove them');
}
const propTypesAST = typescriptToProptypes.parseFromProgram(tsxPath, program, {
shouldResolveObject: ({ name }) => {
if (name === 'classes') {
return false;
}
return undefined;
},
});
const codeWithPropTypes = typescriptToProptypes.inject(propTypesAST, code);
const prettified = prettier.format(codeWithPropTypes, { ...prettierConfig, filepath: tsxPath });
const formatted = fixBabelGeneratorIssues(prettified);
const correctedLineEndings = fixLineEndings(source, formatted);
await fse.writeFile(jsPath, correctedLineEndings);
return TranspileResult.Success;
} catch (err) {
console.error('Something went wrong transpiling %s\n%s\n', tsxPath, err);
return TranspileResult.Failed;
}
}
proptypes.body.forEach(component => {
component.types.forEach(prop => {
if (prop.name === 'classes' && prop.jsDoc) {
prop.jsDoc += '\nSee [CSS API](#css) below for more details.';
} else if (prop.name === 'children' && !prop.jsDoc) {
prop.jsDoc = 'The content of the component.';
} else if (!prop.jsDoc) {
prop.jsDoc = '@ignore';
}
});
});
const jsContent = await fse.readFile(jsFile, 'utf8');
const result = ttp.inject(proptypes, jsContent, {
removeExistingPropTypes: true,
comment: [
'----------------------------- Warning --------------------------------',
'| These PropTypes are generated from the TypeScript type definitions |',
'| To update them edit the d.ts file and run "yarn proptypes" |',
'----------------------------------------------------------------------',
].join('\n'),
shouldInclude: ({ prop }) => {
if (prop.name === 'children') {
return true;
}
const documentRegExp = new RegExp(/\r?\n?@document/);
if (prop.jsDoc && documentRegExp.test(prop.jsDoc)) {
prop.jsDoc = prop.jsDoc.replace(documentRegExp, '');
return true;