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

Fix extraneous semicolon #168

Merged
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
23 changes: 17 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,23 @@ export default function(api) {
`,
{ placeholderPattern: /^NODE$/ }
),
wrapTemplate: template(
`
LEFT = process.env.NODE_ENV !== "production" ? RIGHT : {}
`,
{ placeholderPattern: /^(LEFT|RIGHT)$/ }
),
wrapTemplate: ({ LEFT, RIGHT }, options = {}) => {
const { as = 'assignmentExpression' } = options
const right = template.expression(
`
process.env.NODE_ENV !== "production" ? RIGHT : {}
`,
{ placeholderPattern: /^(LEFT|RIGHT)$/ }
)({ RIGHT })
switch (as) {
case 'variableDeclarator':
return types.variableDeclarator(LEFT, right)
case 'assignmentExpression':
return types.assignmentExpression('=', LEFT, right)
default:
throw new Error(`unrecognized template type ${as}`)
}
},
mode: state.opts.mode || 'remove',
ignoreFilenames,
types,
Expand Down
11 changes: 7 additions & 4 deletions src/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ export default function remove(path, globalOptions, options) {
)
} else {
path.replaceWith(
wrapTemplate({
LEFT: path.node.id,
RIGHT: path.node.init,
})
wrapTemplate(
{
LEFT: path.node.id,
RIGHT: path.node.init,
},
{ as: 'variableDeclarator' }
)
)
}
path.node[visitedKey] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var referencedPropTypes = process.env.NODE_ENV !== "production" ? {
var willBeWrapped = 1;
return null;
}
} : {};;
} : {};
Component.propTypes = process.env.NODE_ENV !== "production" ? babelHelpers.objectSpread({
variant1: function variant1(props) {
var variants = [null];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const referencedPropTypes = process.env.NODE_ENV !== "production" ? {
const willBeWrapped = 1;
return null;
}
} : {};;
} : {};
Component.propTypes = process.env.NODE_ENV !== "production" ? babelHelpers.objectSpread({
variant1: props => {
const variants = [null];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var propTypes = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

var Foo =
/*#__PURE__*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const propTypes = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

class Foo extends React.Component {
render() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var shapePropType = process.env.NODE_ENV !== "production" ? PropTypes.shape({
foo: PropTypes.string
}) : {};;
}) : {};

var ComponentA = function ComponentA() {
return React.createElement("div", null);
Expand All @@ -14,7 +14,7 @@ ComponentA.propTypes = process.env.NODE_ENV !== "production" ? {
var somePropTypes = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

var ComponentB = function ComponentB() {
return React.createElement("div", null);
Expand All @@ -26,7 +26,7 @@ ComponentB.propTypes = process.env.NODE_ENV !== "production" ? {
var somePropTypesC = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

var ComponentC = function ComponentC() {
return React.createElement("div", null);
Expand All @@ -38,7 +38,7 @@ ComponentC.propTypes = process.env.NODE_ENV !== "production" ? {
var somePropTypesD = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

var ComponentD = function ComponentD() {
return React.createElement("div", null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const shapePropType = process.env.NODE_ENV !== "production" ? PropTypes.shape({
foo: PropTypes.string
}) : {};;
}) : {};

const ComponentA = () => <div />;

Expand All @@ -10,7 +10,7 @@ ComponentA.propTypes = process.env.NODE_ENV !== "production" ? {
const somePropTypes = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

const ComponentB = () => <div />;

Expand All @@ -20,7 +20,7 @@ ComponentB.propTypes = process.env.NODE_ENV !== "production" ? {
const somePropTypesC = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

const ComponentC = () => <div />;

Expand All @@ -30,7 +30,7 @@ ComponentC.propTypes = process.env.NODE_ENV !== "production" ? {
const somePropTypesD = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string,
bar: PropTypes.number
} : {};;
} : {};

const ComponentD = () => <div />;

Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/variable-assignment/expected-wrap-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.propTypesExported = void 0;
var propTypesBasic = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

var FooBasic = function FooBasic() {
return React.createElement("div", null);
Expand All @@ -15,10 +15,10 @@ var FooBasic = function FooBasic() {
FooBasic.propTypes = process.env.NODE_ENV !== "production" ? propTypesBasic : {};
var extraReference = process.env.NODE_ENV !== "production" ? {
bar: PropTypes.string
} : {};;
} : {};
var propTypesWithExtraReference = process.env.NODE_ENV !== "production" ? Object.assign({}, extraReference, {
foo: PropTypes.string
}) : {};;
}) : {};

var FooExtraReference = function FooExtraReference() {
return React.createElement("div", null);
Expand All @@ -29,7 +29,7 @@ var propTypesWithExtraReferenceSpread = process.env.NODE_ENV !== "production" ?
foo: PropTypes.string
}, {
bar: PropTypes.string
}) : {};;
}) : {};

var FooExtraReferenceSpread = function FooExtraReferenceSpread() {
return React.createElement("div", null);
Expand All @@ -38,7 +38,7 @@ var FooExtraReferenceSpread = function FooExtraReferenceSpread() {
FooExtraReferenceSpread.propTypes = process.env.NODE_ENV !== "production" ? propTypesWithExtraReferenceSpread : {};
var propTypesWrapped = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

var FooWrapped = function FooWrapped() {
return React.createElement("div", null);
Expand Down Expand Up @@ -68,7 +68,7 @@ var FooExported = function FooExported() {
FooExported.propTypes = process.env.NODE_ENV !== "production" ? propTypesExported : {};
var propTypesCreateClass = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};
var FooCreateClass = createReactClass({
displayName: "FooCreateClass",
propTypes: propTypesCreateClass
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/variable-assignment/expected-wrap-es6.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const propTypesBasic = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

const FooBasic = () => <div />;

FooBasic.propTypes = process.env.NODE_ENV !== "production" ? propTypesBasic : {};
const extraReference = process.env.NODE_ENV !== "production" ? {
bar: PropTypes.string
} : {};;
} : {};
const propTypesWithExtraReference = process.env.NODE_ENV !== "production" ? Object.assign({}, extraReference, {
foo: PropTypes.string
}) : {};;
}) : {};

const FooExtraReference = () => <div />;

Expand All @@ -19,14 +19,14 @@ const propTypesWithExtraReferenceSpread = process.env.NODE_ENV !== "production"
foo: PropTypes.string
}, {
bar: PropTypes.string
}) : {};;
}) : {};

const FooExtraReferenceSpread = () => <div />;

FooExtraReferenceSpread.propTypes = process.env.NODE_ENV !== "production" ? propTypesWithExtraReferenceSpread : {};
const propTypesWrapped = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};

const FooWrapped = () => <div />;

Expand All @@ -47,7 +47,7 @@ const FooExported = () => <div />;
FooExported.propTypes = process.env.NODE_ENV !== "production" ? propTypesExported : {};
const propTypesCreateClass = process.env.NODE_ENV !== "production" ? {
foo: PropTypes.string
} : {};;
} : {};
const FooCreateClass = createReactClass({
propTypes: propTypesCreateClass
});