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

bun-repl

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bun-repl - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

package.json
{
"type": "module",
"name": "bun-repl",
"version": "2.0.0",
"version": "2.0.1",
"description": "Experimental REPL for Bun",

@@ -6,0 +6,0 @@ "main": "src/module/repl.ts",

@@ -14,3 +14,3 @@ import swc from '@swc/core';

strict: true,
strictMode: true,
strictMode: false,
ignoreDynamic: true,

@@ -17,0 +17,0 @@ importInterop: 'none',

@@ -11,2 +11,6 @@ import swc from '@swc/core';

const StringReplaceAll = Function.prototype.call.bind(String.prototype.replaceAll);
const randomUUID = crypto.randomUUID.bind(crypto);
const safeUUID = () => StringReplaceAll(randomUUID(), '-', '') as string;
export default class Transpiler extends swc.Compiler {

@@ -24,3 +28,3 @@ constructor(config: swc.Options = {}) {

preprocess(code: string): string {
return ';void 0;' + code
return code
.replaceAll(/import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*\{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+\})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/g,

@@ -48,18 +52,17 @@ ($0, defaultVar?: string, destructuredVars?: string, wildcardVar?: string, moduleIdentifier: string = '') => {

postprocess(code: string): string {
return code
//.replaceAll(/(?:let|const) ([A-Za-z_$\d]+? ?=.)/g,
// ($0, varname: string) => 'var ' + varname)
//.replaceAll(/(?:let|const) ?({[A-Za-z_$, \t\n\d]+?}) ?(=.)/g,
// ($0, vars: string, end: string) => `var ${vars} ${end}`)
let importsData = [] as ({ requireVar: string, requireStr: string, info: replTranspiledImportInfo, uuid: string })[];
code = '"use strict";void 0;' + code
.replaceAll(/(?:var|let|const) (_.+?) = require\("(.+?)"\);[ \t\n;]*\/\*\$replTranspiledImport:({.+?})\*\//g,
($0, requireVar: string, requireStr: string, infoStr: string) => {
const info = JSON.parse(infoStr) as replTranspiledImportInfo;
let str = `const ${requireVar} = require("${requireStr}");`;
const uuid = safeUUID();
importsData.push({ requireVar, requireStr, info, uuid });
let str = `const ${requireVar}${uuid} = require("${requireStr}");`;
if (info.varname) {
str += `var ${info.varname} = ${requireVar}`;
if (!info.wildcard) str += `.default??${requireVar};`;
str += `const ${info.varname}=${requireVar}${uuid}`;
if (!info.wildcard) str += `.default??${requireVar}${uuid};`;
str += ';';
}
if (info.destructuredVars) {
let ifstr = 'if(!(';
let ifstr = 'true.valueOf["@@replTemp"]={};if(!(';
let delstr = ')){';

@@ -72,9 +75,9 @@ info.destructuredVars.forEach(variable => {

exportStr = match[1];
str += `var { ${exportStr}: ${variable} } = ${requireVar};`;
} else str += `var { ${variable} } = ${requireVar};`;
ifstr += `((async function*(){}).constructor['@@REPLGlobal'].temp.$v="${exportStr}") in ${requireVar}&&`;
delstr += `delete (async function*(){}).constructor['@@REPLGlobal'].global["${variable}"];`;
str += `const{${exportStr}:${variable}}=${requireVar}${uuid};`;
} else str += `const{${variable}}=${requireVar}${uuid};`;
ifstr += `(true.valueOf['@@replTemp'].$v="${exportStr}") in ${requireVar}${uuid}&&`;
delstr += `delete true.valueOf['@@replTemp']["${variable}"];`;
});
const errmsg = `Import named '\${(async function*(){}).constructor['@@REPLGlobal'].temp.$v}' not found in module '${requireStr}'.`;
delstr += `throw new (async function*(){}).constructor['@@REPLGlobal'].SyntaxError(\`${errmsg}\`);};`;
const errmsg = `Import named '\${true.valueOf["@@replTemp"].$v}' not found in module '${requireStr}'.`;
delstr += `{const $err=new SyntaxError(\`${errmsg}\`);$err.stack='';throw $err;}};`;
ifstr = ifstr.slice(0, -2);

@@ -85,2 +88,6 @@ str += ifstr + delstr;

});
for (const importData of importsData) {
code = code.replaceAll(new RegExp(`void\\s+${importData.requireVar}`, 'g'), `void ${importData.requireVar}${importData.uuid}`);
}
return code;
}

@@ -87,0 +94,0 @@

Sorry, the diff of this file is not supported yet

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