@vocab/core 1.2.2 → 1.2.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.
@@ -449,36 +449,36 @@ function extractHasTags(ast) {
449
449
  return icuMessageformatParser.isTagElement(element);
450
450
  });
451
451
  }
452
- function extractParamTypes(ast) {
453
- let params = {};
452
+ function extractParamTypes(ast, currentParams) {
453
+ let params = {
454
+ ...currentParams
455
+ };
454
456
  let vocabTypesImports = new Set();
455
457
  for (const element of ast) {
456
458
  if (icuMessageformatParser.isArgumentElement(element)) {
457
- params[element.value] = 'string';
459
+ if (!(element.value in params)) {
460
+ // Preserve existing types for parameters that we've already parsed
461
+ // This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}`
462
+ params[element.value] = 'string';
463
+ }
458
464
  } else if (icuMessageformatParser.isNumberElement(element)) {
459
465
  params[element.value] = 'number';
460
466
  } else if (icuMessageformatParser.isPluralElement(element)) {
461
467
  params[element.value] = 'number';
462
468
  const children = Object.values(element.options).map(o => o.value);
463
469
  for (const child of children) {
464
- const [subParams, subImports] = extractParamTypes(child);
470
+ const [newParams, subImports] = extractParamTypes(child, params);
465
471
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
466
- params = {
467
- ...params,
468
- ...subParams
469
- };
472
+ params = newParams;
470
473
  }
471
474
  } else if (icuMessageformatParser.isDateElement(element) || icuMessageformatParser.isTimeElement(element)) {
472
475
  params[element.value] = 'Date | number';
473
476
  } else if (icuMessageformatParser.isTagElement(element)) {
474
477
  params[element.value] = 'FormatXMLElementFn<T>';
475
478
  vocabTypesImports.add('FormatXMLElementFn');
476
- const [subParams, subImports] = extractParamTypes(element.children);
479
+ const [newParams, subImports] = extractParamTypes(element.children, params);
477
480
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
478
- params = {
479
- ...params,
480
- ...subParams
481
- };
481
+ params = newParams;
482
482
  } else if (icuMessageformatParser.isSelectElement(element)) {
483
483
  const options = Object.keys(element.options);
484
484
 
@@ -489,12 +489,9 @@ function extractParamTypes(ast) {
489
489
  vocabTypesImports.add('StringWithSuggestions');
490
490
  const children = Object.values(element.options).map(o => o.value);
491
491
  for (const child of children) {
492
- const [subParams, subImports] = extractParamTypes(child);
492
+ const [newParams, subImports] = extractParamTypes(child, params);
493
493
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
494
- params = {
495
- ...params,
496
- ...subParams
497
- };
494
+ params = newParams;
498
495
  }
499
496
  }
500
497
  }
@@ -559,12 +556,9 @@ async function generateRuntime(loadedTranslation) {
559
556
  if (translatedLanguage[key]) {
560
557
  const ast = icuMessageformatParser.parse(translatedLanguage[key].message);
561
558
  hasTags = hasTags || extractHasTags(ast);
562
- const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
559
+ const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
563
560
  imports = new Set([...imports, ...vocabTypesImports]);
564
- params = {
565
- ...params,
566
- ...parsedParams
567
- };
561
+ params = parsedParams;
568
562
  messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
569
563
  }
570
564
  }
@@ -449,36 +449,36 @@ function extractHasTags(ast) {
449
449
  return icuMessageformatParser.isTagElement(element);
450
450
  });
451
451
  }
452
- function extractParamTypes(ast) {
453
- let params = {};
452
+ function extractParamTypes(ast, currentParams) {
453
+ let params = {
454
+ ...currentParams
455
+ };
454
456
  let vocabTypesImports = new Set();
455
457
  for (const element of ast) {
456
458
  if (icuMessageformatParser.isArgumentElement(element)) {
457
- params[element.value] = 'string';
459
+ if (!(element.value in params)) {
460
+ // Preserve existing types for parameters that we've already parsed
461
+ // This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}`
462
+ params[element.value] = 'string';
463
+ }
458
464
  } else if (icuMessageformatParser.isNumberElement(element)) {
459
465
  params[element.value] = 'number';
460
466
  } else if (icuMessageformatParser.isPluralElement(element)) {
461
467
  params[element.value] = 'number';
462
468
  const children = Object.values(element.options).map(o => o.value);
463
469
  for (const child of children) {
464
- const [subParams, subImports] = extractParamTypes(child);
470
+ const [newParams, subImports] = extractParamTypes(child, params);
465
471
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
466
- params = {
467
- ...params,
468
- ...subParams
469
- };
472
+ params = newParams;
470
473
  }
471
474
  } else if (icuMessageformatParser.isDateElement(element) || icuMessageformatParser.isTimeElement(element)) {
472
475
  params[element.value] = 'Date | number';
473
476
  } else if (icuMessageformatParser.isTagElement(element)) {
474
477
  params[element.value] = 'FormatXMLElementFn<T>';
475
478
  vocabTypesImports.add('FormatXMLElementFn');
476
- const [subParams, subImports] = extractParamTypes(element.children);
479
+ const [newParams, subImports] = extractParamTypes(element.children, params);
477
480
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
478
- params = {
479
- ...params,
480
- ...subParams
481
- };
481
+ params = newParams;
482
482
  } else if (icuMessageformatParser.isSelectElement(element)) {
483
483
  const options = Object.keys(element.options);
484
484
 
@@ -489,12 +489,9 @@ function extractParamTypes(ast) {
489
489
  vocabTypesImports.add('StringWithSuggestions');
490
490
  const children = Object.values(element.options).map(o => o.value);
491
491
  for (const child of children) {
492
- const [subParams, subImports] = extractParamTypes(child);
492
+ const [newParams, subImports] = extractParamTypes(child, params);
493
493
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
494
- params = {
495
- ...params,
496
- ...subParams
497
- };
494
+ params = newParams;
498
495
  }
499
496
  }
500
497
  }
@@ -559,12 +556,9 @@ async function generateRuntime(loadedTranslation) {
559
556
  if (translatedLanguage[key]) {
560
557
  const ast = icuMessageformatParser.parse(translatedLanguage[key].message);
561
558
  hasTags = hasTags || extractHasTags(ast);
562
- const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
559
+ const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
563
560
  imports = new Set([...imports, ...vocabTypesImports]);
564
- params = {
565
- ...params,
566
- ...parsedParams
567
- };
561
+ params = parsedParams;
568
562
  messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
569
563
  }
570
564
  }
@@ -433,36 +433,36 @@ function extractHasTags(ast) {
433
433
  return isTagElement(element);
434
434
  });
435
435
  }
436
- function extractParamTypes(ast) {
437
- let params = {};
436
+ function extractParamTypes(ast, currentParams) {
437
+ let params = {
438
+ ...currentParams
439
+ };
438
440
  let vocabTypesImports = new Set();
439
441
  for (const element of ast) {
440
442
  if (isArgumentElement(element)) {
441
- params[element.value] = 'string';
443
+ if (!(element.value in params)) {
444
+ // Preserve existing types for parameters that we've already parsed
445
+ // This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}`
446
+ params[element.value] = 'string';
447
+ }
442
448
  } else if (isNumberElement(element)) {
443
449
  params[element.value] = 'number';
444
450
  } else if (isPluralElement(element)) {
445
451
  params[element.value] = 'number';
446
452
  const children = Object.values(element.options).map(o => o.value);
447
453
  for (const child of children) {
448
- const [subParams, subImports] = extractParamTypes(child);
454
+ const [newParams, subImports] = extractParamTypes(child, params);
449
455
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
450
- params = {
451
- ...params,
452
- ...subParams
453
- };
456
+ params = newParams;
454
457
  }
455
458
  } else if (isDateElement(element) || isTimeElement(element)) {
456
459
  params[element.value] = 'Date | number';
457
460
  } else if (isTagElement(element)) {
458
461
  params[element.value] = 'FormatXMLElementFn<T>';
459
462
  vocabTypesImports.add('FormatXMLElementFn');
460
- const [subParams, subImports] = extractParamTypes(element.children);
463
+ const [newParams, subImports] = extractParamTypes(element.children, params);
461
464
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
462
- params = {
463
- ...params,
464
- ...subParams
465
- };
465
+ params = newParams;
466
466
  } else if (isSelectElement(element)) {
467
467
  const options = Object.keys(element.options);
468
468
 
@@ -473,12 +473,9 @@ function extractParamTypes(ast) {
473
473
  vocabTypesImports.add('StringWithSuggestions');
474
474
  const children = Object.values(element.options).map(o => o.value);
475
475
  for (const child of children) {
476
- const [subParams, subImports] = extractParamTypes(child);
476
+ const [newParams, subImports] = extractParamTypes(child, params);
477
477
  vocabTypesImports = new Set([...vocabTypesImports, ...subImports]);
478
- params = {
479
- ...params,
480
- ...subParams
481
- };
478
+ params = newParams;
482
479
  }
483
480
  }
484
481
  }
@@ -543,12 +540,9 @@ async function generateRuntime(loadedTranslation) {
543
540
  if (translatedLanguage[key]) {
544
541
  const ast = parse(translatedLanguage[key].message);
545
542
  hasTags = hasTags || extractHasTags(ast);
546
- const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
543
+ const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
547
544
  imports = new Set([...imports, ...vocabTypesImports]);
548
- params = {
549
- ...params,
550
- ...parsedParams
551
- };
545
+ params = parsedParams;
552
546
  messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
553
547
  }
554
548
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocab/core",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "main": "dist/vocab-core.cjs.js",
5
5
  "module": "dist/vocab-core.esm.js",
6
6
  "exports": {
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@formatjs/icu-messageformat-parser": "^2.0.10",
43
- "@vocab/types": "^1.1.2",
43
+ "@vocab/types": "^1.2.0",
44
44
  "chalk": "^4.1.0",
45
45
  "chokidar": "^3.4.3",
46
46
  "debug": "^4.3.1",