Skip to content

Commit d00632b

Browse files
refactor: remove optional chaining (#10792)
1 parent 1138e7a commit d00632b

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/compiler-core/src/parser.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const tokenizer = new Tokenizer(stack, {
179179
const name = currentOpenTag!.tag
180180
currentOpenTag!.isSelfClosing = true
181181
endOpenTag(end)
182-
if (stack[0]?.tag === name) {
182+
if (stack[0] && stack[0].tag === name) {
183183
onCloseTag(stack.shift()!, end)
184184
}
185185
},
@@ -587,14 +587,14 @@ function endOpenTag(end: number) {
587587

588588
function onText(content: string, start: number, end: number) {
589589
if (__BROWSER__) {
590-
const tag = stack[0]?.tag
590+
const tag = stack[0] && stack[0].tag
591591
if (tag !== 'script' && tag !== 'style' && content.includes('&')) {
592592
content = currentOptions.decodeEntities!(content, false)
593593
}
594594
}
595595
const parent = stack[0] || currentRoot
596596
const lastNode = parent.children[parent.children.length - 1]
597-
if (lastNode?.type === NodeTypes.TEXT) {
597+
if (lastNode && lastNode.type === NodeTypes.TEXT) {
598598
// merge
599599
lastNode.content += content
600600
setLocEnd(lastNode.loc, end)
@@ -771,7 +771,8 @@ function isComponent({ tag, props }: ElementNode): boolean {
771771
tag === 'component' ||
772772
isUpperCase(tag.charCodeAt(0)) ||
773773
isCoreComponent(tag) ||
774-
currentOptions.isBuiltInComponent?.(tag) ||
774+
(currentOptions.isBuiltInComponent &&
775+
currentOptions.isBuiltInComponent(tag)) ||
775776
(currentOptions.isNativeTag && !currentOptions.isNativeTag(tag))
776777
) {
777778
return true
@@ -828,8 +829,8 @@ function condenseWhitespace(
828829
if (node.type === NodeTypes.TEXT) {
829830
if (!inPre) {
830831
if (isAllWhitespace(node.content)) {
831-
const prev = nodes[i - 1]?.type
832-
const next = nodes[i + 1]?.type
832+
const prev = nodes[i - 1] && nodes[i - 1].type
833+
const next = nodes[i + 1] && nodes[i + 1].type
833834
// Remove if:
834835
// - the whitespace is the first or last node, or:
835836
// - (condense mode) the whitespace is between two comments, or:
@@ -1063,7 +1064,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
10631064
currentOptions.ns === Namespaces.SVG ||
10641065
currentOptions.ns === Namespaces.MATH_ML
10651066

1066-
const delimiters = options?.delimiters
1067+
const delimiters = options && options.delimiters
10671068
if (delimiters) {
10681069
tokenizer.delimiterOpen = toCharCodes(delimiters[0])
10691070
tokenizer.delimiterClose = toCharCodes(delimiters[1])

packages/reactivity/src/effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class ReactiveEffect<T = any> {
128128
if (this.active) {
129129
preCleanupEffect(this)
130130
postCleanupEffect(this)
131-
this.onStop?.()
131+
this.onStop && this.onStop()
132132
this.active = false
133133
}
134134
}

packages/reactivity/src/reactiveEffect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,6 @@ export function trigger(
146146
}
147147

148148
export function getDepFromReactive(object: any, key: string | number | symbol) {
149-
return targetMap.get(object)?.get(key)
149+
const depsMap = targetMap.get(object)
150+
return depsMap && depsMap.get(key)
150151
}

packages/runtime-core/src/components/Suspense.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ function createSuspenseBoundary(
479479
let parentSuspenseId: number | undefined
480480
const isSuspensible = isVNodeSuspensible(vnode)
481481
if (isSuspensible) {
482-
if (parentSuspense?.pendingBranch) {
482+
if (parentSuspense && parentSuspense.pendingBranch) {
483483
parentSuspenseId = parentSuspense.pendingId
484484
parentSuspense.deps++
485485
}
@@ -898,5 +898,6 @@ function setActiveBranch(suspense: SuspenseBoundary, branch: VNode) {
898898
}
899899

900900
function isVNodeSuspensible(vnode: VNode) {
901-
return vnode.props?.suspensible != null && vnode.props.suspensible !== false
901+
const suspensible = vnode.props && vnode.props.suspensible
902+
return suspensible != null && suspensible !== false
902903
}

0 commit comments

Comments
 (0)