'scope', function() { var enclosingScope; var node; env.opts.debug = true; node = astNode.addNodeProperties({}); enclosingScope = astNode.addNodeProperties({}); node.enclosingScope = enclosingScope; expect(node.enclosingScopeId).toBe(enclosingScope.nodeId); });
it('should provide a non-null parentId in debug mode for nodes with a parent', function() { var node; var parent; env.opts.debug = true; node = astNode.addNodeProperties({}); parent = astNode.addNodeProperties({}); node.parent = parent; expect(node.parentId).toBe(parent.nodeId); });
function cb(node, parent, cbState) { var currentScope; var isScope = astnode.isScope(node); // for efficiency, if the node has a `parent` property, assume that we've already // added the required properties if (typeof node.parent !== 'undefined') { astnode.addNodeProperties(node); } node.parent = parent || null; currentScope = getCurrentScope(cbState.scopes); if (currentScope) { node.enclosingScope = currentScope; } if (isScope) { cbState.scopes.push(node); } cbState.nodes.push(node); self._walkers[node.type](node, parent, cbState, cb); if (isScope) { cbState.scopes.pop(); } }
function cb(node, parent, state) { var currentScope; var isScope = astnode.isScope(node); // for efficiency, if the node has a knownVariables property, assume that we've already // added the required properties if (!node.knownVariables) { astnode.addNodeProperties(node); } node.parent = parent || null; currentScope = getCurrentScope(state.scopes); if (currentScope) { node.enclosingScope = currentScope; } if (isScope) { state.scopes.push(node); } state.nodes.push(node); walkers[node.type](node, parent, state, cb); if (isScope) { state.scopes.pop(); } }
it('should add a non-enumerable nodeId if necessary', function() { var node = astnode.addNodeProperties({}); var descriptor = Object.getOwnPropertyDescriptor(node, 'nodeId'); expect(descriptor).toBeDefined(); expect(typeof descriptor.value).toBe('string'); expect(descriptor.enumerable).toBe(false); });
function() { var node; env.opts.debug = true; node = astNode.addNodeProperties({}); expect(node.enclosingScopeId).toBe(null); });
it('should provide a null parentId in debug mode for nodes with no parent', function() { var node; env.opts.debug = true; node = astNode.addNodeProperties({}); expect(node.parentId).toBe(null); });
function() { var descriptor; var node; global.env.opts.debug = true; node = astnode.addNodeProperties({}); expect(node.enclosingScopeId).toBe(null); });
it('should add a non-enumerable, writable enclosingScope if necessary', function() { var node = astnode.addNodeProperties({}); var descriptor = Object.getOwnPropertyDescriptor(node, 'enclosingScope'); expect(descriptor).toBeDefined(); expect(descriptor.value).toBe(undefined); expect(descriptor.enumerable).toBe(false); expect(descriptor.writable).toBe(true); });
it('should add an enumerable nodeId in debug mode', function() { var descriptor; var node; global.env.opts.debug = true; node = astnode.addNodeProperties({}); descriptor = Object.getOwnPropertyDescriptor(node, 'nodeId'); expect(descriptor.enumerable).toBe(true); });
it('should add an enumerable enclosingScopeId in debug mode', function() { var descriptor; var node; env.opts.debug = true; node = astNode.addNodeProperties({}); descriptor = Object.getOwnPropertyDescriptor(node, 'enclosingScopeId'); expect(descriptor).toBeDefined(); expect(descriptor.enumerable).toBe(true); });
function cb(node, parent, cbState) { var currentScope; var isScope = astnode.isScope(node); astnode.addNodeProperties(node); node.parent = parent || null; currentScope = getCurrentScope(cbState.scopes); if (currentScope) { node.enclosingScope = currentScope; } if (isScope) { cbState.scopes.push(node); } cbState.nodes.push(node); self._walkers[node.type](node, parent, cbState, cb); if (isScope) { cbState.scopes.pop(); } }
it('should not overwrite a null parent', function() { var node = astnode.addNodeProperties({parent: null}); expect(node.parent).toBe(null); });
it('should not overwrite an existing nodeId', function() { var nodeId = 'foo'; var node = astnode.addNodeProperties({nodeId: nodeId}); expect(node.nodeId).toBe(nodeId); });
it('should preserve existing properties that are not "node properties"', function() { var node = astnode.addNodeProperties({foo: 1}); expect(typeof node).toBe('object'); expect(node.foo).toBe(1); });
it('should return null if the input is not an object', function() { expect( astnode.addNodeProperties('foo') ).toBe(null); });
it('should return null for undefined input', function() { expect( astnode.addNodeProperties() ).toBe(null); });
it('should not overwrite an existing parent', function() { var parent = {}; var node = astnode.addNodeProperties({parent: parent}); expect(node.parent).toBe(parent); });
it('should not overwrite a null enclosingScope', function() { var node = astnode.addNodeProperties({enclosingScope: null}); expect(node.enclosingScope).toBe(null); });
it('should not overwrite an existing enclosingScope', function() { var enclosingScope = {}; var node = astnode.addNodeProperties({enclosingScope: enclosingScope}); expect(node.enclosingScope).toBe(enclosingScope); });