Bug 148563 - Web Inspector: Improve ScriptSyntaxTree a bit
Summary: Web Inspector: Improve ScriptSyntaxTree a bit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-08-27 22:50 PDT by Joseph Pecoraro
Modified: 2015-08-28 12:31 PDT (History)
9 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (3.22 KB, patch)
2015-08-27 22:51 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-08-27 22:50:25 PDT
* SUMMARY
Improve ScriptSyntaxTree a bit.

- Share and fix ClassDeclaration and ClassExpression recursion to visit the identifier (node.id)
- Include the kind with a VariableDeclaration ("var", "let", "const")
Comment 1 Radar WebKit Bug Importer 2015-08-27 22:50:44 PDT
<rdar://problem/22470522>
Comment 2 Joseph Pecoraro 2015-08-27 22:51:40 PDT
Created attachment 260126 [details]
[PATCH] Proposed Fix
Comment 3 Joseph Pecoraro 2015-08-27 22:52:33 PDT
=
Comment 4 Timothy Hatcher 2015-08-28 05:14:32 PDT
Comment on attachment 260126 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=260126&action=review

> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:881
> +                kind: node.kind

Shoulder map this to an enum?
Comment 5 Timothy Hatcher 2015-08-28 10:30:52 PDT
Comment on attachment 260126 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=260126&action=review

>> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:881
>> +                kind: node.kind
> 
> Shoulder map this to an enum?

Should we*
Comment 6 Joseph Pecoraro 2015-08-28 11:37:41 PDT
(In reply to comment #5)
> Comment on attachment 260126 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=260126&action=review
> 
> >> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:881
> >> +                kind: node.kind
> > 
> > Shoulder map this to an enum?
> 
> Should we*

Currently we just carry over all the other basic properties from esprima right now. Ultimately we would want our own enum types here (and in all other nodes) if we really want ScriptSyntaxTree to abstract any parser.

FWIW, there has been discussion of standardizing JS ASTs and their types in ESTree:
https://github.com/estree/estree
https://github.com/estree/estree/blob/master/es6.md

Esprima _very_ closely matches that. I did notice a few minor differences that can be sorted out later (what is a MetaProperty?). But ultimately if JS AST generators produce ESTree ASTs swapping out any parser would be trivial.
Comment 7 Joseph Pecoraro 2015-08-28 11:43:47 PDT
Also interesting JavaScript "CSTs":
https://github.com/mdevils/cst

> CST means Concrete Syntax Tree. Unlike an AST (Abstract Syntax Tree),
> a CST contains all the information from the JavaScript source file:
> whitespace, punctuators, comments. This information is extremely
> useful for code style checkers and other code linters. CST is also
> useful for cases when you need to apply modifications to existing
> JavaScript files while preserving the initial file formatting.
> 
> This CST implementation is designed to be 100% compatible with JS AST
> (https://github.com/estree/estree).

I think an issue I ran into just yesterday could have benefitted from original source information instead of just token information. Likewise, our PrettyPrinter could be written to use this. Using ASTs we lacked whitespace information that was useful to keep "as authored".
Comment 8 Saam Barati 2015-08-28 12:05:39 PDT
(In reply to comment #5)
> Comment on attachment 260126 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=260126&action=review
> 
> >> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:881
> >> +                kind: node.kind
> > 
> > Shoulder map this to an enum?
> 
> Should we*

I think we should. We could follow what we do for node types here
and just make everything a Symbol.
Comment 9 WebKit Commit Bot 2015-08-28 12:31:54 PDT
Comment on attachment 260126 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 260126

Committed r189118: <http://trac.webkit.org/changeset/189118>
Comment 10 WebKit Commit Bot 2015-08-28 12:31:57 PDT
All reviewed patches have been landed.  Closing bug.