Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const opts = Object.assign(
{
ast: true,
code: false
},
transformerOpts,
{
plugins: [
// For some reason, recast doesn't work with transformFromAst.
// Use this hack instead.
[setAst, { ast }]
].concat(transformerOpts.plugins || [])
}
);
const output = await babel.transformAsync("", opts);
return recast.print(output.ast).code;
}
function compile(filename, source) {
// babel runs out of memory when processing source maps for large files
const sourceMaps = source.length > BABEL_DEOPTIMIZED_LENGTH ? false : 'inline';
return transformAsync(source, { filename, sourceMaps, ...babelConfig }).then(
result => result.code,
);
}
export async function run(src, options, filename = 'MyStyleFile.js') {
const { code, metadata } = await transformAsync(src, {
filename,
babelrc: false,
plugins: [
[require('../src/plugin.js'), { ...options, writeFiles: false }],
].filter(Boolean),
parserOpts: PARSER_OPTS,
});
return [
prettier.format(code, { filepath: filename }),
metadata.astroturf.styles,
];
}
function (file, encoding, cb) {
if (file.isNull()) return cb(null, file)
const opts = {
filename: file.path,
filenameRelative: file.relative,
sourceMap: Boolean(file.sourceMap),
sourceFileName: file.relative,
configFile: false,
plugins: [plugin],
}
babel.transformAsync(file.contents.toString(), opts)
.then(res => {
file.contents = Buffer.from(res.code.replace(/"use strict";/g, ''), 'utf-8')
this.push(file)
})
.catch(err => {
this.emit('error', new PluginError('gulp-wx-babel', err, {
fileName: file.path,
showProperties: true
}))
})
.finally(cb)
},
cb(new PluginError('gulp-babel', '@babel/core@^7.0.0 is required'));
return;
}
const fileOpts = Object.assign({}, opts, {
filename: file.path,
filenameRelative: file.relative,
sourceMap: Boolean(file.sourceMap),
sourceFileName: file.relative,
caller: Object.assign(
{name: 'babel-gulp'},
opts.caller
)
});
babel.transformAsync(file.contents.toString(), fileOpts).then(res => {
if (res) {
if (file.sourceMap && res.map) {
res.map.file = replaceExtension(file.relative);
applySourceMap(file, res.map);
}
file.contents = Buffer.from(res.code);
file.path = replaceExtension(file.path);
file.babel = res.metadata;
}
this.push(file);
}).catch(error => {
this.emit('error', new PluginError('gulp-babel', error, {
fileName: file.path,
return async function transformMdxToJs(filePath, body) {
const jsx = `
import { React, mdx } from '${urlToPrebuilt}';
${await mdx(body, { compilers, filepath: filePath })}
`.replace('@storybook/addon-docs/blocks', urlToPrebuilt);
return transformAsync(jsx, {
filename: filePath,
sourceMaps: true,
plugins: [require.resolve('@babel/plugin-transform-react-jsx')],
});
};
};
export const transformAsync = code => {
return babel.transformAsync(code, babelOptions);
};
function processTs(file, fileContent) {
return babel.transformAsync(fileContent, {filename: file, plugins: [pluginTransformRemoveImport, pluginTransformRemoveExport]}).then((result) => {
return result.code;
});
}
start: 0,
end: null,
body: [],
}
const jsCode = await convert(load, options, {
filePath: id,
caller: {
name: '@svgr/rollup',
previousExport,
defaultPlugins: [svgo, jsx],
},
})
if (babel) {
const { code } = await transformAsync(jsCode, babelOptions)
return { code, map: { mappings: '' } }
}
return { ast, code: jsCode, map: { mappings: '' } }
},
}
return null;
}
let transformOptions = !overrides.config
? config.options
: await overrides.config.call(this, config, {
code: inputCode,
customOptions
});
if (finalizeOptions) {
transformOptions = await finalizeOptions(transformOptions);
}
if (!overrides.result) {
const { code, map } = await babel.transformAsync(inputCode, transformOptions);
return {
code,
map
};
}
const result = await babel.transformAsync(inputCode, transformOptions);
const { code, map } = await overrides.result.call(ctx, result, {
code: inputCode,
customOptions,
config,
transformOptions
});
return {
code,
map