Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function transpileDecl(result, promises, decl, opts, cache) { // eslint-disable-line max-params
// path to the current working file and directory by declaration
const declWF = path.resolve(decl.source && decl.source.input && decl.source.input.file ? decl.source.input.file : result.root.source && result.root.source.input && result.root.source.input.file ? result.root.source.input.file : path.join(process.cwd(), 'index.css'));
const declWD = path.dirname(declWF);
// list of files to watch
const files = {};
// walk each node of the declaration
const declAST = parser(decl.value).parse();
declAST.walk(node => {
// if the node is a url containing an svg fragment
if (isExternalURLFunction(node)) {
// of url()
const urlNode = node.nodes[1];
// split by fragment identifier symbol (#)
const urlParts = urlNode.value.split('#');
// src
const src = urlParts[0];
// fragment identifier
const id = urlParts.slice(1).join('#');
function check(decl, size) {
// Parse the size and walk through Numerics
parse(size, {
ignoreUnknownWords: true
}).walkNumerics(({ value, unit: valueUnit }) => {
// Return early if not a checked unit
if (!lengthUnits.includes(valueUnit)) return;
// Validate scale and units
const validUnit = unit ? valueUnit === unit : true;
const validScale = scale.includes(Math.abs(Number(value)));
// Get message of the violation
let message;
if (!validScale) {
message = messages.expected(`${value}`, scale.join(", "));
} else if (!validUnit) {
message = messages.expected(`${valueUnit}`, `${unit}`);
} else {
function check(decl, size) {
// Parse the size and walk through Numerics
parse(size, {
ignoreUnknownWords: true
}).walkNumerics(({ value, unit: valueUnit }) => {
// Return early if not a checked unit
if (!lengthUnits.includes(valueUnit)) return;
// Validate scale and units
const validUnit = unit ? valueUnit === unit : true;
const validScale = scale.includes(Number(value));
// Get message of the violation
let message;
if (!validScale) {
message = messages.expected(`${value}`, scale.join(", "));
} else if (!validUnit) {
message = messages.expected(`${valueUnit}`, `${unit}`);
} else {
function check(decl, size) {
// Parse the size and walk through Numerics
parse(size, {
ignoreUnknownWords: true
}).walkNumerics(({ value, unit: valueUnit }) => {
// Return early if not a checked unit
if (!lengthUnits.includes(valueUnit)) return;
// Validate scale and units
const validUnit = unit ? valueUnit === unit : true;
const validScale = scale.includes(Number(value));
// Get message of the violation
let message;
if (!validScale) {
message = messages.expected(`${value}`, scale.join(", "));
} else if (!validUnit) {
message = messages.expected(`${valueUnit}`, `${unit}`);
} else {
function check(decl, size) {
// Parse the size and walk through Numerics
parse(size, {
ignoreUnknownWords: true
}).walkNumerics(({ value, unit: valueUnit }) => {
// Return early if not a checked unit
if (!lengthUnits.includes(valueUnit)) return;
// Validate scale and units
const validUnit = unit ? valueUnit === unit : true;
const validScale = scale.includes(Math.abs(Number(value)));
// Get message of the violation
let message;
if (!validScale) {
message = messages.expected(`${value}`, scale.join(", "));
} else if (!validUnit) {
message = messages.expected(`${valueUnit}`, `${unit}`);
} else {
rule.nodes.slice().forEach(decl => {
if (isCustomDecl(decl) && !isBlockIgnored(decl)) {
const { prop } = decl;
// write the parsed value to the custom property
customPropertiesObject[prop] = parse(decl.value).nodes;
// conditionally remove the custom property declaration
if (!opts.preserve) {
decl.remove();
}
}
});
export default (originalValue, variables) => {
// get the ast of the original value
const ast = parse(originalValue);
// walk all of the css env() functions
walkEnvFuncs(ast, node => {
// update the environment value for the css env() function
updateEnvValue(node, variables);
});
// return the stringified ast
return String(ast);
};
function getSingleTimingFunction(animation) {
let timingFunction
parse(animation).walk(node => {
// There should only be one timing function per shorthand
if (timingFunction) {
return
}
// Look for timing keywords
if (
node.type === 'word' &&
[
'ease',
'ease-in',
'ease-in-out',
'ease-out',
'linear',
'step-start',
'step-end'
function check(decl, size) {
// Parse the size and walk through Numerics
parse(size, {
ignoreUnknownWords: true
}).walkNumerics(({ value, unit: valueUnit }) => {
// Return early if not a checked unit
if (!lengthUnits.includes(valueUnit)) return;
// Validate scale and units
const validUnit = unit ? valueUnit === unit : true;
const validScale = scale.includes(Math.abs(Number(value)));
// Get message of the violation
let message;
if (!validScale) {
message = messages.expected(`${value}`, scale.join(", "));
} else if (!validUnit) {
message = messages.expected(`${valueUnit}`, `${unit}`);
} else {
styleAST.walkDecls(decl => {
const declAST = parser(decl.value).parse();
// update the declaration with all transpiled var()s
declAST.walk(node => {
// conditionally update the var()
if (isVarFuntion(node)) {
transpileVar(node, params);
}
});
decl.value = declAST.toString();
});