jsx-loc-plugin 0.2.20 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QPTFKQPZ.js → chunk-QKGIN5XY.js} +5 -4
- package/dist/loader.cjs +5 -4
- package/dist/loader.js +1 -1
- package/dist/vite.cjs +5 -4
- package/dist/vite.js +1 -1
- package/package.json +1 -1
|
@@ -74,10 +74,11 @@ function shouldSkipElement(elementName) {
|
|
|
74
74
|
if (!elementName) return true;
|
|
75
75
|
return SKIP_ELEMENTS.has(elementName);
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
var DATA_ATTR = "data-loc";
|
|
78
|
+
function hasDataAttribute(node) {
|
|
78
79
|
if (!node.attributes) return false;
|
|
79
80
|
return node.attributes.some(
|
|
80
|
-
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name ===
|
|
81
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name === DATA_ATTR
|
|
81
82
|
);
|
|
82
83
|
}
|
|
83
84
|
function findInsertionPoint(node, source) {
|
|
@@ -123,14 +124,14 @@ function transformJsxCode(source, filePath, options = {}) {
|
|
|
123
124
|
if (!node || typeof node !== "object") return;
|
|
124
125
|
if (node.type === "JSXOpeningElement") {
|
|
125
126
|
const elementName = getElementName(node);
|
|
126
|
-
if (!shouldSkipElement(elementName) && !
|
|
127
|
+
if (!shouldSkipElement(elementName) && !hasDataAttribute(node)) {
|
|
127
128
|
const loc = node.loc;
|
|
128
129
|
if (loc && loc.start) {
|
|
129
130
|
const line = loc.start.line;
|
|
130
131
|
const column = loc.start.column;
|
|
131
132
|
const locValue = `${normalizedPath}:${line}:${column}`;
|
|
132
133
|
const insertPos = findInsertionPoint(node, source);
|
|
133
|
-
magicString.appendLeft(insertPos, `
|
|
134
|
+
magicString.appendLeft(insertPos, ` ${DATA_ATTR}="${locValue}"`);
|
|
134
135
|
hasChanges = true;
|
|
135
136
|
}
|
|
136
137
|
}
|
package/dist/loader.cjs
CHANGED
|
@@ -110,10 +110,11 @@ function shouldSkipElement(elementName) {
|
|
|
110
110
|
if (!elementName) return true;
|
|
111
111
|
return SKIP_ELEMENTS.has(elementName);
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
var DATA_ATTR = "data-loc";
|
|
114
|
+
function hasDataAttribute(node) {
|
|
114
115
|
if (!node.attributes) return false;
|
|
115
116
|
return node.attributes.some(
|
|
116
|
-
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name ===
|
|
117
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name === DATA_ATTR
|
|
117
118
|
);
|
|
118
119
|
}
|
|
119
120
|
function findInsertionPoint(node, source) {
|
|
@@ -159,14 +160,14 @@ function transformJsxCode(source, filePath, options = {}) {
|
|
|
159
160
|
if (!node || typeof node !== "object") return;
|
|
160
161
|
if (node.type === "JSXOpeningElement") {
|
|
161
162
|
const elementName = getElementName(node);
|
|
162
|
-
if (!shouldSkipElement(elementName) && !
|
|
163
|
+
if (!shouldSkipElement(elementName) && !hasDataAttribute(node)) {
|
|
163
164
|
const loc = node.loc;
|
|
164
165
|
if (loc && loc.start) {
|
|
165
166
|
const line = loc.start.line;
|
|
166
167
|
const column = loc.start.column;
|
|
167
168
|
const locValue = `${normalizedPath}:${line}:${column}`;
|
|
168
169
|
const insertPos = findInsertionPoint(node, source);
|
|
169
|
-
magicString.appendLeft(insertPos, `
|
|
170
|
+
magicString.appendLeft(insertPos, ` ${DATA_ATTR}="${locValue}"`);
|
|
170
171
|
hasChanges = true;
|
|
171
172
|
}
|
|
172
173
|
}
|
package/dist/loader.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -111,10 +111,11 @@ function shouldSkipElement(elementName) {
|
|
|
111
111
|
if (!elementName) return true;
|
|
112
112
|
return SKIP_ELEMENTS.has(elementName);
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
var DATA_ATTR = "data-loc";
|
|
115
|
+
function hasDataAttribute(node) {
|
|
115
116
|
if (!node.attributes) return false;
|
|
116
117
|
return node.attributes.some(
|
|
117
|
-
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name ===
|
|
118
|
+
(attr) => attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name === DATA_ATTR
|
|
118
119
|
);
|
|
119
120
|
}
|
|
120
121
|
function findInsertionPoint(node, source) {
|
|
@@ -160,14 +161,14 @@ function transformJsxCode(source, filePath, options = {}) {
|
|
|
160
161
|
if (!node || typeof node !== "object") return;
|
|
161
162
|
if (node.type === "JSXOpeningElement") {
|
|
162
163
|
const elementName = getElementName(node);
|
|
163
|
-
if (!shouldSkipElement(elementName) && !
|
|
164
|
+
if (!shouldSkipElement(elementName) && !hasDataAttribute(node)) {
|
|
164
165
|
const loc = node.loc;
|
|
165
166
|
if (loc && loc.start) {
|
|
166
167
|
const line = loc.start.line;
|
|
167
168
|
const column = loc.start.column;
|
|
168
169
|
const locValue = `${normalizedPath}:${line}:${column}`;
|
|
169
170
|
const insertPos = findInsertionPoint(node, source);
|
|
170
|
-
magicString.appendLeft(insertPos, `
|
|
171
|
+
magicString.appendLeft(insertPos, ` ${DATA_ATTR}="${locValue}"`);
|
|
171
172
|
hasChanges = true;
|
|
172
173
|
}
|
|
173
174
|
}
|
package/dist/vite.js
CHANGED