From 56d7fea028855adb74c451c435e55580cd0f1679 Mon Sep 17 00:00:00 2001 From: Ryo Matsukawa <76232929+ryo-manba@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:14:09 +0900 Subject: [PATCH 1/4] chore: fix comments (#296) --- postcss-selector-parser.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postcss-selector-parser.d.ts b/postcss-selector-parser.d.ts index af609e6..eaf1090 100644 --- a/postcss-selector-parser.d.ts +++ b/postcss-selector-parser.d.ts @@ -86,12 +86,12 @@ declare namespace parser { interface Options { /** - * Preserve whitespace when true. Default: false; + * Preserve whitespace when true. Default: true; */ lossless: boolean; /** * When true and a postcss.Rule is passed, set the result of - * processing back onto the rule when done. Default: false. + * processing back onto the rule when done. Default: true. */ updateSelector: boolean; } From e254e601a51aea9df80e9302b314ff7181ece132 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 5 Feb 2025 05:18:51 +0800 Subject: [PATCH 2/4] docs: update `replaceWith` arguments (#300) --- API.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index c8e55ee..2afef72 100644 --- a/API.md +++ b/API.md @@ -254,7 +254,7 @@ if (next && next.type !== 'combinator') { } ``` -### `node.replaceWith(node)` +### `node.replaceWith(node[,...nodeN])` Replace a node with another. @@ -267,6 +267,8 @@ attr.replaceWith(className); Arguments: * `node`: The node to substitute the original with. +... +* `nodeN`: The node to substitute the original with. ### `node.remove()` From 3f5ecb647910d2d1408f6dd0ec45dedf695ab556 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 7 Feb 2025 01:20:00 +0800 Subject: [PATCH 3/4] feat: insert(Before|After) support multiple new node (#302) --- API.md | 2 +- postcss-selector-parser.d.ts | 4 ++-- src/__tests__/container.mjs | 20 ++++++++++++++++++++ src/selectors/container.js | 18 +++++++++++++----- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/API.md b/API.md index 2afef72..e564830 100644 --- a/API.md +++ b/API.md @@ -533,7 +533,7 @@ Arguments: * `node`: The node to add. -### `container.insertBefore(old, new)` & `container.insertAfter(old, new)` +### `container.insertBefore(old, new[, ...newNodes])` & `container.insertAfter(old, new[, ...newNodes])` Add a node before or after an existing node in a container: diff --git a/postcss-selector-parser.d.ts b/postcss-selector-parser.d.ts index eaf1090..4efbc10 100644 --- a/postcss-selector-parser.d.ts +++ b/postcss-selector-parser.d.ts @@ -235,8 +235,8 @@ declare namespace parser { removeChild(child: Child): this; removeAll(): this; empty(): this; - insertAfter(oldNode: Child, newNode: Child): this; - insertBefore(oldNode: Child, newNode: Child): this; + insertAfter(oldNode: Child, newNode: Child, ...restNode: Child[]): this; + insertBefore(oldNode: Child, newNode: Child, ...restNode: Child[]): this; each(callback: (node: Child, index: number) => boolean | void): boolean | undefined; walk( callback: (node: Node, index: number) => boolean | void diff --git a/src/__tests__/container.mjs b/src/__tests__/container.mjs index e852aac..e435ed7 100644 --- a/src/__tests__/container.mjs +++ b/src/__tests__/container.mjs @@ -349,6 +349,16 @@ test('container#insertBefore', (t) => { t.deepEqual(out, 'h1,h2'); }); +test('container#insertBefore (multiple node)', (t) => { + let out = parse('h2', (selectors) => { + let selector = selectors.first; + let clone1 = selector.first.clone({value: 'h1'}); + let clone2 = selector.first.clone({value: 'h0'}); + selectors.insertBefore(selector, clone1, clone2); + }); + t.deepEqual(out, 'h1,h0,h2'); +}); + test('container#insertBefore and node#remove', (t) => { let out = parse('h2', (selectors) => { let selector = selectors.first; @@ -368,6 +378,16 @@ test('container#insertAfter', (t) => { t.deepEqual(out, 'h1,h2'); }); +test('container#insertAfter (multiple node)', (t) => { + let out = parse('h1', (selectors) => { + let selector = selectors.first; + let clone1 = selector.first.clone({value: 'h2'}); + let clone2 = selector.first.clone({value: 'h3'}); + selectors.insertAfter(selector, clone1, clone2); + }); + t.deepEqual(out, 'h1,h2,h3'); +}) + test('container#insertAfter and node#remove', (t) => { let out = parse('h2', (selectors) => { let selector = selectors.first; diff --git a/src/selectors/container.js b/src/selectors/container.js index 2575dde..ee347b4 100644 --- a/src/selectors/container.js +++ b/src/selectors/container.js @@ -78,7 +78,11 @@ export default class Container extends Node { insertAfter (oldNode, newNode) { newNode.parent = this; let oldIndex = this.index(oldNode); - this.nodes.splice(oldIndex + 1, 0, newNode); + const resetNode = []; + for (let i = 2; i < arguments.length; i++) { + resetNode.push(arguments[i]); + } + this.nodes.splice(oldIndex + 1, 0, newNode, ...resetNode); newNode.parent = this; @@ -86,7 +90,7 @@ export default class Container extends Node { for ( let id in this.indexes ) { index = this.indexes[id]; if ( oldIndex < index ) { - this.indexes[id] = index + 1; + this.indexes[id] = index + arguments.length - 1; } } @@ -96,7 +100,11 @@ export default class Container extends Node { insertBefore (oldNode, newNode) { newNode.parent = this; let oldIndex = this.index(oldNode); - this.nodes.splice(oldIndex, 0, newNode); + const resetNode = []; + for (let i = 2; i < arguments.length; i++) { + resetNode.push(arguments[i]); + } + this.nodes.splice(oldIndex, 0, newNode, ...resetNode); newNode.parent = this; @@ -104,7 +112,7 @@ export default class Container extends Node { for ( let id in this.indexes ) { index = this.indexes[id]; if ( index >= oldIndex ) { - this.indexes[id] = index + 1; + this.indexes[id] = index + arguments.length - 1; } } @@ -132,7 +140,7 @@ export default class Container extends Node { * Return the most specific node at the line and column number given. * The source location is based on the original parsed location, locations aren't * updated as selector nodes are mutated. - * + * * Note that this location is relative to the location of the first character * of the selector, and not the location of the selector in the overall document * when used in conjunction with postcss. From ea6cd9324b4be90a4c529c3602deefbc4a2d7a82 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 7 Feb 2025 17:47:03 +0300 Subject: [PATCH 4/4] chore(release): 7.1.0 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c0d1fb..9a8956a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 7.1.0 + +- feat: insert(Before|After) support multiple new node + # 7.0.0 - Feat: make insertions during iteration safe (major) diff --git a/package.json b/package.json index 0483942..f8b1d36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-selector-parser", - "version": "7.0.0", + "version": "7.1.0", "devDependencies": { "@babel/cli": "^7.11.6", "@babel/core": "^7.11.6", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy