Skip to content

Commit

Permalink
chore: upgrade to grumbler-scripts v5
Browse files Browse the repository at this point in the history
  • Loading branch information
westeezy committed Feb 22, 2022
1 parent 7932b22 commit 03c8891
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"readmeFilename": "README.md",
"devDependencies": {
"flow-bin": "0.135.0",
"grumbler-scripts": "^3",
"grumbler-scripts": "^5.0.3",
"mocha": "^4.1.0"
}
}
29 changes: 15 additions & 14 deletions src/node.js
Expand Up @@ -52,12 +52,12 @@ function renderChildren<T>(children : $ReadOnlyArray<ElementNode | TextNode | Co
}

export class ElementNode {
type : (typeof NODE_TYPE.ELEMENT) = NODE_TYPE.ELEMENT
type : (typeof NODE_TYPE.ELEMENT) = NODE_TYPE.ELEMENT;

name : string
props : NodePropsType
children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>> // eslint-disable-line no-use-before-define
onRender : ?<T>(T) => void // eslint-disable-line no-undef
name : string;
props : NodePropsType;
children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>; // eslint-disable-line no-use-before-define
onRender : ?<T>(T) => void; // eslint-disable-line no-undef

constructor(name : string, props : NodePropsType, children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>) { // eslint-disable-line no-use-before-define
this.name = name;
Expand Down Expand Up @@ -85,9 +85,9 @@ export class ElementNode {
}

export class FragmentNode {
type : (typeof NODE_TYPE.FRAGMENT) = NODE_TYPE.FRAGMENT
type : (typeof NODE_TYPE.FRAGMENT) = NODE_TYPE.FRAGMENT;

children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>> // eslint-disable-line no-use-before-define
children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>; // eslint-disable-line no-use-before-define

constructor(children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>) { // eslint-disable-line no-use-before-define
this.children = children;
Expand All @@ -99,9 +99,9 @@ export class FragmentNode {
}

export class TextNode {
type : (typeof NODE_TYPE.TEXT) = NODE_TYPE.TEXT
type : (typeof NODE_TYPE.TEXT) = NODE_TYPE.TEXT;

text : string
text : string;

constructor(text : string) {
this.text = text;
Expand All @@ -114,11 +114,12 @@ export class TextNode {

// eslint-disable-next-line no-unused-vars
export class ComponentNode<P = null> {
type : (typeof NODE_TYPE.COMPONENT) = NODE_TYPE.COMPONENT
type : (typeof NODE_TYPE.COMPONENT) = NODE_TYPE.COMPONENT;

component : ComponentFunctionType<NodePropsType>
props : NodePropsType
children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>
component : ComponentFunctionType<NodePropsType>;
props : NodePropsType;
// eslint-disable-next-line no-use-before-define
children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>;

constructor(component : ComponentFunctionType<NodePropsType>, props : NodePropsType, children : $ReadOnlyArray<ElementNode | TextNode | ComponentNode<*>>) {
this.component = component;
Expand Down Expand Up @@ -185,7 +186,7 @@ export const node : CreateNode = <P>(element, props : P, ...children) => {
// $FlowFixMe
return new ElementNode(element, props, children);
}

if (typeof element === 'function') {
// $FlowFixMe
return new ComponentNode<*>(element, props, children);
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/html.js
@@ -1,4 +1,5 @@
/* @flow */
/* eslint unicorn/prefer-spread: off */

import { ComponentNode, TextNode, ElementNode, type NodePropsType, type NodeRenderer } from '../node';
import { NODE_TYPE } from '../constants';
Expand Down Expand Up @@ -69,7 +70,7 @@ export function html() : HTMLRenderer {
if (node.type === NODE_TYPE.COMPONENT) {
return [].concat(node.renderComponent(htmlRenderer)).join('');
}

if (node.type === NODE_TYPE.ELEMENT) {
const renderedProps = propsToHTML(node.props);

Expand All @@ -83,7 +84,7 @@ export function html() : HTMLRenderer {
return `<${ node.name }${ renderedProps }>${ renderedChildren }</${ node.name }>`;
}
}

if (node.type === NODE_TYPE.TEXT) {
return htmlEncode(node.text);
}
Expand Down
7 changes: 3 additions & 4 deletions src/renderers/react.js
@@ -1,6 +1,5 @@
/* @flow */

// eslint-disable-next-line import/no-unresolved
import type { Node } from 'react';

import { ComponentNode, TextNode, ElementNode, type NodeRenderer, type NodePropsType } from '../node';
Expand Down Expand Up @@ -31,16 +30,16 @@ export function react({ React } : {| React : ReactType |} = {}) : ReactRenderer
if (!React) {
throw new Error(`Must pass React library to react renderer`);
}

const reactRenderer = (node) => {
if (node.type === NODE_TYPE.COMPONENT) {
return React.createElement(() => (node.renderComponent(reactRenderer) || null), node.props, ...node.renderChildren(reactRenderer));
}

if (node.type === NODE_TYPE.ELEMENT) {
return React.createElement(node.name, mapReactProps(node.props), ...node.renderChildren(reactRenderer));
}

if (node.type === NODE_TYPE.TEXT) {
return node.text;
}
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/text.js
@@ -1,4 +1,5 @@
/* @flow */
/* eslint unicorn/prefer-spread: off */

import { ComponentNode, TextNode, ElementNode, type NodeRenderer } from '../node';
import { NODE_TYPE } from '../constants';
Expand All @@ -11,11 +12,11 @@ export function text() : TextRenderer {
if (node.type === NODE_TYPE.COMPONENT) {
return [].concat(node.renderComponent(textRenderer)).join('');
}

if (node.type === NODE_TYPE.ELEMENT) {
throw new Error(`Text renderer does not support basic elements`);
}

if (node.type === NODE_TYPE.TEXT) {
return node.text;
}
Expand Down
7 changes: 4 additions & 3 deletions test/.eslintrc.js
@@ -1,11 +1,12 @@
/* @flow */
/* eslint import/no-commonjs: off */

module.exports = {
'extends': require.resolve('grumbler-scripts/config/.eslintrc-browser-test'),

'rules': {
'react/display-name': 'off',
'react/display-name': 'off',
'react/button-has-type': 'off',
'react/prop-types': 'off'
'react/prop-types': 'off'
}
};
};
14 changes: 7 additions & 7 deletions test/tests/dom.jsx
Expand Up @@ -3,7 +3,7 @@
/** @jsxFrag Fragment */
/* eslint max-lines: off */

import { node, dom, Fragment } from '../../src'; // eslint-disable-line no-unused-vars
import { node, dom, Fragment } from '../../src';

type ExpectedNode = {|
name? : string,
Expand All @@ -17,7 +17,7 @@ function validateDOMElement(domNode : HTMLElement | Text, expected : ExpectedNod
if (domNode.constructor.name === 'HTMLUnknownElement') {
throw new Error(`Expected dom domNode '${ expected.name || 'undefiined' }' to be a valid element`);
}

if (typeof expected.element === 'string' && domNode.constructor.name !== expected.element) {
throw new Error(`Expected dom domNode '${ expected.element || 'undefiined' }', got ${ domNode.constructor.name || 'undefined' }`);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('dom renderer cases', () => {
it('should render an element with innerHTML and a script tag', () => {

window.scriptTagRun = false;

const jsxNode = (
<section innerHTML={ `<p id="foo"><script>window.scriptTagRun = true;</script></p>` } />
);
Expand Down Expand Up @@ -266,11 +266,11 @@ describe('dom renderer cases', () => {
throw new Error(`Expected error to be thrown`);
}
});

it('should render an element with a script tag', () => {

window.scriptTagRun = false;

const jsxNode = (
<section>
<p id="foo">
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('dom renderer cases', () => {
it('should render an element with multiple script tags', () => {

window.scriptTagRunCount = 0;

const jsxNode = (
<section>
<p id="foo">
Expand Down Expand Up @@ -873,7 +873,7 @@ describe('dom renderer cases', () => {
d: 'M0 0L12 12',
id: 'backwardSlash'
};

const circleProps = {
id: 'defCircle',
cx: '0',
Expand Down
6 changes: 3 additions & 3 deletions test/tests/html.jsx
Expand Up @@ -3,7 +3,7 @@
/** @jsxFrag Fragment */
/* eslint react/jsx-no-useless-fragment: off */

import { node, html, Fragment } from '../../src'; // eslint-disable-line no-unused-vars
import { node, html, Fragment } from '../../src';

describe('html renderer cases', () => {

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('html renderer cases', () => {
});

it('should escape special characters', () => {

const jsxNode = (
<button foo={ `&"'$%<>` } { ...{ '$"\'': '<><>%$&' } }>${ `a&<<b>c"<d'''/` }</button>
);
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('html renderer cases', () => {
});

it('should render a basic element as html with innerHTML', () => {

const jsxNode = (
<section>
<p foo="bar" innerHTML={ `<span>hello world</span>` } />
Expand Down

0 comments on commit 03c8891

Please sign in to comment.