From e36bd98723d97eb9fd123527bd94ce50879c1526 Mon Sep 17 00:00:00 2001 From: DMartens Date: Thu, 16 Apr 2020 00:33:30 +0200 Subject: [PATCH] Add updateNodeSourceCodeLocation to the tree adapter (#315) * Add updateNodeSourceCodeLocation to the tree adapter * Add updateNodeSourceCodeLocation to the tree adapter documentation * Renamed updateNodeSourceCodeLocation parameter location to endLocation * Use updateNodeSourceCodeLocation to update the end location of tokens * Update tree adapter updateNodeSourceCodeLocation documentation to reflect updating the source code location of nodes not just elements * Add test for updating node source code location --- .../lib/index.js | 4 ++ .../docs/source-code-location/end-location.md | 48 ++++++++++++++++ .../parse5/docs/tree-adapter/interface.md | 19 ++++++- .../extensions/location-info/parser-mixin.js | 23 ++++---- packages/parse5/lib/tree-adapters/default.js | 4 ++ .../parse5/test/location-info-parser.test.js | 55 ++++++++++++++++++- 6 files changed, 139 insertions(+), 14 deletions(-) create mode 100644 packages/parse5/docs/source-code-location/end-location.md diff --git a/packages/parse5-htmlparser2-tree-adapter/lib/index.js b/packages/parse5-htmlparser2-tree-adapter/lib/index.js index 824047383..58464d78a 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/docs/source-code-location/end-location.md b/packages/parse5/docs/source-code-location/end-location.md new file mode 100644 index 000000000..8b3bd57db --- /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 ac1e56542..f7ef11c47 100644 --- a/packages/parse5/docs/tree-adapter/interface.md +++ b/packages/parse5/docs/tree-adapter/interface.md @@ -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 `