node.d.ts 6.0 KB

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