Repository navigation
Refactor dependency variables - #7781
Conversation
|
For maintainers only:
|
| const extractFragmentIndex = (fragment, index) => [fragment, index]; | ||
|
|
||
| const sortByFragmentIndex = ([a, i], [b, j]) => { | ||
| const x = a.order - b.order; |
There was a problem hiding this comment.
order -> priority
Add types to the method to find these kind of bugs
| * @param {DependencyTemplates} dependencyTemplates the dependency templates | ||
| * @returns {InitFragment[]} | ||
| */ | ||
| getInitFragments(dependency, source, runtimeTemplate, dependencyTemplates) { |
There was a problem hiding this comment.
Better place this in Dependency.
We could allow null as return value to avoid array allocations.
| } | ||
| } | ||
|
|
||
| function getImportVarName(dep) { |
| "System", | ||
| null, | ||
| expr.range, | ||
| expr.loc |
There was a problem hiding this comment.
For consistency loc should not be passed via constructor. (Even if it's better)
| source.replace( | ||
| dep.range[0], | ||
| dep.range[1] - 1, | ||
| this.getContent(dep, runtime) |
There was a problem hiding this comment.
I don't understand. The specifier is defined in dep. What are you referring to?
| ); | ||
| return; | ||
| return this.originalTemplate.getInitFragments(dep, source, runtime); | ||
| } else { |
There was a problem hiding this comment.
Maybe a common base class for all these dependency templates in ConcatenatedModule
|
@ooflorent Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
f24b1d0 to
aedd4eb
Compare
|
Loosely depends on #7789 After that PR StatsTestCases should pass without change. |
61984e5 to
6f49f68
Compare
| class ModuleDecoratorDependency extends ModuleDependency { | ||
| constructor(request, originalModule, range) { | ||
| super(request); | ||
| this.originalModule = originalModule; |
There was a problem hiding this comment.
Rename it to originModule to be consistent to the other dependencies.
|
|
||
| class InitFragment { | ||
| /** | ||
| * @param {string|Source} content [TODO] |
| class InitFragment { | ||
| /** | ||
| * @param {string|Source} content [TODO] | ||
| * @param {number} priority [TODO] |
There was a problem hiding this comment.
Maybe add a stage (multi-tier priority)
| parser, | ||
| "module", | ||
| `require(${JSON.stringify(moduleJsPath)})(module)` | ||
| require.resolve( |
| } | ||
| } | ||
|
|
||
| class ModuleDecoratorDependency extends ModuleDependency { |
| this.path = path; | ||
| this.range = range; | ||
| } | ||
| } |
There was a problem hiding this comment.
identifier and path should contribute to hash
| } = ${runtimeTemplate.moduleExports({ | ||
| module: dep.module, | ||
| request: dep.request | ||
| })}${pathToString(dep.path)};\n`, |
There was a problem hiding this comment.
In a separate PR we need to handle ESM in a better way.
| const dep = new ProvidedDependency( | ||
| getModulePath( | ||
| parser.state.module.context, | ||
| require.resolve("../../buildin/system") |
| getPathToModule(module, type) | ||
| ), | ||
| identifier, | ||
| specifier ? [specifier] : null, |
There was a problem hiding this comment.
can be simplified to pass array or null
| ModuleConcatenation bailout: Cannot concat with ./ref-from-cjs.js (<- Module is referenced from these modules with unsupported syntax: ./cjs.js (referenced with cjs require)) | ||
| | ./index.js 176 bytes [built] | ||
| | ModuleConcatenation bailout: Module is an entry point | ||
| | ./injected-vars.js 40 bytes [built]" |
There was a problem hiding this comment.
remove this form test case, because it's no longer a reason to opt-out
add a hack to include the current module as property in source later we will refactor DependencyTemplate.apply to take a TemplateContext too
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
|
Thanks |
This PR introduces
InitFragmentandCachedConstDependencyto replaceDependencyBlockVariables.What kind of change does this PR introduce?
refactoring
Did you add tests for your changes?
no
Does this PR introduce a breaking change?
yes
What needs to be documented once your changes are merged?
TODO