file_path stringlengths 3 280 | file_language stringclasses 66 values | content stringlengths 1 1.04M | repo_name stringlengths 5 92 | repo_stars int64 0 154k | repo_description stringlengths 0 402 | repo_primary_language stringclasses 108 values | developer_username stringlengths 1 25 | developer_name stringlengths 0 30 | developer_company stringlengths 0 82 |
|---|---|---|---|---|---|---|---|---|---|
crates/swc_node_bundler/tests/pass/reexport/named-2-nested/input/a.js | JavaScript | export { b } from "./b";
console.log("a");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-2-nested/input/b.js | JavaScript | export { c as b } from "./c";
console.log("b");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-2-nested/input/c.js | JavaScript | export const c = 1;
console.log("c", c);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-2-nested/input/entry.js | JavaScript | export { b as a } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-2-nested/output/entry.js | JavaScript | const c = 1;
console.log("c", c);
console.log("b");
console.log("a");
export { c as a };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-3-var/input/a.js | JavaScript | export { b as a } from "./b";
console.log("a");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-3-var/input/b.js | JavaScript | export { c as b } from "./c";
console.log("b");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-3-var/input/c.js | JavaScript | export const c = 1;
console.log("c", c);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-3-var/input/entry.js | JavaScript | export { a } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-3-var/output/entry.js | JavaScript | const c = 1;
console.log("c", c);
console.log("b");
console.log("a");
export { c as a };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-4-fn/input/a.js | JavaScript | export { b } from "./b";
console.log("a");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-4-fn/input/b.js | JavaScript | export function b() {
console.log(b);
}
console.log("b", b);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-4-fn/input/entry.js | JavaScript | export { b as a } from "./a";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-4-fn/output/entry.js | JavaScript | function b() {
console.log(b);
}
console.log("b", b);
console.log("a");
export { b as a };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-5-class/input/a.js | JavaScript | export { b } from "./b";
console.log("a");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-5-class/input/b.js | JavaScript | export class b {}
console.log("b", b);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-5-class/input/entry.js | JavaScript | export { b as a } from "./a";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/named-5-class/output/entry.js | JavaScript | class b {
}
console.log("b", b);
console.log("a");
export { b as a };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-mini/input/a.js | JavaScript | export { d as b } from "./b";
console.log("a.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-mini/input/b.js | JavaScript | const d = 1;
export { d };
console.log("d");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-mini/input/entry.js | JavaScript | export { b } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-mini/output/entry.js | JavaScript | const d = 1;
console.log("d");
console.log("a.js");
export { d as b };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step1/input/a.js | JavaScript | export { default as b } from "./b";
console.log("a.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step1/input/b.js | JavaScript | import { c as b } from "./c";
export default b;
console.log("b");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step1/input/c.js | JavaScript | export const c = "c";
console.log("c");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step1/input/entry.js | JavaScript | export { b } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step1/output/entry.js | JavaScript | const c = "c";
console.log("c");
console.log("b");
console.log("a.js");
export { c as b };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/input/a.js | JavaScript | export { default as b } from "./b";
console.log("a.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/input/b.js | JavaScript | import { c as b } from "./c";
export default b;
console.log("b");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/input/c.js | JavaScript | export { d as c } from "./d";
console.log("c");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/input/d.js | JavaScript | const d = 1;
export { d };
console.log("d");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/input/entry.js | JavaScript | export { b } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive-step2/output/entry.js | JavaScript | const d = 1;
console.log("d");
console.log("c");
console.log("b");
console.log("a.js");
export { d as b };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/a.js | JavaScript | export { default as b } from "./b";
console.log("a.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/b.js | JavaScript | import { c as b } from "./c";
export default b;
console.log("b");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/c.js | JavaScript | export { d as c } from "./d";
console.log("c");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/d.js | JavaScript | import { e as d } from "./e";
export { d };
console.log("d");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/e.js | JavaScript | export const e = "e";
console.log("e");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/input/entry.js | JavaScript | export { b } from "./a";
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/reexport/recursive/output/entry.js | JavaScript | const e = "e";
console.log("e");
console.log("d");
console.log("c");
console.log("b");
console.log("a.js");
export { e as b };
console.log("entry");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/regenerator/1/input/entry.js | JavaScript | async function foo() {}
async function main() {
await foo();
}
console.log(main());
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/regenerator/1/output/entry.js | JavaScript | 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 _async_to_generator(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);
});
};
}
function _ts_generator(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
function foo() {
return _foo.apply(this, arguments);
}
function _foo() {
_foo = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
return [
2
];
});
});
return _foo.apply(this, arguments);
}
function main() {
return _main.apply(this, arguments);
}
function _main() {
_main = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
return [
4,
foo()
];
case 1:
_state.sent();
return [
2
];
}
});
});
return _main.apply(this, arguments);
}
console.log(main());
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/resolve-name-fix/input/entry.js | JavaScript | import assign from "core-js";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/swcrc/jsx/issue-884/input/entry.jsx | JavaScript (JSX) | /**
* Don't ask why it is named as divider.
*/
export const Divider = <div />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/swcrc/jsx/issue-884/output/entry.js | JavaScript | var Divider = React.createElement("div", null);
export { Divider as Divider };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/swcrc/jsx/issue-884/output/entry.jsx | JavaScript (JSX) | /**
* Don't ask why it is named as divider.
*/ export var Divider = React.createElement("div", null);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/a.js | JavaScript | export { c } from "./c";
export { d } from "./d";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/b.js | JavaScript | export const b = 1;
export { e } from "./e";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/c.js | JavaScript | export const c = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/d.js | JavaScript | export const d = 4;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/e.js | JavaScript | export const e = 5;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/input/entry.js | JavaScript | export * from "./a";
export * from "./b";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-1/output/entry.js | JavaScript | const c = 3;
const d = 4;
export { c as c };
export { d as d };
const e = 5;
const b = 1;
export { e as e };
export { b as b };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/a.js | JavaScript | export { c as d } from "./c";
export { d as c } from "./d";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/b.js | JavaScript | export const b = 1;
export { e as a } from "./e";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/c.js | JavaScript | export const c = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/d.js | JavaScript | export const d = 4;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/e.js | JavaScript | export const e = 5;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/input/entry.js | JavaScript | export * from "./a";
export * from "./b";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-all-2/output/entry.js | JavaScript | const c = 3;
const d = 4;
export { c as d };
export { d as c };
const e = 5;
const b = 1;
export { e as a };
export { b as b };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-named/input/a.js | JavaScript | export { foo, bar } from "./common";
export const baz = "from a.js";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-named/input/b.js | JavaScript | export { foo, baz } from "./common";
export const bar = "from b.js";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-named/input/common.js | JavaScript | const foo = 1;
const bar = 1;
const baz = 1;
export { foo, bar, baz };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-named/input/entry.js | JavaScript | export { foo, bar } from "./a";
export { baz } from "./b";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/export-named/output/entry.js | JavaScript | const foo = 1;
const bar = 1;
const baz = 1;
export { foo as foo, bar as bar };
export { baz as baz };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-1/input/a.js | JavaScript | import { common } from "./common";
console.log(common, "a.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-1/input/b.js | JavaScript | import { common } from "./common";
console.log(common, "b.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-1/input/common.js | JavaScript | export const common = 1;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-1/input/entry.js | JavaScript | import "./a";
import "./b";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-1/output/entry.js | JavaScript | const common = 1;
console.log(common, "a.js");
console.log(common, "b.js");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/a.js | JavaScript | import { common1 } from "./common1";
import { common2 } from "./common2";
console.log("a", common1, common2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/b.js | JavaScript | import { common3 } from "./common3";
import { common1 } from "./common1";
console.log("b", common3, common1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/c.js | JavaScript | import { common4 } from "./common4";
import { common2 } from "./common2";
import { common3 } from "./common3";
console.log("c", common4, common2, common3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/common1.js | JavaScript | export const common1 = 1;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/common2.js | JavaScript | const common = 2;
export { common as common2 };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/common3.js | JavaScript | export const common1 = "Test failed :(";
const common3 = 3;
export { common3 };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/common4.js | JavaScript | var common4;
try {
common4 = 4;
} catch (e) {}
export { common4 };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/input/entry.js | JavaScript | import "./a";
import "./b";
import "./c";
import "./common3";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/transitive/import/simple-2/output/entry.js | JavaScript | const common1 = 1;
const common = 2;
console.log("a", common1, common);
const common3 = 3;
console.log("b", common3, common1);
var common4;
try {
common4 = 4;
} catch (e) {}
console.log("c", common4, common, common3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/in-module-export/input/entry.js | JavaScript | const a = 1;
const b = 1;
export const foo = b;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/in-module-export/output/entry.js | JavaScript | const b = 1;
const foo = b;
export { foo as foo };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/in-module/input/entry.js | JavaScript | const foo = 1;
let a = 2;
{
let a = 3;
}
console.log(a);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/in-module/output/entry.js | JavaScript | let a = 2;
console.log(a);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/preserve-import/input/b.js | JavaScript | export function b() {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/preserve-import/input/entry-a.js | JavaScript | import { b } from "./b";
b();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_bundler/tests/pass/tree-shaking/preserve-import/output/entry-a.js | JavaScript | function b() {}
b();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_node_comments/src/lib.rs | Rust | #![cfg_attr(test, deny(warnings))]
use std::sync::Arc;
use dashmap::DashMap;
use rustc_hash::FxBuildHasher;
use swc_atoms::atom;
use swc_common::{
comments::{Comment, CommentKind, Comments},
BytePos, DUMMY_SP,
};
type CommentMap = Arc<DashMap<BytePos, Vec<Comment>, FxBuildHasher>>;
/// Multi-threaded implementation of [Comments]
#[derive(Clone, Default)]
pub struct SwcComments {
pub leading: CommentMap,
pub trailing: CommentMap,
}
impl Comments for SwcComments {
fn add_leading(&self, pos: BytePos, cmt: Comment) {
self.leading.entry(pos).or_default().push(cmt);
}
fn add_leading_comments(&self, pos: BytePos, comments: Vec<Comment>) {
self.leading.entry(pos).or_default().extend(comments);
}
fn has_leading(&self, pos: BytePos) -> bool {
if let Some(v) = self.leading.get(&pos) {
!v.is_empty()
} else {
false
}
}
fn move_leading(&self, from: BytePos, to: BytePos) {
let cmt = self.take_leading(from);
if let Some(mut cmt) = cmt {
if from < to && self.has_leading(to) {
cmt.extend(self.take_leading(to).unwrap());
}
self.add_leading_comments(to, cmt);
}
}
fn take_leading(&self, pos: BytePos) -> Option<Vec<Comment>> {
self.leading.remove(&pos).map(|v| v.1)
}
fn get_leading(&self, pos: BytePos) -> Option<Vec<Comment>> {
self.leading.get(&pos).map(|v| v.to_owned())
}
fn add_trailing(&self, pos: BytePos, cmt: Comment) {
self.trailing.entry(pos).or_default().push(cmt)
}
fn add_trailing_comments(&self, pos: BytePos, comments: Vec<Comment>) {
self.trailing.entry(pos).or_default().extend(comments)
}
fn has_trailing(&self, pos: BytePos) -> bool {
if let Some(v) = self.trailing.get(&pos) {
!v.is_empty()
} else {
false
}
}
fn move_trailing(&self, from: BytePos, to: BytePos) {
let cmt = self.take_trailing(from);
if let Some(mut cmt) = cmt {
if from < to && self.has_trailing(to) {
cmt.extend(self.take_trailing(to).unwrap());
}
self.add_trailing_comments(to, cmt);
}
}
fn take_trailing(&self, pos: BytePos) -> Option<Vec<Comment>> {
self.trailing.remove(&pos).map(|v| v.1)
}
fn get_trailing(&self, pos: BytePos) -> Option<Vec<Comment>> {
self.trailing.get(&pos).map(|v| v.to_owned())
}
fn add_pure_comment(&self, pos: BytePos) {
let mut leading = self.leading.entry(pos).or_default();
let pure_comment = Comment {
kind: CommentKind::Block,
span: DUMMY_SP,
text: atom!("#__PURE__"),
};
if !leading.iter().any(|c| c.text == pure_comment.text) {
leading.push(pure_comment);
}
}
fn with_leading<F, Ret>(&self, pos: BytePos, f: F) -> Ret
where
Self: Sized,
F: FnOnce(&[Comment]) -> Ret,
{
let ret = if let Some(cmts) = self.leading.get(&pos) {
f(&cmts)
} else {
f(&[])
};
ret
}
fn with_trailing<F, Ret>(&self, pos: BytePos, f: F) -> Ret
where
Self: Sized,
F: FnOnce(&[Comment]) -> Ret,
{
let ret = if let Some(cmts) = &self.trailing.get(&pos) {
f(cmts)
} else {
f(&[])
};
ret
}
fn has_flag(&self, lo: BytePos, flag: &str) -> bool {
self.with_leading(lo, |comments| {
for c in comments {
if c.kind == CommentKind::Block {
for line in c.text.lines() {
// jsdoc
let line = line.trim_start_matches(['*', ' ']);
let line = line.trim();
//
if line.len() == (flag.len() + 5)
&& (line.starts_with("#__") || line.starts_with("@__"))
&& line.ends_with("__")
&& flag == &line[3..line.len() - 2]
{
return true;
}
}
}
}
false
})
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_nodejs_common/src/lib.rs | Rust | #![deny(warnings)]
use std::any::type_name;
use anyhow::Context;
use napi::Status;
use serde::de::DeserializeOwned;
pub trait MapErr<T>: Into<Result<T, anyhow::Error>> {
fn convert_err(self) -> napi::Result<T> {
self.into()
.map_err(|err| napi::Error::new(Status::GenericFailure, format!("{:?}", err)))
}
}
impl<T> MapErr<T> for Result<T, anyhow::Error> {}
pub fn get_deserialized<T, B>(buffer: B) -> napi::Result<T>
where
T: DeserializeOwned,
B: AsRef<[u8]>,
{
let mut deserializer = serde_json::Deserializer::from_slice(buffer.as_ref());
deserializer.disable_recursion_limit();
let v = T::deserialize(&mut deserializer)
.with_context(|| {
format!(
"Failed to deserialize buffer as {}\nJSON: {}",
type_name::<T>(),
String::from_utf8_lossy(buffer.as_ref())
)
})
.convert_err()?;
Ok(v)
}
pub fn deserialize_json<T>(json: &str) -> Result<T, serde_json::Error>
where
T: DeserializeOwned,
{
let mut deserializer = serde_json::Deserializer::from_str(json);
deserializer.disable_recursion_limit();
T::deserialize(&mut deserializer)
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_parallel/src/items.rs | Rust | use self::private::Sealed;
mod private {
pub trait Sealed {}
impl<T> Sealed for Vec<T> {}
impl<T> Sealed for &mut Vec<T> {}
impl<T> Sealed for &mut [T] {}
impl<T> Sealed for &[T] {}
}
pub trait IntoItems: Sealed {
type Elem;
type Items: Items<Elem = Self::Elem>;
fn into_items(self) -> Self::Items;
}
impl<T, I> IntoItems for I
where
I: Items<Elem = T>,
{
type Elem = T;
type Items = I;
fn into_items(self) -> Self::Items {
self
}
}
impl<'a, T> IntoItems for &'a mut Vec<T>
where
T: Send + Sync,
{
type Elem = &'a mut T;
type Items = &'a mut [T];
fn into_items(self) -> Self::Items {
self
}
}
/// This is considered as a private type and it's NOT A PUBLIC API.
#[allow(clippy::len_without_is_empty)]
pub trait Items: Sized + IntoIterator<Item = Self::Elem> + Send + Sealed {
type Elem: Send + Sync;
fn len(&self) -> usize;
fn split_at(self, idx: usize) -> (Self, Self);
}
impl<T> Items for Vec<T>
where
T: Send + Sync,
{
type Elem = T;
fn len(&self) -> usize {
Vec::len(self)
}
fn split_at(mut self, at: usize) -> (Self, Self) {
let b = self.split_off(at);
(self, b)
}
}
impl<'a, T> Items for &'a mut [T]
where
T: Send + Sync,
{
type Elem = &'a mut T;
fn len(&self) -> usize {
<[T]>::len(self)
}
fn split_at(self, at: usize) -> (Self, Self) {
let (a, b) = self.split_at_mut(at);
(a, b)
}
}
impl<'a, T> Items for &'a [T]
where
T: Send + Sync,
{
type Elem = &'a T;
fn len(&self) -> usize {
<[T]>::len(self)
}
fn split_at(self, at: usize) -> (Self, Self) {
let (a, b) = self.split_at(at);
(a, b)
}
}
//
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_parallel/src/lib.rs | Rust | #![cfg_attr(not(feature = "parallel"), allow(unused_variables))]
use std::{cell::RefCell, mem::transmute};
pub mod items;
pub mod merge;
#[derive(Default)]
pub struct MaybeScope<'a>(ScopeLike<'a>);
enum ScopeLike<'a> {
Scope(Scope<'a>),
#[cfg(feature = "parallel")]
Global(Option<chili::Scope<'a>>),
}
impl Default for ScopeLike<'_> {
fn default() -> Self {
#[cfg(feature = "parallel")]
{
ScopeLike::Global(None)
}
#[cfg(not(feature = "parallel"))]
{
ScopeLike::Scope(Scope(std::marker::PhantomData))
}
}
}
impl<'a> From<Scope<'a>> for MaybeScope<'a> {
fn from(value: Scope<'a>) -> Self {
MaybeScope(ScopeLike::Scope(value))
}
}
impl<'a> MaybeScope<'a> {
#[allow(clippy::redundant_closure)]
pub fn with<F, R>(&mut self, f: F) -> R
where
F: FnOnce(Scope<'a>) -> R,
{
#[cfg(feature = "parallel")]
let scope: &mut chili::Scope = match &mut self.0 {
ScopeLike::Scope(scope) => unsafe {
// Safety: chili Scope will be alive until the end of the function, because it's
// contract of 'a lifetime in the type.
transmute::<&mut chili::Scope, &mut chili::Scope>(&mut scope.0)
},
#[cfg(feature = "parallel")]
ScopeLike::Global(global_scope) => {
// Initialize global scope lazily, and only once.
let scope = global_scope.get_or_insert_with(|| chili::Scope::global());
unsafe {
// Safety: Global scope is not dropped until the end of the program, and no one
// can access this **instance** of the global scope in the same time.
transmute::<&mut chili::Scope, &mut chili::Scope>(scope)
}
}
};
#[cfg(feature = "parallel")]
let scope = Scope(scope);
#[cfg(not(feature = "parallel"))]
let scope = Scope(std::marker::PhantomData);
f(scope)
}
}
#[cfg(not(feature = "parallel"))]
pub struct Scope<'a>(std::marker::PhantomData<&'a ()>);
#[cfg(feature = "parallel")]
pub struct Scope<'a>(&'a mut chili::Scope<'a>);
#[inline]
pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: Send + FnOnce() -> RA,
B: Send + FnOnce() -> RB,
RA: Send,
RB: Send,
{
thread_local! {
static SCOPE: RefCell<Option<MaybeScope<'static>>> = Default::default();
}
struct RemoveScopeGuard;
impl Drop for RemoveScopeGuard {
fn drop(&mut self) {
SCOPE.set(None);
}
}
let mut scope = SCOPE.take().unwrap_or_default();
let (ra, rb) = join_maybe_scoped(
&mut scope,
|scope| {
let scope = unsafe {
// Safety: inner scope cannot outlive the outer scope
transmute::<Scope, Scope>(scope)
};
let _guard = RemoveScopeGuard;
SCOPE.set(Some(MaybeScope(ScopeLike::Scope(scope))));
oper_a()
},
|scope| {
let scope = unsafe {
// Safety: inner scope cannot outlive the outer scope
transmute::<Scope, Scope>(scope)
};
let _guard = RemoveScopeGuard;
SCOPE.set(Some(MaybeScope(ScopeLike::Scope(scope))));
oper_b()
},
);
// In case of panic, we does not restore the scope so it will be None.
SCOPE.set(Some(scope));
(ra, rb)
}
#[inline]
pub fn join_maybe_scoped<'a, A, B, RA, RB>(
scope: &mut MaybeScope<'a>,
oper_a: A,
oper_b: B,
) -> (RA, RB)
where
A: Send + FnOnce(Scope<'a>) -> RA,
B: Send + FnOnce(Scope<'a>) -> RB,
RA: Send,
RB: Send,
{
scope.with(|scope| join_scoped(scope, oper_a, oper_b))
}
#[inline]
pub fn join_scoped<'a, A, B, RA, RB>(scope: Scope<'a>, oper_a: A, oper_b: B) -> (RA, RB)
where
A: Send + FnOnce(Scope<'a>) -> RA,
B: Send + FnOnce(Scope<'a>) -> RB,
RA: Send,
RB: Send,
{
#[cfg(feature = "parallel")]
let (ra, rb) = scope.0.join(
|scope| {
let scope = Scope(unsafe {
// Safety: This can be dangerous if the user do transmute on the scope, but it's
// not our fault if the user uses transmute.
transmute::<&mut chili::Scope, &mut chili::Scope>(scope)
});
oper_a(scope)
},
|scope| {
let scope = Scope(unsafe {
// Safety: This can be dangerous if the user do transmute on the scope, but it's
// not our fault if the user uses transmute.
transmute::<&mut chili::Scope, &mut chili::Scope>(scope)
});
oper_b(scope)
},
);
#[cfg(not(feature = "parallel"))]
let (ra, rb) = (
oper_a(Scope(std::marker::PhantomData)),
oper_b(Scope(std::marker::PhantomData)),
);
(ra, rb)
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_parallel/src/merge.rs | Rust | use std::{
collections::{hash_map, HashMap},
hash::{BuildHasher, Hash},
};
use crate::join;
pub fn merge_in_parallel<T: Merge>(mut items: Vec<T>) -> T {
assert!(!items.is_empty());
if items.len() == 1 {
return items.into_iter().next().unwrap();
}
let b = items.split_off(items.len() / 2);
let (mut a, b) = join(
move || merge_in_parallel(items),
move || merge_in_parallel(b),
);
a.merge(b);
a
}
/// Used to merge in parallel.
pub trait Merge: Send {
fn merge(&mut self, other: Self);
}
impl<K, V, S> Merge for HashMap<K, V, S>
where
Self: Send,
K: Hash + Eq,
V: Merge,
S: BuildHasher,
{
fn merge(&mut self, other: Self) {
self.reserve(other.len());
for (k, val) in other {
match self.entry(k) {
hash_map::Entry::Occupied(mut o) => o.get_mut().merge(val),
hash_map::Entry::Vacant(v) => {
v.insert(val);
}
}
}
}
}
#[cfg(feature = "indexmap")]
impl<K, V, S> Merge for indexmap::IndexMap<K, V, S>
where
Self: Send,
K: Eq + Hash,
V: Merge,
S: BuildHasher,
{
fn merge(&mut self, other: Self) {
self.reserve(other.len());
for (k, v) in other {
match self.entry(k) {
indexmap::map::Entry::Occupied(mut e) => {
e.get_mut().merge(v);
}
indexmap::map::Entry::Vacant(e) => {
e.insert(v);
}
}
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_parallel/tests/simulate.rs | Rust | use std::{
sync::{Arc, Mutex},
thread::{self, sleep},
time::Duration,
};
use swc_parallel::{items::Items, join};
#[derive(Default)]
struct Context {
sum: usize,
atoms: Vec<hstr::Atom>,
}
impl Parallel for Context {
fn create(&self) -> Self {
Context::default()
}
fn merge(&mut self, other: Self) {
self.sum += other.sum;
}
}
#[test]
fn case_1_single_thread() {
STATE.set(&State::default(), || {
sum_in_parallel(10000);
});
}
#[test]
fn case_2_wait_for() {
STATE.set(&State::default(), || {
let threads = 100;
let mut handles = vec![];
for _ in 0..threads {
handles.push(thread::spawn(move || {
STATE.set(&Default::default(), || sum_in_parallel(10000));
}));
}
sleep(Duration::from_secs(1));
for handle in handles {
handle.join().unwrap();
}
});
}
#[test]
fn case_3_early_exit_of_entry() {
STATE.set(&State::default(), || {
let threads = 100;
let mut handles = vec![];
for _ in 0..threads {
handles.push(thread::spawn(move || {
sleep(Duration::from_secs(1));
STATE.set(&Default::default(), || sum_in_parallel(10000));
}));
}
for handle in handles {
handle.join().unwrap();
}
});
}
#[test]
fn case_4_explode() {
STATE.set(&State::default(), || {
let threads = 100;
let mut handles = vec![];
for _ in 0..threads {
handles.push(thread::spawn(move || {
sleep(Duration::from_secs(1));
for _ in 0..10 {
spawn_work();
}
}));
}
for handle in handles {
handle.join().unwrap();
}
});
}
#[derive(Default)]
struct State {
arc: Arc<Mutex<usize>>,
}
scoped_tls::scoped_thread_local!(static STATE: State);
fn spawn_work() {
let _handle = thread::spawn(move || {
sleep(Duration::from_secs(1));
STATE.set(&State::default(), || sum_in_parallel(10000));
});
}
fn sum_in_parallel(to: usize) {
let items = (0..to).collect::<Vec<_>>();
let mut ctx = Context::default();
maybe_par_idx_raw(&mut ctx, items, &|ctx, _idx, n| {
if n % 100 == 0 {
STATE.with(|state| {
let mut guard = state.arc.lock().unwrap();
*guard += 1;
});
}
if n % 50 == 0 {
ctx.atoms.push(hstr::Atom::from(n.to_string()));
}
ctx.sum += n;
});
assert_eq!(ctx.sum, to * (to - 1) / 2);
}
pub trait Parallel: Send + Sync {
/// Used to create visitor.
fn create(&self) -> Self;
/// This can be called in anytime.
fn merge(&mut self, other: Self);
}
fn maybe_par_idx_raw<C, I, F>(ctx: &mut C, nodes: I, op: &F)
where
C: Parallel,
I: Items,
F: Send + Sync + Fn(&mut C, usize, I::Elem),
{
let len = nodes.len();
if len == 0 {
return;
}
if len == 1 {
op(ctx, 0, nodes.into_iter().next().unwrap());
return;
}
let (na, nb) = nodes.split_at(len / 2);
let (va, vb) = STATE.with(|state| {
join(
|| {
STATE.set(state, || {
let mut new_ctx = ctx.create();
maybe_par_idx_raw(&mut new_ctx, na, op);
new_ctx
})
},
|| {
STATE.set(state, || {
let mut new_ctx = ctx.create();
maybe_par_idx_raw(&mut new_ctx, nb, op);
new_ctx
})
},
)
});
ctx.merge(va);
ctx.merge(vb);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin/scripts/cli.sh | Shell | #!/usr/bin/env bash
set -eu
cargo install --path ./cli
(cd plugins && swc-dev $@) | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin/scripts/test.sh | Shell | #!/usr/bin/env bash
## This script assumes `plugins` is in `$CDPATH`
set -eu
(cd plugins && cargo build && ls -al target/debug)
export PLUGINS_DIR=$(cd plugins > /dev/null && pwd)
echo "Using plugins at $PLUGINS_DIR"
(cd runner && cargo test) | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin/src/allocation.rs | Rust | use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
/// Allocate bytes that won't be dropped by the allocator.
/// Return the pointer to the leaked allocation so the host can write to it.
///
/// Note: Can be bit confusing but alloc / free should be called in host even
/// though this fn is exposed in plugin binary: Host owns responsibility to
/// allocate / free memory space in wasm
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
#[no_mangle]
#[inline(always)]
pub extern "C" fn __alloc(size: i32) -> *mut u8 {
// create a new mutable buffer with specified capacity
let mut buf = Vec::with_capacity(size as usize);
// take a mutable pointer to the buffer
let ptr = buf.as_mut_ptr();
// take ownership of the memory block and
// ensure the its destructor is not
// called when the object goes out of scope
// at the end of the function
std::mem::forget(buf);
// return the pointer so the runtime
// can write data at this offset
ptr
}
/// Free previously allocated memory via __alloc.
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
#[no_mangle]
#[inline(always)]
pub extern "C" fn __free(ptr: *mut u8, size: i32) -> i32 {
let data = unsafe { Vec::from_raw_parts(ptr, size as usize, size as usize) };
std::mem::drop(data);
0 as _
}
/// Allocates memory area of specified size and returns its address.
/// Returns 0 if supplied size is too long.
/// [TODO]: This is for the experiment to alloc memory with specified layout instead of
/// manually creating Vec::new() and forget it. This is not used yet.
#[doc(hidden)]
#[cfg(all(target_arch = "wasm32", feature = "layout_alloc"))]
#[no_mangle]
#[inline(always)]
pub unsafe fn __alloc(size: usize) -> usize {
let layout = match Layout::from_size_align(size as usize, std::mem::align_of::<u8>()) {
Ok(layout) => layout,
// in this case a err may occur only in a case of too long allocated size,
// so just return 0
Err(_) => return 0 as _,
};
unsafe { global_alloc(layout) as _ }
}
/// Deallocates memory area for provided memory pointer and size.
/// Does nothing if supplied size is too long.
/// [TODO]: This is for the experiment to free memory with specified layout with explicit
/// dealloc instead of dropping it. This is not used yet.
#[doc(hidden)]
#[cfg(all(target_arch = "wasm32", feature = "layout_alloc"))]
#[no_mangle]
#[inline(always)]
pub unsafe fn __free(ptr: *mut u8, size: usize) {
let layout = match Layout::from_size_align(size as usize, std::mem::align_of::<u8>()) {
Ok(layout) => layout,
// in this case a err may occur only in a case of too long allocated size,
// so just done nothing
Err(_) => return 0 as _,
};
unsafe {
global_dealloc(ptr, layout);
}
0 as _
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin/src/lib.rs | Rust | #![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(target_arch = "wasm32")]
pub mod allocation;
pub mod pseudo_scoped_key;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin/src/pseudo_scoped_key.rs | Rust | use once_cell::sync::OnceCell;
/// Simple substitution for scoped_thread_local with limited interface parity.
///
/// The only available fn in this struct is `with`, which is being used for the
/// consumers when they need to access global scope handler (HANDLER.with()).
/// Any other interfaces to support thread local is not available.
pub struct PseudoScopedKey<T> {
// As we can't use scoped_thread_local for the global HANDLER, it is challenging
// to set its inner handler for each plugin scope's diagnostic emitter.
// Via lazy init OnceCell we keep static HANDLER as immutable, also allows to set
// plugin specific values when proc_macro expands plugin's transform helper.
pub inner: OnceCell<T>,
}
impl<T> PseudoScopedKey<T> {
pub fn with<F, R>(&self, f: F) -> R
where
F: FnOnce(&T) -> R,
{
f(self.inner.get().expect("Should set handler before call"))
}
}
// This is to conform some of swc_common::errors::Handler's thread-safety
// required properties.
//
// NOTE: This only works cause we know each plugin transform doesn't need any
// thread safety. However, if wasm gets thread support and if we're going to
// support it this should be revisited.
unsafe impl<T> std::marker::Sync for PseudoScopedKey<T> {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin_macro/src/lib.rs | Rust | extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::quote;
use syn::{Item as SynItem, ItemFn};
#[proc_macro_attribute]
pub fn plugin_transform(
_args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let token = proc_macro2::TokenStream::from(input);
let parsed_results = syn::parse2::<SynItem>(token).expect("Failed to parse tokens");
match parsed_results {
SynItem::Fn(func) => handle_func(func, Ident::new("Program", Span::call_site())),
_ => panic!("Please confirm if plugin macro is specified for the function"),
}
}
#[proc_macro_attribute]
pub fn css_plugin_transform(
_args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let token = proc_macro2::TokenStream::from(input);
let parsed_results = syn::parse2::<SynItem>(token).expect("Failed to parse tokens");
match parsed_results {
SynItem::Fn(func) => handle_func(func, Ident::new("Stylesheet", Span::call_site())),
_ => panic!("Please confirm if plugin macro is specified for the function"),
}
}
#[allow(clippy::redundant_clone)]
fn handle_func(func: ItemFn, ast_type: Ident) -> TokenStream {
let ident = func.sig.ident.clone();
let transform_process_impl_ident =
Ident::new("__transform_plugin_process_impl", Span::call_site());
let transform_core_pkg_diag_ident =
Ident::new("__get_transform_plugin_core_pkg_diag", Span::call_site());
let ret = quote! {
#func
// Declaration for imported function from swc host.
// Refer swc_plugin_runner for the actual implementation.
#[cfg(target_arch = "wasm32")] // Allow testing
extern "C" {
fn __set_transform_result(bytes_ptr: u32, bytes_ptr_len: u32);
fn __set_transform_plugin_core_pkg_diagnostics(bytes_ptr: u32, bytes_ptr_len: u32);
fn __emit_diagnostics(bytes_ptr: u32, bytes_ptr_len: u32);
}
/// An emitter for the Diagnostic in plugin's context by borrowing host's
/// environment context.
///
/// It is not expected to call this directly inside of plugin transform.
/// Instead, it is encouraged to use global HANDLER.
pub struct PluginDiagnosticsEmitter;
impl swc_core::common::errors::Emitter for PluginDiagnosticsEmitter {
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
fn emit(&mut self, db: &swc_core::common::errors::DiagnosticBuilder<'_>) {
let diag = swc_core::common::plugin::serialized::PluginSerializedBytes::try_serialize(&swc_core::common::plugin::serialized::VersionedSerializable::new(*db.diagnostic.clone()))
.expect("Should able to serialize Diagnostic");
let (ptr, len) = diag.as_ptr();
#[cfg(target_arch = "wasm32")] // Allow testing
unsafe {
__emit_diagnostics(ptr as u32, len as u32);
}
}
}
/// Call hosts's imported fn to set transform results.
/// __set_transform_result is host side imported fn, which read and copies guest's byte into host.
fn send_transform_result_to_host(bytes_ptr: u32, bytes_ptr_len: u32) {
#[cfg(target_arch = "wasm32")] // Allow testing
unsafe {
__set_transform_result(bytes_ptr, bytes_ptr_len);
}
}
/// Internal function plugin_macro uses to create ptr to PluginError.
fn construct_error_ptr(plugin_error: swc_core::common::plugin::serialized::PluginError) -> u32 {
let ret = swc_core::common::plugin::serialized::PluginSerializedBytes::try_serialize(&swc_core::common::plugin::serialized::VersionedSerializable::new(plugin_error)).expect("Should able to serialize PluginError");
let (ptr, len) = ret.as_ptr();
send_transform_result_to_host(
ptr as _,
len as u32
);
1
}
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn #transform_core_pkg_diag_ident() -> u32 {
let schema_version = swc_core::common::plugin::PLUGIN_TRANSFORM_AST_SCHEMA_VERSION;
let core_pkg_diag = swc_core::diagnostics::get_core_engine_diagnostics();
let result = swc_core::common::plugin::diagnostics::PluginCorePkgDiagnostics {
ast_schema_version: schema_version,
pkg_version: core_pkg_diag.package_semver,
git_sha: core_pkg_diag.git_sha,
cargo_features: core_pkg_diag.cargo_features,
};
let serialized_result = swc_core::common::plugin::serialized::PluginSerializedBytes::try_serialize(
&swc_core::common::plugin::serialized::VersionedSerializable::new(result)
).expect("Diagnostics should be always serializable");
let (serialized_result_ptr, serialized_result_ptr_len) = serialized_result.as_ptr();
#[cfg(target_arch = "wasm32")] // Allow testing
unsafe {
__set_transform_plugin_core_pkg_diagnostics(serialized_result_ptr as _, serialized_result_ptr_len as u32);
}
0
}
// Macro to allow compose plugin's transform function without manual pointer operation.
// Internally it wraps pointer operation also bubbles up error in forms of PluginError.
// There are some cases error won't be wrapped up however - for example, we expect
// serialization of PluginError itself should succeed.
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn #transform_process_impl_ident(
ast_ptr: *const u8, ast_ptr_len: u32,
unresolved_mark: u32, should_enable_comments_proxy: i32) -> u32 {
// Reconstruct `Program` & config string from serialized program
// Host (SWC) should allocate memory, copy bytes and pass ptr to plugin.
let program = swc_core::common::plugin::serialized::PluginSerializedBytes::from_raw_ptr(ast_ptr, ast_ptr_len.try_into().expect("Should able to convert ptr length")).deserialize();
if program.is_err() {
let err = swc_core::common::plugin::serialized::PluginError::Deserialize("Failed to deserialize program received from host".to_string());
return construct_error_ptr(err);
}
let program: #ast_type = program.expect("Should be a program").into_inner();
// Create a handler wired with plugin's diagnostic emitter, set it for global context.
let handler = swc_core::common::errors::Handler::with_emitter(
true,
false,
Box::new(PluginDiagnosticsEmitter)
);
// Construct metadata to the `Program` for the transform plugin.
let plugin_comments_proxy = if should_enable_comments_proxy == 1 { Some(swc_core::plugin::proxies::PluginCommentsProxy) } else { None };
let mut metadata = swc_core::plugin::metadata::TransformPluginProgramMetadata {
comments: plugin_comments_proxy,
source_map: swc_core::plugin::proxies::PluginSourceMapProxy { source_file: swc_core::common::sync::OnceCell::new() },
unresolved_mark: swc_core::common::Mark::from_u32(unresolved_mark as u32),
};
// Take original plugin fn ident, then call it with interop'ed args
let transformed_program = swc_core::common::plugin::serialized::VersionedSerializable::new(swc_core::common::errors::HANDLER.set(&handler, || {
#ident(program, metadata)
}));
// Serialize transformed result, return back to the host.
let serialized_result = swc_core::common::plugin::serialized::PluginSerializedBytes::try_serialize(
&transformed_program
);
if serialized_result.is_err() {
let err = swc_core::common::plugin::serialized::PluginError::Serialize("Failed to serialize transformed program".to_string());
return construct_error_ptr(err);
}
let serialized_result = serialized_result.expect("Should be a realized transformed program");
let (serialized_result_ptr, serialized_result_ptr_len) = serialized_result.as_ptr();
send_transform_result_to_host(serialized_result_ptr as _, serialized_result_ptr_len as u32);
0
}
};
ret.into()
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin_proxy/src/comments/host_comments_storage.rs | Rust | /// A struct to internally store current file's comments for the
/// transform plugins.
///
/// This storage is introduced to conform with existing design to the comments,
/// specifically `SingleThreadedComments`. It doesn't support thread-safety
/// which does not allow to be passed into wasmerEnv (HostEnvironment). A scoped
/// tls holds inner comments as global, per each transform execution. Refer
/// `swc_plugin::transform_execytor::TransformExecutor::transform` for the
/// responsibility to manage actual data.
///
/// Should never attempt to use this other than plugin_runner.
// TODO: This storage does not support mutable yet
#[cfg(feature = "__plugin_rt")]
pub struct HostCommentsStorage {
pub inner: Option<swc_common::comments::SingleThreadedComments>,
}
#[cfg(feature = "__plugin_rt")]
better_scoped_tls::scoped_tls!(
pub static COMMENTS: HostCommentsStorage
);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_plugin_proxy/src/comments/mod.rs | Rust | mod host_comments_storage;
mod plugin_comments_proxy;
#[cfg(feature = "__plugin_rt")]
pub use host_comments_storage::{HostCommentsStorage, COMMENTS};
#[cfg(feature = "__plugin_mode")]
pub use plugin_comments_proxy::PluginCommentsProxy;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.