Skip to content

Commit bfb5250

Browse files
committed
feat(runtime-shared): init
1 parent 1ec90db commit bfb5250

File tree

16 files changed

+129
-29
lines changed

16 files changed

+129
-29
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"size": "run-s \"size-*\" && tsx scripts/usage-size.ts",
1212
"size-global": "node scripts/build.js vue vue-vapor runtime-dom runtime-vapor compiler-dom compiler-vapor -f global -p --size",
1313
"size-esm-runtime": "node scripts/build.js vue vue-vapor -f esm-bundler-runtime",
14-
"size-esm": "node scripts/build.js runtime-dom runtime-vapor runtime-core reactivity shared -f esm-bundler",
14+
"size-esm": "node scripts/build.js runtime-shared runtime-dom runtime-vapor runtime-core reactivity shared -f esm-bundler",
1515
"check": "tsc --incremental --noEmit",
1616
"lint": "eslint --cache .",
1717
"format": "prettier --write --cache .",

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ export function render(_ctx) {
175175
`;
176176

177177
exports[`compiler: element transform > component > v-on="obj" 1`] = `
178-
"import { toHandlers as _toHandlers } from 'vue';
179-
import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor';
178+
"import { resolveComponent as _resolveComponent, toHandlers as _toHandlers, createComponent as _createComponent } from 'vue/vapor';
180179
181180
export function render(_ctx) {
182181
const _component_Foo = _resolveComponent("Foo")

packages/compiler-vapor/src/generators/component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function genCreateComponent(
5959
}
6060

6161
export function genRawProps(props: IRProps[], context: CodegenContext) {
62+
const { vaporHelper } = context
6263
const frag = props
6364
.map(props => {
6465
if (isArray(props)) {
@@ -70,7 +71,7 @@ export function genRawProps(props: IRProps[], context: CodegenContext) {
7071
expr = genMulti(SEGMENTS_OBJECT, genProp(props, context))
7172
else {
7273
expr = genExpression(props.value, context)
73-
if (props.handler) expr = genCall(context.helper('toHandlers'), expr)
74+
if (props.handler) expr = genCall(vaporHelper('toHandlers'), expr)
7475
}
7576
return ['() => (', ...expr, ')']
7677
}

packages/runtime-core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"homepage": "https://github.com/vuejs/core-vapor/tree/main/packages/runtime-core#readme",
4848
"dependencies": {
4949
"@vue/shared": "workspace:*",
50-
"@vue/reactivity": "workspace:*"
50+
"@vue/reactivity": "workspace:*",
51+
"@vue/runtime-shared": "workspace:*"
5152
}
5253
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
import { isObject, toHandlerKey } from '@vue/shared'
1+
import { toHandlers as _toHandlers } from '@vue/runtime-shared'
22
import { warn } from '../warning'
33

4-
/**
5-
* For prefixing keys in v-on="obj" with "on"
6-
* @private
7-
*/
8-
export function toHandlers(
9-
obj: Record<string, any>,
10-
preserveCaseIfNecessary?: boolean,
11-
): Record<string, any> {
12-
const ret: Record<string, any> = {}
13-
if (__DEV__ && !isObject(obj)) {
14-
warn(`v-on with no argument expects an object value.`)
15-
return ret
16-
}
17-
for (const key in obj) {
18-
ret[
19-
preserveCaseIfNecessary && /[A-Z]/.test(key)
20-
? `on:${key}`
21-
: toHandlerKey(key)
22-
] = obj[key]
23-
}
24-
return ret
25-
}
4+
export const toHandlers = _toHandlers.bind(undefined, warn)

packages/runtime-shared/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018-present, Yuxi (Evan) You
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

packages/runtime-shared/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @vue/runtime-shared

packages/runtime-shared/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./dist/runtime-shared.cjs.prod.js')
5+
} else {
6+
module.exports = require('./dist/runtime-shared.cjs.js')
7+
}

packages/runtime-shared/package.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "@vue/runtime-shared",
3+
"version": "3.0.0-vapor",
4+
"description": "@vue/runtime-shared",
5+
"main": "index.js",
6+
"module": "dist/runtime-shared.esm-bundler.js",
7+
"types": "dist/runtime-shared.d.ts",
8+
"files": [
9+
"index.js",
10+
"dist"
11+
],
12+
"exports": {
13+
".": {
14+
"types": "./dist/runtime-shared.d.ts",
15+
"node": {
16+
"production": "./dist/runtime-shared.cjs.prod.js",
17+
"development": "./dist/runtime-shared.cjs.js",
18+
"default": "./index.js"
19+
},
20+
"module": "./dist/runtime-shared.esm-bundler.js",
21+
"import": "./dist/runtime-shared.esm-bundler.js",
22+
"require": "./index.js"
23+
},
24+
"./*": "./*"
25+
},
26+
"sideEffects": false,
27+
"buildOptions": {
28+
"formats": [
29+
"esm-bundler",
30+
"cjs"
31+
]
32+
},
33+
"repository": {
34+
"type": "git",
35+
"url": "git+https://github.com/vuejs/core-vapor.git",
36+
"directory": "packages/runtime-shared"
37+
},
38+
"keywords": [
39+
"vue"
40+
],
41+
"author": "Evan You",
42+
"license": "MIT",
43+
"bugs": {
44+
"url": "https://github.com/vuejs/core-vapor/issues"
45+
},
46+
"homepage": "https://github.com/vuejs/core-vapor/tree/main/packages/runtime-shared#readme"
47+
}

packages/runtime-shared/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { toHandlers } from './toHandlers'
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { isObject, toHandlerKey } from '@vue/shared'
2+
3+
/**
4+
* For prefixing keys in v-on="obj" with "on"
5+
* @private
6+
*/
7+
export function toHandlers(
8+
warn: (msg: string) => void,
9+
obj: Record<string, any>,
10+
preserveCaseIfNecessary?: boolean,
11+
): Record<string, any> {
12+
const ret: Record<string, any> = {}
13+
if (__DEV__ && !isObject(obj)) {
14+
warn(`v-on with no argument expects an object value.`)
15+
return ret
16+
}
17+
for (const key in obj) {
18+
ret[
19+
preserveCaseIfNecessary && /[A-Z]/.test(key)
20+
? `on:${key}`
21+
: toHandlerKey(key)
22+
] = obj[key]
23+
}
24+
return ret
25+
}

packages/runtime-vapor/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"homepage": "https://github.com/vuejs/core-vapor/tree/dev/packages/runtime-vapor#readme",
3737
"dependencies": {
3838
"@vue/shared": "workspace:*",
39-
"@vue/reactivity": "workspace:*"
39+
"@vue/reactivity": "workspace:*",
40+
"@vue/runtime-shared": "workspace:*"
4041
}
4142
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { toHandlers as _toHandlers } from '@vue/runtime-shared'
2+
import { warn } from '../warning'
3+
4+
export const toHandlers = _toHandlers.bind(undefined, warn)

packages/runtime-vapor/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export { createFor } from './apiCreateFor'
127127
export { createComponent } from './apiCreateComponent'
128128

129129
export { resolveComponent, resolveDirective } from './helpers/resolveAssets'
130+
export { toHandlers } from './helpers/toHandlers'
130131

131132
// **Internal** DOM-only runtime directive helpers
132133
export {

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export function fuzzyMatchTarget(partialTargets, includeAllMatching) {
2828
/** @type {Array<string>} */
2929
const matched = []
3030
partialTargets.forEach(partialTarget => {
31+
if (!includeAllMatching && targets.includes(partialTarget)) {
32+
matched.push(partialTarget)
33+
return
34+
}
3135
for (const target of targets) {
3236
if (target.match(partialTarget)) {
3337
matched.push(target)

0 commit comments

Comments
 (0)