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: handle star import name collisions in module concatenation #11751

Merged
merged 2 commits into from Oct 20, 2020

Conversation

Knagis
Copy link
Contributor

@Knagis Knagis commented Oct 20, 2020

What kind of change does this PR introduce?

Fixes #11743

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

Nothing

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@Knagis
Copy link
Contributor Author

Knagis commented Oct 20, 2020

The failing pipelines seem to be related due to change of generated JS.

Not all tests run successfully on Windows, so I can't update snapshots reliably at this point.

@alexander-akait
Copy link
Member

@Knagis What is tests not working? Do you read Contributing?

@Knagis
Copy link
Contributor Author

Knagis commented Oct 20, 2020

@evilebottnawi

one example:

   Expected: "file:///c:/Other/Projects/webpack/test/cases/esm/import-meta/index.js"
   Received: "file:///C:/Other/Projects/webpack/test/cases/esm/import-meta/index.js"

another:

    TypeError: The "filename" argument must be of type string. Received type objectTypeError [ERR_INVALID_ARG_TYPE]: The "filename" argument must be of type string. Received type object

      145 | it("should compile", done => {
      146 |     expect(X()).toBe("X");
    > 147 |     const worker = new external_worker_threads_namespaceObject.Worker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u(651), __webpack_require__.b));
    -       "moduleIdentifier": "<cwd>/test/fixtures/font.ttf",
    +       "moduleIdentifier": "C:/Other/Projects/webpack/test/fixtures/font.ttf",

there were few more. Most tests do run without problems.

I didn't try running under WSL yet since I am in VM where it does not work.

@alexander-akait
Copy link
Member

@Knagis Yep, look we need some improvement for our tests, maybe you can help? I think it should be not hard, problem with C:\ and c:\

@Knagis
Copy link
Contributor Author

Knagis commented Oct 20, 2020

I might be able, yes. I think I might have something in few days.

In the meantime for now I am updating snapshots using WSL which hopefully will enable this PR to be green

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@@ -999,7 +999,7 @@ class ConcatenatedModule extends Module {
const name = reference.identifier.name;
if (ConcatenationScope.isModuleReference(name)) {
const match = ConcatenationScope.matchModuleReference(name);
if (!match || match.ids.length < 1) continue;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0a8529f reverts the changes in ConcatenatedModule.js from 95eabe4
but im curious why this change fixes the initial bug?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findNewName should already return a name that avoids collisions with other variables. But the actual bug was that in some cases potential collisions were not detected. This happened in the case when ids = [], which is the case for namespace objects or the externals (which are also treated as namespace objects).

The above snippet fixes the problem.

@sokra sokra merged commit 51cd3c7 into webpack:master Oct 20, 2020
@sokra
Copy link
Member

sokra commented Oct 20, 2020

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Module concatenation produces invalid output due to name collision
5 participants