@vocab/core 1.2.3 → 1.2.5
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/dist/vocab-core.cjs.dev.js +21 -24
- package/dist/vocab-core.cjs.prod.js +21 -24
- package/dist/vocab-core.esm.js +21 -24
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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 [
|
|
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 [
|
|
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 [
|
|
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
|
}
|
|
@@ -513,6 +510,9 @@ function serialiseObjectToType(v) {
|
|
|
513
510
|
}
|
|
514
511
|
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`;
|
|
515
512
|
const serializeModuleImports = (imports, moduleName) => {
|
|
513
|
+
if (imports.size === 0) {
|
|
514
|
+
return '';
|
|
515
|
+
}
|
|
516
516
|
const importNames = Array.from(imports);
|
|
517
517
|
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`;
|
|
518
518
|
};
|
|
@@ -536,8 +536,8 @@ function serialiseTranslationRuntime(value, imports, loadedTranslation) {
|
|
|
536
536
|
const languagesUnionAsString = Object.keys(loadedTranslation.languages).map(l => `'${l}'`).join(' | ');
|
|
537
537
|
return `${banner}
|
|
538
538
|
|
|
539
|
-
${serializeModuleImports(imports, '@vocab/types')}
|
|
540
539
|
import { createLanguage, createTranslationFile } from '@vocab/core/runtime';
|
|
540
|
+
${serializeModuleImports(imports, '@vocab/types')}
|
|
541
541
|
|
|
542
542
|
const translations = createTranslationFile<${languagesUnionAsString}, ${serialiseObjectToType(translationsType)}>({${content}});
|
|
543
543
|
|
|
@@ -559,12 +559,9 @@ async function generateRuntime(loadedTranslation) {
|
|
|
559
559
|
if (translatedLanguage[key]) {
|
|
560
560
|
const ast = icuMessageformatParser.parse(translatedLanguage[key].message);
|
|
561
561
|
hasTags = hasTags || extractHasTags(ast);
|
|
562
|
-
const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
|
|
562
|
+
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
|
|
563
563
|
imports = new Set([...imports, ...vocabTypesImports]);
|
|
564
|
-
params =
|
|
565
|
-
...params,
|
|
566
|
-
...parsedParams
|
|
567
|
-
};
|
|
564
|
+
params = parsedParams;
|
|
568
565
|
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
|
|
569
566
|
}
|
|
570
567
|
}
|
|
@@ -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
|
-
|
|
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 [
|
|
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 [
|
|
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 [
|
|
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
|
}
|
|
@@ -513,6 +510,9 @@ function serialiseObjectToType(v) {
|
|
|
513
510
|
}
|
|
514
511
|
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`;
|
|
515
512
|
const serializeModuleImports = (imports, moduleName) => {
|
|
513
|
+
if (imports.size === 0) {
|
|
514
|
+
return '';
|
|
515
|
+
}
|
|
516
516
|
const importNames = Array.from(imports);
|
|
517
517
|
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`;
|
|
518
518
|
};
|
|
@@ -536,8 +536,8 @@ function serialiseTranslationRuntime(value, imports, loadedTranslation) {
|
|
|
536
536
|
const languagesUnionAsString = Object.keys(loadedTranslation.languages).map(l => `'${l}'`).join(' | ');
|
|
537
537
|
return `${banner}
|
|
538
538
|
|
|
539
|
-
${serializeModuleImports(imports, '@vocab/types')}
|
|
540
539
|
import { createLanguage, createTranslationFile } from '@vocab/core/runtime';
|
|
540
|
+
${serializeModuleImports(imports, '@vocab/types')}
|
|
541
541
|
|
|
542
542
|
const translations = createTranslationFile<${languagesUnionAsString}, ${serialiseObjectToType(translationsType)}>({${content}});
|
|
543
543
|
|
|
@@ -559,12 +559,9 @@ async function generateRuntime(loadedTranslation) {
|
|
|
559
559
|
if (translatedLanguage[key]) {
|
|
560
560
|
const ast = icuMessageformatParser.parse(translatedLanguage[key].message);
|
|
561
561
|
hasTags = hasTags || extractHasTags(ast);
|
|
562
|
-
const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
|
|
562
|
+
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
|
|
563
563
|
imports = new Set([...imports, ...vocabTypesImports]);
|
|
564
|
-
params =
|
|
565
|
-
...params,
|
|
566
|
-
...parsedParams
|
|
567
|
-
};
|
|
564
|
+
params = parsedParams;
|
|
568
565
|
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
|
|
569
566
|
}
|
|
570
567
|
}
|
package/dist/vocab-core.esm.js
CHANGED
|
@@ -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
|
-
|
|
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 [
|
|
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 [
|
|
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 [
|
|
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
|
}
|
|
@@ -497,6 +494,9 @@ function serialiseObjectToType(v) {
|
|
|
497
494
|
}
|
|
498
495
|
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`;
|
|
499
496
|
const serializeModuleImports = (imports, moduleName) => {
|
|
497
|
+
if (imports.size === 0) {
|
|
498
|
+
return '';
|
|
499
|
+
}
|
|
500
500
|
const importNames = Array.from(imports);
|
|
501
501
|
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`;
|
|
502
502
|
};
|
|
@@ -520,8 +520,8 @@ function serialiseTranslationRuntime(value, imports, loadedTranslation) {
|
|
|
520
520
|
const languagesUnionAsString = Object.keys(loadedTranslation.languages).map(l => `'${l}'`).join(' | ');
|
|
521
521
|
return `${banner}
|
|
522
522
|
|
|
523
|
-
${serializeModuleImports(imports, '@vocab/types')}
|
|
524
523
|
import { createLanguage, createTranslationFile } from '@vocab/core/runtime';
|
|
524
|
+
${serializeModuleImports(imports, '@vocab/types')}
|
|
525
525
|
|
|
526
526
|
const translations = createTranslationFile<${languagesUnionAsString}, ${serialiseObjectToType(translationsType)}>({${content}});
|
|
527
527
|
|
|
@@ -543,12 +543,9 @@ async function generateRuntime(loadedTranslation) {
|
|
|
543
543
|
if (translatedLanguage[key]) {
|
|
544
544
|
const ast = parse(translatedLanguage[key].message);
|
|
545
545
|
hasTags = hasTags || extractHasTags(ast);
|
|
546
|
-
const [parsedParams, vocabTypesImports] = extractParamTypes(ast);
|
|
546
|
+
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params);
|
|
547
547
|
imports = new Set([...imports, ...vocabTypesImports]);
|
|
548
|
-
params =
|
|
549
|
-
...params,
|
|
550
|
-
...parsedParams
|
|
551
|
-
};
|
|
548
|
+
params = parsedParams;
|
|
552
549
|
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`);
|
|
553
550
|
}
|
|
554
551
|
}
|