Repository: nuxt/nuxt
File: packages/nuxt/src/core/plugins/keyed-functions.ts (TypeScript)

Code before:
        function getFunctionMetaByLocalName (localName: string, source: string): BackwardsCompatibleKeyedFunction | undefined {
          if (!localName) { return }
          // check exports (higher priority)
          const exportedName = localNamesToExportedName.get(localName)
          if (exportedName) {
            return namesToSourcesToFunctionMeta.get(exportedName)?.get(source)
          }
          // check static direct imports
          const directImport = directImports.get(localName)
          if (directImport) {
            const functionName = directImport.originalName === 'default'
              ? camelCase(parse(directImport.source).name)
              : directImport.originalName

            // TODO: remove auto-import checks in Nuxt 5
            const sourcesToMetas = namesToSourcesToFunctionMeta.get(functionName)
            if (!sourcesToMetas) { return }

            const fnMeta = sourcesToMetas.get(source)
            if (fnMeta) { return fnMeta }

            // TODO: remove in Nuxt 5
            if (
              source.startsWith(nuxtSrcPath)
              // ensure that the path has been resolved
              && nuxtSrcPath !== '#app'
            ) {
              for (const [fnSource, meta] of sourcesToMetas) {
                if (meta.name !== functionName || !fnSource.startsWith(nuxtSrcPath)) { continue }
                return meta
              }
            }

            const backwardsCompatibleFnMeta = sourcesToMetas.get('') // functions without a source or with a regex fall under ''
            if (backwardsCompatibleFnMeta?.source === undefined) {
              const autoImportResolvedSource = stripExtension(resolveAlias(autoImportsToSources.get(localName) ?? ''))
              if (autoImportResolvedSource === source) {
                return backwardsCompatibleFnMeta
              }
            } else if (backwardsCompatibleFnMeta.source instanceof RegExp && backwardsCompatibleFnMeta.source.test(source)) {
              return backwardsCompatibleFnMeta
            }

            return
          }

          // check local names
          return namesToSourcesToFunctionMeta.get(localName)?.get(source)
        }

        // TODO: use async walker or create sync version of `resolvePath` from kit

Review comment (bug):
this was done primarily because of a failing test case

adding the `#app` alias to the tests broke a lot of them, so I decided to solve it this way, though I'm not too happy about it

Code after:
        function getFunctionMetaByLocalName (localName: string, source: string): BackwardsCompatibleKeyedFunction | undefined {
          if (!localName) { return }
          // check exports (higher priority)
          const exportedName = localNamesToExportedName.get(localName)
          if (exportedName) {
            return namesToSourcesToFunctionMeta.get(exportedName)?.get(source)
          }
          // check static direct imports
          const directImport = directImports.get(localName)
          if (directImport) {
            const functionName = directImport.originalName === 'default'
              ? camelCase(parse(directImport.source).name)
              : directImport.originalName

            // TODO: remove auto-import checks in Nuxt 5
            const sourcesToMetas = namesToSourcesToFunctionMeta.get(functionName)
            if (!sourcesToMetas) { return }

            const fnMeta = sourcesToMetas.get(source)
            if (fnMeta) { return fnMeta }

            // TODO: remove in Nuxt 5
            if (source.startsWith(options.appDir)) {
              for (const [fnSource, meta] of sourcesToMetas) {
                if (meta.name !== functionName || !fnSource.startsWith(options.appDir)) { continue }
                return meta
              }
            }

            const backwardsCompatibleFnMeta = sourcesToMetas.get('') // functions without a source or with a regex fall under ''
            if (backwardsCompatibleFnMeta?.source === undefined) {
              const autoImportResolvedSource = stripExtension(resolveAlias(autoImportsToSources.get(localName) ?? ''))
              if (autoImportResolvedSource === source) {
                return backwardsCompatibleFnMeta
              }
            } else if (backwardsCompatibleFnMeta.source instanceof RegExp && backwardsCompatibleFnMeta.source.test(source)) {
              return backwardsCompatibleFnMeta
            }

            return
          }

          // check local names
          return namesToSourcesToFunctionMeta.get(localName)?.get(source)
        }

        // TODO: use async walker or create sync version of `resolvePath` from kit
        function _resolvePath (path: string) {
          let p = path
          if (isAbsolute(p)) { return p }
          p = resolveAlias(p, options.alias)