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

TS 2.3 API change breaks jsx-alignment #87

Closed
Jessidhia opened this issue Apr 14, 2017 · 2 comments
Closed

TS 2.3 API change breaks jsx-alignment #87

Jessidhia opened this issue Apr 14, 2017 · 2 comments

Comments

@Jessidhia
Copy link
Contributor

Jessidhia commented Apr 14, 2017

The above error seems to happen when using tslint 5.1.0, typescript 2.3.0; not sure how to reduce the input to a code snippet.

The unique part of the stack trace, for which I had to edit tslint/lib/linter.js to be able to obtain at all, looks like this:

TypeError: Cannot read property 'getStart' of undefined
  at JsxAlignmentWalker.getLineAndCharacter (.../node_modules/tslint-react/rules/jsxAlignmentRule.js:128:61)
  at JsxAlignmentWalker._this.getCharacter (.../node_modules/tslint-react/rules/jsxAlignmentRule.js:52:61)
  at JsxAlignmentWalker.checkElement (.../node_modules/tslint-react/rules/jsxAlignmentRule.js:80:39)
  at JsxAlignmentWalker.visitJsxElement (.../node_modules/tslint-react/rules/jsxAlignmentRule.js:60:18)
  at JsxAlignmentWalker.SyntaxWalker.visitNode (.../node_modules/tslint/lib/language/walker/syntaxWalker.js:401:22)
  at .../node_modules/tslint/lib/language/walker/syntaxWalker.js:530:63
  at visitEachNode (.../node_modules/typescript/lib/typescript.js:14674:30)
  at Object.forEachChild (.../node_modules/typescript/lib/typescript.js:14998:21)
  at JsxAlignmentWalker.SyntaxWalker.walkChildren (.../node_modules/tslint/lib/language/walker/syntaxWalker.js:530:12)
  at JsxAlignmentWalker.SyntaxWalker.visitJsxElement (.../node_modules/tslint/lib/language/walker/syntaxWalker.js:153:14)
  at JsxAlignmentWalker.visitJsxElement (.../node_modules/tslint-react/rules/jsxAlignmentRule.js:62:42)
  at JsxAlignmentWalker.SyntaxWalker.visitNode (.../node_modules/tslint/lib/language/walker/syntaxWalker.js:401:22)
@Jessidhia
Copy link
Contributor Author

Jessidhia commented Apr 14, 2017

It looks like TypeScript 2.3 has a new JSXAttributes kind (253), which is the new type of the opening element attributes property, instead of being a just an array of JSXAttribute.

The commit to blame is probably microsoft/TypeScript@41108db

@Jessidhia Jessidhia changed the title TypeError: Cannot read property 'getStart' of undefined TS 2.3 API change: TypeError: Cannot read property 'getStart' of undefined Apr 14, 2017
@Jessidhia Jessidhia changed the title TS 2.3 API change: TypeError: Cannot read property 'getStart' of undefined TS 2.3 API change breaks jsx-alignment Apr 14, 2017
@Jessidhia
Copy link
Contributor Author

I worked around it locally by editing node_modules/tslint-react/rules/jsxAlignmentRule.js like so:

     JsxAlignmentWalker.prototype.checkElement = function (elementOpen, attributes, elementClose, closingTag) {
+        attributes = attributes && attributes.properties ? attributes.properties : attributes;
         if (attributes == null || attributes.length === 0) {

But this change would be invalid in the typescript source.

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

No branches or pull requests

2 participants