Commit 421e8088 authored by lushnikov's avatar lushnikov Committed by Commit bot

DevTools: support pretty-print of async/await

BUG=612493
R=dgozman

Review-Url: https://codereview.chromium.org/2569563002
Cr-Commit-Position: refs/heads/master@{#437749}
parent f282f371
Verifies JavaScript pretty-printing functionality.
Running: asyncAwaitSupport
====== 8< ------
async function foo() {
return await Promise.resolve(1);
}
------ >8 ======
Correct mapping for <async>
Correct mapping for <function>
Correct mapping for <foo>
Correct mapping for <return>
Correct mapping for <Promise>
Correct mapping for <resolve>
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<script src="../../http/tests/inspector/sources-test.js"></script>
<script>
function test()
{
var testJSFormatter = InspectorTest.testPrettyPrint.bind(InspectorTest, "text/javascript");
InspectorTest.runTestSuite([
function asyncAwaitSupport(next)
{
var mappingQueries = ["async", "function", "foo", "return", "Promise", "resolve"];
testJSFormatter("async function foo() {return await Promise.resolve(1);}", mappingQueries, next);
},
]);
}
</script>
</head>
<body onload="runTest()">
<p>Verifies JavaScript pretty-printing functionality.</p>
</body>
</html>
...@@ -11,7 +11,7 @@ FormatterWorker.AcornTokenizer = class { ...@@ -11,7 +11,7 @@ FormatterWorker.AcornTokenizer = class {
constructor(content) { constructor(content) {
this._content = content; this._content = content;
this._comments = []; this._comments = [];
this._tokenizer = acorn.tokenizer(this._content, {ecmaVersion: 7, onComment: this._comments}); this._tokenizer = acorn.tokenizer(this._content, {ecmaVersion: 8, onComment: this._comments});
this._lineEndings = this._content.computeLineEndings(); this._lineEndings = this._content.computeLineEndings();
this._lineNumber = 0; this._lineNumber = 0;
this._tokenLineStart = 0; this._tokenLineStart = 0;
......
...@@ -91,6 +91,7 @@ FormatterWorker.ESTreeWalker.SkipSubtree = {}; ...@@ -91,6 +91,7 @@ FormatterWorker.ESTreeWalker.SkipSubtree = {};
/** @enum {!Array.<string>} */ /** @enum {!Array.<string>} */
FormatterWorker.ESTreeWalker._walkOrder = { FormatterWorker.ESTreeWalker._walkOrder = {
'AwaitExpression': ['arguments'],
'ArrayExpression': ['elements'], 'ArrayExpression': ['elements'],
'ArrowFunctionExpression': ['params', 'body'], 'ArrowFunctionExpression': ['params', 'body'],
'AssignmentExpression': ['left', 'right'], 'AssignmentExpression': ['left', 'right'],
......
...@@ -97,7 +97,7 @@ FormatterWorker.relaxedJSONParser = function(content) { ...@@ -97,7 +97,7 @@ FormatterWorker.relaxedJSONParser = function(content) {
* @param {string} content * @param {string} content
*/ */
FormatterWorker.evaluatableJavaScriptSubstring = function(content) { FormatterWorker.evaluatableJavaScriptSubstring = function(content) {
var tokenizer = acorn.tokenizer(content, {ecmaVersion: 7}); var tokenizer = acorn.tokenizer(content, {ecmaVersion: 8});
var result = ''; var result = '';
try { try {
var token = tokenizer.getToken(); var token = tokenizer.getToken();
...@@ -139,7 +139,7 @@ FormatterWorker.evaluatableJavaScriptSubstring = function(content) { ...@@ -139,7 +139,7 @@ FormatterWorker.evaluatableJavaScriptSubstring = function(content) {
* @param {string} content * @param {string} content
*/ */
FormatterWorker.javaScriptIdentifiers = function(content) { FormatterWorker.javaScriptIdentifiers = function(content) {
var root = acorn.parse(content, {ranges: false, ecmaVersion: 6}); var root = acorn.parse(content, {ranges: false, ecmaVersion: 8});
/** @type {!Array<!ESTree.Node>} */ /** @type {!Array<!ESTree.Node>} */
var identifiers = []; var identifiers = [];
......
...@@ -51,7 +51,7 @@ FormatterWorker.JavaScriptFormatter = class { ...@@ -51,7 +51,7 @@ FormatterWorker.JavaScriptFormatter = class {
this._content = text.substring(this._fromOffset, this._toOffset); this._content = text.substring(this._fromOffset, this._toOffset);
this._lastLineNumber = 0; this._lastLineNumber = 0;
this._tokenizer = new FormatterWorker.AcornTokenizer(this._content); this._tokenizer = new FormatterWorker.AcornTokenizer(this._content);
var ast = acorn.parse(this._content, {ranges: false, ecmaVersion: 7}); var ast = acorn.parse(this._content, {ranges: false, ecmaVersion: 8});
var walker = new FormatterWorker.ESTreeWalker(this._beforeVisit.bind(this), this._afterVisit.bind(this)); var walker = new FormatterWorker.ESTreeWalker(this._beforeVisit.bind(this), this._afterVisit.bind(this));
walker.walk(ast); walker.walk(ast);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment