diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index 294ff7be1a3d..ed34e32462ef 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -25,15 +25,19 @@ export default declare(api => { skipStrip = false; let directiveFound = false; - for (const comment of (comments: Array)) { - 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)) { + 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; + } + } } } diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 5ae4f11e7116..75de3179168c 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -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)) { - 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)) { + 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; + } } }