Socket
Socket
Sign inDemoInstall

@mongosh/async-rewriter2

Package Overview
Dependencies
Maintainers
13
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongosh/async-rewriter2 - npm Package Compare versions

Comparing version 1.10.1 to 1.10.2

.depcheckrc

11

.eslintrc.js

@@ -1,1 +0,10 @@

module.exports = require('../../config/eslintrc.base');
const { fixCygwinPath } = require('@mongodb-js/eslint-config-mongosh/utils');
module.exports = {
root: true,
extends: ['@mongodb-js/eslint-config-mongosh'],
parserOptions: {
tsconfigRootDir: fixCygwinPath(__dirname),
project: ['./tsconfig-lint.json'],
},
};

10

benchmark/index.ts

@@ -6,6 +6,10 @@ import AsyncWriter from '../src/index';

const start = process.hrtime.bigint();
for (let i = 0; i < RUNS; i++)
new AsyncWriter().runtimeSupportCode();
for (let i = 0; i < RUNS; i++) new AsyncWriter().runtimeSupportCode();
const stop = process.hrtime.bigint();
console.log('Time for processing runtime support code', Number(stop - start) / 1_000_000 / RUNS, 'ms');
// eslint-disable-next-line no-console
console.log(
'Time for processing runtime support code',
Number(stop - start) / 1_000_000 / RUNS,
'ms'
);
#!/usr/bin/env node
/* eslint-disable strict, no-sync */
'use strict';

@@ -4,0 +3,0 @@ const AsyncWriter = require('../').default;

#!/usr/bin/env node
/* eslint-disable strict, no-sync */
'use strict';

@@ -10,3 +9,8 @@ const fs = require('fs');

const inJS = path.resolve(__dirname, '..', 'src', 'runtime-support.nocov.js');
const outJS = path.resolve(__dirname, '..', 'src', 'runtime-support.out.nocov.ts');
const outJS = path.resolve(
__dirname,
'..',
'src',
'runtime-support.out.nocov.ts'
);

@@ -24,4 +28,7 @@ if (process.argv[2] === '--firstpass') {

const runtimeSupportCode = rewriter.process(
rewriter.unprocessedRuntimeSupportCode() +
fs.readFileSync(inJS, 'utf8'));
fs.writeFileSync(outJS, `export default ${JSON.stringify(runtimeSupportCode)};\n`);
rewriter.unprocessedRuntimeSupportCode() + fs.readFileSync(inJS, 'utf8')
);
fs.writeFileSync(
outJS,
`export default ${JSON.stringify(runtimeSupportCode)};\n`
);

@@ -37,5 +37,5 @@ "use strict";

step(ast, originalSource, plugins = [], opts = {}) {
const transform = (opts) => ast ?
babel.transformFromAstSync(ast, originalSource, opts) :
babel.transformSync(originalSource, opts);
const transform = (opts) => ast
? babel.transformFromAstSync(ast, originalSource, opts)
: babel.transformSync(originalSource, opts);
return transform({

@@ -51,3 +51,3 @@ plugins,

sourceType: 'script',
...opts
...opts,
});

@@ -61,3 +61,3 @@ }

require('@babel/plugin-transform-parameters').default,
require('@babel/plugin-transform-destructuring').default
require('@babel/plugin-transform-destructuring').default,
])) === null || _a === void 0 ? void 0 : _a.ast;

@@ -69,4 +69,6 @@ ast = (_b = this.step(ast, code, [wrap_as_iife_1.default])) === null || _b === void 0 ? void 0 : _b.ast;

transform_maybe_await_1.default,
{ customErrorBuilder: babel.types.identifier('MongoshAsyncWriterError') }
]
{
customErrorBuilder: babel.types.identifier('MongoshAsyncWriterError'),
},
],
], { code: true, ast: false })) === null || _d === void 0 ? void 0 : _d.code;

@@ -73,0 +75,0 @@ }

@@ -7,4 +7,3 @@ "use strict";

