🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@lit-labs/analyzer

Package Overview
Dependencies
Maintainers
11
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lit-labs/analyzer - npm Package Compare versions

Comparing version

to
0.10.0

4

lib/custom-elements/custom-elements.d.ts

@@ -12,3 +12,3 @@ /**

*/
import ts from 'typescript';
import type ts from 'typescript';
import { AnalyzerInterface, CustomElementDeclaration, Event, NamedDescribed } from '../model.js';

@@ -19,3 +19,3 @@ export type CustomElementClassDeclaration = ts.ClassDeclaration & {

export declare const isCustomElementSubclass: (node: ts.Node, analyzer: AnalyzerInterface) => node is CustomElementClassDeclaration;
export declare const getTagName: (node: ts.ClassDeclaration | ts.ClassExpression) => string | undefined;
export declare const getTagName: (node: ts.ClassDeclaration | ts.ClassExpression, analyzer: AnalyzerInterface) => string | undefined;
/**

@@ -22,0 +22,0 @@ * Parses element metadata from jsDoc tags from a LitElement declaration into

@@ -6,9 +6,2 @@ /**

*/
/**
* @fileoverview
*
* Utilities for analyzing native custom elements (i.e. `HTMLElement`)
* subclasses.
*/
import ts from 'typescript';
import { getClassMembers, getHeritage } from '../javascript/classes.js';

@@ -20,3 +13,3 @@ import { CustomElementDeclaration, } from '../model.js';

const declarations = t.getSymbol()?.getDeclarations();
return (declarations?.some((declaration) => (ts.isInterfaceDeclaration(declaration) &&
return (declarations?.some((declaration) => (analyzer.typescript.isInterfaceDeclaration(declaration) &&
declaration.name?.text === 'HTMLElement') ||

@@ -26,6 +19,6 @@ isCustomElementSubclass(declaration, analyzer)) === true);

export const isCustomElementSubclass = (node, analyzer) => {
if (!ts.isClassLike(node)) {
if (!analyzer.typescript.isClassLike(node)) {
return false;
}
if (getTagName(node) !== undefined) {
if (getTagName(node, analyzer) !== undefined) {
return true;

@@ -43,4 +36,4 @@ }

};
export const getTagName = (node) => {
const jsdocTag = ts
export const getTagName = (node, analyzer) => {
const jsdocTag = analyzer.typescript
.getJSDocTags(node)

@@ -55,14 +48,14 @@ .find((tag) => tag.tagName.text.toLowerCase() === 'customelement');

node.parent.forEachChild((child) => {
if (ts.isExpressionStatement(child) &&
ts.isCallExpression(child.expression) &&
ts.isPropertyAccessExpression(child.expression.expression) &&
if (analyzer.typescript.isExpressionStatement(child) &&
analyzer.typescript.isCallExpression(child.expression) &&
analyzer.typescript.isPropertyAccessExpression(child.expression.expression) &&
child.expression.arguments.length >= 2) {
const [tagNameArg, ctorArg] = child.expression.arguments;
const { expression, name } = child.expression.expression;
if (ts.isIdentifier(expression) &&
if (analyzer.typescript.isIdentifier(expression) &&
expression.text === 'customElements' &&
ts.isIdentifier(name) &&
analyzer.typescript.isIdentifier(name) &&
name.text === 'define' &&
ts.isStringLiteralLike(tagNameArg) &&
ts.isIdentifier(ctorArg) &&
analyzer.typescript.isStringLiteralLike(tagNameArg) &&
analyzer.typescript.isIdentifier(ctorArg) &&
ctorArg.text === node.name?.text) {

@@ -94,3 +87,3 @@ tagName = tagNameArg.text;

const cssParts = new Map();
const jsDocTags = ts.getJSDocTags(node);
const jsDocTags = analyzer.typescript.getJSDocTags(node);
if (jsDocTags !== undefined) {

@@ -128,3 +121,3 @@ for (const tag of jsDocTags) {

return new CustomElementDeclaration({
tagname: getTagName(node),
tagname: getTagName(node, analyzer),
name: node.name?.text ?? '',

@@ -131,0 +124,0 @@ node,

@@ -38,3 +38,3 @@ /**

*/
export declare const getTagName: (ts: TypeScript, declaration: LitClassDeclaration) => string | undefined;
export declare const getTagName: (declaration: LitClassDeclaration, analyzer: AnalyzerInterface) => string | undefined;
//# sourceMappingURL=lit-element.d.ts.map

@@ -17,3 +17,3 @@ /**

return new LitElementDeclaration({
tagname: getTagName(analyzer.typescript, declaration),
tagname: getTagName(declaration, analyzer),
// TODO(kschaaf): support anonymous class expressions when assigned to a const

@@ -82,14 +82,14 @@ name: declaration.name?.text ?? '',

*/
export const getTagName = (ts, declaration) => {
const customElementDecorator = ts
export const getTagName = (declaration, analyzer) => {
const customElementDecorator = analyzer.typescript
.getDecorators(declaration)
?.find((d) => isCustomElementDecorator(ts, d));
?.find((d) => isCustomElementDecorator(analyzer.typescript, d));
if (customElementDecorator !== undefined &&
customElementDecorator.expression.arguments.length === 1 &&
ts.isStringLiteral(customElementDecorator.expression.arguments[0])) {
analyzer.typescript.isStringLiteral(customElementDecorator.expression.arguments[0])) {
// Get tag from decorator: `@customElement('x-foo')`
return customElementDecorator.expression.arguments[0].text;
}
return getCustomElementTagName(declaration);
return getCustomElementTagName(declaration, analyzer);
};
//# sourceMappingURL=lit-element.js.map
{
"name": "@lit-labs/analyzer",
"version": "0.10.0-pre.0",
"version": "0.10.0",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet