Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel Parser crash when there's a syntax error in content script #1297

Open
5 tasks done
maribox opened this issue Dec 21, 2024 · 0 comments
Open
5 tasks done

Babel Parser crash when there's a syntax error in content script #1297

maribox opened this issue Dec 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@maribox
Copy link

maribox commented Dec 21, 2024

Describe the bug

I come from #1295.
I have a problem when I run pnpm dev where, when I edit it auto-saves and tries to execute the content script, then the command crashes, so I have to run pnpm dev again , opening a new browser window which is really annoying. It crashes with a "BABEL_PARSER_SYNTAX_ERROR". I use svelte and wxt 0.19.13.

Log:

pnpm dev

> wxt-svelte-starter@0.0.0 dev /home/fed/Coding/WebDev/Extensions/phonetix/Phonetix
> wxt


WXT 0.19.22                                                                                                                                                                                        2:39:04 PM
✔ Started dev server @ http://localhost:3000                                                                                                                                                      2:39:05 PM
ℹ Pre-rendering chrome-mv3 for development with Vite 6.0.3                                                                                                                                        2:39:05 PM
fi
✔ Built extension in 1.578 s                                                                                                                                                                      2:39:07 PM
  ├─ .output/chrome-mv3/manifest.json               1.06 kB 
  ├─ .output/chrome-mv3/popup.html                  721 B   
  ├─ .output/chrome-mv3/background.js               88.24 kB
  ├─ .output/chrome-mv3/chunks/popup-BxzUToPe.js    8.28 kB 
  ├─ .output/chrome-mv3/content-scripts/content.js  42.3 kB 
  ├─ .output/chrome-mv3/icon/128.png                3.07 kB 
  ├─ .output/chrome-mv3/icon/16.png                 559 B   
  ├─ .output/chrome-mv3/icon/32.png                 916 B   
  ├─ .output/chrome-mv3/icon/48.png                 1.33 kB 
  ├─ .output/chrome-mv3/icon/96.png                 2.37 kB 
  └─ .output/chrome-mv3/wxt.svg                     1.07 kB 
Σ Total size: 149.92 kB                                              
✔ Opened browser in 1.372 s                                                                                                                                                                       2:39:08 PM
ℹ Press o + enter to reopen the browser                                                                                                                                                           2:39:08 PM
ℹ Changed: src/entrypoints/content.ts                                                                                                                                                             2:39:18 PM
/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/lib/index.js:359
    const error = new SyntaxError();
                  ^

