Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 18, 2023
1 parent d261c02 commit 72f8bc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ exports[`SFC compile <script setup> with TypeScript defineEmits w/ type from nor
export interface Emits { (e: 'foo' | 'bar'): void }

export default /*#__PURE__*/_defineComponent({
emits: [\\"foo\\", \\"bar\\"],
emits: ["foo", "bar"],
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
expose();

Expand Down Expand Up @@ -1791,12 +1791,12 @@ exports[`SFC compile <script setup> with TypeScript withDefaults (static) + norm

export default /*#__PURE__*/_defineComponent({
props: {
a: { type: String, required: false, default: \\"a\\" }
a: { type: String, required: false, default: "a" }
},
setup(__props: any, { expose }) {
expose();

const props = __props as { a: string }
const props = __props as { a: string };



Expand Down
18 changes: 10 additions & 8 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export interface ImportBinding {
isUsedInTemplate: boolean
}

type FromNormalScript = { __fromNormalScript?: boolean }

type PropsDeclType = (TSTypeLiteral | TSInterfaceBody) & FromNormalScript

type EmitsDeclType = (TSFunctionType | TSTypeLiteral | TSInterfaceBody) & FromNormalScript
type FromNormalScript<T> = T & { __fromNormalScript?: boolean | null }
type PropsDeclType = FromNormalScript<TSTypeLiteral | TSInterfaceBody>
type EmitsDeclType = FromNormalScript<
TSFunctionType | TSTypeLiteral | TSInterfaceBody
>

/**
* Compile `<script setup>`
Expand Down Expand Up @@ -669,7 +669,7 @@ export function compileScript(
function resolveQualifiedType(
node: Node,
qualifier: (node: Node) => boolean
): (Node & FromNormalScript)| undefined {
): Node | undefined {
if (qualifier(node)) {
return node
}
Expand All @@ -693,7 +693,7 @@ export function compileScript(
filterExtendsType(extendsTypes, bodies)
qualified.body = bodies
}
;(qualified as Node & FromNormalScript).__fromNormalScript =
;(qualified as FromNormalScript<Node>).__fromNormalScript =
scriptAst && i >= scriptSetupAst.body.length
return qualified
}
Expand Down Expand Up @@ -1486,7 +1486,9 @@ export function compileScript(
if (destructureElements.length) {
args += `, { ${destructureElements.join(', ')} }`
if (emitsTypeDecl) {
const content = emitsTypeDecl.__fromNormalScript ? script!.content : scriptSetup.content
const content = emitsTypeDecl.__fromNormalScript
? script!.content
: scriptSetup.content
args += `: { emit: (${content.slice(
emitsTypeDecl.start!,
emitsTypeDecl.end!
Expand Down

0 comments on commit 72f8bc2

Please sign in to comment.