From aa0d53139d9eed9d23f3396bba568a18d9af8417 Mon Sep 17 00:00:00 2001 From: bojiang Date: Fri, 2 Sep 2022 17:11:13 +0800 Subject: [PATCH 1/2] jiangbo91@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 未修改的6.0.1源码 Signed-off-by: bojiang --- README.OpenSource | 2 +- docs/version-history.md | 10 ++ lerna.json | 2 +- .../parse5-html-rewriting-stream/package.json | 6 +- .../lib/index.js | 4 + .../package.json | 4 +- packages/parse5-parser-stream/package.json | 4 +- .../package.json | 6 +- packages/parse5-sax-parser/docs/index.md | 4 +- packages/parse5-sax-parser/package.json | 4 +- .../parse5-serializer-stream/package.json | 4 +- .../docs/source-code-location/end-location.md | 48 +++++++ .../parse5/docs/tree-adapter/interface.md | 21 ++- .../extensions/location-info/parser-mixin.js | 23 ++-- packages/parse5/lib/parser/index.js | 122 ++++-------------- packages/parse5/lib/tree-adapters/default.js | 4 + packages/parse5/package.json | 2 +- .../parse5/test/location-info-parser.test.js | 55 +++++++- 18 files changed, 194 insertions(+), 131 deletions(-) create mode 100644 packages/parse5/docs/source-code-location/end-location.md diff --git a/README.OpenSource b/README.OpenSource index 7c930ff..dd3ed57 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -3,7 +3,7 @@ "Name": "parse5", "License": "MIT", "License File": "NOTICE", - "Version Number": " 5.1.1", + "Version Number": " 6.0.1", "Owner": "sunbingxin@huawei.com", "Upstream URL": "https://github.com/inikulin/parse5.git", "Description": "HTML parser and serializer." diff --git a/docs/version-history.md b/docs/version-history.md index 8d60a00..43ddae4 100644 --- a/docs/version-history.md +++ b/docs/version-history.md @@ -1,5 +1,15 @@ # Version history +# 6.0.1 +* Fixed: Handling of self-closing `
` tags (by [@43081j](https://github.com/43081j)). +* Fixed: Broken link in TreeAdapter document (GH [#317](https://github.com/inikulin/parse5/issues/317)) (by [@ursm](https://github.com/ursm)). +* Fixed: SAXParser example (GH [#316](https://github.com/inikulin/parse5/issues/316)) (by [@mvasilkov](https://github.com/mvasilkov)). + +# 6.0.0 +* Added (**breaking**): Tree adapter interface now has `updateNodeSourceCodeLocation` method which +enables usage of custom location info formats (GH [#314](https://github.com/inikulin/parse5/issues/314)) (by [@DMartens](https://github.com/DMartens)). + + # 5.1.1 * Fixed: Serialization of attributes in non-standard namespaces (by [@Zirro](https://github.com/Zirro)). * Fixed: Quirks and limited-quirks mode detection by doctype (by [@squidfunk](https://github.com/squidfunk)). diff --git a/lerna.json b/lerna.json index fa42581..6cf0b0f 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "lerna": "2.10.2", "packages": ["packages/*"], - "version": "5.1.1" + "version": "6.0.1" } diff --git a/packages/parse5-html-rewriting-stream/package.json b/packages/parse5-html-rewriting-stream/package.json index b95de57..e4bf660 100644 --- a/packages/parse5-html-rewriting-stream/package.json +++ b/packages/parse5-html-rewriting-stream/package.json @@ -1,7 +1,7 @@ { "name": "parse5-html-rewriting-stream", "description": "Streaming HTML rewriter.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -17,8 +17,8 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1", - "parse5-sax-parser": "^5.1.1" + "parse5": "^6.0.1", + "parse5-sax-parser": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5-htmlparser2-tree-adapter/lib/index.js b/packages/parse5-htmlparser2-tree-adapter/lib/index.js index 8240473..58464d7 100644 --- a/packages/parse5-htmlparser2-tree-adapter/lib/index.js +++ b/packages/parse5-htmlparser2-tree-adapter/lib/index.js @@ -342,3 +342,7 @@ exports.setNodeSourceCodeLocation = function(node, location) { exports.getNodeSourceCodeLocation = function(node) { return node.sourceCodeLocation; }; + +exports.updateNodeSourceCodeLocation = function(node, endLocation) { + node.sourceCodeLocation = Object.assign(node.sourceCodeLocation, endLocation); +}; diff --git a/packages/parse5-htmlparser2-tree-adapter/package.json b/packages/parse5-htmlparser2-tree-adapter/package.json index 4c71c1b..cb8d818 100644 --- a/packages/parse5-htmlparser2-tree-adapter/package.json +++ b/packages/parse5-htmlparser2-tree-adapter/package.json @@ -1,7 +1,7 @@ { "name": "parse5-htmlparser2-tree-adapter", "description": "htmlparser2 tree adapter for parse5.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -14,7 +14,7 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1" + "parse5": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5-parser-stream/package.json b/packages/parse5-parser-stream/package.json index 284dd04..068e075 100644 --- a/packages/parse5-parser-stream/package.json +++ b/packages/parse5-parser-stream/package.json @@ -1,7 +1,7 @@ { "name": "parse5-parser-stream", "description": "Streaming HTML parser with scripting support.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -14,7 +14,7 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1" + "parse5": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5-plain-text-conversion-stream/package.json b/packages/parse5-plain-text-conversion-stream/package.json index 7db65e7..974a0d1 100644 --- a/packages/parse5-plain-text-conversion-stream/package.json +++ b/packages/parse5-plain-text-conversion-stream/package.json @@ -1,7 +1,7 @@ { "name": "parse5-plain-text-conversion-stream", "description": "Stream that converts plain text files into HTML document.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -17,8 +17,8 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1", - "parse5-parser-stream": "^5.1.1" + "parse5": "^6.0.1", + "parse5-parser-stream": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5-sax-parser/docs/index.md b/packages/parse5-sax-parser/docs/index.md index a89b295..a089a95 100644 --- a/packages/parse5-sax-parser/docs/index.md +++ b/packages/parse5-sax-parser/docs/index.md @@ -87,8 +87,8 @@ const fs = require('fs'); const file = fs.createWriteStream('google.com.html'); const parser = new SAXParser(); -parser.on('doctype', (name, publicId, systemId) => { - // Process doctype info ans stop parsing +parser.on('doctype', ({ name, publicId, systemId }) => { + // Process doctype info and stop parsing ... parser.stop(); }); diff --git a/packages/parse5-sax-parser/package.json b/packages/parse5-sax-parser/package.json index f8873fa..0924152 100644 --- a/packages/parse5-sax-parser/package.json +++ b/packages/parse5-sax-parser/package.json @@ -1,7 +1,7 @@ { "name": "parse5-sax-parser", "description": "Streaming SAX-style HTML parser.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -15,7 +15,7 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1" + "parse5": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5-serializer-stream/package.json b/packages/parse5-serializer-stream/package.json index 00a6715..2c2948a 100644 --- a/packages/parse5-serializer-stream/package.json +++ b/packages/parse5-serializer-stream/package.json @@ -1,7 +1,7 @@ { "name": "parse5-serializer-stream", "description": "Streaming HTML serializer.", - "version": "5.1.1", + "version": "6.0.1", "author": "Ivan Nikulin (https://github.com/inikulin)", "contributors": "https://github.com/inikulin/parse5/graphs/contributors", "homepage": "https://github.com/inikulin/parse5", @@ -16,7 +16,7 @@ "license": "MIT", "main": "./lib/index.js", "dependencies": { - "parse5": "^5.1.1" + "parse5": "^6.0.1" }, "repository": { "type": "git", diff --git a/packages/parse5/docs/source-code-location/end-location.md b/packages/parse5/docs/source-code-location/end-location.md new file mode 100644 index 0000000..8b3bd57 --- /dev/null +++ b/packages/parse5/docs/source-code-location/end-location.md @@ -0,0 +1,48 @@ +# Interface: EndLocation + +### Properties + +* [endCol](#endcol) +* [endOffset](#endoffset) +* [endLine](#endline) +* [endTag](#endtag) + +--- + +## Properties + + + +### endCol + +**● endCol**: *`number`* + +One-based column index of the last character + +___ + + +### endOffset + +**● endOffset**: *`number`* + +Zero-based last character index + +___ + + +### endLine + +**● endLine**: *`number`* + +One-based line index of the last character + +___ + + +### endTag + +**● endTag**: *[Location](location.md)|undefined* + +Element's end tag location info. +This property is undefined, if the element has no closing tag. \ No newline at end of file diff --git a/packages/parse5/docs/tree-adapter/interface.md b/packages/parse5/docs/tree-adapter/interface.md index ac1e565..238fb19 100644 --- a/packages/parse5/docs/tree-adapter/interface.md +++ b/packages/parse5/docs/tree-adapter/interface.md @@ -2,7 +2,7 @@ Tree adapter is a set of utility functions that provides minimal required abstraction layer beetween parser and a specific AST format. Note that `TreeAdapter` is not designed to be a general purpose AST manipulation library. You can build such library on top of existing `TreeAdapter` or use one of the existing libraries from npm. -*__See__*: [default implementation](https://github.com/inikulin/parse5/blob/master/lib/tree_adapters/default.js) +*__See__*: [default implementation](https://github.com/inikulin/parse5/blob/master/packages/parse5/lib/tree-adapters/default.js) ### Methods @@ -38,7 +38,7 @@ Tree adapter is a set of utility functions that provides minimal required abstra * [setDocumentType](#setdocumenttype) * [setNodeSourceCodeLocation](#setnodesourcecodelocation) * [setTemplateContent](#settemplatecontent) - +* [updateNodeSourceCodeLocation](#updatenodesourcecodelocation) --- ## Methods @@ -588,6 +588,21 @@ Sets the `