How to use the stylus.Parser function in stylus

To help you get started, we’ve selected a few stylus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ThisIsManta / stylus-supremacy / test / runner.js View on Github external
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,
github ThisIsManta / stylus-supremacy / edge / format.js View on Github external
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)}`)
github vuejs / vetur / server / src / modes / style / stylus / parser.ts View on Github external
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;
  }
}
github ThisIsManta / stylus-supremacy / test / runner.js View on Github external
it('can be re-parsed', () => {
			try {
				new Stylus.Parser(outputContent).parse()
			} catch (ex) {
				fail(ex)
			}
		})
github d4rkr00t / language-stylus / src / parser.ts View on Github external
export function buildAst(text:string) : StylusNode | any[] {
  try {
    return new stylus.Parser(text).parse();
  } catch (error) {
    return [];
  }
}
github d4rkr00t / language-stylus / out / src / parser.js View on Github external
function buildAst(text) {
    try {
        return new stylus.Parser(text).parse();
    }
    catch (error) {
        return [];
    }
}
exports.buildAst = buildAst;