Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError [ERR_ASSERTION]: Missing parent symbol when converting function #1436

Closed
doberkofler opened this issue Dec 30, 2020 · 5 comments
Labels
bug Functionality does not match expectation

Comments

@doberkofler
Copy link

doberkofler commented Dec 30, 2020

Search terms

ERR_ASSERTION

Expected Behavior

No exception in TypeDoc 0.20.2 but error in TypeDoc 0.20.3 and TypeDoc 0.20.4

Actual Behavior

npx typedoc
TypeDoc exiting with unexpected error:
AssertionError [ERR_ASSERTION]: Missing parent symbol when converting function
    at Object.convertFunctionOrMethod (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/converter/symbols.js:134:5)
    at Object.convertSymbol (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/converter/symbols.js:75:79)
    at Converter.convertExports (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/converter/converter.js:167:23)
    at Converter.compile (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/converter/converter.js:143:34)
    at Converter.convert (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/converter/converter.js:42:14)
    at Application.convert (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/dist/lib/application.js:151:31)
    at run (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/bin/typedoc:59:25)
    at Object.<anonymous> (/Users/doberkofler/MyDev/ljs_app/trunk/periscope/node_modules/typedoc/bin/typedoc:26:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

Steps to reproduce the bug

typedoc.json

{
	"entryPoints": [
		"./src/components",
		"./src/data",
		"./src/framework"
	],
	"out": "doc",
	"exclude": [
		"**/*.js"
	],
	"excludeExternals": true,
	"hideGenerator": true
}

Environment

  • Typedoc version: 0.20.4
  • TypeScript version: 4.1.3
  • Node.js version: 14.15.3
  • OS: macOS 11.1
@doberkofler doberkofler added the bug Functionality does not match expectation label Dec 30, 2020
@BobKerns
Copy link

BobKerns commented Dec 30, 2020

I hit the same problem about simultaneously. In my case, I tracked it down to the following module declaration:

declare module 'present';
declare function present(): number;

This was needed because of missing declarations for this:

import present from 'present';

My workaround: exclude the file present.d.ts in my typedoc.json file.

Alternate workaround:

const present = require('present') as () => number;

(and comment out the present.d.ts file; the problem seems to stem from processing the declaration, rather than the usage.)

@BobKerns
Copy link

The error message is completely opaque. To track down what symbol was the cause, I changed the assert in typedoc/dist/lib/converter/symbol.js to be this:

    const showScope = s => JSON.stringify({id: s.id, name: s.name, originalName: s.originalName, kind: s.kind})
    assert(parentSymbol, !parentSymbol && `Missing parent symbol when converting function ${symbol.escapedName} scope ${showScope(context.scope)} parent ${showScope(context.scope.parent)}`);

The !parent symbol && is to avoid creating the string on every assert call, as I expect that's rather frequent. This isn't the optimum solution to the opacity, but it was enough for me to find a solution.

@doberkofler
Copy link
Author

@BobKerns Thank you for the debugging tip (I was just too lazy to dig into the source and hoped for some feedback)

I just added the code change and am getting the following error

AssertionError [ERR_ASSERTION]: Missing parent symbol when converting function isStyleSupported scope {"id":7105,"name":"framework/browser/featureDetection","originalName":"framework/browser/featureDetection","kind":1} parent {"id":0,"name":"","originalName":"","kind":0}

without obvious reason (to me) in the following code

function isStyleSupported(prop: string, value: string = 'inherit'): boolean {
	const el = window.document.createElement('div');
	const camelRe = /-([a-z]|[0-9])/ig;

	// Try the native standard method first
	if ('CSS' in window && 'supports' in window.CSS) {
		return window.CSS.supports(prop, value);
	}

	// Check Opera's native method
	if ('supportsCSS' in window) {
		return (window as any).supportsCSS(prop, value); // eslint-disable-line @typescript-eslint/no-explicit-any
	}

	// Convert to camel-case for DOM interactions
	const camel = prop.replace(camelRe, function (all, letter) {
		return String(letter).toUpperCase();
	});

	// Check if the property is supported
	const support = camel in el.style;

	// Assign the property and value to invoke the CSS interpreter
	el.style.cssText = prop + ':' + value;

	// Ensure both the property and value are supported and return
	return support && (el.style as any)[camel] !== ''; // eslint-disable-line @typescript-eslint/no-explicit-any
}

$(function () {
	if (!isStyleSupported('display', 'flex')) {
		$('body').addClass('no-flexbox');
	}

	if (!isStyleSupported('animation-name')) {
		$('body').addClass('no-css-animation');
	}
});

@BobKerns
Copy link

It's not obvious to me either. I didn't attempt to understand what was going wrong. Once I identified the function and context I proceeded by trial and error, removing stuff. That was pretty limited in my case; it may be more challenging here.

If you want to try to debug it, ndb may be helpful.

https://github.com/GoogleChromeLabs/ndb

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 30, 2020

This is caused by the function being present in a non-module file, the assertion that we have a parent isn't appropriate there - it should only be asserted if the function being converted is a method. Fixed in 0.20.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

3 participants