Skip to content

Commit

Permalink
wip: remove unnecessary inlinePropsIdentifier option
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 11, 2020
1 parent 4e8ef55 commit 2a4fc32
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
5 changes: 1 addition & 4 deletions packages/compiler-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ export interface CodegenResult {
}

export interface CodegenContext
extends Omit<
Required<CodegenOptions>,
'bindingMetadata' | 'inline' | 'inlinePropsIdentifier'
> {
extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
source: string
code: string
line: number
Expand Down
4 changes: 0 additions & 4 deletions packages/compiler-core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ interface SharedTransformCodegenOptions {
* This allows the function to directly access setup() local bindings.
*/
inline?: boolean
/**
* Identifier for props in setup() inline mode.
*/
inlinePropsIdentifier?: string
}

export interface TransformOptions extends SharedTransformCodegenOptions {
Expand Down
2 changes: 0 additions & 2 deletions packages/compiler-core/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function createTransformContext(
ssrCssVars = ``,
bindingMetadata = EMPTY_OBJ,
inline = false,
inlinePropsIdentifier = `$props`,
onError = defaultOnError
}: TransformOptions
): TransformContext {
Expand All @@ -145,7 +144,6 @@ export function createTransformContext(
ssrCssVars,
bindingMetadata,
inline,
inlinePropsIdentifier,
onError,

// state
Expand Down
6 changes: 2 additions & 4 deletions packages/compiler-core/src/transforms/transformExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@ export function processExpression(
return node
}

const { inline, inlinePropsIdentifier, bindingMetadata } = context
const { inline, bindingMetadata } = context
const prefix = (raw: string) => {
const type = hasOwn(bindingMetadata, raw) && bindingMetadata[raw]
if (inline) {
// setup inline mode
if (type === 'props') {
return `${inlinePropsIdentifier}.${raw}`
} else if (type === 'setup') {
if (type === 'setup') {
return `${context.helperString(UNREF)}(${raw})`
} else if (type === 'component-import') {
return raw
Expand Down
23 changes: 9 additions & 14 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// <script setup="xxx" lang="ts">
// additional identifiers are needed for TS in order to match declared
// types
// parse the signature to extract the identifiers users are assigning to
// 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') {
setupCtxASTNode = params[1]
for (const p of params[1].properties) {
Expand Down Expand Up @@ -701,7 +697,7 @@ export function compileScript(
}

// 7. finalize setup argument signature.
let args = options.inlineTemplate ? `$props` : ``
let args = ``
if (isTS) {
if (slotsType === 'Slots') {
helperImports.add('Slots')
Expand Down Expand Up @@ -787,7 +783,6 @@ export function compileScript(
source: sfc.template.content,
compilerOptions: {
inline: true,
inlinePropsIdentifier: propsIdentifier,
bindingMetadata
}
// TODO source map
Expand Down

0 comments on commit 2a4fc32

Please sign in to comment.