diff --git a/flow-typed/debugger-html.js b/flow-typed/debugger-html.js
index 48edaea7dc..ce424270b6 100644
--- a/flow-typed/debugger-html.js
+++ b/flow-typed/debugger-html.js
@@ -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
diff --git a/src/actions/sources.js b/src/actions/sources.js
index 0076c4a3c0..fe80bceb5c 100644
--- a/src/actions/sources.js
+++ b/src/actions/sources.js
@@ -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";
@@ -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;
})()
});
diff --git a/src/actions/types.js b/src/actions/types.js
index 3531a69e46..56775588a4 100644
--- a/src/actions/types.js
+++ b/src/actions/types.js
@@ -7,7 +7,6 @@ import type {
LoadedObject,
Location,
GeneratedLocation,
- SourceText,
Frame,
Scope,
Why
@@ -107,7 +106,7 @@ type SourceAction =
source: Source,
status: AsyncStatus,
error: string,
- value: SourceText
+ value: Source
}
| {
type: "BLACKBOX",
@@ -123,7 +122,7 @@ type SourceAction =
error: string,
value: {
isPrettyPrinted: boolean,
- sourceText: SourceText,
+ source: Source,
frames: Frame[]
}
}
@@ -216,7 +215,7 @@ type NavigateAction = { type: "NAVIGATE", url: string };
type ASTAction =
| {
type: "SET_SYMBOLS",
- source: SourceText,
+ source: Source,
symbols: SymbolDeclaration[]
}
| {
diff --git a/src/reducers/sources.js b/src/reducers/sources.js
index 4fb9f9a3a7..a60913f00b 100644
--- a/src/reducers/sources.js
+++ b/src/reducers/sources.js
@@ -154,7 +154,7 @@ 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 };
@@ -162,9 +162,9 @@ function getTextPropsFromAction(action: any) {
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
};
}
diff --git a/src/types.js b/src/types.js
index a7add8fca2..d3c1be22ed 100644
--- a/src/types.js
+++ b/src/types.js
@@ -31,7 +31,6 @@ export type {
LoadedObject,
Location,
Source,
- SourceText,
Pause,
Why
} from "debugger-html";
diff --git a/src/utils/parser/getOutOfScopeLocations.js b/src/utils/parser/getOutOfScopeLocations.js
index 91fd1b24c5..6b66dca01e 100644
--- a/src/utils/parser/getOutOfScopeLocations.js
+++ b/src/utils/parser/getOutOfScopeLocations.js
@@ -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";
@@ -74,7 +74,7 @@ function sortByStart(a: AstLocation, b: AstLocation) {
* location.
*/
function getOutOfScopeLocations(
- source: SourceText,
+ source: Source,
position: AstPosition
): AstLocation[] {
return findFunctions(source)
diff --git a/src/utils/parser/getSymbols.js b/src/utils/parser/getSymbols.js
index e719229aff..f30cdb15ec 100644
--- a/src/utils/parser/getSymbols.js
+++ b/src/utils/parser/getSymbols.js
@@ -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();
@@ -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) {
@@ -288,7 +288,7 @@ function getSnippet(path, prevPath, expression = "") {
}
}
-export function formatSymbols(source: SourceText) {
+export function formatSymbols(source: Source) {
const {
objectProperties,
memberExpressions,
diff --git a/src/utils/parser/utils/ast.js b/src/utils/parser/utils/ast.js
index 60f9001b6d..0e09707e7e 100644
--- a/src/utils/parser/utils/ast.js
+++ b/src/utils/parser/utils/ast.js
@@ -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();
@@ -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;
@@ -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;
}
diff --git a/src/utils/parser/utils/closest.js b/src/utils/parser/utils/closest.js
index 8c50e848de..f1fd39a03d 100644
--- a/src/utils/parser/utils/closest.js
+++ b/src/utils/parser/utils/closest.js
@@ -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) {
@@ -43,7 +43,7 @@ function getClosestMemberExpression(source, token, location: Location) {
}
export function getClosestExpression(
- source: SourceText,
+ source: Source,
token: string,
location: Location
) {
@@ -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, {
@@ -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, {