From e342791423ec2fcc1d0dea95f391db6490e7c1ee Mon Sep 17 00:00:00 2001 From: David Terry Date: Fri, 10 Apr 2020 13:19:06 +0200 Subject: [PATCH] lib/build.js: rm special formatting for storage blocks Removes all special formatting for storage blocks. This was interacting badly with the multiline storage conditions that are commonly used in k-uniswap. Readable formatting for storage blocks is now the responsibility of the spec author. --- lib/build.js | 64 ---------------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/lib/build.js b/lib/build.js index ea000494..7dd3636e 100644 --- a/lib/build.js +++ b/lib/build.js @@ -30,71 +30,7 @@ const BIG_GAS = 3000000; const h = n => s => `<${Array.isArray(n) ? n.join(' ') : n}>${Array.isArray(s) && s.join('') || s}` const newCleanup = (act, text) => { - let storages_blocks = Object - .keys(act.storage || {}) - .map(subjectName => { - // TODO - export this one level higher - all storages - let isCreate = act.creates[subjectName]; - let max_key_length = Object - .keys(act.storage[subjectName]) - .map(key => key.length) - .reduce((a, l) => Math.max(a, l), 0); - let max_lhs_length = Object - .keys(act.storage[subjectName]) - .map(key => act.storage[subjectName][key][0].length) - .reduce((a, l) => Math.max(a, l), 0); - let storage = Object - .keys(act.storage[subjectName]) - .map(key => { - let rewrites = act.storage[subjectName][key]; - const key_ = /^(\d|\#)/.test(key) ? key : `#${subjectName == "ACCT_ID" ? act.subject : subjectName}.${key}` - const def = getStorageDef(key_); - if(!def && false) { - warn(`Storage key ${key_} in ${act.subject}.${act.name} not declared!`) - } - rewrites[0] = rewrites[0] + " ".repeat(max_lhs_length - rewrites[0].length) - let storage_str = " " - + key - + " ".repeat(max_key_length - key.length) - + " |-> " - + (isCreate ? rewrites[0] : rewrites.join(" => ")) - let comment_str = def && def.doc(key_) && (" // " + def.doc(key_) + "\n") || "" - return comment_str + storage_str; - }) - .join("\n") - - // Return the storage block header + body - // - append the contract name to the header when referencing external contracts - // - preserve the creates header when present - let prefix = isCreate ? "creates storage" : "storage" - let header = prefix + (subjectName !== "ACCT_ID" ? " " + subjectName : ""); - return header + "\n\n" + storage + "\n"; - }) - .join("\n\n") - const code_ = text - .split(/\n/) - .reduce(({isStorage, display}, line) => { - const isStorageBlock = (/^storage$/).test(line); - const isOtherStorageBlock = (/^(storage|creates storage)\s+\w/).test(line); - const isBlock = (/^\w/).test(line); - const isStorage_ = isStorageBlock || isOtherStorageBlock || (isStorage && !isBlock); - - return { - isStorage: isStorage_, - display: display - .concat( - isStorage_ && !isStorageBlock - ? [] - : isStorageBlock && storages_blocks || line - ) - }; - }, { - isStorage: false, - display: [] - }) - .display - .join("\n") .replace(/\/\/ doc:/g, "//") .replace(/\/\/ act:/g, "//") .replace(/\/\/(.*)\n/gm, (_1, _2, l) => `//${_2}\n`)