AsyncRewriterErrors["SyntheticPromiseInAlwaysSyncContext"] = "ASYNC-10012";
})(AsyncRewriterErrors || (AsyncRewriterErrors = {}));
exports.AsyncRewriterErrors = AsyncRewriterErrors;
})(AsyncRewriterErrors || (exports.AsyncRewriterErrors = AsyncRewriterErrors = {}));
//# sourceMappingURL=error-codes.js.map

@@ -16,3 +16,3 @@ declare class TypedArray {

find: {
<S extends any>(predicate: (this: void, value: any, index: number, obj: any[]) => value is S, thisArg?: any): S | undefined;
<S extends any>(predicate: (value: any, index: number, obj: any[]) => value is S, thisArg?: any): S | undefined;
(predicate: (value: any, index: number, obj: any[]) => unknown, thisArg?: any): any;

@@ -19,0 +19,0 @@ };

@@ -79,3 +79,4 @@ 'use strict';

const len = O.length >>> 0;
if (typeof callbackfn !== 'function' && Object.prototype.toString.call(callbackfn) !== '[object Function]') {
if (typeof callbackfn !== 'function' &&
Object.prototype.toString.call(callbackfn) !== '[object Function]') {
throw new TypeError();

@@ -159,3 +160,3 @@ }

configurable: true,
writable: true
writable: true,
});

