Skip to content

Commit

Permalink
feat(runtime-shared): init
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 1, 2024
1 parent 1ec90db commit bfb5250
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-vapor/src/generators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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, ')']
}
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*"
}
}
25 changes: 2 additions & 23 deletions packages/runtime-core/src/helpers/toHandlers.ts
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions packages/runtime-shared/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/runtime-shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @vue/runtime-shared
7 changes: 7 additions & 0 deletions packages/runtime-shared/index.js
Original file line number Diff line number Diff line change
@@ -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')
}
47 changes: 47 additions & 0 deletions packages/runtime-shared/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions packages/runtime-shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { toHandlers } from './toHandlers'
25 changes: 25 additions & 0 deletions packages/runtime-shared/src/toHandlers.ts
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion packages/runtime-vapor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*"
}
}
4 changes: 4 additions & 0 deletions packages/runtime-vapor/src/helpers/toHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { toHandlers as _toHandlers } from '@vue/runtime-shared'
import { warn } from '../warning'

export const toHandlers = _toHandlers.bind(undefined, warn)
1 change: 1 addition & 0 deletions packages/runtime-vapor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bfb5250

Please sign in to comment.