shady-css-parser
Version:
A fast, small and flexible CSS parser.
96 lines • 3.56 kB
JavaScript
/**
* @license
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt The complete set of authors may be found
* at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
* be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
* Google as part of the polymer project is also subject to an additional IP
* rights grant found at http://polymer.github.io/PATENTS.txt
*/
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("./common");
/**
* Class used for generating nodes in a CSS AST. Extend this class to implement
* visitors to different nodes while the tree is being generated, and / or
* custom node generation.
*/
class NodeFactory {
/**
* Creates a Stylesheet node.
* @param rules The list of rules that appear at the top
* level of the stylesheet.
*/
stylesheet(rules, range) {
return { type: common_1.nodeType.stylesheet, rules, range };
}
/**
* Creates an At Rule node.
* @param name The "name" of the At Rule (e.g., `charset`)
* @param parameters The "parameters" of the At Rule (e.g., `utf8`)
* @param rulelist The Rulelist node (if any) of the At Rule.
*/
atRule(name, parameters, rulelist = undefined, nameRange, parametersRange, range) {
return {
type: common_1.nodeType.atRule,
name,
parameters,
rulelist,
nameRange,
parametersRange,
range
};
}
/**
* Creates a Comment node.
* @param value The full text content of the comment, including
* opening and closing comment signature.
*/
comment(value, range) {
return { type: common_1.nodeType.comment, value, range };
}
/**
* Creates a Rulelist node.
* @param rules An array of the Rule nodes found within the Ruleset.
*/
rulelist(rules, range) {
return { type: common_1.nodeType.rulelist, rules, range };
}
/**
* Creates a Ruleset node.
* @param selector The selector that corresponds to the Selector
* (e.g., `#foo > .bar`).
* @param rulelist The Rulelist node that corresponds to the Selector.
*/
ruleset(selector, rulelist, selectorRange, range) {
return { type: common_1.nodeType.ruleset, selector, rulelist, selectorRange, range };
}
/**
* Creates a Declaration node.
* @param name The property name of the Declaration (e.g., `color`).
* @param value Either an Expression node, or a Rulelist node, that
* corresponds to the value of the Declaration.
*/
declaration(name, value, nameRange, range) {
return { type: common_1.nodeType.declaration, name, value, nameRange, range };
}
/**
* Creates an Expression node.
* @param text The full text content of the expression (e.g.,
* `url(img.jpg)`)
*/
expression(text, range) {
return { type: common_1.nodeType.expression, text, range };
}
/**
* Creates a Discarded node. Discarded nodes contain content that was not
* parseable (usually due to typos, or otherwise unrecognized syntax).
* @param text The text content that is discarded.
*/
discarded(text, range) {
return { type: common_1.nodeType.discarded, text, range };
}
}
exports.NodeFactory = NodeFactory;
//# sourceMappingURL=node-factory.js.map
;