optimizer.ts — vue Source File
Architecture documentation for optimizer.ts, a typescript file in the vue codebase. 2 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR b7ef6faa_d112_ca70_98b8_d353bda5bfe0["optimizer.ts"] 09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"] b7ef6faa_d112_ca70_98b8_d353bda5bfe0 --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b a80b8e3b_d720_9146_3bf6_594d4ee5dd77["compiler"] b7ef6faa_d112_ca70_98b8_d353bda5bfe0 --> a80b8e3b_d720_9146_3bf6_594d4ee5dd77 4aaa14b9_d580_5a66_5221_1be3a11a7eed["codegen.ts"] 4aaa14b9_d580_5a66_5221_1be3a11a7eed --> b7ef6faa_d112_ca70_98b8_d353bda5bfe0 e5f97d41_92da_796a_60c6_a76258977cea["index.ts"] e5f97d41_92da_796a_60c6_a76258977cea --> b7ef6faa_d112_ca70_98b8_d353bda5bfe0 style b7ef6faa_d112_ca70_98b8_d353bda5bfe0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* In SSR, the vdom tree is generated only once and never patched, so
* we can optimize most element / trees into plain string render functions.
* The SSR optimizer walks the AST tree to detect optimizable elements and trees.
*
* The criteria for SSR optimizability is quite a bit looser than static tree
* detection (which is designed for client re-render). In SSR we bail only for
* components/slots/custom directives.
*/
import { no, makeMap, isBuiltInTag } from 'shared/util'
import { ASTElement, ASTNode, CompilerOptions } from 'types/compiler'
// optimizability constants
export const optimizability = {
FALSE: 0, // whole sub tree un-optimizable
FULL: 1, // whole sub tree optimizable
SELF: 2, // self optimizable but has some un-optimizable children
CHILDREN: 3, // self un-optimizable but have fully optimizable children
PARTIAL: 4 // self un-optimizable with some un-optimizable children
}
let isPlatformReservedTag
export function optimize(root: ASTElement | null, options: CompilerOptions) {
if (!root) return
isPlatformReservedTag = options.isReservedTag || no
walk(root, true)
}
function walk(node: ASTNode, isRoot?: boolean) {
if (isUnOptimizableTree(node)) {
node.ssrOptimizability = optimizability.FALSE
return
}
// root node or nodes with custom directives should always be a VNode
const selfUnoptimizable = isRoot || hasCustomDirective(node)
const check = child => {
if (child.ssrOptimizability !== optimizability.FULL) {
node.ssrOptimizability = selfUnoptimizable
? optimizability.PARTIAL
: optimizability.SELF
}
}
if (selfUnoptimizable) {
node.ssrOptimizability = optimizability.CHILDREN
}
if (node.type === 1) {
for (let i = 0, l = node.children.length; i < l; i++) {
const child = node.children[i]
walk(child)
check(child)
}
if (node.ifConditions) {
for (let i = 1, l = node.ifConditions.length; i < l; i++) {
const block = node.ifConditions[i].block
walk(block, isRoot)
check(block)
}
}
// ... (81 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 ServerRenderer domain, BundleRenderer subdomain.
What functions are defined in optimizer.ts?
optimizer.ts defines 6 function(s): hasCustomDirective, isSelectWithModel, isUnOptimizableTree, optimize, optimizeSiblings, walk.
What does optimizer.ts depend on?
optimizer.ts imports 2 module(s): compiler, util.
What files import optimizer.ts?
optimizer.ts is imported by 2 file(s): codegen.ts, index.ts.
Where is optimizer.ts in the architecture?
optimizer.ts is located at packages/server-renderer/src/optimizing-compiler/optimizer.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