Skip to content

Refactor dependency variables - #7781

Merged
sokra merged 30 commits into
nextfrom
refactor/dep_vars
Jul 31, 2018
Merged

sokra merged 30 commits into
nextfrom
refactor/dep_vars

Conversation

@ooflorent

@ooflorent ooflorent commented Jul 24, 2018 •

Copy link
Copy Markdown
Contributor

This PR introduces InitFragment and CachedConstDependency to replace DependencyBlockVariables.

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

@webpack-bot

Copy link
Copy Markdown
Contributor

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

Comment thread lib/JavascriptGenerator.js Outdated
const extractFragmentIndex = (fragment, index) => [fragment, index];

const sortByFragmentIndex = ([a, i], [b, j]) => {
const x = a.order - b.order;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

order -> priority

Add types to the method to find these kind of bugs

Comment thread lib/dependencies/NullDependency.js Outdated
* @param {DependencyTemplates} dependencyTemplates the dependency templates
* @returns {InitFragment[]}
*/
getInitFragments(dependency, source, runtimeTemplate, dependencyTemplates) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better place this in Dependency.

We could allow null as return value to avoid array allocations.

Comment thread lib/dependencies/ProvidedDependency.js Outdated
}
}

function getImportVarName(dep) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arrow function

Comment thread lib/dependencies/SystemPlugin.js Outdated
"System",
null,
expr.range,
expr.loc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For consistency loc should not be passed via constructor. (Even if it's better)

Comment thread lib/dependencies/ProvidedDependency.js Outdated
source.replace(
dep.range[0],
dep.range[1] - 1,
this.getContent(dep, runtime)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Specifier missing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand. The specifier is defined in dep. What are you referring to?

);
return;
return this.originalTemplate.getInitFragments(dep, source, runtime);
} else {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a common base class for all these dependency templates in ConcatenatedModule

@webpack-bot

Copy link
Copy Markdown
Contributor

@ooflorent Thanks for your update.

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

@sokra Please review the new changes.

@sokra

sokra commented Jul 27, 2018

Copy link
Copy Markdown
Member

Loosely depends on #7789

After that PR StatsTestCases should pass without change.

@ooflorent
ooflorent force-pushed the refactor/dep_vars branch 6 times, most recently from 61984e5 to 6f49f68 Compare July 27, 2018 19:12
@sokra sokra changed the title WIP — Refactor dependency variables Refactor dependency variables Jul 30, 2018
Comment thread lib/NodeStuffPlugin.js Outdated
class ModuleDecoratorDependency extends ModuleDependency {
constructor(request, originalModule, range) {
super(request);
this.originalModule = originalModule;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rename it to originModule to be consistent to the other dependencies.

Comment thread lib/InitFragment.js Outdated

class InitFragment {
/**
* @param {string|Source} content [TODO]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TODOs

Comment thread lib/InitFragment.js Outdated
class InitFragment {
/**
* @param {string|Source} content [TODO]
* @param {number} priority [TODO]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a stage (multi-tier priority)

Comment thread lib/NodeStuffPlugin.js Outdated
parser,
"module",
`require(${JSON.stringify(moduleJsPath)})(module)`
require.resolve(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hoist this to module level

Comment thread lib/NodeStuffPlugin.js Outdated
}
}

class ModuleDecoratorDependency extends ModuleDependency {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

separate file

this.path = path;
this.range = range;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

identifier and path should contribute to hash

} = ${runtimeTemplate.moduleExports({
module: dep.module,
request: dep.request
})}${pathToString(dep.path)};\n`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a separate PR we need to handle ESM in a better way.

Comment thread lib/dependencies/SystemPlugin.js Outdated
const dep = new ProvidedDependency(
getModulePath(
parser.state.module.context,
require.resolve("../../buildin/system")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hoist this to module level

Comment thread lib/node/NodeSourcePlugin.js Outdated
getPathToModule(module, type)
),
identifier,
specifier ? [specifier] : null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove this form test case, because it's no longer a reason to opt-out

@sokra
sokra force-pushed the refactor/dep_vars branch from 28fe67d to 204f223 Compare July 30, 2018 20:45
@sokra
sokra force-pushed the refactor/dep_vars branch from 204f223 to d6f8e49 Compare July 30, 2018 21:10
@webpack-bot

Copy link
Copy Markdown
Contributor

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

@sokra
sokra merged commit 8ffcd91 into next Jul 31, 2018
@sokra
sokra deleted the refactor/dep_vars branch July 31, 2018 07:08
@sokra

sokra commented Jul 31, 2018

Copy link
Copy Markdown
Member

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants