-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
chore(package): use Babel 7 #2750
Changes from 1 commit
13cd286
f8a01f0
4f40d21
e4c55a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import * as Babel from 'babel-standalone' | ||
import * as Babel from '@babel/standalone' | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React, { Component, createElement, isValidElement } from 'react' | ||
|
@@ -15,7 +15,7 @@ import ComponentControls from '../ComponentControls' | |
import ComponentExampleTitle from './ComponentExampleTitle' | ||
|
||
const babelConfig = { | ||
presets: ['es2015', 'react', 'stage-1'], | ||
presets: ['es2015', 'react', ['stage-1', { decoratorsLegacy: true }]], | ||
} | ||
|
||
const headerColumnStyle = { | ||
|
@@ -103,12 +103,16 @@ class ComponentExample extends Component { | |
copyToClipboard(location.href) | ||
} | ||
|
||
handleMouseMove = _.throttle(() => { | ||
const { controlsVisible } = this.state | ||
if (controlsVisible) return | ||
handleMouseMove = _.throttle( | ||
() => { | ||
const { controlsVisible } = this.state | ||
if (controlsVisible) return | ||
|
||
this.setState({ controlsVisible: true }) | ||
}, 200, { trailing: false }) | ||
this.setState({ controlsVisible: true }) | ||
}, | ||
200, | ||
{ trailing: false }, | ||
) | ||
|
||
handleMouseLeave = () => this.setState({ controlsVisible: false }) | ||
|
||
|
@@ -149,7 +153,8 @@ class ComponentExample extends Component { | |
resetJSX = () => { | ||
const { sourceCode } = this.state | ||
const original = this.getOriginalSourceCode() | ||
if (sourceCode !== original && confirm('Lose your changes?')) { // eslint-disable-line no-alert | ||
if (sourceCode !== original && confirm('Lose your changes?')) { | ||
// eslint-disable-line no-alert | ||
this.setState({ sourceCode: original }) | ||
this.renderSourceCode() | ||
} | ||
|
@@ -201,21 +206,23 @@ class ComponentExample extends Component { | |
|
||
// rewrite imports to const statements against the UPPERCASE module names | ||
const imports = _.get(/(^[\s\S])*import[\s\S]*from[\s\S]*['"]\n/.exec(sourceCode), '[0]', '') | ||
.replace(/[\s\n]+/g, ' ') // normalize spaces and make one line | ||
.replace(/ import/g, '\nimport') // one import per line | ||
.split('\n') // split lines | ||
.filter(Boolean) // remove empty lines | ||
.map((l) => { // rewrite imports to const statements | ||
const [ | ||
defaultImport, | ||
destructuredImports, | ||
_module, | ||
] = _.tail(/import\s+([\w]+)?(?:\s*,\s*)?({[\s\w,]+})?\s+from\s+['"](?:.*\/)?([\w\-_]+)['"]/.exec(l)) | ||
.replace(/[\s\n]+/g, ' ') // normalize spaces and make one line | ||
.replace(/ import/g, '\nimport') // one import per line | ||
.split('\n') // split lines | ||
.filter(Boolean) // remove empty lines | ||
.map((l) => { | ||
// rewrite imports to const statements | ||
const [defaultImport, destructuredImports, _module] = _.tail( | ||
/import\s+([\w]+)?(?:\s*,\s*)?({[\s\w,]+})?\s+from\s+['"](?:.*\/)?([\w\-_]+)['"]/.exec(l), | ||
) | ||
|
||
const module = _.snakeCase(_module).toUpperCase() | ||
|
||
if (module === 'COMMON') { | ||
const componentPath = examplePath.split(__PATH_SEP__).splice(0, 2).join(__PATH_SEP__) | ||
const componentPath = examplePath | ||
.split(__PATH_SEP__) | ||
.splice(0, 2) | ||
.join(__PATH_SEP__) | ||
COMMON = require(`docs/app/Examples/${componentPath}/common`) | ||
} else if (module === 'WIREFRAME') { | ||
WIREFRAME = require('docs/app/Examples/behaviors/Visibility/Wireframe').default | ||
|
@@ -234,8 +241,8 @@ class ComponentExample extends Component { | |
const defaultExport = _.get(/export\s+default\s+(?:class|function)?(?:\s+)?(\w+)/.exec(sourceCode), '[1]') | ||
|
||
const body = _.get(/(export\sdefault\sclass|const|class\s\S*\sextends)[\s\S]*/.exec(sourceCode), '[0]', '') | ||
.replace(/export\s+default\s+(?!class|function)\w+([\s\n]+)?/, '') // remove `export default Foo` statements | ||
.replace(/export\s+default\s+/, '') // remove `export default ...` | ||
.replace(/export\s+default\s+(?!class|function)\w+([\s\n]+)?/, '') // remove `export default Foo` statements | ||
.replace(/export\s+default\s+/, '') // remove `export default ...` | ||
|
||
const IIFE = `(function() {\n${imports}${body}return ${defaultExport}\n}())` | ||
|
||
|
@@ -285,24 +292,27 @@ class ComponentExample extends Component { | |
|
||
this.ghBugHref = [ | ||
`${repoURL}/issues/new?`, | ||
_.map({ | ||
title: `fix(${componentName}): your description`, | ||
body: [ | ||
'**Steps to Reproduce**', | ||
'1. Do something', | ||
'2. Do something else.', | ||
'', | ||
'**Expected**', | ||
`The ${componentName} should do this`, | ||
'', | ||
'**Result**', | ||
`The ${componentName} does not do this`, | ||
'', | ||
'**Testcase**', | ||
`If the docs show the issue, use: ${location.href}`, | ||
'Otherwise, fork this to get started: http://codepen.io/levithomason/pen/ZpBaJX', | ||
].join('\n'), | ||
}, (val, key) => `${key}=${encodeURIComponent(val)}`).join('&'), | ||
_.map( | ||
{ | ||
title: `fix(${componentName}): your description`, | ||
body: [ | ||
'**Steps to Reproduce**', | ||
'1. Do something', | ||
'2. Do something else.', | ||
'', | ||
'**Expected**', | ||
`The ${componentName} should do this`, | ||
'', | ||
'**Result**', | ||
`The ${componentName} does not do this`, | ||
'', | ||
'**Testcase**', | ||
`If the docs show the issue, use: ${location.href}`, | ||
'Otherwise, fork this to get started: http://codepen.io/levithomason/pen/ZpBaJX', | ||
].join('\n'), | ||
}, | ||
(val, key) => `${key}=${encodeURIComponent(val)}`, | ||
).join('&'), | ||
].join('') | ||
} | ||
|
||
|
@@ -362,14 +372,8 @@ class ComponentExample extends Component { | |
return ( | ||
<div style={style}> | ||
{this.renderJSXControls()} | ||
<Editor | ||
id={`${this.getKebabExamplePath()}-jsx`} | ||
value={sourceCode} | ||
onChange={this.handleChangeCode} | ||
/> | ||
{error && ( | ||
<pre style={errorStyle}>{error}</pre> | ||
)} | ||
<Editor id={`${this.getKebabExamplePath()}-jsx`} value={sourceCode} onChange={this.handleChangeCode} /> | ||
{error && <pre style={errorStyle}>{error}</pre>} | ||
</div> | ||
) | ||
} | ||
|
@@ -380,8 +384,7 @@ class ComponentExample extends Component { | |
|
||
// add new lines between almost all adjacent elements | ||
// moves inline elements to their own line | ||
const preFormattedHTML = markup | ||
.replace(/><(?!\/i|\/label|\/span|option)/g, '>\n<') | ||
const preFormattedHTML = markup.replace(/><(?!\/i|\/label|\/span|option)/g, '>\n<') | ||
|
||
const beautifiedHTML = html(preFormattedHTML, { | ||
indent_size: 2, | ||
|
@@ -409,11 +412,7 @@ class ComponentExample extends Component { | |
} | ||
|
||
return ( | ||
<Visibility | ||
once={false} | ||
onTopPassed={this.handlePass} | ||
onTopPassedReverse={this.handlePass} | ||
> | ||
<Visibility once={false} onTopPassed={this.handlePass} onTopPassedReverse={this.handlePass}> | ||
<Grid | ||
className='docs-example' | ||
id={this.anchorName} | ||
|
@@ -423,11 +422,7 @@ class ComponentExample extends Component { | |
> | ||
<Grid.Row> | ||
<Grid.Column style={headerColumnStyle} width={12}> | ||
<ComponentExampleTitle | ||
description={description} | ||
title={title} | ||
suiVersion={suiVersion} | ||
/> | ||
<ComponentExampleTitle description={description} title={title} suiVersion={suiVersion} /> | ||
</Grid.Column> | ||
<Grid.Column textAlign='right' width={4}> | ||
<ComponentControls | ||
|
@@ -442,18 +437,10 @@ class ComponentExample extends Component { | |
</Grid.Column> | ||
</Grid.Row> | ||
|
||
<Grid.Row columns={1}> | ||
{children && ( | ||
<Grid.Column style={childrenStyle}> | ||
{children} | ||
</Grid.Column> | ||
)} | ||
</Grid.Row> | ||
<Grid.Row columns={1}>{children && <Grid.Column style={childrenStyle}>{children}</Grid.Column>}</Grid.Row> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should shorten our line length. This is quite hard to read. <Grid.Row columns={1}>{children && <Grid.Column style={childrenStyle}>{children}</Grid.Column>}</Grid.Row> This line is 118 columns, maybe go with 100 columns? <Grid.Row columns={1}>
{children && <Grid.Column style={childrenStyle}>{children}</Grid.Column>}
</Grid.Row> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
|
||
<Grid.Row columns={1}> | ||
<Grid.Column className={`rendered-example ${this.getKebabExamplePath()}`}> | ||
{exampleElement} | ||
</Grid.Column> | ||
<Grid.Column className={`rendered-example ${this.getKebabExamplePath()}`}>{exampleElement}</Grid.Column> | ||
<Grid.Column> | ||
{this.renderJSX()} | ||
{this.renderHTML()} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
babel-preset-env
in the browser too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 😄