SyntaxError: Unexpected token, expected "," (42:10)
    at toParseError (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parse-error.ts:95:45)
    at V8IntrinsicMixin.raise (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/tokenizer/index.ts:1496:19)
    at V8IntrinsicMixin.unexpected (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/tokenizer/index.ts:1536:16)
    at V8IntrinsicMixin.expect (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/util.ts:157:12)
    at V8IntrinsicMixin.parseCallExpressionArguments (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/expression.ts:994:14)
    at V8IntrinsicMixin.parseCoverCallAndAsyncArrowHead (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/expression.ts:883:29)
    at V8IntrinsicMixin.parseSubscript (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/expression.ts:772:19)
    at V8IntrinsicMixin.parseSubscript (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/plugins/typescript/index.ts:2606:20)
    at V8IntrinsicMixin.parseSubscripts (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/expression.ts:730:19)
    at V8IntrinsicMixin.parseExprSubscripts (/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/node_modules/.pnpm/@babel+parser@7.26.3/node_modules/@babel/parser/src/parser/expression.ts:715:17) {
  code: 'BABEL_PARSER_SYNTAX_ERROR',
  reasonCode: 'UnexpectedToken',
  loc: Position { line: 42, column: 10, index: 1479 },
  pos: 1479,
  syntaxPlugin: undefined,
  plugin: 'wxt:remove-entrypoint-main-function',
  id: '/home/fed/Coding/WebDev/Extensions/phonetix/Phonetix/src/entrypoints/content.ts',
  pluginCode: '\n' +
    'export default defineContentScript({\n' +
    "  matches: ['<all_urls>'],\n" +
    '  runAt: "document_start",\n' +
    '  main() {\n' +
    '    // TODO: I will use lists of IPA per language and make it possible to add multiple languages, then put them all into a set and update that set on each settings change\n' +
    '\n' +
    '    var enabled = true\n' +
    '    if (enabled) {\n' +
    '\n' +
    '    let blockTags = new Set(["SCRIPT", "STYLE"])\n' +
    '\n' +
    '    const ActualTextNodes: NodeFilter = (node: Node): number => {\n' +
    '      if (node.nodeType === Node.TEXT_NODE && node.parentElement && !blockTags.has(node.parentElement?.tagName)) {\n' +
    '        return NodeFilter.FILTER_ACCEPT;\n' +
    '      }\n' +
    '      return NodeFilter.FILTER_REJECT;\n' +
    '    };\n' +
    "    // TODO: Currently doesn't work great with shadow root nodes\n" +
    '    function transformAllTextNodes() {\n' +
    '      const walker = document.createTreeWalker(\n' +
    '        document.documentElement,\n' +
    '        NodeFilter.SHOW_TEXT,\n' +
    '        ActualTextNodes\n' +
    '      );\n' +
    '      let node;\n' +
    '      while ((node = walker.nextNode())) {\n' +
    '        if (node.nodeValue?.trim()) \n' +
    '          node.nodeValue = transform(node.nodeValue || "");\n' +
    '      }\n' +
    '    }\n' +
    '\n' +
    '    transformAllTextNodes();\n' +
    '    \n' +
    '    const config = { childList: true, subtree: true };\n' +
    '    const callback = (mutationsList: MutationRecord[]) => {\n' +
    '      mutationsList.forEach(mutation => \n' +
    '        mutation.addedNodes.forEach(node => {\n' +
    '          if (ActualTextNodes(node) == NodeFilter.FILTER_ACCEPT) {\n' +
    '            if (node.nodeValue?.trim())\n' +
    '              node.nodeValue = transform(node.nodeValue || ""\n' +
    '          }\n' +
    '        }\n' +
    '        )\n' +
    '      );\n' +
    '    };\n' +
    '\n' +
    '    const targetNode = document.documentElement\n' +
    '    const observer = new MutationObserver(callback);\n' +
    '    observer.observe(targetNode, config);\n' +
    '  }\n' +
    '  },\n' +
    '});\n' +
    '\n' +
    'function transform(text:string) {\n' +
    '  console.log(text)\n' +
    '  return text.toUpperCase()\n' +
    '}',
  frame: '40 |              if (node.nodeValue?.trim())\n' +
    '41 |                node.nodeValue = transform(node.nodeValue || ""\n' +
    '42 |            }\n' +
    '   |            ^\n' +
    '43 |          }\n' +
    '44 |          )'
}

Node.js v20.18.1
 ELIFECYCLE  Command failed with exit code 1.

Reproduction

myproject.zip

Steps to reproduce

pnpm i
pnpm dev
open a random webpage (e.g. search for apple cider vinegar)
then, in src/entrypoints/content.ts, edit e.g. in line 41 remove the last bracket.

System Info

System:
    OS: Linux 6.12 Fedora Linux 40 (KDE Plasma)
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i7-12850HX
    Memory: 5.48 GB / 31.02 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.18.1 - /usr/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v21.2.0/bin/yarn
    npm: 10.8.2 - /usr/bin/npm
    pnpm: 8.11.0 - ~/.local/share/pnpm/pnpm
    bun: 1.1.17 - ~/.bun/bin/bun
    Watchman: 0.0.0 - /usr/bin/watchman
  Browsers:
    Brave Browser: 131.1.73.101
    Chrome: 133.0.6888.2

Used Package Manager

pnpm

Validations

@maribox maribox added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Dec 21, 2024
@aklinker1 aklinker1 added bug Something isn't working and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants