Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions flow-typed/debugger-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,6 @@ declare module "debugger-html" {
loading?: boolean
};

/**
* SourceText
* @memberof types
* @static
*/
declare type SourceText = {
id: string,
text: string,
contentType: string,
loading?: boolean,
error?: boolean
};

/**
* Script
* This describes scripts which are sent to the debug server to be eval'd
Expand Down
6 changes: 2 additions & 4 deletions src/actions/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
removeSourceFromTabList
} from "../selectors";

import type { Source, SourceText } from "../types";
import type { Source } from "../types";
import type { ThunkArgs } from "./types";
import type { State } from "../reducers/types";

Expand Down Expand Up @@ -358,13 +358,11 @@ export function loadSourceText(source: Source) {

const response = await client.sourceContents(source.id);

const sourceText: SourceText = {
return {
id: source.id,
text: response.source,
contentType: response.contentType || "text/javascript"
};

return sourceText;
})()
});

Expand Down
7 changes: 3 additions & 4 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
LoadedObject,
Location,
GeneratedLocation,
SourceText,
Frame,
Scope,
Why
Expand Down Expand Up @@ -107,7 +106,7 @@ type SourceAction =
source: Source,
status: AsyncStatus,
error: string,
value: SourceText
value: Source
}
| {
type: "BLACKBOX",
Expand All @@ -123,7 +122,7 @@ type SourceAction =
error: string,
value: {
isPrettyPrinted: boolean,
sourceText: SourceText,
source: Source,
frames: Frame[]
}
}
Expand Down Expand Up @@ -216,7 +215,7 @@ type NavigateAction = { type: "NAVIGATE", url: string };
type ASTAction =
| {
type: "SET_SYMBOLS",
source: SourceText,
source: Source,
symbols: SymbolDeclaration[]
}
| {
Expand Down
6 changes: 3 additions & 3 deletions src/reducers/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ function update(

function getTextPropsFromAction(action: any) {
const source = action.source;
const sourceText = action.value;
const { value } = action;

if (action.status === "start") {
return { id: source.id, loading: true };
} else if (action.status === "error") {
return { id: source.id, error: action.error, loading: false };
}
return {
text: sourceText.text,
text: value.text,
id: source.id,
contentType: sourceText.contentType,
contentType: value.contentType,
loading: false
};
}
Expand Down
1 change: 0 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type {
LoadedObject,
Location,
Source,
SourceText,
Pause,
Why
} from "debugger-html";
4 changes: 2 additions & 2 deletions src/utils/parser/getOutOfScopeLocations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import type { SourceText } from "debugger-html";
import type { Source } from "debugger-html";
import type { AstLocation, AstPosition } from "./types";

import get from "lodash/fp/get";
Expand Down Expand Up @@ -74,7 +74,7 @@ function sortByStart(a: AstLocation, b: AstLocation) {
* location.
*/
function getOutOfScopeLocations(
source: SourceText,
source: Source,
position: AstPosition
): AstLocation[] {
return findFunctions(source)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/parser/getSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as t from "babel-types";

import getFunctionName from "./utils/getFunctionName";

import type { SourceText } from "debugger-html";
import type { Source } from "debugger-html";
import type { NodePath, Node, Location as BabelLocation } from "babel-traverse";
const symbolDeclarations = new Map();

Expand Down Expand Up @@ -58,7 +58,7 @@ function getVariableNames(path: NodePath): SymbolDeclaration[] {
}));
}

export default function getSymbols(source: SourceText): SymbolDeclarations {
export default function getSymbols(source: Source): SymbolDeclarations {
if (symbolDeclarations.has(source.id)) {
const symbols = symbolDeclarations.get(source.id);
if (symbols) {
Expand Down Expand Up @@ -288,7 +288,7 @@ function getSnippet(path, prevPath, expression = "") {
}
}

export function formatSymbols(source: SourceText) {
export function formatSymbols(source: Source) {
const {
objectProperties,
memberExpressions,
Expand Down
43 changes: 24 additions & 19 deletions src/utils/parser/utils/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import traverse from "babel-traverse";
import isEmpty from "lodash/isEmpty";
import { isDevelopment } from "devtools-config";

import type { SourceText } from "debugger-html";
import type { Source } from "debugger-html";

const ASTs = new Map();

Expand All @@ -20,7 +20,7 @@ function _parse(code, opts) {
);
}

function parse(text: string, opts?: Object) {
function parse(text: ?string, opts?: Object) {
let ast;
if (!text) {
return;
Expand All @@ -39,32 +39,37 @@ function parse(text: string, opts?: Object) {
return ast;
}

export function getAst(sourceText: SourceText) {
if (ASTs.has(sourceText.id)) {
return ASTs.get(sourceText.id);
// Custom parser for parse-script-tags that adapts its input structure to
// our parser's signature
function htmlParser({ source, line }) {
return parse(source, {
startLine: line
});
}

export function getAst(source: Source) {
if (!source || !source.text) {
return {};
}

if (ASTs.has(source.id)) {
return ASTs.get(source.id);
}

let ast = {};
if (sourceText.contentType == "text/html") {
// Custom parser for parse-script-tags that adapts its input structure to
// our parser's signature
const parser = ({ source, line }) => {
return parse(source, {
startLine: line
});
};
ast = parseScriptTags(sourceText.text, parser) || {};
} else if (sourceText.contentType == "text/javascript") {
ast = parse(sourceText.text);
if (source.contentType == "text/html") {
ast = parseScriptTags(source.text, htmlParser) || {};
} else if (source.contentType == "text/javascript") {
ast = parse(source.text);
}

ASTs.set(sourceText.id, ast);
ASTs.set(source.id, ast);
return ast;
}

type Visitor = { enter: Function };
export function traverseAst(sourceText: SourceText, visitor: Visitor) {
const ast = getAst(sourceText);
export function traverseAst(source: Source, visitor: Visitor) {
const ast = getAst(source);
if (isEmpty(ast)) {
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/parser/utils/closest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
nodeContainsPosition
} from "./helpers";

import type { SourceText, Location } from "debugger-html";
import type { Source, Location } from "debugger-html";
import type { NodePath, Node } from "babel-traverse";

function getNodeValue(node: Node) {
Expand Down Expand Up @@ -43,7 +43,7 @@ function getClosestMemberExpression(source, token, location: Location) {
}

export function getClosestExpression(
source: SourceText,
source: Source,
token: string,
location: Location
) {
Expand All @@ -61,7 +61,7 @@ export function getClosestExpression(
return { expression: getNodeValue(node), location: node.loc };
}

export function getClosestScope(source: SourceText, location: Location) {
export function getClosestScope(source: Source, location: Location) {
let closestPath = null;

traverseAst(source, {
Expand All @@ -83,7 +83,7 @@ export function getClosestScope(source: SourceText, location: Location) {
return closestPath.scope;
}

export function getClosestPath(source: SourceText, location: Location) {
export function getClosestPath(source: Source, location: Location) {
let closestPath = null;

traverseAst(source, {
Expand Down