optimizer.ts — vue Source File
Architecture documentation for optimizer.ts, a typescript file in the vue codebase. 2 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 62546a34_f736_9139_cfec_7d596f17642d["optimizer.ts"] 156bf2e1_8a13_f22d_5437_54f14bcef8fa["util"] 62546a34_f736_9139_cfec_7d596f17642d --> 156bf2e1_8a13_f22d_5437_54f14bcef8fa 47ae9f26_59d1_fab2_349f_966f5d15495a["compiler"] 62546a34_f736_9139_cfec_7d596f17642d --> 47ae9f26_59d1_fab2_349f_966f5d15495a 444dc0ac_813b_2552_2920_d8cccb96280b["index.ts"] 444dc0ac_813b_2552_2920_d8cccb96280b --> 62546a34_f736_9139_cfec_7d596f17642d style 62546a34_f736_9139_cfec_7d596f17642d 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
Functions
Dependencies
- compiler
- util
Imported By
Source
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 CompilerSFC domain, ScriptAnalyzer 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: CompilerSFC, subdomain: ScriptAnalyzer, directory: src/compiler).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free