Skip to content

fix: serialize style-raw CSS with JSON.stringify in parcel-transformer-vue - #1367

Open
akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1361-plasmohq-parcel-transformer-vue-emits-un
Open

akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1361-plasmohq-parcel-transformer-vue-emits-un

Conversation

@akysil

@akysil akysil commented Nov 29, 2026

Copy link
Copy Markdown

Details

This PR fixes the style-raw pipeline in @plasmohq/parcel-transformer-vue, which put the compiled Vue <style> CSS straight into a JS template literal. CSS that contains backslashes, backticks or ${ was read as template-literal syntax:

  • content: "\2022" failed with SyntaxError: Octal escape sequences are not allowed in template strings
  • content: "\f00c" was silently changed into a form feed followed by 00c
  • a backtick in a CSS comment broke the generated module
  • ${foo} in CSS was evaluated as JS

Fixes #1361

Approach

The CSS string is now written with JSON.stringify, the same way the transformer already writes cssModules, __file and custom blocks. The Vue CSUI mount template still gets the same default string export. It just keeps the exact CSS now. I chose this over escaping the template-literal characters by hand, which would add a second escaping routine, and over changing the mount code, which would touch more files for the same result.

Testing

core/* has no test runner, so I tested with a script on Node 20.15.1 (run through tsx). It parses a .vue SFC with this package's parse, runs the style-raw pipeline and evaluates the generated module. It covers the four cases from the issue plus plain multiline CSS: 1/5 pass on main (the four issue cases fail with the errors above), 5/5 with this change.

I also ran the steps of the test-examples.yml workflow locally on Node 20.15.1 with submodules checked out: pnpm i --no-frozen-lockfile, build:packages, build:api and build:cli passed. One run of build:examples with the examples building in parallel failed in examples/with-google-analytics-measurement with Failed to parse .parcelrc. That example has no Vue files, and a full run on clean main (9369e28) passed. When I reran build:examples and test:examples one example at a time over the same projects, both passed, including with-vue.

No UI change of its own: Vue CSUI styles that use CSS escapes or backticks are injected as written instead of breaking the build or being changed.

Known limitations

  • Parallel example builds can race on the shared core/parcel-config/run.json, which every plasmo build rewrites before Parcel starts. That is separate from this fix.

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I agree to license this contribution under the MIT LICENSE
  • I checked the current PR for duplication.

Contacts

  • (OPTIONAL) Discord ID: b81234901824

If your PR is accepted, we will award you with the Contributor role on Discord server.

To join the server, visit: https://www.plasmo.com/s/d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@plasmohq/parcel-transformer-vue emits unescaped template literal in style-raw pipeline, breaking CSS escapes and backticks

1 participant