-
-
Notifications
You must be signed in to change notification settings - Fork 205
fix: merge attributes without tag and attributes with tag #408
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: merge attributes without tag and attributes with tag #408
Conversation
|
Can you provide example? |
Additional examples added |
README.md
Outdated
However this will only process `data-src` attributes on tags that _aren't in the default list_: | ||
|
||
- `<p data-src="..">` will be processed, as `p` is not in the default sources list | ||
- `<img data-src="..">` won't be processed, as `img` is already in the default sources list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is bug, we need fix, attribute: "data-src"
should process all tags have data-src
OK, so if we're considering the current behaviour as a bug, then perhaps what I would suggest is a change to how the Given a config like this: module.exports = {
module: {
rules: [
{
test: /\.html$/i,
loader: "html-loader",
options: {
sources: {
list: [
// All default supported tags and attributes
"...",
{
attribute: "data-src",
type: "src",
},
],
},
},
},
],
},
}; ...internally, the const result = new Map([
...
["img", new Map([
["src", { type: srcType }],
["srcset", { type: srcsetType }]
)],
...
["*", new Map([
["data-src", { type: srcType }]
])
]); Current behaviourWhen processing a tag, the handlers are determined as: const handlers =
options.sources.list.get(tagName.toLowerCase()) ||
options.sources.list.get("*"); ...which means that for an Map(2) {'src' => {…}, 'srcset' => {…}} Proposed changeThe proposal is to use a union of the map entries: const handlers = new Map([
...options.sources.list.get(tagName.toLowerCase() ?? new Map(),
...options.sources.list.get("*") ?? new Map()
]); The result is a merged map of both the attributes specific to the tag, and any attributes that apply to all tags: Map(3) {'src' => {…}, 'srcset' => {…}, 'data-src' => {…}} (The If that solution sounds OK to you, I am happy to modify this PR accordingly. |
Yes, let's do it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's add test case
09d68b5
to
7536bfc
Compare
Codecov Report
@@ Coverage Diff @@
## master #408 +/- ##
==========================================
- Coverage 92.12% 91.96% -0.16%
==========================================
Files 7 7
Lines 584 585 +1
Branches 187 187
==========================================
Hits 538 538
- Misses 37 38 +1
Partials 9 9
Continue to review full report at Codecov.
|
Big thanks for the PR, fixed here #410, |
This PR contains a:
Motivation / Use-Case
Fixes #405
When processing attributes, merge attributes for any tag with attributes for the specific tag:
(More info: #408 (comment))
Breaking Changes
None
Additional Info