diff --git a/packages/localize/src/tools/src/translate/source_files/source_file_utils.ts b/packages/localize/src/tools/src/translate/source_files/source_file_utils.ts index 266caa8b93..04eb96ebc7 100644 --- a/packages/localize/src/tools/src/translate/source_files/source_file_utils.ts +++ b/packages/localize/src/tools/src/translate/source_files/source_file_utils.ts @@ -89,6 +89,24 @@ export function unwrapMessagePartsFromLocalizeCall(call: NodePath 2) { + // This is a minified sequence expression, where the first two expressions in the sequence + // are assignments of the cooked and raw arrays respectively. + const [first, second] = expressions; + if (first.isAssignmentExpression() && second.isAssignmentExpression()) { + cooked = first.get('right'); + if (!cooked.isExpression()) { + throw new BabelParseError( + first.node, 'Unexpected cooked value, expected an expression.'); + } + raw = second.get('right'); + if (!raw.isExpression()) { + throw new BabelParseError(second.node, 'Unexpected raw value, expected an expression.'); + } + } + } } } diff --git a/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts b/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts index 5a83eb6889..eb3db70de7 100644 --- a/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts +++ b/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts @@ -103,6 +103,22 @@ describe('makeEs5Plugin', () => { expect(output.code).toEqual('"try" + (40 + 2) + "me";'); }); + it('should handle minified code', () => { + const diagnostics = new Diagnostics(); + const input = `$localize( + cachedObj|| + ( + cookedParts=['try', 'me'], + rawParts=['try', 'me'], + Object.defineProperty? + Object.defineProperty(cookedParts,"raw",{value:rawParts}): + cookedParts.raw=rawParts, + cachedObj=cookedParts + ),40 + 2)`; + const output = transformSync(input, {plugins: [makeEs5TranslatePlugin(diagnostics, {})]}) !; + expect(output.code).toEqual('"try" + (40 + 2) + "me";'); + }); + it('should handle lazy-load helper calls', () => { const diagnostics = new Diagnostics(); const input = `