prefixIdentifiers.ts — vue Source File
Architecture documentation for prefixIdentifiers.ts, a typescript file in the vue codebase. 8 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 472584c7_15d2_7ac4_2300_5c0fac3bab21["prefixIdentifiers.ts"] fcee39ec_18fe_7a99_fb49_d33db4d055a4["babelUtils.ts"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> fcee39ec_18fe_7a99_fb49_d33db4d055a4 95cbb28a_63b1_cc46_f71a_5a60cb57f576["isStaticProperty"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 95cbb28a_63b1_cc46_f71a_5a60cb57f576 484ec320_49bc_b969_d86d_edc246af3234["walkIdentifiers"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 484ec320_49bc_b969_d86d_edc246af3234 1a27e6b3_7515_332e_8d02_d958c72a568c["types.ts"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 1a27e6b3_7515_332e_8d02_d958c72a568c 5d984136_f02d_b459_9f20_2306143d1d20["BindingMetadata"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 5d984136_f02d_b459_9f20_2306143d1d20 39525954_b18d_7146_ce6a_0e8b51196765["magic-string"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 39525954_b18d_7146_ce6a_0e8b51196765 349d6930_cc0f_5a60_fcc7_13e5b0d624c0["parser"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 349d6930_cc0f_5a60_fcc7_13e5b0d624c0 09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"] 472584c7_15d2_7ac4_2300_5c0fac3bab21 --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b b824bd73_da14_5076_9939_3d47171265ea["compileTemplate.ts"] b824bd73_da14_5076_9939_3d47171265ea --> 472584c7_15d2_7ac4_2300_5c0fac3bab21 445bc304_0400_2ae2_a33b_eaa1d5e1788a["cssVars.ts"] 445bc304_0400_2ae2_a33b_eaa1d5e1788a --> 472584c7_15d2_7ac4_2300_5c0fac3bab21 274291c3_092c_9022_0cef_c4d2708cc615["prefixIdentifiers.spec.ts"] 274291c3_092c_9022_0cef_c4d2708cc615 --> 472584c7_15d2_7ac4_2300_5c0fac3bab21 style 472584c7_15d2_7ac4_2300_5c0fac3bab21 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import MagicString from 'magic-string'
import { parseExpression, ParserOptions, ParserPlugin } from '@babel/parser'
import { makeMap } from 'shared/util'
import { isStaticProperty, walkIdentifiers } from './babelUtils'
import { BindingMetadata } from './types'
const doNotPrefix = makeMap(
'Infinity,undefined,NaN,isFinite,isNaN,' +
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
'require,' + // for webpack
'arguments,' + // parsed as identifier but is a special keyword...
'_c' // cached to save property access
)
/**
* The input is expected to be a valid expression.
*/
export function prefixIdentifiers(
source: string,
isFunctional = false,
isTS = false,
babelOptions: ParserOptions = {},
bindings?: BindingMetadata
) {
const s = new MagicString(source)
const plugins: ParserPlugin[] = [
...(isTS ? (['typescript'] as const) : []),
...(babelOptions?.plugins || [])
]
const ast = parseExpression(source, {
...babelOptions,
plugins
})
const isScriptSetup = bindings && bindings.__isScriptSetup !== false
walkIdentifiers(
ast,
(ident, parent) => {
const { name } = ident
if (doNotPrefix(name)) {
return
}
let prefix = `_vm.`
if (isScriptSetup) {
const type = bindings[name]
if (type && type.startsWith('setup')) {
prefix = `_setup.`
}
}
if (isStaticProperty(parent) && parent.shorthand) {
// property shorthand like { foo }, we need to add the key since
// we rewrite the value
// { foo } -> { foo: _vm.foo }
s.appendLeft(ident.end!, `: ${prefix}${name}`)
} else {
s.prependRight(ident.start!, prefix)
}
},
node => {
if (node.type === 'WithStatement') {
s.remove(node.start!, node.body.start! + 1)
s.remove(node.end! - 1, node.end!)
if (!isFunctional) {
s.prependRight(
node.start!,
`var _vm=this,_c=_vm._self._c${
isScriptSetup ? `,_setup=_vm._self._setupProxy;` : `;`
}`
)
}
}
}
)
return s.toString()
}
Domain
Subdomains
Functions
Dependencies
- BindingMetadata
- babelUtils.ts
- isStaticProperty
- magic-string
- parser
- types.ts
- util
- walkIdentifiers
Imported By
Source
Frequently Asked Questions
What does prefixIdentifiers.ts do?
prefixIdentifiers.ts is a source file in the vue codebase, written in typescript. It belongs to the SfcCompiler domain, ScriptCompiler subdomain.
What functions are defined in prefixIdentifiers.ts?
prefixIdentifiers.ts defines 1 function(s): prefixIdentifiers.
What does prefixIdentifiers.ts depend on?
prefixIdentifiers.ts imports 8 module(s): BindingMetadata, babelUtils.ts, isStaticProperty, magic-string, parser, types.ts, util, walkIdentifiers.
What files import prefixIdentifiers.ts?
prefixIdentifiers.ts is imported by 3 file(s): compileTemplate.ts, cssVars.ts, prefixIdentifiers.spec.ts.
Where is prefixIdentifiers.ts in the architecture?
prefixIdentifiers.ts is located at packages/compiler-sfc/src/prefixIdentifiers.ts (domain: SfcCompiler, subdomain: ScriptCompiler, directory: packages/compiler-sfc/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free