style: fix lint errors in vapor

This commit is contained in:
Rizumu Ayaka 2023-12-29 22:05:33 +08:00
parent a82d070890
commit dce55475a5
No known key found for this signature in database
31 changed files with 155 additions and 144 deletions

View File

@ -1,4 +1,4 @@
import { type RootNode, BindingTypes } from '@vue/compiler-dom'
import { BindingTypes, type RootNode } from '@vue/compiler-dom'
import { type CompilerOptions, compile as _compile } from '../src'
function compile(template: string | RootNode, options: CompilerOptions = {}) {

View File

@ -1,14 +1,14 @@
import { ErrorCodes, NodeTypes } from '@vue/compiler-dom'
import {
type RootIRNode,
type CompilerOptions,
parse,
transform,
transformVBind,
transformElement,
IRNodeTypes,
type RootIRNode,
compile as _compile,
generate,
parse,
transform,
transformElement,
transformVBind,
} from '../../src'
function compileWithVBind(

View File

@ -6,11 +6,11 @@ import {
} from '@vue/compiler-dom'
import {
type CompilerOptions,
compile as _compile,
RootIRNode,
transform,
generate,
IRNodeTypes,
type RootIRNode,
compile as _compile,
generate,
transform,
} from '../../src'
import { getBaseTransformPreset } from '../../src/compile'

View File

@ -1,11 +1,11 @@
import { BindingTypes, ErrorCodes, parse, NodeTypes } from '@vue/compiler-dom'
import { BindingTypes, ErrorCodes, NodeTypes, parse } from '@vue/compiler-dom'
import {
type CompilerOptions,
compile as _compile,
RootIRNode,
transform,
generate,
IRNodeTypes,
type RootIRNode,
compile as _compile,
generate,
transform,
} from '../../src'
import { transformVOn } from '../../src/transforms/vOn'

View File

@ -1,11 +1,11 @@
import { BindingTypes, NodeTypes, parse } from '@vue/compiler-dom'
import {
type CompilerOptions,
compile as _compile,
transform,
generate as generate,
IRNodeTypes,
RootIRNode,
type RootIRNode,
compile as _compile,
generate as generate,
transform,
} from '../../src'
import { getBaseTransformPreset } from '../../src/compile'

View File

@ -6,11 +6,11 @@ import {
} from '@vue/compiler-dom'
import {
type CompilerOptions,
compile as _compile,
RootIRNode,
transform,
generate,
IRNodeTypes,
type RootIRNode,
compile as _compile,
generate,
transform,
} from '../../src'
import { getBaseTransformPreset } from '../../src/compile'

View File

@ -1,11 +1,11 @@
import {
type CodegenResult,
type CompilerOptions as BaseCompilerOptions,
type RootNode,
parse,
defaultOnError,
createCompilerError,
type CodegenResult,
ErrorCodes,
type RootNode,
createCompilerError,
defaultOnError,
parse,
} from '@vue/compiler-dom'
import { extend, isString } from '@vue/shared'
import {

View File

@ -1,6 +1,6 @@
import {
CompilerError,
SourceLocation,
type CompilerError,
type SourceLocation,
createCompilerError,
} from '@vue/compiler-dom'

View File

@ -1,33 +1,33 @@
import {
BindingTypes,
type CodegenOptions,
type CodegenResult,
NewlineType,
type Position,
type SourceLocation,
NewlineType,
advancePositionWithMutation,
locStub,
BindingTypes,
createSimpleExpression,
walkIdentifiers,
advancePositionWithClone,
advancePositionWithMutation,
createSimpleExpression,
isSimpleIdentifier,
locStub,
walkIdentifiers,
} from '@vue/compiler-dom'
import {
type IRDynamicChildren,
type RootIRNode,
type SetPropIRNode,
type IRExpression,
type OperationNode,
type VaporHelper,
type SetEventIRNode,
type WithDirectiveIRNode,
type SetTextIRNode,
type SetHtmlIRNode,
type CreateTextNodeIRNode,
type InsertNodeIRNode,
type PrependNodeIRNode,
type AppendNodeIRNode,
type CreateTextNodeIRNode,
type IRDynamicChildren,
type IRExpression,
IRNodeTypes,
type InsertNodeIRNode,
type OperationNode,
type PrependNodeIRNode,
type RootIRNode,
type SetEventIRNode,
type SetHtmlIRNode,
type SetPropIRNode,
type SetTextIRNode,
type VaporHelper,
type WithDirectiveIRNode,
} from './ir'
import { SourceMapGenerator } from 'source-map-js'
import { camelize, isGloballyAllowed, isString, makeMap } from '@vue/shared'
@ -212,7 +212,7 @@ function createCodegenContext(
generatedLine: context.line,
generatedColumn: context.column - 1,
source: filename,
// @ts-ignore it is possible to be null
// @ts-expect-error it is possible to be null
name,
})
}

View File

@ -1,24 +1,24 @@
import {
type AllNode,
type TransformOptions as BaseTransformOptions,
type CompilerCompatOptions,
type ElementNode,
NodeTypes,
type ParentNode,
type RootNode,
type TemplateChildNode,
type ElementNode,
type TransformOptions as BaseTransformOptions,
type ParentNode,
type AllNode,
type CompilerCompatOptions,
NodeTypes,
defaultOnError,
defaultOnWarn,
} from '@vue/compiler-dom'
import { EMPTY_OBJ, NOOP, isArray } from '@vue/shared'
import { EMPTY_OBJ, NOOP, extend, isArray } from '@vue/shared'
import {
type OperationNode,
type RootIRNode,
type IRDynamicInfo,
type IRExpression,
IRNodeTypes,
type OperationNode,
type RootIRNode,
} from './ir'
import type { VaporDirectiveNode, HackOptions } from './ir'
import type { HackOptions, VaporDirectiveNode } from './ir'
export type NodeTransform = (
node: RootNode | TemplateChildNode,
@ -73,30 +73,33 @@ function createRootContext(
parent: null,
index: 0,
root: null!, // set later
options: {
filename: '',
prefixIdentifiers: false,
hoistStatic: false,
hmr: false,
cacheHandlers: false,
nodeTransforms: [],
directiveTransforms: {},
transformHoist: null,
isBuiltInComponent: NOOP,
isCustomElement: NOOP,
expressionPlugins: [],
scopeId: null,
slotted: true,
ssr: false,
inSSR: false,
ssrCssVars: ``,
bindingMetadata: EMPTY_OBJ,
inline: false,
isTS: false,
onError: defaultOnError,
onWarn: defaultOnWarn,
...options,
},
options: extend(
{},
{
filename: '',
prefixIdentifiers: false,
hoistStatic: false,
hmr: false,
cacheHandlers: false,
nodeTransforms: [],
directiveTransforms: {},
transformHoist: null,
isBuiltInComponent: NOOP,
isCustomElement: NOOP,
expressionPlugins: [],
scopeId: null,
slotted: true,
ssr: false,
inSSR: false,
ssrCssVars: ``,
bindingMetadata: EMPTY_OBJ,
inline: false,
isTS: false,
onError: defaultOnError,
onWarn: defaultOnWarn,
},
options,
),
dynamic: ir.dynamic,
inVOnce: false,
@ -175,8 +178,7 @@ function createContext<T extends TemplateChildNode>(
parent: TransformContext<ParentNode>,
index: number,
): TransformContext<T> {
const ctx: TransformContext<T> = {
...parent,
const ctx: TransformContext<T> = extend({}, parent, {
node,
parent,
index,
@ -190,7 +192,7 @@ function createContext<T extends TemplateChildNode>(
placeholder: null,
children: {},
},
}
})
return ctx
}

View File

@ -1,12 +1,12 @@
import {
type ElementNode,
type AttributeNode,
NodeTypes,
type ElementNode,
ElementTypes,
NodeTypes,
} from '@vue/compiler-dom'
import { isBuiltInDirective, isVoidTag } from '@vue/shared'
import { NodeTransform, TransformContext } from '../transform'
import { VaporDirectiveNode, IRNodeTypes } from '../ir'
import type { NodeTransform, TransformContext } from '../transform'
import { IRNodeTypes, type VaporDirectiveNode } from '../ir'
export const transformElement: NodeTransform = (node, ctx) => {
return function postTransformElement() {

View File

@ -1,5 +1,5 @@
import { NodeTypes, SimpleExpressionNode } from '@vue/compiler-dom'
import { NodeTransform } from '../transform'
import { NodeTypes, type SimpleExpressionNode } from '@vue/compiler-dom'
import type { NodeTransform } from '../transform'
import { IRNodeTypes } from '../ir'
export const transformInterpolation: NodeTransform = (node, ctx) => {

View File

@ -1,7 +1,7 @@
import {
ErrorCodes,
createCompilerError,
createSimpleExpression,
ErrorCodes,
} from '@vue/compiler-core'
import { camelize } from '@vue/shared'
import { IRNodeTypes } from '../ir'

View File

@ -1,5 +1,5 @@
import { IRNodeTypes } from '../ir'
import { DirectiveTransform } from '../transform'
import type { DirectiveTransform } from '../transform'
import { DOMErrorCodes, createDOMCompilerError } from '@vue/compiler-dom'
export const transformVHtml: DirectiveTransform = (dir, node, context) => {

View File

@ -1,12 +1,12 @@
import {
createCompilerError,
ElementTypes,
ErrorCodes,
createCompilerError,
} from '@vue/compiler-core'
import type { DirectiveTransform } from '../transform'
import { IRNodeTypes, KeyOverride, SetEventIRNode } from '../ir'
import { IRNodeTypes, type KeyOverride, type SetEventIRNode } from '../ir'
import { resolveModifiers } from '@vue/compiler-dom'
import { camelize } from '@vue/shared'
import { camelize, extend } from '@vue/shared'
export const transformVOn: DirectiveTransform = (dir, node, context) => {
let { arg, exp, loc, modifiers } = dir
@ -54,7 +54,7 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
if (nonKeyModifiers.includes('right')) {
if (isStaticClick) {
arg = { ...arg, content: 'contextmenu' }
arg = extend({}, arg, { content: 'contextmenu' })
} else if (!arg.isStatic) {
keyOverride = ['click', 'contextmenu']
}
@ -64,7 +64,7 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
// TODO error here
}
if (isStaticClick) {
arg = { ...arg, content: 'mouseup' }
arg = extend({}, arg, { content: 'mouseup' })
} else if (!arg.isStatic) {
keyOverride = ['click', 'mouseup']
}

View File

@ -1,5 +1,5 @@
import { NodeTypes, findDir } from '@vue/compiler-dom'
import { NodeTransform } from '../transform'
import type { NodeTransform } from '../transform'
const seen = new WeakSet()

View File

@ -1,5 +1,5 @@
import { DOMErrorCodes, createDOMCompilerError } from '@vue/compiler-dom'
import { DirectiveTransform } from '../transform'
import type { DirectiveTransform } from '../transform'
import { IRNodeTypes } from '../ir'
export const transformVText: DirectiveTransform = (dir, node, context) => {

View File

@ -1,4 +1,4 @@
import { EffectScope, Ref, ref } from '@vue/reactivity'
import { EffectScope, type Ref, ref } from '@vue/reactivity'
import {
onEffectCleanup,
watchEffect,

View File

@ -1,9 +1,9 @@
import {
template,
children,
setText,
render,
ref,
render,
setText,
template,
unmountComponent,
watchEffect,
} from '../src'

View File

@ -1,4 +1,4 @@
import { template, fragment } from '../src'
import { fragment, template } from '../src'
describe('api: template', () => {
test('create element', () => {

View File

@ -1,6 +1,6 @@
import { template, children, withDirectives, on, vShow, render } from '../src'
import { ref, defineComponent, nextTick } from 'vue'
import { beforeEach, afterEach, describe, test, expect } from 'vitest'
import { children, on, render, template, vShow, withDirectives } from '../src'
import { defineComponent, nextTick, ref } from 'vue'
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
let host: HTMLElement

View File

@ -1,13 +1,13 @@
import {
ComputedRef,
Ref,
type ComputedRef,
type DebuggerOptions,
type EffectScheduler,
ReactiveEffect,
ReactiveFlags,
type Ref,
getCurrentScope,
isReactive,
isRef,
ReactiveEffect,
EffectScheduler,
DebuggerOptions,
getCurrentScope,
ReactiveFlags,
} from '@vue/reactivity'
import {
EMPTY_OBJ,
@ -25,10 +25,10 @@ import {
import { currentInstance } from './component'
import {
type Scheduler,
type SchedulerJob,
getVaporSchedulerByFlushMode,
vaporPostScheduler,
vaporSyncScheduler,
SchedulerJob,
} from './scheduler'
import {
VaporErrorCodes,

View File

@ -1,8 +1,8 @@
import { EffectScope, Ref, ref } from '@vue/reactivity'
import { EffectScope, type Ref, ref } from '@vue/reactivity'
import { EMPTY_OBJ } from '@vue/shared'
import { Block } from './render'
import { type DirectiveBinding } from './directive'
import type { Block } from './render'
import type { DirectiveBinding } from './directive'
import {
type ComponentPropsOptions,
type NormalizedPropsOptions,

View File

@ -1,7 +1,7 @@
// NOTE: runtime-core/src/componentProps.ts
import {
Data,
type Data,
EMPTY_ARR,
EMPTY_OBJ,
camelize,
@ -13,7 +13,7 @@ import {
isReservedProp,
} from '@vue/shared'
import { shallowReactive, toRaw } from '@vue/reactivity'
import { type ComponentInternalInstance, type Component } from './component'
import type { Component, ComponentInternalInstance } from './component'
export type ComponentPropsOptions<P = Data> =
| ComponentObjectPropsOptions<P>

View File

@ -1,5 +1,5 @@
import { isFunction } from '@vue/shared'
import { currentInstance, type ComponentInternalInstance } from './component'
import { type ComponentInternalInstance, currentInstance } from './component'
import { watchEffect } from './apiWatch'
export type DirectiveModifiers<M extends string = string> = Record<M, boolean>

View File

@ -107,9 +107,16 @@ export function setDynamicProp(el: Element, key: string, val: any) {
type Children = Record<number, [ChildNode, Children]>
export function children(n: Node): Children {
return { ...Array.from(n.childNodes).map((n) => [n, children(n)]) }
const result: Children = {}
const array = Array.from(n.childNodes)
for (let i = 0; i < array.length; i++) {
const n = array[i]
result[i] = [n, children(n)]
}
return result
}
export function createTextNode(val: unknown): Text {
// eslint-disable-next-line no-restricted-globals
return document.createTextNode(toDisplayString(val))
}

View File

@ -3,7 +3,7 @@
// The ultimate aim is to uncouple this replicated code and
// facilitate its shared use between two runtimes.
import { type ComponentInternalInstance } from './component'
import type { ComponentInternalInstance } from './component'
import { isFunction, isPromise } from '@vue/shared'
import { warn } from './warning'
import { VaporLifecycleHooks } from './enums'

View File

@ -1,5 +1,5 @@
import { proxyRefs } from '@vue/reactivity'
import { invokeArrayFns, type Data } from '@vue/shared'
import { type Data, invokeArrayFns } from '@vue/shared'
import {
type Component,
type ComponentInternalInstance,
@ -33,7 +33,8 @@ export function render(
export function normalizeContainer(container: string | ParentNode): ParentNode {
return typeof container === 'string'
? (document.querySelector(container) as ParentNode)
? // eslint-disable-next-line no-restricted-globals
(document.querySelector(container) as ParentNode)
: container
}

View File

@ -1,5 +1,5 @@
import { ReactiveEffect } from '@vue/reactivity'
import { ComponentInternalInstance } from './component'
import type { ReactiveEffect } from '@vue/reactivity'
import type { ComponentInternalInstance } from './component'
import { getIsRendering } from '.'
export interface SchedulerJob extends Function {

View File

@ -4,6 +4,7 @@ export const template = (str: string): (() => DocumentFragment) => {
return () => {
if (!cached) {
cached = true
// eslint-disable-next-line no-restricted-globals
const t = document.createElement('template')
t.innerHTML = str
// first render: insert the node directly.

View File

@ -3,10 +3,10 @@ import {
children,
on,
ref,
template,
watchEffect,
render as renderComponent,
setText,
render as renderComponent // TODO:
template,
watchEffect, // TODO:
} from '@vue/vapor'
export default {
@ -22,7 +22,7 @@ export default {
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
value: true
value: true,
})
return __returned__
@ -32,7 +32,7 @@ export default {
const t0 = template('<button></button>')
const n0 = t0()
const {
0: [n1]
0: [n1],
} = children(n0)
on(n1, 'click', _ctx.handleClick)
watchEffect(() => {
@ -55,36 +55,36 @@ export default {
/* <Comp :inline-double="count * 2" /> */
get inlineDouble() {
return _ctx.count * 2
}
},
},
n0
n0,
)
return n0
}
},
}
const child = {
props: {
count: { type: Number, default: 1 },
inlineDouble: { type: Number, default: 2 }
inlineDouble: { type: Number, default: 2 },
},
setup(props) {
watch(
() => props.count,
v => console.log('count changed', v)
v => console.log('count changed', v),
)
watch(
() => props.inlineDouble,
v => console.log('inlineDouble changed', v)
v => console.log('inlineDouble changed', v),
)
const __returned__ = {}
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
value: true
value: true,
})
return __returned__
@ -94,11 +94,11 @@ const child = {
const t0 = template('<p></p>')
const n0 = t0()
const {
0: [n1]
0: [n1],
} = children(n0)
watchEffect(() => {
setText(n1, void 0, _ctx.count + ' * 2 = ' + _ctx.inlineDouble)
})
return n0
}
},
}