-
Notifications
You must be signed in to change notification settings - Fork 505
Closed
Labels
kind: bugSomething isn't workingSomething isn't workingscope: upstreamIssue in upstream dependencyIssue in upstream dependencytopic: async-to-promisesRelated to bugs with babel-plugin-async-to-promisesRelated to bugs with babel-plugin-async-to-promises
Description
Current Behavior
While working on my code I noticed a bug that led to my transpiled files and I saw that tsdx
was incorrectly transforming my break
inside switch cases to return
.
I thoughts that was rather odd so I created a sample project with the following code to pinpoint the issue:
function wait() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 1000);
});
}
export const test = async () => {
await wait();
switch ('' as any) {
case 'a':
break;
case 'b':
break;
default:
break;
}
const foo = { bar: true };
console.log('foo :', foo);
};
When running tsdx build
, this is what I get:
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function wait() {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve();
}, 1000);
});
}
var test = function test() {
try {
return Promise.resolve(wait()).then(function () {
switch ('') {
case 'a':
return;
case 'b':
return;
default:
return;
}
var foo = {
bar: true
};
console.log('foo :', foo);
});
} catch (e) {
return Promise.reject(e);
}
};
exports.test = test;
//# sourceMappingURL=switch-test.cjs.development.js.map
As you can see, inside test
, break
s inside then
are transformed to return
s, which is NOT correct. The console.log
line would never be reached.
Expected behavior
break
s inside then
should stay break
s.
Suggested solution(s)
No idea. The problem may come from babel or rollrup or one of their plugins.
Any idea what may cause the problem?
Your environment
Software | Version(s) |
---|---|
TSDX | 0.12.3 |
TypeScript | ^3.7.5 |
Browser | |
npm/Yarn | yarn 1.19.1 |
Node | 10.16.3 |
Operating System | Linux, but same behavior on windows |
agilgur5, schickling and rivertam
Metadata
Metadata
Assignees
Labels
kind: bugSomething isn't workingSomething isn't workingscope: upstreamIssue in upstream dependencyIssue in upstream dependencytopic: async-to-promisesRelated to bugs with babel-plugin-async-to-promisesRelated to bugs with babel-plugin-async-to-promises