Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const compiler = require('vue-native-template-compiler');
const constants = require('vue-native-scripts/src/util/constants');
let pug;
try {
pug = require('pug');
} catch (e) {
console.log('pug not loaded');
}
const defaultTemplate = {
import: `import { Component as ${constants.COMPONENT} } from 'react'`,
render: `const ${constants.TEMPLATE_RENDER} = () => null`,
};
function transpileTemplateContent(content, lang) {
if (lang === 'pug') {
if (pug) {
return pug.render(content);
} else {
throw new Error(`failed to load pug! please add pug as a dependency.`);
}
}
return content;
}
function parseTemplate(template) {
if (!template) {
const compiler = require('vue-native-template-compiler');
const constants = require('vue-native-scripts/src/util/constants');
let pug;
try {
pug = require('pug');
} catch (e) {
console.log('pug not loaded');
}
const defaultTemplate = {
import: `import { Component as ${constants.COMPONENT} } from 'react'`,
render: `const ${constants.TEMPLATE_RENDER} = () => null`,
};
function transpileTemplateContent(content, lang) {
if (lang === 'pug') {
if (pug) {
return pug.render(content);
} else {
throw new Error(`failed to load pug! please add pug as a dependency.`);
}
}
return content;
}
function parseTemplate(template) {
if (!template) {
return defaultTemplate;
function parseScript(script) {
if (!script) {
return defaultScript;
}
const scriptContent = script.content.replace(/\/\/\n/g, '').trim();
const s = `const ${constants.SCRIPT_OPTIONS} = `;
return scriptContent
.replace(/[\s;]*module.exports[\s]*=/, `\n${s}`)
.replace(/[\s;]*export[\s]+default[\s]*\{/, `\n${s} {`);
}
const defaultScript = `const ${constants.SCRIPT_OPTIONS} = {}`;
const constants = require('vue-native-scripts/src/util/constants');
function parseScript(script) {
if (!script) {
return defaultScript;
}
const scriptContent = script.content.replace(/\/\/\n/g, '').trim();
const s = `const ${constants.SCRIPT_OPTIONS} = `;
return scriptContent
.replace(/[\s;]*module.exports[\s]*=/, `\n${s}`)
.replace(/[\s;]*export[\s]+default[\s]*\{/, `\n${s} {`);
}
module.exports = parseScript;
module.exports.transform = function({ src, filename, options }) {
if (vueExtensions.some(ext => filename.endsWith("." + ext))) {
return vueNativeScripts.transform({ src, filename, options });
}
return upstreamTransformer.transform({ src, filename, options });
};
function parseStyles(styles) {
const parsedStylesObj = styles.reduce((prev, curr) => {
const { content, lang } = curr;
const transpiledContent = transpileStylesContent(content, lang);
const cssAST = cssParse(transpiledContent);
return Object.assign({}, prev, parseCSS(cssAST));
}, {});
return `const ${constants.CSS} = ${JSON.stringify(parsedStylesObj)}`;
}