Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/lit-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"chalk": "^2.4.2",
"didyoumean2": "4.1.0",
"fast-glob": "^2.2.6",
"parse5": "5.1.0",
"parse5": "^6.0.1",
"ts-simple-type": "~1.0.5",
"vscode-css-languageservice": "4.3.0",
"vscode-html-languageservice": "3.1.0",
Expand All @@ -55,6 +55,7 @@
"@rollup/plugin-node-resolve": "^8.1.0",
"@rollup/plugin-replace": "^2.3.3",
"@types/node": "^14.0.13",
"@types/parse5": "^6.0.0",
"@wessberg/rollup-plugin-ts": "^1.2.25",
"ava": "^3.8.2",
"cross-env": "^7.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Attribute, Element } from "parse5";
import { HtmlNodeAttrAssignment, HtmlNodeAttrAssignmentKind } from "../../../../../types/html-node/html-node-attr-assignment-types";
import { HtmlNodeAttr } from "../../../../../types/html-node/html-node-attr-types";
import { Range } from "../../../../../types/range";
import { getSourceLocation, IP5NodeAttr, IP5TagNode } from "../parse-html-p5/parse-html-types";
import { ParseHtmlContext } from "./parse-html-context";

/**
Expand All @@ -12,8 +12,8 @@ import { ParseHtmlContext } from "./parse-html-context";
* @param context
*/
export function parseHtmlAttrAssignment(
p5Node: IP5TagNode,
p5Attr: IP5NodeAttr,
p5Node: Element,
p5Attr: Attribute,
htmlAttr: HtmlNodeAttr,
context: ParseHtmlContext
): HtmlNodeAttrAssignment | undefined {
Expand Down Expand Up @@ -54,8 +54,8 @@ export function parseHtmlAttrAssignment(
}
}

