Skip to content

Commit 638cd6d

Browse files
authored
Fix printing unary statement with -(--i) (#4835)
1 parent aacf324 commit 638cd6d

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

packages/app/src/sandbox/eval/transpilers/babel/convert-esmodule/__snapshots__/index.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`convert-esmodule can convert + + 1`] = `
4-
"\\"use strict\\";
5-
c = (10, + +15);
6-
"
7-
`;
8-
93
exports[`convert-esmodule can convert class default exports 1`] = `
104
"\\"use strict\\";
115
Object.defineProperty(exports, \\"__esModule\\", {
@@ -298,7 +292,7 @@ exports[`convert-esmodule doesn't set var definitions 1`] = `
298292
Object.defineProperty(exports, \\"__esModule\\", {
299293
value: true
300294
});
301-
var global = typeof window !== \\"undefined\\" ? window : {};
295+
var global = typeof window !== \\"undefined\\" ? window : {};
302296
exports.global = global;
303297
"
304298
`;
@@ -635,6 +629,12 @@ var WS_CHARS = \\"u2000- 

   \\";
635629
"
636630
`;
637631

632+
exports[`convert-esmodule printer issues can convert + + 1`] = `
633+
"\\"use strict\\";
634+
c = (10, + + 15);
635+
"
636+
`;
637+
638638
exports[`convert-esmodule renames exports that are already defined, even in block scope 1`] = `
639639
"\\"use strict\\";
640640
var __$csb_exports = \\"testtest\\";

packages/app/src/sandbox/eval/transpilers/babel/convert-esmodule/generator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ export const customGenerator = {
6969
) {
7070
if (node.prefix) {
7171
state.write(node.operator);
72-
if (
73-
node.operator.length > 1 ||
74-
node.argument.type === 'UnaryExpression'
75-
) {
72+
if (node.operator.length > 1) {
7673
state.write(' ');
7774
}
7875
if (
@@ -83,6 +80,7 @@ export const customGenerator = {
8380
this[node.argument.type](node.argument, state);
8481
state.write(')');
8582
} else {
83+
state.write(' ');
8684
this[node.argument.type](node.argument, state);
8785
}
8886
} else {

packages/app/src/sandbox/eval/transpilers/babel/convert-esmodule/index.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,18 @@ describe('convert-esmodule', () => {
424424
expect(convertEsModule(code)).toMatchSnapshot();
425425
});
426426

427-
it('can convert + +', () => {
428-
const code = `
429-
c = (10.0, + +(15))
430-
`;
431-
432-
expect(convertEsModule(code)).toMatchSnapshot();
427+
describe('printer issues', () => {
428+
it('can convert + +', () => {
429+
const code = `
430+
c = (10.0, + +(15))
431+
`;
432+
433+
expect(convertEsModule(code)).toMatchSnapshot();
434+
});
435+
436+
it('can convert -(--i)', () => {
437+
const code = `a = -(--i)`;
438+
expect(convertEsModule(code)).toBe('"use strict";\na = - --i;\n');
439+
});
433440
});
434441
});

0 commit comments

Comments
 (0)