mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
chore(jsdoc): remove jsdoc/env from astnode
This commit is contained in:
parent
ad6d74e937
commit
e816766f6c
@ -1,7 +1,7 @@
|
||||
// TODO: docs
|
||||
/** @module jsdoc/src/astnode */
|
||||
const _ = require('lodash');
|
||||
const { cast } = require('@jsdoc/util');
|
||||
const env = require('jsdoc/env');
|
||||
const { SCOPE } = require('@jsdoc/core').name;
|
||||
const { Syntax } = require('jsdoc/src/syntax');
|
||||
|
||||
@ -46,7 +46,6 @@ exports.isScope = node => // TODO: handle blocks with "let" declarations
|
||||
|
||||
// TODO: docs
|
||||
exports.addNodeProperties = node => {
|
||||
const debugEnabled = Boolean(env.opts.debug);
|
||||
const newProperties = {};
|
||||
|
||||
if (!node || typeof node !== 'object') {
|
||||
@ -56,11 +55,11 @@ exports.addNodeProperties = node => {
|
||||
if (!node.nodeId) {
|
||||
newProperties.nodeId = {
|
||||
value: `astnode${uid++}`,
|
||||
enumerable: debugEnabled
|
||||
enumerable: true
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.parent && node.parent !== null) {
|
||||
if (_.isUndefined(node.parent)) {
|
||||
newProperties.parent = {
|
||||
// `null` means 'no parent', so use `undefined` for now
|
||||
value: undefined,
|
||||
@ -68,7 +67,7 @@ exports.addNodeProperties = node => {
|
||||
};
|
||||
}
|
||||
|
||||
if (!node.enclosingScope && node.enclosingScope !== null) {
|
||||
if (_.isUndefined(node.enclosingScope)) {
|
||||
newProperties.enclosingScope = {
|
||||
// `null` means 'no enclosing scope', so use `undefined` for now
|
||||
value: undefined,
|
||||
@ -76,7 +75,7 @@ exports.addNodeProperties = node => {
|
||||
};
|
||||
}
|
||||
|
||||
if (debugEnabled && typeof node.parentId === 'undefined') {
|
||||
if (_.isUndefined(node.parentId)) {
|
||||
newProperties.parentId = {
|
||||
enumerable: true,
|
||||
get() {
|
||||
@ -85,7 +84,7 @@ exports.addNodeProperties = node => {
|
||||
};
|
||||
}
|
||||
|
||||
if (debugEnabled && typeof node.enclosingScopeId === 'undefined') {
|
||||
if (_.isUndefined(node.enclosingScopeId)) {
|
||||
newProperties.enclosingScopeId = {
|
||||
enumerable: true,
|
||||
get() {
|
||||
|
||||
@ -2,7 +2,6 @@ describe('jsdoc/src/astNode', () => {
|
||||
const astBuilder = require('jsdoc/src/astbuilder');
|
||||
const astNode = require('jsdoc/src/astnode');
|
||||
const babelParser = require('@babel/parser');
|
||||
const env = require('jsdoc/env');
|
||||
const Syntax = require('jsdoc/src/syntax').Syntax;
|
||||
|
||||
function parse(str) {
|
||||
@ -79,16 +78,6 @@ describe('jsdoc/src/astNode', () => {
|
||||
});
|
||||
|
||||
describe('addNodeProperties', () => {
|
||||
let debugEnabled;
|
||||
|
||||
beforeEach(() => {
|
||||
debugEnabled = Boolean(env.opts.debug);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
env.opts.debug = debugEnabled;
|
||||
});
|
||||
|
||||
it('should return null for undefined input', () => {
|
||||
expect( astNode.addNodeProperties() ).toBe(null);
|
||||
});
|
||||
@ -104,13 +93,13 @@ describe('jsdoc/src/astNode', () => {
|
||||
expect(node.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('should add a non-enumerable nodeId if necessary', () => {
|
||||
it('should add a nodeId if necessary', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(node, 'nodeId');
|
||||
|
||||
expect(descriptor).toBeObject();
|
||||
expect(descriptor.value).toBeString();
|
||||
expect(descriptor.enumerable).toBeFalse();
|
||||
expect(descriptor.enumerable).toBeTrue();
|
||||
});
|
||||
|
||||
it('should not overwrite an existing nodeId', () => {
|
||||
@ -120,17 +109,6 @@ describe('jsdoc/src/astNode', () => {
|
||||
expect(node.nodeId).toBe(nodeId);
|
||||
});
|
||||
|
||||
it('should add an enumerable nodeId in debug mode', () => {
|
||||
let descriptor;
|
||||
let node;
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
descriptor = Object.getOwnPropertyDescriptor(node, 'nodeId');
|
||||
|
||||
expect(descriptor.enumerable).toBeTrue();
|
||||
});
|
||||
|
||||
it('should add a non-enumerable, writable parent if necessary', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(node, 'parent');
|
||||
@ -154,34 +132,24 @@ describe('jsdoc/src/astNode', () => {
|
||||
expect(node.parent).toBeNull();
|
||||
});
|
||||
|
||||
it('should add an enumerable parentId in debug mode', () => {
|
||||
let descriptor;
|
||||
let node;
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
descriptor = Object.getOwnPropertyDescriptor(node, 'parentId');
|
||||
it('should add an enumerable parentId', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(node, 'parentId');
|
||||
|
||||
expect(descriptor).toBeObject();
|
||||
expect(descriptor.enumerable).toBeTrue();
|
||||
});
|
||||
|
||||
it('should provide a null parentId in debug mode for nodes with no parent', () => {
|
||||
let node;
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
it('should provide a null parentId for nodes with no parent', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
|
||||
expect(node.parentId).toBeNull();
|
||||
});
|
||||
|
||||
it('should provide a non-null parentId in debug mode for nodes with a parent', () => {
|
||||
let node;
|
||||
let parent;
|
||||
it('should provide a non-null parentId for nodes with a parent', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const parent = astNode.addNodeProperties({});
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
parent = astNode.addNodeProperties({});
|
||||
node.parent = parent;
|
||||
|
||||
expect(node.parentId).toBe(parent.nodeId);
|
||||
@ -210,36 +178,24 @@ describe('jsdoc/src/astNode', () => {
|
||||
expect(node.enclosingScope).toBeNull();
|
||||
});
|
||||
|
||||
it('should add an enumerable enclosingScopeId in debug mode', () => {
|
||||
let descriptor;
|
||||
let node;
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
descriptor = Object.getOwnPropertyDescriptor(node, 'enclosingScopeId');
|
||||
it('should add an enumerable enclosingScopeId', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(node, 'enclosingScopeId');
|
||||
|
||||
expect(descriptor).toBeObject();
|
||||
expect(descriptor.enumerable).toBeTrue();
|
||||
});
|
||||
|
||||
it('should provide a null enclosingScopeId in debug mode for nodes with no enclosing scope',
|
||||
() => {
|
||||
let node;
|
||||
it('should provide a null enclosingScopeId for nodes with no enclosing scope', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
expect(node.enclosingScopeId).toBeNull();
|
||||
});
|
||||
|
||||
expect(node.enclosingScopeId).toBeNull();
|
||||
});
|
||||
it('should provide a non-null enclosingScopeId for nodes with an enclosing scope', () => {
|
||||
const node = astNode.addNodeProperties({});
|
||||
const enclosingScope = astNode.addNodeProperties({});
|
||||
|
||||
it('should provide a non-null enclosingScopeId in debug mode for nodes with an enclosing ' +
|
||||
'scope', () => {
|
||||
let enclosingScope;
|
||||
let node;
|
||||
|
||||
env.opts.debug = true;
|
||||
node = astNode.addNodeProperties({});
|
||||
enclosingScope = astNode.addNodeProperties({});
|
||||
node.enclosingScope = enclosingScope;
|
||||
|
||||
expect(node.enclosingScopeId).toBe(enclosingScope.nodeId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user