Sha256: eeaac01dca24bccbb6d2f69ad5750a254eb311d3679fe837659c0fd1d9378c09

Contents?: true

Size: 940 Bytes

Versions: 24

Compression:

Stored size: 940 Bytes

Contents

"use strict";

const parser = require("./parser");
const processor = require("./processor");
const getLang = require("./get-lang");
const normalOpts = require("./normal-opts");

function getSyntax (opts, source) {
	const rules = opts.syntax && opts.syntax.config && opts.syntax.config.rules;
	const file = opts.from || "";
	return (rules && rules.find(
		rule => rule.test.test ? rule.test.test(file) : rule.test(file, source)
	)) || getLang(file, source) || {
		lang: "css",
	};
}

function parse (source, opts) {
	source = source.toString();
	opts = normalOpts(opts, this);
	const syntax = getSyntax(opts, source);
	const syntaxOpts = Object.assign({}, opts, syntax.opts);
	let root;
	if (syntax.extract) {
		root = processor(source, syntax.extract, syntaxOpts);
		root.source.lang = syntax.extract;
	} else {
		root = parser(source, syntax.lang, syntaxOpts);
		root.source.lang = syntax.lang;
	}
	return root;
}

module.exports = parse;

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.7 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.6 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.5 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.4 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.3 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.2 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.1 node_modules/postcss-syntax/parse.js
trusty-cms-4.3.5 node_modules/postcss-syntax/parse.js
trusty-cms-5.0.0 node_modules/postcss-syntax/parse.js
trusty-cms-4.3.4 node_modules/postcss-syntax/parse.js
trusty-cms-4.3.3 node_modules/postcss-syntax/parse.js
trusty-cms-4.3.2 node_modules/postcss-syntax/parse.js
trusty-cms-4.3.1 node_modules/postcss-syntax/parse.js
trusty-cms-4.3 node_modules/postcss-syntax/parse.js
trusty-cms-4.2.3 node_modules/postcss-syntax/parse.js
trusty-cms-4.2.2 node_modules/postcss-syntax/parse.js
trusty-cms-4.2.1 node_modules/postcss-syntax/parse.js
trusty-cms-4.2 node_modules/postcss-syntax/parse.js
trusty-cms-4.1.9 node_modules/postcss-syntax/parse.js