Title: [209492] trunk
Revision
209492
Author
joep...@webkit.org
Date
2016-12-07 16:04:13 -0800 (Wed, 07 Dec 2016)

Log Message

Web Inspector: Add ability to distinguish if a Script was parsed as a module
https://bugs.webkit.org/show_bug.cgi?id=164900
<rdar://problem/29323817>

Reviewed by Timothy Hatcher.

Source/_javascript_Core:

* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::didParseSource):
* inspector/protocol/Debugger.json:
Add an optional event parameter to distinguish if a script was a module or not.

Source/WebInspectorUI:

* UserInterface/Models/Script.js:
(WebInspector.Script.prototype.get sourceType):
New property of Scripts. SourceType is either Program or Module.

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager.prototype.scriptDidParse):
* UserInterface/Protocol/DebuggerObserver.js:
(WebInspector.DebuggerObserver.prototype.scriptParsed):
Convert incoming module boolean into SourceType when creating new Scripts.

* UserInterface/Models/ScriptSyntaxTree.js:
(WebInspector.ScriptSyntaxTree):
(WebInspector.ScriptSyntaxTree.prototype._recurse):
(WebInspector.ScriptSyntaxTree.prototype._createInternalSyntaxTree):
Update the generic AST for new module specific Esprima types.

* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype.textEditorScriptSourceType):
* UserInterface/Views/TextEditor.js:
(WebInspector.TextEditor.prototype._startWorkerPrettyPrint):
For pretty printing correctly state if this is a module or not for Esprima.

LayoutTests:

* inspector/model/parse-script-syntax-tree-expected.txt:
* inspector/model/parse-script-syntax-tree.html:
* inspector/model/resources/module.js: Added.
(import.string_appeared_here.myModule):
* inspector/model/resources/other-module.js: Added.
(myOtherModule):
* inspector/model/resources/program.js: Added.
(myProgram):
* inspector/model/script-sourceType-expected.txt: Added.
* inspector/model/script-sourceType.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209491 => 209492)


--- trunk/LayoutTests/ChangeLog	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/LayoutTests/ChangeLog	2016-12-08 00:04:13 UTC (rev 209492)
@@ -1,5 +1,24 @@
 2016-12-07  Joseph Pecoraro  <pecor...@apple.com>
 
+        Web Inspector: Add ability to distinguish if a Script was parsed as a module
+        https://bugs.webkit.org/show_bug.cgi?id=164900
+        <rdar://problem/29323817>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/model/parse-script-syntax-tree-expected.txt:
+        * inspector/model/parse-script-syntax-tree.html:
+        * inspector/model/resources/module.js: Added.
+        (import.string_appeared_here.myModule):
+        * inspector/model/resources/other-module.js: Added.
+        (myOtherModule):
+        * inspector/model/resources/program.js: Added.
+        (myProgram):
+        * inspector/model/script-sourceType-expected.txt: Added.
+        * inspector/model/script-sourceType.html: Added.
+
+2016-12-07  Joseph Pecoraro  <pecor...@apple.com>
+
         Web Inspector: Update Esprima to support new features / syntax (**, async/await, trailing comma)
         https://bugs.webkit.org/show_bug.cgi?id=164830
         <rdar://problem/29293814>

Modified: trunk/LayoutTests/inspector/model/parse-script-syntax-tree-expected.txt (209491 => 209492)


--- trunk/LayoutTests/inspector/model/parse-script-syntax-tree-expected.txt	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/LayoutTests/inspector/model/parse-script-syntax-tree-expected.txt	2016-12-08 00:04:13 UTC (rev 209492)
@@ -45,6 +45,12 @@
 passed ArrowFunctionExpression
 passed Async Functions
 passed AwaitExpression
+passed ImportDeclaration, ImportSpecifier
+passed ImportDefaultSpecifier
+passed ImportNamespaceSpecifier
+passed ExportNamedDeclaration, ExportSpecifier
+passed ExportDefaultDeclaration
+passed ExportAllDeclaration
 passed computed method on object literal
 passed method on object literal
 passed computed method property on object literal

Modified: trunk/LayoutTests/inspector/model/parse-script-syntax-tree.html (209491 => 209492)


