Skip to content

Commit

Permalink
Work around for some flow type issues when types are not removed first
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jul 13, 2018
1 parent b8a9039 commit a811f87
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/__fixtures__/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type Props = {
id?: string
};

export type ViewState = {
view: State,
model: StageModelState
};

class StageView extends AbstractStageView<AbstractProps & AbstractProps> {
state: ViewState;
}
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/target-browser-dev.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Target: Browser: Dev flow 1`] = `"class StageView extends AbstractStageView {}"`;

exports[`Target: Browser: Dev loadable 1`] = `
"import loadable from 'loadable-components';
export const Home = loadable(() => import(
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/target-browser-prod.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ exports[`Target: Browser: Prod esnext: object spread 1`] = `"import\\"core-js/mo

exports[`Target: Browser: Prod esnext: optional_chaining 1`] = `"var _obj$foo,_obj$foo$bar,obj={foo:{bar:{baz:42}}},baz=null==obj||null==(_obj$foo=obj.foo)||null==(_obj$foo$bar=_obj$foo.bar)?void 0:_obj$foo$bar.baz;"`;

exports[`Target: Browser: Prod flow 1`] = `"import _inheritsLoose from\\"@babel/runtime/helpers/builtin/es6/inheritsLoose\\";var StageView=/*#__PURE__*/function(a){function b(){return a.apply(this,arguments)||this}return _inheritsLoose(b,a),b}(AbstractStageView);"`;

exports[`Target: Browser: Prod loadable 1`] = `"import loadable from\\"loadable-components\\";export var Home=loadable(function(){return import(/*webpackChunkName:'Home-JfPYC'*/\\"./views/Home\\")},{modules:[\\"./views/Home\\"]});export var About=loadable(function(){return import(/*webpackChunkName:'About-8yDxR'*/\\"./views/About\\")},{modules:[\\"./views/About\\"]});export var Contact=loadable(function(){return import(/*webpackChunkName:'Contact-AIf6m'*/\\"./views/Contact\\")},{modules:[\\"./views/Contact\\"]});"`;

exports[`Target: Browser: Prod loadable magic-comments 1`] = `"import loadable from\\"loadable-components\\";export var Home=loadable(function(){return import(/*webpackChunkName:'Home-JfPYC'*/\\"./views/Home\\")},{modules:[\\"./views/Home\\"]});export var About=loadable(function(){return import(/* webpackChunkName: \\"About\\" */\\"./views/About\\")},{modules:[\\"./views/About\\"]});export var Contact=loadable(function(){return import(/*webpackMode:'lazy',webpackFoo:'bar',webpackChunkName:'Contact-AIf6m'*/\\"./views/Contact\\")},{modules:[\\"./views/Contact\\"]});"`;
Expand Down
6 changes: 6 additions & 0 deletions __tests__/__snapshots__/target-node.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Target: NodeJS flow 1`] = `
"\\"use strict\\";
class StageView extends AbstractStageView {}"
`;

exports[`Target: NodeJS loadable 1`] = `
"\\"use strict\\";
Expand Down
16 changes: 16 additions & 0 deletions __tests__/__snapshots__/target-universal-node.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ exports[`Target: Universal: Node Imports esnext: optional_chaining 1`] = `
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Target: Universal: Node Imports flow 1`] = `
"import _inheritsLoose from \\"@babel/runtime/helpers/builtin/es6/inheritsLoose\\";
var StageView =
/*#__PURE__*/
function (_AbstractStageView) {
_inheritsLoose(StageView, _AbstractStageView);
function StageView() {
return _AbstractStageView.apply(this, arguments) || this;
}
return StageView;
}(AbstractStageView);"
`;

exports[`Target: Universal: Node Imports loadable 1`] = `
"import \\"core-js/modules/es6.promise\\";
import _interopRequireWildcard from \\"@babel/runtime/helpers/builtin/es6/interopRequireWildcard\\";
Expand Down
16 changes: 16 additions & 0 deletions __tests__/__snapshots__/target-universal.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ exports[`Target: Universal esnext: optional_chaining 1`] = `
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Target: Universal flow 1`] = `
"import _inheritsLoose from \\"@babel/runtime/helpers/builtin/es6/inheritsLoose\\";
var StageView =
/*#__PURE__*/
function (_AbstractStageView) {
_inheritsLoose(StageView, _AbstractStageView);
function StageView() {
return _AbstractStageView.apply(this, arguments) || this;
}
return StageView;
}(AbstractStageView);"
`;

exports[`Target: Universal loadable 1`] = `
"import loadable from 'loadable-components';
export var Home = loadable(function () {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/transpile-es2015.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Transpile: ES2015 flow 1`] = `"class StageView extends AbstractStageView {}"`;

exports[`Transpile: ES2015 loadable 1`] = `
"import loadable from 'loadable-components';
export const Home = loadable(() => import(
Expand Down
16 changes: 16 additions & 0 deletions __tests__/__snapshots__/transpile-es5.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ exports[`Transpile: ES5 esnext: optional_chaining 1`] = `
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Transpile: ES5 flow 1`] = `
"import _inheritsLoose from \\"@babel/runtime/helpers/builtin/es6/inheritsLoose\\";
var StageView =
/*#__PURE__*/
function (_AbstractStageView) {
_inheritsLoose(StageView, _AbstractStageView);
function StageView() {
return _AbstractStageView.apply(this, arguments) || this;
}
return StageView;
}(AbstractStageView);"
`;

exports[`Transpile: ES5 loadable 1`] = `
"import loadable from 'loadable-components';
export var Home = loadable(function () {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/transpile-esm.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Transpile: ESM flow 1`] = `"class StageView extends AbstractStageView {}"`;

exports[`Transpile: ESM loadable 1`] = `
"import loadable from 'loadable-components';
export const Home = loadable(() => import(
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/transpile-modern.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Transpile: Modern flow 1`] = `"class StageView extends AbstractStageView {}"`;

exports[`Transpile: Modern loadable 1`] = `
"import loadable from 'loadable-components';
export const Home = loadable(() => import(
Expand Down
6 changes: 6 additions & 0 deletions __tests__/__snapshots__/transpile-node8.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ const obj = {
baz = (_obj$foo = obj.foo) == null ? void 0 : (_obj$foo$bar = _obj$foo.bar) == null ? void 0 : _obj$foo$bar.baz;"
`;

exports[`Transpile: NodeJS v8 flow 1`] = `
"\\"use strict\\";
class StageView extends AbstractStageView {}"
`;

exports[`Transpile: NodeJS v8 loadable 1`] = `
"\\"use strict\\";
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable filenames/match-exported, no-console, complexity */
import flowStrip from "@babel/plugin-transform-flow-strip-types"

import asyncPart from "./parts/async"
import compressionPart from "./parts/compression"

Expand Down Expand Up @@ -38,6 +40,11 @@ export default function buildPreset(context, input) {
reactPart(presets, plugins, options)
envPart(presets, plugins, options)

// We need to make sure that stripping flow types is executed
// before some other specific plugins as the runtime of the code
// otherwise sometimes does not work correctly.
plugins.unshift(flowStrip)

// Assemble final config
return {
// Babel basic configuration
Expand Down

0 comments on commit a811f87

Please sign in to comment.