]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: disallow optional chaining (#10919)
authorKevin Deng 三咲智子 <sxzz@sxzz.moe>
Wed, 29 May 2024 07:03:20 +0000 (15:03 +0800)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 07:03:20 +0000 (15:03 +0800)
eslint.config.js
packages/compiler-core/src/babelUtils.ts
packages/reactivity/src/effect.ts
packages/runtime-core/src/devtools.ts
packages/runtime-core/src/hydration.ts
packages/runtime-core/src/warning.ts

index 3587a815067cd12215486fb05415a887c5b133af..334787fd9886a367ff9b6ef2a7d7e19b19a30f69 100644 (file)
@@ -45,6 +45,12 @@ export default tseslint.config(
           message:
             'Our output target is ES2016, so async/await syntax should be avoided.',
         },
+        {
+          selector: 'ChainExpression',
+          message:
+            'Our output target is ES2016, and optional chaining results in ' +
+            'verbose helpers and should be avoided.',
+        },
       ],
       'sort-imports': ['error', { ignoreDeclarationSort: true }],
 
@@ -134,7 +140,7 @@ export default tseslint.config(
   {
     files: [
       'eslint.config.js',
-      'rollup.config.js',
+      'rollup*.config.js',
       'scripts/**',
       './*.{js,ts}',
       'packages/*/*.js',
index d3812f84ce67e0a29137eabbae972693e14e2298..7482494e17a614d9bbea742c0cffcbd715c34cd1 100644 (file)
@@ -53,6 +53,7 @@ export function walkIdentifiers(
         }
       } else if (
         node.type === 'ObjectProperty' &&
+        // eslint-disable-next-line no-restricted-syntax
         parent?.type === 'ObjectPattern'
       ) {
         // mark property in destructure pattern
@@ -407,6 +408,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean {
     // no: export { NODE as foo } from "foo";
     case 'ExportSpecifier':
       // @ts-expect-error
+      // eslint-disable-next-line no-restricted-syntax
       if (grandparent?.source) {
         return false
       }
index 29d29cc42414e57905ea1a7ccf1bfea976575da2..1528f4b1d89aa1ca7c8336c68de8d0670e73dff5 100644 (file)
@@ -281,6 +281,7 @@ export function trackEffect(
       effect._depsLength++
     }
     if (__DEV__) {
+      // eslint-disable-next-line no-restricted-syntax
       effect.onTrack?.(extend({ effect }, debuggerEventExtraInfo!))
     }
   }
@@ -309,6 +310,7 @@ export function triggerEffects(
       (tracking ??= dep.get(effect) === effect._trackId)
     ) {
       if (__DEV__) {
+        // eslint-disable-next-line no-restricted-syntax
         effect.onTrigger?.(extend({ effect }, debuggerEventExtraInfo))
       }
       effect.trigger()
index 5bff57a416541f911ebdf8a554588f80e637fded..2af81be83707423343dcee9848aa01af6b21295e 100644 (file)
@@ -63,6 +63,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) {
     // some envs mock window but not fully
     window.HTMLElement &&
     // also exclude jsdom
+    // eslint-disable-next-line no-restricted-syntax
     !window.navigator?.userAgent?.includes('jsdom')
   ) {
     const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
index 87e4c60a2534ecb501e2f09009e9fe6680effe3b..3be8837ce4b85751d891bbcfc4f70c217ee534b5 100644 (file)
@@ -757,11 +757,14 @@ function propHasMismatch(
       }
     }
 
+    // eslint-disable-next-line no-restricted-syntax
     const root = instance?.subTree
     if (
       vnode === root ||
+      // eslint-disable-next-line no-restricted-syntax
       (root?.type === Fragment && (root.children as VNode[]).includes(vnode))
     ) {
+      // eslint-disable-next-line no-restricted-syntax
       const cssVars = instance?.getCssVars?.()
       for (const key in cssVars) {
         expectedMap.set(`--${key}`, String(cssVars[key]))
@@ -842,7 +845,9 @@ function toStyleMap(str: string): Map<string, string> {
   const styleMap: Map<string, string> = new Map()
   for (const item of str.split(';')) {
     let [key, value] = item.split(':')
+    // eslint-disable-next-line no-restricted-syntax
     key = key?.trim()
+    // eslint-disable-next-line no-restricted-syntax
     value = value?.trim()
     if (key && value) {
       styleMap.set(key, value)
index c3b2ebbd02db6f12efbfab1364d8ad7a20902559..d130638b6af965d11467e8791921a947427ec7e9 100644 (file)
@@ -45,6 +45,7 @@ export function warn(msg: string, ...args: any[]) {
       instance,
       ErrorCodes.APP_WARN_HANDLER,
       [
+        // eslint-disable-next-line no-restricted-syntax
         msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
         instance && instance.proxy,
         trace