MCPcopy
hub / github.com/vuejs/core / buildDirectiveArgs

Function buildDirectiveArgs

packages/compiler-core/src/transforms/transformElement.ts:875–924  ·  view source on GitHub ↗
(
  dir: DirectiveNode,
  context: TransformContext,
)

Source from the content-addressed store, hash-verified

873}
874
875export function buildDirectiveArgs(
876 dir: DirectiveNode,
877 context: TransformContext,
878): ArrayExpression {
879 const dirArgs: ArrayExpression['elements'] = []
880 const runtime = directiveImportMap.get(dir)
881 if (runtime) {
882 // built-in directive with runtime
883 dirArgs.push(context.helperString(runtime))
884 } else {
885 // user directive.
886 // see if we have directives exposed via <script setup>
887 const fromSetup =
888 !__BROWSER__ && resolveSetupReference('v-' + dir.name, context)
889 if (fromSetup) {
890 dirArgs.push(fromSetup)
891 } else {
892 // inject statement for resolving directive
893 context.helper(RESOLVE_DIRECTIVE)
894 context.directives.add(dir.name)
895 dirArgs.push(toValidAssetId(dir.name, `directive`))
896 }
897 }
898 const { loc } = dir
899 if (dir.exp) dirArgs.push(dir.exp)
900 if (dir.arg) {
901 if (!dir.exp) {
902 dirArgs.push(`void 0`)
903 }
904 dirArgs.push(dir.arg)
905 }
906 if (Object.keys(dir.modifiers).length) {
907 if (!dir.arg) {
908 if (!dir.exp) {
909 dirArgs.push(`void 0`)
910 }
911 dirArgs.push(`void 0`)
912 }
913 const trueExpression = createSimpleExpression(`true`, false, loc)
914 dirArgs.push(
915 createObjectExpression(
916 dir.modifiers.map(modifier =>
917 createObjectProperty(modifier, trueExpression),
918 ),
919 loc,
920 ),
921 )
922 }
923 return createArrayExpression(dirArgs, dir.loc)
924}
925
926function stringifyDynamicPropNames(props: string[]): string {
927 let propsNamesString = `[`

Callers 2

buildSSRPropsFunction · 0.85
transformElementFunction · 0.85

Calls 11

toValidAssetIdFunction · 0.90
createSimpleExpressionFunction · 0.90
createObjectExpressionFunction · 0.90
createObjectPropertyFunction · 0.90
createArrayExpressionFunction · 0.90
resolveSetupReferenceFunction · 0.85
helperStringMethod · 0.80
mapMethod · 0.80
pushMethod · 0.65
helperMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected