Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [jsStat, tsxStat] = await Promise.all([fse.stat(jsPath), fse.stat(tsxPath)]);
if (jsStat.mtimeMs > tsxStat.mtimeMs) {
// JavaScript version is newer, skip transpiling
return TranspileResult.Skipped;
}
}
const source = await fse.readFile(tsxPath, 'utf8');
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;
async function generateProptypes(
tsFile: string,
jsFile: string,
program: ttp.ts.Program,
): Promise {
const proptypes = ttp.parseFromProgram(tsFile, program, {
shouldResolveObject: ({ name }) => {
if (name.toLowerCase().endsWith('classes') || name === 'theme' || name.endsWith('Props')) {
return false;
}
return undefined;
},
});
if (proptypes.body.length === 0) {
return GenerateResult.NoComponent;
}
proptypes.body.forEach(component => {
component.types.forEach(prop => {
if (prop.name === 'classes' && prop.jsDoc) {
prop.jsDoc += '\nSee [CSS API](#css) below for more details.';