Comparing version 1.4.7 to 1.5.0
@@ -8,5 +8,5 @@ const transpileJSX = require('./lib/components'); | ||
* @param {string} input The source code with JSX to transpile. | ||
* @param {Config} config Options for the program. | ||
* @param {(true|'dom')} [config.quoteProps=false] Whether to surround property names with quotes, e.g., for the Google Closure Compiler. When `dom` is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter. Default `false`. | ||
* @param {function} [config.warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
* @param {!_alaJsx.Config} config Options for the program. | ||
* @param {(boolean|string)} [config.quoteProps=false] Whether to surround property names with quotes. When the `dom` string is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter (E.g., for the _Google Closure Compiler_). Default `false`. | ||
* @param {function(...string)} [config.warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
*/ | ||
@@ -43,5 +43,10 @@ const jsx = (input, config = {}) => { | ||
/** | ||
* @typedef {Object} Config Options for the program. | ||
* @prop {(true|'dom')} [quoteProps=false] Whether to surround property names with quotes, e.g., for the Google Closure Compiler. When `dom` is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter. Default `false`. | ||
* @prop {function} [warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {_alaJsx.Config} Config Options for the program. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} _alaJsx.Config Options for the program. | ||
* @prop {(boolean|string)} [quoteProps=false] Whether to surround property names with quotes. When the `dom` string is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter (E.g., for the _Google Closure Compiler_). Default `false`. | ||
* @prop {function(...string)} [warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
*/ |
@@ -51,3 +51,3 @@ let detectJSX = require('@a-la/detect-jsx'); if (detectJSX && detectJSX.__esModule) detectJSX = detectJSX.default; | ||
*/ | ||
const parseContent = (content, quoteProps = false, warn) => { | ||
const parseContent = (content, quoteProps = false, warn = null) => { | ||
if (!content) return [] | ||
@@ -54,0 +54,0 @@ // const C = content |
@@ -108,4 +108,10 @@ const { SyncReplaceable, makeMarkers, makeCutRule } = require('restream'); | ||
class ExtractedJSX { | ||
/** | ||
* @param {{ string: string, props: string, content: string, tagName: string }} properties | ||
*/ | ||
constructor(properties) { | ||
Object.assign(this, properties) | ||
this.string = properties.string | ||
this.props = properties.props | ||
this.content = properties.content | ||
this.tagName = properties.tagName | ||
} | ||
@@ -112,0 +118,0 @@ } |
@@ -122,3 +122,3 @@ const { SyncReplaceable } = require('restream'); | ||
* Accepts the parsed node properties to make a JS object string out of them. | ||
* @param {Object.<string, string>} pp The properties out of which to make a string object. | ||
* @param {!Object<string, string>} pp The properties out of which to make a string object. | ||
* @returns {string|null} Either a JS object body string, or null if no keys were in the object. | ||
@@ -128,5 +128,6 @@ */ | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false, whitespace = {}, beforeCloseWs = '') => { | ||
const { length } = Object.keys(pp) | ||
const keys = Object.keys(pp) | ||
const { length } = keys | ||
if (!length && !destructuring.length) return '{}' | ||
const pr = `{${Object.keys(pp).reduce((a, k) => { | ||
const pr = `{${keys.reduce((a, k) => { | ||
const v = pp[k] | ||
@@ -149,5 +150,5 @@ const kk = quoteProps || k.indexOf('-') != -1 ? `'${k}'` : k | ||
* @param {string} tagName The name of the tag to create, or a reference to a component function. | ||
* @param {Object.<string, string>} props The properties of the element. The properties' values can be passed as strings or references as the `e` function will be called under the scope in which the JSX is written, e.g., when creating components `const C = ({ reference }) => <div id={reference} class="String"/>`. | ||
* @param {string[]} children The array with the child nodes which are strings, but encode either a reference, a string or an invocation the the `e` function again. Thus the jsx is parsed recursively depth-first. | ||
* @param {string[]} [destructuring] Any properties for destructuring. | ||
* @param {!Object<string, string>} props The properties of the element. The properties' values can be passed as strings or references as the `e` function will be called under the scope in which the JSX is written, e.g., when creating components `const C = ({ reference }) => <div id={reference} class="String"/>`. | ||
* @param {!Array<string>} children The array with the child nodes which are strings, but encode either a reference, a string or an invocation the the `e` function again. Thus the jsx is parsed recursively depth-first. | ||
* @param {!Array<string>} [destructuring] Any properties for destructuring. | ||
* @param {boolean} [quoteProps=false] Whether to quote the properties' keys (for Closure compiler). | ||
@@ -160,3 +161,3 @@ * @example | ||
*/ | ||
const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn, whitespace, beforeCloseWs) => { | ||
const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn = null, whitespace = {}, beforeCloseWs = '') => { | ||
const cn = isComponentName(tagName) | ||
@@ -190,4 +191,4 @@ const tn = cn ? tagName : `'${tagName}'` | ||
* @param {string} input The string inside of which the chunk needs to be replaced. | ||
* @param {string} index The index of the `<` found with `detect-jsx.findPosition`. | ||
* @param {string} length The length of the string that needs to be cut out. | ||
* @param {number} index The index of the `<` found with `detect-jsx.findPosition`. | ||
* @param {number} length The length of the string that needs to be cut out. | ||
* @param {string} chunk The new string that needs to be placed back into the input. | ||
@@ -194,0 +195,0 @@ * |
@@ -20,3 +20,3 @@ const { SyncReplaceable } = require('restream'); | ||
}) | ||
.replace(/([\s\S]+?)?(\n\s*)$/, (m, v = '', a) => { | ||
.replace(/([\s\S]+?)?(\n\s*)$/, (m, v = '', a = '') => { | ||
_a = a | ||
@@ -79,4 +79,4 @@ return v | ||
* @param {string} string The initial string. | ||
* @param {{from: number, to: number, expression: string }[]} temps | ||
* @return {string[]} | ||
* @param {Array<!{from: number, to: number, expression: string }>} temps | ||
* @return {!Array<string>} | ||
* @private This is called by parseSimpleContent. | ||
@@ -83,0 +83,0 @@ */ |
@@ -0,1 +1,8 @@ | ||
## 24 April 2019 | ||
### [1.5.0](https://github.com/a-la/jsx/compare/v1.4.7...v1.5.0) | ||
- [externs] Add externs. | ||
- [types] Annotate all types correctly. | ||
## 16 April 2019 | ||
@@ -6,2 +13,3 @@ | ||
- [fix] Fix export default object support. | ||
- [deps] Update and unfix dependencies. | ||
@@ -8,0 +16,0 @@ ## 3 April 2019 |
{ | ||
"name": "@a-la/jsx", | ||
"version": "1.4.7", | ||
"version": "1.5.0", | ||
"description": "The JSX Transform For ÀLaMode And Other Packages.", | ||
@@ -16,7 +16,8 @@ "main": "build/index.js", | ||
"b": "alamode src -o build -s", | ||
"d": "yarn-s d1", | ||
"d1": "NODE_DEBUG=doc doc src/index.js -g", | ||
"d": "yarn-s d1 externs", | ||
"d1": "typal src/index.js -c", | ||
"externs": "typal externs.js -e", | ||
"build": "yarn-s d b doc", | ||
"rec": "NODE_DEBUG=appshot appshot -T 23 -a Terminal -y 150 -f", | ||
"e": "alanode", | ||
"dev": "alanode src/jsx", | ||
"depack": "depack-dev depack -c -o depack.js -O 2017 -a -p -w", | ||
@@ -27,4 +28,6 @@ "example/": "yarn e example/example.js" | ||
"build", | ||
"src" | ||
"src", | ||
"externs.js" | ||
], | ||
"externs": "externs.js", | ||
"repository": { | ||
@@ -52,11 +55,12 @@ "type": "git", | ||
"alamode": "^1.9.3", | ||
"documentary": "^1.23.4", | ||
"argufy": "^1.5.0", | ||
"documentary": "^1.25.0", | ||
"eslint-config-artdeco": "1.0.1", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "^3.11.5" | ||
"zoroaster": "^3.12.0" | ||
}, | ||
"dependencies": { | ||
"@a-la/detect-jsx": "^1.0.1", | ||
"restream": "^3.6.0" | ||
"restream": "^3.7.1" | ||
} | ||
} |
@@ -8,5 +8,5 @@ import transpileJSX from './lib/components' | ||
* @param {string} input The source code with JSX to transpile. | ||
* @param {Config} config Options for the program. | ||
* @param {(true|'dom')} [config.quoteProps=false] Whether to surround property names with quotes, e.g., for the Google Closure Compiler. When `dom` is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter. Default `false`. | ||
* @param {function} [config.warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
* @param {!_alaJsx.Config} config Options for the program. | ||
* @param {(boolean|string)} [config.quoteProps=false] Whether to surround property names with quotes. When the `dom` string is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter (E.g., for the _Google Closure Compiler_). Default `false`. | ||
* @param {function(...string)} [config.warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
*/ | ||
@@ -43,5 +43,10 @@ const jsx = (input, config = {}) => { | ||
/** | ||
* @typedef {Object} Config Options for the program. | ||
* @prop {(true|'dom')} [quoteProps=false] Whether to surround property names with quotes, e.g., for the Google Closure Compiler. When `dom` is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter. Default `false`. | ||
* @prop {function} [warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {_alaJsx.Config} Config Options for the program. | ||
*/ | ||
/** | ||
* @suppress {nonStandardJsDocs} | ||
* @typedef {Object} _alaJsx.Config Options for the program. | ||
* @prop {(boolean|string)} [quoteProps=false] Whether to surround property names with quotes. When the `dom` string is passed, it will only quote props for invoking html components, i.e., those that start with a lowercase letter (E.g., for the _Google Closure Compiler_). Default `false`. | ||
* @prop {function(...string)} [warn] The function to receive warnings, e.g., when destructuring of properties is used on dom elements (for Closure Compiler). | ||
*/ |
@@ -51,3 +51,3 @@ import detectJSX from '@a-la/detect-jsx' | ||
*/ | ||
export const parseContent = (content, quoteProps = false, warn) => { | ||
export const parseContent = (content, quoteProps = false, warn = null) => { | ||
if (!content) return [] | ||
@@ -54,0 +54,0 @@ // const C = content |
@@ -108,4 +108,10 @@ import { SyncReplaceable, makeMarkers, makeCutRule } from 'restream' | ||
export class ExtractedJSX { | ||
/** | ||
* @param {{ string: string, props: string, content: string, tagName: string }} properties | ||
*/ | ||
constructor(properties) { | ||
Object.assign(this, properties) | ||
this.string = properties.string | ||
this.props = properties.props | ||
this.content = properties.content | ||
this.tagName = properties.tagName | ||
} | ||
@@ -112,0 +118,0 @@ } |
@@ -122,3 +122,3 @@ import { SyncReplaceable } from 'restream' | ||
* Accepts the parsed node properties to make a JS object string out of them. | ||
* @param {Object.<string, string>} pp The properties out of which to make a string object. | ||
* @param {!Object<string, string>} pp The properties out of which to make a string object. | ||
* @returns {string|null} Either a JS object body string, or null if no keys were in the object. | ||
@@ -128,5 +128,6 @@ */ | ||
const makeObjectBody = (pp, destructuring = [], quoteProps = false, whitespace = {}, beforeCloseWs = '') => { | ||
const { length } = Object.keys(pp) | ||
const keys = Object.keys(pp) | ||
const { length } = keys | ||
if (!length && !destructuring.length) return '{}' | ||
const pr = `{${Object.keys(pp).reduce((a, k) => { | ||
const pr = `{${keys.reduce((a, k) => { | ||
const v = pp[k] | ||
@@ -149,5 +150,5 @@ const kk = quoteProps || k.indexOf('-') != -1 ? `'${k}'` : k | ||
* @param {string} tagName The name of the tag to create, or a reference to a component function. | ||
* @param {Object.<string, string>} props The properties of the element. The properties' values can be passed as strings or references as the `e` function will be called under the scope in which the JSX is written, e.g., when creating components `const C = ({ reference }) => <div id={reference} class="String"/>`. | ||
* @param {string[]} children The array with the child nodes which are strings, but encode either a reference, a string or an invocation the the `e` function again. Thus the jsx is parsed recursively depth-first. | ||
* @param {string[]} [destructuring] Any properties for destructuring. | ||
* @param {!Object<string, string>} props The properties of the element. The properties' values can be passed as strings or references as the `e` function will be called under the scope in which the JSX is written, e.g., when creating components `const C = ({ reference }) => <div id={reference} class="String"/>`. | ||
* @param {!Array<string>} children The array with the child nodes which are strings, but encode either a reference, a string or an invocation the the `e` function again. Thus the jsx is parsed recursively depth-first. | ||
* @param {!Array<string>} [destructuring] Any properties for destructuring. | ||
* @param {boolean} [quoteProps=false] Whether to quote the properties' keys (for Closure compiler). | ||
@@ -160,3 +161,3 @@ * @example | ||
*/ | ||
export const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn, whitespace, beforeCloseWs) => { | ||
export const pragma = (tagName, props = {}, children = [], destructuring = [], quoteProps = false, warn = null, whitespace = {}, beforeCloseWs = '') => { | ||
const cn = isComponentName(tagName) | ||
@@ -190,4 +191,4 @@ const tn = cn ? tagName : `'${tagName}'` | ||
* @param {string} input The string inside of which the chunk needs to be replaced. | ||
* @param {string} index The index of the `<` found with `detect-jsx.findPosition`. | ||
* @param {string} length The length of the string that needs to be cut out. | ||
* @param {number} index The index of the `<` found with `detect-jsx.findPosition`. | ||
* @param {number} length The length of the string that needs to be cut out. | ||
* @param {string} chunk The new string that needs to be placed back into the input. | ||
@@ -194,0 +195,0 @@ * |
@@ -20,3 +20,3 @@ import { SyncReplaceable } from 'restream' | ||
}) | ||
.replace(/([\s\S]+?)?(\n\s*)$/, (m, v = '', a) => { | ||
.replace(/([\s\S]+?)?(\n\s*)$/, (m, v = '', a = '') => { | ||
_a = a | ||
@@ -79,4 +79,4 @@ return v | ||
* @param {string} string The initial string. | ||
* @param {{from: number, to: number, expression: string }[]} temps | ||
* @return {string[]} | ||
* @param {Array<!{from: number, to: number, expression: string }>} temps | ||
* @return {!Array<string>} | ||
* @private This is called by parseSimpleContent. | ||
@@ -83,0 +83,0 @@ */ |
53415
19
1095
7
Updatedrestream@^3.7.1