New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tsr

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsr - npm Package Compare versions

Comparing version 1.3.3 to 1.3.4

dist/util/export.d.ts

81

dist/util/edit.js

@@ -12,2 +12,7 @@ import ts from "typescript";

import { parseFile } from "./parseFile.js";
import {
isWholeExportDeclarationWithFile,
isNamedExport,
isWholeExportDeclaration
} from "./export.js";
const transform = (source, transformer) => {

@@ -126,3 +131,3 @@ const file = ts.createSourceFile("file.ts", source, ts.ScriptTarget.Latest);

const printed = result ? printer.printFile(result).replace(/\n$/, "") : "";
const leading = code.match(/^([\s]+)/)?.[0] || "";
const leading = code.match(/^(\s+)/)?.[0] || "";
return `${leading}${printed}`;

@@ -150,2 +155,46 @@ };

};
const deeplyGetExportNames = ({
item,
files,
fileNames,
options
}) => {
const filesAlreadyVisited = /* @__PURE__ */ new Set();
return innerDeeplyGetExportNames({
item,
files,
fileNames,
options,
filesAlreadyVisited
});
};
const innerDeeplyGetExportNames = ({
item,
files,
fileNames,
options,
filesAlreadyVisited
}) => {
if (filesAlreadyVisited.has(item.file)) {
return [];
}
const parsed = parseFile({
file: item.file,
content: files.get(item.file) || "",
options,
destFiles: fileNames
});
const deepExportNames = parsed.exports.filter(
(v) => isWholeExportDeclaration(v) && isWholeExportDeclarationWithFile(v)
).flatMap(
(v) => innerDeeplyGetExportNames({
item: v,
files,
fileNames,
options,
filesAlreadyVisited: filesAlreadyVisited.add(item.file)
})
);
return parsed.exports.filter(isNamedExport).flatMap((v) => v.name).concat(deepExportNames);
};
const processFile = ({

@@ -329,15 +378,12 @@ targetFile,

case "whole": {
if (!item.file) {
if (!isWholeExportDeclarationWithFile(item)) {
break;
}
const parsed = parseFile({
file: item.file,
content: files.get(item.file) || "",
options,
destFiles: fileNames
const exportNames = deeplyGetExportNames({
item,
files,
fileNames,
options
});
const exported = parsed.exports.flatMap(
(v) => "name" in v ? v.name : []
);
if (exported.some((v) => usage.has(v))) {
if (exportNames.some((v) => usage.has(v))) {
break;

@@ -424,3 +470,3 @@ }

if (changes.length === 0) {
const result2 = {
const result = {
operation: "edit",

@@ -430,3 +476,3 @@ content: files.get(targetFile) || "",

};
return result2;
return result;
}

@@ -443,3 +489,3 @@ let content = applyTextChanges(files.get(targetFile) || "", changes);

fileService.set(targetFile, content);
const result2 = applyCodeFix({
const result = applyCodeFix({
fixId: fixIdDelete,

@@ -449,6 +495,6 @@ fileName: targetFile,

});
if (result2 === content) {
if (result === content) {
break;
}
content = result2;
content = result;
}

@@ -463,3 +509,3 @@ fileService.set(targetFile, content);

fileService.set(targetFile, content);
const result = {
return {
operation: "edit",

@@ -469,3 +515,2 @@ content: fileService.get(targetFile),

};
return result;
};

@@ -472,0 +517,0 @@ const edit = ({

import ts from "typescript";
import { parseFile } from "./parseFile.js";
const ALL_EXPORTS_OF_UNKNOWN_FILE = "__all_exports_of_unknown_file__";
const ALL_EXPORTS_OF_UNKNOWN_FILE = "#all_exports_of_unknown_file#";
const CIRCULAR_DEPENDENCY = "#circular_dependency#";
const getExportsOfFile = ({

@@ -11,2 +12,3 @@ targetFile,

const result = [];
const alreadyVisited = /* @__PURE__ */ new Set();
const stack = [targetFile];

@@ -18,2 +20,7 @@ while (stack.length) {

}
if (alreadyVisited.has(item)) {
result.push(CIRCULAR_DEPENDENCY);
continue;
}
alreadyVisited.add(item);
const { exports } = parseFile({

@@ -20,0 +27,0 @@ file: item,

import ts from 'typescript';
type Export = {
kind: ts.SyntaxKind.VariableStatement;
name: string[];
change: {
code: string;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.FunctionDeclaration;
name: string;
change: {
code: string;
isUnnamedDefaultExport?: boolean;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.InterfaceDeclaration;
name: string;
change: {
code: string;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.TypeAliasDeclaration;
name: string;
change: {
code: string;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.ExportAssignment;
name: 'default';
change: {
code: string;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.ExportDeclaration;
type: 'named';
name: string[];
skip: boolean;
change: {
code: string;
span: {
start: number;
length: number;
};
};
start: number;
} | {
kind: ts.SyntaxKind.ExportDeclaration;
type: 'namespace';
name: string;
start: number;
change: {
code: string;
span: {
start: number;
length: number;
};
};
} | {
kind: ts.SyntaxKind.ExportDeclaration;
type: 'whole';
file: string | null;
specifier: string;
start: number;
change: {
code: string;
span: {
start: number;
length: number;
};
};
} | {
kind: ts.SyntaxKind.ClassDeclaration;
name: string;
change: {
code: string;
isUnnamedDefaultExport?: boolean;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
} | {
kind: ts.SyntaxKind.EnumDeclaration;
name: string;
change: {
code: string;
span: {
start: number;
length: number;
};
};
skip: boolean;
start: number;
};
import { Export } from './export.js';
type AmbientDeclaration = {

@@ -128,0 +4,0 @@ kind: ts.SyntaxKind.ModuleDeclaration;

@@ -45,3 +45,3 @@ {

},
"version": "1.3.3"
"version": "1.3.4"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc