Skip to content

update topLevelDeclarations for ConcatenatedModule #15315

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

Merged
merged 5 commits into from
Feb 14, 2022
Merged

Conversation

vankop
Copy link
Member

@vankop vankop commented Feb 4, 2022

update top level declarations for ConcatenatedModule in code generation step

What kind of change does this PR introduce?

fixes #13022

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)

@vankop vankop force-pushed the fix/issue-13022 branch 2 times, most recently from df032ad to f0de515 Compare February 4, 2022 12:54
update top level declarations for ConcatenatedModule in code generation step
- add topLevelDeclarations to code generation results
- set topLevelDeclarations=undefined if any child topLevelDeclarations=undefined
@webpack-bot
Copy link
Contributor

@vankop Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

- add topLevelDeclarations to code generation results
- set topLevelDeclarations=undefined if any child topLevelDeclarations=undefined
@vankop vankop assigned sokra and unassigned vankop Feb 7, 2022
{ chunk, codeGenerationResults },
{ options, compilation }
) {
let topLevelDeclarations =
module.buildInfo && module.buildInfo.topLevelDeclarations;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using both topLevelDeclarations maybe it's better to use

const topLevelDeclarations =
			(data && data.get("topLevelDeclarations")) ||
			(module.buildInfo && module.buildInfo.topLevelDeclarations);

So the topLevelDeclarations from code generations overrides the original topLevelDeclarations, since it's basically a better version of it. It includes renames, which means some original topLevelDeclarations might be no longer in the code generation topLevelDeclarations, e. g. all reserved names.

Copy link
Member

Choose a reason for hiding this comment

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

Assuming it should also be possible that buildInfo.topLevelDeclarations is not set but data.topLevelDeclarations is, we also need to improve that piece of code:

(!entryModule.buildInfo ||
!entryModule.buildInfo.topLevelDeclarations)

Copy link
Member Author

Choose a reason for hiding this comment

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

So the topLevelDeclarations from code generations overrides the original topLevelDeclarations, since it's basically a better version of it. It includes renames, which means some original topLevelDeclarations might be no longer in the code generation topLevelDeclarations, e. g. all reserved names.

yeah, reserved names (globals) is a case.

Assuming it should also be possible that buildInfo.topLevelDeclarations is not set but data.topLevelDeclarations

not sure that this wont be a breaking change.. I have change hooks api ( added codeGenerationResults )

Copy link
Member Author

Choose a reason for hiding this comment

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

btw case

{
		entry: {
			index: path.resolve(__dirname, "./index.js")
		},
		output: {
			library: "setTimeout",
			libraryExport: "default"
		},
		optimization: {
			concatenateModules: true
		}
	}

will not work.. since "global" setTimeout points to variable

@sokra sokra merged commit 18c3590 into main Feb 14, 2022
@sokra sokra deleted the fix/issue-13022 branch February 14, 2022 13:46
@sokra
Copy link
Member

sokra commented Feb 14, 2022

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.

Const reassignment in production build
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy