Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions packages/babel-plugin-jsx-dom-expressions/src/dom/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,31 @@ function transformAttributes(path, results) {
);
//NOTE: can't be checked at compile time so add to compiled output
hasHydratableEvent = true;
} else {
/**
* Spreads already de-duplicate attributes.
*
* This handles the case when attributes are duplicated without the presence of a spread. Such:
* `<div style="duplicate1" style="duplicate2" />;`
*/
const seenAttributes = {};
const duplicates = [];
path
.get("openingElement")
.get("attributes")
.forEach(attr => {
const key = t.isJSXNamespacedName(attr.node.name)
? `${attr.node.name.namespace.name}:${attr.node.name.name.name}`
: attr.node.name.name;

if (!key.startsWith("use:") && key !== "ref" && seenAttributes[key]) {
duplicates.push(seenAttributes[key]);
}
seenAttributes[key] = attr;
});
for (const duplicate of duplicates) {
duplicate.remove();
}
}

/**
Expand Down Expand Up @@ -1171,12 +1196,7 @@ function processSpreads(path, attributes, { elem, isSVG, hasChildren, wrapCondit
: node.argument;

spreadArgs.push(isStatic ? t.objectExpression([t.spreadElement(s)]) : s);
} else if (
(firstSpread ||
(t.isJSXExpressionContainer(node.value) &&
isDynamic(attribute.get("value").get("expression"), { checkMember: true }))) &&
canNativeSpread(key, { checkNameSpaces: true })
) {
} else if (key && !key.startsWith("use:") && key !== "ref") {
const isContainer = t.isJSXExpressionContainer(node.value);
const dynamic =
isContainer && isDynamic(attribute.get("value").get("expression"), { checkMember: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,5 @@ const template88 = (
{count()}
</button>
);

const template89 = <div style="duplicate1" style="duplicate2"/>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { className as _$className } from "r-dom";
import { use as _$use } from "r-dom";
import { spread as _$spread } from "r-dom";
import { mergeProps as _$mergeProps } from "r-dom";
var _tmpl$ = /*#__PURE__*/ _$template(
`<div id="main"><h1 id="my-h1"><a href="/">Welcome</a></h1></div>`
),
var _tmpl$ = /*#__PURE__*/ _$template(`<div><h1><a href="/">Welcome</a></h1></div>`),
_tmpl$2 = /*#__PURE__*/ _$template(`<div><div></div><div> </div><div></div></div>`),
_tmpl$3 = /*#__PURE__*/ _$template(`<div foo></div>`),
_tmpl$4 = /*#__PURE__*/ _$template(`<div></div>`),
Expand All @@ -29,7 +27,7 @@ var _tmpl$ = /*#__PURE__*/ _$template(
_tmpl$14 = /*#__PURE__*/ _$template(`<div data="&quot;hi&quot;"data2="&quot;"></div>`),
_tmpl$15 = /*#__PURE__*/ _$template(`<a></a>`),
_tmpl$16 = /*#__PURE__*/ _$template(`<div><a></a></div>`),
_tmpl$17 = /*#__PURE__*/ _$template(`<div start="Hi">Hi</div>`),
_tmpl$17 = /*#__PURE__*/ _$template(`<div>Hi</div>`),
_tmpl$18 = /*#__PURE__*/ _$template(`<label><span>Input is </span><input><div></div></label>`),
_tmpl$19 = /*#__PURE__*/ _$template(
`<div class="class1 class2 class3 class4 class5 class6"random="random1 random2\n random3 random4"style="color:red;background-color:blue !important;border:1px solid black;font-size:12px"></div>`
Expand Down Expand Up @@ -72,7 +70,8 @@ var _tmpl$ = /*#__PURE__*/ _$template(
_tmpl$43 = /*#__PURE__*/ _$template(`<video poster="1.jpg"></video>`),
_tmpl$44 = /*#__PURE__*/ _$template(`<div><video poster="1.jpg"></video></div>`),
_tmpl$45 = /*#__PURE__*/ _$template(`<div><video></video></div>`),
_tmpl$46 = /*#__PURE__*/ _$template(`<button type="button"></button>`);
_tmpl$46 = /*#__PURE__*/ _$template(`<button type="button"></button>`),
_tmpl$47 = /*#__PURE__*/ _$template(`<div style="duplicate2"></div>`);
import * as styles from "./styles.module.css";
import { binding } from "somewhere";
function refFn() {}
Expand All @@ -86,41 +85,53 @@ const template = (() => {
_el$3 = _el$2.firstChild;
_$spread(
_el$,
_$mergeProps(results, {
class: {
selected: unknown
_$mergeProps(
{
id: "main"
},
style: {
color
results,
{
class: {
selected: unknown
},
style: {
color
}
}
}),
),
false,
true
);
_$spread(
_el$2,
_$mergeProps(results, {
foo: "",
disabled: "",
get title() {
return welcoming();
},
get style() {
return {
"background-color": color(),
"margin-right": "40px"
};
_$mergeProps(
{
id: id
},
get ["class"]() {
return [
"base",
{
dynamic: dynamic(),
selected
}
];
results,
{
foo: "",
disabled: "",
get title() {
return welcoming();
},
get style() {
return {
"background-color": color(),
"margin-right": "40px"
};
},
get ["class"]() {
return [
"base",
{
dynamic: dynamic(),
selected
}
];
}
}
}),
),
false,
true
);
Expand Down Expand Up @@ -385,15 +396,28 @@ const template25 = (() => {
})();
const template26 = (() => {
var _el$35 = _tmpl$17();
_$setAttribute(_el$35, "middle", middle);
_$spread(_el$35, spread, false, true);
_$spread(
_el$35,
_$mergeProps(
{
start: "Hi",
middle: middle
},
spread
),
false,
true
);
return _el$35;
})();
const template27 = (() => {
var _el$36 = _tmpl$17();
_$spread(
_el$36,
_$mergeProps(
{
start: "Hi"
},
first,
{
middle: middle
Expand Down Expand Up @@ -820,4 +844,5 @@ const template88 = (() => {
});
return _el$107;
})();
const template89 = _tmpl$47();
_$delegateEvents(["click", "input"]);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { className as _$className } from "r-dom";
import { use as _$use } from "r-dom";
import { spread as _$spread } from "r-dom";
import { mergeProps as _$mergeProps } from "r-dom";
var _tmpl$ = /*#__PURE__*/ _$template(`<div id=main><h1 id=my-h1><a href=/>Welcome`),
var _tmpl$ = /*#__PURE__*/ _$template(`<div><h1><a href=/>Welcome`),
_tmpl$2 = /*#__PURE__*/ _$template(`<div><div></div><div> </div><div>`),
_tmpl$3 = /*#__PURE__*/ _$template(`<div foo>`),
_tmpl$4 = /*#__PURE__*/ _$template(`<div>`),
Expand All @@ -27,7 +27,7 @@ var _tmpl$ = /*#__PURE__*/ _$template(`<div id=main><h1 id=my-h1><a href=/>Welco
_tmpl$14 = /*#__PURE__*/ _$template(`<div data="&quot;hi&quot;"data2="&quot;">`),
_tmpl$15 = /*#__PURE__*/ _$template(`<a>`),
_tmpl$16 = /*#__PURE__*/ _$template(`<div><a>`),
_tmpl$17 = /*#__PURE__*/ _$template(`<div start=Hi>Hi`),
_tmpl$17 = /*#__PURE__*/ _$template(`<div>Hi`),
_tmpl$18 = /*#__PURE__*/ _$template(`<label><span>Input is </span><input><div>`),
_tmpl$19 = /*#__PURE__*/ _$template(
`<div class="class1 class2 class3 class4 class5 class6"random="random1 random2\n random3 random4"style="color:red;background-color:blue !important;border:1px solid black;font-size:12px">`
Expand Down Expand Up @@ -74,41 +74,53 @@ const template = (() => {
_el$3 = _el$2.firstChild;
_$spread(
_el$,
_$mergeProps(results, {
class: {
selected: unknown
_$mergeProps(
{
id: "main"
},
style: {
color
results,
{
class: {
selected: unknown
},
style: {
color
}
}
}),
),
false,
true
);
_$spread(
_el$2,
_$mergeProps(results, {
foo: "",
disabled: "",
get title() {
return welcoming();
},
get style() {
return {
"background-color": color(),
"margin-right": "40px"
};
_$mergeProps(
{
id: id
},
get ["class"]() {
return [
"base",
{
dynamic: dynamic(),
selected
}
];
results,
{
foo: "",
disabled: "",
get title() {
return welcoming();
},
get style() {
return {
"background-color": color(),
"margin-right": "40px"
};
},
get ["class"]() {
return [
"base",
{
dynamic: dynamic(),
selected
}
];
}
}
}),
),
false,
true
);
Expand Down Expand Up @@ -373,15 +385,28 @@ const template25 = (() => {
})();
const template26 = (() => {
var _el$35 = _tmpl$17();
_$setAttribute(_el$35, "middle", middle);
_$spread(_el$35, spread, false, true);
_$spread(
_el$35,
_$mergeProps(
{
start: "Hi",
middle: middle
},
spread
),
false,
true
);
return _el$35;
})();
const template27 = (() => {
var _el$36 = _tmpl$17();
_$spread(
_el$36,
_$mergeProps(
{
start: "Hi"
},
first,
{
middle: middle
Expand Down Expand Up @@ -808,4 +833,4 @@ const template88 = (() => {
});
return _el$107;
})();
_$delegateEvents(["click", "input"]);
_$delegateEvents(["click", "input"]);
Loading
Loading