code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function _nodeIsClosureScopeBoundary(node, parentNode) {
if (node.type === Syntax.Program) {
return true;
}
var parentIsFunction =
parentNode.type === Syntax.FunctionDeclaration
|| parentNode.type === Syntax.FunctionExpression
|| parentNode.type === Syntax.ArrowFunctionExpression;
var parentIs... | @param {object} node
@param {object} parentNode
@return {boolean} | _nodeIsClosureScopeBoundary | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _nodeIsBlockScopeBoundary(node, parentNode) {
if (node.type === Syntax.Program) {
return false;
}
return node.type === Syntax.BlockStatement
&& parentNode.type === Syntax.CatchClause;
} | @param {object} node
@param {object} parentNode
@return {boolean} | _nodeIsBlockScopeBoundary | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function traverse(node, path, state) {
/*jshint -W004*/
// Create a scope stack entry if this is the first node we've encountered in
// its local scope
var startIndex = null;
var parentNode = path[0];
if (!Array.isArray(node) && state.localScope.parentNode !== parentNode) {
if (_nodeIsClosureScopeBounda... | @param {object} node
@param {array} path
@param {object} state | traverse | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function traverser(node, path, state) {
node.range && utils.catchup(node.range[0], state);
traverse(node, path, state);
node.range && utils.catchup(node.range[1], state);
} | @param {object} node
@param {array} path
@param {object} state | traverser | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function collectClosureIdentsAndTraverse(node, path, state) {
utils.analyzeAndTraverse(
visitLocalClosureIdentifiers,
collectClosureIdentsAndTraverse,
node,
path,
state
);
} | @param {object} node
@param {array} path
@param {object} state | collectClosureIdentsAndTraverse | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function collectBlockIdentsAndTraverse(node, path, state) {
utils.analyzeAndTraverse(
visitLocalBlockIdentifiers,
collectBlockIdentsAndTraverse,
node,
path,
state
);
} | @param {object} node
@param {array} path
@param {object} state | collectBlockIdentsAndTraverse | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitLocalClosureIdentifiers(node, path, state) {
var metaData;
switch (node.type) {
case Syntax.ArrowFunctionExpression:
case Syntax.FunctionExpression:
// Function expressions don't get their names (if there is one) added to
// the closure scope they're defined in
return false;
... | @param {object} node
@param {array} path
@param {object} state | visitLocalClosureIdentifiers | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitLocalBlockIdentifiers(node, path, state) {
// TODO: Support 'let' here...maybe...one day...or something...
if (node.type === Syntax.CatchClause) {
return false;
}
} | @param {object} node
@param {array} path
@param {object} state | visitLocalBlockIdentifiers | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function walker(node, path, state) {
var visitors = state.g.visitors;
for (var i = 0; i < visitors.length; i++) {
if (visitors[i].test(node, path, state)) {
return visitors[i](traverse, node, path, state);
}
}
} | @param {object} node
@param {array} path
@param {object} state | walker | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getAstForSource(source, options) {
if (_astCache[source] && !options.disableAstCache) {
return _astCache[source];
}
var ast = esprima.parse(source, {
comment: true,
loc: true,
range: true,
sourceType: options.sourceType
});
if (!options.disableAstCache) {
_astCache[source] = a... | @param {object} node
@param {array} path
@param {object} state | getAstForSource | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function transform(visitors, source, options) {
options = options || {};
var ast;
try {
ast = getAstForSource(source, options);
} catch (e) {
e.message = 'Parse Error: ' + e.message;
throw e;
}
var state = utils.createState(source, ast, options);
state.g.visitors = visitors;
if (options.s... | Applies all available transformations to the source
@param {array} visitors
@param {string} source
@param {?object} options
@return {object} | transform | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function createState(source, rootNode, transformOptions) {
return {
/**
* A tree representing the current local scope (and its lexical scope chain)
* Useful for tracking identifiers from parent scopes, etc.
* @type {Object}
*/
localScope: {
parentNode: rootNode,
parentScope: nu... | A `state` object represents the state of the parser. It has "local" and
"global" parts. Global contains parser position, source, etc. Local contains
scope based properties like current class name. State should contain all the
info required for transformation. It's the only mandatory object that is
being passed to every... | createState | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function updateState(state, update) {
var ret = Object.create(state);
Object.keys(update).forEach(function(updatedKey) {
ret[updatedKey] = update[updatedKey];
});
return ret;
} | Updates a copy of a given state with "update" and returns an updated state.
@param {object} state
@param {object} update
@return {object} | updateState | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function catchup(end, state, contentTransformer) {
if (end < state.g.position) {
// cannot move backwards
return;
}
var source = state.g.source.substring(state.g.position, end);
var transformed = updateIndent(source, state);
if (state.g.sourceMap && transformed) {
// record where we are
state.... | Given a state fill the resulting buffer from the original source up to
the end
@param {number} end
@param {object} state
@param {?function} contentTransformer Optional callback to transform newly
added content. | catchup | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getNodeSourceText(node, state) {
return state.g.source.substring(node.range[0], node.range[1]);
} | Returns original source for an AST node.
@param {object} node
@param {object} state
@return {string} | getNodeSourceText | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _replaceNonWhite(value) {
return value.replace(nonWhiteRegexp, ' ');
} | Returns original source for an AST node.
@param {object} node
@param {object} state
@return {string} | _replaceNonWhite | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getNextSyntacticCharOffset(char, state) {
var pendingSource = state.g.source.substring(state.g.position);
var pendingSourceLines = pendingSource.split('\n');
var charOffset = 0;
var line;
var withinBlockComment = false;
var withinString = false;
lineLoop: while ((line = pendingSourceLines.shift(... | Finds the position of the next instance of the specified syntactic char in
the pending source.
NOTE: This will skip instances of the specified char if they sit inside a
comment body.
NOTE: This function also assumes that the buffer's current position is not
already within a comment or a string. This is ra... | getNextSyntacticCharOffset | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function catchupWhiteOut(end, state) {
catchup(end, state, _replaceNonWhite);
} | Catches up as `catchup` but replaces non-whitespace chars with spaces. | catchupWhiteOut | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function catchupWhiteSpace(end, state) {
catchup(end, state, _stripNonWhite);
} | Catches up as `catchup` but removes all non-whitespace characters. | catchupWhiteSpace | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function catchupNewlines(end, state) {
catchup(end, state, stripNonNewline);
} | Catches up as `catchup` but removes all non-newline characters.
Equivalent to appending as many newlines as there are in the original source
between the current position and `end`. | catchupNewlines | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function move(end, state) {
// move the internal cursors
if (state.g.sourceMap) {
if (end < state.g.position) {
state.g.position = 0;
state.g.sourceLine = 1;
state.g.sourceColumn = 0;
}
var source = state.g.source.substring(state.g.position, end);
var sourceLines = source.split('\... | Same as catchup but does not touch the buffer
@param {number} end
@param {object} state | move | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function append(str, state) {
if (state.g.sourceMap && str) {
state.g.sourceMap.addMapping({
generated: { line: state.g.bufferLine, column: state.g.bufferColumn },
original: { line: state.g.sourceLine, column: state.g.sourceColumn },
source: state.g.sourceMapFilename
});
var transformedL... | Appends a string of text to the buffer
@param {string} str
@param {object} state | append | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function updateIndent(str, state) {
/*jshint -W004*/
var indentBy = state.indentBy;
if (indentBy < 0) {
for (var i = 0; i < -indentBy; i++) {
str = str.replace(leadingIndentRegexp, '$1');
}
} else {
for (var i = 0; i < indentBy; i++) {
str = str.replace(leadingIndentRegexp, '$1$2$2');
... | Update indent using state.indentBy property. Indent is measured in
double spaces. Updates a single line only.
@param {string} str
@param {object} state
@return {string} | updateIndent | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function indentBefore(start, state) {
var end = start;
start = start - 1;
while (start > 0 && state.g.source[start] != '\n') {
if (!state.g.source[start].match(/[ \t]/)) {
end = start;
}
start--;
}
return state.g.source.substring(start + 1, end);
} | Calculates indent from the beginning of the line until "start" or the first
character before start.
@example
" foo.bar()"
^
start
indent will be " "
@param {number} start
@param {object} state
@return {string} | indentBefore | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getDocblock(state) {
if (!state.g.docblock) {
var docblock = _dereq_('./docblock');
state.g.docblock =
docblock.parseAsObject(docblock.extract(state.g.source));
}
return state.g.docblock;
} | Calculates indent from the beginning of the line until "start" or the first
character before start.
@example
" foo.bar()"
^
start
indent will be " "
@param {number} start
@param {object} state
@return {string} | getDocblock | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function identWithinLexicalScope(identName, state, stopBeforeNode) {
var currScope = state.localScope;
while (currScope) {
if (currScope.identifiers[identName] !== undefined) {
return true;
}
if (stopBeforeNode && currScope.parentNode === stopBeforeNode) {
break;
}
currScope = curr... | Calculates indent from the beginning of the line until "start" or the first
character before start.
@example
" foo.bar()"
^
start
indent will be " "
@param {number} start
@param {object} state
@return {string} | identWithinLexicalScope | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function identInLocalScope(identName, state) {
return state.localScope.identifiers[identName] !== undefined;
} | Calculates indent from the beginning of the line until "start" or the first
character before start.
@example
" foo.bar()"
^
start
indent will be " "
@param {number} start
@param {object} state
@return {string} | identInLocalScope | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function initScopeMetadata(boundaryNode, path, node) {
return {
boundaryNode: boundaryNode,
bindingPath: path,
bindingNode: node
};
} | @param {object} boundaryNode
@param {?array} path
@return {?object} node | initScopeMetadata | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function declareIdentInLocalScope(identName, metaData, state) {
state.localScope.identifiers[identName] = {
boundaryNode: metaData.boundaryNode,
path: metaData.bindingPath,
node: metaData.bindingNode,
state: Object.create(state)
};
} | @param {object} boundaryNode
@param {?array} path
@return {?object} node | declareIdentInLocalScope | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getLexicalBindingMetadata(identName, state) {
var currScope = state.localScope;
while (currScope) {
if (currScope.identifiers[identName] !== undefined) {
return currScope.identifiers[identName];
}
currScope = currScope.parentScope;
}
} | @param {object} boundaryNode
@param {?array} path
@return {?object} node | getLexicalBindingMetadata | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getLocalBindingMetadata(identName, state) {
return state.localScope.identifiers[identName];
} | @param {object} boundaryNode
@param {?array} path
@return {?object} node | getLocalBindingMetadata | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function analyzeAndTraverse(analyzer, traverser, node, path, state) {
if (node.type) {
if (analyzer(node, path, state) === false) {
return;
}
path.unshift(node);
}
getOrderedChildren(node).forEach(function(child) {
traverser(child, path, state);
});
node.type && path.shift();
} | Apply the given analyzer function to the current node. If the analyzer
doesn't return false, traverse each child of the current node using the given
traverser function.
@param {function} analyzer
@param {function} traverser
@param {object} node
@param {array} path
@param {object} state | analyzeAndTraverse | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getOrderedChildren(node) {
var queue = [];
for (var key in node) {
if (node.hasOwnProperty(key)) {
enqueueNodeWithStartIndex(queue, node[key]);
}
}
queue.sort(function(a, b) { return a[1] - b[1]; });
return queue.map(function(pair) { return pair[0]; });
} | It is crucial that we traverse in order, or else catchup() on a later
node that is processed out of order can move the buffer past a node
that we haven't handled yet, preventing us from modifying that node.
This can happen when a node has multiple properties containing children.
For example, XJSElement nodes have `ope... | getOrderedChildren | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function enqueueNodeWithStartIndex(queue, node) {
if (typeof node !== 'object' || node === null) {
return;
}
if (node.range) {
queue.push([node, node.range[0]]);
} else if (Array.isArray(node)) {
for (var ii = 0; ii < node.length; ii++) {
enqueueNodeWithStartIndex(queue, node[ii]);
}
}
} | Helper function for analyzeAndTraverse which queues up all of the children
of the given node.
Children can also be found in arrays, so we basically want to merge all of
those arrays together so we can sort them and then traverse the children
in order.
One example is the Program node. It contains `body` and `comments`... | enqueueNodeWithStartIndex | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function containsChildOfType(node, type) {
return containsChildMatching(node, function(node) {
return node.type === type;
});
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | containsChildOfType | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function containsChildMatching(node, matcher) {
var foundMatchingChild = false;
function nodeTypeAnalyzer(node) {
if (matcher(node) === true) {
foundMatchingChild = true;
return false;
}
}
function nodeTypeTraverser(child, path, state) {
if (!foundMatchingChild) {
foundMatchingChil... | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | containsChildMatching | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function nodeTypeAnalyzer(node) {
if (matcher(node) === true) {
foundMatchingChild = true;
return false;
}
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | nodeTypeAnalyzer | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function nodeTypeTraverser(child, path, state) {
if (!foundMatchingChild) {
foundMatchingChild = containsChildMatching(child, matcher);
}
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | nodeTypeTraverser | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getBoundaryNode(path) {
for (var ii = 0; ii < path.length; ++ii) {
if (scopeTypes[path[ii].type]) {
return path[ii];
}
}
throw new Error(
'Expected to find a node with one of the following types in path:\n' +
JSON.stringify(Object.keys(scopeTypes))
);
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | getBoundaryNode | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getTempVar(tempVarIndex) {
return '$__' + tempVarIndex;
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | getTempVar | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function injectTempVar(state) {
var tempVar = '$__' + (state.localScope.tempVarIndex++);
state.localScope.tempVars.push(tempVar);
return tempVar;
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | injectTempVar | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function injectTempVarDeclarations(state, index) {
if (state.localScope.tempVars.length) {
state.g.buffer =
state.g.buffer.slice(0, index) +
'var ' + state.localScope.tempVars.join(', ') + ';' +
state.g.buffer.slice(index);
state.localScope.tempVars = [];
}
} | Checks whether a node or any of its sub-nodes contains
a syntactic construct of the passed type.
@param {object} node - AST node to test.
@param {string} type - node type to lookup. | injectTempVarDeclarations | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function process(traverse, node, path, state) {
utils.move(node.range[0], state);
traverse(node, path, state);
utils.catchup(node.range[1], state);
} | Implements ES6 call spread.
instance.method(a, b, c, ...d)
instance.method.apply(instance, [a, b, c].concat(d)) | process | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitCallSpread(traverse, node, path, state) {
utils.catchup(node.range[0], state);
if (node.type === Syntax.NewExpression) {
// Input = new Set(1, 2, ...list)
// Output = new (Function.prototype.bind.apply(Set, [null, 1, 2].concat(list)))
utils.append('new (Function.prototype.bind.apply(', s... | Implements ES6 call spread.
instance.method(a, b, c, ...d)
instance.method.apply(instance, [a, b, c].concat(d)) | visitCallSpread | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _generateAnonymousClassName(state) {
var mungeNamespace = state.mungeNamespace || '';
return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
} | Used to generate a unique class for use with code-gens for anonymous class
expressions.
@param {object} state
@return {string} | _generateAnonymousClassName | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _getMungedName(identName, state) {
var mungeNamespace = state.mungeNamespace;
var shouldMinify = state.g.opts.minify;
if (shouldMinify) {
if (!_mungedSymbolMaps[mungeNamespace]) {
_mungedSymbolMaps[mungeNamespace] = {
symbolMap: {},
identUUIDCounter: 0
};
}
var s... | Given an identifier name, munge it using the current state's mungeNamespace.
@param {string} identName
@param {object} state
@return {string} | _getMungedName | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _getSuperClassInfo(node, state) {
var ret = {
name: null,
expression: null
};
if (node.superClass) {
if (node.superClass.type === Syntax.Identifier) {
ret.name = node.superClass.name;
} else {
// Extension from an expression
ret.name = _generateAnonymousClassName(state);... | Extracts super class information from a class node.
Information includes name of the super class and/or the expression string
(if extending from an expression)
@param {object} node
@param {object} state
@return {object} | _getSuperClassInfo | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _isConstructorMethod(classElement) {
return classElement.type === Syntax.MethodDefinition &&
classElement.key.type === Syntax.Identifier &&
classElement.key.name === 'constructor';
} | Used with .filter() to find the constructor method in a list of
MethodDefinition nodes.
@param {object} classElement
@return {boolean} | _isConstructorMethod | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _shouldMungeIdentifier(node, state) {
return (
!!state.methodFuncNode &&
!utils.getDocblock(state).hasOwnProperty('preventMunge') &&
/^_(?!_)/.test(node.name)
);
} | @param {object} node
@param {object} state
@return {boolean} | _shouldMungeIdentifier | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitClassMethod(traverse, node, path, state) {
if (!state.g.opts.es5 && (node.kind === 'get' || node.kind === 'set')) {
throw new Error(
'This transform does not support ' + node.kind + 'ter methods for ES6 ' +
'classes. (line: ' + node.loc.start.line + ', col: ' +
node.loc.start.colum... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitClassMethod | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitClassFunctionExpression(traverse, node, path, state) {
var methodNode = path[0];
var isGetter = methodNode.kind === 'get';
var isSetter = methodNode.kind === 'set';
state = utils.updateState(state, {
methodFuncNode: node
});
if (methodNode.key.name === 'constructor') {
utils.append('... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitClassFunctionExpression | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitClassMethodParam(traverse, node, path, state) {
var paramName = node.name;
if (_shouldMungeIdentifier(node, state)) {
paramName = _getMungedName(node.name, state);
}
utils.append(paramName, state);
utils.move(node.range[1], state);
} | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitClassMethodParam | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _renderClassBody(traverse, node, path, state) {
var className = state.className;
var superClass = state.superClass;
// Set up prototype of constructor on same line as `extends` for line-number
// preservation. This relies on function-hoisting if a constructor function is
// defined in the class body... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | _renderClassBody | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitClassDeclaration(traverse, node, path, state) {
var className = node.id.name;
var superClass = _getSuperClassInfo(node, state);
state = utils.updateState(state, {
mungeNamespace: className,
className: className,
superClass: superClass
});
_renderClassBody(traverse, node, path, stat... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitClassDeclaration | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitClassExpression(traverse, node, path, state) {
var className = node.id && node.id.name || _generateAnonymousClassName(state);
var superClass = _getSuperClassInfo(node, state);
utils.append('(function(){', state);
state = utils.updateState(state, {
mungeNamespace: className,
className: cl... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitClassExpression | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitPrivateIdentifier(traverse, node, path, state) {
utils.append(_getMungedName(node.name, state), state);
utils.move(node.range[1], state);
} | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitPrivateIdentifier | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitSuperCallExpression(traverse, node, path, state) {
var superClassName = state.superClass.name;
if (node.callee.type === Syntax.Identifier) {
if (_isConstructorMethod(state.methodNode)) {
utils.append(superClassName + '.call(', state);
} else {
var protoProp = SUPER_PROTO_IDENT_PRE... | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitSuperCallExpression | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitSuperMemberExpression(traverse, node, path, state) {
var superClassName = state.superClass.name;
utils.append(SUPER_PROTO_IDENT_PREFIX + superClassName, state);
utils.move(node.object.range[1], state);
} | @param {function} traverse
@param {object} node
@param {array} path
@param {object} state | visitSuperMemberExpression | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitStructuredVariable(traverse, node, path, state) {
// Allocate new temp for the pattern.
utils.append(utils.getTempVar(state.localScope.tempVarIndex) + '=', state);
// Skip the pattern and assign the init to the temp.
utils.catchupWhiteSpace(node.init.range[0], state);
traverse(node.init, path, s... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | visitStructuredVariable | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function isStructuredPattern(node) {
return node.type === Syntax.ObjectPattern ||
node.type === Syntax.ArrayPattern;
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | isStructuredPattern | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getDestructuredComponents(node, state) {
var tmpIndex = state.localScope.tempVarIndex;
var components = [];
var patternItems = getPatternItems(node);
for (var idx = 0; idx < patternItems.length; idx++) {
var item = patternItems[idx];
if (!item) {
continue;
}
if (item.type === Sy... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | getDestructuredComponents | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getPatternItems(node) {
return node.properties || node.elements;
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | getPatternItems | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getPatternItemAccessor(node, patternItem, tmpIndex, idx) {
var tmpName = utils.getTempVar(tmpIndex);
if (node.type === Syntax.ObjectPattern) {
if (reservedWordsHelper.isReservedWord(patternItem.key.name)) {
return tmpName + '["' + patternItem.key.name + '"]';
} else if (patternItem.key.type =... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | getPatternItemAccessor | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getPatternItemValue(node, patternItem) {
return node.type === Syntax.ObjectPattern
? patternItem.value
: patternItem;
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | getPatternItemValue | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitStructuredAssignment(traverse, node, path, state) {
var exprNode = node.expression;
utils.append('var ' + utils.getTempVar(state.localScope.tempVarIndex) + '=', state);
utils.catchupWhiteSpace(exprNode.right.range[0], state);
traverse(exprNode.right, path, state);
utils.catchup(exprNode.right.r... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | visitStructuredAssignment | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitStructuredParameter(traverse, node, path, state) {
utils.append(utils.getTempVar(getParamIndex(node, path)), state);
utils.catchupWhiteSpace(node.range[1], state);
return true;
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | visitStructuredParameter | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getParamIndex(paramNode, path) {
var funcNode = path[0];
var tmpIndex = 0;
for (var k = 0; k < funcNode.params.length; k++) {
var param = funcNode.params[k];
if (param === paramNode) {
break;
}
if (isStructuredPattern(param)) {
tmpIndex++;
}
}
return tmpIndex;
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | getParamIndex | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function isFunctionNode(node) {
return (node.type == Syntax.FunctionDeclaration ||
node.type == Syntax.FunctionExpression ||
node.type == Syntax.MethodDefinition ||
node.type == Syntax.ArrowFunctionExpression);
} | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | isFunctionNode | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitFunctionBodyForStructuredParameter(traverse, node, path, state) {
var funcNode = path[0];
utils.catchup(funcNode.body.range[0] + 1, state);
renderDestructuredComponents(funcNode, state);
if (funcNode.rest) {
utils.append(
restParamVisitors.renderRestParamSetup(funcNode, state),
s... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | visitFunctionBodyForStructuredParameter | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function renderDestructuredComponents(funcNode, state) {
var destructuredComponents = [];
for (var k = 0; k < funcNode.params.length; k++) {
var param = funcNode.params[k];
if (isStructuredPattern(param)) {
destructuredComponents.push(
getDestructuredComponents(param, state)
);
st... | Implements ES6 destructuring assignment and pattern matchng.
function init({port, ip, coords: [x, y]}) {
return (x && y) ? {id, port} : {ip};
};
function init($__0) {
var
port = $__0.port,
ip = $__0.ip,
$__1 = $__0.coords,
x = $__1[0],
y = $__1[1];
return (x && y) ? {id, port} : {ip};
}
var x, {... | renderDestructuredComponents | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitObjectConciseMethod(traverse, node, path, state) {
var isGenerator = node.value.generator;
if (isGenerator) {
utils.catchupWhiteSpace(node.range[0] + 1, state);
}
if (node.computed) { // [<expr>]() { ...}
utils.catchup(node.key.range[1] + 1, state);
} else if (reservedWordsHelper.isReser... | Desugars concise methods of objects to function expressions.
var foo = {
method(x, y) { ... }
};
var foo = {
method: function(x, y) { ... }
}; | visitObjectConciseMethod | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function _nodeIsFunctionWithRestParam(node) {
return (node.type === Syntax.FunctionDeclaration
|| node.type === Syntax.FunctionExpression
|| node.type === Syntax.ArrowFunctionExpression)
&& node.rest;
} | Desugars ES6 rest parameters into an ES3 arguments array.
function printf(template, ...args) {
args.forEach(...);
}
We could use `Array.prototype.slice.call`, but that usage of arguments causes
functions to be deoptimized in V8, so instead we use a for-loop.
function printf(template) {
for (var args = [], $__0 =... | _nodeIsFunctionWithRestParam | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitFunctionParamsWithRestParam(traverse, node, path, state) {
if (node.parametricType) {
utils.catchup(node.parametricType.range[0], state);
path.unshift(node);
traverse(node.parametricType, path, state);
path.shift();
}
// Render params.
if (node.params.length) {
path.unshift(no... | Desugars ES6 rest parameters into an ES3 arguments array.
function printf(template, ...args) {
args.forEach(...);
}
We could use `Array.prototype.slice.call`, but that usage of arguments causes
functions to be deoptimized in V8, so instead we use a for-loop.
function printf(template) {
for (var args = [], $__0 =... | visitFunctionParamsWithRestParam | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function renderRestParamSetup(functionNode, state) {
var idx = state.localScope.tempVarIndex++;
var len = state.localScope.tempVarIndex++;
return 'for (var ' + functionNode.rest.name + '=[],' +
utils.getTempVar(idx) + '=' + functionNode.params.length + ',' +
utils.getTempVar(len) + '=arguments.length;' +... | Desugars ES6 rest parameters into an ES3 arguments array.
function printf(template, ...args) {
args.forEach(...);
}
We could use `Array.prototype.slice.call`, but that usage of arguments causes
functions to be deoptimized in V8, so instead we use a for-loop.
function printf(template) {
for (var args = [], $__0 =... | renderRestParamSetup | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitFunctionBodyWithRestParam(traverse, node, path, state) {
utils.catchup(node.range[0] + 1, state);
var parentNode = path[0];
utils.append(renderRestParamSetup(parentNode, state), state);
return true;
} | Desugars ES6 rest parameters into an ES3 arguments array.
function printf(template, ...args) {
args.forEach(...);
}
We could use `Array.prototype.slice.call`, but that usage of arguments causes
functions to be deoptimized in V8, so instead we use a for-loop.
function printf(template) {
for (var args = [], $__0 =... | visitFunctionBodyWithRestParam | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getPropertyNames(properties) {
var names = [];
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
if (property.type === Syntax.SpreadProperty) {
continue;
}
if (property.type === Syntax.Identifier) {
names.push(property.name);
} else {
names.pu... | Desugars ES7 rest properties into ES5 object iteration. | getPropertyNames | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getRestFunctionCall(source, exclusion) {
return restFunction + '(' + source + ',' + exclusion + ')';
} | Desugars ES7 rest properties into ES5 object iteration. | getRestFunctionCall | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getSimpleShallowCopy(accessorExpression) {
// This could be faster with 'Object.assign({}, ' + accessorExpression + ')'
// but to unify code paths and avoid a ES6 dependency we use the same
// helper as for the exclusion case.
return getRestFunctionCall(accessorExpression, '{}');
} | Desugars ES7 rest properties into ES5 object iteration. | getSimpleShallowCopy | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function renderRestExpression(accessorExpression, excludedProperties) {
var excludedNames = getPropertyNames(excludedProperties);
if (!excludedNames.length) {
return getSimpleShallowCopy(accessorExpression);
}
return getRestFunctionCall(
accessorExpression,
'{' + excludedNames.join(':1,') + ':1}'
... | Desugars ES7 rest properties into ES5 object iteration. | renderRestExpression | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitObjectLiteralSpread(traverse, node, path, state) {
utils.catchup(node.range[0], state);
utils.append('Object.assign({', state);
// Skip the original {
utils.move(node.range[0] + 1, state);
var previousWasSpread = false;
for (var i = 0; i < node.properties.length; i++) {
var property = ... | Implements ES7 object spread property.
https://gist.github.com/sebmarkbage/aa849c7973cb4452c547
{ ...a, x: 1 }
Object.assign({}, a, {x: 1 }) | visitObjectLiteralSpread | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitMethod(traverse, node, path, state) {
path.unshift(node);
traverse(node.key, path, state);
path.unshift(node.value);
traverse(node.value.params, path, state);
node.value.rest && traverse(node.value.rest, path, state);
node.value.returnType && traverse(node.value.returnType, path, state);
tr... | Methods cause trouble, since esprima parses them as a key/value pair, where
the location of the value starts at the method body. For example
{ bar(x:number,...y:Array<number>):number {} }
is parsed as
{ bar: function(x: number, ...y:Array<number>): number {} }
except that the location of the FunctionExpression value is... | visitMethod | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitImportType(traverse, node, path, state) {
utils.catchupWhiteOut(node.range[1], state);
return false;
} | Methods cause trouble, since esprima parses them as a key/value pair, where
the location of the value starts at the method body. For example
{ bar(x:number,...y:Array<number>):number {} }
is parsed as
{ bar: function(x: number, ...y:Array<number>): number {} }
except that the location of the FunctionExpression value is... | visitImportType | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function stripNonWhiteParen(value) {
return value.replace(reNonWhiteParen, '');
} | Removes all non-whitespace/parenthesis characters | stripNonWhiteParen | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function isTagName(name) {
return tagConvention.test(name);
} | Removes all non-whitespace/parenthesis characters | isTagName | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitReactTag(traverse, object, path, state) {
var openingElement = object.openingElement;
var nameObject = openingElement.name;
var attributesObject = openingElement.attributes;
utils.catchup(openingElement.range[0], state, trimLeft);
if (nameObject.type === Syntax.JSXNamespacedName && nameObject.... | Removes all non-whitespace/parenthesis characters | visitReactTag | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function visitReactDisplayName(traverse, object, path, state) {
var left, right;
if (object.type === Syntax.AssignmentExpression) {
left = object.left;
right = object.right;
} else if (object.type === Syntax.Property) {
left = object.key;
right = object.value;
} else if (object.type === Syntax.... | Transforms the following:
var MyComponent = React.createClass({
render: ...
});
into:
var MyComponent = React.createClass({
displayName: 'MyComponent',
render: ...
});
Also catches:
MyComponent = React.createClass(...);
exports.MyComponent = React.createClass(...);
module.exports = {MyComponent: React.cre... | visitReactDisplayName | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getAllVisitors(excludes) {
var ret = [];
for (var i = 0, il = transformRunOrder.length; i < il; i++) {
if (!excludes || excludes.indexOf(transformRunOrder[i]) === -1) {
ret = ret.concat(transformVisitors[transformRunOrder[i]]);
}
}
return ret;
} | Given a list of transform names, return the ordered list of visitors to be
passed to the transform() function.
@param {array?} excludes
@return {array} | getAllVisitors | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
function getVisitorsBySet(sets) {
var visitorsToInclude = sets.reduce(function(visitors, set) {
if (!transformSets.hasOwnProperty(set)) {
throw new Error('Unknown visitor set: ' + set);
}
transformSets[set].forEach(function(visitor) {
visitors[visitor] = true;
});
return visitors;
},... | Given a list of visitor set names, return the ordered list of visitors to be
passed to jstransform.
@param {array}
@return {array} | getVisitorsBySet | javascript | 3Dparallax/insight | src/devtools2/lib/JSXTransformer.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/JSXTransformer.js | MIT |
textWrite = function (contents) {
return write(fileName, contents);
} | Is an URL on another domain. Only works for browser use, returns
false in non-browser environments. Only used to know if an
optimized .js version of a text resource should be loaded
instead.
@param {String} url
@returns Boolean | textWrite | javascript | 3Dparallax/insight | src/devtools2/lib/text.js | https://github.com/3Dparallax/insight/blob/master/src/devtools2/lib/text.js | MIT |
function compareLevel (direction, current, expected) {
if (direction === SORTING_ORDER.DESC) {
return current <= expected
}
return current >= expected
} | Determine if the given `current` level is enabled by comparing it
against the current threshold (`expected`).
@param {SORTING_ORDER} direction comparison direction "ASC" or "DESC"
@param {number} current current log level number representation
@param {number} expected threshold value to compare with
@returns {boolean} | compareLevel | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function genLevelComparison (levelComparison) {
if (typeof levelComparison === 'string') {
return compareLevel.bind(null, levelComparison)
}
return levelComparison
} | Create a level comparison function based on `levelComparison`
it could a default function which compares levels either in "ascending" or "descending" order or custom comparison function
@param {SORTING_ORDER | Function} levelComparison sort levels order direction or custom comparison function
@returns Function | genLevelComparison | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function mappings (customLevels = null, useOnlyCustomLevels = false) {
const customNums = customLevels
/* eslint-disable */
? Object.keys(customLevels).reduce((o, k) => {
o[customLevels[k]] = k
return o
}, {})
: null
/* eslint-enable */
const labels = Object.assign(
Object... | Create a level comparison function based on `levelComparison`
it could a default function which compares levels either in "ascending" or "descending" order or custom comparison function
@param {SORTING_ORDER | Function} levelComparison sort levels order direction or custom comparison function
@returns Function | mappings | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function assertDefaultLevelFound (defaultLevel, customLevels, useOnlyCustomLevels) {
if (typeof defaultLevel === 'number') {
const values = [].concat(
Object.keys(customLevels || {}).map(key => customLevels[key]),
useOnlyCustomLevels ? [] : Object.keys(nums).map(level => +level),
Infinity
)
... | Create a level comparison function based on `levelComparison`
it could a default function which compares levels either in "ascending" or "descending" order or custom comparison function
@param {SORTING_ORDER | Function} levelComparison sort levels order direction or custom comparison function
@returns Function | assertDefaultLevelFound | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function assertNoLevelCollisions (levels, customLevels) {
const { labels, values } = levels
for (const k in customLevels) {
if (k in values) {
throw Error('levels cannot be overridden')
}
if (customLevels[k] in labels) {
throw Error('pre-existing level values cannot be used for new levels')
... | Create a level comparison function based on `levelComparison`
it could a default function which compares levels either in "ascending" or "descending" order or custom comparison function
@param {SORTING_ORDER | Function} levelComparison sort levels order direction or custom comparison function
@returns Function | assertNoLevelCollisions | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function assertLevelComparison (levelComparison) {
if (typeof levelComparison === 'function') {
return
}
if (typeof levelComparison === 'string' && Object.values(SORTING_ORDER).includes(levelComparison)) {
return
}
throw new Error('Levels comparison should be one of "ASC", "DESC" or "function" type'... | Validates whether `levelComparison` is correct
@throws Error
@param {SORTING_ORDER | Function} levelComparison - value to validate
@returns | assertLevelComparison | javascript | pinojs/pino | lib/levels.js | https://github.com/pinojs/pino/blob/master/lib/levels.js | MIT |
function defaultMixinMergeStrategy (mergeObject, mixinObject) {
return Object.assign(mixinObject, mergeObject)
} | Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
Fields from `mergeObject` have higher priority in this strategy.
@param {Object} mergeObject The object a user has supplied to the logging function.
@param {Object} mixinObject The result of the `mixin` method.
@return {Object} | defaultMixinMergeStrategy | javascript | pinojs/pino | lib/proto.js | https://github.com/pinojs/pino/blob/master/lib/proto.js | MIT |
function write (_obj, msg, num) {
const t = this[timeSym]()
const mixin = this[mixinSym]
const errorKey = this[errorKeySym]
const messageKey = this[messageKeySym]
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy
let obj
const streamWriteHook = this[hooksSym].streamWrite
... | Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
Fields from `mergeObject` have higher priority in this strategy.
@param {Object} mergeObject The object a user has supplied to the logging function.
@param {Object} mixinObject The result of the `mixin` method.
@return {Object} | write | javascript | pinojs/pino | lib/proto.js | https://github.com/pinojs/pino/blob/master/lib/proto.js | MIT |
function flush (cb) {
if (cb != null && typeof cb !== 'function') {
throw Error('callback must be a function')
}
const stream = this[streamSym]
if (typeof stream.flush === 'function') {
stream.flush(cb || noop)
} else if (cb) cb()
} | Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
Fields from `mergeObject` have higher priority in this strategy.
@param {Object} mergeObject The object a user has supplied to the logging function.
@param {Object} mixinObject The result of the `mixin` method.
@return {Object} | flush | javascript | pinojs/pino | lib/proto.js | https://github.com/pinojs/pino/blob/master/lib/proto.js | MIT |
function normalizeDestFileDescriptor (destination) {
const fd = Number(destination)
if (typeof destination === 'string' && Number.isFinite(fd)) {
return fd
}
// destination could be undefined if we are in a worker
if (destination === undefined) {
// This is stdout in UNIX systems
return 1
}
re... | Convert a string integer file descriptor to a proper native integer
file descriptor.
@param {string} destination The file descriptor string to attempt to convert.
@returns {Number} | normalizeDestFileDescriptor | javascript | pinojs/pino | lib/tools.js | https://github.com/pinojs/pino/blob/master/lib/tools.js | MIT |
async function loadTransportStreamBuilder (target) {
let fn
try {
const toLoad = target.startsWith('file://') ? target : 'file://' + target
if (toLoad.endsWith('.ts') || toLoad.endsWith('.cts')) {
// TODO: add support for the TSM modules loader ( https://github.com/lukeed/tsm ).
if (process[Sym... | Loads & returns a function to build transport streams
@param {string} target
@returns {Promise<function(object): Promise<import('node:stream').Writable>>}
@throws {Error} In case the target module does not export a function | loadTransportStreamBuilder | javascript | pinojs/pino | lib/transport-stream.js | https://github.com/pinojs/pino/blob/master/lib/transport-stream.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.