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 c246f9b9_73ff_c006_0f1d_57169c68facd["optimizer.ts"] 156bf2e1_8a13_f22d_5437_54f14bcef8fa["util"] c246f9b9_73ff_c006_0f1d_57169c68facd --> 156bf2e1_8a13_f22d_5437_54f14bcef8fa 47ae9f26_59d1_fab2_349f_966f5d15495a["compiler"] c246f9b9_73ff_c006_0f1d_57169c68facd --> 47ae9f26_59d1_fab2_349f_966f5d15495a d70222cb_3265_c3fc_c0cf_09247995ea9a["codegen.ts"] d70222cb_3265_c3fc_c0cf_09247995ea9a --> c246f9b9_73ff_c006_0f1d_57169c68facd b07dc083_d74f_670a_70c5_76b4dd72b30c["index.ts"] b07dc083_d74f_670a_70c5_76b4dd72b30c --> c246f9b9_73ff_c006_0f1d_57169c68facd style c246f9b9_73ff_c006_0f1d_57169c68facd 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, OptimizingCompiler 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: 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