зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1586775 - Basic debugger code cleanup r=jlast
Differential Revision: https://phabricator.services.mozilla.com/D48244 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
95fe2a1f7a
Коммит
cd434a9bf5
|
@ -72,7 +72,7 @@ function convertToList(results, source) {
|
|||
for (const column of results[line]) {
|
||||
positions.push({
|
||||
line: Number(line),
|
||||
column: column,
|
||||
column,
|
||||
sourceId: id,
|
||||
sourceUrl: url,
|
||||
});
|
||||
|
@ -186,7 +186,7 @@ async function _setBreakpointPositions(cx, sourceId, line, thunkArgs) {
|
|||
dispatch({
|
||||
type: "ADD_BREAKPOINT_POSITIONS",
|
||||
cx,
|
||||
source: source,
|
||||
source,
|
||||
positions,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -225,7 +225,7 @@ export function toggleBreakpointAtLine(cx: Context, line: number) {
|
|||
addBreakpoint(cx, {
|
||||
sourceId: selectedSource.id,
|
||||
sourceUrl: selectedSource.url,
|
||||
line: line,
|
||||
line,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ export function continueToHere(
|
|||
await dispatch(
|
||||
addHiddenBreakpoint(cx, {
|
||||
line,
|
||||
column: column,
|
||||
column,
|
||||
sourceId: selectedSource.id,
|
||||
})
|
||||
);
|
||||
|
|
|
@ -45,7 +45,7 @@ export async function prettyPrintSource(
|
|||
const url = getPrettySourceURL(generatedSource.url);
|
||||
const { code, mappings } = await prettyPrint({
|
||||
text: content.value,
|
||||
url: url,
|
||||
url,
|
||||
});
|
||||
await sourceMaps.applySourceMap(generatedSource.id, url, code, mappings);
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ describe("sources - new sources", () => {
|
|||
return [
|
||||
{
|
||||
id: generatedToOriginalId(source.id, url),
|
||||
url: url,
|
||||
url,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
|
|
@ -29,7 +29,7 @@ describe("file text search", () => {
|
|||
count: 2,
|
||||
index: 2,
|
||||
matchIndex: 1,
|
||||
matches: matches,
|
||||
matches,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ export async function onConnect(connection: any, actions: Object) {
|
|||
// they are active once attached.
|
||||
actions.addEventListenerBreakpoints([]).catch(e => console.error(e));
|
||||
|
||||
const traits = tabTarget.traits;
|
||||
const { traits } = tabTarget;
|
||||
await actions.connect(
|
||||
tabTarget.url,
|
||||
threadFront.actor,
|
||||
|
|
|
@ -34,8 +34,7 @@ function addThreadEventListeners(thread: ThreadFront) {
|
|||
}
|
||||
|
||||
function setupEvents(dependencies: Dependencies) {
|
||||
const threadFront = dependencies.threadFront;
|
||||
const tabTarget = dependencies.tabTarget;
|
||||
const { tabTarget, threadFront } = dependencies;
|
||||
actions = dependencies.actions;
|
||||
sourceQueue.initialize(actions);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ export class DebugLine extends PureComponent<Props> {
|
|||
if (!isDocumentReady(source, location)) {
|
||||
return;
|
||||
}
|
||||
const sourceId = location.sourceId;
|
||||
const { sourceId } = location;
|
||||
const doc = getDocument(sourceId);
|
||||
|
||||
let { line, column } = toEditorPosition(location);
|
||||
|
@ -104,9 +104,8 @@ export class DebugLine extends PureComponent<Props> {
|
|||
this.debugExpression.clear();
|
||||
}
|
||||
|
||||
const sourceId = location.sourceId;
|
||||
const { line } = toEditorPosition(location);
|
||||
const doc = getDocument(sourceId);
|
||||
const doc = getDocument(location.sourceId);
|
||||
const { lineClass } = this.getTextClasses(why);
|
||||
doc.removeLineClass(line, "line", lineClass);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ class SourceFooter extends PureComponent<Props, State> {
|
|||
onClick={() => toggleBlackBox(cx, selectedSource)}
|
||||
className={classnames("action", type, {
|
||||
active: sourceLoaded,
|
||||
blackboxed: blackboxed,
|
||||
blackboxed,
|
||||
})}
|
||||
key={type}
|
||||
title={tooltip}
|
||||
|
|
|
@ -239,7 +239,7 @@ const mapStateToProps = (state, { source }) => {
|
|||
return {
|
||||
cx: getContext(state),
|
||||
tabSources: getSourcesForTabs(state),
|
||||
selectedSource: selectedSource,
|
||||
selectedSource,
|
||||
activeSearch: getActiveSearch(state),
|
||||
hasSiblingOfSameName: getHasSiblingOfSameName(state, source),
|
||||
};
|
||||
|
|
|
@ -45,9 +45,9 @@ function generateDefaults(
|
|||
},
|
||||
},
|
||||
location: breakpoint.location,
|
||||
source: source,
|
||||
breakpoint: breakpoint,
|
||||
log: log,
|
||||
source,
|
||||
breakpoint,
|
||||
log,
|
||||
getDefaultValue: jest.fn(),
|
||||
openConditionalPanel: jest.fn(),
|
||||
closeConditionalPanel: jest.fn(),
|
||||
|
|
|
@ -93,7 +93,7 @@ function shouldAutoExpand(depth, item, debuggeeUrl, projectRoot) {
|
|||
function findSource({ threads, sources }, itemPath, source) {
|
||||
const targetThread = threads.find(thread => itemPath.includes(thread.actor));
|
||||
if (targetThread && source) {
|
||||
const actor = targetThread.actor;
|
||||
const { actor } = targetThread;
|
||||
if (sources[actor]) {
|
||||
return sources[actor][source.id];
|
||||
}
|
||||
|
|
|
@ -172,12 +172,11 @@ class SourceTreeItem extends Component<Props, State> {
|
|||
};
|
||||
|
||||
handleDownloadFile = async (cx: Context, source: ?Source, item: TreeNode) => {
|
||||
const name = item.name;
|
||||
if (!this.props.sourceContent) {
|
||||
const { sourceContent } = this.props;
|
||||
if (!sourceContent) {
|
||||
await this.props.loadSourceText({ cx, source });
|
||||
}
|
||||
const data = this.props.sourceContent;
|
||||
downloadFile(data, name);
|
||||
downloadFile(sourceContent, item.name);
|
||||
};
|
||||
|
||||
addCollapseExpandAllOptions = (menuOptions: ContextMenu, item: TreeNode) => {
|
||||
|
|
|
@ -30,7 +30,7 @@ describe("SourcesTree", () => {
|
|||
|
||||
it("Should show a 'No Sources' message if there are no sources", async () => {
|
||||
const { component, defaultState } = render();
|
||||
const sourceTree = defaultState.sourceTree;
|
||||
const { sourceTree } = defaultState;
|
||||
sourceTree.contents = [];
|
||||
component.setState({ sourceTree: sourceTree });
|
||||
expect(component).toMatchSnapshot();
|
||||
|
|
|
@ -83,7 +83,7 @@ function filter(values, query) {
|
|||
|
||||
return fuzzyAldrin.filter(values, query, {
|
||||
key: "value",
|
||||
maxResults: maxResults,
|
||||
maxResults,
|
||||
preparedQuery,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ function generateDefaults(disabled) {
|
|||
{
|
||||
...makeMockBreakpoint(source, 1),
|
||||
id: "https://example.com/main.js:1:",
|
||||
disabled: disabled,
|
||||
disabled,
|
||||
options: {
|
||||
condition: "",
|
||||
logValue: "",
|
||||
|
@ -43,7 +43,7 @@ function generateDefaults(disabled) {
|
|||
{
|
||||
...makeMockBreakpoint(source, 2),
|
||||
id: "https://example.com/main.js:2:",
|
||||
disabled: disabled,
|
||||
disabled,
|
||||
options: {
|
||||
hidden: false,
|
||||
},
|
||||
|
@ -51,7 +51,7 @@ function generateDefaults(disabled) {
|
|||
{
|
||||
...makeMockBreakpoint(source, 3),
|
||||
id: "https://example.com/main.js:3:",
|
||||
disabled: disabled,
|
||||
disabled,
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ class Expressions extends Component<Props, State> {
|
|||
}
|
||||
|
||||
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
||||
const target = e.target;
|
||||
const { target } = e;
|
||||
if (features.autocompleteExpression) {
|
||||
this.findAutocompleteMatches(target.value, target.selectionStart);
|
||||
}
|
||||
|
|
|
@ -69,14 +69,13 @@ export default function FrameMenu(
|
|||
|
||||
const menuOptions = [];
|
||||
|
||||
const source = frame.source;
|
||||
|
||||
const toggleFrameworkElement = toggleFrameworkGroupingElement(
|
||||
callbacks.toggleFrameworkGrouping,
|
||||
frameworkGroupingOn
|
||||
);
|
||||
menuOptions.push(toggleFrameworkElement);
|
||||
|
||||
const { source } = frame;
|
||||
if (source) {
|
||||
const copySourceUri2 = copySourceElement(source.url);
|
||||
menuOptions.push(copySourceUri2);
|
||||
|
|
|
@ -50,7 +50,7 @@ class WhyPaused extends PureComponent<Props, State> {
|
|||
return exception;
|
||||
}
|
||||
|
||||
const preview = exception.preview;
|
||||
const { preview } = exception;
|
||||
if (!preview || !preview.name || !preview.message) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -134,16 +134,14 @@ class XHRBreakpoints extends Component<Props, State> {
|
|||
};
|
||||
|
||||
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
||||
const target = e.target;
|
||||
this.setState({ inputValue: target.value });
|
||||
this.setState({ inputValue: e.target.value });
|
||||
};
|
||||
|
||||
handleMethodChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
|
||||
const target = e.target;
|
||||
this.setState({
|
||||
focused: true,
|
||||
editing: true,
|
||||
inputMethod: target.value,
|
||||
inputMethod: e.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ export default function SmartGap({
|
|||
const tokenRect = token.getBoundingClientRect();
|
||||
// $FlowIgnore
|
||||
const previewRect = preview.getBoundingClientRect();
|
||||
const orientation = coords.orientation;
|
||||
const { orientation } = coords;
|
||||
let optionalMarginLeft, optionalMarginTop;
|
||||
|
||||
if (orientation === "down") {
|
||||
|
@ -156,8 +156,8 @@ export default function SmartGap({
|
|||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
style={{
|
||||
height: height,
|
||||
width: width,
|
||||
height,
|
||||
width,
|
||||
position: "absolute",
|
||||
marginLeft: optionalMarginLeft,
|
||||
marginTop: optionalMarginTop,
|
||||
|
|
|
@ -75,7 +75,7 @@ describe("SearchInput", () => {
|
|||
it("stores scroll history in state", () => {
|
||||
const onHistoryScroll = jest.fn();
|
||||
wrapper.setProps({
|
||||
onHistoryScroll: onHistoryScroll,
|
||||
onHistoryScroll,
|
||||
onKeyDown: jest.fn(),
|
||||
});
|
||||
wrapper.find("input").simulate("keyDown", createSearch(searches[0]));
|
||||
|
|
|
@ -27,9 +27,7 @@ function generateDefaults(overrides) {
|
|||
flashLineRange: jest.fn(),
|
||||
isHidden: false,
|
||||
symbols: {},
|
||||
selectedLocation: {
|
||||
sourceId: sourceId,
|
||||
},
|
||||
selectedLocation: { sourceId },
|
||||
onAlphabetizeClick: jest.fn(),
|
||||
...overrides,
|
||||
};
|
||||
|
@ -147,7 +145,7 @@ describe("Outline", () => {
|
|||
};
|
||||
|
||||
const { component } = render({
|
||||
symbols: symbols,
|
||||
symbols,
|
||||
alphabetizeOutline: true,
|
||||
});
|
||||
expect(component).toMatchSnapshot();
|
||||
|
@ -181,7 +179,7 @@ describe("Outline", () => {
|
|||
],
|
||||
};
|
||||
|
||||
const { component } = render({ symbols: symbols });
|
||||
const { component } = render({ symbols });
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
||||
|
@ -199,7 +197,7 @@ describe("Outline", () => {
|
|||
};
|
||||
|
||||
const { component } = render({
|
||||
symbols: symbols,
|
||||
symbols,
|
||||
alphabetizeOutline: true,
|
||||
});
|
||||
expect(component).toMatchSnapshot();
|
||||
|
@ -211,13 +209,13 @@ describe("Outline", () => {
|
|||
classes: [makeSymbolDeclaration("x_klass", 24, 27)],
|
||||
};
|
||||
|
||||
const { component, props } = render({ symbols: symbols });
|
||||
const { component, props } = render({ symbols });
|
||||
|
||||
await component.find("h2").simulate("click", {});
|
||||
|
||||
expect(props.selectLocation).toHaveBeenCalledWith(mockcx, {
|
||||
line: 24,
|
||||
sourceId: sourceId,
|
||||
sourceId,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -296,7 +294,7 @@ describe("Outline", () => {
|
|||
expect(copyToTheClipboard).toHaveBeenCalledWith(mockFunctionText);
|
||||
expect(props.flashLineRange).toHaveBeenCalledWith({
|
||||
end: endLine,
|
||||
sourceId: sourceId,
|
||||
sourceId,
|
||||
start: startLine,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -362,7 +362,7 @@ describe("QuickOpenModal", () => {
|
|||
expect(props.selectSpecificLocation).toHaveBeenCalledWith(mockcx, {
|
||||
column: 12,
|
||||
line: 34,
|
||||
sourceId: sourceId,
|
||||
sourceId,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -636,7 +636,7 @@ describe("QuickOpenModal", () => {
|
|||
expect(wrapper.state().selectedIndex).toEqual(0);
|
||||
expect(props.highlightLineRange).toHaveBeenCalledWith({
|
||||
end: 3,
|
||||
sourceId: sourceId,
|
||||
sourceId,
|
||||
start: 1,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,10 +9,7 @@ import { shallow } from "enzyme";
|
|||
import WhyPaused from "../SecondaryPanes/WhyPaused.js";
|
||||
|
||||
function render(why: Object, delay: ?number) {
|
||||
const props = {
|
||||
why: why,
|
||||
delay: delay,
|
||||
};
|
||||
const props = { why, delay };
|
||||
|
||||
// $FlowIgnore
|
||||
const component = shallow(<WhyPaused.WrappedComponent {...props} />);
|
||||
|
|
|
@ -39,7 +39,7 @@ export function initialBreakpointsState(
|
|||
): BreakpointsState {
|
||||
return {
|
||||
breakpoints: {},
|
||||
xhrBreakpoints: xhrBreakpoints,
|
||||
xhrBreakpoints,
|
||||
breakpointsDisabled: false,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ function update(
|
|||
return zip(inputs, results).reduce(
|
||||
(_state, [input, result]) =>
|
||||
updateExpressionInList(_state, input, {
|
||||
input: input,
|
||||
input,
|
||||
value: result,
|
||||
updating: false,
|
||||
}),
|
||||
|
|
|
@ -61,7 +61,6 @@ function update(
|
|||
return { ...state, query: action.query };
|
||||
|
||||
case "ADD_SEARCH_RESULT":
|
||||
const results = state.results;
|
||||
if (action.result.matches.length === 0) {
|
||||
return state;
|
||||
}
|
||||
|
@ -71,7 +70,7 @@ function update(
|
|||
...action.result,
|
||||
matches: action.result.matches.map(m => ({ type: "MATCH", ...m })),
|
||||
};
|
||||
return { ...state, results: [...results, result] };
|
||||
return { ...state, results: [...state.results, result] };
|
||||
|
||||
case "UPDATE_STATUS":
|
||||
const ongoingSearch =
|
||||
|
|
|
@ -18,7 +18,6 @@ import type { PauseState } from "./pause";
|
|||
import type { PreviewState } from "./preview";
|
||||
import type { PendingBreakpointsState } from "../selectors";
|
||||
import type { ProjectTextSearchState } from "./project-text-search";
|
||||
import type { Record } from "../utils/makeRecord";
|
||||
import type { SourcesState } from "./sources";
|
||||
import type { SourceActorsState } from "./source-actors";
|
||||
import type { TabList } from "./tabs";
|
||||
|
@ -29,7 +28,7 @@ import type { EventListenersState } from "./event-listeners";
|
|||
export type State = {
|
||||
ast: ASTState,
|
||||
breakpoints: BreakpointsState,
|
||||
expressions: Record<ExpressionState>,
|
||||
expressions: ExpressionState,
|
||||
eventListenerBreakpoints: EventListenersState,
|
||||
threads: ThreadsState,
|
||||
fileSearch: FileSearchState,
|
||||
|
|
|
@ -117,7 +117,7 @@ function mockIndexeddDB() {
|
|||
// NOTE: We polyfill finally because TRY uses node 8
|
||||
if (!global.Promise.prototype.finally) {
|
||||
global.Promise.prototype.finally = function finallyPolyfill(callback) {
|
||||
const constructor = this.constructor;
|
||||
const { constructor } = this;
|
||||
|
||||
return this.then(
|
||||
function(value) {
|
||||
|
|
|
@ -340,6 +340,8 @@ export type Expression = {
|
|||
value: Object,
|
||||
from: string,
|
||||
updating: boolean,
|
||||
exception?: string,
|
||||
error?: string,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,6 +41,7 @@ export function findFunctionByName(
|
|||
return null;
|
||||
}
|
||||
|
||||
const functions = symbols.functions;
|
||||
return functions.find(node => node.name === name && node.index === index);
|
||||
return symbols.functions.find(
|
||||
node => node.name === name && node.index === index
|
||||
);
|
||||
}
|
||||
|
|
|
@ -114,10 +114,7 @@ export function toSourceLine(sourceId: string, line: number): ?number {
|
|||
}
|
||||
|
||||
export function scrollToColumn(codeMirror: any, line: number, column: number) {
|
||||
const { top, left } = codeMirror.charCoords(
|
||||
{ line: line, ch: column },
|
||||
"local"
|
||||
);
|
||||
const { top, left } = codeMirror.charCoords({ line, ch: column }, "local");
|
||||
|
||||
if (!isVisible(codeMirror, top, left)) {
|
||||
const scroller = codeMirror.getScrollerElement();
|
||||
|
@ -268,7 +265,7 @@ export function getCursorColumn(codeMirror: Object): number {
|
|||
|
||||
export function getTokenEnd(codeMirror: Object, line: number, column: number) {
|
||||
const token = codeMirror.getTokenAt({
|
||||
line: line,
|
||||
line,
|
||||
ch: column + 1,
|
||||
});
|
||||
const tokenString = token.string;
|
||||
|
|
|
@ -159,7 +159,7 @@ export default class SourceEditor {
|
|||
* @memberof utils/source-editor
|
||||
*/
|
||||
setFirstVisibleLine(line: number) {
|
||||
const { top } = this.editor.charCoords({ line: line, ch: 0 }, "local");
|
||||
const { top } = this.editor.charCoords({ line, ch: 0 }, "local");
|
||||
this.editor.scrollTo(0, top);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,28 +32,28 @@ function isUnavailable(value) {
|
|||
}
|
||||
|
||||
export function getValue(expression: Expression) {
|
||||
const value = expression.value;
|
||||
const { value, from, exception, error } = expression;
|
||||
if (!value) {
|
||||
return {
|
||||
path: expression.from,
|
||||
path: from,
|
||||
value: { unavailable: true },
|
||||
};
|
||||
}
|
||||
|
||||
if (value.exception) {
|
||||
if (isUnavailable(value.exception)) {
|
||||
if (exception) {
|
||||
if (isUnavailable(exception)) {
|
||||
return { value: { unavailable: true } };
|
||||
}
|
||||
return {
|
||||
path: value.from,
|
||||
value: value.exception,
|
||||
path: from,
|
||||
value: exception,
|
||||
};
|
||||
}
|
||||
|
||||
if (value.error) {
|
||||
if (error) {
|
||||
return {
|
||||
path: value.from,
|
||||
value: value.error,
|
||||
path: from,
|
||||
value: error,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/* 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 <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
// @flow
|
||||
|
||||
/**
|
||||
* Immutable JS conversion utils
|
||||
* @deprecated
|
||||
* @module utils/fromJS
|
||||
*/
|
||||
|
||||
import * as I from "immutable";
|
||||
import { isFunction } from "lodash";
|
||||
|
||||
// hasOwnProperty is defensive because it is possible that the
|
||||
// object that we're creating a map for has a `hasOwnProperty` field
|
||||
function hasOwnProperty(value, key) {
|
||||
if (value.hasOwnProperty && isFunction(value.hasOwnProperty)) {
|
||||
return value.hasOwnProperty(key);
|
||||
}
|
||||
|
||||
if (value.prototype && value.prototype.hasOwnProperty) {
|
||||
return value.prototype.hasOwnProperty(key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
creates an immutable map, where each of the value's
|
||||
items are transformed into their own map.
|
||||
|
||||
NOTE: we guard against `length` being a property because
|
||||
length confuses Immutable's internal algorithm.
|
||||
*/
|
||||
function createMap(value) {
|
||||
const hasLength = hasOwnProperty(value, "length");
|
||||
const length = value.length;
|
||||
|
||||
if (hasLength) {
|
||||
value.length = `${value.length}`;
|
||||
}
|
||||
|
||||
let map = I.Seq(value)
|
||||
.map(fromJS)
|
||||
.toMap();
|
||||
|
||||
if (hasLength) {
|
||||
map = map.set("length", length);
|
||||
value.length = length;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
function createList(value) {
|
||||
return I.Seq(value)
|
||||
.map(fromJS)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* When our app state is fully typed, we should be able to get rid of
|
||||
* this function. This is only temporarily necessary to support
|
||||
* converting typed objects to immutable.js, which usually happens in
|
||||
* reducers.
|
||||
*
|
||||
* @memberof utils/fromJS
|
||||
* @static
|
||||
*/
|
||||
function fromJS(value: any): any {
|
||||
if (Array.isArray(value)) {
|
||||
return createList(value);
|
||||
}
|
||||
if (value && value.constructor && value.constructor.meta) {
|
||||
// This adds support for tcomb objects which are native JS objects
|
||||
// but are not "plain", so the above checks fail. Since they
|
||||
// behave the same we can use the same constructors, but we need
|
||||
// special checks for them.
|
||||
const kind = value.constructor.meta.kind;
|
||||
if (kind === "struct") {
|
||||
return createMap(value);
|
||||
} else if (kind === "list") {
|
||||
return createList(value);
|
||||
}
|
||||
}
|
||||
|
||||
// If it's a primitive type, just return the value. Note `==` check
|
||||
// for null, which is intentionally used to match either `null` or
|
||||
// `undefined`.
|
||||
if (value == null || typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Otherwise, treat it like an object. We can't reliably detect if
|
||||
// it's a plain object because we might be objects from other JS
|
||||
// contexts so `Object !== Object`.
|
||||
|
||||
return createMap(value);
|
||||
}
|
||||
|
||||
module.exports = fromJS;
|
|
@ -1,50 +0,0 @@
|
|||
/* 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 <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
// @flow
|
||||
|
||||
/**
|
||||
* When Flow 0.29 is released (very soon), we can use this Record type
|
||||
* instead of the builtin immutable.js Record type. This is better
|
||||
* because all the fields are actually typed, unlike the builtin one.
|
||||
* This depends on a performance fix that will go out in 0.29 though;
|
||||
* @module utils/makeRecord
|
||||
*/
|
||||
|
||||
import * as I from "immutable";
|
||||
|
||||
/**
|
||||
* @memberof utils/makeRecord
|
||||
* @static
|
||||
*/
|
||||
export type Record<T: Object> = {
|
||||
equals<A>(other: A): boolean,
|
||||
get<A>(key: $Keys<T>, notSetValue?: any): A,
|
||||
getIn<A>(keyPath: Array<any>, notSetValue?: any): A,
|
||||
hasIn<A>(keyPath: Array<any>): boolean,
|
||||
set<A>(key: $Keys<T>, value: A): Record<T>,
|
||||
setIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
|
||||
merge(values: $Shape<T>): Record<T>,
|
||||
mergeIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
|
||||
delete<A>(key: $Keys<T>, value: A): Record<T>,
|
||||
deleteIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
|
||||
update<A>(key: $Keys<T>, value: A): Record<T>,
|
||||
updateIn(keyPath: Array<any>, ...iterables: Array<any>): Record<T>,
|
||||
remove<A>(key: $Keys<T>): Record<T>,
|
||||
toJS(): T,
|
||||
} & T;
|
||||
|
||||
/**
|
||||
* Make an immutable record type
|
||||
*
|
||||
* @param spec - the keys and their default values
|
||||
* @return a state record factory function
|
||||
* @memberof utils/makeRecord
|
||||
* @static
|
||||
*/
|
||||
function makeRecord<T>(spec: T & Object): () => Record<T> {
|
||||
return I.Record(spec);
|
||||
}
|
||||
|
||||
export default makeRecord;
|
|
@ -24,13 +24,11 @@ CompiledModules(
|
|||
'defer.js',
|
||||
'DevToolsUtils.js',
|
||||
'expressions.js',
|
||||
'fromJS.js',
|
||||
'function.js',
|
||||
'indentation.js',
|
||||
'isMinified.js',
|
||||
'location.js',
|
||||
'log.js',
|
||||
'makeRecord.js',
|
||||
'memoize.js',
|
||||
'memoizeLast.js',
|
||||
'memoizableAction.js',
|
||||
|
|
|
@ -60,7 +60,7 @@ export function getScope(
|
|||
|
||||
const key = `${actor}-${scopeIndex}`;
|
||||
if (type === "function" || type === "block") {
|
||||
const bindings = scope.bindings;
|
||||
const { bindings } = scope;
|
||||
|
||||
let vars = getBindingVariables(bindings, key);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ export function getFramePopVariables(why: Why, path: string): NamedValue[] {
|
|||
const vars: Array<NamedValue> = [];
|
||||
|
||||
if (why && why.frameFinished) {
|
||||
const frameFinished = why.frameFinished;
|
||||
const { frameFinished } = why;
|
||||
|
||||
// Always display a `throw` property if present, even if it is falsy.
|
||||
if (Object.prototype.hasOwnProperty.call(frameFinished, "throw")) {
|
||||
|
|
|
@ -84,8 +84,7 @@ export function isJavaScript(source: Source, content: SourceContent): boolean {
|
|||
* @static
|
||||
*/
|
||||
export function isPretty(source: Source): boolean {
|
||||
const url = source.url;
|
||||
return isPrettyURL(url);
|
||||
return isPrettyURL(source.url);
|
||||
}
|
||||
|
||||
export function isPrettyURL(url: string): boolean {
|
||||
|
@ -398,8 +397,7 @@ export function getTextAtPosition(
|
|||
asyncContent: AsyncValue<SourceContent> | null,
|
||||
location: SourceLocation
|
||||
) {
|
||||
const column = location.column || 0;
|
||||
const line = location.line;
|
||||
const { column, line = 0 } = location;
|
||||
|
||||
const lineText = getLineText(sourceId, asyncContent, line);
|
||||
return lineText.slice(column, column + 100).trim();
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/* 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 <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
// @flow
|
||||
|
||||
import fromJS from "../fromJS";
|
||||
|
||||
const preview = {
|
||||
kind: "ArrayLike",
|
||||
length: 201,
|
||||
items: [
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
"a test",
|
||||
"a",
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
{
|
||||
type: "null",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("fromJS", () => {
|
||||
it("supports array like objects", () => {
|
||||
const iPreview = fromJS(preview);
|
||||
expect(iPreview.get("length")).toEqual(201);
|
||||
expect(iPreview.get("items").size).toEqual(10);
|
||||
});
|
||||
|
||||
it("supports arrays", () => {
|
||||
const iItems = fromJS(preview.items);
|
||||
expect(iItems.getIn([0, "type"])).toEqual("null");
|
||||
expect(iItems.size).toEqual(10);
|
||||
});
|
||||
|
||||
it("supports objects without a prototype", () => {
|
||||
expect(() => fromJS(Object.create(null))).not.toThrow();
|
||||
});
|
||||
|
||||
it("supports objects with `hasOwnProperty` fields", () => {
|
||||
const value = {
|
||||
lookupIterator: {
|
||||
value: {},
|
||||
writable: true,
|
||||
},
|
||||
|
||||
hasOwnProperty: {
|
||||
value: {},
|
||||
writable: true,
|
||||
},
|
||||
arguments: {
|
||||
value: {},
|
||||
writable: false,
|
||||
},
|
||||
};
|
||||
|
||||
const newMap = fromJS(value);
|
||||
expect(newMap.getIn(["hasOwnProperty", "writable"])).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -47,7 +47,7 @@ export function getWasmText(sourceId: string, data: Uint8Array) {
|
|||
result = { lines: ["No luck with wast conversion"], offsets: [0], done };
|
||||
}
|
||||
|
||||
const offsets = result.offsets;
|
||||
const { offsets } = result;
|
||||
const lines = [];
|
||||
for (let i = 0; i < offsets.length; i++) {
|
||||
lines[offsets[i]] = i;
|
||||
|
|
|
@ -839,7 +839,7 @@ const scopeCollectionVisitor = {
|
|||
scope && scope !== parentScope;
|
||||
scope = scope.parent
|
||||
) {
|
||||
const freeVariables = state.freeVariables;
|
||||
const { freeVariables } = state;
|
||||
state.freeVariables = state.freeVariableStack.pop();
|
||||
const parentFreeVariables = state.freeVariables;
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ function extractSymbol(path: SimplePath, symbols, state) {
|
|||
property: { name, loc },
|
||||
} = callee;
|
||||
symbols.callExpressions.push({
|
||||
name: name,
|
||||
name,
|
||||
values: args.filter(arg => arg.value).map(arg => arg.value),
|
||||
location: loc,
|
||||
});
|
||||
|
@ -435,8 +435,7 @@ function getSnippet(
|
|||
return expression;
|
||||
}
|
||||
|
||||
const name = node.name;
|
||||
const prop = extendSnippet(name, expression, path, prevPath);
|
||||
const prop = extendSnippet(node.name, expression, path, prevPath);
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
@ -455,8 +454,7 @@ function getSnippet(
|
|||
}
|
||||
|
||||
if (t.isIdentifier(path)) {
|
||||
const node = path.node;
|
||||
return `${node.name}.${expression}`;
|
||||
return `${path.node.name}.${expression}`;
|
||||
}
|
||||
|
||||
if (t.isObjectProperty(path)) {
|
||||
|
|
|
@ -61,7 +61,7 @@ function _getNextStep(
|
|||
if (nextStatement) {
|
||||
return {
|
||||
...nextStatement.node.loc.start,
|
||||
sourceId: sourceId,
|
||||
sourceId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ type InvertedMapping = {
|
|||
|
||||
function prettyPrint({ url, indent, sourceText }) {
|
||||
const prettified = prettyFast(sourceText, {
|
||||
url: url,
|
||||
url,
|
||||
indent: " ".repeat(indent),
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче