Moved function "jsonText" to be local to "convertText"

This commit is contained in:
Antonino Porcino 2016-07-09 11:56:26 +02:00
parent 854293c589
commit b3cc40e297
1 changed files with 6 additions and 13 deletions

View File

@ -143,24 +143,17 @@ const curlyMap = {'{': 1, '}': -1};
* @typedef {{fileName:string,force:boolean,modules:string,defines:*,reactImportPath:string=,lodashImportPath:string=,flow:boolean,name:string,native:boolean,propTemplates:*,format:string,_:*,version:boolean,help:boolean,listTargetVersion:boolean,modules:string, dryRun:boolean}} Options
*/
/**
* @param {string} txt
* @param {boolean} removeWhitespaces
* @return {string}
*/
function jsonText(txt, normalizeWhitespaces) {
const text = normalizeWhitespaces ? normalizeHtmlWhitespace(txt) : txt;
return JSON.stringify(text);
}
/**
* @param node
* @param {Context} context
* @param {string} txt
* @param {boolean} [removeWhitespaces]
* @param {boolean} [normalizeWhitespaces]
* @return {string}
*/
function convertText(node, context, txt, normalizeWhitespaces) {
function jsonText(text) {
return JSON.stringify(normalizeWhitespaces ? normalizeHtmlWhitespace(text) : text);
}
let res = '';
let first = true;
const concatChar = node.type === 'text' ? ',' : '+';
@ -168,7 +161,7 @@ function convertText(node, context, txt, normalizeWhitespaces) {
const start = txt.indexOf('{');
const pre = txt.substr(0, start);
if (pre) {
res += (first ? '' : concatChar) + jsonText(pre, normalizeWhitespaces);
res += (first ? '' : concatChar) + jsonText(pre);
first = false;
}
let curlyCounter = 1;
@ -186,7 +179,7 @@ function convertText(node, context, txt, normalizeWhitespaces) {
}
}
if (txt) {
res += (first ? '' : concatChar) + jsonText(txt, normalizeWhitespaces);
res += (first ? '' : concatChar) + jsonText(txt);
}
if (res === '') {
res = 'true';