--- trunk/LayoutTests/inspector/model/parse-script-syntax-tree.html	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/LayoutTests/inspector/model/parse-script-syntax-tree.html	2016-12-08 00:04:13 UTC (rev 209492)
@@ -5,11 +5,13 @@
 <script>
 function test()
 {
-    function makeNode(text, isExpression)
+    function makeNode(text, isExpression, isModule)
     {
-        var script = new WebInspector.Script(1, new WebInspector.TextRange(0, text.length));
-        var scriptSyntaxTree = new WebInspector.ScriptSyntaxTree(text, script);
-        var syntaxTree = scriptSyntaxTree._syntaxTree;
+        const target = null, url = ""
+        let sourceType = isModule ? WebInspector.Script.SourceType.Module : WebInspector.Script.SourceType.Program;
+        let script = new WebInspector.Script(target, 1, new WebInspector.TextRange(0, text.length), url, sourceType);
+        let scriptSyntaxTree = new WebInspector.ScriptSyntaxTree(text, script);
+        let syntaxTree = scriptSyntaxTree._syntaxTree;
 
         InspectorTest.assert(scriptSyntaxTree.parsedSuccessfully, "ScriptSyntaxTree should be able to parse: \"" + text + "\"");
         InspectorTest.assert(syntaxTree.type === WebInspector.ScriptSyntaxTree.NodeType.Program, "Should be program.");
@@ -17,12 +19,22 @@
         if (isExpression) {
             InspectorTest.assert(syntaxTree.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
             return syntaxTree.body[0]._expression_;
-        } else
+        } else if (isModule) {
+            InspectorTest.assert(syntaxTree.sourceType === "module");
             return syntaxTree.body[0];
+        } else {
+            InspectorTest.assert(syntaxTree.sourceType === "script");
+            return syntaxTree.body[0];
+        }
     }
 
-    var node = null;
+    function makeNodeForModule(text)
+    {
+        return makeNode(text, false, true);
+    }
 
+    let node = null;
+
     node = makeNode("x = 20;", true);
     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.AssignmentExpression);
     InspectorTest.assert(node.left);
