Home / File/ codegen.spec.ts — vue Source File

codegen.spec.ts — vue Source File

Architecture documentation for codegen.spec.ts, a typescript file in the vue codebase. 8 imports, 0 dependents.

File typescript VueCore GlobalAPI 8 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  1ce15a60_e704_f44b_e133_a9ef736678fc["codegen.spec.ts"]
  1a27e6b3_7515_332e_8d02_d958c72a568c["types.ts"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 1a27e6b3_7515_332e_8d02_d958c72a568c
  fd729ff9_ab37_2b0a_f764_780a95167427["BindingTypes"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> fd729ff9_ab37_2b0a_f764_780a95167427
  71c23c60_e463_32f9_8a85_8e36e7f91fd7["index"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 71c23c60_e463_32f9_8a85_8e36e7f91fd7
  68f0d316_a711_a6b4_53ec_77a7d150f31b["optimizer"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 68f0d316_a711_a6b4_53ec_77a7d150f31b
  88a8184f_387e_a0ea_d5f4_ebc464b1c234["codegen"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 88a8184f_387e_a0ea_d5f4_ebc464b1c234
  09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b
  28507de2_df66_4d38_8b45_3af459d16f77["index"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> 28507de2_df66_4d38_8b45_3af459d16f77
  b0b6bd3d_bce8_b3b0_ce33_925aad47348a["options"]
  1ce15a60_e704_f44b_e133_a9ef736678fc --> b0b6bd3d_bce8_b3b0_ce33_925aad47348a
  style 1ce15a60_e704_f44b_e133_a9ef736678fc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { parse } from 'compiler/parser/index'
import { optimize } from 'compiler/optimizer'
import { generate } from 'compiler/codegen'
import { isObject, isFunction, extend } from 'shared/util'
import { isReservedTag } from 'web/util/index'
import { baseOptions } from 'web/compiler/options'
import { BindingTypes } from '../../../../packages/compiler-sfc/src/types'

function assertCodegen(template, generatedCode, ...args) {
  let staticRenderFnCodes: string[] = []
  let generateOptions = baseOptions
  let proc: Function | null = null
  let len = args.length
  while (len--) {
    const arg = args[len]
    if (Array.isArray(arg)) {
      staticRenderFnCodes = arg
    } else if (isObject(arg)) {
      generateOptions = arg
    } else if (isFunction(arg)) {
      proc = arg
    }
  }
  const ast = parse(template, baseOptions)
  optimize(ast, baseOptions)
  proc && proc(ast)
  const res = generate(ast, generateOptions)
  expect(res.render).toBe(generatedCode)
  expect(res.staticRenderFns).toEqual(staticRenderFnCodes)
}

describe('codegen', () => {
  it('generate directive', () => {
    assertCodegen(
      '<p v-custom1:arg1.modifier="value1" v-custom2></p>',
      `with(this){return _c('p',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:(value1),expression:"value1",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}]})}`
    )
  })

  it('generate filters', () => {
    assertCodegen(
      '<div :id="a | b | c">{{ d | e | f }}</div>',
      `with(this){return _c('div',{attrs:{"id":_f("c")(_f("b")(a))}},[_v(_s(_f("f")(_f("e")(d))))])}`
    )
  })

  it('generate filters with no arguments', () => {
    assertCodegen(
      '<div>{{ d | e() }}</div>',
      `with(this){return _c('div',[_v(_s(_f("e")(d)))])}`
    )
  })

  it('generate v-for directive', () => {
    assertCodegen(
      '<div><li v-for="item in items" :key="item.uid"></li></div>',
      `with(this){return _c('div',_l((items),function(item){return _c('li',{key:item.uid})}),0)}`
    )
    // iterator syntax
    assertCodegen(
// ... (684 more lines)

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does codegen.spec.ts do?
codegen.spec.ts is a source file in the vue codebase, written in typescript. It belongs to the VueCore domain, GlobalAPI subdomain.
What functions are defined in codegen.spec.ts?
codegen.spec.ts defines 1 function(s): assertCodegen.
What does codegen.spec.ts depend on?
codegen.spec.ts imports 8 module(s): BindingTypes, codegen, index, index, optimizer, options, types.ts, util.
Where is codegen.spec.ts in the architecture?
codegen.spec.ts is located at test/unit/modules/compiler/codegen.spec.ts (domain: VueCore, subdomain: GlobalAPI, directory: test/unit/modules/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free