All files / src/codegen/generators memberVars.ts

100% Statements 17/17
100% Branches 9/9
100% Functions 4/4
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x   1x   1x   17x 17x 2x 1x       1x                 32x 1x   46x 17x 6x   17x    
import { Feature } from "../../types";
import { ContractSchema } from "../contractSchema";
import { Generator, ind } from "../generator";
 
export class MemberVarsGen implements Generator {
    gen(schema: ContractSchema): string {
        let members = ``;
        if (schema.hasLiteRef() && schema.liteRefArrayLength(0) === 0) {
            if (schema.features.includes(Feature.DYNAMICREFLIBRARY)) {
                members += `` +
                `mapping(uint256 => PatchworkDynamicRefs.DynamicLiteRefs) internal _dynamicLiterefStorage; // tokenId => indexed slots\n` +
                `\n`;
            } else {
                members += `` +
                `struct DynamicLiteRefs {\n` +
                `    uint256[] slots; // 4 per\n` +
                `    mapping(uint64 => uint256) idx;\n` +
                `}\n\n` +
                `mapping(uint256 => DynamicLiteRefs) internal _dynamicLiterefStorage; // tokenId => indexed slots\n` +
                `\n`;
            }
        }
        if (schema.fields.some((field: any) => field.type === "string")) {
            members += `mapping(uint256 => string) internal _dynamicStringStorage; // tokenId => string\n\n`;
        }
        const hasAnyPatchType = [Feature.PATCH, Feature['1155PATCH'], Feature.ACCOUNTPATCH].some(patch => schema.features.includes(patch));
        if (hasAnyPatchType ||  schema.features.some((feature: Feature) => feature === Feature.MINTABLE)) {
            members += `uint256 internal _nextTokenId;\n\n`;
        }
        return ind(4, members);
    }
}