Skip to content

Commit

Permalink
add comments, handle textarea.value inlining, see solidjs/solid#2312
Browse files Browse the repository at this point in the history
  • Loading branch information
titoBouzout committed Sep 29, 2024
1 parent 536d06d commit 9f5eca2
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions babel-preset/transform/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
getAttributeLiteral,
isAttributeLiteral,
} from './attributes.js'
import { isVoidElement, validateChildrenHTML } from './html.js'
import {
escapeHTML,
isVoidElement,
validateChildrenHTML,
} from './html.js'
import { merge, mergeToTag } from './merge.js'
import { buildProps } from './props.js'
import { getTagName } from './tag.js'
Expand All @@ -36,6 +40,7 @@ export function buildPartial(path, state) {
let isCustomElement = tagName.includes('-')
let isImportNode = isCustomElement
let xmlns = ''
let textChildren = ''

// attributes

Expand All @@ -51,28 +56,52 @@ export function buildPartial(path, state) {
if (attr.isJSXAttribute() && t.isJSXIdentifier(attr.node.name)) {
const name = attr.node.name.name

/** `isXML` */

if (name === 'xmlns') {
isXML = true
}

/** `isCustomElement` */

isCustomElement = isCustomElement || name === 'is'

/**
* Should mark as `importNode`?
*
* @url https://github.com/ryansolid/dom-expressions/pull/349
*/

isImportNode =
isImportNode ||
// Firefox needs `importNode` for images/iframes with loading="lazy"
((tagName === 'img' || tagName === 'iframe') &&
name === 'loading')

if (name === 'xmlns') {
isXML = true
}
/** Should inline the attribute into the template? */

if (isAttributeLiteral(attr.node)) {
/**
* Skip inlining the `xmlns` attribute in the tag when its a
* literal
*/
if (name === 'xmlns') {
xmlns = getAttributeLiteral(attr.node)
/**
* Skip inlining the `xmlns` attribute in the tag when its a
* literal
*/

continue
}

/**
* Do not inline `value` as an attribute when its a `textarea`
*
* @url https://github.com/solidjs/solid/issues/2312
*/
if (tagName === 'textarea' && name === 'value') {
textChildren += getAttributeLiteral(attr.node)
continue
}

/** Inline attribute */
const value = getAttributeLiteral(attr.node)

buildAttributeIntoTag(tag, name, value)
Expand Down Expand Up @@ -116,6 +145,8 @@ export function buildPartial(path, state) {

// children

tag.content += escapeHTML(textChildren)

let children = t.react.buildChildren(path.node)

validateChildrenHTML(tag.tagName, children)
Expand Down

0 comments on commit 9f5eca2

Please sign in to comment.