Regression in `v1.4.15`: `ReferenceError: resource is not defined` in strict mode
jeengbe opened this issue · comments
Jesper Engberg commented
Describe the bug
Updating from .14
-> .15
, code with using
fails in strict mode with ReferenceError: resource is not defined
.
This is the generated _using_ctx()
:
function _using_ctx() {
var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
var err = new Error();
err.name = "SuppressedError";
err.suppressed = suppressed;
err.error = error;
return err;
}
, empty = {}
, stack = [];
function using(isAwait, value) {
if (value != null) {
if (Object(value) !== value) {
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
}
if (isAwait) {
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
}
if (dispose == null) {
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
}
if (typeof dispose !== "function") {
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
}
stack.push({
v: value,
d: dispose,
a: isAwait
});
} else if (isAwait) {
stack.push({
d: value,
a: isAwait
});
}
return value;
}
return {
e: empty,
u: using.bind(null, false),
a: using.bind(null, true),
d: function() {
var error = this.e;
function next() {
while (resource = stack.pop()) {
// ^^^^^ fails here
try {
var resource1, disposalResult = resource1.d && resource1.d.call(resource1.v);
if (resource1.a) {
return Promise.resolve(disposalResult).then(next, err);
}
} catch (e) {
return err(e);
}
}
if (error !== empty)
throw error;
}
function err(e) {
error = error !== empty ? new _disposeSuppressedError(error,e) : e;
return next();
}
return next();
}
};
The test is run in strict mode.
Input code
No response
Config
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
},
},
},
Playground link (or link to the minimal reproduction)
Note that the produced code has to be run in strict mode.
SWC Info output
No response
Expected behavior
n/a
Actual behavior
No response
Version
1.4.15
Additional context
This change broke it: #8860
SWC Bot commented
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.