Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('can be formatted', () => {
if (fs.existsSync(inputFormattedFilePath)) fs.unlinkSync(inputFormattedFilePath)
try {
const tree = new Stylus.Parser(inputContent).parse()
fs.writeFileSync(inputDebuggingFilePath, JSON.stringify(tree, null, '\t'))
} catch (ex) {
// Do nothing
}
const actualContent = format(inputContent, formattingOptions)
const errorMessage = compareContent(actualContent, outputContent)
if (errorMessage) {
fs.writeFileSync(inputFormattedFilePath, actualContent)
const stack = [
inputFilePath,
inputFormattedFilePath,
inputDebuggingFilePath,
outputFilePath,
modifiedContent = 'wrap\n' + originalLines.map(line => {
if (line.trim().length > 0) {
return (originalTabStopChar || '\t') + line.substring(twoShortestIndent[0].length)
} else {
return ''
}
}).join('\n')
}
}
// Used to determine some information that `rootNode` does not offer
// For example, a single-line comment
const modifiedLines = modifiedContent.split(/\r?\n/)
// Store the Stylus parsed tree
const rootNode = new Stylus.Parser(modifiedContent).parse()
// Return the original content if it only has comments
if (rootNode.nodes.every(node => node instanceof Stylus.nodes.Comment)) {
return content
}
function travel(parentNode, inputNode, indentLevel, insideExpression = false, data = {}) {
// Check argument type
if (!(_.isObject(parentNode) || parentNode === null && inputNode instanceof Stylus.nodes.Root)) {
throw new Error(`Found a parent node of ${JSON.stringify(parentNode)}`)
} else if (!(_.isObject(inputNode))) {
throw new Error(`Found an input node of ${JSON.stringify(inputNode)}` + (parentNode ? `, which had a parent node of ${JSON.stringify(parentNode)}` : ''))
} else if (!(_.isInteger(indentLevel) && indentLevel >= 0)) {
throw new Error(`Found an indent level of ${JSON.stringify(indentLevel)}`)
} else if (!(_.isBoolean(insideExpression))) {
throw new Error(`Found an expression flag of ${JSON.stringify(insideExpression)}`)
export function buildAst(text: string): StylusNode | null {
try {
const root = new stylus.Parser(text).parse();
// root is read only
const ret = JSON.parse(JSON.stringify(root.toJSON()));
addScope(ret, 0, []);
return ret;
} catch (error) {
return null;
}
}
it('can be re-parsed', () => {
try {
new Stylus.Parser(outputContent).parse()
} catch (ex) {
fail(ex)
}
})
export function buildAst(text:string) : StylusNode | any[] {
try {
return new stylus.Parser(text).parse();
} catch (error) {
return [];
}
}
function buildAst(text) {
try {
return new stylus.Parser(text).parse();
}
catch (error) {
return [];
}
}
exports.buildAst = buildAst;