deno_emit
deno_emit copied to clipboard
Deno.emit tree shaking issues
I'll provide an example repo, attached as a zip file and inline files here for examination:
Files
example-1.ts
:
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";
assert(true);
example-2-asserts.ts
:
export class AssertionError extends Error {
constructor(message: string) {
super(message);
this.name = "AssertionError";
}
}
/** Make an assertion, error will be thrown if `expr` does not have truthy value. */
export function assert(expr: unknown, msg = ""): asserts expr {
if (!expr) {
throw new AssertionError(msg);
}
}
example-2.ts
:
import { assert } from "./example-2-asserts.ts";
assert(true);
main.ts
:
import { assertStrictEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
async function bundleModule(filePath: string): Promise<string> {
const emitResult = await Deno.emit(filePath, { bundle: "module" });
return emitResult.files["deno:///bundle.js"];
}
const filePaths = ["example-1.ts", "example-2.ts"];
const bundles = await Promise.all(
filePaths.map((filePath) => bundleModule(filePath)),
);
try {
assertStrictEquals(...bundles as [string, string]);
console.log("Bundles are identical");
} catch (ex) {
console.error(ex.message);
}
run
:
deno run --unstable --allow-net=deno.land --allow-read=. main.ts
I created two modules which import assert
and invoke it:
- one which imports
assert
from https://deno.land/[email protected]/testing/asserts.ts - one which imports from a local module where I manually copied from the source: only the
assert
function (and theAssertionError
class on which it depends)
I then bundled them both using Deno.emit
and compared the bundles with assertStrictEquals
:
bundle-example % deno --version
deno 1.12.0 (release, x86_64-apple-darwin)
v8 9.2.230.14
typescript 4.3.2
bundle-example % ./run
Values are not strictly equal:
[Diff] Actual / Expected
- const ANSI_PATTERN = new RegExp([
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
- ].join("|"), "g");
- var DiffType;
- (function(DiffType1) {
- DiffType1["removed"] = "removed";
- DiffType1["common"] = "common";
- DiffType1["added"] = "added";
- })(DiffType || (DiffType = {
- }));
class AssertionError extends Error {
constructor(message){
super(message);
this.name = "AssertionError";
}
}
function assert(expr, msg = "") {
if (!expr) {
throw new AssertionError(msg);
}
}
assert(true);
The one using the remote import results in an unrelated regex and string enum being emitted.
@kdy1 Any ideas?
No. I don't have any idea as I don't know what Deno.emit
does.
No. I don't have any idea as I don't know what
Deno.emit
does.
@kdy1 I forgot to say that the result is the same for deno bundle
when I mentioned you.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Not stale. Still waiting for engagement by others.
@bartlomieju Can you reopen this?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
This issue still persists in Deno v1.16.2
:
$ deno --version
deno 1.16.2 (release, x86_64-unknown-linux-gnu)
v8 9.7.106.2
typescript 4.4.2
$ ./run
Values are not strictly equal:
[Diff] Actual / Expected
- const { Deno } = globalThis;
- typeof Deno?.noColor === "boolean" ? Deno.noColor : true;
- new RegExp([
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
- ].join("|"), "g");
- var DiffType;
- (function(DiffType) {
- DiffType["removed"] = "removed";
- DiffType["common"] = "common";
- DiffType["added"] = "added";
- })(DiffType || (DiffType = {
- }));
class AssertionError extends Error {
constructor(message){
super(message);
this.name = "AssertionError";
}
}
function assert(expr, msg = "") {
if (!expr) {
throw new AssertionError(msg);
}
}
assert(true);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
This issue still persists in Deno v1.17.3
:
% deno --version
deno 1.17.3 (release, x86_64-apple-darwin)
v8 9.7.106.15
typescript 4.5.2
% ./run
Values are not strictly equal:
[Diff] Actual / Expected
- const { Deno } = globalThis;
- typeof Deno?.noColor === "boolean" ? Deno.noColor : true;
- new RegExp([
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
- ].join("|"), "g");
- var DiffType;
- (function(DiffType1) {
- DiffType1["removed"] = "removed";
- DiffType1["common"] = "common";
- DiffType1["added"] = "added";
- })(DiffType || (DiffType = {}));
class AssertionError extends Error {
constructor(message){
super(message);
this.name = "AssertionError";
}
}
function assert(expr, msg = "") {
if (!expr) {
throw new AssertionError(msg);
}
}
assert(true);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
The issue persists in Deno v1.20.1
:
% deno --version
deno 1.20.1 (release, x86_64-apple-darwin)
v8 10.0.139.6
typescript 4.6.2
% ./run
Values are not strictly equal:
[Diff] Actual / Expected
// deno-fmt-ignore-file
// deno-lint-ignore-file
// This code was bundled using `deno bundle` and it's not recommended to edit it manually
- const { Deno } = globalThis;
- typeof Deno?.noColor === "boolean" ? Deno.noColor : true;
- new RegExp([
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
- ].join("|"), "g");
- var DiffType;
- (function(DiffType1) {
- DiffType1["removed"] = "removed";
- DiffType1["common"] = "common";
- DiffType1["added"] = "added";
- })(DiffType || (DiffType = {}));
class AssertionError extends Error {
constructor(message){
super(message);
this.name = "AssertionError";
}
}
function assert(expr, msg = "") {
if (!expr) {
throw new AssertionError(msg);
}
}
assert(true);
This issue should be migrated to https://github.com/denoland/deno_emit