From 8d84ebc246fcec81a4050d41960f0b45e25e8f46 Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Thu, 13 Feb 2025 19:12:23 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A2=EF=B8=8F=20Refine=20client=20jsx?= =?UTF-8?q?=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crosschain/unlockable.d.js | 2 ++ kastro/transpiler/jsx.js | 26 +++++++++++++++++++------- node/ipfs.js | 36 ++++++++++++++++++------------------ node/test/ipfs.test.js | 26 ++++++++++++-------------- util/dom.js | 9 ++++++++- 5 files changed, 59 insertions(+), 40 deletions(-) diff --git a/crosschain/unlockable.d.js b/crosschain/unlockable.d.js index 7fafd2e..6ed187a 100644 --- a/crosschain/unlockable.d.js +++ b/crosschain/unlockable.d.js @@ -24,3 +24,5 @@ crosschain.Unlockable = function () { } /** @type {string} */ crosschain.Unlockable.prototype.userPrompt; + +export default crosschain; \ No newline at end of file diff --git a/kastro/transpiler/jsx.js b/kastro/transpiler/jsx.js index 77cf1d4..66f174a 100644 --- a/kastro/transpiler/jsx.js +++ b/kastro/transpiler/jsx.js @@ -121,14 +121,17 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { if (elem.openingElement) { /** @const {string} */ const tagName = getJsxTagName(elem); - if (tagName.charCodeAt(0) < 91 && !assetComponents.has(tagName)) { + if (assetComponents.has(tagName)) return 0; + if (tagName.charCodeAt(0) < 91) { const info = specifierInfo[tagName]; if (info && info.state == SpecifierState.Remove) info.state = SpecifierState.PinRemove; + if (styleSheetComponents.has(tagName)) return 0; const props = {}; let keepImport = false; let instance = null; + let hasOptionalProps = false; for (const attr of elem.openingElement.attributes) { if (attr.type !== 'JSXAttribute') continue; const name = attr.name.name; @@ -145,6 +148,8 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { instance = content.slice(attr.value.start + 1, attr.value.end - 1); } else if (!name.endsWith("$")) props[name] = attr.value; + else + hasOptionalProps = true; } if ((tagName in specifierInfo || localComponents.has(tagName)) && !styleSheetComponents.has(tagName)) { keepImport = true; @@ -160,7 +165,7 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { traverse(v.expression, null); return content.slice(v.start + 1, v.end - 1); } - const callParams = Object.keys(props).length + const callParams = (Object.keys(props).length || hasOptionalProps) ? `{\n ${Object.entries(props).map(([k, v]) => `${k}: ${serialize(v)}`).join(",\n ")}\n }` : ""; const call = `${tagName}(${callParams})`; @@ -173,6 +178,7 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { for (const attr of elem.openingElement.attributes) { const name = attr.name.name; if (name.startsWith("on") && name.charCodeAt(2) < 91) { + traverse(attr.value.expression, attr.value); const value = content.slice(attr.value.start + 1, attr.value.end - 1); const element = `${getJsxTagName(parent)}.children[${childIndex}]`; statements.push(`${element}.${name.toLowerCase()} = ${value}`); @@ -189,11 +195,14 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { return 1; } - const processInlineCss = (node) => { - if (node.tag.type != "Identifier" || node.tag.name != "css") return; + const processInlineCss = (node, parent) => { /** @const {string} */ const strippedCss = content.slice(node.start + 4, node.end - 1) .replace(/\$\{[^}]*\}/g, "a"); // Template literals cannot be exported identifiers, simply replace them with a placeholder + + if (parent.type == "VariableDeclarator" && parent.id.type == "Identifier") + styleSheetComponents.add(parent.id.name); + updates.push({ beg: node.start, end: node.end, @@ -213,8 +222,10 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { if (!isPropertyName && !isDestructured) specifierInfo[node.name].state = SpecifierState.Keep; } else if (node.type === "TaggedTemplateExpression") { - processInlineCss(node); - return; + if (node.tag.type == "Identifier" && node.tag.name == "css") { + processInlineCss(node, parent); + return; + } } else if (node.type === "JSXElement" || node.type === "JSXFragment") { const statements = []; processJsxElement(node, parent, 0, statements); @@ -303,7 +314,8 @@ const transpile = (isEntry, file, content, domIdMapper, globals) => { /** @const {!Array} */ const identifiers = block.match(IdentPattern) || []; for (const ident of identifiers) { - const info = specifierInfo[ident]; + const rootIdent = ident.split('.')[0]; + const info = specifierInfo[rootIdent]; if (info) info.state = SpecifierState.Keep; } } diff --git a/node/ipfs.js b/node/ipfs.js index faf1f73..512d817 100644 --- a/node/ipfs.js +++ b/node/ipfs.js @@ -71,48 +71,48 @@ const CID = (hash) => { * @param {!Uint8Array} cidByte * @return {!Promise} */ -const cidBytetanOku = (nodeUrl, cidByte) => { +const readWithCIDBytes = (nodeUrl, cidByte) => { /** @const {string} */ - const yerelCID = CID(cidByte); - return fetch(nodeUrl + "/ipfs/" + yerelCID) + const localCID = CID(cidByte); + return fetch(nodeUrl + "/ipfs/" + localCID) .then((res) => res.arrayBuffer()) .then((/** @type {!ArrayBuffer} */ buf) => hash(new Uint8Array(buf)) - .then((gelenByte) => CID(gelenByte) === yerelCID + .then((gelenByte) => CID(gelenByte) === localCID ? new TextDecoder().decode(buf) - : Promise.reject("IPFS hash'i tutmadı")) + : Promise.reject("IPFS hash mismatch")) ); } /** * @param {string} nodeUrl - * @param {string} veri IPFS'e yazılacak veri. - * @param {string} veriŞekli Yazılacak verinin şekli, mimetype standardında - * @return {!Promise} onaylanmış IPFS cidByte. + * @param {string} data Data to be written to IPFS. + * @param {string} dataType Mime type of the data. + * @return {!Promise} Validated IPFS cidByte's of the data. */ -const yaz = (nodeUrl, veri, veriŞekli) => { +const write = (nodeUrl, data, dataType) => { /** @const {!Uint8Array} */ - const encoded = new TextEncoder().encode(veri); + const encoded = new TextEncoder().encode(data); /** @const {!FormData} */ const formData = new FormData() - formData.set("blob", new Blob([encoded], { type: veriŞekli })); + formData.set("blob", new Blob([encoded], { type: dataType })); /** @const {!Promise} */ - const gelenSöz = fetch(nodeUrl + "/api/v0/add", { + const remoteHashPromise = fetch(nodeUrl + "/api/v0/add", { method: "POST", body: formData }) .then((res) => res.json()) .then((/** @type {node.ipfs.AddResult} */ res) => res.Hash) - return Promise.all([hash(encoded), gelenSöz]) - .then(([/** !Uint8Array */ yerel, /** string */ gelen]) => CID(yerel) == gelen - ? yerel - : Promise.reject(`IPFS'ten farklı sonuç döndü. Yerel: ${CID(yerel)}, Gelen: ${gelen}`) + return Promise.all([hash(encoded), remoteHashPromise]) + .then(([/** !Uint8Array */ local, /** string */ remote]) => CID(local) == remote + ? local + : Promise.reject(`IPFS hash mismatch. Local: ${CID(local)}, Remote: ${remote}`) ) } export default { CID, - cidBytetanOku, + readWithCIDBytes, hash, - yaz, + write, }; diff --git a/node/test/ipfs.test.js b/node/test/ipfs.test.js index 9f066f3..b27b2ec 100644 --- a/node/test/ipfs.test.js +++ b/node/test/ipfs.test.js @@ -5,18 +5,16 @@ test("CID test", () => { /** @const {!TextEncoder} */ const encoder = new TextEncoder(); - return Promise.all([ - ipfs.hash(encoder.encode("a".repeat(2680))) - .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) - .toBe("Qmawd3DRAY5YwtCzQe8gBumMXA1JCrzvbH2WQR6ZTykVoG")), - ipfs.hash(encoder.encode("KimlikDAO\n")) - .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) - .toBe("QmafCiqeYQtiXokAEUB4ToMcZJREhJcShbzvjrYmC1WCsi")), - ipfs.hash(encoder.encode("foo\n")) - .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) - .toBe("QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6")), - ipfs.hash(encoder.encode("a".repeat(31337))) - .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) - .toBe("Qmbq6rxwg5uKYAEhdFvPnBqzbJWAPfhB4LwF4yGamvzWSR")), - ]).then((_) => { }); + ipfs.hash(encoder.encode("a".repeat(2680))) + .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) + .toBe("Qmawd3DRAY5YwtCzQe8gBumMXA1JCrzvbH2WQR6ZTykVoG")); + ipfs.hash(encoder.encode("KimlikDAO\n")) + .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) + .toBe("QmafCiqeYQtiXokAEUB4ToMcZJREhJcShbzvjrYmC1WCsi")); + ipfs.hash(encoder.encode("foo\n")) + .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) + .toBe("QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6")); + ipfs.hash(encoder.encode("a".repeat(31337))) + .then((/** @type {!Uint8Array} */ hash) => expect(ipfs.CID(hash)) + .toBe("Qmbq6rxwg5uKYAEhdFvPnBqzbJWAPfhB4LwF4yGamvzWSR")); }); diff --git a/util/dom.js b/util/dom.js index 1d87c1d..002aee5 100644 --- a/util/dom.js +++ b/util/dom.js @@ -4,7 +4,7 @@ import { LangCode } from "./i18n"; const GEN = true; /** @define {LangCode} */ -const Lang = LangCode.TR; +const Lang = LangCode.EN; /** * @nosideeffects @@ -59,6 +59,12 @@ const gösterGizle = (birim, göster) => birim.style.display = göster ? "" : "n */ const adlaGizle = (ad) => adla(ad).style.display = "none"; +/** + * @noinline + * @param {string} ad + */ +const hideById = adlaGizle; + /** * @noinline * @param {string} ad @@ -262,6 +268,7 @@ export default { gösterGizle, show, hide, + hideById, // Widgets bindDropdown, düğmeDurdur,