mirror of https://github.com/vuejs/core.git
refactor(compiler-sfc): remove useless type generation
we are no longer type-checking generated code
This commit is contained in:
parent
acd7eb22cf
commit
fe9760188d
|
@ -2084,11 +2084,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as {
|
const props = __props;
|
||||||
foo?: string
|
|
||||||
bar?: number
|
|
||||||
baz: boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2112,12 +2108,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as {
|
const props = __props;
|
||||||
foo: () => void
|
|
||||||
bar: boolean
|
|
||||||
baz: boolean | (() => void)
|
|
||||||
qux: string | number
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2140,11 +2131,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as {
|
const props = __props;
|
||||||
foo?: string
|
|
||||||
bar?: number
|
|
||||||
baz: boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2168,7 +2155,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as { a: string };
|
const props = __props;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2194,7 +2181,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string };
|
const props = __props;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2217,7 +2204,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as { foo: () => void, bar: boolean, baz: boolean | (() => void), qux: string | number };
|
const props = __props;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2239,9 +2226,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
setup(__props: any, { expose: __expose }) {
|
setup(__props: any, { expose: __expose }) {
|
||||||
__expose();
|
__expose();
|
||||||
|
|
||||||
const props = __props as {
|
const props = __props;
|
||||||
foo?: () => 'string'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1482,9 +1482,6 @@ const emit = defineEmits(['a', 'b'])
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`fred: { type: String, required: false, get default() { return 'fred' } }`
|
`fred: { type: String, required: false, get default() { return 'fred' } }`
|
||||||
)
|
)
|
||||||
expect(content).toMatch(
|
|
||||||
`{ foo: string, bar?: number, baz: boolean, qux(): number, quux(): void, quuxx: Promise<string>, fred: string }`
|
|
||||||
)
|
|
||||||
expect(content).toMatch(`const props = __props`)
|
expect(content).toMatch(`const props = __props`)
|
||||||
expect(bindings).toStrictEqual({
|
expect(bindings).toStrictEqual({
|
||||||
foo: BindingTypes.PROPS,
|
foo: BindingTypes.PROPS,
|
||||||
|
|
|
@ -59,8 +59,7 @@ import { ScriptCompileContext } from './script/context'
|
||||||
import {
|
import {
|
||||||
processDefineProps,
|
processDefineProps,
|
||||||
DEFINE_PROPS,
|
DEFINE_PROPS,
|
||||||
WITH_DEFAULTS,
|
WITH_DEFAULTS
|
||||||
PropsDeclType
|
|
||||||
} from './script/defineProps'
|
} from './script/defineProps'
|
||||||
|
|
||||||
// Special compiler macros
|
// Special compiler macros
|
||||||
|
@ -1002,52 +1001,6 @@ export function compileScript(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function genSetupPropsType(node: PropsDeclType) {
|
|
||||||
const scriptSource = node.__fromNormalScript
|
|
||||||
? script!.content
|
|
||||||
: scriptSetup!.content
|
|
||||||
if (hasStaticWithDefaults()) {
|
|
||||||
// if withDefaults() is used, we need to remove the optional flags
|
|
||||||
// on props that have default values
|
|
||||||
let res = `{ `
|
|
||||||
const members = node.type === 'TSTypeLiteral' ? node.members : node.body
|
|
||||||
for (const m of members) {
|
|
||||||
if (
|
|
||||||
(m.type === 'TSPropertySignature' ||
|
|
||||||
m.type === 'TSMethodSignature') &&
|
|
||||||
m.typeAnnotation &&
|
|
||||||
m.key.type === 'Identifier'
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
(ctx.propsRuntimeDefaults as ObjectExpression).properties.some(
|
|
||||||
p => {
|
|
||||||
if (p.type === 'SpreadElement') return false
|
|
||||||
return (
|
|
||||||
resolveObjectKey(p.key, p.computed) ===
|
|
||||||
(m.key as Identifier).name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
res +=
|
|
||||||
m.key.name +
|
|
||||||
(m.type === 'TSMethodSignature' ? '()' : '') +
|
|
||||||
scriptSource.slice(
|
|
||||||
m.typeAnnotation.start!,
|
|
||||||
m.typeAnnotation.end!
|
|
||||||
) +
|
|
||||||
', '
|
|
||||||
} else {
|
|
||||||
res += scriptSource.slice(m.start!, m.typeAnnotation.end!) + `, `
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (res.length ? res.slice(0, -2) : res) + ` }`
|
|
||||||
} else {
|
|
||||||
return scriptSource.slice(node.start!, node.end!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function genRuntimeEmits() {
|
function genRuntimeEmits() {
|
||||||
function genEmitsFromTS() {
|
function genEmitsFromTS() {
|
||||||
return typeDeclaredEmits.size
|
return typeDeclaredEmits.size
|
||||||
|
@ -1659,12 +1612,7 @@ export function compileScript(
|
||||||
// we use a default __props so that template expressions referencing props
|
// we use a default __props so that template expressions referencing props
|
||||||
// can use it directly
|
// can use it directly
|
||||||
if (ctx.propsIdentifier) {
|
if (ctx.propsIdentifier) {
|
||||||
s.prependLeft(
|
s.prependLeft(startOffset, `\nconst ${ctx.propsIdentifier} = __props;\n`)
|
||||||
startOffset,
|
|
||||||
`\nconst ${ctx.propsIdentifier} = __props${
|
|
||||||
ctx.propsTypeDecl ? ` as ${genSetupPropsType(ctx.propsTypeDecl)}` : ``
|
|
||||||
};\n`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (ctx.propsDestructureRestId) {
|
if (ctx.propsDestructureRestId) {
|
||||||
s.prependLeft(
|
s.prependLeft(
|
||||||
|
|
Loading…
Reference in New Issue