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
Improve output of using
#15959
Merged
Merged
Improve output of using
#15959
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ff23d28
improve
liuxingbaoyu 8df7565
fix
liuxingbaoyu f9e8ff3
improve
liuxingbaoyu bd20e3a
review
liuxingbaoyu ebb7847
improve
liuxingbaoyu 5e7ba63
improve from ts
liuxingbaoyu ae14da3
fix
liuxingbaoyu f79d39c
rebase
liuxingbaoyu 3a5ca3f
rebase
liuxingbaoyu 5d8432f
Update makefile
nicolo-ribaudo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* @minVersion 7.23.9 */ | ||
|
||
type Stack = { | ||
v: any; | ||
d: () => any; | ||
a: boolean; | ||
}; | ||
|
||
export default function _usingCtx() { | ||
var _disposeSuppressedError = | ||
typeof SuppressedError === "function" | ||
? // eslint-disable-next-line no-undef | ||
SuppressedError | ||
: (function (error: Error, suppressed: Error) { | ||
var err = new Error() as SuppressedError; | ||
err.name = "SuppressedError"; | ||
err.suppressed = suppressed; | ||
err.error = error; | ||
return err; | ||
} as SuppressedErrorConstructor), | ||
empty = {}, | ||
stack: Stack[] = []; | ||
function using(isAwait: boolean, value: any) { | ||
if (value != null) { | ||
if (Object(value) !== value) { | ||
throw new TypeError( | ||
"using declarations can only be used with objects, functions, null, or undefined.", | ||
); | ||
} | ||
// core-js-pure uses Symbol.for for polyfilling well-known symbols | ||
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 }); | ||
} | ||
return value; | ||
} | ||
return { | ||
// error | ||
e: empty, | ||
// using | ||
u: using.bind(null, false), | ||
// await using | ||
a: using.bind(null, true), | ||
// dispose | ||
d: function () { | ||
var error = this.e; | ||
|
||
function next(): any { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
while ((resource = stack.pop())) { | ||
try { | ||
var resource, | ||
disposalResult = resource.d.call(resource.v); | ||
if (resource.a) { | ||
return Promise.resolve(disposalResult).then(next, err); | ||
} | ||
} catch (e) { | ||
return err(e); | ||
} | ||
} | ||
if (error !== empty) throw error; | ||
} | ||
|
||
function err(e: Error) { | ||
error = error !== empty ? new _disposeSuppressedError(error, e) : e; | ||
|
||
return next(); | ||
} | ||
|
||
return next(); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
...el-plugin-proposal-explicit-resource-management/test/fixtures/source-maps/block/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
try { | ||
var _stack = []; | ||
const x = babelHelpers.using(_stack, fn()); | ||
var _usingCtx = babelHelpers.usingCtx(); | ||
const x = _usingCtx.u(fn()); | ||
doSomethingWith(x); | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
_usingCtx.e = _; | ||
} finally { | ||
babelHelpers.dispose(_stack, _error, _hasError); | ||
_usingCtx.d(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect users to use the
core-js-pure
conversion helper? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily, but maybe users are importing "things that can be disposed" from libraries that have been compiled with core-js, and that thus use
Symbol.for("Symbol.dispose")
as their protocol.