parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.43k stars 2.26k forks source link

[parcel+transformer v2] [compiler v3] pug : "Unexpected token indent" #5643

Open KaKi87 opened 3 years ago

KaKi87 commented 3 years ago

🐛 bug report

The pug transformer doesn't allow the root DOM element to be indented.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
    "devDependencies": {
        "@parcel/transformer-coffeescript": "^2.0.0-nightly.529",
        "@parcel/transformer-pug": "^2.0.0-nightly.529",
        "@parcel/transformer-sass": "^2.0.0-nightly.529",
        "@parcel/transformer-vue": "^2.0.0-nightly.1973",
        "@vue/compiler-sfc": "^3.0.5",
        "parcel": "^2.0.0-nightly.527",
        "pug": "^3.0.0",
        "sass": "^1.32.4"
    },
    "dependencies": {
        "vue": "^3.0.5"
    }
}

🤔 Expected Behavior

The following pug code would be valid :

<template lang="pug">
    main.main Hello
</template>

😯 Current Behavior

Only the following pug code is valid :

<template lang="pug">
main.main Hello
</template>
@parcel/transformer-vue: Pug:2:1 1| > 2| main.main Hello -------^ 3| unexpected token "indent"
          Error: Pug:2:1
    1| 
  > 2|     main.main Hello
-------^
    3| 

unexpected token "indent"

💁 Possible Solution

Trim the template content before passing it to the pug transformer.

Related pull request on Rollup : https://github.com/vuejs/rollup-plugin-vue/pull/89

🔦 Context

I am trying to make the code more readable by indenting the root element as I do with CSS & JS.

Related issue on Rollup : https://github.com/vuejs/rollup-plugin-vue/issues/86

💻 Code Sample

Cf. current behavior section

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.527
Node 14.15.4
Yarn 1.22.5
Operating System Windows 10.2004.21286.1000

Thanks !

mischnic commented 3 years ago

The deindent step mentioned in the rollup issue should happen somewhere here: https://github.com/parcel-bundler/parcel/blob/49ac217507d5914a2e38ca402593d26527cdb673/packages/transformers/vue/src/VueTransformer.js#L218-L246