@@ -184,12 +185,10 @@ Object.defineProperty(Array.prototype, 'findIndex', {

configurable: true,
writable: true
writable: true,
});
Array.prototype.reduce = function (callback) {
if (this === null) {
throw new TypeError('Array.prototype.reduce ' +
'called on null or undefined');
throw new TypeError('Array.prototype.reduce ' + 'called on null or undefined');
}
if (typeof callback !== 'function') {
throw new TypeError(callback +
' is not a function');
throw new TypeError(callback + ' is not a function');
}

@@ -208,4 +207,3 @@ const o = Object(this);

if (k >= len) {
throw new TypeError('Reduce of empty array ' +
'with no initial value');
throw new TypeError('Reduce of empty array ' + 'with no initial value');
}

@@ -258,3 +256,3 @@ value = o[k++];

Set.prototype.forEach = function (callback, thisArg) {
[...this].forEach(value => {
[...this].forEach((value) => {
callback.call(thisArg, value, value, this);

@@ -265,15 +263,23 @@ });

Array.prototype.sort = function (compareFn) {
return origArraySort.call(this, compareFn ? function (...args) {
return [...(function* () {
yield compareFn(...args);
})()][0];
} : undefined);
return origArraySort.call(this, compareFn
? function (...args) {
return [
...(function* () {
yield compareFn(...args);
})(),
][0];
}
: undefined);
};
const origTypedArraySort = TypedArray.prototype.sort;
TypedArray.prototype.sort = function (compareFn) {
return origTypedArraySort.call(this, compareFn ? function (...args) {
return [...(function* () {
yield compareFn(...args);
})()][0];
} : undefined);
return origTypedArraySort.call(this, compareFn
? function (...args) {
return [
...(function* () {
yield compareFn(...args);
})(),
][0];
}
: undefined);
};

@@ -293,3 +299,3 @@ Array.prototype.flatMap = function (...args) {

const array = Array.prototype.filter.call(this, func, thisArg);
return new (this.constructor)(array);
return new this.constructor(array);
};

@@ -296,0 +302,0 @@ const origFptS = Function.prototype.toString;

import * as babel from '@babel/core';
import * as BabelTypes from '@babel/types';
declare const _default: ({ types: t }: {
import type * as BabelTypes from '@babel/types';
declare const _default: ({ types: t, }: {
types: typeof BabelTypes;

@@ -5,0 +5,0 @@ }) => babel.PluginObj<{

@@ -27,4 +27,6 @@ "use strict";

const babel = __importStar(require("@babel/core"));
exports.default = ({ types: t }) => {
function asNodeKey(v) { return v; }
exports.default = ({ types: t, }) => {
function asNodeKey(v) {
return v;
}
const isGeneratedInnerFunction = asNodeKey(Symbol('isGeneratedInnerFunction'));

@@ -95,3 +97,3 @@ const isGeneratedHelper = asNodeKey(Symbol('isGeneratedHelper'));

)`, {
allowAwaitOutsideFunction: true
allowAwaitOutsideFunction: true,
});

@@ -116,3 +118,6 @@ const assertNotSyntheticExpressionTemplate = babel.template.expression(`

}
`, { placeholderPattern: false, placeholderWhitelist: new Set(['DE_IDENTIFIER']) });
`, {
placeholderPattern: false,
placeholderWhitelist: new Set(['DE_IDENTIFIER']),
});
const returnValueWrapperTemplate = babel.template.expression(`(

@@ -137,8 +142,9 @@ SYNC_RETURN_VALUE_IDENTIFIER = NODE,

return;
const originalSource = path.parent.start !== undefined ?
this.file.code.slice((_a = path.parent.start) !== null && _a !== void 0 ? _a : undefined, (_b = path.parent.end) !== null && _b !== void 0 ? _b : undefined) :
'function () { [unknown code] }';
const originalSource = path.parent.start !== undefined
? this.file.code.slice((_a = path.parent.start) !== null && _a !== void 0 ? _a : undefined, (_b = path.parent.end) !== null && _b !== void 0 ? _b : undefined)
: 'function () { [unknown code] }';
const encodedOriginalSource = encodeURIComponent(originalSource);
const originalSourceNode = t.expressionStatement(t.stringLiteral(`<async_rewriter>${encodedOriginalSource}</>`));
const existingIdentifiers = (_c = path.findParent(path => !!path.getData(identifierGroupKey))) === null || _c === void 0 ? void 0 : _c.getData(identifierGroupKey);
const existingIdentifiers = (_c = path
.findParent((path) => !!path.getData(identifierGroupKey))) === null || _c === void 0 ? void 0 : _c.getData(identifierGroupKey);
const functionState = path.scope.generateUidIdentifier('fs');

@@ -162,27 +168,31 @@ const synchronousReturnValue = path.scope.generateUidIdentifier('srv');

syntheticPromiseSymbol,
demangleError
demangleError,
};
path.parentPath.setData(identifierGroupKey, identifiersGroup);
const commonHelpers = existingIdentifiers ? [] : [
Object.assign(syntheticPromiseSymbolTemplate({
SP_IDENTIFIER: syntheticPromiseSymbol
}), { [isGeneratedHelper]: true }),
Object.assign(expressionHolderVariableTemplate({
EXPRESSION_HOLDER_IDENTIFIER: expressionHolder
}), { [isGeneratedHelper]: true })
];
const promiseHelpers = existingIdentifiers ? [] : [
...commonHelpers,
Object.assign(markSyntheticPromiseTemplate({
MSP_IDENTIFIER: markSyntheticPromise,
SP_IDENTIFIER: syntheticPromiseSymbol
}), { [isGeneratedHelper]: true }),
Object.assign(isSyntheticPromiseTemplate({
ISP_IDENTIFIER: isSyntheticPromise,
SP_IDENTIFIER: syntheticPromiseSymbol
}), { [isGeneratedHelper]: true }),
Object.assign(demangleErrorTemplate({
DE_IDENTIFIER: demangleError
}), { [isGeneratedHelper]: true })
];
const commonHelpers = existingIdentifiers
? []
: [
Object.assign(syntheticPromiseSymbolTemplate({
SP_IDENTIFIER: syntheticPromiseSymbol,
}), { [isGeneratedHelper]: true }),
Object.assign(expressionHolderVariableTemplate({
EXPRESSION_HOLDER_IDENTIFIER: expressionHolder,
}), { [isGeneratedHelper]: true }),
];
const promiseHelpers = existingIdentifiers
? []
: [
...commonHelpers,
Object.assign(markSyntheticPromiseTemplate({
MSP_IDENTIFIER: markSyntheticPromise,
SP_IDENTIFIER: syntheticPromiseSymbol,
}), { [isGeneratedHelper]: true }),
Object.assign(isSyntheticPromiseTemplate({
ISP_IDENTIFIER: isSyntheticPromise,
SP_IDENTIFIER: syntheticPromiseSymbol,
}), { [isGeneratedHelper]: true }),
Object.assign(demangleErrorTemplate({
DE_IDENTIFIER: demangleError,
}), { [isGeneratedHelper]: true }),
];
const syncFnHelpers = [

@@ -193,4 +203,4 @@ ...commonHelpers,

SP_IDENTIFIER: syntheticPromiseSymbol,
CUSTOM_ERROR_BUILDER: (_k = this.opts.customErrorBuilder) !== null && _k !== void 0 ? _k : t.identifier('Error')
}), { [isGeneratedHelper]: true })
CUSTOM_ERROR_BUILDER: (_k = this.opts.customErrorBuilder) !== null && _k !== void 0 ? _k : t.identifier('Error'),
}), { [isGeneratedHelper]: true }),
];

@@ -202,4 +212,4 @@ if (path.parentPath.node.async) {

rethrowTemplate({
ORIGINAL_CODE: path.node.body
})
ORIGINAL_CODE: path.node.body,
}),
]));

@@ -217,4 +227,4 @@ return;

rethrowTemplate({
ORIGINAL_CODE: path.node.body
})
ORIGINAL_CODE: path.node.body,
}),
]));

@@ -226,3 +236,3 @@ return;

SYNC_RETURN_VALUE_IDENTIFIER: synchronousReturnValue,
ORIGINAL_CODE: Object.assign(path.node, { [isOriginalBody]: true })
ORIGINAL_CODE: Object.assign(path.node, { [isOriginalBody]: true }),
}), { [isGeneratedInnerFunction]: true });

@@ -234,3 +244,3 @@ const wrapperFunction = wrapperFunctionTemplate({

MSP_IDENTIFIER: markSyntheticPromise,
ASYNC_TRY_CATCH_WRAPPER: asyncTryCatchWrapper
ASYNC_TRY_CATCH_WRAPPER: asyncTryCatchWrapper,
});

@@ -240,3 +250,3 @@ path.replaceWith(t.blockStatement([

...promiseHelpers,
...wrapperFunction
...wrapperFunction,
]));

@@ -246,6 +256,12 @@ },

enter(path) {
if (path.node.operator === 'typeof' && path.node.argument.type === 'Identifier' && !path.node[isExpandedTypeof]) {
path.replaceWith(t.conditionalExpression(t.binaryExpression('===', { ...path.node, [isGeneratedHelper]: true, [isExpandedTypeof]: true }, t.stringLiteral('undefined')), t.stringLiteral('undefined'), { ...path.node, [isExpandedTypeof]: true }));
if (path.node.operator === 'typeof' &&
path.node.argument.type === 'Identifier' &&
!path.node[isExpandedTypeof]) {
path.replaceWith(t.conditionalExpression(t.binaryExpression('===', {
...path.node,
[isGeneratedHelper]: true,
[isExpandedTypeof]: true,
}, t.stringLiteral('undefined')), t.stringLiteral('undefined'), { ...path.node, [isExpandedTypeof]: true }));
}
}
},
},

@@ -255,8 +271,7 @@ Expression: {

var _a, _b;
if (path.parentPath.isArrowFunctionExpression() && path.key === 'body') {
path.replaceWith(t.blockStatement([
t.returnStatement(path.node)
]));
if (path.parentPath.isArrowFunctionExpression() &&
path.key === 'body') {
path.replaceWith(t.blockStatement([t.returnStatement(path.node)]));
}
if ((_b = (_a = path.find(path => path.isFunction() || !!path.node[isGeneratedHelper])) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b[isGeneratedHelper]) {
if ((_b = (_a = path.find((path) => path.isFunction() || !!path.node[isGeneratedHelper])) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b[isGeneratedHelper]) {
return path.skip();

@@ -275,14 +290,16 @@ }

if (functionParent.node[isGeneratedInnerFunction]) {
if (!((_b = (_a = path.findParent(path => path.isFunction() || !!path.node[isOriginalBody])) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b[isOriginalBody])) {
if (!((_b = (_a = path.findParent((path) => path.isFunction() || !!path.node[isOriginalBody])) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b[isOriginalBody])) {
return;
}
identifierGroup = (_d = (_c = functionParent.getFunctionParent()) === null || _c === void 0 ? void 0 : _c.getData) === null || _d === void 0 ? void 0 : _d.call(_c, identifierGroupKey);
identifierGroup = (_d = (_c = functionParent
.getFunctionParent()) === null || _c === void 0 ? void 0 : _c.getData) === null || _d === void 0 ? void 0 : _d.call(_c, identifierGroupKey);
if (!identifierGroup) {
throw new Error('Parent of generated inner function does not have existing identifiers available');
}
if (path.parentPath.isReturnStatement() && !path.node[isGeneratedHelper]) {
if (path.parentPath.isReturnStatement() &&
!path.node[isGeneratedHelper]) {
path.replaceWith(Object.assign(returnValueWrapperTemplate({
SYNC_RETURN_VALUE_IDENTIFIER: identifierGroup.synchronousReturnValue,
FUNCTION_STATE_IDENTIFIER: identifierGroup.functionState,
NODE: path.node
NODE: path.node,
}), { [isGeneratedHelper]: true }));

@@ -308,3 +325,4 @@ return;

return;
if (path.parentPath.isUnaryExpression() && path.parentPath.node.operator === 'delete')
if (path.parentPath.isUnaryExpression() &&
path.parentPath.node.operator === 'delete')
return;

@@ -332,6 +350,6 @@ if (path.isLiteral() ||

return;
const { expressionHolder, isSyntheticPromise, assertNotSyntheticPromise } = identifierGroup;
const prettyOriginalString = limitStringLength(path.node.start !== undefined ?
this.file.code.slice((_e = path.node.start) !== null && _e !== void 0 ? _e : undefined, (_f = path.node.end) !== null && _f !== void 0 ? _f : undefined) :
'<unknown>', 24);
const { expressionHolder, isSyntheticPromise, assertNotSyntheticPromise, } = identifierGroup;
const prettyOriginalString = limitStringLength(path.node.start !== undefined
? this.file.code.slice((_e = path.node.start) !== null && _e !== void 0 ? _e : undefined, (_f = path.node.end) !== null && _f !== void 0 ? _f : undefined)
: '<unknown>', 24);
if (!functionParent.node.async) {

@@ -341,3 +359,3 @@ path.replaceWith(Object.assign(assertNotSyntheticExpressionTemplate({

NODE: path.node,
ANSP_IDENTIFIER: assertNotSyntheticPromise
ANSP_IDENTIFIER: assertNotSyntheticPromise,
}), { [isGeneratedHelper]: true }));

@@ -351,6 +369,6 @@ return;

ISP_IDENTIFIER: isSyntheticPromise,
NODE: path.node
NODE: path.node,
}), { [isGeneratedHelper]: true }));
path.skip();
}
},
},

@@ -360,14 +378,19 @@ CatchClause: {

var _a;
if (path.node[isGeneratedHelper] || !path.node.param || path.node.param.type !== 'Identifier')
if (path.node[isGeneratedHelper] ||
!path.node.param ||
path.node.param.type !== 'Identifier')
return;
const existingIdentifiers = (_a = path.findParent(path => !!path.getData(identifierGroupKey))) === null || _a === void 0 ? void 0 : _a.getData(identifierGroupKey);
const existingIdentifiers = (_a = path
.findParent((path) => !!path.getData(identifierGroupKey))) === null || _a === void 0 ? void 0 : _a.getData(identifierGroupKey);
if (!existingIdentifiers)
return;
path.replaceWith(Object.assign(t.catchClause(path.node.param, t.blockStatement([
t.expressionStatement(t.assignmentExpression('=', path.node.param, t.callExpression(existingIdentifiers.demangleError, [path.node.param]))),
path.node.body
t.expressionStatement(t.assignmentExpression('=', path.node.param, t.callExpression(existingIdentifiers.demangleError, [
path.node.param,
]))),
path.node.body,
])), { [isGeneratedHelper]: true }));
}
}
}
},
},
},
};

@@ -378,6 +401,6 @@ };

return input;
return input.slice(0, (maxLength - 5) * 0.7) +
return (input.slice(0, (maxLength - 5) * 0.7) +
' ... ' +
input.slice(input.length - (maxLength - 5) * 0.3);
input.slice(input.length - (maxLength - 5) * 0.3));
}
//# sourceMappingURL=transform-maybe-await.js.map
import * as babel from '@babel/core';
import * as BabelTypes from '@babel/types';
declare const _default: ({ types: t }: {
import type * as BabelTypes from '@babel/types';
declare const _default: ({ types: t, }: {
types: typeof BabelTypes;
}) => babel.PluginObj<{}>;
export default _default;

@@ -27,4 +27,6 @@ "use strict";

const babel = __importStar(require("@babel/core"));
exports.default = ({ types: t }) => {
function asNodeKey(v) { return v; }
exports.default = ({ types: t, }) => {
function asNodeKey(v) {
return v;
}
const isGeneratedTryCatch = asNodeKey(Symbol('isGeneratedTryCatch'));

@@ -53,5 +55,5 @@ const notUncatchableCheck = babel.template.expression(`

t.variableDeclaration('let', [
t.variableDeclarator(path.node.handler.param, catchParam)
t.variableDeclarator(path.node.handler.param, catchParam),
]),
path.node.handler.body
path.node.handler.body,
]));

@@ -66,9 +68,7 @@ }

catchParam = fallbackCatchParam;
handler = t.catchClause(catchParam, t.blockStatement([
t.throwStatement(catchParam)
]));
handler = t.catchClause(catchParam, t.blockStatement([t.throwStatement(catchParam)]));
}
if (!finalizer) {
path.replaceWith(Object.assign(t.tryStatement(block, t.catchClause(catchParam, t.blockStatement([
t.ifStatement(notUncatchableCheck({ ERR_IDENTIFIER: catchParam }), handler.body, t.throwStatement(catchParam))
t.ifStatement(notUncatchableCheck({ ERR_IDENTIFIER: catchParam }), handler.body, t.throwStatement(catchParam)),
]))), { [isGeneratedTryCatch]: true }));

@@ -80,18 +80,22 @@ }

path.replaceWithMultiple([
t.variableDeclaration('let', [t.variableDeclarator(isCatchable, t.booleanLiteral(true))]),
t.variableDeclaration('let', [
t.variableDeclarator(isCatchable, t.booleanLiteral(true)),
]),
Object.assign(t.tryStatement(block, t.catchClause(catchParam, t.blockStatement([
t.expressionStatement(t.assignmentExpression('=', isCatchable, notUncatchableCheck({ ERR_IDENTIFIER: catchParam }))),
t.ifStatement(isCatchable, Object.assign(t.tryStatement(handler.body, t.catchClause(exceptionFromCatchIdentifier, t.blockStatement([
t.expressionStatement(t.assignmentExpression('=', isCatchable, notUncatchableCheck({ ERR_IDENTIFIER: exceptionFromCatchIdentifier }))),
t.throwStatement(exceptionFromCatchIdentifier)
]))), { [isGeneratedTryCatch]: true }), t.throwStatement(catchParam))
t.expressionStatement(t.assignmentExpression('=', isCatchable, notUncatchableCheck({
ERR_IDENTIFIER: exceptionFromCatchIdentifier,
}))),
t.throwStatement(exceptionFromCatchIdentifier),
]))), { [isGeneratedTryCatch]: true }), t.throwStatement(catchParam)),
])), t.blockStatement([
t.ifStatement(isCatchable, finalizer)
])), { [isGeneratedTryCatch]: true })
t.ifStatement(isCatchable, finalizer),
])), { [isGeneratedTryCatch]: true }),
]);
}
}
}
},
},
};
};
//# sourceMappingURL=uncatchable-exceptions.js.map

