@nuasite/cms 0.3.0 → 0.3.1
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/package.json
CHANGED
|
@@ -131,7 +131,7 @@ function extractElementBounds(
|
|
|
131
131
|
): ArrayElementBounds[] {
|
|
132
132
|
const bounds: ArrayElementBounds[] = []
|
|
133
133
|
for (const el of elements) {
|
|
134
|
-
if (el
|
|
134
|
+
if (el?.loc) {
|
|
135
135
|
bounds.push({
|
|
136
136
|
// Babel loc is 1-indexed; convert to 0-indexed file lines
|
|
137
137
|
startLine: el.loc.start.line - 1 + frontmatterStartLine,
|
|
@@ -273,7 +273,7 @@ export async function handleRemoveArrayItem(
|
|
|
273
273
|
const freshLines = freshContent.split('\n')
|
|
274
274
|
|
|
275
275
|
const bounds = elementBounds[arrayIndex]!
|
|
276
|
-
|
|
276
|
+
const removeStart = bounds.startLine
|
|
277
277
|
let removeEnd = bounds.endLine
|
|
278
278
|
|
|
279
279
|
// Clean up trailing comma on the line after the element, or leading comma
|
|
@@ -298,7 +298,7 @@ export async function handleRemoveArrayItem(
|
|
|
298
298
|
if (removeStart > 0 && removeStart <= freshLines.length) {
|
|
299
299
|
const prevLine = freshLines[removeStart - 1]!
|
|
300
300
|
const nextLine = freshLines[removeStart]
|
|
301
|
-
if (nextLine
|
|
301
|
+
if (nextLine?.trim().startsWith(']') && prevLine.trimEnd().endsWith(',')) {
|
|
302
302
|
freshLines[removeStart - 1] = prevLine.replace(/,\s*$/, '')
|
|
303
303
|
}
|
|
304
304
|
}
|
|
@@ -397,7 +397,7 @@ export async function handleAddArrayItem(
|
|
|
397
397
|
for (let i = freshLines.length - 1; i >= 0; i--) {
|
|
398
398
|
if (freshLines[i]!.trim().startsWith(']')) {
|
|
399
399
|
const prev = freshLines[i - 1]
|
|
400
|
-
if (prev
|
|
400
|
+
if (prev?.trimEnd().endsWith(',')) {
|
|
401
401
|
// Check if this is the array we're editing by scanning backwards
|
|
402
402
|
// to find the array variable
|
|
403
403
|
freshLines[i - 1] = prev.replace(/,(\s*)$/, '$1')
|