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

ImportDeclaration.parent is not expected to be a TSModuleDeclaration #217

Closed
flying-sheep opened this issue Apr 12, 2017 · 4 comments
Closed
Labels

Comments

@flying-sheep
Copy link
Contributor

flying-sheep commented Apr 12, 2017

the rule import/newline-after-import accesses a ImportDeclaration’s parent, expecting it to have a body

that’s not true if you encounter a TSModuleDeclarationTSModuleBlockImportDeclaration:

declare module 'postcss-modules' {
	import {Plugin} from 'postcss'
	...
}

a fix for this specific problem would be a visitor like TSModuleDeclaration(m) { m.body = m.statements }

@soda0289
Copy link
Member

I have seen this one before. If I remember correctly it doesnt cuase a crash. But it expects that the parent is the Program node, which is true for es6. Not sure if we should update our produced ast nodes or fix the plugin. But in this case it might make sense to use the property body instead of statements. I think class nodes use body property can't remember which nodes, if any, use the statements property.

@soda0289 soda0289 added bug and removed triage labels Apr 12, 2017
@flying-sheep
Copy link
Contributor Author

flying-sheep commented Apr 12, 2017

it crashed for me:

const { parent } = node  // parent === { type: 'TSModuleBlock', statements: [...], ... }
const nodePosition = parent.body.indexOf(node)  // parent.body === undefined

@soda0289
Copy link
Member

Do you want to submit a PR to rename statements property to body? I looked in the ESTree spec and they never use statements as a property only body. I think we should follow that same pattern.

flying-sheep added a commit to flying-sheep/typescript-eslint-parser that referenced this issue Apr 12, 2017
@flying-sheep
Copy link
Contributor Author

Done: #218

flying-sheep added a commit to flying-sheep/typescript-eslint-parser that referenced this issue Apr 12, 2017
flying-sheep added a commit to flying-sheep/typescript-eslint-parser that referenced this issue Apr 12, 2017
flying-sheep added a commit to flying-sheep/typescript-eslint-parser that referenced this issue Apr 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants