UNPKG

dependency-injection-cat

Version:

DI Cat is a truly clean DI-container, which allows you not to pollute your business logic with decorators from DI/IOC libraries!

43 lines (42 loc) 2.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getContextNameFromContainerCall = void 0; var typescript_1 = __importDefault(require("typescript")); var CompilationContext_1 = require("../../../compilation-context/CompilationContext"); var removeQuotesFromString_1 = require("../../utils/removeQuotesFromString"); var getContextNameFromContainerCall = function (node) { var _a, _b; var firstArg = (_a = node.arguments[0]) !== null && _a !== void 0 ? _a : null; if (firstArg && !typescript_1.default.isObjectLiteralExpression(firstArg)) { CompilationContext_1.CompilationContext.reportError({ node: node, message: 'First argument in container access should be an object literal', filePath: node.getSourceFile().fileName, }); return null; } var contextNameProperty = (_b = firstArg.properties .filter(typescript_1.default.isPropertyAssignment) .find(function (it) { var _a; return ((_a = it.name) === null || _a === void 0 ? void 0 : _a.getText()) === 'name'; })) !== null && _b !== void 0 ? _b : null; if (contextNameProperty === null) { CompilationContext_1.CompilationContext.reportError({ node: node, message: 'You should pass "name" property to the container access props', filePath: node.getSourceFile().fileName, }); return null; } if (!typescript_1.default.isStringLiteral(contextNameProperty.initializer)) { CompilationContext_1.CompilationContext.reportError({ node: node, message: 'Property "name" in container access props should be a string literal', filePath: node.getSourceFile().fileName, }); return null; } return (0, removeQuotesFromString_1.removeQuotesFromString)(contextNameProperty.initializer.getText()); }; exports.getContextNameFromContainerCall = getContextNameFromContainerCall;