Skip to content
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

fix(es/compat): Don't add pure annotations to dummy spans #8172

Merged
merged 24 commits into from
Oct 23, 2023
Merged
2 changes: 2 additions & 0 deletions crates/jsdoc/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ impl Comments for SwcComments {
}

fn add_pure_comment(&self, pos: BytePos) {
assert_ne!(pos, BytePos(0), "cannot add pure comment to zero position");

let mut leading = self.leading.entry(pos).or_default();
let pure_comment = Comment {
kind: CommentKind::Block,
Expand Down
24 changes: 24 additions & 0 deletions crates/swc/tests/exec/issues-8xxx/8155/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"tsx": false
},
"transform": {
"legacyDecorator": true
},
"target": "es5",
// "loose": false,
"minify": {
"compress": false,
"mangle": false
},
"loose": false
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
16 changes: 16 additions & 0 deletions crates/swc/tests/exec/issues-8xxx/8155/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const someFn = (xx, x, y) => [x, y];

const getArray = () => [1, 2, 3];

const goodFunction = async () => {
const rb = await getArray();
const rc = await getArray();
console.log(someFn(1, rb, rc));
}

const badFunction = async () => {
console.log(someFn(1, await getArray(), await getArray()))
}

goodFunction();
badFunction();
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"tsx": false
},
"transform": {
"legacyDecorator": true
},
"target": "es2016",
"minify": {
"compress": true
},
"loose": false,
"externalHelpers": false
},
"isModule": true
}
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/1/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const someFn = (xx, x, y) => [x, y];

const getArray = () => [1, 2, 3];

const goodFunction = async () => {
const rb = await getArray();
const rc = await getArray();
console.log(someFn(1, rb, rc));
}

const badFunction = async () => {
console.log(someFn(1, await getArray(), await getArray()))
}

goodFunction();
badFunction();
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var _ref, _ref1;
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
let someFn = (xx, x, y)=>[
x,
y
], getArray = ()=>[
1,
2,
3
], goodFunction = (_ref = _async_to_generator(function*() {
let rb = yield getArray(), rc = yield getArray();
console.log(someFn(1, rb, rc));
}), function() {
return _ref.apply(this, arguments);
}), badFunction = (_ref1 = _async_to_generator(function*() {
console.log(someFn(1, (yield getArray()), (yield getArray())));
}), function() {
return _ref1.apply(this, arguments);
});
goodFunction(), badFunction();
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/2/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"tsx": false
},
"transform": {
"legacyDecorator": true
},
"target": "es2016",
"loose": false,
"externalHelpers": false
},
"isModule": true
}
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/2/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const someFn = (xx, x, y) => [x, y];

const getArray = () => [1, 2, 3];

const goodFunction = async () => {
const rb = await getArray();
const rc = await getArray();
console.log(someFn(1, rb, rc));
}

const badFunction = async () => {
console.log(someFn(1, await getArray(), await getArray()))
}

goodFunction();
badFunction();
30 changes: 30 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8155/2/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
const someFn = (xx, x, y)=>[
x,
y
];
const getArray = ()=>[
1,
2,
3
];
const goodFunction = function() {
var _ref = _async_to_generator(function*() {
const rb = yield getArray();
const rc = yield getArray();
console.log(someFn(1, rb, rc));
});
return function goodFunction() {
return _ref.apply(this, arguments);
};
}();
const badFunction = function() {
var _ref = _async_to_generator(function*() {
console.log(someFn(1, (yield getArray()), (yield getArray())));
});
return function badFunction() {
return _ref.apply(this, arguments);
};
}();
goodFunction();
badFunction();
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//// [asyncArrowFunction10_es5.ts]
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
_async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
});
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//// [asyncArrowFunction10_es6.ts]
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
_async_to_generator(function*() {});
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//// [asyncArrowFunction1_es5.ts]
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
_async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
});
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//// [asyncArrowFunction1_es6.ts]
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
_async_to_generator(function*() {});
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,81 @@ var M;
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
M || (M = {});
_async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
p
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
mp
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
mp
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
p
];
});
}), function(M) {
function _f1() {
return (_f1 = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
})).apply(this, arguments);
}
M.f1 = function() {
return _f1.apply(this, arguments);
};
}(M || (M = {}));
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
//// [asyncAwaitIsolatedModules_es6.ts]
var M;
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
M || (M = {});
_async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {
return p;
}), _async_to_generator(function*() {
return mp;
}), _async_to_generator(function*() {
return mp;
}), _async_to_generator(function*() {
return p;
}), function(M) {
function _f1() {
return (_f1 = _async_to_generator(function*() {})).apply(this, arguments);
}
M.f1 = function() {
return _f1.apply(this, arguments);
};
}(M || (M = {}));
79 changes: 78 additions & 1 deletion crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,81 @@ var M;
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
M || (M = {});
_async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
p
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
mp
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
mp
];
});
}), _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2,
p
];
});
}), function(M) {
function _f1() {
return (_f1 = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
})).apply(this, arguments);
}
M.f1 = function() {
return _f1.apply(this, arguments);
};
}(M || (M = {}));
Loading
Loading