/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at . */
import React, { Component } from "react";
import PropTypes from "prop-types";
import { formatDisplayName } from "../../utils/pause/frames";
import "./PreviewFunction.css";
const IGNORED_SOURCE_URLS = ["debugger eval code"];
export default class PreviewFunction extends Component {
static get propTypes() {
return {
func: PropTypes.object.isRequired,
};
}
renderFunctionName(func) {
const { l10n } = this.context;
const name = formatDisplayName(func, undefined, l10n);
return {name};
}
renderParams(func) {
const { parameterNames = [] } = func;
return parameterNames
.filter(Boolean)
.map((param, i, arr) => {
const elements = [
{param}
,
];
// if this isn't the last param, add a comma
if (i !== arr.length - 1) {
elements.push(
{", "}
);
}
return elements;
})
.flat();
}
jumpToDefinitionButton(func) {
const { location } = func;
if (!location?.url || IGNORED_SOURCE_URLS.includes(location.url)) {
return null;
}
const lastIndex = location.url.lastIndexOf("/");
return (
);
}
render() {
const { func } = this.props;
return (
{this.renderFunctionName(func)}
(
{this.renderParams(func)}
)
{this.jumpToDefinitionButton(func)}
);
}
}
PreviewFunction.contextTypes = { l10n: PropTypes.object };