Web Inspector: Update Esprima to support modern JavaScript language features
authorpecoraro@apple.com <pecoraro@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Aug 2019 03:03:32 +0000 (03:03 +0000)
committerpecoraro@apple.com <pecoraro@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Aug 2019 03:03:32 +0000 (03:03 +0000)
commita8127ed7b5728d2b884c85dc57e175366f1912d6
treee00286c9aea03a96a37c685aba1dede3cb297293
parente5796ff7f6ac91a29cde6782b8b699f55dfb809d
Web Inspector: Update Esprima to support modern JavaScript language features
https://bugs.webkit.org/show_bug.cgi?id=200796

Reviewed by Ross Kirsling.

Source/WebInspectorUI:

Use a fork of Esprima to support modern JavaScript language features
while going through the process to upstream support:

  ES2018 Feature: Async Iteration (for-await-of)
  https://github.com/jquery/esprima/issues/1990

  ES2019 Feature: Numeric Separator
  https://github.com/jquery/esprima/issues/1989

  ES2019 Feature: Optional catch binding
  https://github.com/jquery/esprima/issues/1953

  ES2020 Feature: BigInt
  https://github.com/jquery/esprima/issues/1988

ESTree compatible AST changes are summarized as:

  - CatchClause `param` property is now nullable
  - ForOfStatement now has a boolean `await` property
  - Literal can be a `"bigint"` type (works if the environment has BigInt or not)

The pretty printer only needed to have additional handling for `for-await-of`.

* UserInterface/External/Esprima/esprima.js:
New version. Typescript output expects a modern JavaScript environment
instead of just ES6.

* Tools/Formatting/index.html:
Update the formatting tool for easier use in case of errors.

* UserInterface/Models/ScriptSyntaxTree.js:
(WI.ScriptSyntaxTree.prototype._createInternalSyntaxTree):

* UserInterface/Test/TestHarness.js:
(TestHarness.prototype.passOrFail):
Convenience for pass/fail with the same message based on a condition.

* UserInterface/Workers/Formatter/EsprimaFormatter.js:
(EsprimaFormatter.prototype._handleTokenAtNode):
Ensure a space after `await` in `for await` syntax.

LayoutTests:

* inspector/formatting/resources/javascript-tests/classes-expected.js:
* inspector/formatting/resources/javascript-tests/classes.js:
* inspector/formatting/resources/javascript-tests/for-statements-expected.js:
* inspector/formatting/resources/javascript-tests/for-statements.js:
* inspector/formatting/resources/javascript-tests/generators-expected.js:
* inspector/formatting/resources/javascript-tests/generators.js:
* inspector/formatting/resources/javascript-tests/numbers-expected.js: Added.
* inspector/formatting/resources/javascript-tests/numbers.js: Added.
* inspector/formatting/resources/javascript-tests/try-catch-finally-statements-expected.js:
* inspector/formatting/resources/javascript-tests/try-catch-finally-statements.js:
* inspector/formatting/resources/javascript-tests/unary-binary-expressions-expected.js:
* inspector/formatting/resources/javascript-tests/unary-binary-expressions.js:
Test formatting of new JavaScript language features.

* inspector/formatting/formatting-css-expected.txt:
* inspector/formatting/formatting-javascript-expected.txt:
* inspector/formatting/formatting-javascript.html:
* inspector/formatting/resources/utilities.js:
(TestPage.registerInitializer.async.runFormattingTest):
(TestPage.registerInitializer.window.addFormattingTests):
(TestPage.registerInitializer):
Cleaner output and better handling for debugging failures.

* inspector/model/parse-script-syntax-tree.html:
Test new AST permutations.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248760 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/formatting/formatting-css-expected.txt
LayoutTests/inspector/formatting/formatting-javascript-expected.txt
LayoutTests/inspector/formatting/formatting-javascript.html
LayoutTests/inspector/formatting/resources/javascript-tests/classes-expected.js
LayoutTests/inspector/formatting/resources/javascript-tests/classes.js
LayoutTests/inspector/formatting/resources/javascript-tests/for-statements-expected.js
LayoutTests/inspector/formatting/resources/javascript-tests/for-statements.js
LayoutTests/inspector/formatting/resources/javascript-tests/generators-expected.js
LayoutTests/inspector/formatting/resources/javascript-tests/generators.js
LayoutTests/inspector/formatting/resources/javascript-tests/numbers-expected.js [new file with mode: 0644]
LayoutTests/inspector/formatting/resources/javascript-tests/numbers.js [new file with mode: 0644]
LayoutTests/inspector/formatting/resources/javascript-tests/try-catch-finally-statements-expected.js
LayoutTests/inspector/formatting/resources/javascript-tests/try-catch-finally-statements.js
LayoutTests/inspector/formatting/resources/javascript-tests/unary-binary-expressions-expected.js
LayoutTests/inspector/formatting/resources/javascript-tests/unary-binary-expressions.js
LayoutTests/inspector/formatting/resources/utilities.js
LayoutTests/inspector/model/parse-script-syntax-tree.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Tools/Formatting/index.html
Source/WebInspectorUI/UserInterface/External/Esprima/esprima.js
Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js
Source/WebInspectorUI/UserInterface/Test/TestHarness.js
Source/WebInspectorUI/UserInterface/Workers/Formatter/EsprimaFormatter.js