feat(runtime-shared): init

This commit is contained in:
三咲智子 Kevin Deng 2024-05-01 20:01:57 +09:00
parent 1ec90db776
commit bfb52502f8
No known key found for this signature in database
16 changed files with 129 additions and 29 deletions

View File

@ -11,7 +11,7 @@
"size": "run-s \"size-*\" && tsx scripts/usage-size.ts",
"size-global": "node scripts/build.js vue vue-vapor runtime-dom runtime-vapor compiler-dom compiler-vapor -f global -p --size",
"size-esm-runtime": "node scripts/build.js vue vue-vapor -f esm-bundler-runtime",
"size-esm": "node scripts/build.js runtime-dom runtime-vapor runtime-core reactivity shared -f esm-bundler",
"size-esm": "node scripts/build.js runtime-shared runtime-dom runtime-vapor runtime-core reactivity shared -f esm-bundler",
"check": "tsc --incremental --noEmit",
"lint": "eslint --cache .",
"format": "prettier --write --cache .",

View File

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

View File

@ -59,6 +59,7 @@ export function genCreateComponent(
}
export function genRawProps(props: IRProps[], context: CodegenContext) {
const { vaporHelper } = context
const frag = props
.map(props => {
if (isArray(props)) {
@ -70,7 +71,7 @@ export function genRawProps(props: IRProps[], context: CodegenContext) {
expr = genMulti(SEGMENTS_OBJECT, genProp(props, context))
else {
expr = genExpression(props.value, context)
if (props.handler) expr = genCall(context.helper('toHandlers'), expr)
if (props.handler) expr = genCall(vaporHelper('toHandlers'), expr)
}
return ['() => (', ...expr, ')']
}

View File

@ -47,6 +47,7 @@
"homepage": "https://github.com/vuejs/core-vapor/tree/main/packages/runtime-core#readme",
"dependencies": {
"@vue/shared": "workspace:*",
"@vue/reactivity": "workspace:*"
"@vue/reactivity": "workspace:*",
"@vue/runtime-shared": "workspace:*"
}
}

View File

@ -1,25 +1,4 @@
import { isObject, toHandlerKey } from '@vue/shared'
import { toHandlers as _toHandlers } from '@vue/runtime-shared'
import { warn } from '../warning'
/**
* For prefixing keys in v-on="obj" with "on"
* @private
*/
export function toHandlers(
obj: Record<string, any>,
preserveCaseIfNecessary?: boolean,
): Record<string, any> {
const ret: Record<string, any> = {}
if (__DEV__ && !isObject(obj)) {
warn(`v-on with no argument expects an object value.`)
return ret
}
for (const key in obj) {
ret[
preserveCaseIfNecessary && /[A-Z]/.test(key)
? `on:${key}`
: toHandlerKey(key)
] = obj[key]
}
return ret
}
export const toHandlers = _toHandlers.bind(undefined, warn)

View File

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

View File

@ -0,0 +1 @@
# @vue/runtime-shared

View File

@ -0,0 +1,7 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/runtime-shared.cjs.prod.js')
} else {
module.exports = require('./dist/runtime-shared.cjs.js')
}

View File

@ -0,0 +1,47 @@
{
"name": "@vue/runtime-shared",
"version": "3.0.0-vapor",
"description": "@vue/runtime-shared",
"main": "index.js",
"module": "dist/runtime-shared.esm-bundler.js",
"types": "dist/runtime-shared.d.ts",
"files": [
"index.js",
"dist"
],
"exports": {
".": {
"types": "./dist/runtime-shared.d.ts",
"node": {
"production": "./dist/runtime-shared.cjs.prod.js",
"development": "./dist/runtime-shared.cjs.js",
"default": "./index.js"
},
"module": "./dist/runtime-shared.esm-bundler.js",
"import": "./dist/runtime-shared.esm-bundler.js",
"require": "./index.js"
},
"./*": "./*"
},
"sideEffects": false,
"buildOptions": {
"formats": [
"esm-bundler",
"cjs"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/core-vapor.git",
"directory": "packages/runtime-shared"
},
"keywords": [
"vue"
],
"author": "Evan You",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/core-vapor/issues"
},
"homepage": "https://github.com/vuejs/core-vapor/tree/main/packages/runtime-shared#readme"
}

View File

@ -0,0 +1 @@
export { toHandlers } from './toHandlers'

View File

@ -0,0 +1,25 @@
import { isObject, toHandlerKey } from '@vue/shared'
/**
* For prefixing keys in v-on="obj" with "on"
* @private
*/
export function toHandlers(
warn: (msg: string) => void,
obj: Record<string, any>,
preserveCaseIfNecessary?: boolean,
): Record<string, any> {
const ret: Record<string, any> = {}
if (__DEV__ && !isObject(obj)) {
warn(`v-on with no argument expects an object value.`)
return ret
}
for (const key in obj) {
ret[
preserveCaseIfNecessary && /[A-Z]/.test(key)
? `on:${key}`
: toHandlerKey(key)
] = obj[key]
}
return ret
}

View File

@ -36,6 +36,7 @@
"homepage": "https://github.com/vuejs/core-vapor/tree/dev/packages/runtime-vapor#readme",
"dependencies": {
"@vue/shared": "workspace:*",
"@vue/reactivity": "workspace:*"
"@vue/reactivity": "workspace:*",
"@vue/runtime-shared": "workspace:*"
}
}

View File

@ -0,0 +1,4 @@
import { toHandlers as _toHandlers } from '@vue/runtime-shared'
import { warn } from '../warning'
export const toHandlers = _toHandlers.bind(undefined, warn)

View File

@ -127,6 +127,7 @@ export { createFor } from './apiCreateFor'
export { createComponent } from './apiCreateComponent'
export { resolveComponent, resolveDirective } from './helpers/resolveAssets'
export { toHandlers } from './helpers/toHandlers'
// **Internal** DOM-only runtime directive helpers
export {

View File

@ -319,6 +319,9 @@ importers:
'@vue/reactivity':
specifier: workspace:*
version: link:../reactivity
'@vue/runtime-shared':
specifier: workspace:*
version: link:../runtime-shared
'@vue/shared':
specifier: workspace:*
version: link:../shared
@ -335,6 +338,8 @@ importers:
specifier: ^3.1.3
version: 3.1.3
packages/runtime-shared: {}
packages/runtime-test:
dependencies:
'@vue/runtime-core':
@ -349,6 +354,9 @@ importers:
'@vue/reactivity':
specifier: workspace:*
version: link:../reactivity
'@vue/runtime-shared':
specifier: workspace:*
version: link:../runtime-shared
'@vue/shared':
specifier: workspace:*
version: link:../shared

View File

@ -28,6 +28,10 @@ export function fuzzyMatchTarget(partialTargets, includeAllMatching) {
/** @type {Array<string>} */
const matched = []
partialTargets.forEach(partialTarget => {
if (!includeAllMatching && targets.includes(partialTarget)) {
matched.push(partialTarget)
return
}
for (const target of targets) {
if (target.match(partialTarget)) {
matched.push(target)