Skip to content

Commit 0433ae8

Browse files
authored
Move esmodule export to be after the declaration (codesandbox#3452)
1 parent 2f3fa90 commit 0433ae8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ exports[`convert-esmodule can convert class default exports 1`] = `
44
"Object.defineProperty(exports, \\"__esModule\\", {
55
value: true
66
});
7-
exports.default = A;
87
class A {}
8+
exports.default = A;
99
"
1010
`;
1111

1212
exports[`convert-esmodule can convert default exports 1`] = `
1313
"Object.defineProperty(exports, \\"__esModule\\", {
1414
value: true
1515
});
16-
exports.default = test;
1716
function test() {}
17+
exports.default = test;
1818
"
1919
`;
2020

@@ -140,8 +140,8 @@ exports[`convert-esmodule handles export mutations 1`] = `
140140
"Object.defineProperty(exports, \\"__esModule\\", {
141141
value: true
142142
});
143-
exports.default = test;
144143
function test() {}
144+
exports.default = test;
145145
exports.default = test = 5;;
146146
"
147147
`;
@@ -150,8 +150,8 @@ exports[`convert-esmodule handles export mutations with no named function 1`] =
150150
"Object.defineProperty(exports, \\"__esModule\\", {
151151
value: true
152152
});
153-
exports.default = $csb__default;
154153
function $csb__default() {}
154+
exports.default = $csb__default;
155155
"
156156
`;
157157

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,18 @@ export function convertEsModule(code: string) {
170170
name: varName,
171171
};
172172
}
173+
174+
program.body[
175+
i
176+
] = statement.declaration as meriyah.ESTree.DeclarationStatement;
177+
i++;
178+
173179
program.body.splice(
174180
i,
175181
0,
176182
generateExportStatement(statement.declaration.id.name, 'default')
177183
);
178184
i++;
179-
180-
program.body[
181-
i
182-
] = statement.declaration as meriyah.ESTree.DeclarationStatement;
183-
i++;
184185
} else {
185186
program.body[i] = {
186187
type: n.VariableDeclaration,

0 commit comments

Comments
 (0)