Fix prefer-object-spread in src/language-html (#7352)
This commit is contained in:
1 parent
9fccf61a0d
commit
d4c816959a
4 files changed
+38
-41
No files matched your search
@@ -67,7 +67,7 @@ class Node {
|
||||
}
|
||||
|
||||
clone(overrides) {
|
||||
return new Node(overrides ? Object.assign({}, this, overrides) : this);
|
||||
return new Node(overrides ? { ...this, ...overrides } : this);
|
||||
}
|
||||
|
||||
get firstChild() {
|
||||
|
||||
@@ -17,8 +17,11 @@ const getCssStyleTags = property =>
|
||||
)
|
||||
.reduce((reduced, value) => Object.assign(reduced, value), {});
|
||||
|
||||
const CSS_DISPLAY_TAGS = Object.assign({}, getCssStyleTags("display"), {
|
||||
const CSS_DISPLAY_TAGS = {
|
||||
...getCssStyleTags("display"),
|
||||
|
||||
// TODO: send PR to upstream
|
||||
|
||||
button: "inline-block",
|
||||
|
||||
// special cases for some css display=none elements
|
||||
@@ -30,7 +33,7 @@ const CSS_DISPLAY_TAGS = Object.assign({}, getCssStyleTags("display"), {
|
||||
// there's no css display for these elements but they behave these ways
|
||||
video: "inline-block",
|
||||
audio: "inline-block"
|
||||
});
|
||||
};
|
||||
const CSS_DISPLAY_DEFAULT = "inline";
|
||||
const CSS_WHITE_SPACE_TAGS = getCssStyleTags("white-space");
|
||||
const CSS_WHITE_SPACE_DEFAULT = "normal";
|
||||
|
||||
@@ -375,12 +375,11 @@ function extractWhitespaces(ast /*, options*/) {
|
||||
i !== children.length - 1 &&
|
||||
children[i + 1].type === TYPE_WHITESPACE;
|
||||
|
||||
return newChildren.concat(
|
||||
Object.assign({}, child, {
|
||||
hasLeadingSpaces,
|
||||
hasTrailingSpaces
|
||||
})
|
||||
);
|
||||
return newChildren.concat({
|
||||
...child,
|
||||
hasLeadingSpaces,
|
||||
hasTrailingSpaces
|
||||
});
|
||||
}, [])
|
||||
});
|
||||
});
|
||||
@@ -442,25 +441,25 @@ function addIsSpaceSensitive(ast /*, options */) {
|
||||
return node.clone({
|
||||
children: node.children
|
||||
.map(child => {
|
||||
return Object.assign({}, child, {
|
||||
return {
|
||||
...child,
|
||||
isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode(child),
|
||||
isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode(child)
|
||||
});
|
||||
};
|
||||
})
|
||||
.map((child, index, children) =>
|
||||
Object.assign({}, child, {
|
||||
isLeadingSpaceSensitive:
|
||||
index === 0
|
||||
? child.isLeadingSpaceSensitive
|
||||
: children[index - 1].isTrailingSpaceSensitive &&
|
||||
child.isLeadingSpaceSensitive,
|
||||
isTrailingSpaceSensitive:
|
||||
index === children.length - 1
|
||||
? child.isTrailingSpaceSensitive
|
||||
: children[index + 1].isLeadingSpaceSensitive &&
|
||||
child.isTrailingSpaceSensitive
|
||||
})
|
||||
)
|
||||
.map((child, index, children) => ({
|
||||
...child,
|
||||
isLeadingSpaceSensitive:
|
||||
index === 0
|
||||
? child.isLeadingSpaceSensitive
|
||||
: children[index - 1].isTrailingSpaceSensitive &&
|
||||
child.isLeadingSpaceSensitive,
|
||||
isTrailingSpaceSensitive:
|
||||
index === children.length - 1
|
||||
? child.isTrailingSpaceSensitive
|
||||
: children[index + 1].isLeadingSpaceSensitive &&
|
||||
child.isTrailingSpaceSensitive
|
||||
}))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -83,19 +83,14 @@ function embed(path, print, textToDoc, options) {
|
||||
indent(
|
||||
concat([
|
||||
line,
|
||||
textToDoc(
|
||||
node.value,
|
||||
Object.assign(
|
||||
{
|
||||
__isInHtmlInterpolation: true // to avoid unexpected `}}`
|
||||
},
|
||||
options.parser === "angular"
|
||||
? { parser: "__ng_interpolation", trailingComma: "none" }
|
||||
: options.parser === "vue"
|
||||
? { parser: "__vue_expression" }
|
||||
: { parser: "__js_expression" }
|
||||
)
|
||||
)
|
||||
textToDoc(node.value, {
|
||||
__isInHtmlInterpolation: true, // to avoid unexpected `}}`
|
||||
...(options.parser === "angular"
|
||||
? { parser: "__ng_interpolation", trailingComma: "none" }
|
||||
: options.parser === "vue"
|
||||
? { parser: "__vue_expression" }
|
||||
: { parser: "__js_expression" })
|
||||
})
|
||||
])
|
||||
),
|
||||
node.parent.next &&
|
||||
@@ -142,7 +137,7 @@ function embed(path, print, textToDoc, options) {
|
||||
node,
|
||||
(code, opts) =>
|
||||
// strictly prefer single quote to avoid unnecessary html entity escape
|
||||
textToDoc(code, Object.assign({ __isInHtmlAttribute: true }, opts)),
|
||||
textToDoc(code, { __isInHtmlAttribute: true, ...opts }),
|
||||
options
|
||||
);
|
||||
if (embeddedAttributeValueDoc) {
|
||||
@@ -958,7 +953,7 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
|
||||
const printMaybeHug = doc => (shouldHug ? printHug(doc) : printExpand(doc));
|
||||
|
||||
const textToDoc = (code, opts) =>
|
||||
originalTextToDoc(code, Object.assign({ __onHtmlBindingRoot }, opts));
|
||||
originalTextToDoc(code, { __onHtmlBindingRoot, ...opts });
|
||||
|
||||
if (
|
||||
node.fullName === "srcset" &&
|
||||
@@ -1020,7 +1015,7 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
|
||||
if (options.parser === "angular") {
|
||||
const ngTextToDoc = (code, opts) =>
|
||||
// angular does not allow trailing comma
|
||||
textToDoc(code, Object.assign({ trailingComma: "none" }, opts));
|
||||
textToDoc(code, { trailingComma: "none", ...opts });
|
||||
|
||||
/**
|
||||
* *directive="angularDirective"
|
||||
|
||||
Reference in new issue
Block a user