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

fix: unminified build breaks __vitePreload #5785

Merged
merged 2 commits into from Nov 22, 2021
Merged

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Nov 22, 2021

Description

close #5753

When there are comments in dynamic import, e.g.

import(/*not following dependency*/'./App.vue')

We will get url = /*not following dependency*/ "./App.vue" , which does not meet the conditions:

if (url[0] === `"` && url[url.length - 1] === `"`) {

In fact es-module-lexer will return a .n field containing the escaped url, which is ./App.vue in this example.
So we can use the .n field first.

Additional context

https://github.com/guybedford/es-module-lexer/blob/c5cdb28d848c91e9296bbcf9a17196f230f68a5f/types/lexer.d.ts#L2-L22

 /**
   * Module name
   * 
   * To handle escape sequences in specifier strings, the .n field of imported specifiers will be provided where possible.
   * 
   * For dynamic import expressions, this field will be empty if not a valid JS string.
   * 
   * @example
   * const [imports1, exports1] = parse(String.raw`import './\u0061\u0062.js'`);
   * imports1[0].n;
   * // Returns "./ab.js"
   * 
   * const [imports2, exports2] = parse(`import("./ab.js")`);
   * imports2[0].n;
   * // Returns "./ab.js"
   * 
   * const [imports3, exports3] = parse(`import("./" + "ab.js")`);
   * imports3[0].n;
   * // Returns undefined
   */
  readonly n: string | undefined;

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Nov 22, 2021
patak-dev
patak-dev previously approved these changes Nov 22, 2021
@patak-dev patak-dev merged commit 757a74a into vitejs:main Nov 22, 2021
@patak-dev
Copy link
Member

I love your PRs @ygj6 ❤️

@Shinigami92
Copy link
Member

I love your PRs @ygj6 ❤️

⬆️ What @patak-js says ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unminified build breaks __vitePreload
3 participants