Skip to content

Commit

Permalink
fix(es/compat): Don't add pure annotations to dummy spans (#8172)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8155.
 - Closes #8173.
  • Loading branch information
kdy1 committed Oct 23, 2023
1 parent 7747dbd commit 9ceb57b
Show file tree
Hide file tree
Showing 41 changed files with 1,960 additions and 25 deletions.
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 = {}));

1 comment on commit 9ceb57b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 9ceb57b Previous: c26a225 Ratio
es/full/bugs-1 297970 ns/iter (± 7243) 297591 ns/iter (± 15876) 1.00
es/full/minify/libraries/antd 1427398240 ns/iter (± 16026126) 1418868535 ns/iter (± 19210989) 1.01
es/full/minify/libraries/d3 296284197 ns/iter (± 5188108) 293681257 ns/iter (± 947857) 1.01
es/full/minify/libraries/echarts 1142581354 ns/iter (± 18205769) 1125468958 ns/iter (± 9821259) 1.02
es/full/minify/libraries/jquery 89644058 ns/iter (± 238689) 89100441 ns/iter (± 364942) 1.01
es/full/minify/libraries/lodash 105349051 ns/iter (± 923866) 105560679 ns/iter (± 366341) 1.00
es/full/minify/libraries/moment 52882032 ns/iter (± 278327) 52471867 ns/iter (± 79387) 1.01
es/full/minify/libraries/react 19108447 ns/iter (± 639183) 18905262 ns/iter (± 187544) 1.01
es/full/minify/libraries/terser 233008526 ns/iter (± 1725639) 233453084 ns/iter (± 2025616) 1.00
es/full/minify/libraries/three 419360918 ns/iter (± 8984638) 414839760 ns/iter (± 2630087) 1.01
es/full/minify/libraries/typescript 2839524316 ns/iter (± 9903501) 2813695612 ns/iter (± 10647686) 1.01
es/full/minify/libraries/victory 627274999 ns/iter (± 11036912) 609167287 ns/iter (± 11730707) 1.03
es/full/minify/libraries/vue 127432693 ns/iter (± 243308) 127190271 ns/iter (± 496240) 1.00
es/full/codegen/es3 35188 ns/iter (± 409) 33369 ns/iter (± 75) 1.05
es/full/codegen/es5 35176 ns/iter (± 120) 33389 ns/iter (± 281) 1.05
es/full/codegen/es2015 35176 ns/iter (± 66) 33319 ns/iter (± 90) 1.06
es/full/codegen/es2016 35165 ns/iter (± 74) 33329 ns/iter (± 102) 1.06
es/full/codegen/es2017 35137 ns/iter (± 35) 33341 ns/iter (± 113) 1.05
es/full/codegen/es2018 35141 ns/iter (± 57) 33447 ns/iter (± 128) 1.05
es/full/codegen/es2019 35278 ns/iter (± 67) 33332 ns/iter (± 53) 1.06
es/full/codegen/es2020 35276 ns/iter (± 53) 33385 ns/iter (± 89) 1.06
es/full/all/es3 179778422 ns/iter (± 1090071) 176851152 ns/iter (± 1655263) 1.02
es/full/all/es5 172410368 ns/iter (± 1024060) 170574306 ns/iter (± 1166089) 1.01
es/full/all/es2015 130018732 ns/iter (± 1057600) 129207422 ns/iter (± 1533857) 1.01
es/full/all/es2016 128708929 ns/iter (± 1945213) 128333484 ns/iter (± 923435) 1.00
es/full/all/es2017 128164224 ns/iter (± 540931) 127794822 ns/iter (± 1129992) 1.00
es/full/all/es2018 126167606 ns/iter (± 835959) 125382985 ns/iter (± 698973) 1.01
es/full/all/es2019 125274437 ns/iter (± 803543) 125013938 ns/iter (± 1202019) 1.00
es/full/all/es2020 120825084 ns/iter (± 1319743) 121063117 ns/iter (± 1272673) 1.00
es/full/parser 558546 ns/iter (± 3304) 562074 ns/iter (± 3452) 0.99
es/full/base/fixer 19117 ns/iter (± 95) 17785 ns/iter (± 49) 1.07
es/full/base/resolver_and_hygiene 86604 ns/iter (± 129) 82619 ns/iter (± 623) 1.05

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.