isml-linter 5.42.1 → 5.42.2

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.42.2] - 2023-01-29
4
+
5
+ ### Fixed
6
+ - HTML conditional comment children indentation;
7
+
3
8
  ## [5.42.1] - 2023-01-28
4
9
 
5
10
  ### Fixed
@@ -1064,6 +1069,7 @@
1064
1069
  ### Added
1065
1070
  - Linter is published;
1066
1071
 
1072
+ [5.42.2]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.1...v5.42.2
1067
1073
  [5.42.1]: https://github.com/FabiowQuixada/isml-linter/compare/v5.42.0...v5.42.1
1068
1074
  [5.42.0]: https://github.com/FabiowQuixada/isml-linter/compare/v5.41.0...v5.42.0
1069
1075
  [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.2",
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';
@@ -128,8 +128,9 @@ const parseNextElement = state => {
128
128
  parseTextElement(state, newElement);
129
129
  }
130
130
 
131
- newElement.columnNumber = getElementColumnNumber(newElement, state);
132
- newElement.isVoidElement = !config.disableHtml5 && Constants.voidElementsArray.indexOf(newElement.tagType) >= 0;
131
+ newElement.columnNumber = getElementColumnNumber(newElement, state);
132
+ newElement.isVoidElement = !config.disableHtml5 && Constants.voidElementsArray.indexOf(newElement.tagType) >= 0;
133
+ newElement.isHtmlConditionalComment = !!(newElement.type === 'htmlOrIsmlComment' && (newElement.value.indexOf('<!--[if') >= 0 || newElement.value.indexOf('<!--<![endif]' >= 0)));
133
134
 
134
135
  if (state.isCrlfLineBreak) {
135
136
  newElement.globalPos += newElement.lineNumber - 1;
@@ -158,10 +159,11 @@ const parseNextElement = state => {
158
159
  };
159
160
 
160
161
  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('<!--');
162
+ const trimmedElement = newElement.value.trim().toLowerCase();
163
+ const isTag = trimmedElement.startsWith('<') && !trimmedElement.startsWith('<!--');
164
+ const isExpression = trimmedElement.startsWith('${');
165
+ const isHtmlOrIsmlComment = trimmedElement.startsWith('<!--');
166
+ const isConditionalComment = trimmedElement.indexOf('<!--[if') >= 0 || trimmedElement.indexOf('<![endif') >= 0;
165
167
 
166
168
  if (isTag) {
167
169
  if (trimmedElement.startsWith('<is') || trimmedElement.startsWith('</is')) {
@@ -171,6 +173,8 @@ const parseTagOrExpressionElement = (state, newElement) => {
171
173
  } else {
172
174
  newElement.type = 'htmlTag';
173
175
  }
176
+ } else if (isConditionalComment) {
177
+ newElement.type = 'htmlConditionalComment';
174
178
  } else if (isHtmlOrIsmlComment) {
175
179
  newElement.type = 'htmlOrIsmlComment';
176
180
  } else if (isExpression) {
@@ -180,16 +184,24 @@ const parseTagOrExpressionElement = (state, newElement) => {
180
184
  }
181
185
 
182
186
  if (isTag) {
183
- newElement.tagType = getElementType(trimmedElement);
184
-
187
+ newElement.tagType = getElementType(trimmedElement);
185
188
  newElement.isCustomTag = newElement.type === 'ismlTag' && !SfccTagContainer[newElement.tagType];
186
189
  }
187
190
 
188
191
  newElement.isSelfClosing = isSelfClosing(trimmedElement);
192
+ newElement.isClosingTag = isTag && trimmedElement.startsWith('</');
193
+ newElement.lineNumber = getLineBreakQty(state.pastContent) + getLeadingLineBreakQty(newElement.value) + 1;
194
+ newElement.globalPos = state.pastContent.length + getLeadingEmptyChars(newElement.value).length;
195
+
196
+ // TODO Refactor this, remove this post-processing;
197
+ if (newElement.type === 'htmlConditionalComment') {
198
+ newElement.tagType = 'html_conditional_comment';
199
+ newElement.isSelfClosing = false;
189
200
 
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;
201
+ if (trimmedElement.indexOf('<!--<![endif]') >= 0) {
202
+ newElement.isClosingTag = true;
203
+ }
204
+ }
193
205
  };
194
206
 
195
207
  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;