@@ -1,4 +0,4 @@

import * as babel from '@babel/core';
import * as BabelTypes from '@babel/types';
declare type WrapState = {
import type * as babel from '@babel/core';
import type * as BabelTypes from '@babel/types';
type WrapState = {
movedStatements: babel.types.Statement[];

@@ -11,5 +11,5 @@ functionDeclarations: babel.types.FunctionDeclaration[];

};
declare const _default: ({ types: t }: {
declare const _default: ({ types: t, }: {
types: typeof BabelTypes;
}) => babel.PluginObj<WrapState>;
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ({ types: t }) => {
exports.default = ({ types: t, }) => {
return {

@@ -24,3 +24,5 @@ pre() {

const expr = t.assignmentExpression('=', decl.id, decl.init);
asAssignments.push(t.variableDeclaration('const', [t.variableDeclarator(path.scope.generateUidIdentifier('v'), expr)]));
asAssignments.push(t.variableDeclaration('const', [
t.variableDeclarator(path.scope.generateUidIdentifier('v'), expr),
]));
}

@@ -65,3 +67,6 @@ }

path.replaceWith(t.program([
t.expressionStatement({ ...path.node.directives[0].value, type: 'StringLiteral' })
t.expressionStatement({
...path.node.directives[0].value,
type: 'StringLiteral',
}),
]));

@@ -75,9 +80,13 @@ }

this.completionRecordId = path.scope.generateUidIdentifier('cr');
this.movedStatements.unshift(t.variableDeclaration('var', [t.variableDeclarator(this.completionRecordId)]));
this.movedStatements.unshift(t.variableDeclaration('var', [
t.variableDeclarator(this.completionRecordId),
]));
path.replaceWith(t.program([
...this.variables.map(v => t.variableDeclaration('var', [t.variableDeclarator(t.identifier(v))])),
...this.variables.map((v) => t.variableDeclaration('var', [
t.variableDeclarator(t.identifier(v)),
])),
...this.functionDeclarations,
t.expressionStatement(t.callExpression(t.arrowFunctionExpression([], t.blockStatement(this.movedStatements)), []))
t.expressionStatement(t.callExpression(t.arrowFunctionExpression([], t.blockStatement(this.movedStatements)), [])),
], path.node.directives));
}
},
},

@@ -103,9 +112,9 @@ BlockStatement: {

...path.node.body,
t.returnStatement(this.completionRecordId)
t.returnStatement(this.completionRecordId),
]));
}
}
}
},
},
},
};
};
//# sourceMappingURL=wrap-as-iife.js.map
{
"name": "@mongosh/async-rewriter2",
"version": "1.10.1",
"version": "1.10.2",
"description": "MongoDB Shell Async Rewriter Package",
"main": "./lib/index.js",
"scripts": {
"pretest": "npm run compile-ts",
"pretest": "npm run compile",
"benchmark": "node -r ts-node/register benchmark/index.ts",
"test": "mocha --experimental-vm-modules -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./{src,lib}/**/*.spec.ts\"",
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
"lint": "eslint --report-unused-disable-directives \"./{src,test}/**/*.{js,ts,tsx}\"",
"check": "npm run lint && depcheck --skip-missing=true",
"compile-ts": "node bin/make-runtime-support.js --firstpass && tsc -p tsconfig.json && node bin/make-runtime-support.js --secondpass && tsc -p tsconfig.json",
"prepublish": "npm run compile-ts"
"eslint": "eslint",
"lint": "npm run eslint . && npm run prettier -- --check .",
"check": "npm run lint && npm run depcheck",
"depcheck": "depcheck",
"compile": "node bin/make-runtime-support.js --firstpass && tsc -p tsconfig.json && node bin/make-runtime-support.js --secondpass && tsc -p tsconfig.json",
"prepublish": "npm run compile",
"prettier": "prettier",
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
},

@@ -37,10 +41,18 @@ "bin": {

"dependencies": {
"@babel/core": "7.16.x",
"@babel/plugin-transform-destructuring": "^7.16.7",
"@babel/plugin-transform-parameters": "^7.16.7",
"@babel/plugin-transform-shorthand-properties": "^7.16.7",
"@babel/types": "^7.16.8",
"@types/babel__core": "^7.1.18"
"@babel/core": "^7.22.8",
"@babel/plugin-transform-destructuring": "^7.22.5",
"@babel/plugin-transform-parameters": "^7.22.5",
"@babel/plugin-transform-shorthand-properties": "^7.22.5",
"@babel/types": "^7.22.5",
"@types/babel__core": "^7.20.1"
},
"gitHead": "05ad91b4dd40382a13f27abe1ae8c3f9f52a38f7"
"devDependencies": {
"@mongodb-js/eslint-config-mongosh": "1.10.2",
"@mongodb-js/prettier-config-devtools": "^1.0.1",
"@mongodb-js/tsconfig-mongosh": "1.10.2",
"depcheck": "^1.4.3",
"eslint": "^7.25.0",
"prettier": "^2.8.8"
},
"gitHead": "9351a54cc24def10a97fe7f8c7b455c02fdce62e"
}

@@ -43,5 +43,7 @@ # next-gen async-rewriter

```js
function foo() { return db.test.find(); }
function foo() {
return db.test.find();
}
class A {}
foo()
foo();
```

@@ -122,3 +124,4 @@

} catch (innerErr) {
_isCatchable = !innerErr || !innerErr[Symbol.for('@@mongosh.uncatchable')];
_isCatchable =
!innerErr || !innerErr[Symbol.for('@@mongosh.uncatchable')];
throw innerErr;

@@ -163,11 +166,12 @@ }

