Fix "TypeError: comments is not iterable" (#8701)

This commit is contained in:
Alican Çubukçuoğlu 2018-11-09 13:58:28 -08:00 committed by Daniel Tschinder
parent 4f206b2416
commit bf8c4785f2
2 changed files with 23 additions and 17 deletions

View File

@ -25,15 +25,19 @@ export default declare(api => {
skipStrip = false; skipStrip = false;
let directiveFound = false; let directiveFound = false;
for (const comment of (comments: Array<Object>)) { if (comments) {
if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) { for (const comment of (comments: Array<Object>)) {
directiveFound = true; if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) {
directiveFound = true;
// remove flow directive // remove flow directive
comment.value = comment.value.replace(FLOW_DIRECTIVE, ""); comment.value = comment.value.replace(FLOW_DIRECTIVE, "");
// remove the comment completely if it only consists of whitespace and/or stars // remove the comment completely if it only consists of whitespace and/or stars
if (!comment.value.replace(/\*/g, "").trim()) comment.ignore = true; if (!comment.value.replace(/\*/g, "").trim()) {
comment.ignore = true;
}
}
} }
} }

View File

@ -51,16 +51,18 @@ export default declare((api, options) => {
let pragmaSet = !!options.pragma; let pragmaSet = !!options.pragma;
let pragmaFragSet = !!options.pragmaFrag; let pragmaFragSet = !!options.pragmaFrag;
for (const comment of (file.ast.comments: Array<Object>)) { if (file.ast.comments) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value); for (const comment of (file.ast.comments: Array<Object>)) {
if (jsxMatches) { const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
pragma = jsxMatches[1]; if (jsxMatches) {
pragmaSet = true; pragma = jsxMatches[1];
} pragmaSet = true;
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value); }
if (jsxFragMatches) { const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
pragmaFrag = jsxFragMatches[1]; if (jsxFragMatches) {
pragmaFragSet = true; pragmaFrag = jsxFragMatches[1];
pragmaFragSet = true;
}
} }
} }