This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from WordPress/create-tree-walker
🎨 Switch toVdom from array iteration to createTreeWalker
- Loading branch information
Showing
8 changed files
with
174 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>toVdom</title> | ||
</head> | ||
|
||
<body data-wp-island> | ||
<div data-testid="it should delete comments"> | ||
<!-- ##1## --> | ||
<div data-testid="it should keep this node between comments"> | ||
Comments inner node | ||
<!-- ##2## --> | ||
</div> | ||
</div> | ||
|
||
<div data-testid="it should delete processing instructions"> | ||
<div id="replace-with-processing-instructions"></div> | ||
</div> | ||
|
||
<script> | ||
const processingInstructions = ` | ||
<div> | ||
<?xpacket ##1## ?> | ||
<div data-testid="it should keep this node between processing instructions"> | ||
Processing instructions inner node | ||
<?xpacket ##2## ?> | ||
</div> | ||
</div> | ||
`; | ||
|
||
const processingInstructionsElement = new DOMParser() | ||
.parseFromString(processingInstructions, 'text/xml') | ||
.querySelector('div'); | ||
document | ||
.getElementById('replace-with-processing-instructions') | ||
.replaceWith(processingInstructionsElement); | ||
</script> | ||
|
||
<div data-testid="it should replace CDATA with text nodes"> | ||
<div id="replace-with-cdata"></div> | ||
</div> | ||
|
||
<script> | ||
const cdata = ` | ||
<div> | ||
<![CDATA[##1##]]> | ||
<div data-testid="it should keep this node between CDATA"> | ||
<![CDATA[##2##]]> | ||
</div> | ||
</div> | ||
`; | ||
|
||
const cdataElement = new DOMParser() | ||
.parseFromString(cdata, 'text/xml') | ||
.querySelector('div'); | ||
document | ||
.getElementById('replace-with-cdata') | ||
.replaceWith(cdataElement); | ||
</script> | ||
|
||
<script src="../../build/runtime.js"></script> | ||
<script src="../../build/vendors.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test, expect } from '../tests'; | ||
|
||
test.describe('toVdom', () => { | ||
test.beforeEach(async ({ goToFile }) => { | ||
await goToFile('tovdom.html'); | ||
}); | ||
|
||
test('it should delete comments', async ({ page }) => { | ||
const el = page.getByTestId('it should delete comments'); | ||
const c = await el.innerHTML(); | ||
expect(c).not.toContain('##1##'); | ||
expect(c).not.toContain('##2##'); | ||
const el2 = page.getByTestId( | ||
'it should keep this node between comments' | ||
); | ||
await expect(el2).toBeVisible(); | ||
}); | ||
|
||
test('it should delete processing instructions', async ({ page }) => { | ||
const el = page.getByTestId('it should delete processing instructions'); | ||
const c = await el.innerHTML(); | ||
expect(c).not.toContain('##1##'); | ||
expect(c).not.toContain('##2##'); | ||
const el2 = page.getByTestId( | ||
'it should keep this node between processing instructions' | ||
); | ||
await expect(el2).toBeVisible(); | ||
}); | ||
|
||
test('it should replace CDATA with text nodes', async ({ page }) => { | ||
const el = page.getByTestId('it should replace CDATA with text nodes'); | ||
const c = await el.innerHTML(); | ||
expect(c).toContain('##1##'); | ||
expect(c).toContain('##2##'); | ||
const el2 = page.getByTestId('it should keep this node between CDATA'); | ||
await expect(el2).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters