Skip to content

Chore/upgrade prettier v3 #365

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

Merged
merged 31 commits into from
Jul 14, 2023

Conversation

carmanchris31
Copy link
Contributor

WIP of upgrading to prettier v3

There are currently 153 failing tests, most of which are because of thrown errors. Any help with troubleshooting these errors is welcome and appreciated.

Current output of npm test:
test-results.txt

dummdidumm and others added 26 commits March 14, 2023 11:54
Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](chalk/ansi-regex@v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [trim-off-newlines](https://github.com/stevemao/trim-off-newlines) from 1.0.1 to 1.0.3.
- [Release notes](https://github.com/stevemao/trim-off-newlines/releases)
- [Commits](stevemao/trim-off-newlines@v1.0.1...v1.0.3)

---
updated-dependencies:
- dependency-name: trim-off-newlines
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](isaacs/minimatch@v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/kornelski/http-cache-semantics/releases)
- [Commits](kornelski/http-cache-semantics@v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [minimist](https://github.com/minimistjs/minimist) from 1.2.5 to 1.2.8.
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](minimistjs/minimist@v1.2.5...v1.2.8)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fix attributeRegex so that it correctly matches attributes that are not enclosed in quotes.
fix sveltejs#344

---------

Co-authored-by: Simon Holthausen <[email protected]>
@dummdidumm
Copy link
Member

@carmanchris31 now that Prettier version 3 is out officially, do you want to continue working on this PR or should I pick it up?

package.json Outdated
"ava": "3.15.0",
"prettier": "^2.7.1",
"prettier": "^3.0.0-alpha.11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be updated to ^3.0.0 now

src/embed.ts Outdated
const embedScript = (isTopLevel: boolean) =>
embedType(
'script',
// Use babel-ts as fallback because the absence does not mean the content is not TS,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we no longer support default language. you must now specify it explicitly in the script block. the comment on isTypeScript can be updated as well

@carmanchris31
Copy link
Contributor Author

@carmanchris31 now that Prettier version 3 is out officially, do you want to continue working on this PR or should I pick it up?

Please do, thanks! 🙏

@dummdidumm dummdidumm mentioned this pull request Jul 5, 2023
@sebastinez
Copy link

sebastinez commented Jul 6, 2023

Hmm so I think I found one reason for the Cannot read properties of undefined (reading \'length\') error (which seems one that shows up a lot), but not sure on the solution yet.

The preprocess snips the content in the style and the script tag as called for
This is the preprocessed string for the unsupported-language printer test

'<script lang="coffee" ✂prettier:content✂="CgoKYWxlcnQgIlRoaXMgaXMgbm90IHZhbGlkIEpTIGFuZCBzaG91bGQgbm90IGJlIGZvcm1hdHRlZC4iCgoK">{}</script><style lang="stylus" ✂prettier:content✂="CiAgaDEKICAgIGNvbG9yOiByZWQK"></style>'

But then when the svelte compiler parses the string, we don't get the attributes property on the instance property as we do on the css property.

{
  html: {
    start: 141,
    end: 139,
    type: 'Fragment',
    children: [
      { start: 139, end: 141, type: 'Text', raw: '\n\n', data: '\n\n' }
    ]
  },
  css: {
    type: 'Style',
    start: 141,
    end: 220,
    attributes: [
      {
        start: 148,
        end: 161,
        type: 'Attribute',
        name: 'lang',
        value: [
          {
            start: 154,
            end: 160,
            type: 'Text',
            raw: 'stylus',
            data: 'stylus'
          }
        ]
      },
      {
        start: 162,
        end: 211,
        type: 'Attribute',
        name: '✂prettier:content✂',
        value: [
          {
            start: 182,
            end: 210,
            type: 'Text',
            raw: 'CiAgaDEKICAgIGNvbG9yOiByZWQK',
            data: 'CiAgaDEKICAgIGNvbG9yOiByZWQK'
          }
        ]
      }
    ],
    children: [],
    content: { start: 212, end: 212, styles: '' }
  },
  instance: {
    type: 'Script',
    start: 0,
    end: 139,
    context: 'default',
    content: Node {
      type: 'Program',
      start: 128,
      end: 130,
      loc: SourceLocation {
        start: Position { line: 1, column: 0 },
        end: Position { line: 1, column: 130 }
      },
      body: [
        Node {
          type: 'BlockStatement',
          start: 128,
          end: 130,
          loc: SourceLocation {
            start: Position { line: 1, column: 128 },
            end: Position { line: 1, column: 130 }
          },
          body: []
        }
      ],
      sourceType: 'module'
    }
  },
  module: undefined,
  __isRoot: true
}

Later when trying to extract the prettier-content attribute here

function getSnippedContent(node: Node) {

We get an empty string, and this breaks the AstPath iteration, as the error stackTrace says.

  › AstPath.each (file://node_modules/prettier/index.mjs:17308:33)
  › AstPath.map (file://node_modules/prettier/index.mjs:17322:10)
  › src/embed.ts:223:25
  › Generator.next (<anonymous>)
  › src/embed.ts:8:71
  › __awaiter (src/embed.ts:4:12)
  › embedTag (src/embed.ts:141:12)
  › embedType (src/embed.ts:70:13)
  › embedScript (src/embed.ts:81:13)

I hope this can help, will keep looking

@sebastinez
Copy link

sebastinez commented Jul 6, 2023

Follow up: Ok just checked on the previous behavior and it seems that the top level nodes aren't recognized as such here, due to the _isRoot property missing.

return printTopLevelParts(n, options, path, print);

So we don't get to extract the prettier:content attributes, and fail later

@carmanchris31
Copy link
Contributor Author

Follow up: Ok just checked on the previous behavior and it seems that the top level nodes aren't recognized as such here, due to the _isRoot property missing.

return printTopLevelParts(n, options, path, print);

So we don't get to extract the prettier:content attributes, and fail later

Interesting. It sounds like that could be responsible for a vast number of the failures!

@dummdidumm
Copy link
Member

Found the reason for all the breakage - embed call behavior has changed: prettier/prettier#15093 . This is gonna take some refactoring..

@dummdidumm dummdidumm marked this pull request as ready for review July 14, 2023 14:36
@dummdidumm dummdidumm merged commit c4295e8 into sveltejs:next Jul 14, 2023
@developomp
Copy link

finally! 🥳

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.

7 participants