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/node.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 [
package/node.test.js CHANGED
@@ -1257,6 +1257,11 @@ var $;
1257
1257
  "use strict";
1258
1258
  var $;
1259
1259
  (function ($) {
1260
+ function is_identifier(tree) {
1261
+ if (tree.type)
1262
+ return false;
1263
+ return /^[a-z_$][a-z_$0-9]*$/i.test(tree.text());
1264
+ }
1260
1265
  function $mol_tree2_js_to_text(js) {
1261
1266
  function sequence(open, separator, close) {
1262
1267
  return (input, belt) => [
@@ -1357,25 +1362,21 @@ var $;
1357
1362
  '{}': block('{', '', '}'),
1358
1363
  '[]': (input, belt) => {
1359
1364
  const first = input.kids[0];
1360
- if (first.type)
1365
+ if (!is_identifier(first))
1361
1366
  return sequence('[', '', ']')(input, belt);
1362
1367
  else
1363
1368
  return [input.data('.' + first.text())];
1364
1369
  },
1365
1370
  '?.[]': (input, belt) => {
1366
1371
  const first = input.kids[0];
1367
- if (first.type)
1372
+ if (!is_identifier(first))
1368
1373
  return sequence('?.[', '', ']')(input, belt);
1369
1374
  else
1370
1375
  return [input.data('?.' + first.text())];
1371
1376
  },
1372
- ':': (input, belt) => {
1373
- const first = input.kids[0];
1374
- if (first.type)
1375
- return duplet('[', ']: ')(input, belt);
1376
- else
1377
- return duplet('', ': ')(input, belt);
1378
- },
1377
+ ':': (input, belt) => input.kids[0].type
1378
+ ? duplet('[', ']: ')(input, belt)
1379
+ : duplet('', ': ')(input, belt),
1379
1380
  'let': duplet('let ', ' = '),
1380
1381
  'const': duplet('const ', ' = '),
1381
1382
  'var': duplet('var ', ' = '),
@@ -1406,7 +1407,7 @@ var $;
1406
1407
  '?:': triplet('', ' ? ', ' : '),
1407
1408
  '.': (input, belt) => {
1408
1409
  const first = input.kids[0];
1409
- if (first.type)
1410
+ if (!is_identifier(first))
1410
1411
  return triplet('[', ']')(input, belt);
1411
1412
  else
1412
1413
  return [