Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ASI hazards issue #829

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/transformers/CJSImportTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,16 @@ export default class CJSImportTransformer extends Transformer {
* For example, this:
* export const {x: [a = 2, b], c} = d;
* becomes this:
* ({x: [exports.a = 2, exports.b], c: exports.c} = d;)
* ;({x: [exports.a = 2, exports.b], c: exports.c} = d;)
*/
private processComplexExportVar(): void {
this.tokens.removeInitialToken();
this.tokens.removeToken();
const needsParens = this.tokens.matches1(tt.braceL);
if (needsParens) {
this.tokens.appendCode("(");
this.tokens.appendCode(";(");
} else if (this.tokens.matches1(tt.bracketL)) {
this.tokens.appendCode(";");
}

let depth = 0;
Expand Down
10 changes: 5 additions & 5 deletions test/imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,13 +1259,13 @@ module.exports = exports.default;
export let {y}: Foo = z;
`,
`"use strict";${ESMODULE_PREFIX}
( {a: exports.a = 2, b: [exports.c, exports.d], ...exports.e} = f);
[exports.g = 3, ...exports.h] = i;
( {j: exports.j} = k);
( {l: exports.l = () => {const m = 3;}} = {});
;( {a: exports.a = 2, b: [exports.c, exports.d], ...exports.e} = f);
; [exports.g = 3, ...exports.h] = i;
;( {j: exports.j} = k);
;( {l: exports.l = () => {const m = 3;}} = {});
exports.x;
exports.x = 2;
( {y: exports.y} = z);
;( {y: exports.y} = z);
`,
{transforms: ["imports", "typescript"]},
);
Expand Down