isml-linter 5.42.1 → 5.42.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.42.3] - 2023-01-29
4
+
5
+ ### Fixed
6
+ - Tree build fix when self-closing HTML conditional comments are present;
7
+
8
+ ## [5.42.2] - 2023-01-29
9
+
10
+ ### Fixed
11
+ - HTML conditional comment children indentation;
12
+
3
13
  ## [5.42.1] - 2023-01-28
4
14
 
5
15
  ### Fixed
@@ -1064,6 +1074,8 @@
1064
1074
  ### Added
1065
1075
  - Linter is published;
1066
1076
 
1077
+ [5.42.3]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.2...v5.42.3
1078
+ [5.42.2]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.1...v5.42.2
1067
1079
  [5.42.1]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.0...v5.42.1
1068
1080
  [5.42.0]: https://github.com/FabiowQuixada/isml-linter/compare/v5.41.0...v5.42.0
1069
1081
  [5.41.0]: https://github.com/FabiowQuixada/isml-linter/compare/v5.40.5...v5.41.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isml-linter",
3
- "version": "5.42.1",
3
+ "version": "5.42.3",
4
4
  "author": "Fabiow Quixadá <ftquixada@gmail.com>",
5
5
  "license": "MIT",
6
6
  "main": "src/publicApi.js",
@@ -54,7 +54,9 @@ class IsmlNode {
54
54
 
55
55
  const head = this.head.trim();
56
56
 
57
- if (head.startsWith('<!--')) {
57
+ if (head.startsWith('<!--[if')) {
58
+ return 'html_conditional_comment';
59
+ } else if (head.startsWith('<!--')) {
58
60
  return 'html_comment';
59
61
  } else if (this.isDocType()) {
60
62
  return 'doctype';
@@ -402,6 +404,11 @@ class IsmlNode {
402
404
  indentation += ' ';
403
405
  }
404
406
 
407
+ // if(this.isRoot()) {
408
+ // console.log('Depth\t :: LineNumber\t :: Content');
409
+ // }
410
+
411
+ // console.log(this.depth + '\t :: ' + this.lineNumber + '\t\t :: ' + indentation + getDisplayText(this));
405
412
  console.log(this.depth + ' :: ' + this.lineNumber + ' :: ' + indentation + getDisplayText(this));
406
413
 
407
414
  for (let i = 0; i < this.children.length; i++) {
@@ -158,10 +158,11 @@ const parseNextElement = state => {
158
158
  };
159
159
 
160
160
  const parseTagOrExpressionElement = (state, newElement) => {
161
- const trimmedElement = newElement.value.trim().toLowerCase();
162
- const isTag = trimmedElement.startsWith('<') && !trimmedElement.startsWith('<!--');
163
- const isExpression = trimmedElement.startsWith('${');
164
- const isHtmlOrIsmlComment = trimmedElement.startsWith('<!--');
161
+ const trimmedElement = newElement.value.trim().toLowerCase();
162
+ const isTag = trimmedElement.startsWith('<') && !trimmedElement.startsWith('<!--');
163
+ const isExpression = trimmedElement.startsWith('${');
164
+ const isHtmlOrIsmlComment = trimmedElement.startsWith('<!--');
165
+ const isConditionalComment = trimmedElement.indexOf('<!--[if') >= 0 || trimmedElement.indexOf('<![endif') >= 0;
165
166
 
166
167
  if (isTag) {
167
168
  if (trimmedElement.startsWith('<is') || trimmedElement.startsWith('</is')) {
@@ -171,6 +172,8 @@ const parseTagOrExpressionElement = (state, newElement) => {
171
172
  } else {
172
173
  newElement.type = 'htmlTag';
173
174
  }
175
+ } else if (isConditionalComment) {
176
+ newElement.type = 'htmlConditionalComment';
174
177
  } else if (isHtmlOrIsmlComment) {
175
178
  newElement.type = 'htmlOrIsmlComment';
176
179
  } else if (isExpression) {
@@ -180,16 +183,24 @@ const parseTagOrExpressionElement = (state, newElement) => {
180
183
  }
181
184
 
182
185
  if (isTag) {
183
- newElement.tagType = getElementType(trimmedElement);
184
-
186
+ newElement.tagType = getElementType(trimmedElement);
185
187
  newElement.isCustomTag = newElement.type === 'ismlTag' && !SfccTagContainer[newElement.tagType];
186
188
  }
187
189
 
188
190
  newElement.isSelfClosing = isSelfClosing(trimmedElement);
191
+ newElement.isClosingTag = isTag && trimmedElement.startsWith('</');
192
+ newElement.lineNumber = getLineBreakQty(state.pastContent) + getLeadingLineBreakQty(newElement.value) + 1;
193
+ newElement.globalPos = state.pastContent.length + getLeadingEmptyChars(newElement.value).length;
194
+
195
+ // TODO Refactor this, remove this post-processing;
196
+ if (newElement.type === 'htmlConditionalComment') {
197
+ newElement.tagType = 'html_conditional_comment';
198
+ newElement.isSelfClosing = newElement.value.indexOf('<!--[if') >= 0 && newElement.value.indexOf('<![endif') >= 0;
189
199
 
190
- newElement.isClosingTag = isTag && trimmedElement.startsWith('</');
191
- newElement.lineNumber = getLineBreakQty(state.pastContent) + getLeadingLineBreakQty(newElement.value) + 1;
192
- newElement.globalPos = state.pastContent.length + getLeadingEmptyChars(newElement.value).length;
200
+ if (trimmedElement.indexOf('<!--<![endif]') >= 0) {
201
+ newElement.isClosingTag = true;
202
+ }
203
+ }
193
204
  };
194
205
 
195
206
  const parseTextElement = (state, newElement) => {
@@ -613,7 +613,7 @@ const addIndentation = (node, isOpeningTag) => {
613
613
  const fullLeadingContent = content.substring(0, startingPos);
614
614
  const preLineBreakContent = fullLeadingContent.substring(0, fullLeadingContent.lastIndexOf(Constants.EOL) + 1);
615
615
  const fullTrailingContent = content.substring(endingPos);
616
- const nodeIndentation = node.isInSameLineAsParent() && isOpeningTag ? '' : Rule.getIndentation(node.depth - 1);
616
+ let nodeIndentation = node.isInSameLineAsParent() && isOpeningTag ? '' : Rule.getIndentation(node.depth - 1);
617
617
  const attributeOffset = Rule.getAttributeIndentationOffset();
618
618
  const attributeList = node.getAttributeList();
619
619
  let contentResult = '';
@@ -642,7 +642,20 @@ const addIndentation = (node, isOpeningTag) => {
642
642
  contentResult = node.head.trim();
643
643
  }
644
644
  } else {
645
- contentResult = node.tail.trim();
645
+ const nodeLastChild = node.getLastChild();
646
+
647
+ if (nodeLastChild) {
648
+ const lastChildLineNumber = nodeLastChild.isContainer() ?
649
+ nodeLastChild.getLastChild().getLastLineNumber() :
650
+ nodeLastChild.getLastLineNumber();
651
+
652
+ if (node.tailLineNumber === lastChildLineNumber) {
653
+ contentResult = Constants.EOL + nodeIndentation;
654
+ nodeIndentation = '';
655
+ }
656
+ }
657
+
658
+ contentResult += node.tail.trim();
646
659
  }
647
660
 
648
661
  return preLineBreakContent + nodeIndentation + contentResult + fullTrailingContent;