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

feat: implement compiler options #98

Merged
merged 1 commit into from
Apr 26, 2023
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
8 changes: 4 additions & 4 deletions lib/emit.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
}
function __wbg_adapter_16(arg0, arg1, arg2) {
wasm
._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc399077d245373c2(
._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb231fdb129de9b(
arg0,
arg1,
addHeapObject(arg2),
Expand Down Expand Up @@ -283,7 +283,7 @@ function handleError(f, args) {
}
}
function __wbg_adapter_25(arg0, arg1, arg2, arg3) {
wasm.wasm_bindgen__convert__closures__invoke2_mut__h3cf9829b75bbfd88(
wasm.wasm_bindgen__convert__closures__invoke2_mut__h0edd3e8b1a7686ec(
arg0,
arg1,
addHeapObject(arg2),
Expand Down Expand Up @@ -389,8 +389,8 @@ const imports = {
__wbindgen_throw: function (arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
},
__wbindgen_closure_wrapper422: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 144, __wbg_adapter_16);
__wbindgen_closure_wrapper423: function (arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 138, __wbg_adapter_16);
return addHeapObject(ret);
},
},
Expand Down
Binary file modified lib/emit_bg.wasm
Binary file not shown.
14 changes: 10 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export async function bundle(
cacheSetting,
cacheRoot,
allowRemote,
type,
compilerOptions,
} = options;
let bundleLoad = load;
if (!bundleLoad) {
Expand All @@ -154,13 +156,17 @@ export async function bundle(
}
root = root instanceof URL ? root : toFileUrl(resolve(root));
const { bundle: jsBundle } = await instantiate();
return jsBundle(
const result = await jsBundle(
root.toString(),
bundleLoad,
JSON.stringify(imports),
undefined,
undefined,
type,
imports,
compilerOptions,
);
return {
code: result.code,
map: result.maybe_map ?? undefined,
};
}

/** Transpile TypeScript (or JavaScript) into JavaScript, returning a promise
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function hello() {
return "Hello there!";
}
export { hello as default };

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function hello() {
return "Hello there!";
}
export { hello as default };

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function hello() {
return "Hello there!";
}
export { hello as default };
86 changes: 85 additions & 1 deletion tests/bundle_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertStringIncludes } from "https://deno.land/std@0.182.0/testing/asserts.ts";
import {
assert,
assertEquals,
assertExists,
assertStringIncludes,
} from "https://deno.land/std@0.182.0/testing/asserts.ts";
import { resolveFixture, testBundle } from "./utils.ts";

// FIXME: This repeats the test below. Consider supporting URLs without wrapping
Expand Down Expand Up @@ -53,3 +58,82 @@ Deno.test({
);
}),
});

Deno.test({
name: "inline source maps are enabled by default",
fn: testBundle(resolveFixture("mod.ts"), undefined, ({ result }) => {
assertEquals(result.map, undefined);
assert(
result.code.split("\n").at(-2)?.startsWith(
"//# sourceMappingURL=data:application/json;base64,",
),
);
}),
});

Deno.test({
name: "setting inlineSourceMap to true produces inline source maps",
fn: testBundle(resolveFixture("mod.ts"), {
compilerOptions: {
inlineSourceMap: true,
},
}, ({ result }) => {
assertEquals(result.map, undefined);
assert(
result.code.split("\n").at(-2)?.startsWith(
"//# sourceMappingURL=data:application/json;base64,",
),
);
}),
});

Deno.test({
name: "setting inlineSourceMap does not produce any source maps",
fn: testBundle(resolveFixture("mod.ts"), {
compilerOptions: {
inlineSourceMap: false,
},
}, ({ result }) => {
assertEquals(result.map, undefined);
assert(
!result.code.includes(
"//# sourceMappingURL=data:application/json;base64,",
),
);
}),
});

Deno.test({
name:
"setting sourceMap to true is not enough to produce external source maps as inline takes precedence",
fn: testBundle(resolveFixture("mod.ts"), {
compilerOptions: {
inlineSourceMap: false,
},
}, ({ result }) => {
assertEquals(result.map, undefined);
assert(
!result.code.includes(
"//# sourceMappingURL=data:application/json;base64,",
),
);
}),
});

Deno.test({
name:
"setting sourceMap to true and inlineSourceMap to false produces external source maps",
fn: testBundle(resolveFixture("mod.ts"), {
compilerOptions: {
sourceMap: true,
inlineSourceMap: false,
},
}, ({ result }) => {
assertExists(result.map);
assert(
!result.code.includes(
"//# sourceMappingURL=data:application/json;base64,",
),
);
}),
});