Skip to content

Commit 0eeaccd

Browse files
authored
Merge pull request #121 from vuejs/vue-shared-esm
fix: esm build support by inlining @vue/shared utility functions
2 parents 7a89405 + d7bde14 commit 0eeaccd

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/stubs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { transformVNodeArgs, h, createVNode } from 'vue'
2-
import { hyphenate } from '@vue/shared'
2+
import { hyphenate } from './utils/vueShared'
33
import { MOUNT_COMPONENT_REF, MOUNT_PARENT_NAME } from './constants'
44
import { config } from './config'
55
import { matchName } from './utils/matchName'

src/utils/matchName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { camelize, capitalize } from '@vue/shared'
1+
import { camelize, capitalize } from './vueShared'
22

33
export function matchName(target, sourceName) {
44
const camelized = camelize(target)

src/utils/vueShared.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => {
2+
const cache: Record<string, string> = Object.create(null)
3+
return ((str: string) => {
4+
const hit = cache[str]
5+
return hit || (cache[str] = fn(str))
6+
}) as any
7+
}
8+
9+
const camelizeRE = /-(\w)/g
10+
export const camelize = cacheStringFunction((str: string): string => {
11+
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
12+
})
13+
14+
export const capitalize = cacheStringFunction((str: string): string => {
15+
return str.charAt(0).toUpperCase() + str.slice(1)
16+
})
17+
18+
const hyphenateRE = /\B([A-Z])/g
19+
export const hyphenate = cacheStringFunction((str: string): string => {
20+
return str.replace(hyphenateRE, '-$1').toLowerCase()
21+
})
22+
23+
export const enum ShapeFlags {
24+
ELEMENT = 1,
25+
FUNCTIONAL_COMPONENT = 1 << 1,
26+
STATEFUL_COMPONENT = 1 << 2,
27+
TEXT_CHILDREN = 1 << 3,
28+
ARRAY_CHILDREN = 1 << 4,
29+
SLOTS_CHILDREN = 1 << 5,
30+
TELEPORT = 1 << 6,
31+
SUSPENSE = 1 << 7,
32+
COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8,
33+
COMPONENT_KEPT_ALIVE = 1 << 9,
34+
COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT
35+
}

src/vue-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentPublicInstance, nextTick, App } from 'vue'
2-
import { ShapeFlags } from '@vue/shared'
2+
import { ShapeFlags } from './utils/vueShared'
33
import { config } from './config'
44

55
import { DOMWrapper } from './dom-wrapper'

0 commit comments

Comments
 (0)