Skip to content

Commit 3d92037

Browse files
committed
Code refactor
- move newProperties to a function and call it only when needed - added more mapped attributes - updated tsconfig
1 parent 8005481 commit 3d92037

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-jsx",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "",
55
"source": "src/jsx-runtime.ts",
66
"main": "./dist/jsx-runtime.js",

src/jsx-runtime.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import { Dynamic } from 'solid-js/web';
33

44
export const Fragment = (properties: PropsWithChildren): JSX.Element => properties.children;
55

6-
export const jsx = (
7-
type: string | ((properties_: PropsWithChildren) => JSX.Element),
8-
properties: Record<string, unknown> & { children: JSX.Element }
9-
): JSX.Element => {
6+
const getNewProperties = (
7+
properties: Record<string, unknown> & { children?: JSX.Element }
8+
): PropsWithChildren => {
109
const newProperties: Record<string, unknown> = {};
11-
1210
for (const key of Object.keys(properties)) newProperties[jsxKeyToSolid(key)] = properties[key];
11+
return newProperties;
12+
};
1313

14-
return typeof type === 'function'
14+
export const jsx = (
15+
type: string | ((properties_: PropsWithChildren) => JSX.Element),
16+
properties: PropsWithChildren
17+
): JSX.Element =>
18+
typeof type === 'function'
1519
? type.name === 'Fragment'
1620
? properties.children
17-
: type(newProperties)
18-
: createComponent(Dynamic, mergeProps(newProperties, { component: type }));
19-
};
21+
: type(getNewProperties(properties))
22+
: createComponent(Dynamic, mergeProps(getNewProperties(properties), { component: type }));
2023

2124
// For the moment we do not distinguish static children from dynamic ones
2225
export const jsxs = jsx;
@@ -34,6 +37,11 @@ const MAPPED_ATTRIBUTES = new Map([
3437
['autoFocus', 'autofocus'],
3538
['contentEditable', 'contenteditable'],
3639
['noValidate', 'novalidate'],
40+
['isMap', 'ismap'],
41+
['playsInline', 'playsinline'],
42+
['allowFullScreen', 'allowfullscreen'],
43+
['formNoValidate', 'formnovalidate'],
44+
['noModule', 'nomodule'],
3745
]);
3846

3947
const jsxKeyToSolid = (key: string): string =>

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
14+
"target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
"jsx": "preserve" /* Specify what JSX code is generated. */,
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -74,7 +74,7 @@
7474
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7575

7676
/* Type Checking */
77-
"strict": true /* Enable all strict type-checking options. */,
77+
"strict": true /* Enable all strict type-checking options. */
7878
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
7979
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
8080
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
@@ -96,6 +96,6 @@
9696

9797
/* Completeness */
9898
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
99+
// "skipLibCheck": true /* Skip type checking all .d.ts files. */
100100
}
101101
}

0 commit comments

Comments
 (0)