@vocab/core
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -454,3 +454,3 @@ 'use strict'; | ||
let params = {}; | ||
let imports = new Set(); | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
@@ -466,3 +466,3 @@ if (icuMessageformatParser.isArgumentElement(element)) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -477,5 +477,5 @@ ...params, | ||
params[element.value] = 'FormatXMLElementFn<T>'; | ||
imports.add(`import { FormatXMLElementFn } from '@vocab/types';`); | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -486,7 +486,13 @@ ...params, | ||
} else if (icuMessageformatParser.isSelectElement(element)) { | ||
params[element.value] = Object.keys(element.options).map(o => `'${o}'`).join(' | '); | ||
const options = Object.keys(element.options); | ||
// `other` will always be an option as the parser enforces this by default | ||
const nonOtherOptions = options.filter(o => o !== 'other'); | ||
const nonOtherOptionsUnion = nonOtherOptions.map(o => `'${o}'`).join(' | '); | ||
params[element.value] = `StringWithSuggestions<${nonOtherOptionsUnion}>`; | ||
vocabTypesImports.add('StringWithSuggestions'); | ||
const children = Object.values(element.options).map(o => o.value); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -499,3 +505,3 @@ ...params, | ||
} | ||
return [params, imports]; | ||
return [params, vocabTypesImports]; | ||
} | ||
@@ -514,2 +520,6 @@ function serialiseObjectToType(v) { | ||
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`; | ||
const serializeModuleImports = (imports, moduleName) => { | ||
const importNames = Array.from(imports); | ||
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`; | ||
}; | ||
function serialiseTranslationRuntime(value, imports, loadedTranslation) { | ||
@@ -535,3 +545,3 @@ trace('Serialising translations:', loadedTranslation); | ||
${Array.from(imports).join('\n')} | ||
${serializeModuleImports(imports, '@vocab/types')} | ||
import { createLanguage, createTranslationFile } from '@vocab/core/runtime'; | ||
@@ -559,4 +569,4 @@ | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, parsedImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...parsedImports]); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
@@ -563,0 +573,0 @@ ...params, |
@@ -454,3 +454,3 @@ 'use strict'; | ||
let params = {}; | ||
let imports = new Set(); | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
@@ -466,3 +466,3 @@ if (icuMessageformatParser.isArgumentElement(element)) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -477,5 +477,5 @@ ...params, | ||
params[element.value] = 'FormatXMLElementFn<T>'; | ||
imports.add(`import { FormatXMLElementFn } from '@vocab/types';`); | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -486,7 +486,13 @@ ...params, | ||
} else if (icuMessageformatParser.isSelectElement(element)) { | ||
params[element.value] = Object.keys(element.options).map(o => `'${o}'`).join(' | '); | ||
const options = Object.keys(element.options); | ||
// `other` will always be an option as the parser enforces this by default | ||
const nonOtherOptions = options.filter(o => o !== 'other'); | ||
const nonOtherOptionsUnion = nonOtherOptions.map(o => `'${o}'`).join(' | '); | ||
params[element.value] = `StringWithSuggestions<${nonOtherOptionsUnion}>`; | ||
vocabTypesImports.add('StringWithSuggestions'); | ||
const children = Object.values(element.options).map(o => o.value); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -499,3 +505,3 @@ ...params, | ||
} | ||
return [params, imports]; | ||
return [params, vocabTypesImports]; | ||
} | ||
@@ -514,2 +520,6 @@ function serialiseObjectToType(v) { | ||
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`; | ||
const serializeModuleImports = (imports, moduleName) => { | ||
const importNames = Array.from(imports); | ||
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`; | ||
}; | ||
function serialiseTranslationRuntime(value, imports, loadedTranslation) { | ||
@@ -535,3 +545,3 @@ trace('Serialising translations:', loadedTranslation); | ||
${Array.from(imports).join('\n')} | ||
${serializeModuleImports(imports, '@vocab/types')} | ||
import { createLanguage, createTranslationFile } from '@vocab/core/runtime'; | ||
@@ -559,4 +569,4 @@ | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, parsedImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...parsedImports]); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
@@ -563,0 +573,0 @@ ...params, |
@@ -438,3 +438,3 @@ import { existsSync, promises } from 'fs'; | ||
let params = {}; | ||
let imports = new Set(); | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
@@ -450,3 +450,3 @@ if (isArgumentElement(element)) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -461,5 +461,5 @@ ...params, | ||
params[element.value] = 'FormatXMLElementFn<T>'; | ||
imports.add(`import { FormatXMLElementFn } from '@vocab/types';`); | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -470,7 +470,13 @@ ...params, | ||
} else if (isSelectElement(element)) { | ||
params[element.value] = Object.keys(element.options).map(o => `'${o}'`).join(' | '); | ||
const options = Object.keys(element.options); | ||
// `other` will always be an option as the parser enforces this by default | ||
const nonOtherOptions = options.filter(o => o !== 'other'); | ||
const nonOtherOptionsUnion = nonOtherOptions.map(o => `'${o}'`).join(' | '); | ||
params[element.value] = `StringWithSuggestions<${nonOtherOptionsUnion}>`; | ||
vocabTypesImports.add('StringWithSuggestions'); | ||
const children = Object.values(element.options).map(o => o.value); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
imports = new Set([...imports, ...subImports]); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
@@ -483,3 +489,3 @@ ...params, | ||
} | ||
return [params, imports]; | ||
return [params, vocabTypesImports]; | ||
} | ||
@@ -498,2 +504,6 @@ function serialiseObjectToType(v) { | ||
const banner = `// This file is automatically generated by Vocab.\n// To make changes update translation.json files directly.`; | ||
const serializeModuleImports = (imports, moduleName) => { | ||
const importNames = Array.from(imports); | ||
return `import { ${Array.from(importNames).join(', ')} } from '${moduleName}'`; | ||
}; | ||
function serialiseTranslationRuntime(value, imports, loadedTranslation) { | ||
@@ -519,3 +529,3 @@ trace('Serialising translations:', loadedTranslation); | ||
${Array.from(imports).join('\n')} | ||
${serializeModuleImports(imports, '@vocab/types')} | ||
import { createLanguage, createTranslationFile } from '@vocab/core/runtime'; | ||
@@ -543,4 +553,4 @@ | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, parsedImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...parsedImports]); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
@@ -547,0 +557,0 @@ ...params, |
{ | ||
"name": "@vocab/core", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"main": "dist/vocab-core.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/vocab-core.esm.js", |
130021
2880