wat4wasm 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,10 +4,10 @@ export const START_BLOCK_NAME = "start";
4
4
 
5
5
  export default function (wat, WAT4WASM) {
6
6
  let startCalls = [];
7
- let removedWat = wat;
8
7
 
9
8
  wat = wat.replaceAll(/\(main(\s+)(\$.[^\s]*)(\s)/g, `(start$1$2)\n\n(func$1$2$3`)
10
9
 
10
+ let removedWat = wat;
11
11
  while (helpers.hasBlock(removedWat, START_BLOCK_NAME)) {
12
12
  let block = helpers.lastBlockOf(removedWat, START_BLOCK_NAME);
13
13
  removedWat = block.removedRaw();
@@ -59,12 +59,13 @@ const TEXT_ONINIT_BLOCK = (offset, length, setter) => String(
59
59
  )
60
60
  `).trim();
61
61
 
62
- const extern = new Set();
63
62
 
64
- export default function (wat, WAT4WASM) {
63
+ function replaceAllText(wat, WAT4WASM) {
65
64
 
65
+ const extern = new Set();
66
66
  const maskSet = new helpers.MaskSet(wat);
67
67
  const textBlocks = new Array();
68
+ const textGetters = new Map();
68
69
 
69
70
  while (maskSet.hasBlock(TEXT_BLOCK_NAME)) {
70
71
  let block = maskSet.lastBlockOf(TEXT_BLOCK_NAME);
@@ -89,6 +90,8 @@ export default function (wat, WAT4WASM) {
89
90
  block.isExtended = true;
90
91
 
91
92
  wat = dataRequest.modifiedRaw;
93
+
94
+ textGetters.set(block.uuid, text)
92
95
  }
93
96
  else {
94
97
  block.isExtended = false;
@@ -105,13 +108,10 @@ export default function (wat, WAT4WASM) {
105
108
  (local.get $arguments) ;; ${block.strPreview}
106
109
  )`).trim();
107
110
 
111
+ textGetters.set(textGetters.get(block.uuid), block.tableGetter)
108
112
  wat = growRequest.modifiedRaw;
109
113
  });
110
114
 
111
- textBlocks.filter(block => block.isExtended).forEach(block => {
112
- wat = wat.replaceAll(block.toString(), block.tableGetter);
113
- });
114
-
115
115
  const oninit = textBlocks.filter(block => block.isExtended).map(block =>
116
116
  TEXT_ONINIT_BLOCK(
117
117
  block.dataOffset,
@@ -123,5 +123,23 @@ export default function (wat, WAT4WASM) {
123
123
  wat = APPEND_ON_INIT(wat, oninit);
124
124
  }
125
125
 
126
+ while (helpers.hasBlock(wat, "text")) {
127
+ const block = helpers.lastBlockOf(wat, "text");
128
+ const text = helpers.findQuotedText(block);
129
+ const getter = textGetters.get(text);
130
+
131
+ if (getter) {
132
+ wat = block.replacedRaw(getter)
133
+ }
134
+ }
135
+
136
+ return wat;
137
+ }
138
+
139
+ export default function (wat) {
140
+ while (helpers.hasBlock(wat, "text")) {
141
+ wat = replaceAllText(wat);
142
+ }
143
+
126
144
  return wat;
127
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wat4wasm",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/central-network/wat4wasm#readme",
6
6
  "bugs": {
package/wat4wasm CHANGED
@@ -1277,8 +1277,8 @@ function REPLACE_ALL (wat) {
1277
1277
  const START_BLOCK_NAME = "start";
1278
1278
  function START (wat, WAT4WASM) {
1279
1279
  let startCalls = [];
1280
- let removedWat = wat;
1281
1280
  wat = wat.replaceAll(/\(main(\s+)(\$.[^\s]*)(\s)/g, `(start$1$2)\n\n(func$1$2$3`)
1281
+ let removedWat = wat;
1282
1282
  while (helpers.hasBlock(removedWat, START_BLOCK_NAME)) {
1283
1283
  let block = helpers.lastBlockOf(removedWat, START_BLOCK_NAME);
1284
1284
  removedWat = block.removedRaw();
@@ -1406,10 +1406,11 @@ const TEXT_ONINIT_BLOCK = (offset, length, setter) => String(
1406
1406
  ${setter}
1407
1407
  )
1408
1408
  `).trim();
1409
- const extern = new Set();
1410
- function TEXT (wat, WAT4WASM) {
1409
+ function replaceAllText(wat, WAT4WASM) {
1410
+ const extern = new Set();
1411
1411
  const maskSet = new helpers.MaskSet(wat);
1412
1412
  const textBlocks = new Array();
1413
+ const textGetters = new Map();
1413
1414
  while (maskSet.hasBlock(TEXT_BLOCK_NAME)) {
1414
1415
  let block = maskSet.lastBlockOf(TEXT_BLOCK_NAME);
1415
1416
  maskSet.mask(block);
@@ -1428,6 +1429,7 @@ function TEXT (wat, WAT4WASM) {
1428
1429
  block.strContent = text;
1429
1430
  block.isExtended = true;
1430
1431
  wat = dataRequest.modifiedRaw;
1432
+ textGetters.set(block.uuid, text)
1431
1433
  }
1432
1434
  else {
1433
1435
  block.isExtended = false;
@@ -1442,11 +1444,9 @@ function TEXT (wat, WAT4WASM) {
1442
1444
  (local.get $textDecoder)
1443
1445
  (local.get $arguments) ;; ${block.strPreview}
1444
1446
  )`).trim();
1447
+ textGetters.set(textGetters.get(block.uuid), block.tableGetter)
1445
1448
  wat = growRequest.modifiedRaw;
1446
1449
  });
1447
- textBlocks.filter(block => block.isExtended).forEach(block => {
1448
- wat = wat.replaceAll(block.toString(), block.tableGetter);
1449
- });
1450
1450
  const oninit = textBlocks.filter(block => block.isExtended).map(block =>
1451
1451
  TEXT_ONINIT_BLOCK(
1452
1452
  block.dataOffset,
@@ -1456,6 +1456,20 @@ function TEXT (wat, WAT4WASM) {
1456
1456
  if (oninit.trim()) {
1457
1457
  wat = APPEND_ON_INIT(wat, oninit);
1458
1458
  }
1459
+ while (helpers.hasBlock(wat, "text")) {
1460
+ const block = helpers.lastBlockOf(wat, "text");
1461
+ const text = helpers.findQuotedText(block);
1462
+ const getter = textGetters.get(text);
1463
+ if (getter) {
1464
+ wat = block.replacedRaw(getter)
1465
+ }
1466
+ }
1467
+ return wat;
1468
+ }
1469
+ function TEXT (wat) {
1470
+ while (helpers.hasBlock(wat, "text")) {
1471
+ wat = replaceAllText(wat);
1472
+ }
1459
1473
  return wat;
1460
1474
  }
1461
1475