Skip to content

Commit

Permalink
[Web Inspector] Fix syntax errror when viewing import.meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Aug 14, 2023
1 parent e5b29e9 commit 68de5bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Source/WebInspectorUI/Tools/JSFormatter/JSFormatterDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ JSFormatterDebug = class JSFormatterDebug
{
constructor(sourceText, sourceType)
{
let tree = esprima.parse(sourceText, {attachComment: true, range: true, tokens: true, sourceType});
const parseFn = sourceType === "module" ? esprima.parseModule : esprima.parse;
let tree = parseFn(sourceText, {attachComment: true, range: true, tokens: true, sourceType});
let walker = new ESTreeWalker(this._before.bind(this), this._after.bind(this));

this._statistics = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ WI.ScriptSyntaxTree = class ScriptSyntaxTree

try {
let sourceType = this._script.sourceType === WI.Script.SourceType.Module ? "module" : "script";
let esprimaSyntaxTree = esprima.parse(sourceText, {loc: true, range: true, sourceType});
const parseFn = sourceType === "module" ? esprima.parseModule : esprima.parse;
let esprimaSyntaxTree = parseFn(sourceText, {loc: true, range: true, sourceType});
this._syntaxTree = this._createInternalSyntaxTree(esprimaSyntaxTree);
this._parsedSuccessfully = true;
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ JSFormatter = class JSFormatter
constructor(sourceText, sourceType, builder, indentString = " ")
{
this._success = false;
const parseFn = sourceType === "module" ? esprima.parseModule : esprima.parse;

let tree = (function() {
try {
return esprima.parse(sourceText, {attachComment: true, range: true, tokens: true, sourceType});
return parseFn(sourceText, {attachComment: true, range: true, tokens: true, sourceType});
} catch(error) {
console.error(`Failed to parse source text of type "${sourceType}".`, error);
return null;
Expand Down

0 comments on commit 68de5bf

Please sign in to comment.