@mongosh/async-rewriter2
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -6,4 +6,4 @@ import * as babel from '@babel/core'; | ||
}) => babel.PluginObj<{ | ||
file: babel.types.File; | ||
file: babel.BabelFile; | ||
}>; | ||
export default _default; |
@@ -121,3 +121,3 @@ "use strict"; | ||
BlockStatement(path) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
if (!path.parentPath.isFunction()) | ||
@@ -132,16 +132,16 @@ return; | ||
const originalSource = path.parent.start !== undefined ? | ||
this.file.code.slice(path.parent.start, path.parent.end) : | ||
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 = [...originalSource].map(char => char.charCodeAt(0).toString(16).padStart(4, '0')).join(''); | ||
const originalSourceNode = t.expressionStatement(t.stringLiteral(`<async_rewriter>${encodedOriginalSource}</>`)); | ||
const existingIdentifiers = (_a = path.findParent(path => !!path.getData(identifierGroupKey))) === null || _a === void 0 ? void 0 : _a.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'); | ||
const synchronousReturnValue = path.scope.generateUidIdentifier('srv'); | ||
const asynchronousReturnValue = path.scope.generateUidIdentifier('arv'); | ||
const expressionHolder = (_b = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.expressionHolder) !== null && _b !== void 0 ? _b : path.scope.generateUidIdentifier('ex'); | ||
const markSyntheticPromise = (_c = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.markSyntheticPromise) !== null && _c !== void 0 ? _c : path.scope.generateUidIdentifier('msp'); | ||
const isSyntheticPromise = (_d = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.isSyntheticPromise) !== null && _d !== void 0 ? _d : path.scope.generateUidIdentifier('isp'); | ||
const assertNotSyntheticPromise = (_e = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.assertNotSyntheticPromise) !== null && _e !== void 0 ? _e : path.scope.generateUidIdentifier('ansp'); | ||
const syntheticPromiseSymbol = (_f = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.syntheticPromiseSymbol) !== null && _f !== void 0 ? _f : path.scope.generateUidIdentifier('sp'); | ||
const demangleError = (_g = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.demangleError) !== null && _g !== void 0 ? _g : path.scope.generateUidIdentifier('de'); | ||
const expressionHolder = (_d = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.expressionHolder) !== null && _d !== void 0 ? _d : path.scope.generateUidIdentifier('ex'); | ||
const markSyntheticPromise = (_e = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.markSyntheticPromise) !== null && _e !== void 0 ? _e : path.scope.generateUidIdentifier('msp'); | ||
const isSyntheticPromise = (_f = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.isSyntheticPromise) !== null && _f !== void 0 ? _f : path.scope.generateUidIdentifier('isp'); | ||
const assertNotSyntheticPromise = (_g = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.assertNotSyntheticPromise) !== null && _g !== void 0 ? _g : path.scope.generateUidIdentifier('ansp'); | ||
const syntheticPromiseSymbol = (_h = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.syntheticPromiseSymbol) !== null && _h !== void 0 ? _h : path.scope.generateUidIdentifier('sp'); | ||
const demangleError = (_j = existingIdentifiers === null || existingIdentifiers === void 0 ? void 0 : existingIdentifiers.demangleError) !== null && _j !== void 0 ? _j : path.scope.generateUidIdentifier('de'); | ||
const identifiersGroup = { | ||
@@ -186,3 +186,3 @@ functionState, | ||
SP_IDENTIFIER: syntheticPromiseSymbol, | ||
CUSTOM_ERROR_BUILDER: (_h = this.opts.customErrorBuilder) !== null && _h !== void 0 ? _h : t.identifier('Error') | ||
CUSTOM_ERROR_BUILDER: (_k = this.opts.customErrorBuilder) !== null && _k !== void 0 ? _k : t.identifier('Error') | ||
}), { [isGeneratedHelper]: true }) | ||
@@ -252,13 +252,18 @@ ]; | ||
exit(path) { | ||
if (!path.getFunctionParent()) | ||
var _a, _b, _c, _d, _e, _f; | ||
const functionParent = path.getFunctionParent(); | ||
if (!functionParent) | ||
return; | ||
if (!path.getFunctionParent().node.async && | ||
!path.getFunctionParent().node[isAlwaysSyncFunction]) | ||
if (!functionParent.node.async && | ||
!functionParent.node[isAlwaysSyncFunction]) | ||
return; | ||
let identifierGroup; | ||
if (path.getFunctionParent().node[isGeneratedInnerFunction]) { | ||
if (!path.findParent(path => path.isFunction() || !!path.node[isOriginalBody]).node[isOriginalBody]) { | ||
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])) { | ||
return; | ||
} | ||
identifierGroup = path.getFunctionParent().getFunctionParent().getData(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]) { | ||
@@ -274,3 +279,3 @@ path.replaceWith(Object.assign(returnValueWrapperTemplate({ | ||
else { | ||
identifierGroup = path.getFunctionParent().getData(identifierGroupKey); | ||
identifierGroup = functionParent.getData(identifierGroupKey); | ||
} | ||
@@ -313,5 +318,5 @@ if (path.parentPath.isCallExpression() && | ||
const prettyOriginalString = limitStringLength(path.node.start !== undefined ? | ||
this.file.code.slice(path.node.start, path.node.end) : | ||
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 (!path.getFunctionParent().node.async) { | ||
if (!functionParent.node.async) { | ||
path.replaceWith(Object.assign(assertNotSyntheticExpressionTemplate({ | ||
@@ -318,0 +323,0 @@ ORIGINAL_SOURCE: t.stringLiteral(prettyOriginalString), |
@@ -22,3 +22,3 @@ "use strict"; | ||
this.variables.push(decl.id.name); | ||
if (decl.init !== null) { | ||
if (decl.init) { | ||
const expr = t.assignmentExpression('=', decl.id, decl.init); | ||
@@ -25,0 +25,0 @@ asAssignments.push(t.variableDeclaration('const', [t.variableDeclarator(path.scope.generateUidIdentifier('v'), expr)])); |
{ | ||
"name": "@mongosh/async-rewriter2", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "MongoDB Shell Async Rewriter Package", | ||
@@ -8,4 +8,4 @@ "main": "./lib/index.js", | ||
"pretest": "npm run compile-ts", | ||
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 --colors -r ts-node/register \"./{src,lib}/**/*.spec.ts\"", | ||
"test-ci": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./{src,lib}/**/*.spec.ts\"", | ||
"test": "mocha -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}\"", | ||
@@ -30,11 +30,14 @@ "check": "npm run lint && depcheck --skip-missing=true", | ||
}, | ||
"mongosh": { | ||
"unitTestsOnly": true | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/plugin-transform-destructuring": "^7.13.0", | ||
"@babel/plugin-transform-parameters": "^7.13.0", | ||
"@babel/plugin-transform-shorthand-properties": "^7.12.13", | ||
"@babel/types": "^7.9.0", | ||
"@types/babel__core": "^7.1.6" | ||
"@babel/core": "^7.14.8", | ||
"@babel/plugin-transform-destructuring": "^7.14.7", | ||
"@babel/plugin-transform-parameters": "^7.14.5", | ||
"@babel/plugin-transform-shorthand-properties": "^7.14.5", | ||
"@babel/types": "^7.14.8", | ||
"@types/babel__core": "^7.1.15" | ||
}, | ||
"gitHead": "fb1691775754ab5b9018acdb4831b423ee3d77e6" | ||
"gitHead": "248a6f4c1c92ad432a8dc7d078600c6b86f03335" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94109
993