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
  537da575_d51d_525b_d1bc_6c6bf82c78a1["analyzeBindingsFromOptions()"]
  c9346cac_54e3_f6ca_68a7_03c6e82c9609["compileScript.ts"]
  537da575_d51d_525b_d1bc_6c6bf82c78a1 -->|defined in| c9346cac_54e3_f6ca_68a7_03c6e82c9609
  14d6c8d1_8b2c_a3db_d77c_d93821233e45["analyzeScriptBindings()"]
  14d6c8d1_8b2c_a3db_d77c_d93821233e45 -->|calls| 537da575_d51d_525b_d1bc_6c6bf82c78a1
  651c296a_4fca_026a_b02e_46bcddaa4010["getObjectOrArrayExpressionKeys()"]
  537da575_d51d_525b_d1bc_6c6bf82c78a1 -->|calls| 651c296a_4fca_026a_b02e_46bcddaa4010
  6bf6c4d9_0a3d_a29e_0f34_7bceb709898e["getObjectExpressionKeys()"]
  537da575_d51d_525b_d1bc_6c6bf82c78a1 -->|calls| 6bf6c4d9_0a3d_a29e_0f34_7bceb709898e
  style 537da575_d51d_525b_d1bc_6c6bf82c78a1 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, defined in packages/compiler-sfc/src/compileScript.ts.
Where is analyzeBindingsFromOptions() defined?
analyzeBindingsFromOptions() is defined in packages/compiler-sfc/src/compileScript.ts at line 1675.
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