diff --git a/.husky/pre-commit b/.husky/pre-commit index 1c43e09..ddd6c03 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,5 +2,6 @@ . "$(dirname -- "$0")/_/husky.sh" npm test +npm run lint:fix npm run lint:check npm run lint-staged \ No newline at end of file diff --git a/src/reverse_translator.ts b/src/reverse_translator.ts index 4699539..78cc8a3 100644 --- a/src/reverse_translator.ts +++ b/src/reverse_translator.ts @@ -39,6 +39,8 @@ import { escapeStr } from './utils'; export class JsonTemplateReverseTranslator { private options?: EngineOptions; + private level = 0; + constructor(options?: EngineOptions) { this.options = options; } @@ -429,9 +431,14 @@ export class JsonTemplateReverseTranslator { translateObjectExpression(expr: ObjectExpression): string { const code: string[] = []; - code.push('{\n\t'); - code.push(this.translateExpressions(expr.props, ',\n\t')); - code.push('\n}'); + const prevIndentation = ' '.repeat(this.level); + code.push('{\n'); + this.level++; + const currIndentation = ' '.repeat(this.level); + code.push(currIndentation); + code.push(this.translateExpressions(expr.props, `,\n${currIndentation}`)); + this.level--; + code.push(`\n${prevIndentation}}`); return code.join(''); } diff --git a/src/utils/common.test.ts b/src/utils/common.test.ts index 16d0cd8..5e0b011 100644 --- a/src/utils/common.test.ts +++ b/src/utils/common.test.ts @@ -48,11 +48,11 @@ describe('Common Utils tests', () => { expect(CommonUtils.escapeStr(undefined)).toEqual(''); }); it('should return escaped string for simple string input', () => { - expect(CommonUtils.escapeStr('aabc')).toEqual(`'aabc'`); + expect(CommonUtils.escapeStr('aabc')).toEqual(`"aabc"`); }); it('should return escaped string for string with escape characters', () => { - expect(CommonUtils.escapeStr(`a\nb'c`)).toEqual(`'a\nb\\'c'`); + expect(CommonUtils.escapeStr(`a\nb'"c`)).toEqual(`"a\nb'\\"c"`); }); }); describe('CreateAsyncFunction', () => { diff --git a/src/utils/common.ts b/src/utils/common.ts index 83bf884..68cdfe8 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -49,5 +49,5 @@ export function escapeStr(s?: string): string { if (typeof s !== 'string') { return ''; } - return `'${s.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`; + return `"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`; } diff --git a/src/utils/converter.ts b/src/utils/converter.ts index 533c826..c142e86 100644 --- a/src/utils/converter.ts +++ b/src/utils/converter.ts @@ -77,6 +77,7 @@ function processAllFilter( type: SyntaxType.PATH, root: currentInputAST.root, pathType: currentInputAST.pathType, + inferredPathType: currentInputAST.inferredPathType, parts: matchedInputParts, returnAsArray: true, } as PathExpression; @@ -121,6 +122,7 @@ function processWildCardSelector( type: SyntaxType.PATH, root: currentInputAST.root, pathType: currentInputAST.pathType, + inferredPathType: currentInputAST.inferredPathType, parts: matchedInputParts, } as PathExpression; }