function getAssignmentLocation(p5Node: IP5TagNode, p5Attr: IP5NodeAttr, htmlAttr: HtmlNodeAttr, context: ParseHtmlContext): Range | undefined {
const sourceLocation = getSourceLocation(p5Node);
function getAssignmentLocation(p5Node: Element, p5Attr: Attribute, htmlAttr: HtmlNodeAttr, context: ParseHtmlContext): Range | undefined {
const sourceLocation = p5Node.sourceCodeLocation;
if (sourceLocation == null) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Attribute, Element } from "parse5";
import {
LIT_HTML_BOOLEAN_ATTRIBUTE_MODIFIER,
LIT_HTML_EVENT_LISTENER_ATTRIBUTE_MODIFIER,
Expand All @@ -10,7 +11,6 @@ import {
IHtmlNodeAttrSourceCodeLocation
} from "../../../../../types/html-node/html-node-attr-types";
import { parseLitAttrName } from "../../../../../util/general-util";
import { getSourceLocation, IP5NodeAttr, IP5TagNode } from "../parse-html-p5/parse-html-types";
import { parseHtmlAttrAssignment } from "./parse-html-attr-assignment";
import { ParseHtmlAttrContext } from "./parse-html-attr-context";

Expand All @@ -19,7 +19,7 @@ import { ParseHtmlAttrContext } from "./parse-html-attr-context";
* @param p5Node
* @param context
*/
export function parseHtmlNodeAttrs(p5Node: IP5TagNode, context: ParseHtmlAttrContext): HtmlNodeAttr[] {
export function parseHtmlNodeAttrs(p5Node: Element, context: ParseHtmlAttrContext): HtmlNodeAttr[] {
return p5Node.attrs
.map(htmlAttr =>
parseHtmlNodeAttr(p5Node, htmlAttr, {
Expand All @@ -36,7 +36,7 @@ export function parseHtmlNodeAttrs(p5Node: IP5TagNode, context: ParseHtmlAttrCon
* @param p5Attr
* @param context
*/
export function parseHtmlNodeAttr(p5Node: IP5TagNode, p5Attr: IP5NodeAttr, context: ParseHtmlAttrContext): HtmlNodeAttr | undefined {
export function parseHtmlNodeAttr(p5Node: Element, p5Attr: Attribute, context: ParseHtmlAttrContext): HtmlNodeAttr | undefined {
const { htmlNode } = context;
const { name, modifier } = parseLitAttrName(p5Attr.name);

Expand Down Expand Up @@ -66,10 +66,10 @@ export function parseHtmlNodeAttr(p5Node: IP5TagNode, p5Attr: IP5NodeAttr, conte
* @param p5Attr
* @param context
*/
function makeHtmlAttrLocation(p5Node: IP5TagNode, p5Attr: IP5NodeAttr, context: ParseHtmlAttrContext): IHtmlNodeAttrSourceCodeLocation | undefined {
function makeHtmlAttrLocation(p5Node: Element, p5Attr: Attribute, context: ParseHtmlAttrContext): IHtmlNodeAttrSourceCodeLocation | undefined {
const { name, modifier } = parseLitAttrName(p5Attr.name);

const sourceLocation = getSourceLocation(p5Node);
const sourceLocation = p5Node.sourceCodeLocation;
if (sourceLocation == null) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Element, Node } from "parse5";
import { TS_IGNORE_FLAG } from "../../../../../constants";
import { HtmlNode, HtmlNodeKind, IHtmlNodeBase, IHtmlNodeSourceCodeLocation } from "../../../../../types/html-node/html-node-types";
import { isCommentNode, isTagNode } from "../parse-html-p5/parse-html";
import { getSourceLocation, IP5TagNode, P5Node } from "../parse-html-p5/parse-html-types";
import { parseHtmlNodeAttrs } from "./parse-html-attribute";
import { ParseHtmlContext } from "./parse-html-context";

Expand All @@ -11,7 +11,7 @@ import { ParseHtmlContext } from "./parse-html-context";
* @param parent
* @param context
*/
export function parseHtmlNodes(p5Nodes: P5Node[], parent: HtmlNode | undefined, context: ParseHtmlContext): HtmlNode[] {
export function parseHtmlNodes(p5Nodes: Node[], parent: HtmlNode | undefined, context: ParseHtmlContext): HtmlNode[] {
const htmlNodes: HtmlNode[] = [];
let ignoreNextNode = false;
for (const p5Node of p5Nodes) {
Expand Down Expand Up @@ -43,9 +43,9 @@ export function parseHtmlNodes(p5Nodes: P5Node[], parent: HtmlNode | undefined,
* @param parent
* @param context
*/
export function parseHtmlNode(p5Node: IP5TagNode, parent: HtmlNode | undefined, context: ParseHtmlContext): HtmlNode | undefined {
export function parseHtmlNode(p5Node: Element, parent: HtmlNode | undefined, context: ParseHtmlContext): HtmlNode | undefined {
// `sourceCodeLocation` will be undefined if the element was implicitly created by the parser.
if (getSourceLocation(p5Node) == null) return undefined;
if (p5Node.sourceCodeLocation == null) return undefined;

const htmlNodeBase: IHtmlNodeBase = {
tagName: p5Node.tagName.toLowerCase(),
Expand Down Expand Up @@ -74,9 +74,9 @@ export function parseHtmlNode(p5Node: IP5TagNode, parent: HtmlNode | undefined,
* @param p5Node
* @param context
*/
function isSelfClosed(p5Node: IP5TagNode, context: ParseHtmlContext) {
function isSelfClosed(p5Node: Element, context: ParseHtmlContext) {
const isEmpty = p5Node.childNodes == null || p5Node.childNodes.length === 0;
const isSelfClosed = getSourceLocation(p5Node)!.startTag.endOffset === getSourceLocation(p5Node)!.endOffset;
const isSelfClosed = p5Node.sourceCodeLocation!.startTag.endOffset === p5Node.sourceCodeLocation!.endOffset;
return isEmpty && isSelfClosed;
}

Expand All @@ -85,8 +85,8 @@ function isSelfClosed(p5Node: IP5TagNode, context: ParseHtmlContext) {
* @param p5Node
* @param context
*/
function makeHtmlNodeLocation(p5Node: IP5TagNode, context: ParseHtmlContext): IHtmlNodeSourceCodeLocation {
const loc = getSourceLocation(p5Node)!;
function makeHtmlNodeLocation(p5Node: Element, context: ParseHtmlContext): IHtmlNodeSourceCodeLocation {
const loc = p5Node.sourceCodeLocation!;

return {
start: loc.startOffset,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import { IP5CommentNode, IP5DocumentFragmentNode, IP5NodeBase, IP5TagNode, IP5TextNode, P5Node } from "./parse-html-types";

const { parseFragment } = require("parse5");
import { parseFragment, Element, DocumentFragment, Node, TextNode, CommentNode } from "parse5";

/**
* Returns if a p5Node is a tag node.
* @param node
*/
export function isTagNode(node: P5Node): node is IP5TagNode {
export function isTagNode(node: Node): node is Element {
return !node.nodeName.includes("#");
}

/**
* Returns if a p5Node is a document fragment.
* @param node
*/
export function isDocumentFragmentNode(node: IP5NodeBase): node is IP5DocumentFragmentNode {
export function isDocumentFragmentNode(node: Node): node is DocumentFragment {
return node.nodeName === "#document-fragment";
}

/**
* Returns if a p5Node is a text node.
* @param node
*/
export function isTextNode(node: P5Node): node is IP5TextNode {
export function isTextNode(node: Node): node is TextNode {
return node.nodeName === "#text";
}

/**
* Returns if a p5Node is a comment node.
* @param node
*/
export function isCommentNode(node: P5Node): node is IP5CommentNode {
export function isCommentNode(node: Node): node is CommentNode {
return node.nodeName === "#comment";
}

/**
* Parse a html string into p5Nodes.
* @param html
*/
export function parseHtml(html: string): IP5DocumentFragmentNode {
return parseFragment(html, { sourceCodeLocationInfo: true, locationInfo: true });
export function parseHtml(html: string): DocumentFragment {
return parseFragment(html, { sourceCodeLocationInfo: true });
}