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

Deno.bundle causes Assertion error in the TS compiler #7518

Closed
littledivy opened this issue Sep 16, 2020 · 4 comments
Closed

Deno.bundle causes Assertion error in the TS compiler #7518

littledivy opened this issue Sep 16, 2020 · 4 comments
Labels
bug Something isn't working correctly cli related to cli/ dir

Comments

@littledivy
Copy link
Member

Error
image

Steps to reproduce

const code: string = `
// foo.ts
export * from "./a.ts";
export * from "./b.ts";
`
await Deno.bundle(
        "/foo.ts",
        {
          "/foo.ts": code,
        },
        {
          target: "es3",
          module: "esnext",
        },
  );

where a.ts and b.ts can be any valid typescript module

Deno - 1.4.0
v8 - 8.7.75
typescript - 4.0.2

@kitsonk
Copy link
Contributor

kitsonk commented Sep 16, 2020

I thought we had an issue for this, but we don't. The title should be deno bundle doesnt support export * exports.

@JordanMajd
Copy link

JordanMajd commented Sep 21, 2020

TLDR: I suspect export * from "./a.ts" counts as a redirect, but buildLocalSourceFileCache doesn't respect it.

Additional Notes: Things like export {pickle} from "./jar.ts"; also are affected by this issue.

Pull Request: #7607

Wall of text:
runtimeBundle calls buildLocalSourceFileCache(sourceFileMap) but an assertion fails because the entries in sourceFileMap don't contain any sourceCode.

Removing the assertion removes the error, but the bundle still won't contain the expected exports from foo.ts.

While debugging, I found this could be overcome by replacing the call to buildLocalSourceFileCache with buildSourceFileCache and ensuring that the return's output was never empty output: state.bundleOutput ? state.bundleOutput : {},.

It looks like there are two differences between the functions:

  1. buildSourceFileCache ensures that if the imported file is a redirect, the mappedUrl will reflect the redirect.
  2. buildLocalSourceFileCache modifies the imports mappedUrl by removing memmory://.

After testing I found that 1. was the issue; export * from "./a.ts"; counts as a redirect, but buildLocalSourceFileCache isn't updating the mappedURL to reflect that.

The solution was:

  1. remove the offending assert(entry.sourceCode.length > 0); on line 493.
  2. add the following right below line 505's assert(importedFile); to buildLocalSourceFileCache
if (importedFile.redirect) {
  mappedUrl = importedFile.redirect;
}

Repro'd tested the fix with the following: \deno.exe run --unstable --allow-all .\comp.ts

//comp.ts
const code = `
// foo.ts
export * from "./a.ts";
export * from "./b.ts";
`;
await Deno.bundle(
  "/foo.ts",
  {
    "/foo.ts": code,
  },
  {
    target: "es3",
    module: "esnext",
  },
);
//a.ts
export default function(){
}
//b.ts
export default function(){
}

@kitsonk kitsonk added bug Something isn't working correctly cli related to cli/ dir labels Sep 21, 2020
@kitsonk kitsonk mentioned this issue Sep 23, 2020
18 tasks
@kitsonk
Copy link
Contributor

kitsonk commented Oct 23, 2020

For deno bundle this now works, but for Deno.bundle() it requires #8060 so we should keep this open until that.

@kitsonk
Copy link
Contributor

kitsonk commented Nov 5, 2020

#8060 is resolved... closing.

@kitsonk kitsonk closed this as completed Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants