Home / File/ modules.ts — vue Source File

modules.ts — vue Source File

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

File typescript ServerRenderer OptimizingCompiler 7 imports 1 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e["modules.ts"]
  d70222cb_3265_c3fc_c0cf_09247995ea9a["codegen.ts"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> d70222cb_3265_c3fc_c0cf_09247995ea9a
  a0033b88_b768_84c8_da01_e6315f54737c["util.ts"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> a0033b88_b768_84c8_da01_e6315f54737c
  abecdb7e_6551_469d_217a_85f9116b2ac7["isRenderableAttr"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> abecdb7e_6551_469d_217a_85f9116b2ac7
  b7caa073_65fb_c118_30f5_48c5f1ec8907["StringSegment"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> b7caa073_65fb_c118_30f5_48c5f1ec8907
  6d00c927_5e4e_8ab1_e4eb_3210e91f735b["attrs"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> 6d00c927_5e4e_8ab1_e4eb_3210e91f735b
  b36266ce_99dc_d616_0b1f_4d6a196dc37f["index"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> b36266ce_99dc_d616_0b1f_4d6a196dc37f
  47ae9f26_59d1_fab2_349f_966f5d15495a["compiler"]
  90d3f44d_ff5a_6ebd_69e4_9cea3949738e --> 47ae9f26_59d1_fab2_349f_966f5d15495a
  d70222cb_3265_c3fc_c0cf_09247995ea9a["codegen.ts"]
  d70222cb_3265_c3fc_c0cf_09247995ea9a --> 90d3f44d_ff5a_6ebd_69e4_9cea3949738e
  style 90d3f44d_ff5a_6ebd_69e4_9cea3949738e 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, OptimizingCompiler 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 7 module(s): StringSegment, 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: OptimizingCompiler, 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