@html-eslint/parser
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -35,3 +35,3 @@ /** | ||
while(this.convertedStack.top() === null) { | ||
while (this.convertedStack.top() === null) { | ||
this.convertedStack.pop(); | ||
@@ -38,0 +38,0 @@ } |
const utils = require("./utils"); | ||
function toBaseNode(node) { | ||
const { | ||
childNodes, | ||
parentNode, // eslint-disable-line no-unused-vars | ||
nodeName, | ||
attrs, | ||
sourceCodeLocation, | ||
...extra | ||
} = node; | ||
const type = utils.toType(nodeName); | ||
return { | ||
type, | ||
...extra, | ||
...utils.toESLocation(sourceCodeLocation, childNodes), | ||
// start tag | ||
startTag: | ||
sourceCodeLocation && sourceCodeLocation.startTag | ||
? { | ||
...utils.toESLocation(sourceCodeLocation.startTag), | ||
} | ||
: null, | ||
// end tag | ||
endTag: | ||
sourceCodeLocation && sourceCodeLocation.endTag | ||
? { | ||
...utils.toESLocation(sourceCodeLocation.endTag), | ||
} | ||
: null, | ||
// attributes | ||
attrs: attrs | ||
? attrs.map((attr) => ({ | ||
...attr, | ||
...(sourceCodeLocation && sourceCodeLocation.attrs | ||
? utils.getAttrLocation(sourceCodeLocation, attr.name) | ||
: null), | ||
})) | ||
: [], | ||
}; | ||
} | ||
function extendsToProgramNode(node) { | ||
return Object.assign(node, { | ||
body: [], | ||
tokens: [], | ||
comments: [], | ||
}); | ||
} | ||
function extendsToTextNode(node) { | ||
return Object.assign(node, { | ||
lineNodes: utils.getLineNodes(node, node.value), | ||
}); | ||
} | ||
function extendsToCommentNode(node) { | ||
return Object.assign(node, utils.getCommentTags(node), { | ||
lineNodes: utils.getLineNodes( | ||
{ | ||
...node, | ||
range: [node.range[0] + 4], | ||
start: node.range[0] + 4, | ||
}, | ||
node.data | ||
), | ||
}); | ||
} | ||
const NodeConverter = { | ||
@@ -8,45 +75,13 @@ toNode(node) { | ||
} | ||
const {childNodes, | ||
parentNode, // eslint-disable-line no-unused-vars | ||
nodeName, | ||
attrs, | ||
sourceCodeLocation, | ||
...extra | ||
} = node; | ||
const type = utils.toType(nodeName); | ||
return { | ||
type, | ||
...extra, | ||
...utils.toESLocation(sourceCodeLocation, childNodes), | ||
// start tag | ||
startTag: | ||
sourceCodeLocation && sourceCodeLocation.startTag | ||
? { | ||
...utils.toESLocation(sourceCodeLocation.startTag), | ||
} | ||
: null, | ||
// end tag | ||
endTag: | ||
sourceCodeLocation && sourceCodeLocation.endTag | ||
? { | ||
...utils.toESLocation(sourceCodeLocation.endTag), | ||
} | ||
: null, | ||
// attributes | ||
attrs: attrs | ||
? attrs.map((attr) => ({ | ||
...attr, | ||
...(sourceCodeLocation && sourceCodeLocation.attrs | ||
? utils.getAttrLocation(sourceCodeLocation, attr.name) | ||
: null), | ||
})) | ||
: [], | ||
...(type === "Program" | ||
? { | ||
body: [], | ||
tokens: [], | ||
comments: [], | ||
} | ||
: {}), | ||
}; | ||
let base = toBaseNode(node); | ||
switch (base.type) { | ||
case "Program": | ||
return extendsToProgramNode(base); | ||
case "comment": | ||
return extendsToCommentNode(base); | ||
case "text": | ||
return extendsToTextNode(base); | ||
default: | ||
return base; | ||
} | ||
}, | ||
@@ -53,0 +88,0 @@ }; |
@@ -79,3 +79,67 @@ function getLocFromChildNodes(childNodes) { | ||
return !node || (node.nodeName !== "#document" && !node.sourceCodeLocation); | ||
} | ||
}, | ||
getCommentTags(node) { | ||
return { | ||
startTag: { | ||
range: [node.range[0], node.range[0] + 4], | ||
start: node.start, | ||
end: node.start + 4, | ||
loc: { | ||
start: { | ||
line: node.loc.start.line, | ||
column: node.loc.start.column, | ||
}, | ||
end: { | ||
line: node.loc.start.line, | ||
column: node.loc.start.column + 5, | ||
}, | ||
}, | ||
}, | ||
endTag: { | ||
range: [node.range[1] - 3, node.range[1]], | ||
start: node.start, | ||
end: node.start + 4, | ||
loc: { | ||
start: { | ||
line: node.loc.end.line, | ||
column: node.loc.end.column - 3, | ||
}, | ||
end: { | ||
line: node.loc.end.line, | ||
column: node.loc.end.column, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}, | ||
getLineNodes(node, text) { | ||
let [rangeStart] = node.range; | ||
let startOffset = node.start; | ||
let { line } = node.loc.start; | ||
return text.split("\n").map((textLine) => { | ||
const indentLength = (textLine.match(/[^\S\n\r]/g) || []).length; | ||
rangeStart += indentLength; | ||
startOffset += indentLength; | ||
const lineNode = { | ||
range: [rangeStart, rangeStart + textLine.trimStart().length], | ||
start: startOffset, | ||
end: rangeStart + textLine.length, | ||
loc: { | ||
start: { | ||
line, | ||
column: indentLength + 1, | ||
}, | ||
end: { | ||
line, | ||
column: textLine.length + 1, | ||
}, | ||
}, | ||
textLine, | ||
}; | ||
rangeStart += textLine.trimStart().length + 1; | ||
startOffset += textLine.trimStart().length + 1; | ||
line += 1; | ||
return lineNode; | ||
}); | ||
}, | ||
}; |
{ | ||
"name": "@html-eslint/parser", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Parser for @html-eslint/eslint-plugin", | ||
@@ -32,3 +32,3 @@ "author": "yeonjuan", | ||
}, | ||
"gitHead": "229d0fa2f80eb6f34da26fe45768beea16bec53f" | ||
"gitHead": "eef02fe80c18eead290d77b41b38b4281a2599ef" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12293
422