UNPKG

2.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const types_1 = require("@babel/types");
4const types_2 = require("./types");
5const lodash_1 = require("lodash");
6const paths_1 = require("./paths");
7const compact_1 = require("./compact");
8const rawStringIdentifier = (fragmentOrOperationName) => types_1.identifier(lodash_1.camelCase(fragmentOrOperationName + "RawString"));
9const importDeclarationWithIdentifier = (identifier, source) => types_1.importDeclaration([types_1.importDefaultSpecifier(identifier)], types_1.stringLiteral(source));
10const rawStringImportDeclaration = (fragmentOrOperationName, source) => importDeclarationWithIdentifier(rawStringIdentifier(fragmentOrOperationName), source);
11const stringImportDeclaration = (fragmentOrOperationName, source) => importDeclarationWithIdentifier(types_2.stringIdentifier(fragmentOrOperationName), source);
12const joinedStringDeclaration = (fragmentOrOperationName, fragmentDependencies) => types_1.variableDeclaration("const", [
13 types_1.variableDeclarator(types_2.stringIdentifier(fragmentOrOperationName), types_1.callExpression(types_1.memberExpression(types_1.arrayExpression([
14 rawStringIdentifier(fragmentOrOperationName),
15 ...fragmentDependencies.map(fragment => types_2.stringIdentifier(fragment))
16 ]), types_1.identifier("join")), [types_1.stringLiteral("\n\n")]))
17]);
18const exportedJoinedStringDeclaration = (fragmentOrOperationName, fragmentDependencies) => types_2.exportDeclaration(joinedStringDeclaration(fragmentOrOperationName, fragmentDependencies));
19const exportedStringDeclaration = (fragmentOrOperationName) => types_2.exportDeclaration(types_1.variableDeclaration("const", [
20 types_1.variableDeclarator(types_2.stringIdentifier(fragmentOrOperationName), rawStringIdentifier(fragmentOrOperationName))
21]));
22exports.default = (fragmentOrOperationName, filePath, outputPath, fragmentDependencies, exportStringDeclaration = false) => compact_1.default((fragmentDependencies.length > 0 || exportStringDeclaration
23 ? rawStringImportDeclaration
24 : stringImportDeclaration)(fragmentOrOperationName, paths_1.relativePath(outputPath, filePath)), fragmentDependencies.length > 0
25 ? (exportStringDeclaration
26 ? exportedJoinedStringDeclaration
27 : joinedStringDeclaration)(fragmentOrOperationName, fragmentDependencies)
28 : exportStringDeclaration &&
29 exportedStringDeclaration(fragmentOrOperationName));
30//# sourceMappingURL=stringDeclarations.js.map
\No newline at end of file