@@ -52,7 +64,7 @@
     InspectorTest.assert(node.elements[0].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
     InspectorTest.assert(node.elements[1].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
     InspectorTest.log("passed ArrayExpression");
-    
+
     node = makeNode("{foo();}", false);
     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
     InspectorTest.assert(node.body);
@@ -112,7 +124,7 @@
     InspectorTest.assert(node.consequent.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
     InspectorTest.assert(node.alternate.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
     InspectorTest.log("passed ConditionalExpression");
-    
+
     node = makeNode("label:while(true) {continue label;}", false);
     InspectorTest.assert(node.body.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ContinueStatement);
     InspectorTest.assert(node.body.body.body[0].label.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
@@ -321,7 +333,7 @@
     InspectorTest.assert(node.right.properties[0].key.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
     InspectorTest.log("passed Property");
 
-    node = makeNode("function foo(...things) { return things; }", false);    
+    node = makeNode("function foo(...things) { return things; }", false);
     InspectorTest.assert(node.params.length === 1);
     InspectorTest.assert(node.params[0].type === WebInspector.ScriptSyntaxTree.NodeType.RestElement);
     InspectorTest.assert(node.params[0].argument.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
@@ -550,6 +562,66 @@
     InspectorTest.assert(node.body.body[0]._expression_.argument.value === 1);
     InspectorTest.log("passed AwaitExpression");
 
+
+    // Modules
+
+    node = makeNodeForModule(`import {a,b as x,c} from "module.js"`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ImportDeclaration);
+    InspectorTest.assert(node.source.value === "module.js");
+    InspectorTest.assert(node.specifiers.length === 3);
+    InspectorTest.assert(node.specifiers[0].type === WebInspector.ScriptSyntaxTree.NodeType.ImportSpecifier);
+    InspectorTest.assert(node.specifiers[0].local.name === "a");
+    InspectorTest.assert(node.specifiers[0].imported.name === "a");
+    InspectorTest.assert(node.specifiers[1].type === WebInspector.ScriptSyntaxTree.NodeType.ImportSpecifier);
+    InspectorTest.assert(node.specifiers[1].local.name === "x");
+    InspectorTest.assert(node.specifiers[1].imported.name === "b");
+    InspectorTest.assert(node.specifiers[2].type === WebInspector.ScriptSyntaxTree.NodeType.ImportSpecifier);
+    InspectorTest.assert(node.specifiers[2].local.name === "c");
+    InspectorTest.assert(node.specifiers[2].imported.name === "c");
+    InspectorTest.log("passed ImportDeclaration, ImportSpecifier");
+
+    node = makeNodeForModule(`import x from "module.js"`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ImportDeclaration);
+    InspectorTest.assert(node.source.value === "module.js");
+    InspectorTest.assert(node.specifiers.length === 1);
+    InspectorTest.assert(node.specifiers[0].type === WebInspector.ScriptSyntaxTree.NodeType.ImportDefaultSpecifier);
+    InspectorTest.log("passed ImportDefaultSpecifier");
+
+    node = makeNodeForModule(`import * as A from "module.js"`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ImportDeclaration);
+    InspectorTest.assert(node.source.value === "module.js");
+    InspectorTest.assert(node.specifiers.length === 1);
+    InspectorTest.assert(node.specifiers[0].type === WebInspector.ScriptSyntaxTree.NodeType.ImportNamespaceSpecifier);
+    InspectorTest.assert(node.specifiers[0].local.name === "A");
+    InspectorTest.log("passed ImportNamespaceSpecifier");
+
+    node = makeNodeForModule(`export {a, b as x, c}`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ExportNamedDeclaration);
+    InspectorTest.assert(node.specifiers.length === 3);
+    InspectorTest.assert(node.specifiers[0].type === WebInspector.ScriptSyntaxTree.NodeType.ExportSpecifier);
+    InspectorTest.assert(node.specifiers[0].local.name === "a");
+    InspectorTest.assert(node.specifiers[0].exported.name === "a");
+    InspectorTest.assert(node.specifiers[1].type === WebInspector.ScriptSyntaxTree.NodeType.ExportSpecifier);
+    InspectorTest.assert(node.specifiers[1].local.name === "b");
+    InspectorTest.assert(node.specifiers[1].exported.name === "x");
+    InspectorTest.assert(node.specifiers[2].type === WebInspector.ScriptSyntaxTree.NodeType.ExportSpecifier);
+    InspectorTest.assert(node.specifiers[2].local.name === "c");
+    InspectorTest.assert(node.specifiers[2].exported.name === "c");
+    InspectorTest.log("passed ExportNamedDeclaration, ExportSpecifier");
+
+    node = makeNodeForModule(`export default x`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ExportDefaultDeclaration);
+    InspectorTest.assert(node.declaration.name === "x");
+    InspectorTest.log("passed ExportDefaultDeclaration");
+
+    node = makeNodeForModule(`export * from "module.js"`);
+    InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ExportAllDeclaration);
+    InspectorTest.assert(node.source.value === "module.js");
+    InspectorTest.log("passed ExportAllDeclaration");
+
+
+    // Divots
+
     node = makeNode("var o = {['c']() { }};", false);
     //                        ^
     //                 type profiling return divot.

Added: trunk/LayoutTests/inspector/model/resources/module.js (0 => 209492)


--- trunk/LayoutTests/inspector/model/resources/module.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/model/resources/module.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -0,0 +1,3 @@
+import "./other-module.js"
+
+function myModule() {}

Added: trunk/LayoutTests/inspector/model/resources/other-module.js (0 => 209492)


--- trunk/LayoutTests/inspector/model/resources/other-module.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/model/resources/other-module.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -0,0 +1 @@
+function myOtherModule() {}

Added: trunk/LayoutTests/inspector/model/resources/program.js (0 => 209492)


--- trunk/LayoutTests/inspector/model/resources/program.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/model/resources/program.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -0,0 +1 @@
+function myProgram() {}

Added: trunk/LayoutTests/inspector/model/script-sourceType-expected.txt (0 => 209492)


--- trunk/LayoutTests/inspector/model/script-sourceType-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/model/script-sourceType-expected.txt	2016-12-08 00:04:13 UTC (rev 209492)
@@ -0,0 +1,11 @@
+Tests for WebInspector.Script.SourceType.
+
+
+== Running test suite: WebInspector.Script.SourceType
+-- Running test case: WebInspector.Script.SourceType.Program
+PASS: <script> should be SourceType.Program.
+
+-- Running test case: WebInspector.Script.SourceType.Module
+PASS: imported module should be SourceType.Module.
+PASS: <script type="module"> should be SourceType.Module.
+

Added: trunk/LayoutTests/inspector/model/script-sourceType.html (0 => 209492)


--- trunk/LayoutTests/inspector/model/script-sourceType.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/model/script-sourceType.html	2016-12-08 00:04:13 UTC (rev 209492)
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function triggerProgramScript() {
+    let script = document.createElement("script");
+    script.src = ""
+    document.body.appendChild(script);
+}
+
+function triggerModuleScript() {
+    let script = document.createElement("script");
+    script.type = "module";
+    script.src = ""
+    document.body.appendChild(script);
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite("WebInspector.Script.SourceType");
+
+    suite.addTestCase({
+        name: "WebInspector.Script.SourceType.Program",
+        description: "Normal <script src> should be Program.",
+        test(resolve, reject) {
+            InspectorTest.evaluateInPage("triggerProgramScript()");
+            let listener = WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, (event) => {
+                let script = event.data.script;
+                if (!/program.js$/.test(script.url))
+                    return;
+
+                WebInspector.debuggerManager.removeEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, listener);
+                InspectorTest.expectEqual(script.sourceType, WebInspector.Script.SourceType.Program, `<script> should be SourceType.Program.`);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "WebInspector.Script.SourceType.Module",
+        description: "Module <script type=module> should be Module.",
+        test(resolve, reject) {
+            InspectorTest.evaluateInPage("triggerModuleScript()");
+            let listener = WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, (event) => {
+                let script = event.data.script;
+                if (!/module.js$/.test(script.url))
+                    return;
+
+                if (/other-module.js$/.test(script.url)) {
+                    InspectorTest.expectEqual(script.sourceType, WebInspector.Script.SourceType.Module, `imported module should be SourceType.Module.`);
+                    return;
+                }
+
+                WebInspector.debuggerManager.removeEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, listener);
+                InspectorTest.expectEqual(script.sourceType, WebInspector.Script.SourceType.Module, `<script type="module"> should be SourceType.Module.`);
+                resolve();
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests for WebInspector.Script.SourceType.</p>
+</body>
+</html>

Modified: trunk/Source/_javascript_Core/ChangeLog (209491 => 209492)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-08 00:04:13 UTC (rev 209492)
@@ -1,3 +1,16 @@
+2016-12-07  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Add ability to distinguish if a Script was parsed as a module
+        https://bugs.webkit.org/show_bug.cgi?id=164900
+        <rdar://problem/29323817>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/agents/InspectorDebuggerAgent.cpp:
+        (Inspector::InspectorDebuggerAgent::didParseSource):
+        * inspector/protocol/Debugger.json:
+        Add an optional event parameter to distinguish if a script was a module or not.
+
 2016-12-07  Simon Fraser  <simon.fra...@apple.com>
 
         Add system trace points for _javascript_ VM entry/exit

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp (209491 => 209492)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp	2016-12-08 00:04:13 UTC (rev 209492)
@@ -887,11 +887,12 @@
     String sourceURL = script.sourceURL;
     String sourceMappingURL = sourceMapURLForScript(script);
 
+    const bool isModule = script.sourceProvider->sourceType() == JSC::SourceProviderSourceType::Module;
     const bool* isContentScript = script.isContentScript ? &script.isContentScript : nullptr;
     String* sourceURLParam = hasSourceURL ? &sourceURL : nullptr;
     String* sourceMapURLParam = sourceMappingURL.isEmpty() ? nullptr : &sourceMappingURL;
 
-    m_frontendDispatcher->scriptParsed(scriptIDStr, script.url, script.startLine, script.startColumn, script.endLine, script.endColumn, isContentScript, sourceURLParam, sourceMapURLParam);
+    m_frontendDispatcher->scriptParsed(scriptIDStr, script.url, script.startLine, script.startColumn, script.endLine, script.endColumn, isContentScript, sourceURLParam, sourceMapURLParam, isModule ? &isModule : nullptr);
 
     m_scripts.set(sourceID, script);
 

Modified: trunk/Source/_javascript_Core/inspector/protocol/Debugger.json (209491 => 209492)


--- trunk/Source/_javascript_Core/inspector/protocol/Debugger.json	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/_javascript_Core/inspector/protocol/Debugger.json	2016-12-08 00:04:13 UTC (rev 209492)
@@ -304,7 +304,8 @@
                 { "name": "endColumn", "type": "integer", "description": "Length of the last line of the script." },
                 { "name": "isContentScript", "type": "boolean", "optional": true, "description": "Determines whether this script is a user extension script." },
                 { "name": "sourceURL", "type": "string", "optional": true, "description": "sourceURL name of the script (if any)." },
-                { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." }
+                { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." },
+                { "name": "module", "type": "boolean", "optional": true, "description": "True if this script was parsed as a module." }
             ],
             "description": "Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger."
         },

Modified: trunk/Source/WebInspectorUI/ChangeLog (209491 => 209492)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-12-08 00:04:13 UTC (rev 209492)
@@ -1,5 +1,35 @@
 2016-12-07  Joseph Pecoraro  <pecor...@apple.com>
 
+        Web Inspector: Add ability to distinguish if a Script was parsed as a module
+        https://bugs.webkit.org/show_bug.cgi?id=164900
+        <rdar://problem/29323817>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Models/Script.js:
+        (WebInspector.Script.prototype.get sourceType):
+        New property of Scripts. SourceType is either Program or Module.
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WebInspector.DebuggerManager.prototype.scriptDidParse):
+        * UserInterface/Protocol/DebuggerObserver.js:
+        (WebInspector.DebuggerObserver.prototype.scriptParsed):
+        Convert incoming module boolean into SourceType when creating new Scripts.
+
+        * UserInterface/Models/ScriptSyntaxTree.js:
+        (WebInspector.ScriptSyntaxTree):
+        (WebInspector.ScriptSyntaxTree.prototype._recurse):
+        (WebInspector.ScriptSyntaxTree.prototype._createInternalSyntaxTree):
+        Update the generic AST for new module specific Esprima types.
+
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor.prototype.textEditorScriptSourceType):
+        * UserInterface/Views/TextEditor.js:
+        (WebInspector.TextEditor.prototype._startWorkerPrettyPrint):
+        For pretty printing correctly state if this is a module or not for Esprima.
+
+2016-12-07  Joseph Pecoraro  <pecor...@apple.com>
+
         Web Inspector: Update Esprima to support new features / syntax (**, async/await, trailing comma)
         https://bugs.webkit.org/show_bug.cgi?id=164830
         <rdar://problem/29293814>

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -671,7 +671,7 @@
         InspectorFrontendHost.beep();
     }
 
-    scriptDidParse(target, scriptIdentifier, url, startLine, startColumn, endLine, endColumn, isContentScript, sourceURL, sourceMapURL)
+    scriptDidParse(target, scriptIdentifier, url, startLine, startColumn, endLine, endColumn, isModule, isContentScript, sourceURL, sourceMapURL)
     {
         // Called from WebInspector.DebuggerObserver.
 
@@ -690,7 +690,9 @@
         if (!WebInspector.isDebugUIEnabled() && isWebKitInternalScript(sourceURL))
             return;
 
-        let script = new WebInspector.Script(target, scriptIdentifier, new WebInspector.TextRange(startLine, startColumn, endLine, endColumn), url, isContentScript, sourceURL, sourceMapURL);
+        let range = new WebInspector.TextRange(startLine, startColumn, endLine, endColumn);
+        let sourceType = isModule ? WebInspector.Script.SourceType.Module : WebInspector.Script.SourceType.Program;
+        let script = new WebInspector.Script(target, scriptIdentifier, range, url, sourceType, isContentScript, sourceURL, sourceMapURL);
 
         targetData.addScript(script);
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Script.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Script.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Script.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -25,7 +25,7 @@
 
 WebInspector.Script = class Script extends WebInspector.SourceCode
 {
-    constructor(target, id, range, url, injected, sourceURL, sourceMapURL)
+    constructor(target, id, range, url, sourceType, injected, sourceURL, sourceMapURL)
     {
         super();
 
@@ -37,6 +37,7 @@
         this._id = id || null;
         this._range = range || null;
         this._url = url || null;
+        this._sourceType = sourceType || WebInspector.Script.SourceType.Program;
         this._sourceURL = sourceURL || null;
         this._sourceMappingURL = sourceMapURL || null;
         this._injected = injected || false;
@@ -77,26 +78,15 @@
 
     // Public
 
-    get target()
-    {
-        return this._target;
-    }
+    get target() { return this._target; }
+    get id() { return this._id; }
+    get range() { return this._range; }
+    get url() { return this._url; }
+    get sourceType() { return this._sourceType; }
+    get sourceURL() { return this._sourceURL; }
+    get sourceMappingURL() { return this._sourceMappingURL; }
+    get injected() { return this._injected; }
 
-    get id()
-    {
-        return this._id;
-    }
-
-    get range()
-    {
-        return this._range;
-    }
-
-    get url()
-    {
-        return this._url;
-    }
-
     get contentIdentifier()
     {
         if (this._url)
@@ -119,16 +109,6 @@
         return this._sourceURL;
     }
 
-    get sourceURL()
-    {
-        return this._sourceURL;
-    }
-
-    get sourceMappingURL()
-    {
-        return this._sourceMappingURL;
-    }
-
     get urlComponents()
     {
         if (!this._urlComponents)
@@ -179,11 +159,6 @@
         return null;
     }
 
-    get injected()
-    {
-        return this._injected;
-    }
-
     get dynamicallyAddedScriptElement()
     {
         return this._dynamicallyAddedScriptElement;
@@ -315,6 +290,11 @@
     }
 };
 
+WebInspector.Script.SourceType = {
+    Program: "script-source-type-program",
+    Module: "script-source-type-module",
+};
+
 WebInspector.Script.TypeIdentifier = "script";
 WebInspector.Script.URLCookieKey = "script-url";
 WebInspector.Script.DisplayNameCookieKey = "script-display-name";

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -34,7 +34,8 @@
         this._script = script;
 
         try {
-            var esprimaSyntaxTree = esprima.parse(sourceText, {range: true});
+            let sourceType = this._script.sourceType === WebInspector.Script.SourceType.Module ? "module" : "script";
+            let esprimaSyntaxTree = esprima.parse(sourceText, {range: true, sourceType});
             this._syntaxTree = this._createInternalSyntaxTree(esprimaSyntaxTree);
             this._parsedSuccessfully = true;
         } catch (error) {
@@ -487,6 +488,39 @@
         case WebInspector.ScriptSyntaxTree.NodeType.YieldExpression:
             this._recurse(node.argument, callback, state);
             break;
+
+        // Modules.
+
+        case WebInspector.ScriptSyntaxTree.NodeType.ExportAllDeclaration:
+            this._recurse(node.source, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ExportNamedDeclaration:
+            this._recurse(node.declaration, callback, state);
+            this._recurseArray(node.specifiers, callback, state);
+            this._recurse(node.source, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ExportDefaultDeclaration:
+            this._recurse(node.declaration, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ExportSpecifier:
+            this._recurse(node.local, callback, state);
+            this._recurse(node.exported, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ImportDeclaration:
+            this._recurseArray(node.specifiers, callback, state);
+            this._recurse(node.source, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ImportDefaultSpecifier:
+            this._recurse(node.local, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ImportNamespaceSpecifier:
+            this._recurse(node.local, callback, state);
+            break;
+        case WebInspector.ScriptSyntaxTree.NodeType.ImportSpecifier:
+            this._recurse(node.imported, callback, state);
+            this._recurse(node.local, callback, state);
+            break;
+
         // All the leaf nodes go here.
         case WebInspector.ScriptSyntaxTree.NodeType.DebuggerStatement:
         case WebInspector.ScriptSyntaxTree.NodeType.EmptyStatement:
@@ -938,6 +972,63 @@
                 delegate: node.delegate
             };
             break;
+
+        // Modules.
+
+        case "ExportAllDeclaration":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ExportAllDeclaration,
+                source: this._createInternalSyntaxTree(node.source),
+            };
+            break;
+        case "ExportNamedDeclaration":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ExportNamedDeclaration,
+                declaration: this._createInternalSyntaxTree(node.declaration),
+                specifiers: node.specifiers.map(this._createInternalSyntaxTree, this),
+                source: this._createInternalSyntaxTree(node.source),
+            };
+            break;
+        case "ExportDefaultDeclaration":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ExportDefaultDeclaration,
+                declaration: this._createInternalSyntaxTree(node.declaration),
+            };
+            break;
+        case "ExportSpecifier":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ExportSpecifier,
+                local: this._createInternalSyntaxTree(node.local),
+                exported: this._createInternalSyntaxTree(node.exported),
+            };
+            break;
+        case "ImportDeclaration":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ImportDeclaration,
+                specifiers: node.specifiers.map(this._createInternalSyntaxTree, this),
+                source: this._createInternalSyntaxTree(node.source),
+            };
+            break;
+        case "ImportDefaultSpecifier":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ImportDefaultSpecifier,
+                local: this._createInternalSyntaxTree(node.local),
+            };
+            break;
+        case "ImportNamespaceSpecifier":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ImportNamespaceSpecifier,
+                local: this._createInternalSyntaxTree(node.local),
+            };
+            break;
+        case "ImportSpecifier":
+            result = {
+                type: WebInspector.ScriptSyntaxTree.NodeType.ImportSpecifier,
+                imported: this._createInternalSyntaxTree(node.imported),
+                local: this._createInternalSyntaxTree(node.local),
+            };
+            break;
+
         default:
             console.error("Unsupported Syntax Tree Node: " + node.type, node);
             return null;
@@ -977,6 +1068,10 @@
     DebuggerStatement: Symbol("debugger-statement"),
     DoWhileStatement: Symbol("do-while-statement"),
     EmptyStatement: Symbol("empty-statement"),
+    ExportAllDeclaration: Symbol("export-all-declaration"),
+    ExportDefaultDeclaration: Symbol("export-default-declaration"),
+    ExportNamedDeclaration: Symbol("export-named-declaration"),
+    ExportSpecifier: Symbol("export-specifier"),
     ExpressionStatement: Symbol("_expression_-statement"),
     ForInStatement: Symbol("for-in-statement"),
     ForOfStatement: Symbol("for-of-statement"),
@@ -985,6 +1080,10 @@
     FunctionExpression: Symbol("function-_expression_"),
     Identifier: Symbol("identifier"),
     IfStatement: Symbol("if-statement"),
+    ImportDeclaration: Symbol("import-declaration"),
+    ImportDefaultSpecifier: Symbol("import-default-specifier"),
+    ImportNamespaceSpecifier: Symbol("import-namespace-specifier"),
+    ImportSpecifier: Symbol("import-specifier"),
     LabeledStatement: Symbol("labeled-statement"),
     Literal: Symbol("literal"),
     LogicalExpression: Symbol("logical-_expression_"),

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/DebuggerObserver.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/DebuggerObserver.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/DebuggerObserver.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -37,7 +37,7 @@
         WebInspector.debuggerManager.reset();
     }
 
-    scriptParsed(scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, sourceURL, sourceMapURL)
+    scriptParsed(scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, sourceURL, sourceMapURL, isModule)
     {
         if (this._legacyScriptParsed) {
             // COMPATIBILITY (iOS 9): Debugger.scriptParsed had slightly different arguments.
@@ -46,11 +46,11 @@
             let legacySourceMapURL = arguments[7];
             let hasSourceURL = arguments[8];
             let legacySourceURL = hasSourceURL ? url : undefined;
-            WebInspector.debuggerManager.scriptDidParse(this.target, scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, legacySourceURL, legacySourceMapURL);
+            WebInspector.debuggerManager.scriptDidParse(this.target, scriptId, url, startLine, startColumn, endLine, endColumn, isModule, isContentScript, legacySourceURL, legacySourceMapURL);
             return;
         }
 
-        WebInspector.debuggerManager.scriptDidParse(this.target, scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript, sourceURL, sourceMapURL);
+        WebInspector.debuggerManager.scriptDidParse(this.target, scriptId, url, startLine, startColumn, endLine, endColumn, isModule, isContentScript, sourceURL, sourceMapURL);
     }
 
     scriptFailedToParse(url, scriptSource, startLine, errorLine, errorMessage)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -1183,6 +1183,12 @@
         return this._sourceCode.url;
     }
 
+    textEditorScriptSourceType(textEditor)
+    {
+        let script = this._getAssociatedScript();
+        return script ? script.sourceType : WebInspector.Script.SourceType.Program;
+    }
+
     textEditorShouldHideLineNumber(textEditor, lineNumber)
     {
         return lineNumber in this._invalidLineNumbers;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js (209491 => 209492)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2016-12-08 00:04:07 UTC (rev 209491)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2016-12-08 00:04:13 UTC (rev 209492)
@@ -839,8 +839,8 @@
         let indentString = WebInspector.indentString();
         const includeSourceMapData = true;
 
-        // FIXME: Properly pass if this is a module or script.
-        const isModule = false;
+        let sourceType = this._delegate.textEditorScriptSourceType(this);
+        const isModule = sourceType === WebInspector.Script.SourceType.Module;
 
         let workerProxy = WebInspector.FormatterWorkerProxy.singleton();
         workerProxy.formatJavaScript(sourceText, isModule, indentString, includeSourceMapData, ({formattedText, sourceMapData}) => {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to