Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/compat): Fix syntax context of
async-to-generator
(#6741)
**Description:** Previously, the `async-to-generator` produced invalid AST, in the aspect of span hygiene. [Playground](https://play.swc.rs/?version=1.3.24&code=H4sIAAAAAAAAAz1MbQqAIBT77yn2UyG6gNQJuoSZRCAa7xkk4d1TicZgH7C5%2B4yUYGPgBE7ZuyWazREmSIVpxiMAcumi0C3ANZxyvQ6%2Fqa8CehxjaGNpOAcLaWjn%2F6KhKN1dGaoULSpfHPTdxn8AAAA%3D&config=H4sIAAAAAAAAA0WOSwrDMAxE76K1F22hXfgE3fQQxlWCi39ICsQY3z12cMlOjObNTIUfW9AVsiFGGheXKGYHDVIysiWXBRQId2kxnrEpwF2QovFv9BmJQQtt2D2GVpROIj9u92enfEqMk1MQXHRLGR02hUzIfL1MXP3f2XpFSN9tCPWccWa%2BoF0Zk3P8mcYxoR3Kj7IYzwAAAA%3D%3D). It generate two bindings for `args` so it's invalid. **Related issue:** - Closes #6730.
- Loading branch information
Showing
16 changed files
with
194 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false | ||
}, | ||
"target": "es2015", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": { | ||
"toplevel": false, | ||
"keep_classnames": false, | ||
"keep_fnames": false, | ||
"keep_private_props": false, | ||
"ie8": false, | ||
"safari10": false | ||
} | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": true | ||
} |
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,11 @@ | ||
import { Plugin, PluginBuild } from 'esbuild'; | ||
|
||
export const styleLoader = (): Plugin => { | ||
return { | ||
setup(build: PluginBuild) { | ||
build.onLoad(async (args) => { | ||
|
||
}); | ||
}, | ||
}; | ||
}; |
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,13 @@ | ||
import r from "@swc/helpers/src/_async_to_generator.mjs"; | ||
export const styleLoader = ()=>{ | ||
return { | ||
setup (t) { | ||
t.onLoad(function() { | ||
var t = r(function*(r) {}); | ||
return function(r) { | ||
return t.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
}; | ||
}; |
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
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
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6730/config.json
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,3 @@ | ||
{ | ||
"defaults": false | ||
} |
45 changes: 45 additions & 0 deletions
45
crates/swc_ecma_minifier/tests/fixture/issues/6730/input.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
export const styleLoader = () => { | ||
return { | ||
name: 'style-loader', | ||
setup(build) { | ||
build.onLoad({ | ||
filter: /.*/, | ||
namespace: 'less' | ||
}, function () { | ||
var _ref = _asyncToGenerator(function* (args) { }); | ||
return function (args) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
}; | ||
}; |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_minifier/tests/fixture/issues/6730/mangle.json
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,3 @@ | ||
{ | ||
"toplevel": true | ||
} |
42 changes: 42 additions & 0 deletions
42
crates/swc_ecma_minifier/tests/fixture/issues/6730/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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function n(n, e, t, r, o, u, i) { | ||
try { | ||
var a = n[u](i); | ||
var c = a.value; | ||
} catch (s) { | ||
t(s); | ||
return; | ||
} | ||
if (a.done) e(c); | ||
else Promise.resolve(c).then(r, o); | ||
} | ||
function e(e) { | ||
return function() { | ||
var t = this, r = arguments; | ||
return new Promise(function(o, u) { | ||
var i = e.apply(t, r); | ||
function a(e) { | ||
n(i, o, u, a, c, "next", e); | ||
} | ||
function c(e) { | ||
n(i, o, u, a, c, "throw", e); | ||
} | ||
a(void 0); | ||
}); | ||
}; | ||
} | ||
export const styleLoader = ()=>{ | ||
return { | ||
name: 'style-loader', | ||
setup (n) { | ||
n.onLoad({ | ||
filter: /.*/, | ||
namespace: 'less' | ||
}, function() { | ||
var n = e(function*(n) {}); | ||
return function(e) { | ||
return n.apply(this, arguments); | ||
}; | ||
}()); | ||
} | ||
}; | ||
}; |
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