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

Switched JS to use default regex #86

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion example-project/src-client/auth/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
42 changes: 18 additions & 24 deletions src/server/code-parse/language/default/codecrumbs.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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 }]
}, []);
};

Expand All @@ -99,7 +94,6 @@ const setupGetCrumbs = getCommentsFromCode => (fileCode, path) => {
}
};

const DEFAULT_COMMENT_REGEX = /^([^\/\/]*)\/\/(.*)$/;
const getCrumbs = setupGetCrumbs(setupGetCommentsFromCode(DEFAULT_COMMENT_REGEX));

module.exports = {
Expand Down
7 changes: 6 additions & 1 deletion src/server/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down