refactor(docs-infra): refactors `addImageDimensionsImpl` (#37046)
This commit changes the `addImageDimensionsImpl` method to reduce nesting. It will exit early, if the conditions are not matched. PR Close #37046
This commit is contained in:
parent
90205079d7
commit
2418c6aca1
|
@ -15,12 +15,17 @@ module.exports = function addImageDimensions(getImageDimensions) {
|
|||
return (ast, file) => {
|
||||
visit(ast, node => {
|
||||
|
||||
if (is(node, 'img')) {
|
||||
if (!is(node, 'img')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const props = node.properties;
|
||||
const src = props.src;
|
||||
if (!src) {
|
||||
file.message('Missing src in image tag `' + source(node, file) + '`');
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const dimensions = getImageDimensions(addImageDimensionsImpl.basePath, src);
|
||||
if (props.width === undefined && props.height === undefined) {
|
||||
|
@ -34,8 +39,6 @@ module.exports = function addImageDimensions(getImageDimensions) {
|
|||
file.fail(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue