Home / File/ modules.ts — vue Source File

modules.ts — vue Source File

Architecture documentation for modules.ts, a typescript file in the vue codebase. 6 imports, 1 dependents.

File typescript ServerRenderer BundleRenderer 6 imports 1 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  92853cf6_4176_f03f_0670_cca3d63c003e["modules.ts"]
  4aaa14b9_d580_5a66_5221_1be3a11a7eed["codegen.ts"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> 4aaa14b9_d580_5a66_5221_1be3a11a7eed
  89eacf5c_deee_e42e_d519_69cb05e48e63["util.ts"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> 89eacf5c_deee_e42e_d519_69cb05e48e63
  953457f9_439e_4bfb_da0b_a8f1356764a0["isRenderableAttr"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> 953457f9_439e_4bfb_da0b_a8f1356764a0
  25eda96e_d536_1889_d475_255d9ddf047a["attrs"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> 25eda96e_d536_1889_d475_255d9ddf047a
  e07318ce_1584_4c80_9350_b88731fb2da0["index"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> e07318ce_1584_4c80_9350_b88731fb2da0
  a80b8e3b_d720_9146_3bf6_594d4ee5dd77["compiler"]
  92853cf6_4176_f03f_0670_cca3d63c003e --> a80b8e3b_d720_9146_3bf6_594d4ee5dd77
  4aaa14b9_d580_5a66_5221_1be3a11a7eed["codegen.ts"]
  4aaa14b9_d580_5a66_5221_1be3a11a7eed --> 92853cf6_4176_f03f_0670_cca3d63c003e
  style 92853cf6_4176_f03f_0670_cca3d63c003e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import {
  RAW,
  // INTERPOLATION,
  EXPRESSION
} from './codegen'

import { propsToAttrMap, isRenderableAttr } from '../util'

import { isBooleanAttr, isEnumeratedAttr } from 'web/util/attrs'

import type { StringSegment } from './codegen'
import type { CodegenState } from 'compiler/codegen/index'
import { ASTAttr, ASTElement } from 'types/compiler'

const plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/

// let the model AST transform translate v-model into appropriate
// props bindings
export function applyModelTransform(el: ASTElement, state: CodegenState) {
  if (el.directives) {
    for (let i = 0; i < el.directives.length; i++) {
      const dir = el.directives[i]
      if (dir.name === 'model') {
        state.directives.model(el, dir, state.warn)
        // remove value for textarea as its converted to text
        if (el.tag === 'textarea' && el.props) {
          el.props = el.props.filter(p => p.name !== 'value')
        }
        break
      }
    }
  }
}

export function genAttrSegments(attrs: Array<ASTAttr>): Array<StringSegment> {
  return attrs.map(({ name, value }) => genAttrSegment(name, value))
}

export function genDOMPropSegments(
  props: Array<ASTAttr>,
  attrs: Array<ASTAttr> | null | undefined
): Array<StringSegment> {
  const segments: StringSegment[] = []
  props.forEach(({ name, value }) => {
    name = propsToAttrMap[name] || name.toLowerCase()
    if (
      isRenderableAttr(name) &&
      !(attrs && attrs.some(a => a.name === name))
    ) {
      segments.push(genAttrSegment(name, value))
    }
  })
  return segments
}

function genAttrSegment(name: string, value: string): StringSegment {
  if (plainStringRE.test(value)) {
    // force double quote
    value = value.replace(/^'|'$/g, '"')
    // force enumerated attr to "true"
    if (isEnumeratedAttr(name) && value !== `"false"`) {
      value = `"true"`
    }
    return {
      type: RAW,
      value: isBooleanAttr(name)
        ? ` ${name}="${name}"`
        : value === '""'
        ? ` ${name}`
        : ` ${name}="${JSON.parse(value)}"`
    }
  } else {
    return {
      type: EXPRESSION,
      value: `_ssrAttr(${JSON.stringify(name)},${value})`
    }
  }
}

export function genClassSegments(
  staticClass: string | null | undefined,
  classBinding: string | null | undefined
): Array<StringSegment> {
  if (staticClass && !classBinding) {
    return [{ type: RAW, value: ` class="${JSON.parse(staticClass)}"` }]
  } else {
    return [
      {
        type: EXPRESSION,
        value: `_ssrClass(${staticClass || 'null'},${classBinding || 'null'})`
      }
    ]
  }
}

export function genStyleSegments(
  staticStyle: string | null | undefined,
  parsedStaticStyle: string | null | undefined,
  styleBinding: string | null | undefined,
  vShowExpression: string | null | undefined
): Array<StringSegment> {
  if (staticStyle && !styleBinding && !vShowExpression) {
    return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }]
  } else {
    return [
      {
        type: EXPRESSION,
        value: `_ssrStyle(${parsedStaticStyle || 'null'},${
          styleBinding || 'null'
        }, ${
          vShowExpression
            ? `{ display: (${vShowExpression}) ? '' : 'none' }`
            : 'null'
        })`
      }
    ]
  }
}

Subdomains

Dependencies

Frequently Asked Questions

What does modules.ts do?
modules.ts is a source file in the vue codebase, written in typescript. It belongs to the ServerRenderer domain, BundleRenderer subdomain.
What functions are defined in modules.ts?
modules.ts defines 6 function(s): applyModelTransform, genAttrSegment, genAttrSegments, genClassSegments, genDOMPropSegments, genStyleSegments.
What does modules.ts depend on?
modules.ts imports 6 module(s): attrs, codegen.ts, compiler, index, isRenderableAttr, util.ts.
What files import modules.ts?
modules.ts is imported by 1 file(s): codegen.ts.
Where is modules.ts in the architecture?
modules.ts is located at packages/server-renderer/src/optimizing-compiler/modules.ts (domain: ServerRenderer, subdomain: BundleRenderer, directory: packages/server-renderer/src/optimizing-compiler).

Analyze Your Own Codebase

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

Try Supermodel Free