Skip to content

Commit

Permalink
chore(deps): upgrade to TypeScript 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 10, 2024
1 parent e596378 commit b1db66a
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 106 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "node scripts/dev.js",
"build": "node scripts/build.js",
"build-dts": "tsc -p tsconfig.build-browser.json && tsc -p tsconfig.build-node.json && rollup -c rollup.dts.config.js",
"build-dts": "tsc -p tsconfig.build.json --noCheck && rollup -c rollup.dts.config.js",
"clean": "rimraf --glob packages/*/dist temp .eslintcache",
"size": "run-s \"size-*\" && tsx scripts/usage-size.ts",
"size-global": "node scripts/build.js vue runtime-dom -f global -p --size",
Expand Down Expand Up @@ -105,7 +105,7 @@
"todomvc-app-css": "^2.4.3",
"tslib": "^2.7.0",
"tsx": "^4.19.0",
"typescript": "~5.5.4",
"typescript": "~5.6.2",
"typescript-eslint": "^8.4.0",
"vite": "catalog:",
"vitest": "^2.0.5"
Expand Down
7 changes: 7 additions & 0 deletions packages-private/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"isolatedDeclarations": false
},
"include": ["."]
}
11 changes: 8 additions & 3 deletions packages/compiler-core/__tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ElementTypes,
Namespaces,
NodeTypes,
type Property,
type SimpleExpressionNode,
type VNodeCall,
locStub,
} from '../src'
Expand All @@ -22,7 +24,10 @@ const bracketsRE = /^\[|\]$/g
// e.g.
// - createObjectMatcher({ 'foo': '[bar]' }) matches { foo: bar }
// - createObjectMatcher({ '[foo]': 'bar' }) matches { [foo]: "bar" }
export function createObjectMatcher(obj: Record<string, any>) {
export function createObjectMatcher(obj: Record<string, any>): {
type: NodeTypes
properties: Partial<Property>[]
} {
return {
type: NodeTypes.JS_OBJECT_EXPRESSION,
properties: Object.keys(obj).map(key => ({
Expand All @@ -31,7 +36,7 @@ export function createObjectMatcher(obj: Record<string, any>) {
type: NodeTypes.SIMPLE_EXPRESSION,
content: key.replace(bracketsRE, ''),
isStatic: !leadingBracketRE.test(key),
},
} as SimpleExpressionNode,
value: isString(obj[key])
? {
type: NodeTypes.SIMPLE_EXPRESSION,
Expand Down Expand Up @@ -78,7 +83,7 @@ type Flags = PatchFlags | ShapeFlags
export function genFlagText(
flag: Flags | Flags[],
names: { [k: number]: string } = PatchFlagNames,
) {
): string {
if (isArray(flag)) {
let f = 0
flag.forEach(ff => {
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type ForNode,
type InterpolationNode,
NodeTypes,
type RootNode,
type SimpleExpressionNode,
} from '../../src/ast'
import { ErrorCodes } from '../../src/errors'
Expand All @@ -24,7 +25,10 @@ import { createObjectMatcher } from '../testUtils'
export function parseWithForTransform(
template: string,
options: CompilerOptions = {},
) {
): {
root: RootNode
node: ForNode & { codegenNode: ForCodegenNode }
} {
const ast = parse(template, options)
transform(ast, {
nodeTransforms: [
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-sfc/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type SFCParseOptions,
type SFCScriptBlock,
type SFCScriptCompileOptions,
compileScript,
parse,
Expand All @@ -12,7 +13,7 @@ export function compileSFCScript(
src: string,
options?: Partial<SFCScriptCompileOptions>,
parseOptions?: SFCParseOptions,
) {
): SFCScriptBlock {
const { descriptor, errors } = parse(src, parseOptions)
if (errors.length) {
console.warn(errors[0])
Expand All @@ -23,7 +24,7 @@ export function compileSFCScript(
})
}

export function assertCode(code: string) {
export function assertCode(code: string): void {
// parse the generated code to make sure it is valid
try {
babelParse(code, {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const KeepAliveImpl: ComponentOptions = {
keys.add(key)
// prune oldest entry
if (max && keys.size > parseInt(max as string, 10)) {
pruneCacheEntry(keys.values().next().value)
pruneCacheEntry(keys.values().next().value!)
}
}
// avoid vnode being unmounted
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const render = baseRender as RootRenderFunction<TestElement>
export const createApp = baseCreateApp as CreateAppFunction<TestElement>

// convenience for one-off render validations
export function renderToString(vnode: VNode) {
export function renderToString(vnode: VNode): string {
const root = nodeOps.createElement('div')
render(vnode, root)
return serializeInner(root)
Expand Down
32 changes: 24 additions & 8 deletions packages/runtime-test/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export interface NodeOp {
let nodeId: number = 0
let recordedNodeOps: NodeOp[] = []

export function logNodeOp(op: NodeOp) {
export function logNodeOp(op: NodeOp): void {
recordedNodeOps.push(op)
}

export function resetOps() {
export function resetOps(): void {
recordedNodeOps = []
}

Expand Down Expand Up @@ -128,7 +128,7 @@ function createComment(text: string): TestComment {
return node
}

function setText(node: TestText, text: string) {
function setText(node: TestText, text: string): void {
logNodeOp({
type: NodeOpTypes.SET_TEXT,
targetNode: node,
Expand All @@ -137,7 +137,11 @@ function setText(node: TestText, text: string) {
node.text = text
}

function insert(child: TestNode, parent: TestElement, ref?: TestNode | null) {
function insert(
child: TestNode,
parent: TestElement,
ref?: TestNode | null,
): void {
let refIndex
if (ref) {
refIndex = parent.children.indexOf(ref)
Expand Down Expand Up @@ -166,7 +170,7 @@ function insert(child: TestNode, parent: TestElement, ref?: TestNode | null) {
}
}

function remove(child: TestNode, logOp = true) {
function remove(child: TestNode, logOp = true): void {
const parent = child.parentNode
if (parent) {
if (logOp) {
Expand All @@ -188,7 +192,7 @@ function remove(child: TestNode, logOp = true) {
}
}

function setElementText(el: TestElement, text: string) {
function setElementText(el: TestElement, text: string): void {
logNodeOp({
type: NodeOpTypes.SET_ELEMENT_TEXT,
targetNode: el,
Expand Down Expand Up @@ -228,11 +232,23 @@ function querySelector(): never {
throw new Error('querySelector not supported in test renderer.')
}

function setScopeId(el: TestElement, id: string) {
function setScopeId(el: TestElement, id: string): void {
el.props[id] = ''
}

export const nodeOps = {
export const nodeOps: {
insert: typeof insert
remove: typeof remove
createElement: typeof createElement
createText: typeof createText
createComment: typeof createComment
setText: typeof setText
setElementText: typeof setElementText
parentNode: typeof parentNode
nextSibling: typeof nextSibling
querySelector: typeof querySelector
setScopeId: typeof setScopeId
} = {
insert,
remove,
createElement,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-test/src/patchProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function patchProp(
key: string,
prevValue: any,
nextValue: any,
) {
): void {
logNodeOp({
type: NodeOpTypes.PATCH,
targetNode: el,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-test/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function serializeInner(
node: TestElement,
indent: number = 0,
depth: number = 0,
) {
): string {
const newLine = indent ? `\n` : ``
return node.children.length
? newLine +
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-test/src/triggerEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function triggerEvent(
el: TestElement,
event: string,
payload: any[] = [],
) {
): void {
const { eventListeners } = el
if (eventListeners) {
const listener = eventListeners[event]
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-compat/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function triggerEvent(
target: Element,
event: string,
process?: (e: any) => any,
) {
): Event {
const e = new Event(event, {
bubbles: true,
cancelable: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/__tests__/e2e/commits.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,4 @@ export default {
],
},
],
}
} as any
51 changes: 37 additions & 14 deletions packages/vue/__tests__/e2e/e2eUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ export async function expectByPolling(
}
}

export function setupPuppeteer(args?: string[]) {
interface PuppeteerUtils {
page: () => Page
click(selector: string, options?: ClickOptions): Promise<void>
count(selector: string): Promise<number>
text(selector: string): Promise<string | null>
value(selector: string): Promise<string>
html(selector: string): Promise<string>
classList(selector: string): Promise<string[]>
children(selector: string): Promise<any[]>
isVisible(selector: string): Promise<boolean>
isChecked(selector: string): Promise<boolean>
isFocused(selector: string): Promise<boolean>
setValue(selector: string, value: string): Promise<any>
typeValue(selector: string, value: string): Promise<any>
enterValue(selector: string, value: string): Promise<any>
clearValue(selector: string): Promise<any>
timeout(time: number): Promise<any>
nextFrame(): Promise<any>
}

export function setupPuppeteer(args?: string[]): PuppeteerUtils {
let browser: Browser
let page: Page

Expand Down Expand Up @@ -69,35 +89,38 @@ export function setupPuppeteer(args?: string[]) {
await browser.close()
})

async function click(selector: string, options?: ClickOptions) {
async function click(
selector: string,
options?: ClickOptions,
): Promise<void> {
await page.click(selector, options)
}

async function count(selector: string) {
async function count(selector: string): Promise<number> {
return (await page.$$(selector)).length
}

async function text(selector: string) {
return await page.$eval(selector, node => node.textContent)
async function text(selector: string): Promise<string | null> {
return page.$eval(selector, node => node.textContent)
}

async function value(selector: string) {
return await page.$eval(selector, node => (node as HTMLInputElement).value)
async function value(selector: string): Promise<string> {
return page.$eval(selector, node => (node as HTMLInputElement).value)
}

async function html(selector: string) {
return await page.$eval(selector, node => node.innerHTML)
async function html(selector: string): Promise<string> {
return page.$eval(selector, node => node.innerHTML)
}

async function classList(selector: string) {
return await page.$eval(selector, (node: any) => [...node.classList])
async function classList(selector: string): Promise<string[]> {
return page.$eval(selector, (node: any) => [...node.classList])
}

async function children(selector: string) {
return await page.$eval(selector, (node: any) => [...node.children])
async function children(selector: string): Promise<any[]> {
return page.$eval(selector, (node: any) => [...node.children])
}

async function isVisible(selector: string) {
async function isVisible(selector: string): Promise<boolean> {
const display = await page.$eval(selector, node => {
return window.getComputedStyle(node).display
})
Expand Down
Loading

0 comments on commit b1db66a

Please sign in to comment.