From ecae0042c4dd20310233f004cbdc0182208b00be Mon Sep 17 00:00:00 2001 From: TechQuery Date: Mon, 19 Nov 2018 16:27:18 +0800 Subject: [PATCH 1/2] [ Add ] Serialization of CDATASection nodes [ Optimize ] Enable ESLint & Prettier --- lib/constants.js | 2 +- lib/serialization.js | 6 ++++++ package.json | 7 ++++--- test/.eslintrc | 7 ++++++- test/wpt/XMLSerializer-serializeToString.test.js | 9 +++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 4c9dfd2..a04bfd8 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -8,7 +8,7 @@ module.exports.NODE_TYPES = { ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, // historical TEXT_NODE: 3, - CDATA_SECTION_NODE: 4, // historical + CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, // historical ENTITY_NODE: 6, // historical PROCESSING_INSTRUCTION_NODE: 7, diff --git a/lib/serialization.js b/lib/serialization.js index df3d120..43cea6d 100644 --- a/lib/serialization.js +++ b/lib/serialization.js @@ -299,6 +299,10 @@ function serializeElement(node, namespace, prefixMap, requireWellFormed, refs) { return markup; } +function serializeCDATASection(node) { + return ""; +} + /** * @param {{prefixIndex: number}} refs */ @@ -348,6 +352,8 @@ function xmlSerialization(node, namespace, prefixMap, requireWellFormed, refs) { ); case NODE_TYPES.ATTRIBUTE_NODE: return ""; + case NODE_TYPES.CDATA_SECTION_NODE: + return serializeCDATASection(node); default: throw new TypeError("Only Nodes and Attr objects can be serialized"); } diff --git a/package.json b/package.json index f833dd5..e965bd4 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "eslint": "^4.19.1", "jest": "^23.1.0", "jsdom": "^11.11.0", - "prettier": "^1.13.4", + "prettier": "^1.15.2", "webidl2js": "^9.0.0" }, "repository": { @@ -19,8 +19,9 @@ "url": "https://github.com/jsdom/w3c-xmlserializer.git" }, "scripts": { - "build": "node scripts/convert-idl.js", - "prepublish": "node scripts/convert-idl.js", + "format": "prettier --write \"{,!(node_modules|.git|src)/**/}*.{html,md,js,json,css,less}\"", + "build": "npm run format && node scripts/convert-idl.js", + "prepublish": "npm run build", "test": "jest" } } diff --git a/test/.eslintrc b/test/.eslintrc index 55f121d..623794b 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,5 +1,10 @@ { "env": { + "es6": true, "jest": true - } + }, + "parserOptions": { + "ecmaVersion": 8 + }, + "extends": "eslint:recommended" } diff --git a/test/wpt/XMLSerializer-serializeToString.test.js b/test/wpt/XMLSerializer-serializeToString.test.js index 76eadd9..7309cc8 100644 --- a/test/wpt/XMLSerializer-serializeToString.test.js +++ b/test/wpt/XMLSerializer-serializeToString.test.js @@ -64,4 +64,13 @@ describe("WPT", () => { serializer.serializeToString(root) ); }); + + test("check CDATASection nodes are serialized correctly", () => { + const markup = + ""; + + const document = new DOMParser().parseFromString(markup, "application/xml"); + + expect(new XMLSerializer().serializeToString(document)).toEqual(markup); + }); }); From 00bc681b9c122cc716d144c1f1c175afcc02380a Mon Sep 17 00:00:00 2001 From: TechQuery Date: Thu, 13 Dec 2018 02:57:58 +0800 Subject: [PATCH 2/2] [ Remove ] Prettier & ESLint changes --- package.json | 7 +++---- test/.eslintrc | 7 +------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 64c2427..0b54a73 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "eslint": "^4.19.1", "jest": "^23.1.0", "jsdom": "^11.11.0", - "prettier": "^1.15.2", + "prettier": "^1.13.4", "webidl2js": "^9.0.0" }, "repository": { @@ -19,9 +19,8 @@ "url": "https://github.com/jsdom/w3c-xmlserializer.git" }, "scripts": { - "format": "prettier --write \"{,!(node_modules|.git|src)/**/}*.{html,md,js,json,css,less}\"", - "build": "npm run format && node scripts/convert-idl.js", - "prepublish": "npm run build", + "build": "node scripts/convert-idl.js", + "prepublish": "node scripts/convert-idl.js", "test": "jest" } } diff --git a/test/.eslintrc b/test/.eslintrc index 623794b..55f121d 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,10 +1,5 @@ { "env": { - "es6": true, "jest": true - }, - "parserOptions": { - "ecmaVersion": 8 - }, - "extends": "eslint:recommended" + } }