Skip to content

Commit 4575221

Browse files
ShreyAmbeshrenovate[bot]farnabaz
authored
Fix Nuxt V4 upgrade Fix (#411)
--------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Farnabaz <farnabaz@gmail.com>
1 parent a692428 commit 4575221

File tree

12 files changed

+1420
-452
lines changed

12 files changed

+1420
-452
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"verify": "npm run dev:prepare && npm run lint && npm run test && npm run typecheck"
6969
},
7070
"dependencies": {
71-
"@nuxt/kit": "^3.17.7",
71+
"@nuxt/kit": "^4.0.3",
7272
"@shikijs/langs": "^3.8.0",
7373
"@shikijs/themes": "^3.8.0",
7474
"@shikijs/transformers": "^3.8.0",
@@ -115,13 +115,13 @@
115115
"@nuxt/devtools": "^2.6.2",
116116
"@nuxt/eslint-config": "^1.5.2",
117117
"@nuxt/module-builder": "^1.0.1",
118-
"@nuxt/schema": "^3.17.7",
118+
"@nuxt/schema": "^4.0.3",
119119
"@nuxt/test-utils": "^3.19.2",
120120
"@nuxt/ui": "^3.2.0",
121121
"@nuxtjs/mdc": "link:.",
122122
"@types/node": "^24.0.13",
123123
"eslint": "^9.31.0",
124-
"nuxt": "^3.17.7",
124+
"nuxt": "^4.0.3",
125125
"rehype": "^13.0.2",
126126
"release-it": "^19.0.3",
127127
"typescript": "5.8.3",

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"@monaco-editor/loader": "^1.5.0",
1313
"@nuxtjs/mdc": "workspace:*",
1414
"@nuxtlabs/monarch-mdc": "^0.8.0",
15-
"nuxt": "^3.17.7"
15+
"nuxt": "^4.0.3"
1616
}
1717
}

pnpm-lock.yaml

Lines changed: 1396 additions & 431 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/components/MDCRenderer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function _renderSlots(node: MDCNode, h: CreateElement, options: MDCRenderOptions
228228
229229
const slotNodes: Record<string, { props?: Record<string, any>, children: MDCNode[] }> = children.reduce((data, node) => {
230230
if (!isTemplate(node)) {
231-
data[DEFAULT_SLOT].children.push(node)
231+
data[DEFAULT_SLOT]!.children.push(node)
232232
return data
233233
}
234234
@@ -445,7 +445,7 @@ function getSlotName(node: MDCNode) {
445445
continue
446446
}
447447
// Get slot name
448-
name = propName.split(/[:#]/, 2)[1]
448+
name = propName.split(/[:#]/, 2)[1]!
449449
break
450450
}
451451
return name || DEFAULT_SLOT

src/runtime/highlighter/shiki.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function createShikiHighlighter({
106106

107107
if (typeof lang === 'string' && !loadedLanguages.includes(lang) && !isSpecialLang(lang)) {
108108
if (bundledLangs[lang]) {
109-
await shiki.loadLanguage(bundledLangs[lang])
109+
await shiki.loadLanguage(bundledLangs[lang]!)
110110
} else {
111111
// eslint-disable-next-line nuxt/prefer-import-meta
112112
if (process.dev) {
@@ -165,9 +165,9 @@ export function createShikiHighlighter({
165165
if (code?.includes('\n')) {
166166
// Set newline for empty lines
167167
if (node.children.length === 0 || (
168-
node.children.length === 1 && node.children[0].type === 'element'
169-
&& node.children[0].children.length === 1 && node.children[0].children[0].type === 'text'
170-
&& node.children[0].children[0].value === ''
168+
node.children.length === 1 && node.children[0]!.type === 'element'
169+
&& node.children[0]!.children.length === 1 && node.children[0]!.children[0]!.type === 'text'
170+
&& node.children[0]!.children[0]!.value === ''
171171
)) {
172172
node.children = [{
173173
type: 'element',

src/runtime/parser/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function compileHast(this: any, options: MDCParseOptions = {}) {
119119
// Include styles if excerpt contains code block
120120
if (excerpt.children.find(node => node.type === 'element' && node.tag === 'pre')) {
121121
const lastChild = body.children[body.children.length - 1]
122-
if (lastChild.type === 'element' && lastChild.tag === 'style') {
122+
if (lastChild && lastChild.type === 'element' && lastChild.tag === 'style') {
123123
excerpt.children.push(lastChild)
124124
}
125125
}

src/runtime/parser/handlers/list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default function list(state: State, node: List) {
1616
const child = results[index]
1717

1818
if (
19-
child.type === 'element'
19+
child
20+
&& child.type === 'element'
2021
&& child.tagName === 'li'
2122
&& child.properties
2223
&& Array.isArray(child.properties.className)

src/runtime/parser/handlers/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function parseHighlightedLines(lines?: string | null) {
4848
.filter(Boolean)
4949
.flatMap((line) => {
5050
const [start, end] = line.trim().split('-').map(a => Number(a.trim()))
51-
return Array.from({ length: (end || start) - start + 1 }).map((_, i) => start + i)
51+
return Array.from({ length: (end || start || 0) - ((start || 0)) + 1 }).map((_, i) => (start || 0) + i)
5252
})
5353
return lineArray.length ? lineArray : undefined
5454
}

src/runtime/stringify/mdc-remark.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export function mdcRemark(options?: Options | undefined | null) {
6969
return
7070
}
7171
if (index && parent && parent.children) {
72-
if (index > 0 && parent.children[index - 1].type === 'text') {
72+
if (index > 0 && parent.children[index - 1]?.type === 'text') {
7373
const text = parent.children[index - 1] as Text
7474
if (!['\n', ' ', '\t'].includes(text.value.slice(-1))) {
7575
text.value += ' '
7676
}
7777
}
78-
if (index && index < parent.children.length - 1 && parent.children[index + 1].type === 'text') {
78+
if (index && index < parent.children.length - 1 && parent.children[index + 1]?.type === 'text') {
7979
const text = parent.children[index + 1] as Text
8080
if (!['\n', ' ', '\t', ',', '.'].includes(text.value.slice(0, 1))) {
8181
text.value = ' ' + text.value
@@ -143,7 +143,7 @@ const mdcRemarkNodeHandlers = {
143143
}
144144

145145
if (own.call(state.handlers, node.tagName)) {
146-
return state.handlers[node.tagName](state, node as Element, parent) || undefined
146+
return state.handlers[node.tagName]!(state, node as Element, parent) || undefined
147147
}
148148

149149
// Unknown literal.

src/runtime/stringify/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function computeHighlightRanges(input: string[] | string) {
44
let start = numbers[0]
55

66
for (let i = 1; i <= numbers.length; i++) {
7-
if (numbers[i] !== numbers[i - 1] + 1) {
7+
if (numbers[i] !== numbers[i - 1]! + 1) {
88
if (start === numbers[i - 1]) {
99
ranges.push(`${start}`)
1010
} else {

0 commit comments

Comments
 (0)