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

Framework: Upgrade to Babel 6 #1515

Merged
merged 3 commits into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [
"es2015",
"stage-2"
],
"plugins": [
"transform-runtime",
"transform-class-properties",
"transform-export-extensions",
"add-module-exports",
"syntax-jsx",
"transform-react-jsx",
"transform-react-display-name"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function deserialize( shortcode ) {
const parsed = Shortcode.parse( shortcode );

if ( parsed ) {
return ( { attrs: { named: { to, subject } = {} } = {}, content } ) => {
return ( ( { attrs: { named: { to, subject } = {} } = {}, content } ) => {
let fields = [];
let parsedField;

Expand All @@ -60,7 +60,7 @@ export function deserialize( shortcode ) {
}

return pickBy( { to, subject, fields } );
}( parsed );
} )( parsed );
}

return {};
Expand Down
10 changes: 5 additions & 5 deletions client/components/tinymce/plugins/wpcom-view/gallery-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import GalleryShortcode from 'components/gallery-shortcode';
class GalleryView extends Component {

static match( content ) {
const match = shortcodeUtils.next( 'gallery', content );
const nextMatch = shortcodeUtils.next( 'gallery', content );

if ( match ) {
if ( nextMatch ) {
return {
index: match.index,
content: match.content,
index: nextMatch.index,
content: nextMatch.content,
options: {
shortcode: match.shortcode
shortcode: nextMatch.shortcode
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export default class EmbedViewManager extends EventEmitter {
}

const rxLink = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi;
let match;
while ( ( match = rxLink.exec( content ) ) ) {
const url = match[ 2 ];
let currentMatch;
while ( ( currentMatch = rxLink.exec( content ) ) ) {
const url = currentMatch[ 2 ];

// Disregard URL if it's not a supported embed pattern for the site
const isMatchingPattern = list.embeds.some( ( pattern ) => pattern.test( url ) );
Expand All @@ -118,7 +118,7 @@ export default class EmbedViewManager extends EventEmitter {
}

return {
index: match.index + match[ 1 ].length,
index: currentMatch.index + currentMatch[ 1 ].length,
content: url
};
}
Expand Down
6 changes: 3 additions & 3 deletions client/layout/guided-tours/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function get( site ) {
target: 'sidebar',
arrow: 'left-middle',
placement: 'beside',
next: ( () => {
next: ( ( () => {
if ( site && site.is_previewable ) {
return 'click-preview';
}
if ( site && site.is_customizable ) {
return 'themes';
}
return 'finish';
}() ),
} )() ),
},
'click-preview': {
target: 'site-card-preview',
Expand Down Expand Up @@ -84,7 +84,7 @@ function get( site ) {
return 'themes';
}
return 'finish';
}() ),
} )(),
},
themes: {
text: i18n.translate( "Change your {{strong}}Theme{{/strong}} to choose a new layout, or {{strong}}Customize{{/strong}} your theme's colors, fonts, and more.", {
Expand Down
24 changes: 18 additions & 6 deletions client/lib/upgrades/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export * from './cart';
export * from './checkout';
export * from './free-trials';
export * from './domain-management';
export * from './domain-search';
export * from './purchases';
// These could be rewritten as `export * from`, pending resolution of Babel
// transform bug: http://phabricator.babeljs.io/T2877

import * as cart from './cart';
import * as checkout from './checkout';
import * as freeTrials from './free-trials';
import * as domainManagement from './domain-management';
import * as domainSearch from './domain-search';
import * as purchases from './purchases';

export default {
...cart,
...checkout,
...freeTrials,
...domainManagement,
...domainSearch,
...purchases
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be included in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be included in this PR?

I'll look at this a bit more. It curently fails to compile with the following error with the original code:

ERROR in ./client/lib/upgrades/actions/index.js
Module parse failed: /Users/andrew/Documents/Code/wp-calypso/node_modules/react-hot-loader/index.js!/Users/andrew/Documents/Code/wp-calypso/node_modules/babel-loader/index.js?cacheDirectory!/Users/andrew/Documents/Code/wp-calypso/client/lib/upgrades/actions/index.js Line 5: Unexpected token
You may need an appropriate loader to handle this file type.
| 'use strict';
| 
| import _Object$defineProperty from 'babel-runtime/core-js/object/define-property';
| Object.defineProperty(exports, "__esModule", {
|   value: true
 @ ./client/my-sites/current-site/index.jsx 26:22-53

However, it's a bit puzzling, since the additional export supports are from a stage 1 proposal (source), so I'd expect them to be supported per our configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is a bug with Babel: http://phabricator.babeljs.io/T6888

4 changes: 2 additions & 2 deletions client/me/notification-settings/blogs-settings/blog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export default React.createClass( {
<Header
{ ...{ blog, settings, disableToggle } }
onToggle={ () => this.setState( { isExpanded: ! isExpanded } ) } />
{ () => {
{ ( () => {
if ( isExpanded || disableToggle ) {
return <SettingsForm
{ ...{ sourceId, devices, settings, hasUnsavedChanges, isApplyAllVisible: ! disableToggle, onToggle, onSave, onSaveToAll } }
settingKeys={ [ 'new_comment', 'comment_like', 'post_like', 'follow', 'achievement', 'mentions' ] } />;
}
}() }
} )() }
</Card>
);
}
Expand Down
4 changes: 2 additions & 2 deletions client/me/notification-settings/settings-form/settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default React.createClass( {
settingKeys={ this.props.settingKeys }
settings={ this.props.settings.get( streams.EMAIL ) }
onToggle={ this.props.onToggle } />
{ () => {
{ ( () => {
if ( this.props.devices && this.props.devices.initialized && this.props.devices.get().length > 0 ) {
return <Stream
key={ streams.DEVICES }
Expand All @@ -89,7 +89,7 @@ export default React.createClass( {
settings={ this.props.settings.get( streams.DEVICES ) }
onToggle={ this.props.onToggle } />
}
}() }
} )() }
<Stream
key={ 'selected-stream' }
className={ 'selected-stream' }
Expand Down
4 changes: 2 additions & 2 deletions client/me/notification-settings/settings-form/stream.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default React.createClass( {

return (
<div className={ classNames( 'notification-settings-form-stream', this.props.className ) }>
{ () => {
{ ( () => {
if ( this.props.devices ) {
return <DeviceSelector
devices={ this.props.devices }
Expand All @@ -66,7 +66,7 @@ export default React.createClass( {
}

return ( <StreamHeader stream={ this.props.stream } /> );
}() }
} )() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on these - were they breaking tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on these - were they breaking tests?

If I recall correctly, the code was failing to compile on the newer version of Babel.

<StreamOptions
blogId={ this.props.blogId }
stream={ stream }
Expand Down
2 changes: 1 addition & 1 deletion client/me/purchases/payment/edit-card-details/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const EditCardDetails = React.createClass( {
* @param card
* @param fields
*/
mergeCard( card, fields: {} ) {
mergeCard( card, fields = {} ) {
return assign( {}, fields, {
name: card.name
} );
Expand Down
4 changes: 2 additions & 2 deletions client/my-sites/site-settings/press-this-link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const pressThis = function( postURL ) {

class PressThisLink extends React.Component {

propTypes: {
static propTypes = {
site: PropTypes.object.isRequired,
}
};

/**
* Legacy press-this pointing to wp-admin. This will be
Expand Down