Skip to content

Commit 928af5f

Browse files
authored
refactor(types): enable isolatedDeclarations (#11178)
1 parent 506c4c5 commit 928af5f

File tree

132 files changed

+776
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+776
-526
lines changed

packages/compiler-core/src/ast.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export function createVNodeCall(
618618
isBlock: VNodeCall['isBlock'] = false,
619619
disableTracking: VNodeCall['disableTracking'] = false,
620620
isComponent: VNodeCall['isComponent'] = false,
621-
loc = locStub,
621+
loc: SourceLocation = locStub,
622622
): VNodeCall {
623623
if (context) {
624624
if (isBlock) {
@@ -851,18 +851,24 @@ export function createReturnStatement(
851851
}
852852
}
853853

854-
export function getVNodeHelper(ssr: boolean, isComponent: boolean) {
854+
export function getVNodeHelper(
855+
ssr: boolean,
856+
isComponent: boolean,
857+
): typeof CREATE_VNODE | typeof CREATE_ELEMENT_VNODE {
855858
return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE
856859
}
857860

858-
export function getVNodeBlockHelper(ssr: boolean, isComponent: boolean) {
861+
export function getVNodeBlockHelper(
862+
ssr: boolean,
863+
isComponent: boolean,
864+
): typeof CREATE_BLOCK | typeof CREATE_ELEMENT_BLOCK {
859865
return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK
860866
}
861867

862868
export function convertToBlock(
863869
node: VNodeCall,
864870
{ helper, removeHelper, inSSR }: TransformContext,
865-
) {
871+
): void {
866872
if (!node.isBlock) {
867873
node.isBlock = true
868874
removeHelper(getVNodeHelper(inSSR, node.isComponent))

packages/compiler-core/src/babelUtils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function walkIdentifiers(
2828
includeAll = false,
2929
parentStack: Node[] = [],
3030
knownIds: Record<string, number> = Object.create(null),
31-
) {
31+
): void {
3232
if (__BROWSER__) {
3333
return
3434
}
@@ -108,7 +108,7 @@ export function isReferencedIdentifier(
108108
id: Identifier,
109109
parent: Node | null,
110110
parentStack: Node[],
111-
) {
111+
): boolean {
112112
if (__BROWSER__) {
113113
return false
114114
}
@@ -177,7 +177,7 @@ export function isInNewExpression(parentStack: Node[]): boolean {
177177
export function walkFunctionParams(
178178
node: Function,
179179
onIdent: (id: Identifier) => void,
180-
) {
180+
): void {
181181
for (const p of node.params) {
182182
for (const id of extractIdentifiers(p)) {
183183
onIdent(id)
@@ -188,7 +188,7 @@ export function walkFunctionParams(
188188
export function walkBlockDeclarations(
189189
block: BlockStatement | Program,
190190
onIdent: (node: Identifier) => void,
191-
) {
191+
): void {
192192
for (const stmt of block.body) {
193193
if (stmt.type === 'VariableDeclaration') {
194194
if (stmt.declare) continue
@@ -313,7 +313,7 @@ export const isStaticProperty = (node: Node): node is ObjectProperty =>
313313
(node.type === 'ObjectProperty' || node.type === 'ObjectMethod') &&
314314
!node.computed
315315

316-
export const isStaticPropertyKey = (node: Node, parent: Node) =>
316+
export const isStaticPropertyKey = (node: Node, parent: Node): boolean =>
317317
isStaticProperty(parent) && parent.key === node
318318

319319
/**
@@ -495,7 +495,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean {
495495
return true
496496
}
497497

498-
export const TS_NODE_TYPES = [
498+
export const TS_NODE_TYPES: string[] = [
499499
'TSAsExpression', // foo as number
500500
'TSTypeAssertion', // (<number>foo)
501501
'TSNonNullExpression', // foo!

packages/compiler-core/src/compat/compatConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function getCompatValue(
106106
export function isCompatEnabled(
107107
key: CompilerDeprecationTypes,
108108
context: MergedParserOptions | TransformContext,
109-
) {
109+
): boolean {
110110
const mode = getCompatValue('MODE', context)
111111
const value = getCompatValue(key, context)
112112
// in v3 mode, only enable if explicitly set to true
@@ -132,7 +132,7 @@ export function warnDeprecation(
132132
context: MergedParserOptions | TransformContext,
133133
loc: SourceLocation | null,
134134
...args: any[]
135-
) {
135+
): void {
136136
const val = getCompatValue(key, context)
137137
if (val === 'suppress-warning') {
138138
return

packages/compiler-core/src/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export interface CoreCompilerError extends CompilerError {
99
code: ErrorCodes
1010
}
1111

12-
export function defaultOnError(error: CompilerError) {
12+
export function defaultOnError(error: CompilerError): never {
1313
throw error
1414
}
1515

16-
export function defaultOnWarn(msg: CompilerError) {
16+
export function defaultOnWarn(msg: CompilerError): void {
1717
__DEV__ && console.warn(`[Vue warn] ${msg.message}`)
1818
}
1919

packages/compiler-core/src/runtimeHelpers.ts

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,85 @@
1-
export const FRAGMENT = Symbol(__DEV__ ? `Fragment` : ``)
2-
export const TELEPORT = Symbol(__DEV__ ? `Teleport` : ``)
3-
export const SUSPENSE = Symbol(__DEV__ ? `Suspense` : ``)
4-
export const KEEP_ALIVE = Symbol(__DEV__ ? `KeepAlive` : ``)
5-
export const BASE_TRANSITION = Symbol(__DEV__ ? `BaseTransition` : ``)
6-
export const OPEN_BLOCK = Symbol(__DEV__ ? `openBlock` : ``)
7-
export const CREATE_BLOCK = Symbol(__DEV__ ? `createBlock` : ``)
8-
export const CREATE_ELEMENT_BLOCK = Symbol(__DEV__ ? `createElementBlock` : ``)
9-
export const CREATE_VNODE = Symbol(__DEV__ ? `createVNode` : ``)
10-
export const CREATE_ELEMENT_VNODE = Symbol(__DEV__ ? `createElementVNode` : ``)
11-
export const CREATE_COMMENT = Symbol(__DEV__ ? `createCommentVNode` : ``)
12-
export const CREATE_TEXT = Symbol(__DEV__ ? `createTextVNode` : ``)
13-
export const CREATE_STATIC = Symbol(__DEV__ ? `createStaticVNode` : ``)
14-
export const RESOLVE_COMPONENT = Symbol(__DEV__ ? `resolveComponent` : ``)
15-
export const RESOLVE_DYNAMIC_COMPONENT = Symbol(
1+
export const FRAGMENT: unique symbol = Symbol(__DEV__ ? `Fragment` : ``)
2+
export const TELEPORT: unique symbol = Symbol(__DEV__ ? `Teleport` : ``)
3+
export const SUSPENSE: unique symbol = Symbol(__DEV__ ? `Suspense` : ``)
4+
export const KEEP_ALIVE: unique symbol = Symbol(__DEV__ ? `KeepAlive` : ``)
5+
export const BASE_TRANSITION: unique symbol = Symbol(
6+
__DEV__ ? `BaseTransition` : ``,
7+
)
8+
export const OPEN_BLOCK: unique symbol = Symbol(__DEV__ ? `openBlock` : ``)
9+
export const CREATE_BLOCK: unique symbol = Symbol(__DEV__ ? `createBlock` : ``)
10+
export const CREATE_ELEMENT_BLOCK: unique symbol = Symbol(
11+
__DEV__ ? `createElementBlock` : ``,
12+
)
13+
export const CREATE_VNODE: unique symbol = Symbol(__DEV__ ? `createVNode` : ``)
14+
export const CREATE_ELEMENT_VNODE: unique symbol = Symbol(
15+
__DEV__ ? `createElementVNode` : ``,
16+
)
17+
export const CREATE_COMMENT: unique symbol = Symbol(
18+
__DEV__ ? `createCommentVNode` : ``,
19+
)
20+
export const CREATE_TEXT: unique symbol = Symbol(
21+
__DEV__ ? `createTextVNode` : ``,
22+
)
23+
export const CREATE_STATIC: unique symbol = Symbol(
24+
__DEV__ ? `createStaticVNode` : ``,
25+
)
26+
export const RESOLVE_COMPONENT: unique symbol = Symbol(
27+
__DEV__ ? `resolveComponent` : ``,
28+
)
29+
export const RESOLVE_DYNAMIC_COMPONENT: unique symbol = Symbol(
1630
__DEV__ ? `resolveDynamicComponent` : ``,
1731
)
18-
export const RESOLVE_DIRECTIVE = Symbol(__DEV__ ? `resolveDirective` : ``)
19-
export const RESOLVE_FILTER = Symbol(__DEV__ ? `resolveFilter` : ``)
20-
export const WITH_DIRECTIVES = Symbol(__DEV__ ? `withDirectives` : ``)
21-
export const RENDER_LIST = Symbol(__DEV__ ? `renderList` : ``)
22-
export const RENDER_SLOT = Symbol(__DEV__ ? `renderSlot` : ``)
23-
export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``)
24-
export const TO_DISPLAY_STRING = Symbol(__DEV__ ? `toDisplayString` : ``)
25-
export const MERGE_PROPS = Symbol(__DEV__ ? `mergeProps` : ``)
26-
export const NORMALIZE_CLASS = Symbol(__DEV__ ? `normalizeClass` : ``)
27-
export const NORMALIZE_STYLE = Symbol(__DEV__ ? `normalizeStyle` : ``)
28-
export const NORMALIZE_PROPS = Symbol(__DEV__ ? `normalizeProps` : ``)
29-
export const GUARD_REACTIVE_PROPS = Symbol(__DEV__ ? `guardReactiveProps` : ``)
30-
export const TO_HANDLERS = Symbol(__DEV__ ? `toHandlers` : ``)
31-
export const CAMELIZE = Symbol(__DEV__ ? `camelize` : ``)
32-
export const CAPITALIZE = Symbol(__DEV__ ? `capitalize` : ``)
33-
export const TO_HANDLER_KEY = Symbol(__DEV__ ? `toHandlerKey` : ``)
34-
export const SET_BLOCK_TRACKING = Symbol(__DEV__ ? `setBlockTracking` : ``)
32+
export const RESOLVE_DIRECTIVE: unique symbol = Symbol(
33+
__DEV__ ? `resolveDirective` : ``,
34+
)
35+
export const RESOLVE_FILTER: unique symbol = Symbol(
36+
__DEV__ ? `resolveFilter` : ``,
37+
)
38+
export const WITH_DIRECTIVES: unique symbol = Symbol(
39+
__DEV__ ? `withDirectives` : ``,
40+
)
41+
export const RENDER_LIST: unique symbol = Symbol(__DEV__ ? `renderList` : ``)
42+
export const RENDER_SLOT: unique symbol = Symbol(__DEV__ ? `renderSlot` : ``)
43+
export const CREATE_SLOTS: unique symbol = Symbol(__DEV__ ? `createSlots` : ``)
44+
export const TO_DISPLAY_STRING: unique symbol = Symbol(
45+
__DEV__ ? `toDisplayString` : ``,
46+
)
47+
export const MERGE_PROPS: unique symbol = Symbol(__DEV__ ? `mergeProps` : ``)
48+
export const NORMALIZE_CLASS: unique symbol = Symbol(
49+
__DEV__ ? `normalizeClass` : ``,
50+
)
51+
export const NORMALIZE_STYLE: unique symbol = Symbol(
52+
__DEV__ ? `normalizeStyle` : ``,
53+
)
54+
export const NORMALIZE_PROPS: unique symbol = Symbol(
55+
__DEV__ ? `normalizeProps` : ``,
56+
)
57+
export const GUARD_REACTIVE_PROPS: unique symbol = Symbol(
58+
__DEV__ ? `guardReactiveProps` : ``,
59+
)
60+
export const TO_HANDLERS: unique symbol = Symbol(__DEV__ ? `toHandlers` : ``)
61+
export const CAMELIZE: unique symbol = Symbol(__DEV__ ? `camelize` : ``)
62+
export const CAPITALIZE: unique symbol = Symbol(__DEV__ ? `capitalize` : ``)
63+
export const TO_HANDLER_KEY: unique symbol = Symbol(
64+
__DEV__ ? `toHandlerKey` : ``,
65+
)
66+
export const SET_BLOCK_TRACKING: unique symbol = Symbol(
67+
__DEV__ ? `setBlockTracking` : ``,
68+
)
3569
/**
3670
* @deprecated no longer needed in 3.5+ because we no longer hoist element nodes
3771
* but kept for backwards compat
3872
*/
39-
export const PUSH_SCOPE_ID = Symbol(__DEV__ ? `pushScopeId` : ``)
73+
export const PUSH_SCOPE_ID: unique symbol = Symbol(__DEV__ ? `pushScopeId` : ``)
4074
/**
4175
* @deprecated kept for backwards compat
4276
*/
43-
export const POP_SCOPE_ID = Symbol(__DEV__ ? `popScopeId` : ``)
44-
export const WITH_CTX = Symbol(__DEV__ ? `withCtx` : ``)
45-
export const UNREF = Symbol(__DEV__ ? `unref` : ``)
46-
export const IS_REF = Symbol(__DEV__ ? `isRef` : ``)
47-
export const WITH_MEMO = Symbol(__DEV__ ? `withMemo` : ``)
48-
export const IS_MEMO_SAME = Symbol(__DEV__ ? `isMemoSame` : ``)
77+
export const POP_SCOPE_ID: unique symbol = Symbol(__DEV__ ? `popScopeId` : ``)
78+
export const WITH_CTX: unique symbol = Symbol(__DEV__ ? `withCtx` : ``)
79+
export const UNREF: unique symbol = Symbol(__DEV__ ? `unref` : ``)
80+
export const IS_REF: unique symbol = Symbol(__DEV__ ? `isRef` : ``)
81+
export const WITH_MEMO: unique symbol = Symbol(__DEV__ ? `withMemo` : ``)
82+
export const IS_MEMO_SAME: unique symbol = Symbol(__DEV__ ? `isMemoSame` : ``)
4983

5084
// Name mapping for runtime helpers that need to be imported from 'vue' in
5185
// generated code. Make sure these are correctly exported in the runtime!
@@ -91,7 +125,7 @@ export const helperNameMap: Record<symbol, string> = {
91125
[IS_MEMO_SAME]: `isMemoSame`,
92126
}
93127

94-
export function registerRuntimeHelpers(helpers: Record<symbol, string>) {
128+
export function registerRuntimeHelpers(helpers: Record<symbol, string>): void {
95129
Object.getOwnPropertySymbols(helpers).forEach(s => {
96130
helperNameMap[s] = helpers[s]
97131
})

packages/compiler-core/src/tokenizer.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,15 @@ export interface Callbacks {
213213
* We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End
214214
* sequences with an increased offset.
215215
*/
216-
export const Sequences = {
216+
export const Sequences: {
217+
Cdata: Uint8Array
218+
CdataEnd: Uint8Array
219+
CommentEnd: Uint8Array
220+
ScriptEnd: Uint8Array
221+
StyleEnd: Uint8Array
222+
TitleEnd: Uint8Array
223+
TextareaEnd: Uint8Array
224+
} = {
217225
Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]), // CDATA[
218226
CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]), // ]]>
219227
CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]), // `-->`
@@ -227,7 +235,7 @@ export const Sequences = {
227235

228236
export default class Tokenizer {
229237
/** The current state the tokenizer is in. */
230-
public state = State.Text
238+
public state: State = State.Text
231239
/** The read buffer. */
232240
private buffer = ''
233241
/** The beginning of the section that is currently being read. */
@@ -249,8 +257,8 @@ export default class Tokenizer {
249257

250258
private readonly entityDecoder?: EntityDecoder
251259

252-
public mode = ParseMode.BASE
253-
public get inSFCRoot() {
260+
public mode: ParseMode = ParseMode.BASE
261+
public get inSFCRoot(): boolean {
254262
return this.mode === ParseMode.SFC && this.stack.length === 0
255263
}
256264

@@ -526,7 +534,7 @@ export default class Tokenizer {
526534
this.state = State.SpecialStartSequence
527535
}
528536

529-
public enterRCDATA(sequence: Uint8Array, offset: number) {
537+
public enterRCDATA(sequence: Uint8Array, offset: number): void {
530538
this.inRCDATA = true
531539
this.currentSequence = sequence
532540
this.sequenceIndex = offset
@@ -917,7 +925,7 @@ export default class Tokenizer {
917925
*
918926
* States that are more likely to be hit are higher up, as a performance improvement.
919927
*/
920-
public parse(input: string) {
928+
public parse(input: string): void {
921929
this.buffer = input
922930
while (this.index < this.buffer.length) {
923931
const c = this.buffer.charCodeAt(this.index)

packages/compiler-core/src/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export function createTransformContext(
326326
return context
327327
}
328328

329-
export function transform(root: RootNode, options: TransformOptions) {
329+
export function transform(root: RootNode, options: TransformOptions): void {
330330
const context = createTransformContext(root, options)
331331
traverseNode(root, context)
332332
if (options.hoistStatic) {
@@ -403,7 +403,7 @@ function createRootCodegen(root: RootNode, context: TransformContext) {
403403
export function traverseChildren(
404404
parent: ParentNode,
405405
context: TransformContext,
406-
) {
406+
): void {
407407
let i = 0
408408
const nodeRemoved = () => {
409409
i--
@@ -422,7 +422,7 @@ export function traverseChildren(
422422
export function traverseNode(
423423
node: RootNode | TemplateChildNode,
424424
context: TransformContext,
425-
) {
425+
): void {
426426
context.currentNode = node
427427
// apply transform plugins
428428
const { nodeTransforms } = context

packages/compiler-core/src/transforms/cacheStatic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
OPEN_BLOCK,
3232
} from '../runtimeHelpers'
3333

34-
export function cacheStatic(root: RootNode, context: TransformContext) {
34+
export function cacheStatic(root: RootNode, context: TransformContext): void {
3535
walk(
3636
root,
3737
undefined,

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export function resolveComponentType(
228228
node: ComponentNode,
229229
context: TransformContext,
230230
ssr = false,
231-
) {
231+
): string | symbol | CallExpression {
232232
let { tag } = node
233233

234234
// 1. dynamic component
@@ -374,7 +374,7 @@ export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode
374374
export function buildProps(
375375
node: ElementNode,
376376
context: TransformContext,
377-
props: ElementNode['props'] = node.props,
377+
props: ElementNode['props'] | undefined = node.props,
378378
isComponent: boolean,
379379
isDynamicComponent: boolean,
380380
ssr = false,

packages/compiler-core/src/transforms/vBind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
9999
export const transformBindShorthand = (
100100
dir: DirectiveNode,
101101
context: TransformContext,
102-
) => {
102+
): void => {
103103
const arg = dir.arg!
104104

105105
const propName = camelize((arg as SimpleExpressionNode).content)

0 commit comments

Comments
 (0)