Skip to content

Commit 69d5c68

Browse files
committed
wip: update directive scope variable mapping
1 parent bdc66c7 commit 69d5c68

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,7 @@ export function resolveComponentType(
257257
// this is skipped in browser build since browser builds do not perform
258258
// binding analysis.
259259
if (!__BROWSER__) {
260-
const fromSetup = resolveSetupReference(
261-
tag,
262-
capitalize(camelize(tag)),
263-
context
264-
)
260+
const fromSetup = resolveSetupReference(tag, context)
265261
if (fromSetup) {
266262
return fromSetup
267263
}
@@ -273,22 +269,23 @@ export function resolveComponentType(
273269
return toValidAssetId(tag, `component`)
274270
}
275271

276-
function resolveSetupReference(
277-
name: string,
278-
interopName: string,
279-
context: TransformContext
280-
) {
272+
function resolveSetupReference(name: string, context: TransformContext) {
281273
const bindings = context.bindingMetadata
282274
if (!bindings) {
283275
return
284276
}
285277

278+
const camelName = camelize(name)
279+
const PascalName = capitalize(camelName)
286280
const checkType = (type: BindingTypes) => {
287281
if (bindings[name] === type) {
288282
return name
289283
}
290-
if (bindings[interopName] === type) {
291-
return interopName
284+
if (bindings[camelName] === type) {
285+
return camelName
286+
}
287+
if (bindings[PascalName] === type) {
288+
return PascalName
292289
}
293290
}
294291

@@ -615,15 +612,7 @@ function buildDirectiveArgs(
615612
} else {
616613
// user directive.
617614
// see if we have directives exposed via <script setup>
618-
const fromSetup =
619-
!__BROWSER__ &&
620-
resolveSetupReference(
621-
dir.name,
622-
// v-my-dir -> vMyDir
623-
'v' + capitalize(camelize(dir.name)),
624-
context
625-
)
626-
615+
const fromSetup = !__BROWSER__ && resolveSetupReference(dir.name, context)
627616
if (fromSetup) {
628617
dirArgs.push(fromSetup)
629618
} else {

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ exports[`SFC compile <script setup> inlineTemplate mode referencing scope compon
224224
225225
import ChildComp from './Child.vue'
226226
import SomeOtherComp from './Other.vue'
227-
import vMyDir from './my-dir'
227+
import myDir from './my-dir'
228228
229229
export default {
230230
expose: [],
@@ -234,7 +234,7 @@ export default {
234234
return (_ctx, _cache) => {
235235
return (_openBlock(), _createBlock(_Fragment, null, [
236236
_withDirectives(_createVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
237-
[_unref(vMyDir)]
237+
[_unref(myDir)]
238238
]),
239239
_createVNode(ChildComp),
240240
_createVNode(SomeOtherComp)

packages/compiler-sfc/__tests__/compileScript.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const myEmit = defineEmit(['foo', 'bar'])
192192
<script setup>
193193
import ChildComp from './Child.vue'
194194
import SomeOtherComp from './Other.vue'
195-
import vMyDir from './my-dir'
195+
import myDir from './my-dir'
196196
</script>
197197
<template>
198198
<div v-my-dir></div>
@@ -202,7 +202,7 @@ const myEmit = defineEmit(['foo', 'bar'])
202202
`,
203203
{ inlineTemplate: true }
204204
)
205-
expect(content).toMatch('[_unref(vMyDir)]')
205+
expect(content).toMatch('[_unref(myDir)]')
206206
expect(content).toMatch('_createVNode(ChildComp)')
207207
// kebab-case component support
208208
expect(content).toMatch('_createVNode(SomeOtherComp)')

0 commit comments

Comments
 (0)