11/**
22 * @typedef {import('estree').Property } Property
3+ *
4+ * @typedef {import('estree-jsx').JSXAttribute } JsxAttribute
35 * @typedef {import('estree-jsx').JSXElement } JsxElement
46 * @typedef {import('estree-jsx').JSXSpreadAttribute } JsxSpreadAttribute
5- * @typedef { import('estree-jsx').JSXAttribute } JsxAttribute
7+ *
68 * @typedef {import('hast').Element } HastElement
9+ *
710 * @typedef {import('../state.js').State } State
811 */
912
1215 */
1316
1417import { stringify as commas } from 'comma-separated-tokens'
15- import { svg , find , hastToReact } from 'property-information'
18+ import { name as identifierName } from 'estree-util-is-identifier-name'
19+ import { find , hastToReact , svg } from 'property-information'
1620import { stringify as spaces } from 'space-separated-tokens'
17- import {
18- start as identifierStart ,
19- cont as identifierCont ,
20- name as identifierName
21- } from 'estree-util-is-identifier-name'
2221import styleToObject from 'style-to-object'
2322
2423const own = { } . hasOwnProperty
@@ -63,10 +62,10 @@ export function element(node, state) {
6362 // Ignore nullish and `NaN` values.
6463 // Ignore `false` and falsey known booleans.
6564 if (
66- value === undefined ||
6765 value === null ||
68- ( typeof value === 'number' && Number . isNaN ( value ) ) ||
66+ value === undefined ||
6967 value === false ||
68+ ( typeof value === 'number' && Number . isNaN ( value ) ) ||
7069 ( ! value && info . boolean )
7170 ) {
7271 continue
@@ -125,7 +124,7 @@ export function element(node, state) {
125124 attributeValue = { type : 'Literal' , value : String ( value ) }
126125 }
127126
128- if ( jsxIdentifierName ( prop ) ) {
127+ if ( identifierName ( prop , { jsx : true } ) ) {
129128 attributes . push ( {
130129 type : 'JSXAttribute' ,
131130 name : { type : 'JSXIdentifier' , name : prop } ,
@@ -197,6 +196,7 @@ function parseStyle(value, tagName) {
197196 try {
198197 styleToObject ( value , iterator )
199198 } catch ( error ) {
199+ // To do: use `cause`.
200200 const exception = /** @type {Error } */ ( error )
201201 exception . message =
202202 tagName + '[style]' + exception . message . slice ( 'undefined' . length )
@@ -212,7 +212,7 @@ function parseStyle(value, tagName) {
212212 * Key.
213213 * @param {string } value
214214 * Value.
215- * @returns {void }
215+ * @returns {undefined }
216216 * Nothing.
217217 */
218218 function iterator ( name , value ) {
@@ -277,32 +277,3 @@ function toCamel(_, $1) {
277277function toDash ( $0 ) {
278278 return '-' + $0 . toLowerCase ( )
279279}
280-
281- /**
282- * Checks if the given string is a valid identifier name.
283- *
284- * Allows dashes, so it’s actually JSX identifier names.
285- *
286- * @param {string } name
287- * Whatever.
288- * @returns {boolean }
289- * Whether `name` is a valid JSX identifier.
290- */
291- function jsxIdentifierName ( name ) {
292- let index = - 1
293-
294- while ( ++ index < name . length ) {
295- if ( ! ( index ? cont : identifierStart ) ( name . charCodeAt ( index ) ) ) return false
296- }
297-
298- // `false` if `name` is empty.
299- return index > 0
300-
301- /**
302- * @param {number } code
303- * @returns {boolean }
304- */
305- function cont ( code ) {
306- return identifierCont ( code ) || code === 45 /* `-` */
307- }
308- }
0 commit comments