From 47090149f8ddbf164b427f876999d9a7632a1f9e Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 23 Nov 2023 10:32:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=B9=E6=AE=8A=E7=B1=BB?= =?UTF-8?q?=E5=9E=8Bnull=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/constants.js | 9 ++++++++- src/index.js | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e40d15b..727573a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkit", - "version": "1.10.14", + "version": "1.11.0", "type": "module", "description": "A library for building fast, lightweight web components.", "main": "dist/index.js", diff --git a/src/constants.js b/src/constants.js index 49e7b79..afb01be 100644 --- a/src/constants.js +++ b/src/constants.js @@ -101,7 +101,7 @@ function getType(v) { return { type, default: v, attribute } default: - return { type: String, default: v + '' } + return { type: null, default: '' } } } @@ -131,6 +131,10 @@ export function parsePropsDeclaration(options) { options = { type: Array } break + case String: + options = { type: String } + break + default: options = getType(options) break @@ -174,6 +178,9 @@ export function fixedValue(value, options) { } } + case null: + return value + default: return value === null || value === void 0 ? null : value + '' } diff --git a/src/index.js b/src/index.js index 690f48d..c110ec4 100644 --- a/src/index.js +++ b/src/index.js @@ -296,7 +296,7 @@ export class Component extends HTMLElement { let options = this.#getPropOptions(name) || {} let attrName = options.attrName - if (options.attribute === false) { + if (options.attribute === false || options.type === null) { this.removeAttribute(attrName) return } @@ -340,7 +340,7 @@ export class Component extends HTMLElement { if (options) { value = fixedValue(value, options) - if (options.attribute === false) { + if (options.attribute === false || options.type === null) { if (value === null) { return }