@vocab/core
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -452,8 +452,14 @@ 'use strict'; | ||
} | ||
function extractParamTypes(ast) { | ||
let params = {}; | ||
function extractParamTypes(ast, currentParams) { | ||
let params = { | ||
...currentParams | ||
}; | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
if (icuMessageformatParser.isArgumentElement(element)) { | ||
params[element.value] = 'string'; | ||
if (!(element.value in params)) { | ||
// Preserve existing types for parameters that we've already parsed | ||
// This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}` | ||
params[element.value] = 'string'; | ||
} | ||
} else if (icuMessageformatParser.isNumberElement(element)) { | ||
@@ -465,8 +471,5 @@ params[element.value] = 'number'; | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -478,8 +481,5 @@ } else if (icuMessageformatParser.isDateElement(element) || icuMessageformatParser.isTimeElement(element)) { | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
const [newParams, subImports] = extractParamTypes(element.children, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} else if (icuMessageformatParser.isSelectElement(element)) { | ||
@@ -495,8 +495,5 @@ const options = Object.keys(element.options); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -566,8 +563,5 @@ } | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
...params, | ||
...parsedParams | ||
}; | ||
params = parsedParams; | ||
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`); | ||
@@ -574,0 +568,0 @@ } |
@@ -452,8 +452,14 @@ 'use strict'; | ||
} | ||
function extractParamTypes(ast) { | ||
let params = {}; | ||
function extractParamTypes(ast, currentParams) { | ||
let params = { | ||
...currentParams | ||
}; | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
if (icuMessageformatParser.isArgumentElement(element)) { | ||
params[element.value] = 'string'; | ||
if (!(element.value in params)) { | ||
// Preserve existing types for parameters that we've already parsed | ||
// This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}` | ||
params[element.value] = 'string'; | ||
} | ||
} else if (icuMessageformatParser.isNumberElement(element)) { | ||
@@ -465,8 +471,5 @@ params[element.value] = 'number'; | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -478,8 +481,5 @@ } else if (icuMessageformatParser.isDateElement(element) || icuMessageformatParser.isTimeElement(element)) { | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
const [newParams, subImports] = extractParamTypes(element.children, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} else if (icuMessageformatParser.isSelectElement(element)) { | ||
@@ -495,8 +495,5 @@ const options = Object.keys(element.options); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -566,8 +563,5 @@ } | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
...params, | ||
...parsedParams | ||
}; | ||
params = parsedParams; | ||
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`); | ||
@@ -574,0 +568,0 @@ } |
@@ -436,8 +436,14 @@ import { existsSync, promises } from 'fs'; | ||
} | ||
function extractParamTypes(ast) { | ||
let params = {}; | ||
function extractParamTypes(ast, currentParams) { | ||
let params = { | ||
...currentParams | ||
}; | ||
let vocabTypesImports = new Set(); | ||
for (const element of ast) { | ||
if (isArgumentElement(element)) { | ||
params[element.value] = 'string'; | ||
if (!(element.value in params)) { | ||
// Preserve existing types for parameters that we've already parsed | ||
// This applies to self-referential parameters, for example `{foo, plural, 1 {{foo} thing} other {{foo} things}}` | ||
params[element.value] = 'string'; | ||
} | ||
} else if (isNumberElement(element)) { | ||
@@ -449,8 +455,5 @@ params[element.value] = 'number'; | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -462,8 +465,5 @@ } else if (isDateElement(element) || isTimeElement(element)) { | ||
vocabTypesImports.add('FormatXMLElementFn'); | ||
const [subParams, subImports] = extractParamTypes(element.children); | ||
const [newParams, subImports] = extractParamTypes(element.children, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} else if (isSelectElement(element)) { | ||
@@ -479,8 +479,5 @@ const options = Object.keys(element.options); | ||
for (const child of children) { | ||
const [subParams, subImports] = extractParamTypes(child); | ||
const [newParams, subImports] = extractParamTypes(child, params); | ||
vocabTypesImports = new Set([...vocabTypesImports, ...subImports]); | ||
params = { | ||
...params, | ||
...subParams | ||
}; | ||
params = newParams; | ||
} | ||
@@ -550,8 +547,5 @@ } | ||
hasTags = hasTags || extractHasTags(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast); | ||
const [parsedParams, vocabTypesImports] = extractParamTypes(ast, params); | ||
imports = new Set([...imports, ...vocabTypesImports]); | ||
params = { | ||
...params, | ||
...parsedParams | ||
}; | ||
params = parsedParams; | ||
messages.add(`'${encodeWithinSingleQuotes(translatedLanguage[key].message)}'`); | ||
@@ -558,0 +552,0 @@ } |
{ | ||
"name": "@vocab/core", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"main": "dist/vocab-core.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/vocab-core.esm.js", |
130444
2862