mol_tree2 1.0.921 → 1.0.923

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.
package/web.mjs CHANGED
@@ -1266,6 +1266,11 @@ var $;
1266
1266
  "use strict";
1267
1267
  var $;
1268
1268
  (function ($) {
1269
+ function is_identifier(tree) {
1270
+ if (tree.type)
1271
+ return false;
1272
+ return /^[a-z_$][a-z_$0-9]*$/i.test(tree.text());
1273
+ }
1269
1274
  function $mol_tree2_js_to_text(js) {
1270
1275
  function sequence(open, separator, close) {
1271
1276
  return (input, belt) => [
@@ -1366,25 +1371,21 @@ var $;
1366
1371
  '{}': block('{', '', '}'),
1367
1372
  '[]': (input, belt) => {
1368
1373
  const first = input.kids[0];
1369
- if (first.type)
1374
+ if (!is_identifier(first))
1370
1375
  return sequence('[', '', ']')(input, belt);
1371
1376
  else
1372
1377
  return [input.data('.' + first.text())];
1373
1378
  },
1374
1379
  '?.[]': (input, belt) => {
1375
1380
  const first = input.kids[0];
1376
- if (first.type)
1381
+ if (!is_identifier(first))
1377
1382
  return sequence('?.[', '', ']')(input, belt);
1378
1383
  else
1379
1384
  return [input.data('?.' + first.text())];
1380
1385
  },
1381
- ':': (input, belt) => {
1382
- const first = input.kids[0];
1383
- if (first.type)
1384
- return duplet('[', ']: ')(input, belt);
1385
- else
1386
- return duplet('', ': ')(input, belt);
1387
- },
1386
+ ':': (input, belt) => input.kids[0].type
1387
+ ? duplet('[', ']: ')(input, belt)
1388
+ : duplet('', ': ')(input, belt),
1388
1389
  'let': duplet('let ', ' = '),
1389
1390
  'const': duplet('const ', ' = '),
1390
1391
  'var': duplet('var ', ' = '),
@@ -1415,7 +1416,7 @@ var $;
1415
1416
  '?:': triplet('', ' ? ', ' : '),
1416
1417
  '.': (input, belt) => {
1417
1418
  const first = input.kids[0];
1418
- if (first.type)
1419
+ if (!is_identifier(first))
1419
1420
  return triplet('[', ']')(input, belt);
1420
1421
  else
1421
1422
  return [