Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsenv/utils

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/utils - npm Package Compare versions

Comparing version 1.4.1 to 1.4.2

50

js_ast/js_static_analysis.js

@@ -70,3 +70,3 @@ import { getTypePropertyNode } from "./js_ast.js"

export const analyzeNewWorkerOrNewSharedWorker = (path) => {
export const analyzeNewWorkerOrNewSharedWorker = (path, { isJsModule }) => {
const node = path.node

@@ -76,6 +76,6 @@ if (!isNewWorkerOrNewSharedWorker(node)) {

}
return analyzeWorkerCallArguments(
path,
node.callee.name === "Worker" ? "worker" : "shared_worker",
)
return analyzeWorkerCallArguments(path, {
isJsModule,
workerType: node.callee.name === "Worker" ? "worker" : "shared_worker",
})
}

@@ -90,3 +90,3 @@ const isNewWorkerOrNewSharedWorker = (node) => {

const analyzeWorkerCallArguments = (path, workerType) => {
const analyzeWorkerCallArguments = (path, { isJsModule, workerType }) => {
const node = path.node

@@ -136,2 +136,3 @@ const mentions = []

const newUrlMentions = analyzeNewUrlCall(path.get("arguments")[0], {
isJsModule,
ignoreInsideWorker: false,

@@ -152,3 +153,3 @@ })

export const analyzeServiceWorkerRegisterCall = (path) => {
export const analyzeServiceWorkerRegisterCall = (path, { isJsModule } = {}) => {
const node = path.node

@@ -158,3 +159,6 @@ if (!isServiceWorkerRegisterCall(node)) {

}
return analyzeWorkerCallArguments(path, "service_worker")
return analyzeWorkerCallArguments(path, {
isJsModule,
workerType: "service_worker",
})
}

@@ -207,3 +211,6 @@ const isServiceWorkerRegisterCall = (node) => {

export const analyzeNewUrlCall = (path, { ignoreInsideWorker = true } = {}) => {
export const analyzeNewUrlCall = (
path,
{ isJsModule = false, ignoreInsideWorker = true } = {},
) => {
const node = path.node

@@ -242,3 +249,3 @@ if (!isNewUrlCall(node)) {

const secondArgNode = node.arguments[1]
const baseUrlType = analyzeUrlNodeType(secondArgNode)
const baseUrlType = analyzeUrlNodeType(secondArgNode, { isJsModule })
if (baseUrlType) {

@@ -278,3 +285,3 @@ // we can understand the second argument

}
const analyzeUrlNodeType = (secondArgNode) => {
const analyzeUrlNodeType = (secondArgNode, { isJsModule } = {}) => {
if (secondArgNode.type === "StringLiteral") {

@@ -292,3 +299,19 @@ return "StringLiteral"

if (
!isJsModule &&
secondArgNode.type === "MemberExpression" &&
secondArgNode.object.type === "MemberExpression" &&
secondArgNode.object.object.type === "Identifier" &&
// because of minification we can't assume _context.
// so anything matching "*.meta.url" (in the context of new URL())
// will be assumed to be the equivalent to "import.meta.url"
// secondArgNode.object.object.name === "_context" &&
secondArgNode.object.property.type === "Identifier" &&
secondArgNode.object.property.name === "meta" &&
secondArgNode.property.type === "Identifier" &&
secondArgNode.property.name === "url"
) {
return "context.meta.url"
}
if (
secondArgNode.type === "MemberExpression" &&
secondArgNode.object.type === "Identifier" &&

@@ -410,2 +433,7 @@ secondArgNode.object.name === "window" &&

export const analyzeSystemNewUrlCall = () => {
// TODO: new URL(specifier, _context.meta.url)
// apparently it won't recognize the service worker without this so I have to take that into account
}
const getNodePosition = (node) => {

@@ -412,0 +440,0 @@ return {

export const msAsDuration = (ms) => {
if (ms < 1) {
// it would be messy to write 0.0001 second (stands for 0.1 milliseconds)
// but is not in the scope of this for now
return "not implemented"
// it would be barely readable to write 0.0001 second (stands for 0.1 millisecond)
// and this precision does not matter
// (this function is meant to display a duration to a human)
// so in this case we'll return "less than 1 millisecond"
return "less than 1 millisecond"
}

@@ -7,0 +9,0 @@ const { primary, remaining } = parseMs(ms)

{
"name": "@jsenv/utils",
"version": "1.4.1",
"version": "1.4.2",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": {

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