@nudojs/parser 1.1.2 → 1.1.4

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.
Files changed (2) hide show
  1. package/dist/index.js +96 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -343,37 +343,105 @@ function parseObjectLiteral(content) {
343
343
  }
344
344
  return absExact({ k: "obj", slots });
345
345
  }
346
+ function scanWithStrings(s, onChar, onStructural) {
347
+ let depth = 0;
348
+ let inString = null;
349
+ for (let i = 0; i < s.length; i++) {
350
+ const ch = s[i];
351
+ if (inString) {
352
+ onChar(ch, i);
353
+ if (ch === "\\") {
354
+ i++;
355
+ if (i < s.length) onChar(s[i], i);
356
+ continue;
357
+ }
358
+ if (ch === inString) inString = null;
359
+ continue;
360
+ }
361
+ if (ch === '"' || ch === "'") {
362
+ inString = ch;
363
+ onChar(ch, i);
364
+ continue;
365
+ }
366
+ if (ch === "(" || ch === "[" || ch === "{") {
367
+ depth++;
368
+ onChar(ch, i);
369
+ onStructural(ch, i, depth);
370
+ continue;
371
+ }
372
+ if (ch === ")" || ch === "]" || ch === "}") {
373
+ depth--;
374
+ onChar(ch, i);
375
+ onStructural(ch, i, depth);
376
+ continue;
377
+ }
378
+ onChar(ch, i);
379
+ onStructural(ch, i, depth);
380
+ }
381
+ }
346
382
  function splitTopLevelArgs(s) {
347
383
  const result = [];
348
- let depth = 0;
349
384
  let current = "";
350
- for (const ch of s) {
385
+ let depth = 0;
386
+ let inString = null;
387
+ for (let i = 0; i < s.length; i++) {
388
+ const ch = s[i];
389
+ if (inString) {
390
+ current += ch;
391
+ if (ch === "\\") {
392
+ i++;
393
+ if (i < s.length) current += s[i];
394
+ continue;
395
+ }
396
+ if (ch === inString) inString = null;
397
+ continue;
398
+ }
399
+ if (ch === '"' || ch === "'") {
400
+ inString = ch;
401
+ current += ch;
402
+ continue;
403
+ }
351
404
  if (ch === "(" || ch === "[" || ch === "{") depth++;
352
405
  if (ch === ")" || ch === "]" || ch === "}") depth--;
353
406
  if (ch === "," && depth === 0) {
354
407
  result.push(current.trim());
355
408
  current = "";
356
- } else {
357
- current += ch;
409
+ continue;
358
410
  }
411
+ current += ch;
359
412
  }
360
413
  if (current.trim()) result.push(current.trim());
361
414
  return result;
362
415
  }
363
416
  function findTopLevelColon(s) {
364
- let depth = 0;
365
- for (let i = 0; i < s.length; i++) {
366
- const ch = s[i];
367
- if (ch === "(" || ch === "[" || ch === "{") depth++;
368
- if (ch === ")" || ch === "]" || ch === "}") depth--;
369
- if (ch === ":" && depth === 0) return i;
370
- }
371
- return -1;
417
+ let found = -1;
418
+ scanWithStrings(
419
+ s,
420
+ () => {
421
+ },
422
+ (ch, i, depth) => {
423
+ if (found === -1 && ch === ":" && depth === 0) found = i;
424
+ }
425
+ );
426
+ return found;
372
427
  }
373
428
  function findTopLevelArrow(s) {
374
429
  let depth = 0;
430
+ let inString = null;
375
431
  for (let i = 0; i < s.length - 1; i++) {
376
432
  const ch = s[i];
433
+ if (inString) {
434
+ if (ch === "\\") {
435
+ i++;
436
+ continue;
437
+ }
438
+ if (ch === inString) inString = null;
439
+ continue;
440
+ }
441
+ if (ch === '"' || ch === "'") {
442
+ inString = ch;
443
+ continue;
444
+ }
377
445
  if (ch === "(" || ch === "[" || ch === "{") depth++;
378
446
  else if (ch === ")" || ch === "]" || ch === "}") depth--;
379
447
  else if (depth === 0 && ch === "=" && s[i + 1] === ">") return i;
@@ -383,9 +451,23 @@ function findTopLevelArrow(s) {
383
451
  function extractBalancedParens(text, startIdx) {
384
452
  if (text[startIdx] !== "(") return null;
385
453
  let depth = 0;
454
+ let inString = null;
386
455
  for (let i = startIdx; i < text.length; i++) {
387
- if (text[i] === "(") depth++;
388
- if (text[i] === ")") depth--;
456
+ const ch = text[i];
457
+ if (inString) {
458
+ if (ch === "\\") {
459
+ i++;
460
+ continue;
461
+ }
462
+ if (ch === inString) inString = null;
463
+ continue;
464
+ }
465
+ if (ch === '"' || ch === "'") {
466
+ inString = ch;
467
+ continue;
468
+ }
469
+ if (ch === "(") depth++;
470
+ if (ch === ")") depth--;
389
471
  if (depth === 0) return text.slice(startIdx + 1, i);
390
472
  }
391
473
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/parser",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -39,7 +39,7 @@
39
39
  "registry": "https://registry.npmjs.org"
40
40
  },
41
41
  "dependencies": {
42
- "@nudojs/core": "1.1.2",
42
+ "@nudojs/core": "1.1.4",
43
43
  "@babel/types": "^8.0.6"
44
44
  },
45
45
  "scripts": {