Skip to content

Commit 59a8c26

Browse files
committed
Revert "feat(compiler-sfc): expose resolve type-based props and emits (vuejs#8874)"
This reverts commit d52617f.
1 parent dc54c59 commit 59a8c26

File tree

4 files changed

+13
-48
lines changed

4 files changed

+13
-48
lines changed

packages/compiler-sfc/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export {
3333

3434
// Internals for type resolution
3535
export { invalidateTypeCache, registerTS } from './script/resolveType'
36-
export { extractRuntimeProps } from './script/defineProps'
37-
export { extractRuntimeEmits } from './script/defineEmits'
3836

3937
// Types
4038
export type {
@@ -60,7 +58,6 @@ export type { SFCScriptCompileOptions } from './compileScript'
6058
export type { ScriptCompileContext } from './script/context'
6159
export type {
6260
TypeResolveContext,
63-
SimpleTypeResolveOptions,
6461
SimpleTypeResolveContext
6562
} from './script/resolveType'
6663
export type {

packages/compiler-sfc/src/script/defineEmits.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
} from '@babel/types'
99
import { isCallOf } from './utils'
1010
import { ScriptCompileContext } from './context'
11-
import {
12-
TypeResolveContext,
13-
resolveTypeElements,
14-
resolveUnionType
15-
} from './resolveType'
11+
import { resolveTypeElements, resolveUnionType } from './resolveType'
1612

1713
export const DEFINE_EMITS = 'defineEmits'
1814

@@ -68,7 +64,7 @@ export function genRuntimeEmits(ctx: ScriptCompileContext): string | undefined {
6864
return emitsDecl
6965
}
7066

71-
export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
67+
function extractRuntimeEmits(ctx: ScriptCompileContext): Set<string> {
7268
const emits = new Set<string>()
7369
const node = ctx.emitsTypeDecl!
7470

@@ -101,7 +97,7 @@ export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
10197
}
10298

10399
function extractEventNames(
104-
ctx: TypeResolveContext,
100+
ctx: ScriptCompileContext,
105101
eventName: ArrayPattern | Identifier | ObjectPattern | RestElement,
106102
emits: Set<string>
107103
) {

packages/compiler-sfc/src/script/defineProps.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
} from '@babel/types'
99
import { BindingTypes, isFunctionType } from '@vue/compiler-dom'
1010
import { ScriptCompileContext } from './context'
11-
import {
12-
TypeResolveContext,
13-
inferRuntimeType,
14-
resolveTypeElements
15-
} from './resolveType'
11+
import { inferRuntimeType, resolveTypeElements } from './resolveType'
1612
import {
1713
resolveObjectKey,
1814
UNKNOWN_TYPE,
@@ -154,7 +150,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
154150
}
155151
}
156152
} else if (ctx.propsTypeDecl) {
157-
propsDecls = extractRuntimeProps(ctx)
153+
propsDecls = genRuntimePropsFromTypes(ctx)
158154
}
159155

160156
const modelsDecls = genModelProps(ctx)
@@ -166,9 +162,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
166162
}
167163
}
168164

169-
export function extractRuntimeProps(
170-
ctx: TypeResolveContext
171-
): string | undefined {
165+
function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
172166
// this is only called if propsTypeDecl exists
173167
const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl!)
174168
if (!props.length) {
@@ -181,7 +175,7 @@ export function extractRuntimeProps(
181175
for (const prop of props) {
182176
propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults))
183177
// register bindings
184-
if ('bindingMetadata' in ctx && !(prop.key in ctx.bindingMetadata)) {
178+
if (!(prop.key in ctx.bindingMetadata)) {
185179
ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
186180
}
187181
}
@@ -199,7 +193,7 @@ export function extractRuntimeProps(
199193
}
200194

201195
function resolveRuntimePropsFromType(
202-
ctx: TypeResolveContext,
196+
ctx: ScriptCompileContext,
203197
node: Node
204198
): PropTypeData[] {
205199
const props: PropTypeData[] = []
@@ -228,7 +222,7 @@ function resolveRuntimePropsFromType(
228222
}
229223

230224
function genRuntimePropFromType(
231-
ctx: TypeResolveContext,
225+
ctx: ScriptCompileContext,
232226
{ key, required, type, skipCheck }: PropTypeData,
233227
hasStaticDefaults: boolean
234228
): string {
@@ -290,7 +284,7 @@ function genRuntimePropFromType(
290284
* static properties, we can directly generate more optimized default
291285
* declarations. Otherwise we will have to fallback to runtime merging.
292286
*/
293-
function hasStaticWithDefaults(ctx: TypeResolveContext) {
287+
function hasStaticWithDefaults(ctx: ScriptCompileContext) {
294288
return !!(
295289
ctx.propsRuntimeDefaults &&
296290
ctx.propsRuntimeDefaults.type === 'ObjectExpression' &&
@@ -303,7 +297,7 @@ function hasStaticWithDefaults(ctx: TypeResolveContext) {
303297
}
304298

305299
function genDestructuredDefaultValue(
306-
ctx: TypeResolveContext,
300+
ctx: ScriptCompileContext,
307301
key: string,
308302
inferredType?: string[]
309303
):

packages/compiler-sfc/src/script/resolveType.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ import type TS from 'typescript'
4242
import { extname, dirname } from 'path'
4343
import { minimatch as isMatch } from 'minimatch'
4444

45-
export type SimpleTypeResolveOptions = Partial<
46-
Pick<
47-
SFCScriptCompileOptions,
48-
'globalTypeFiles' | 'fs' | 'babelParserPlugins' | 'isProd'
49-
>
50-
>
51-
5245
/**
5346
* TypeResolveContext is compatible with ScriptCompileContext
5447
* but also allows a simpler version of it with minimal required properties
@@ -66,28 +59,13 @@ export type SimpleTypeResolveOptions = Partial<
6659
*/
6760
export type SimpleTypeResolveContext = Pick<
6861
ScriptCompileContext,
69-
// file
70-
| 'source'
71-
| 'filename'
72-
73-
// utils
74-
| 'error'
75-
| 'helper'
76-
| 'getString'
77-
78-
// props
79-
| 'propsTypeDecl'
80-
| 'propsRuntimeDefaults'
81-
| 'propsDestructuredBindings'
82-
83-
// emits
84-
| 'emitsTypeDecl'
62+
// required
63+
'source' | 'filename' | 'error' | 'options'
8564
> &
8665
Partial<
8766
Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>
8867
> & {
8968
ast: Statement[]
90-
options: SimpleTypeResolveOptions
9169
}
9270

9371
export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext

0 commit comments

Comments
 (0)