Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

[PrettyPrint] auto-pretty-print minified sources (#4171)#4700

Merged
bomsy merged 11 commits into
firefox-devtools:masterfrom
assafdd:master
Nov 18, 2017
Merged

[PrettyPrint] auto-pretty-print minified sources (#4171)#4700
bomsy merged 11 commits into
firefox-devtools:masterfrom
assafdd:master

Conversation

@assafdd

@assafdd assafdd commented Nov 15, 2017

Copy link
Copy Markdown
Contributor

Associated Issue: #4171

Summary of Changes

  • copied isMinified heuristic from old debugger
  • auto togglePrettyPrint on setText

Test Plan:

run tests on

  1. New Tab - about:home (some react resources under vendor folder)
  2. http://devtools-html.github.io/debugger-examples/examples/todomvc/ (bower_components/backbone/local-storage folder)

One odd is that if you close pretty-print source while it's selected it will reappear while if you close it while the original version is visible it won't.

@assafdd

assafdd commented Nov 15, 2017

Copy link
Copy Markdown
Contributor Author

the commit also broke Editor.spec.js with to the following exception
● Editor › should set text
TypeError: Cannot read property 'match' of undefined
at isOriginalId (node_modules/devtools-source-map/src/utils/index.js:19:14)

Comment thread src/components/Editor/index.js Outdated
isMinified(selected.id, selected.text)
) {
togglePrettyPrint(selectedSource.get("id"));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this in actions/sources#selectSource we like to have the actions control the business logic

Comment thread src/components/Editor/index.js Outdated
this.setText(nextProps);
if (nextProps.selectedSource !== this.props.selectedSource) {
this.setText(nextProps);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was resetting the text each time, we setEmptylines and other stuff even though the selected source has not changed

Assaf Dagan added 2 commits November 16, 2017 00:24
@assafdd

assafdd commented Nov 15, 2017

Copy link
Copy Markdown
Contributor Author

Move the login to the action.
@bomsy I don't think the if statement is needed any more. WDYT?
if (nextProps.selectedSource !== this.props.selectedSource) {

@assafdd

assafdd commented Nov 15, 2017

Copy link
Copy Markdown
Contributor Author

Still some jest test are failing on my machine.

@jasonLaster

Copy link
Copy Markdown
Contributor

kill the IF

@bomsy

bomsy commented Nov 15, 2017

Copy link
Copy Markdown
Contributor

@assafdd yeah ..not relevant

@assafdd

assafdd commented Nov 16, 2017

Copy link
Copy Markdown
Contributor Author

@jasonLaster I removed the IF, fixed expressions.spec.js
I can't figures out why createPrettySource.spec.js is breaking and if it's releted to my changes at all.
Any suggestions how to continue?

@jasonLaster

Copy link
Copy Markdown
Contributor

will look

Comment thread src/actions/sources.js Outdated
await dispatch(loadSourceText(source.toJS()));
await dispatch(setOutOfScopeLocations());
const src = getSource(getState(), id).toJS();
if (src.text && isMinified(src.id, src.text)) {

@bomsy bomsy Nov 16, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assafdd We should also be checking if this is a generated file or not before auto pretty printing. That's probably the issue with the tests aswell

@bomsy bomsy Nov 16, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding && !isOriginalId(src.id) should do the trick

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @bomsy I'm on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bomsy

bomsy commented Nov 16, 2017

Copy link
Copy Markdown
Contributor

tiny lint issues
image

@assafdd

assafdd commented Nov 16, 2017

Copy link
Copy Markdown
Contributor Author

Well, I think it's finally ready :)

Assaf Dagan added 2 commits November 16, 2017 23:09
…racter "`" (709:32) (firefox-devtools#4619) - bump pretty-fast & acorn to latest"

This reverts commit b7cbbdd.
Comment thread src/actions/sources.js Outdated
await dispatch(loadSourceText(source.toJS()));
await dispatch(setOutOfScopeLocations());
const src = getSource(getState(), id).toJS();
if (src.text && !isOriginalId(src.id) && isMinified(src.id, src.text)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @assafdd,
just noticed one last tiny thing. we should do add shouldPrettyPrint(src). it'll look something like this

if (src.text && !isOriginalId(src.id) && (isMinified(src.id, src.text) || shouldPrettyPrint(src))) { 

so we make sure all holes are covered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do shouldPrettyPrint(src)) && isMinified(src.id, src.text)

@bomsy bomsy Nov 18, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be too strict as there might be files that don't meet the isMinified heuristics but we might still want to pretty print if shouldPrettyPrint(src) is `true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can. I move the empty text check to isMinified util.
Otherwise "should evaluate expressions in specific scope" in expressions.spec.js breaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bomsy I tried to play with shouldPrettyPrint() and its seems to be truthy on any JS source that I have checked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! it's fine, i had a scenario which i found but can't find it any more so its fine

@bomsy bomsy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bomsy bomsy merged commit 9b0bdfe into firefox-devtools:master Nov 18, 2017
@bomsy

bomsy commented Nov 18, 2017

Copy link
Copy Markdown
Contributor

Thanks! @assafdd

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants