Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Breaking: Properly categorize constructors with no body #427

Merged
merged 1 commit into from
Jan 12, 2018

Conversation

j-f1
Copy link
Contributor

@j-f1 j-f1 commented Jan 5, 2018

I think this is a breaking change, but feel free to correct me if I’m wrong.

Error this fixes:

.../node_modules/eslint/lib/rules/strict.js:220
            const isBlock = node.body.type === "BlockStatement",
                                      ^
TypeError: Cannot read property 'type' of null
    at enterFunction (.../node_modules/eslint/lib/rules/strict.js:220:39)
    at listeners.(anonymous function).forEach.listener (.../node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (.../node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (.../node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (.../node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (.../node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (.../node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at Traverser.enter (.../node_modules/eslint/lib/linter.js:956:32)
    at Traverser.__execute (.../node_modules/estraverse/estraverse.js:397:31)
    at Traverser.traverse (.../node_modules/estraverse/estraverse.js:501:28)
    at Traverser.traverse (.../node_modules/eslint/lib/util/traverser.js:31:22)
    at Linter._verifyWithoutProcessors (.../node_modules/eslint/lib/linter.js:953:19)
    at preprocess.map.textBlock (.../node_modules/eslint/lib/linter.js:994:35)
    at Array.map (<anonymous>)
    at Linter.verify (.../node_modules/eslint/lib/linter.js:993:42)

@kaicataldo
Copy link
Member

Just for my own edification (I'm still pretty new to TypeScript), mind sharing the code that's causing this issue?

@j-f1
Copy link
Contributor Author

j-f1 commented Jan 9, 2018

declare class Foo {
  constructor(bar: string)
}

(class Foo { constructor() } also works, but there isn’t really a real-world use for it)

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM, but definitely want to get someone else who has more experience reviewing this too.

@JamesHenry
Copy link
Member

Yes, this is a breaking change for anything which consumes the the AST via the parseForESLint method. I think that is just eslint-plugin-typescript.

LGTM!

@JamesHenry JamesHenry merged commit 6ce4cd8 into eslint:master Jan 12, 2018
@j-f1 j-f1 deleted the fix-empty-body-constructors branch January 12, 2018 14:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants