Skip to content

Commit

Permalink
feat(es/common): Introduce pure Span and BytePos to handle `#__PU…
Browse files Browse the repository at this point in the history
…RE__` (#9539)

**Related issue:**

- #9538
  • Loading branch information
magic-akari authored Sep 9, 2024
1 parent 12488da commit f63a481
Show file tree
Hide file tree
Showing 190 changed files with 962 additions and 2,180 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-houses-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_common: minor
---

feat(es/common): Introduce pure Span and BytePos to handle `#__PURE__`
2 changes: 0 additions & 2 deletions crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
),
Optional::new(
compat::es2022::es2022(
comments,
compat::es2022::Config {
class_properties: compat::es2022::class_properties::Config {
private_as_properties: assumptions.private_fields_as_properties,
Expand Down Expand Up @@ -271,7 +270,6 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
ignore_function_length: assumptions.ignore_function_length
},
},
comments,
self.unresolved_mark
),
should_enable(self.target, EsVersion::Es2017)
Expand Down
4 changes: 0 additions & 4 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,6 @@ impl ModuleConfig {
unresolved_mark,
config,
available_features,
comments,
))
} else {
let resolver = build_resolver(base_url, paths, config.resolve_fully);
Expand All @@ -1339,7 +1338,6 @@ impl ModuleConfig {
unresolved_mark,
config,
available_features,
comments,
))
}
}
Expand All @@ -1350,7 +1348,6 @@ impl ModuleConfig {
unresolved_mark,
config,
available_features,
comments,
))
} else {
let resolver = build_resolver(base_url, paths, config.config.resolve_fully);
Expand All @@ -1362,7 +1359,6 @@ impl ModuleConfig {
unresolved_mark,
config,
available_features,
comments,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
const SampleData = typedModel("SampleVideo", VideosSchema, undefined, undefined, {
byPlatform: function() {
byPlatform: /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*(platform) {
const result = yield this.find({
platform: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var obj = {
platform: platform
};
},
byPlatform: function() {
byPlatform: /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function(platform) {
var result;
return _ts_generator._(this, function(_state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function _scanUser() {
case 0:
return [
4,
Promise.all(groups.map(function() {
Promise.all(groups.map(/*#__PURE__*/ function() {
var _ref = _async_to_generator._(function(param) {
var users, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, user, err;
return _ts_generator._(this, function(_state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function scanUser(groups) {
}
function _scanUser() {
_scanUser = _async_to_generator._(function*(groups) {
yield Promise.all(groups.map(function() {
yield Promise.all(groups.map(/*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*({ users }) {
for (const user of users){
console.log("user", user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const _interop_require_default = require("@swc/helpers/_/_interop_require_defaul
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
function Foo() {
return /*#__PURE__*/ _react.default.createElement("div", {
onClick: function() {
onClick: /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*(e) {
yield doSomething();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
export var foo = function() {
export var foo = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
try {
Expand Down
10 changes: 5 additions & 5 deletions crates/swc/tests/fixture/issues-4xxx/4108/1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
import { Transaction } from "@solana/web3.js";
import { WalletNotConnectedError } from "@solana/wallet-adapter-base";
export var getErrorForTransaction = function() {
export var getErrorForTransaction = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function(connection, txid) {
var tx, errors;
return _ts_generator(this, function(_state) {
Expand Down Expand Up @@ -157,7 +157,7 @@ function _sendTransactionsWithManualRetry() {
});
return _sendTransactionsWithManualRetry.apply(this, arguments);
}
export var sendTransactions = function() {
export var sendTransactions = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function(connection, wallet, instructionSet, signersSet) {
var _loop, _loop1, sequenceType, commitment, successCallback, failCallback, block, beforeTransactions, afterTransactions, _unsignedTxns, unsignedTxns, i, partiallySignedTransactions, fullySignedTransactions, signedTxns, pendingTxns, i1, _ret, result, _tmp;
var _arguments = arguments;
Expand Down Expand Up @@ -364,7 +364,7 @@ export var sendTransactions = function() {
return _ref.apply(this, arguments);
};
}();
export var sendTransaction = function() {
export var sendTransaction = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function(connection, wallet, instructions, signers) {
var awaitConfirmation, commitment, includesFeePayer, block, transaction, _tmp, _transaction, _transaction1, _transaction2, rawTransaction, options, txid, slot, confirmation, errors;
var _arguments = arguments;
Expand Down Expand Up @@ -482,7 +482,7 @@ export var sendTransaction = function() {
return _ref.apply(this, arguments);
};
}();
export var sendTransactionWithRetry = function() {
export var sendTransactionWithRetry = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function(connection, wallet, instructions, signers) {
var commitment, includesFeePayer, block, beforeSend, transaction, _tmp, _transaction, _transaction1, _transaction2, _ref, txid, slot;
var _arguments = arguments;
Expand Down Expand Up @@ -777,7 +777,7 @@ function _awaitTransactionSignatureConfirmation() {
subId = 0;
return [
4,
new Promise(function() {
new Promise(/*#__PURE__*/ function() {
var _ref = _async_to_generator(function(resolve, reject) {
return _ts_generator(this, function(_state) {
switch(_state.label){
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-4xxx/4226/1/output/exec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import "reflect-metadata";
var v0 = function() {
var v0 = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function(v1) {
return _ts_generator(this, function(_state) {
return [
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-4xxx/4226/2/output/exec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import "reflect-metadata";
const v0 = function() {
const v0 = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function*(v1) {
return v1;
});
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-4xxx/4226/3/output/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
var _ts_generator = require("@swc/helpers/_/_ts_generator");
require("reflect-metadata");
var v0 = function() {
var v0 = /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function(v1) {
return _ts_generator._(this, function(_state) {
return [
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAD,AAAL;;gBAAMA;aAAAA;kCAAAA;mCAAAA;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;aAAAA;kCAAAA;mCAAAA;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"names": [
"Foo",
"bar",
Expand Down
10 changes: 5 additions & 5 deletions crates/swc/tests/fixture/issues-6xxx/6353/output/input.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
(function() {
/*#__PURE__*/ (function() {
var _ref = _async_to_generator._(function*(x) {
return 0;
});
return function(x) {
return _ref.apply(this, arguments);
};
})().x++;
(function() {
/*#__PURE__*/ (function() {
var _ref = _async_to_generator._(function*(x) {
return 0;
});
return function(x) {
return _ref.apply(this, arguments);
};
})().x--;
++function() {
++/*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*(x) {
return 0;
});
return function(x) {
return _ref.apply(this, arguments);
};
}().x;
--function() {
--/*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*(x) {
return 0;
});
return function(x) {
return _ref.apply(this, arguments);
};
}().x;
(function() {
/*#__PURE__*/ (function() {
var _ref = _async_to_generator._(function*(x) {
return 0;
});
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-6xxx/6730/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { _ as r } from "@swc/helpers/_/_async_to_generator";
export const styleLoader = ()=>{
return {
setup (t) {
t.onLoad(function() {
t.onLoad(/*#__PURE__*/ function() {
var t = r(function*(r) {});
return function(r) {
return t.apply(this, arguments);
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ let someFn = (xx, x, y)=>[
1,
2,
3
], goodFunction = function() {
], goodFunction = /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*() {
console.log(someFn(1, (yield getArray()), (yield getArray())));
});
return function() {
return _ref.apply(this, arguments);
};
}(), badFunction = function() {
}(), badFunction = /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*() {
console.log(someFn(1, (yield getArray()), (yield getArray())));
});
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-8xxx/8155/2/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const getArray = ()=>[
2,
3
];
const goodFunction = function() {
const goodFunction = /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*() {
const rb = yield getArray();
const rc = yield getArray();
Expand All @@ -18,7 +18,7 @@ const goodFunction = function() {
return _ref.apply(this, arguments);
};
}();
const badFunction = function() {
const badFunction = /*#__PURE__*/ function() {
var _ref = _async_to_generator._(function*() {
console.log(someFn(1, (yield getArray()), (yield getArray())));
});
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-8xxx/8375/1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _hello = require("./src/hello");
const _node = _interop_require_wildcard._(require("@sentry/node"));
const _node = /*#__PURE__*/ _interop_require_wildcard._(require("@sentry/node"));
_node;
(0, _hello.helloWorld)("SWC"); /*#__PURE__*/
(0, _hello.helloWorld)("SWC");
16 changes: 8 additions & 8 deletions crates/swc/tests/fixture/issues-9xxx/9527/output/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Base = function Base() {
};
;
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -24,7 +24,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -39,7 +39,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -55,7 +55,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -68,7 +68,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -82,7 +82,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -95,7 +95,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -109,7 +109,7 @@ expect(function() {
}(Base));
}).toThrow();
expect(function() {
return new /*#__PURE__*/ (function(Base) {
return new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand Down
8 changes: 4 additions & 4 deletions crates/swc/tests/fixture/issues-9xxx/9527/output/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Base = function Base() {
_class_call_check._(this, Base);
};
;
new /*#__PURE__*/ (function(Base) {
new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -17,7 +17,7 @@ new /*#__PURE__*/ (function(Base) {
}
return _class;
}(Base));
new /*#__PURE__*/ (function(Base) {
new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -29,7 +29,7 @@ new /*#__PURE__*/ (function(Base) {
}
return _class;
}(Base));
new /*#__PURE__*/ (function(Base) {
new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand All @@ -41,7 +41,7 @@ new /*#__PURE__*/ (function(Base) {
}
return _class;
}(Base));
new /*#__PURE__*/ (function(Base) {
new (/*#__PURE__*/ function(Base) {
"use strict";
_inherits._(_class, Base);
function _class() {
Expand Down
Loading

0 comments on commit f63a481

Please sign in to comment.