MCPcopy Index your code
hub / github.com/nodejs/node / VariableDeclaration

Function VariableDeclaration

lib/internal/repl/await.js:66–136  ·  view source on GitHub ↗
(node, state, c)

Source from the content-addressed store, hash-verified

64 walk.base.ReturnStatement(node, state, c);
65 },
66 VariableDeclaration(node, state, c) {
67 const variableKind = node.kind;
68 const isIterableForDeclaration = ArrayPrototypeIncludes(
69 ['ForOfStatement', 'ForInStatement'],
70 state.ancestors[state.ancestors.length - 2].type,
71 );
72
73 if (variableKind === 'var' || isTopLevelDeclaration(state)) {
74 state.replace(
75 node.start,
76 node.start + variableKind.length + (isIterableForDeclaration ? 1 : 0),
77 variableKind === 'var' && isIterableForDeclaration ?
78 '' :
79 'void' + (node.declarations.length === 1 ? '' : ' ('),
80 );
81
82 if (!isIterableForDeclaration) {
83 ArrayPrototypeForEach(node.declarations, (decl) => {
84 state.prepend(decl, '(');
85 state.append(decl, decl.init ? ')' : '=undefined)');
86 });
87
88 if (node.declarations.length !== 1) {
89 state.append(node.declarations[node.declarations.length - 1], ')');
90 }
91 }
92
93 const variableIdentifiersToHoist = [
94 ['var', []],
95 ['let', []],
96 ];
97 function registerVariableDeclarationIdentifiers(node) {
98 switch (node.type) {
99 case 'Identifier':
100 ArrayPrototypePush(
101 variableIdentifiersToHoist[variableKind === 'var' ? 0 : 1][1],
102 node.name,
103 );
104 break;
105 case 'ObjectPattern':
106 ArrayPrototypeForEach(node.properties, (property) => {
107 registerVariableDeclarationIdentifiers(property.value || property.argument);
108 });
109 break;
110 case 'ArrayPattern':
111 ArrayPrototypeForEach(node.elements, (element) => {
112 registerVariableDeclarationIdentifiers(element);
113 });
114 break;
115 }
116 }
117
118 ArrayPrototypeForEach(node.declarations, (decl) => {
119 registerVariableDeclarationIdentifiers(decl.id);
120 });
121
122 ArrayPrototypeForEach(
123 variableIdentifiersToHoist,

Callers

nothing calls this directly

Calls 4

VariableDeclarationMethod · 0.80
isTopLevelDeclarationFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected