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

Use of enums in object declaration causes failure with --align-object-properties & TypeScript #692

Open
systemmonkey42 opened this issue Aug 30, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@systemmonkey42
Copy link

systemmonkey42 commented Aug 30, 2021

Tested with Prettierx version: 0.19.0 and master (0.19.1-dev)

The following code fragment

enum horses {
    draught,
    brumby,
    stock,
    calabrese,
    curly,
    clydesdale,
    cleveland,
}

const weight: { [key in horses]?: number } = {
    [horses.draught]: 320,
    [horses.brumby]: 900,
    [horses.clydesdale]: 1200,
};

Causes prettierX to fail when the --align-object-properties option is set.

brodybits@brodybits-mini-mac-book prettierx % ./bin/prettierx.js --align-object-properties info.ts                    
info.ts[error] info.ts: TypeError: Cannot read property 'raw' of undefined
[error]     at getPropertyPadding (/Users/brodybits/prettierx/src/language-js/print/property.js:144:20)
[error]     at AstPath.call (/Users/brodybits/prettierx/src/common/ast-path.js:66:20)
[error]     at printProperty (/Users/brodybits/prettierx/src/language-js/print/property.js:186:32)
[error]     at printPathNoParens (/Users/brodybits/prettierx/src/language-js/printer-estree.js:374:14)
[error]     at Object.genericPrint [as print] (/Users/brodybits/prettierx/src/language-js/printer-estree.js:90:19)
[error]     at callPluginPrintFunction (/Users/brodybits/prettierx/src/main/ast-to-doc.js:133:21)
[error]     at mainPrintInternal (/Users/brodybits/prettierx/src/main/ast-to-doc.js:76:17)
[error]     at mainPrint (/Users/brodybits/prettierx/src/main/ast-to-doc.js:56:14)
[error]     at /Users/brodybits/prettierx/src/language-js/print/object.js:122:18
[error]     at AstPath.each (/Users/brodybits/prettierx/src/common/ast-path.js:95:7)
brodybits@brodybits-mini-mac-book prettierx % ./bin/prettierx.js --align-object-properties --parser=typescript info.ts
info.ts[error] info.ts: TypeError: Cannot read property 'raw' of undefined
[error]     at getPropertyPadding (/Users/brodybits/prettierx/src/language-js/print/property.js:144:20)
[error]     at AstPath.call (/Users/brodybits/prettierx/src/common/ast-path.js:66:20)
[error]     at printProperty (/Users/brodybits/prettierx/src/language-js/print/property.js:186:32)
[error]     at printPathNoParens (/Users/brodybits/prettierx/src/language-js/printer-estree.js:374:14)
[error]     at Object.genericPrint [as print] (/Users/brodybits/prettierx/src/language-js/printer-estree.js:90:19)
[error]     at callPluginPrintFunction (/Users/brodybits/prettierx/src/main/ast-to-doc.js:133:21)
[error]     at mainPrintInternal (/Users/brodybits/prettierx/src/main/ast-to-doc.js:76:17)
[error]     at mainPrint (/Users/brodybits/prettierx/src/main/ast-to-doc.js:56:14)
[error]     at /Users/brodybits/prettierx/src/language-js/print/object.js:122:18
[error]     at AstPath.each (/Users/brodybits/prettierx/src/common/ast-path.js:95:7)

Without the --align-object-properties, formatting works as usual.

Kind Regards

@brodycj
Copy link
Owner

brodycj commented Aug 30, 2021

I tried this in my prettierX, works perfectly for me. Can you post some more info such as how you ran prettierX to help us get to the bottom of this?


Now reproduced with --align-object-properties (see below)

@systemmonkey42
Copy link
Author

Thanks for trying this.

This clearly pointed to my configuration, so I culled my .prettierrc until I found the culprit.

{
  "alignObjectProperties": true
}

With this settings enabled, prettierx produces the error.

Thanks again.

@brodycj brodycj changed the title Use of enums in object declaration causes failure Use of enums in object declaration causes failure with --align-object-properties Aug 30, 2021
@brodycj brodycj added the bug Something isn't working label Aug 30, 2021
@brodycj brodycj changed the title Use of enums in object declaration causes failure with --align-object-properties Use of enums in object declaration causes failure with --align-object-properties & TypeScript Aug 30, 2021
@brodycj
Copy link
Owner

brodycj commented Aug 30, 2021

I just reproduced it with --align-object-properties & TypeScript in my work area, updated the title. I would be grateful if you can put this info into the original description as well.

Reproduced with both babel-ts (default prettierX parser for TypeScript) & typescript parsers.

brodybits@brodybits-mini-mac-book prettierx % ./bin/prettierx.js --align-object-properties info.ts                    
info.ts[error] info.ts: TypeError: Cannot read property 'raw' of undefined
[error]     at getPropertyPadding (/Users/brodybits/prettierx/src/language-js/print/property.js:144:20)
[error]     at AstPath.call (/Users/brodybits/prettierx/src/common/ast-path.js:66:20)
[error]     at printProperty (/Users/brodybits/prettierx/src/language-js/print/property.js:186:32)
[error]     at printPathNoParens (/Users/brodybits/prettierx/src/language-js/printer-estree.js:374:14)
[error]     at Object.genericPrint [as print] (/Users/brodybits/prettierx/src/language-js/printer-estree.js:90:19)
[error]     at callPluginPrintFunction (/Users/brodybits/prettierx/src/main/ast-to-doc.js:133:21)
[error]     at mainPrintInternal (/Users/brodybits/prettierx/src/main/ast-to-doc.js:76:17)
[error]     at mainPrint (/Users/brodybits/prettierx/src/main/ast-to-doc.js:56:14)
[error]     at /Users/brodybits/prettierx/src/language-js/print/object.js:122:18
[error]     at AstPath.each (/Users/brodybits/prettierx/src/common/ast-path.js:95:7)
brodybits@brodybits-mini-mac-book prettierx % ./bin/prettierx.js --align-object-properties --parser=typescript info.ts
info.ts[error] info.ts: TypeError: Cannot read property 'raw' of undefined
[error]     at getPropertyPadding (/Users/brodybits/prettierx/src/language-js/print/property.js:144:20)
[error]     at AstPath.call (/Users/brodybits/prettierx/src/common/ast-path.js:66:20)
[error]     at printProperty (/Users/brodybits/prettierx/src/language-js/print/property.js:186:32)
[error]     at printPathNoParens (/Users/brodybits/prettierx/src/language-js/printer-estree.js:374:14)
[error]     at Object.genericPrint [as print] (/Users/brodybits/prettierx/src/language-js/printer-estree.js:90:19)
[error]     at callPluginPrintFunction (/Users/brodybits/prettierx/src/main/ast-to-doc.js:133:21)
[error]     at mainPrintInternal (/Users/brodybits/prettierx/src/main/ast-to-doc.js:76:17)
[error]     at mainPrint (/Users/brodybits/prettierx/src/main/ast-to-doc.js:56:14)
[error]     at /Users/brodybits/prettierx/src/language-js/print/object.js:122:18
[error]     at AstPath.each (/Users/brodybits/prettierx/src/common/ast-path.js:95:7)

@Yikes2000
Copy link

Fixed here ... #700

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

3 participants