Home / File/ optimizer.ts — vue Source File

optimizer.ts — vue Source File

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

File typescript VueCore GlobalAPI 2 imports 1 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  c66d4aaa_9814_c96c_1d3f_ef17ed6ab384["optimizer.ts"]
  09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"]
  c66d4aaa_9814_c96c_1d3f_ef17ed6ab384 --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b
  a80b8e3b_d720_9146_3bf6_594d4ee5dd77["compiler"]
  c66d4aaa_9814_c96c_1d3f_ef17ed6ab384 --> a80b8e3b_d720_9146_3bf6_594d4ee5dd77
  b5f71c2e_6baa_62e4_4167_0496c4d6e540["index.ts"]
  b5f71c2e_6baa_62e4_4167_0496c4d6e540 --> c66d4aaa_9814_c96c_1d3f_ef17ed6ab384
  style c66d4aaa_9814_c96c_1d3f_ef17ed6ab384 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { makeMap, isBuiltInTag, cached, no } from 'shared/util'
import { ASTElement, CompilerOptions, ASTNode } from 'types/compiler'

let isStaticKey
let isPlatformReservedTag

const genStaticKeysCached = cached(genStaticKeys)

/**
 * Goal of the optimizer: walk the generated template AST tree
 * and detect sub-trees that are purely static, i.e. parts of
 * the DOM that never needs to change.
 *
 * Once we detect these sub-trees, we can:
 *
 * 1. Hoist them into constants, so that we no longer need to
 *    create fresh nodes for them on each re-render;
 * 2. Completely skip them in the patching process.
 */
export function optimize(
  root: ASTElement | null | undefined,
  options: CompilerOptions
) {
  if (!root) return
  isStaticKey = genStaticKeysCached(options.staticKeys || '')
  isPlatformReservedTag = options.isReservedTag || no
  // first pass: mark all non-static nodes.
  markStatic(root)
  // second pass: mark static roots.
  markStaticRoots(root, false)
}

function genStaticKeys(keys: string): Function {
  return makeMap(
    'type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap' +
      (keys ? ',' + keys : '')
  )
}

function markStatic(node: ASTNode) {
  node.static = isStatic(node)
  if (node.type === 1) {
    // do not make component slot content static. this avoids
    // 1. components not able to mutate slot nodes
    // 2. static slot content fails for hot-reloading
    if (
      !isPlatformReservedTag(node.tag) &&
      node.tag !== 'slot' &&
      node.attrsMap['inline-template'] == null
    ) {
      return
    }
    for (let i = 0, l = node.children.length; i < l; i++) {
      const child = node.children[i]
      markStatic(child)
      if (!child.static) {
        node.static = false
      }
    }
    if (node.ifConditions) {
// ... (76 more lines)

Domain

Subdomains

Dependencies

  • compiler
  • util

Imported By

Frequently Asked Questions

What does optimizer.ts do?
optimizer.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 optimizer.ts?
optimizer.ts defines 6 function(s): genStaticKeys, isDirectChildOfTemplateFor, isStatic, markStatic, markStaticRoots, optimize.
What does optimizer.ts depend on?
optimizer.ts imports 2 module(s): compiler, util.
What files import optimizer.ts?
optimizer.ts is imported by 1 file(s): index.ts.
Where is optimizer.ts in the architecture?
optimizer.ts is located at src/compiler/optimizer.ts (domain: VueCore, subdomain: GlobalAPI, directory: src/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free