to-function.ts — vue Source File
Architecture documentation for to-function.ts, a typescript file in the vue codebase. 6 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR cf353af6_04db_f570_4b3b_5a4df92dabc9["to-function.ts"] 8dfd476b_479e_3ce1_9cb2_3ae3930648d1["codeframe.ts"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 8dfd476b_479e_3ce1_9cb2_3ae3930648d1 54df2c7b_ea8a_2236_df99_5519ea06c771["generateCodeFrame"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 54df2c7b_ea8a_2236_df99_5519ea06c771 156bf2e1_8a13_f22d_5437_54f14bcef8fa["util"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 156bf2e1_8a13_f22d_5437_54f14bcef8fa 5e280904_7607_16e2_62e5_1d6d092f34a6["debug"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 5e280904_7607_16e2_62e5_1d6d092f34a6 907f4994_ea28_43b1_7976_0db9f0e97637["component"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 907f4994_ea28_43b1_7976_0db9f0e97637 47ae9f26_59d1_fab2_349f_966f5d15495a["compiler"] cf353af6_04db_f570_4b3b_5a4df92dabc9 --> 47ae9f26_59d1_fab2_349f_966f5d15495a 9fa4763f_e2cf_bb11_a018_df048a4dc205["create-compiler.ts"] 9fa4763f_e2cf_bb11_a018_df048a4dc205 --> cf353af6_04db_f570_4b3b_5a4df92dabc9 style cf353af6_04db_f570_4b3b_5a4df92dabc9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { noop, extend } from 'shared/util'
import { warn as baseWarn, tip } from 'core/util/debug'
import { generateCodeFrame } from './codeframe'
import type { Component } from 'types/component'
import { CompilerOptions } from 'types/compiler'
type CompiledFunctionResult = {
render: Function
staticRenderFns: Array<Function>
}
function createFunction(code, errors) {
try {
return new Function(code)
} catch (err: any) {
errors.push({ err, code })
return noop
}
}
export function createCompileToFunctionFn(compile: Function): Function {
const cache = Object.create(null)
return function compileToFunctions(
template: string,
options?: CompilerOptions,
vm?: Component
): CompiledFunctionResult {
options = extend({}, options)
const warn = options.warn || baseWarn
delete options.warn
/* istanbul ignore if */
if (__DEV__) {
// detect possible CSP restriction
try {
new Function('return 1')
} catch (e: any) {
if (e.toString().match(/unsafe-eval|CSP/)) {
warn(
'It seems you are using the standalone build of Vue.js in an ' +
'environment with Content Security Policy that prohibits unsafe-eval. ' +
'The template compiler cannot work in this environment. Consider ' +
'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
'templates into render functions.'
)
}
}
}
// check cache
const key = options.delimiters
? String(options.delimiters) + template
: template
if (cache[key]) {
return cache[key]
}
// compile
const compiled = compile(template, options)
// check compilation errors/tips
if (__DEV__) {
if (compiled.errors && compiled.errors.length) {
if (options.outputSourceRange) {
compiled.errors.forEach(e => {
warn(
`Error compiling template:\n\n${e.msg}\n\n` +
generateCodeFrame(template, e.start, e.end),
vm
)
})
} else {
warn(
`Error compiling template:\n\n${template}\n\n` +
compiled.errors.map(e => `- ${e}`).join('\n') +
'\n',
vm
)
}
}
if (compiled.tips && compiled.tips.length) {
if (options.outputSourceRange) {
compiled.tips.forEach(e => tip(e.msg, vm))
} else {
compiled.tips.forEach(msg => tip(msg, vm))
}
}
}
// turn code into functions
const res: any = {}
const fnGenErrors: any[] = []
res.render = createFunction(compiled.render, fnGenErrors)
res.staticRenderFns = compiled.staticRenderFns.map(code => {
return createFunction(code, fnGenErrors)
})
// check function generation errors.
// this should only happen if there is a bug in the compiler itself.
// mostly for codegen development use
/* istanbul ignore if */
if (__DEV__) {
if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
warn(
`Failed to generate render function:\n\n` +
fnGenErrors
.map(
({ err, code }) => `${(err as any).toString()} in\n\n${code}\n`
)
.join('\n'),
vm
)
}
}
return (cache[key] = res)
}
}
Domain
Subdomains
Types
Dependencies
- codeframe.ts
- compiler
- component
- debug
- generateCodeFrame
- util
Imported By
Source
Frequently Asked Questions
What does to-function.ts do?
to-function.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, StyleProcessor subdomain.
What functions are defined in to-function.ts?
to-function.ts defines 2 function(s): createCompileToFunctionFn, createFunction.
What does to-function.ts depend on?
to-function.ts imports 6 module(s): codeframe.ts, compiler, component, debug, generateCodeFrame, util.
What files import to-function.ts?
to-function.ts is imported by 1 file(s): create-compiler.ts.
Where is to-function.ts in the architecture?
to-function.ts is located at src/compiler/to-function.ts (domain: CompilerSFC, subdomain: StyleProcessor, directory: src/compiler).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free