Skip to content

Commit

Permalink
chore: @typescript-eslint/explicit-module-boundary-types (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 14, 2021
1 parent 8472d33 commit 3337060
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function handleHotUpdate({
return [...affectedModules].filter(Boolean) as ModuleNode[]
}

export function isEqualBlock(a: SFCBlock | null, b: SFCBlock | null) {
export function isEqualBlock(a: SFCBlock | null, b: SFCBlock | null): boolean {
if (!a && !b) return true
if (!a || !b) return false
// src imports will trigger their own updates
Expand All @@ -161,7 +161,7 @@ export function isEqualBlock(a: SFCBlock | null, b: SFCBlock | null) {
export function isOnlyTemplateChanged(
prev: SFCDescriptor,
next: SFCDescriptor
) {
): boolean {
return (
isEqualBlock(prev.script, next.script) &&
isEqualBlock(prev.scriptSetup, next.scriptSetup) &&
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export function setResolvedScript(
descriptor: SFCDescriptor,
script: SFCScriptBlock,
ssr: boolean
) {
): void {
;(ssr ? ssrCache : clientCache).set(descriptor, script)
}

export function resolveScript(
descriptor: SFCDescriptor,
options: ResolvedOptions,
ssr: boolean
) {
): SFCScriptBlock | null {
if (!descriptor.script && !descriptor.scriptSetup) {
return null
}
Expand Down
24 changes: 18 additions & 6 deletions packages/plugin-vue/src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import path from 'path'
import slash from 'slash'
import hash from 'hash-sum'
import { parse, SFCDescriptor } from '@vue/compiler-sfc'
import { CompilerError, parse, SFCDescriptor } from '@vue/compiler-sfc'

// node_modules/@vue/compiler-sfc/dist/compiler-sfc.d.ts SFCParseResult should be exported so it can be re-used
export interface SFCParseResult {
descriptor: SFCDescriptor
errors: Array<CompilerError | SyntaxError>
}

const cache = new Map<string, SFCDescriptor>()
const prevCache = new Map<string, SFCDescriptor | undefined>()
Expand All @@ -11,7 +17,7 @@ export function createDescriptor(
source: string,
root: string,
isProduction: boolean | undefined
) {
): SFCParseResult {
const { descriptor, errors } = parse(source, {
filename,
sourceMap: true
Expand All @@ -26,15 +32,21 @@ export function createDescriptor(
return { descriptor, errors }
}

export function getPrevDescriptor(filename: string) {
export function getPrevDescriptor(filename: string): SFCDescriptor | undefined {
return prevCache.get(filename)
}

export function setPrevDescriptor(filename: string, entry: SFCDescriptor) {
export function setPrevDescriptor(
filename: string,
entry: SFCDescriptor
): void {
prevCache.set(filename, entry)
}

export function getDescriptor(filename: string, errorOnMissing = true) {
export function getDescriptor(
filename: string,
errorOnMissing = true
): SFCDescriptor | undefined {
if (cache.has(filename)) {
return cache.get(filename)!
}
Expand All @@ -46,6 +58,6 @@ export function getDescriptor(filename: string, errorOnMissing = true) {
}
}

export function setDescriptor(filename: string, entry: SFCDescriptor) {
export function setDescriptor(filename: string, entry: SFCDescriptor): void {
cache.set(filename, entry)
}
4 changes: 3 additions & 1 deletion packages/plugin-vue/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface VueQuery {
raw?: boolean
}

export function parseVueRequest(id: string) {
export function parseVueRequest(
id: string
): { filename: string; query: VueQuery } {
const [filename, rawQuery] = id.split(`?`, 2)
const query = qs.parse(rawQuery) as VueQuery
if (query.vue != null) {
Expand Down

0 comments on commit 3337060

Please sign in to comment.