Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ imports_granularity = "Crate"
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true
edition = "2018"
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/binding_core_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ plugin = [
"wasmer-wasi",
"wasmer/js-default",
"wasmer-wasi/js-default",
"js-sys",
]

[dependencies]
anyhow = "1.0.58"
console_error_panic_hook = "0.1.7"
js-sys = { version = "0.3.59", optional = true }
js-sys = { version = "0.3.59" }
once_cell = "1.13.0"
parking_lot_core = "0.9.3"
path-clean = "0.1.0"
Expand All @@ -49,6 +48,7 @@ wasm-bindgen = { version = "0.2.82", features = [
"serde-serialize",
"enable-interning",
] }
wasm-bindgen-futures = "0.4.32"
wasmer = { version = "2.3.0", optional = true, default-features = false }
wasmer-wasi = { version = "2.3.0", optional = true, default-features = false }

Expand Down
267 changes: 241 additions & 26 deletions crates/binding_core_wasm/__tests__/simple.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,248 @@
const swc = require("../pkg");

it("should be loadable", function () {
const output = swc.transformSync("class Foo {}", {});
describe("transform", () => {
it("should work", function () {
const output = swc.transformSync("class Foo {}", {});

expect(output).toMatchInlineSnapshot(`
Object {
"code": "function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError(\\"Cannot call a class as a function\\");
}
}
var Foo = function Foo() {
\\"use strict\\";
_classCallCheck(this, Foo);
};
",
}
`);
});

it("should work with async facade", async () => {
const output = await swc.transform("class Foo {}", {});

expect(output).toMatchInlineSnapshot(`
Object {
"code": "function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError(\\"Cannot call a class as a function\\");
}
}
var Foo = function Foo() {
\\"use strict\\";
_classCallCheck(this, Foo);
};
",
}
`);
});

it("should work with program object", async () => {
const input = swc.parseSync("class Foo {}", {
syntax: "typescript",
target: "es2021",
});

const output = await swc.transform(input, {});
expect(output).toMatchInlineSnapshot(`
Object {
"code": "function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError(\\"Cannot call a class as a function\\");
}
}
var Foo = function Foo() {
\\"use strict\\";
_classCallCheck(this, Foo);
};
",
}
`);
});

it("should support 'paths' and 'baseUrl'", () => {
const { code } = swc.transformSync(
`
import foo from '@src/app';
console.log(foo)
`,
{
filename: "main.js",
jsc: {
parser: {
syntax: "typescript",
},
target: "es2021",
transform: {},
baseUrl: __dirname,
paths: {
"@src/*": ["bar/*"],
},
},
module: {
type: "commonjs",
},
}
);

expect(code).toContain(`bar/app`);
});
});

it("should support 'paths' and 'baseUrl'", async () => {
const { code } = await swc.transformSync(
`
import foo from '@src/app';
console.log(foo)
`,
{
filename: "main.js",
jsc: {
parser: {
syntax: "typescript",
describe("parse", () => {
it("should work", () => {
const output = swc.parseSync("class Foo {}", {
syntax: "typescript",
target: "es2021",
});

expect(output).toMatchInlineSnapshot(`
Object {
"body": Array [
Object {
"body": Array [],
"declare": false,
"decorators": Array [],
"identifier": Object {
"optional": false,
"span": Object {
"ctxt": 0,
"end": 394,
"start": 391,
},
"type": "Identifier",
"value": "Foo",
},
"implements": Array [],
"isAbstract": false,
"span": Object {
"ctxt": 0,
"end": 397,
"start": 385,
},
"superClass": null,
"superTypeParams": null,
"type": "ClassDeclaration",
"typeParams": null,
},
target: "es2021",
transform: {},
baseUrl: __dirname,
paths: {
"@src/*": ["bar/*"],
],
"interpreter": null,
"span": Object {
"ctxt": 0,
"end": 397,
"start": 385,
},
"type": "Module",
}
`);
});

it("should work with async facade", async () => {
const output = await swc.parse("class Foo {}", {
syntax: "typescript",
target: "es2021",
});

expect(output).toMatchInlineSnapshot(`
Object {
"body": Array [
Object {
"body": Array [],
"declare": false,
"decorators": Array [],
"identifier": Object {
"optional": false,
"span": Object {
"ctxt": 0,
"end": 407,
"start": 404,
},
"type": "Identifier",
"value": "Foo",
},
"implements": Array [],
"isAbstract": false,
"span": Object {
"ctxt": 0,
"end": 410,
"start": 398,
},
"superClass": null,
"superTypeParams": null,
"type": "ClassDeclaration",
"typeParams": null,
},
},
module: {
type: "commonjs",
},
}
);

expect(code).toContain(`bar/app`);
],
"interpreter": null,
"span": Object {
"ctxt": 0,
"end": 410,
"start": 398,
},
"type": "Module",
}
`);
});
});

describe("minify", () => {
it("should work", () => {
const output = swc.minifySync(
"const somename = 1; console.log(somename);"
);

expect(output).toMatchInlineSnapshot(`
Object {
"code": "const a=1;console.log(1)",
}
`);
});

it("should work with async facade", async () => {
const output = await swc.minify(
"const somename = 1; console.log(somename);"
);

expect(output).toMatchInlineSnapshot(`
Object {
"code": "const a=1;console.log(1)",
}
`);
});
});

describe("print", () => {
it("should work", () => {
const input = swc.parseSync("class Foo {}", {
syntax: "typescript",
target: "es2021",
});

const output = swc.printSync(input);
expect(output).toMatchInlineSnapshot(`
Object {
"code": "class Foo {
}
",
}
`);
});

it("should work with async facade", async () => {
const input = swc.parseSync("class Foo {}", {
syntax: "typescript",
target: "es2021",
});

const output = await swc.print(input);
expect(output).toMatchInlineSnapshot(`
Object {
"code": "class Foo {
}
",
}
`);
});
});
Loading