Home / Function/ analyzeBindingsFromOptions() — vue Function Reference

analyzeBindingsFromOptions() — vue Function Reference

Architecture documentation for the analyzeBindingsFromOptions() function in compileScript.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  9548dd10_d35f_a913_7443_6fb7433b922a["analyzeBindingsFromOptions()"]
  6ffb0652_a408_04f3_8b33_d6a4b3a523f3["analyzeScriptBindings()"]
  6ffb0652_a408_04f3_8b33_d6a4b3a523f3 -->|calls| 9548dd10_d35f_a913_7443_6fb7433b922a
  8dcaa987_ab63_9adc_07fb_9895ce59197d["getObjectOrArrayExpressionKeys()"]
  9548dd10_d35f_a913_7443_6fb7433b922a -->|calls| 8dcaa987_ab63_9adc_07fb_9895ce59197d
  aeeaaa47_7ff7_b2d7_ea67_858caa97d707["getObjectExpressionKeys()"]
  9548dd10_d35f_a913_7443_6fb7433b922a -->|calls| aeeaaa47_7ff7_b2d7_ea67_858caa97d707
  style 9548dd10_d35f_a913_7443_6fb7433b922a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/compileScript.ts lines 1675–1749

function analyzeBindingsFromOptions(node: ObjectExpression): BindingMetadata {
  const bindings: BindingMetadata = {}
  // #3270, #3275
  // mark non-script-setup so we don't resolve components/directives from these
  Object.defineProperty(bindings, '__isScriptSetup', {
    enumerable: false,
    value: false
  })
  for (const property of node.properties) {
    if (
      property.type === 'ObjectProperty' &&
      !property.computed &&
      property.key.type === 'Identifier'
    ) {
      // props
      if (property.key.name === 'props') {
        // props: ['foo']
        // props: { foo: ... }
        for (const key of getObjectOrArrayExpressionKeys(property.value)) {
          bindings[key] = BindingTypes.PROPS
        }
      }

      // inject
      else if (property.key.name === 'inject') {
        // inject: ['foo']
        // inject: { foo: {} }
        for (const key of getObjectOrArrayExpressionKeys(property.value)) {
          bindings[key] = BindingTypes.OPTIONS
        }
      }

      // computed & methods
      else if (
        property.value.type === 'ObjectExpression' &&
        (property.key.name === 'computed' || property.key.name === 'methods')
      ) {
        // methods: { foo() {} }
        // computed: { foo() {} }
        for (const key of getObjectExpressionKeys(property.value)) {
          bindings[key] = BindingTypes.OPTIONS
        }
      }
    }

    // setup & data
    else if (
      property.type === 'ObjectMethod' &&
      property.key.type === 'Identifier' &&
      (property.key.name === 'setup' || property.key.name === 'data')
    ) {
      for (const bodyItem of property.body.body) {
        // setup() {
        //   return {
        //     foo: null
        //   }
        // }
        if (
          bodyItem.type === 'ReturnStatement' &&
          bodyItem.argument &&
          bodyItem.argument.type === 'ObjectExpression'
        ) {
          for (const key of getObjectExpressionKeys(bodyItem.argument)) {
            bindings[key] =
              property.key.name === 'setup'
                ? BindingTypes.SETUP_MAYBE_REF
                : BindingTypes.DATA
          }
        }
      }
    }
  }

  return bindings
}

Domain

Subdomains

Frequently Asked Questions

What does analyzeBindingsFromOptions() do?
analyzeBindingsFromOptions() is a function in the vue codebase.
What does analyzeBindingsFromOptions() call?
analyzeBindingsFromOptions() calls 2 function(s): getObjectExpressionKeys, getObjectOrArrayExpressionKeys.
What calls analyzeBindingsFromOptions()?
analyzeBindingsFromOptions() is called by 1 function(s): analyzeScriptBindings.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free