Example #1
0
            '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);
        });
Example #2
0
        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);
        });
Example #3
0
    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();
        }
    }
Example #4
0
    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();
        }
    }
Example #5
0
        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);
        });
Example #6
0
            function() {
                var node;

                env.opts.debug = true;
                node = astNode.addNodeProperties({});

                expect(node.enclosingScopeId).toBe(null);
            });
Example #7
0
        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);
        });
Example #8
0
            function() {
            var descriptor;
            var node;

            global.env.opts.debug = true;
            node = astnode.addNodeProperties({});

            expect(node.enclosingScopeId).toBe(null);
        });
Example #9
0
        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);
        });
Example #10
0
        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);
        });
Example #11
0
        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);
        });
Example #12
0
    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();
        }
    }
Example #13
0
        it('should not overwrite a null parent', function() {
            var node = astnode.addNodeProperties({parent: null});

            expect(node.parent).toBe(null);
        });
Example #14
0
        it('should not overwrite an existing nodeId', function() {
            var nodeId = 'foo';
            var node = astnode.addNodeProperties({nodeId: nodeId});

            expect(node.nodeId).toBe(nodeId);
        });
Example #15
0
        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);
        });
Example #16
0
 it('should return null if the input is not an object', function() {
     expect( astnode.addNodeProperties('foo') ).toBe(null);
 });
Example #17
0
 it('should return null for undefined input', function() {
     expect( astnode.addNodeProperties() ).toBe(null);
 });
Example #18
0
        it('should not overwrite an existing parent', function() {
            var parent = {};
            var node = astnode.addNodeProperties({parent: parent});

            expect(node.parent).toBe(parent);
        });
Example #19
0
        it('should not overwrite a null enclosingScope', function() {
            var node = astnode.addNodeProperties({enclosingScope: null});

            expect(node.enclosingScope).toBe(null);
        });
Example #20
0
        it('should not overwrite an existing enclosingScope', function() {
            var enclosingScope = {};
            var node = astnode.addNodeProperties({enclosingScope: enclosingScope});

            expect(node.enclosingScope).toBe(enclosingScope);
        });