'<async_rewriter>(() => {\n return db.test.find().toArray();\n})</>';
const _syntheticPromise = Symbol.for("@@mongosh.syntheticPromise");
const _syntheticPromise = Symbol.for('@@mongosh.syntheticPromise');
function _markSyntheticPromise(p) {
return Object.defineProperty(p, _syntheticPromise, {
value: true
value: true,
});
}
function _isp(p) { // '_isSyntheticPromise' would be way too long here
function _isp(p) {
// '_isSyntheticPromise' would be way too long here
return p && p[_syntheticPromise];

@@ -180,5 +184,5 @@ }

let _functionState = "sync",
_synchronousReturnValue,
_ex;
let _functionState = 'sync',
_synchronousReturnValue,
_ex;

@@ -194,20 +198,18 @@ const _asynchronousReturnValue = (async () => {

return (
_synchronousReturnValue = (
(_synchronousReturnValue =
// Most expressions are wrapped in ('original source', _ex = ..., _isp(_ex) ? await _ex : _ex)
_ex = ('db.test.find()',
_ex = ('db.test',
_ex = ('db',
_ex = db, _isp(_ex) ? await _ex : _ex
).test, _isp(_ex) ? await _ex : _ex
).find(), _isp(_ex) ? await _ex : _ex
).toArray()
, _isp(_ex) ? await _ex : _ex
),
_functionState === 'async' ? _synchronousReturnValue : null);
((_ex = ('db.test.find()',
(_ex = ('db.test',
(_ex = ('db', (_ex = db), _isp(_ex) ? await _ex : _ex).test),
_isp(_ex) ? await _ex : _ex).find()),
_isp(_ex) ? await _ex : _ex).toArray()),
_isp(_ex) ? await _ex : _ex)),
_functionState === 'async' ? _synchronousReturnValue : null
);
} catch (err) {
err = _demangleError(err);
if (_functionState === "sync") {
if (_functionState === 'sync') {
// Forward synchronous exceptions.
_synchronousReturnValue = err;
_functionState = "threw";
_functionState = 'threw';
} else {

@@ -219,4 +221,4 @@ // If we are already asynchronous, just return a rejected Promise as usual.

// If we did not throw here, we returned. Tell the caller that.
if (_functionState !== "threw") {
_functionState = "returned";
if (_functionState !== 'threw') {
_functionState = 'returned';
}

@@ -226,9 +228,9 @@ }

if (_functionState === "returned") {
if (_functionState === 'returned') {
return _synchronousReturnValue;
} else if (_functionState === "threw") {
} else if (_functionState === 'threw') {
throw _synchronousReturnValue;
}
_functionState = "async";
_functionState = 'async';
// Since this was originally a non-async function, mark this as something

@@ -235,0 +237,0 @@ // that should implicitly be awaited.

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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

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