Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'scss-parser' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const deepArray = filenames.reduce((acc, filename) => {
// Do nothing for non-style files.
const ext = filename.split('.').pop()
if (!exts.includes(ext)) return acc
// File contents.
const fileContents = readFileSync(filename, 'utf-8')
// 1st try `scss-parser`.
try {
const parsedData = parse(fileContents).value
const selectors = parseStyleAST(parsedData)
return acc.concat(selectors)
// 2nd try `gonzales-pe`.
} catch(e) {
const parsed = parse2(fileContents, { syntax: ext })
const nodes = []
// Built-in traversal method, no need to recursively
// traverse the tree, cherry pick, and flatten the results!
parsed.traverse(node => {
if (shouldKeep2.includes(node.type)) {
const thing = node.content.find(({ type }) => type === 'ident')
if (thing) nodes.push(thing.content)
}
})
function parseScssDependencies(sourceContents, destinationFolder, sourceFolder) {
const sourceTree = scssParser.parse(sourceContents);
const scssWrapper = createQueryWrapper(sourceTree);
const importNodes = scssWrapper('atrule')
.has(wrapper => wrapper.node.value === 'import')
.children('string_single').nodes;
importNodes.forEach(node => {
// This should be the path for the import statement
const importPath = node.node.value;
// Prefix any resolved files with an underscore as they are not part of the core spec
const replacePath = resolveDependenciesAndCopy({
sourcePath: importPath,
destinationFolder,
sourceFolder,
prefix: '_',
});
sourceContents.replace(importPath, replacePath);
});
function parseProperties(source, baseDirectory) {
// Get the raw SCSS concrete syntax tree.
const rawTree = parseCSS(source);
removeWhitespace(rawTree);
// Convert the concrete syntax tree into a more convenient AST.
let schema
const rootRules = []
for (const rule of rawTree.value) {
if (rule.type === 'atrule') {
removeWhitespace(rule);
const [keyword, argument] = rule.value;
if (keyword.value === 'schema') {
schema = visitSchema(argument, baseDirectory)
} else if (keyword.value === 'import') {
rootRules.push(...visitImport(argument, baseDirectory))
}
} else {
rootRules.push(visitRule(rule, false))
function bemLintFileData(filePath, data, result, blockList, options) {
const fileOptions = options.getFileOptions(filePath);
const bem = createBem(fileOptions);
const moduleName = fileOptions.name;
const blockName = bem.getBlockNameFromFile(filePath);
const isIsolatedBlock = getIsIsolatedBlock(fileOptions, blockName);
if (isIsolatedBlock) {
result.addBlock(moduleName, blockName);
}
const ast = parse(data);
const $ = createQueryAst(ast);
// Checker
function checkInternalClassName() {
eachClassName($, (className, wrapper) => {
if (!bem.isBlockName(className, blockName)) {
if (bem.isClassPrefixMissing(className, blockName)) {
result.addError(`".${className}" should have a block prefix, ".${bem.getBaseClassFromBlockName(blockName)}" expected.`, filePath, moduleName, blockName, wrapper);
} else if (isClassFollowedByAPseudoClass($(wrapper))) {
result.addWarning(`".${className}" is only tolerated in this stylesheet.`, filePath, moduleName, blockName, wrapper);
} else {
result.addError(`".${className}" is incoherent with the file name, ".${bem.getBaseClassFromBlockName(blockName)}" expected.`, filePath, moduleName, blockName, wrapper);
}
}
});
}
export function parseDeclarations(data) {
const ast = parse(data);
const $ast = createQueryWrapper(ast);
const implicitGlobalDeclarations = $ast('declaration').hasParent('stylesheet');
const explicitGlobalDeclarations = $ast('declaration').hasParent('block')
.filter(node => isExplicitGlobalDeclaration($ast, node));
let implicitGlobals = implicitGlobalDeclarations.map(declaration => parseDeclaration($ast, declaration, SCOPE_IMPICIT));
let explicitGlobals = explicitGlobalDeclarations.map(declaration => parseDeclaration($ast, declaration, SCOPE_EXPLICIT));
return { explicitGlobals, implicitGlobals };
}
function parseExpression($ast, declaration) {
let flagsReached = false;
return stringify($ast(declaration)
.children('value')
.get(0))
.trim();
}