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 "TypeError: comments is not iterable" #8701

Merged
merged 1 commit into from Nov 9, 2018
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
22 changes: 13 additions & 9 deletions packages/babel-plugin-transform-flow-strip-types/src/index.js
Expand Up @@ -25,15 +25,19 @@ export default declare(api => {
skipStrip = false;
let directiveFound = false;

for (const comment of (comments: Array<Object>)) {
if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) {
directiveFound = true;

// remove flow directive
comment.value = comment.value.replace(FLOW_DIRECTIVE, "");

// remove the comment completely if it only consists of whitespace and/or stars
if (!comment.value.replace(/\*/g, "").trim()) comment.ignore = true;
if (comments) {
for (const comment of (comments: Array<Object>)) {
if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) {
directiveFound = true;

// remove flow directive
comment.value = comment.value.replace(FLOW_DIRECTIVE, "");

// remove the comment completely if it only consists of whitespace and/or stars
if (!comment.value.replace(/\*/g, "").trim()) {
comment.ignore = true;
}
}
}
}

Expand Down
22 changes: 12 additions & 10 deletions packages/babel-plugin-transform-react-jsx/src/index.js
Expand Up @@ -51,16 +51,18 @@ export default declare((api, options) => {
let pragmaSet = !!options.pragma;
let pragmaFragSet = !!options.pragmaFrag;

for (const comment of (file.ast.comments: Array<Object>)) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (jsxMatches) {
pragma = jsxMatches[1];
pragmaSet = true;
}
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
if (jsxFragMatches) {
pragmaFrag = jsxFragMatches[1];
pragmaFragSet = true;
if (file.ast.comments) {
for (const comment of (file.ast.comments: Array<Object>)) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (jsxMatches) {
pragma = jsxMatches[1];
pragmaSet = true;
}
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
if (jsxFragMatches) {
pragmaFrag = jsxFragMatches[1];
pragmaFragSet = true;
}
}
}

Expand Down