Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function sfcToAST(
source: string,
babelParserPlugins?: BabelParserPlugins,
basedir?: string
): AstResult {
const plugins = getBabelParserPlugins(babelParserPlugins)
const sfc = parseComponent(source)
const res: AstResult = {}
if (sfc.script) {
if (!sfc.script.content && sfc.script.src) {
// Src Imports
if (basedir) {
try {
sfc.script.content = fs.readFileSync(
path.resolve(basedir, sfc.script.src),
'utf-8'
)
} catch (e) {
console.error(e)
sfc.script.content = ''
}
}
}
exports.parse = function parse(file, options, withWrap = true) {
const {target} = options;
const content = preParse(file.contents.toString());
let {
script = {},
template = {},
styles = [{}],
customBlocks = []
} = parseComponent(content, {});
let configBlocks = {
default: [],
target: []
};
customBlocks.forEach(block => {
if (block.type === 'config') {
if (!block.attrs.target) {
configBlocks.default.push(block);
}
if (block.attrs.target === (process.env.MARS_ENV_TARGET || target)) {
configBlocks.target.push(block);
}
}