Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace defaultProps with JS fallback assignments #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const addMarkers = require('./addMarkers')
const h = React.createElement

function Refractor(props) {
const className = props.className || 'refractor';
const inline = props.inline || false;

if (process.env.NODE_ENV !== 'production') {
if (!fract.registered(props.language)) {
// eslint-disable-next-line no-console
Expand All @@ -19,11 +22,11 @@ function Refractor(props) {

const langClassName = `language-${props.language}`
const codeProps = {className: langClassName}
const preProps = {className: [props.className, langClassName].filter(Boolean).join(' ')}
const preProps = {className: [className, langClassName].filter(Boolean).join(' ')}

if (props.inline) {
if (inline) {
codeProps.style = {display: 'inline'}
codeProps.className = props.className
codeProps.className = className
}

let ast = fract.highlight(props.value, props.language)
Expand All @@ -34,7 +37,7 @@ function Refractor(props) {
const value = ast.length === 0 ? props.value : ast.map(mapChildren.depth(0))

const code = h('code', codeProps, value)
return props.inline ? code : h('pre', preProps, code)
return inline ? code : h('pre', preProps, code)
}

Refractor.propTypes = {
Expand All @@ -54,11 +57,6 @@ Refractor.propTypes = {
),
}

Refractor.defaultProps = {
className: 'refractor',
inline: false,
}

Refractor.registerLanguage = (lang) => fract.register(lang)
Refractor.hasLanguage = (lang) => fract.registered(lang)

Expand Down