1 import Container from './container';
2 import CssSyntaxError from './css-syntax-error';
3 import postcss from './postcss';
4 import Result from './result';
5 export default class Node implements postcss.Node {
7 * Returns a string representing the node's type. Possible values are
8 * root, atrule, rule, decl or comment.
12 * Contains information to generate byte-to-byte equal node string as it
13 * was in origin input.
15 raws: postcss.NodeRaws;
17 * Returns the node's parent node.
21 * Returns the input source of the node. The property is used in source map
22 * generation. If you create a node manually (e.g., with postcss.decl() ),
23 * that node will not have a source property and will be absent from the
24 * source map. For this reason, the plugin developer should consider cloning
25 * nodes to create new ones (in which case the new node's source will
26 * reference the original, cloned node) or setting the source property
29 source: postcss.NodeSource;
30 constructor(defaults?: Object);
32 * This method produces very useful error messages. If present, an input
33 * source map will be used to get the original position of the source, even
34 * from a previous compilation step (e.g., from Sass compilation).
35 * @returns The original position of the node in the source, showing line
36 * and column numbers and also a small excerpt to facilitate debugging.
42 message: string, options?: postcss.NodeErrorOptions): CssSyntaxError;
44 * Creates an instance of Warning and adds it to messages. This method is
45 * provided as a convenience wrapper for Result#warn.
46 * Note that `opts.node` is automatically passed to Result#warn for you.
47 * @param result The result that will receive the warning.
48 * @param text Warning message. It will be used in the `text` property of
50 * @param opts Properties to assign to the message object.
52 warn(result: Result, text: string, opts?: postcss.WarningOptions): void;
54 * Removes the node from its parent and cleans the parent property in the
55 * node and its children.
56 * @returns This node for chaining.
60 * @returns A CSS string representing the node.
62 toString(stringifier?: any): string;
64 * @param overrides New properties to override in the clone.
65 * @returns A clone of this node. The node and its (cloned) children will
66 * have a clean parent and code style properties.
68 clone(overrides?: Object): Node;
70 * Shortcut to clone the node and insert the resulting cloned node before
72 * @param overrides New Properties to override in the clone.
73 * @returns The cloned node.
75 cloneBefore(overrides?: Object): Node;
77 * Shortcut to clone the node and insert the resulting cloned node after
79 * @param overrides New Properties to override in the clone.
80 * @returns The cloned node.
82 cloneAfter(overrides?: Object): Node;
84 * Inserts node(s) before the current node and removes the current node.
85 * @returns This node for chaining.
87 replaceWith(...nodes: (Node | Object)[]): this;
89 * Removes the node from its current parent and inserts it at the end of
90 * newParent. This will clean the before and after code style properties
91 * from the node and replace them with the indentation style of newParent.
92 * It will also clean the between property if newParent is in another Root.
93 * @param newParent Where the current node will be moved.
94 * @returns This node for chaining.
96 moveTo(newParent: Container): this;
98 * Removes the node from its current parent and inserts it into a new
99 * parent before otherNode. This will also clean the node's code style
100 * properties just as it would in node.moveTo(newParent).
101 * @param otherNode Will be after the current node after moving.
102 * @returns This node for chaining.
104 moveBefore(otherNode: Node): this;
106 * Removes the node from its current parent and inserts it into a new
107 * parent after otherNode. This will also clean the node's code style
108 * properties just as it would in node.moveTo(newParent).
109 * @param otherNode Will be before the current node after moving.
110 * @returns This node for chaining.
112 moveAfter(otherNode: Node): this;
114 * @returns The next child of the node's parent; or, returns undefined if
115 * the current node is the last child.
119 * @returns The previous child of the node's parent; or, returns undefined
120 * if the current node is the first child.
123 toJSON(): postcss.JsonNode;
125 * @param prop Name or code style property.
126 * @param defaultType Name of default value. It can be easily missed if the
127 * value is the same as prop.
128 * @returns A code style property value. If the node is missing the code
129 * style property (because the node was manually built or cloned), PostCSS
130 * will try to autodetect the code style property by looking at other nodes
133 raw(prop: string, defaultType?: string): any;
135 * @returns The Root instance of the node's tree.
138 cleanRaws(keepBetween?: boolean): void;
139 positionInside(index: number): {
143 positionBy(options: any): {
148 * Deprecated. Use Node#remove.
151 replace(nodes: any): this;
152 style(prop: string, defaultType?: string): any;
153 cleanStyles(keepBetween?: boolean): void;