diff --git a/example-project/src-client/auth/actions.js b/example-project/src-client/auth/actions.js index 0bfee82e..97658b99 100644 --- a/example-project/src-client/auth/actions.js +++ b/example-project/src-client/auth/actions.js @@ -10,7 +10,9 @@ import { function authenticate(provider) { return dispatch => { - //cc:signin#1;firebase sign in;+1;call to firebase with auth provider, proceed if success response + /* + * cc:signin#1;firebase sign in;+1;call to firebase with auth provider, proceed if success response + */ firebaseAuth.signInWithPopup(provider) .then(result => dispatch(signInSuccess(result))) .catch(error => dispatch(signInError(error))); diff --git a/src/server/code-parse/language/default/codecrumbs.js b/src/server/code-parse/language/default/codecrumbs.js index 59da7cc0..9a2cc2e6 100644 --- a/src/server/code-parse/language/default/codecrumbs.js +++ b/src/server/code-parse/language/default/codecrumbs.js @@ -1,7 +1,8 @@ +const compact = require('lodash/compact'); const { CC_NODE_TYPE, NO_TRAIL_FLOW } = require('../../../shared-constants'); -const CRUMB = 'codecrumb', - CRUMB_SHORT_HANDLER = 'cc'; +const CRUMB_REGEX = /cc|codecrumb/; +const DEFAULT_COMMENT_REGEX = /\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm; const getCommentNodeValue = node => (node.value || '').trim(); @@ -38,12 +39,7 @@ const parseCodecrumbComment = (node = {}) => { return cc; }; -const isCodecrumb = node => { - if (!node) return false; - - const comment = getCommentNodeValue(node); - return comment.startsWith(CRUMB) || comment.startsWith(CRUMB_SHORT_HANDLER); -}; +const isCodecrumb = node => CRUMB_REGEX.test(getCommentNodeValue(node)); const buildCrumb = (params, crumbNodeLines, path) => ({ type: CC_NODE_TYPE, @@ -57,22 +53,21 @@ const buildCrumb = (params, crumbNodeLines, path) => ({ }); const setupGetCommentsFromCode = regex => fileCode => { - if (!fileCode) return []; - - return fileCode.split('\n').reduce((comments, item, i) => { - const codeLine = item.trim(); - if (!codeLine) return comments; - - const matches = regex.exec(codeLine); - if (matches) { - const lineNumber = i + 1; - return [ - ...comments, - { value: matches[matches.length - 1], nodeLines: [lineNumber, lineNumber] } - ]; - } + if (!fileCode) { + return []; + } + + const result = compact(regex.exec(fileCode)) || []; + + return result.reduce((comments, value) => { + value = value.trim() + const index = fileCode.indexOf(value); + const tempString = fileCode.substring(0, index); + const matchLineNumber = tempString.split('\n').length; - return comments; + const commentStringCount = value.split('\n').length + const nodeLines = [matchLineNumber, matchLineNumber + commentStringCount - 1]; + return [...comments, { value, nodeLines }] }, []); }; @@ -99,7 +94,6 @@ const setupGetCrumbs = getCommentsFromCode => (fileCode, path) => { } }; -const DEFAULT_COMMENT_REGEX = /^([^\/\/]*)\/\/(.*)$/; const getCrumbs = setupGetCrumbs(setupGetCommentsFromCode(DEFAULT_COMMENT_REGEX)); module.exports = { diff --git a/src/server/utils/logger.js b/src/server/utils/logger.js index f851da1b..d269ee55 100644 --- a/src/server/utils/logger.js +++ b/src/server/utils/logger.js @@ -5,7 +5,12 @@ const logAdapter = msg => console.log(msg); module.exports = { getText: e => { try { - return typeof e === 'object' ? JSON.stringify(e) : e; + if (typeof e === 'object') { + const stringifiedError = JSON.stringify(e); + return stringifiedError === '{}' ? e : stringifiedError; + } else { + return e; + } } catch (e) { return `COULD NOT PARSE ERROR ${e}`; }