Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
claimedDomModules.add(domModule);
const template = dom5.query(domModule, (e) => e.tagName === 'template');
if (template === null) {
continue;
}
// It's ok to tag templates with the expression `Polymer.html` without
// adding an import because `Polymer.html` is re-exported by both
// polymer.html and polymer-element.html and, crucially, template
// inlining happens before rewriting references.
const templateLiteral = jsc.taggedTemplateExpression(
jsc.memberExpression(
jsc.identifier('Polymer'), jsc.identifier('html')),
serializeNodeToTemplateLiteral(
parse5.treeAdapters.default.getTemplateContent(template)));
const nodePath = getNodePathInProgram(program, element.astNode);
if (nodePath === undefined) {
console.warn(
new Warning({
code: 'not-found',
message: `Can't find recast node for element ${element.tagName}`,
parsedDocument: this.document.parsedDocument,
severity: Severity.WARNING,
sourceRange: element.sourceRange!
}).toString());
continue;
}
const node = nodePath.node;
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
if (startTagRange && isPositionInsideRange(position, startTagRange, false)) {
if (position.line === startTagRange.start.line) {
// If the cursor is in the "
startTagRange.start.column + (node.tagName || '').length + 1) {
return {kind: 'tagName', element: node};
}
}
// Otherwise we're in the start tag, but not in the tag name or any
// particular attribute, but definitely in the attributes section.
return {kind: 'attribute', attribute: null, element: node};
}
// The edges of a comment aren't part of the comment.
if (parse5.treeAdapters.default.isCommentNode(node) &&
isPositionInsideRange(position, sourceRange, false)) {
return {kind: 'comment', commentNode: node};
}
if (parse5.treeAdapters.default.isTextNode(node)) {
const parent = node.parentNode;
if (parent && parent.tagName === 'script') {
return {kind: 'scriptTagContents', textNode: node};
}
if (parent && parent.tagName === 'style') {
return {kind: 'styleTagContents', textNode: node};
}
return {kind: 'text', textNode: node};
}
if (isPositionInsideRange(position, sourceRange, false)) {
/**
* This is tricky. Consider the position inside an empty element, i.e.
* here:
* .
continue;
}
switch (extension) {
case '.js':
scripts.add(file);
break;
case '.css':
stylesheets.add(file);
break;
}
}
}
// Find the head and body elements
const treeAdapter = parse5.treeAdapters.default;
const document = parse5.parse(params.inputContent, {
treeAdapter,
locationInfo: true
});
let headElement;
let bodyElement;
for (const docChild of document.childNodes) {
if (docChild.tagName === 'html') {
for (const htmlChild of docChild.childNodes) {
if (htmlChild.tagName === 'head') {
headElement = htmlChild;
} else if (htmlChild.tagName === 'body') {
bodyElement = htmlChild;
}
}
}
function getDocument(source) {
return parse5.parse(source, {treeAdapter: parse5.treeAdapters.htmlparser2});
}
});
function getDocument(source) {
return parse5.parse(source, {treeAdapter: parse5.treeAdapters.htmlparser2});
}
Parse5DomAdapter.makeCurrent = function () {
treeAdapter = parse5.treeAdapters.htmlparser2;
setRootDomAdapter(new Parse5DomAdapter());
};
Parse5DomAdapter.prototype.hasProperty = function (element, name) {
Parse5DomAdapter.makeCurrent = function () {
treeAdapter = parse5.treeAdapters.htmlparser2;
setRootDomAdapter(new Parse5DomAdapter());
};
/**
function serializeNode(node) {
const treeAdapter = parse.treeAdapters.default;
const frag = treeAdapter.createDocumentFragment();
treeAdapter.appendChild(frag, node);
return parse.serialize(frag);
}
private _getWarningsForTemplate(
parsedHtml: ParsedHtmlDocument, template: parse5.ASTNode): Warning[] {
let warnings: Warning[] = [];
const content = parse5.treeAdapters.default.getTemplateContent(template);
for (const node of dom5.depthFirst(content)) {
if (dom5.isElement(node) && node.attrs.length > 0) {
warnings =
warnings.concat(this._getWarningsForElementAttrs(parsedHtml, node));
} else if (
dom5.isTextNode(node) && typeof node.value === 'string' &&
this._extractBadBindingExpression(node.value)) {
warnings.push(new Warning({
parsedDocument: parsedHtml,
code: 'unbalanced-delimiters',
message: this._getMessageForBadBindingExpression(node.value),
severity: Severity.ERROR,
sourceRange: parsedHtml.sourceRangeForNode(node)!
}));
}