Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runValidation(source: string, expectedOutput: {}, options: Options, skipNodeCheck: boolean): void {
const compile = options.useCS2 ? cs2Compile : cs1Compile;
const coffeeES5 = compile(source, { bare: true }) as string;
const decaffeinateES6 = convert(source, options).code;
const transformed = babel.transformSync(decaffeinateES6, {
presets: ['@babel/preset-env']
});
const decaffeinateES5 = (transformed && transformed.code) || '';
const coffeeOutput = runCodeAndExtract(coffeeES5);
const decaffeinateOutput = runCodeAndExtract(decaffeinateES5);
try {
assertDeepEqual(decaffeinateOutput, coffeeOutput, 'decaffeinate and coffee output were different.');
} catch (err) {
// add some additional context for debugging
err.message = `Additional Debug:
SOURCE
${source}
********************
INPUT -> COFFEE-SCRIPT -> ES5
${coffeeES5}
async function makeBackwardsCompatible (source) {
const cssProcessed = await processCss(source)
return babel.transformSync(cssProcessed, {
presets: [[presetEnv, {
// use browserslist config from package.json
useBuiltIns: 'entry'
}]]
}).code
}
// Fix differently-named types:
.replace(/\bmixed\b/g, 'unknown')
.replace(/\| void\b/g, '| undefined')
// Fix `import type` syntax:
.replace(/\bimport type\b/g, 'import')
.replace(/\btype ([_a-zA-Z]+)( *[,\n}])/g, '$1$2')
// We aren't JS anymore:
.replace(/\/\/ @flow/, '')
.replace(/'(\.[^']*)\.js'/, "'$1'")
return output
}
// Transpile errors to plain Javascript and TypeScript:
const errorFile = fs.readFileSync('src/types/error.js', 'utf8')
const errorJs = babel.transformSync(errorFile, {
presets: ['@babel/preset-flow'],
plugins: [
'@babel/plugin-transform-modules-commonjs',
'babel-plugin-transform-fake-error-class'
]
}).code
fs.writeFileSync('types.js', errorJs)
fs.writeFileSync('src/types/error.ts', jsToTs(errorFile))
// Transpile Flow types to Typescript:
const typesFile = fs.readFileSync('src/types/types.js', 'utf8')
fs.writeFileSync('src/types/types.ts', jsToTs(typesFile))
// Fix the files with ESLint:
const cli = new eslint.CLIEngine({ fix: true, ignore: false })
const report = cli.executeOnFiles(['./src/types/*.ts'])
const fn = `function MDXContent({ components, ...props }) {
return (
${jsxNodes.map(childNode => toJSX(childNode, node)).join('')}
)
};
MDXContent.isMDXComponent = true`
// Check JSX nodes against imports
const babelPluginExtractImportNamesInstance = new BabelPluginExtractImportNames()
transformSync(importStatements, {
configFile: false,
babelrc: false,
plugins: [
require('@babel/plugin-syntax-jsx'),
require('@babel/plugin-syntax-object-rest-spread'),
babelPluginExtractImportNamesInstance.plugin
]
})
const importNames = babelPluginExtractImportNamesInstance.state.names
const babelPluginApplyMdxPropInstance = new BabelPluginApplyMdxProp()
const babelPluginApplyMdxPropToExportsInstance = new BabelPluginApplyMdxProp()
const fnPostMdxTypeProp = transformSync(fn, {
configFile: false,
babelrc: false,
it('should allow for default import', () => {
const code = `
import App, * as proxies from 'cerebral';
proxies.state.hello.world;
`
const { code: result } = transformSync(code, pluginOptions)
expect(result).toMatchSnapshot()
})
})
const tester = allOpts => async opts => {
let rawCode = opts.code
if (!opts.code && opts.filename) {
rawCode = await readFile(opts.filename, 'utf-8')
}
if (allOpts.transform) {
rawCode = allOpts.transform(rawCode)
}
const { code } = babel.transformSync(rawCode, {
plugins: [
'macros',
'@babel/plugin-syntax-jsx',
`@babel/plugin-syntax-class-properties`,
...(allOpts.plugins || [])
],
presets: allOpts.presets,
babelrc: false,
filename: opts.babelFileName || __filename
})
expect(`${rawCode}${separator}${code}`).toMatchSnapshot()
}
expect(() => {
transformSync('<>', {
filename: __filename,
plugins: [[jsxPragmatic, { export: 'jsx' }]]
})
}).toThrow(
'@emotion/babel-plugin-jsx-pragmatic: You must specify `module` and `import`'
function transformFile(filePath) {
const fileContent = fs.readFileSync(filePath);
const { code } = transformSync(fileContent, {
babelrc: false,
configFile: false,
plugins: [
['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
],
});
fs.writeFileSync(filePath, code);
}
reactFiles.forEach((fileName) => {
}];
optionsCopy.presets = presets;
optionsCopy.sourceMaps = true;
if (result.map) {
optionsCopy.inputSourceMap = result.map;
}
if (result.ast) {
result = babelCore.transformFromAstSync(
result.ast,
result.code,
optionsCopy
);
} else {
result = babelCore.transformSync(result.code, optionsCopy);
}
if (ast === false) {
delete result.ast;
}
}
transform(content, path) {
return babel.transformSync(content, {
presets: [
require("@babel/preset-env"),
require("babel-preset-minify")
],
comments: false
}).code;
}
}])