wip: remove unnecessary inlinePropsIdentifier option

This commit is contained in:
Evan You 2020-11-11 10:36:59 -05:00
parent 4e8ef55237
commit 2a4fc32d15
5 changed files with 12 additions and 28 deletions

View File

@ -66,10 +66,7 @@ export interface CodegenResult {
} }
export interface CodegenContext export interface CodegenContext
extends Omit< extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
Required<CodegenOptions>,
'bindingMetadata' | 'inline' | 'inlinePropsIdentifier'
> {
source: string source: string
code: string code: string
line: number line: number

View File

@ -91,10 +91,6 @@ interface SharedTransformCodegenOptions {
* This allows the function to directly access setup() local bindings. * This allows the function to directly access setup() local bindings.
*/ */
inline?: boolean inline?: boolean
/**
* Identifier for props in setup() inline mode.
*/
inlinePropsIdentifier?: string
} }
export interface TransformOptions extends SharedTransformCodegenOptions { export interface TransformOptions extends SharedTransformCodegenOptions {

View File

@ -125,7 +125,6 @@ export function createTransformContext(
ssrCssVars = ``, ssrCssVars = ``,
bindingMetadata = EMPTY_OBJ, bindingMetadata = EMPTY_OBJ,
inline = false, inline = false,
inlinePropsIdentifier = `$props`,
onError = defaultOnError onError = defaultOnError
}: TransformOptions }: TransformOptions
): TransformContext { ): TransformContext {
@ -145,7 +144,6 @@ export function createTransformContext(
ssrCssVars, ssrCssVars,
bindingMetadata, bindingMetadata,
inline, inline,
inlinePropsIdentifier,
onError, onError,
// state // state

View File

@ -98,14 +98,12 @@ export function processExpression(
return node return node
} }
const { inline, inlinePropsIdentifier, bindingMetadata } = context const { inline, bindingMetadata } = context
const prefix = (raw: string) => { const prefix = (raw: string) => {
const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw] const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw]
if (inline) { if (inline) {
// setup inline mode // setup inline mode
if (type === 'props') { if (type === 'setup') {
return `${inlinePropsIdentifier}.${raw}`
} else if (type === 'setup') {
return `${context.helperString(UNREF)}(${raw})` return `${context.helperString(UNREF)}(${raw})`
} else if (type === 'component-import') { } else if (type === 'component-import') {
return raw return raw

View File

@ -405,20 +405,16 @@ export function compileScript(
) )
} }
// parse the signature to extract the identifiers users are assigning to
// the arguments. props identifier is always needed for inline mode
// template compilation
const params = ((signatureAST as ExpressionStatement)
.expression as ArrowFunctionExpression).params
if (params[0] && params[0].type === 'Identifier') {
propsASTNode = params[0]
propsIdentifier = propsASTNode.name
}
if (isTS) { if (isTS) {
// <script setup="xxx" lang="ts"> // <script setup="xxx" lang="ts">
// additional identifiers are needed for TS in order to match declared // parse the signature to extract the identifiers users are assigning to
// types // the arguments. They are needed for matching type delcarations.
const params = ((signatureAST as ExpressionStatement)
.expression as ArrowFunctionExpression).params
if (params[0] && params[0].type === 'Identifier') {
propsASTNode = params[0]
propsIdentifier = propsASTNode.name
}
if (params[1] && params[1].type === 'ObjectPattern') { if (params[1] && params[1].type === 'ObjectPattern') {
setupCtxASTNode = params[1] setupCtxASTNode = params[1]
for (const p of params[1].properties) { for (const p of params[1].properties) {
@ -701,7 +697,7 @@ export function compileScript(
} }
// 7. finalize setup argument signature. // 7. finalize setup argument signature.
let args = options.inlineTemplate ? `$props` : `` let args = ``
if (isTS) { if (isTS) {
if (slotsType === 'Slots') { if (slotsType === 'Slots') {
helperImports.add('Slots') helperImports.add('Slots')
@ -787,7 +783,6 @@ export function compileScript(
source: sfc.template.content, source: sfc.template.content,
compilerOptions: { compilerOptions: {
inline: true, inline: true,
inlinePropsIdentifier: propsIdentifier,
bindingMetadata bindingMetadata
} }
// TODO source map // TODO source map