Comparing version 1.4.2 to 1.4.3
@@ -25,4 +25,5 @@ let detectJSX = require('@a-la/detect-jsx'); if (detectJSX && detectJSX.__esModule) detectJSX = detectJSX.default; | ||
const children = parseContent(content, quoteProps, warn) | ||
const { obj, destructuring } = getProps(props) | ||
const f = pragma(tagName, obj, children, destructuring, quoteProps, warn) | ||
const { obj, destructuring, whitespace } = getProps(props.replace(/^ */, '')) | ||
const beforeCloseWs = /\s*$/.exec(props) || [''] | ||
const f = pragma(tagName, obj, children, destructuring, quoteProps, warn, whitespace, beforeCloseWs) | ||
const res = replaceChunk(input, position, length, f) | ||
@@ -29,0 +30,0 @@ // find another one one |
@@ -59,5 +59,6 @@ const { SyncReplaceable } = require('restream'); | ||
const destructuring = [] | ||
const whitespace = {} | ||
const lastClose = positions.reduce((acc, { open, close }) => { | ||
const before =props.slice(acc, open) | ||
const [, propName] = /(\S+)\s*=\s*$/.exec(before) || [] | ||
const before = props.slice(acc, open) | ||
const [, wsBefore, propName, wsBeforeAssign, afterAssign] = /(\s*)(\S+)(\s*)=(\s*)$/.exec(before) || [] | ||
const val = props.slice(open + 1, close) | ||
@@ -71,7 +72,9 @@ if (!propName && !/\s*\.\.\./.test(val)) | ||
} | ||
whitespace[propName] = { before: wsBefore, beforeAssign: wsBeforeAssign, afterAssign } | ||
const beforeOrNot = before || '' // when using destructuring | ||
const propOrNot = propName || '' | ||
const bb = beforeOrNot.slice(0, beforeOrNot.length - propOrNot.length - 1) | ||
const plain = getPlain(bb) | ||
const { plain, whitespace: ws } = getPlain(bb) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
return close + 1 | ||
@@ -81,10 +84,12 @@ }, 0) | ||
if (!positions.length) { | ||
const plain = getPlain(props) | ||
const { plain, whitespace: ws } = getPlain(props) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
} else { | ||
const whatsLeft = props.slice(lastClose) | ||
const plain = getPlain(whatsLeft) | ||
const { plain, whitespace: ws } = getPlain(whatsLeft) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
} | ||
return { obj, destructuring } | ||
return { obj, destructuring, whitespace } | ||
} | ||
@@ -98,7 +103,10 @@ | ||
const r = [] | ||
const res = string.replace(/(\S+)\s*=\s*(["'])([\s\S]+?)\2/g, (m, name, q, val, i) => { | ||
const whitespace = {} | ||
const res = string.replace(/(\s*)(\S+)(\s*)=(\s*)(["'])([\s\S]+?)\5/g, (m, wsBefore, name, wsBeforeAssign, wsAfterAssign, q, val, i) => { | ||
whitespace[name] = { before: wsBefore, beforeAssign: wsBeforeAssign, afterAssign: wsAfterAssign } | ||
r.push({ i, name, val: `${q}${val}${q}` }) | ||
return ' '.repeat(m.length) | ||
return '%'.repeat(m.length) | ||
}) | ||
res.replace(/(\S+)/g, (m, name, i) => { | ||
res.replace(/(\s*)([^\s%]+)/g, (m, ws, name, i) => { | ||
whitespace[name] = { before: ws } | ||
r.push({ i, name, val: '\'\'' }) // boolean | ||
@@ -113,3 +121,3 @@ }) | ||
}, {}) | ||
return obj | ||
return { plain: obj, whitespace } | ||
} | ||
@@ -123,3 +131,3 @@ | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false) => { | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false, whitespace = {}, beforeCloseWs = '') => { | ||
const { length } = Object.keys(pp) | ||
@@ -130,4 +138,5 @@ if (!length && !destructuring.length) return '{}' | ||
const kk = quoteProps || k.indexOf('-') != -1 ? `'${k}'` : k | ||
return [...a, `${kk}:${v}`] | ||
}, destructuring).join(',')}}` | ||
const { before = '', beforeAssign = '', afterAssign = '' } = whitespace[k] || {} | ||
return [...a, `${before}${kk}${beforeAssign}:${afterAssign}${v}`] | ||
}, destructuring).join(',')}${beforeCloseWs}}` | ||
return pr | ||
@@ -155,3 +164,3 @@ } | ||
*/ | ||
const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn) => { | ||
const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn, whitespace, beforeCloseWs) => { | ||
const cn = isComponentName(tagName) | ||
@@ -166,3 +175,3 @@ const tn = cn ? tagName : `'${tagName}'` | ||
} | ||
const pr = makeObjectBody(props, destructuring, qp) | ||
const pr = makeObjectBody(props, destructuring, qp, whitespace, beforeCloseWs) | ||
const c = children.reduce((acc, cc, i) => { | ||
@@ -169,0 +178,0 @@ const prev = children[i-1] |
@@ -0,1 +1,7 @@ | ||
## 25 February 2019 | ||
### 1.4.3 | ||
- [feature] Preserve new lines in attributes. | ||
## 15 February 2019 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@a-la/jsx", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "The JSX Transform For ÀLaMode And Other Packages.", | ||
@@ -48,7 +48,7 @@ "main": "build/index.js", | ||
"@wrote/read": "1.0.2", | ||
"alamode": "1.7.3", | ||
"documentary": "1.21.1", | ||
"alamode": "1.8.2", | ||
"documentary": "1.21.2", | ||
"eslint-config-artdeco": "1.0.1", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "3.6.6" | ||
"zoroaster": "3.7.3" | ||
}, | ||
@@ -55,0 +55,0 @@ "dependencies": { |
@@ -102,3 +102,3 @@ # @a-la/jsx | ||
return false | ||
},role:"aria-button"}, | ||
}, role:"aria-button"}, | ||
h(Title), | ||
@@ -105,0 +105,0 @@ h(RichTextArea,{dynamic:''}), |
@@ -25,4 +25,5 @@ import detectJSX from '@a-la/detect-jsx' | ||
const children = parseContent(content, quoteProps, warn) | ||
const { obj, destructuring } = getProps(props) | ||
const f = pragma(tagName, obj, children, destructuring, quoteProps, warn) | ||
const { obj, destructuring, whitespace } = getProps(props.replace(/^ */, '')) | ||
const beforeCloseWs = /\s*$/.exec(props) || [''] | ||
const f = pragma(tagName, obj, children, destructuring, quoteProps, warn, whitespace, beforeCloseWs) | ||
const res = replaceChunk(input, position, length, f) | ||
@@ -29,0 +30,0 @@ // find another one one |
@@ -59,5 +59,6 @@ import { SyncReplaceable } from 'restream' | ||
const destructuring = [] | ||
const whitespace = {} | ||
const lastClose = positions.reduce((acc, { open, close }) => { | ||
const before =props.slice(acc, open) | ||
const [, propName] = /(\S+)\s*=\s*$/.exec(before) || [] | ||
const before = props.slice(acc, open) | ||
const [, wsBefore, propName, wsBeforeAssign, afterAssign] = /(\s*)(\S+)(\s*)=(\s*)$/.exec(before) || [] | ||
const val = props.slice(open + 1, close) | ||
@@ -71,7 +72,9 @@ if (!propName && !/\s*\.\.\./.test(val)) | ||
} | ||
whitespace[propName] = { before: wsBefore, beforeAssign: wsBeforeAssign, afterAssign } | ||
const beforeOrNot = before || '' // when using destructuring | ||
const propOrNot = propName || '' | ||
const bb = beforeOrNot.slice(0, beforeOrNot.length - propOrNot.length - 1) | ||
const plain = getPlain(bb) | ||
const { plain, whitespace: ws } = getPlain(bb) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
return close + 1 | ||
@@ -81,10 +84,12 @@ }, 0) | ||
if (!positions.length) { | ||
const plain = getPlain(props) | ||
const { plain, whitespace: ws } = getPlain(props) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
} else { | ||
const whatsLeft = props.slice(lastClose) | ||
const plain = getPlain(whatsLeft) | ||
const { plain, whitespace: ws } = getPlain(whatsLeft) | ||
Object.assign(obj, plain) | ||
Object.assign(whitespace, ws) | ||
} | ||
return { obj, destructuring } | ||
return { obj, destructuring, whitespace } | ||
} | ||
@@ -98,7 +103,10 @@ | ||
const r = [] | ||
const res = string.replace(/(\S+)\s*=\s*(["'])([\s\S]+?)\2/g, (m, name, q, val, i) => { | ||
const whitespace = {} | ||
const res = string.replace(/(\s*)(\S+)(\s*)=(\s*)(["'])([\s\S]+?)\5/g, (m, wsBefore, name, wsBeforeAssign, wsAfterAssign, q, val, i) => { | ||
whitespace[name] = { before: wsBefore, beforeAssign: wsBeforeAssign, afterAssign: wsAfterAssign } | ||
r.push({ i, name, val: `${q}${val}${q}` }) | ||
return ' '.repeat(m.length) | ||
return '%'.repeat(m.length) | ||
}) | ||
res.replace(/(\S+)/g, (m, name, i) => { | ||
res.replace(/(\s*)([^\s%]+)/g, (m, ws, name, i) => { | ||
whitespace[name] = { before: ws } | ||
r.push({ i, name, val: '\'\'' }) // boolean | ||
@@ -113,3 +121,3 @@ }) | ||
}, {}) | ||
return obj | ||
return { plain: obj, whitespace } | ||
} | ||
@@ -123,3 +131,3 @@ | ||
export | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false) => { | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false, whitespace = {}, beforeCloseWs = '') => { | ||
const { length } = Object.keys(pp) | ||
@@ -130,4 +138,5 @@ if (!length && !destructuring.length) return '{}' | ||
const kk = quoteProps || k.indexOf('-') != -1 ? `'${k}'` : k | ||
return [...a, `${kk}:${v}`] | ||
}, destructuring).join(',')}}` | ||
const { before = '', beforeAssign = '', afterAssign = '' } = whitespace[k] || {} | ||
return [...a, `${before}${kk}${beforeAssign}:${afterAssign}${v}`] | ||
}, destructuring).join(',')}${beforeCloseWs}}` | ||
return pr | ||
@@ -155,3 +164,3 @@ } | ||
*/ | ||
export const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn) => { | ||
export const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn, whitespace, beforeCloseWs) => { | ||
const cn = isComponentName(tagName) | ||
@@ -166,3 +175,3 @@ const tn = cn ? tagName : `'${tagName}'` | ||
} | ||
const pr = makeObjectBody(props, destructuring, qp) | ||
const pr = makeObjectBody(props, destructuring, qp, whitespace, beforeCloseWs) | ||
const c = children.reduce((acc, cc, i) => { | ||
@@ -169,0 +178,0 @@ const prev = children[i-1] |
48665
1005