Watch Expressions Shouldn't Be Allowed with Syntax Errors
I created a bogus watch expression:
If a syntax error is detected for a watch expression, we shouldn't allow its creation -- we should instead highlight the input box red and notify the user that their expression is invalid.
The title was off based on your description.
hmm. that's a good point... hadn't thought of that. That'll actually simplify the evaluate code a bit
Here's a quick screenshot
in the future we can show a tooltip w/ the error, but that's not important now
and a patch
diff --git a/src/actions/expressions.js b/src/actions/expressions.js
index 85968ea..521e513 100644
--- a/src/actions/expressions.js
+++ b/src/actions/expressions.js
@@ -32,6 +32,11 @@ export function addExpression(input: string) {
return;
}
+ const error = await parser.hasSyntaxError(input);
+ if (error) {
+ return false;
+ }
+
const expression = getExpression(getState(), input);
if (expression) {
return dispatch(evaluateExpression(expression));
@@ -102,14 +107,6 @@ function evaluateExpression(expression: Expression) {
}
let input = expression.input;
- const error = await parser.hasSyntaxError(input);
- if (error) {
- return dispatch({
- type: "EVALUATE_EXPRESSION",
- input: expression.input,
- value: { input: expression.input, result: error }
- });
- }
const frame = getSelectedFrame(getState());
diff --git a/src/components/SecondaryPanes/Expressions.js b/src/components/SecondaryPanes/Expressions.js
index 5362c50..2a604f3 100644
--- a/src/components/SecondaryPanes/Expressions.js
+++ b/src/components/SecondaryPanes/Expressions.js
@@ -41,7 +41,8 @@ class Expressions extends PureComponent<Props, State> {
super(...args);
this.state = {
- editing: null
+ editing: null,
+ error: null
};
this.renderExpression = this.renderExpression.bind(this);
@@ -163,26 +164,34 @@ class Expressions extends PureComponent<Props, State> {
}
}
- renderNewExpressionInput() {
- const onKeyPress = e => {
- if (e.key !== "Enter") {
- return;
- }
-
- const value = e.target.value;
- if (value == "") {
- return;
- }
-
- e.stopPropagation();
- e.target.value = "";
- this.props.addExpression(value);
- };
+ onKeyPress = async e => {
+ if (e.key !== "Enter") {
+ return;
+ }
+
+ const value = e.target.value;
+ if (value == "") {
+ return;
+ }
+ e.stopPropagation();
+ const error = await parser.hasSyntaxError(value);
+ this.setState({ error });
+
+ if (error) {
+ return;
+ }
+
+ e.target.value = "";
+ this.props.addExpression(value);
+ };
+
+ renderNewExpressionInput() {
+ const {error} = state
return (
<li className="expression-input-container">
<input
- className="input-expression"
+ className=classnames("input-expression", {error})
type="text"
placeholder={L10N.getStr("expressions.placeholder")}
onBlur={e => (e.target.value = "")}
diff --git a/src/components/SecondaryPanes/Frames/index.js b/src/components/SecondaryPanes/Frames/index.js
index d5d3b51..e98032b 100644
--- a/src/components/SecondaryPanes/Frames/index.js
+++ b/src/components/SecondaryPanes/Frames/index.js
@@ -204,6 +204,7 @@ class Frames extends Component<Props, State> {
}
}
+// Should be converted to flow types
Frames.propTypes = {
frames: PropTypes.array,
frameworkGroupingOn: PropTypes.bool.isRequired,
/claim
Thanks for claiming the issue! :wave:
Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.
:fox_face: Debugger team!